0be28f6c1dc5e93abf2833c4fb37101855cd0f14
[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
88 #include "testpmd.h"
89
90 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
91
92 #ifdef RTE_NIC_BYPASS
93 uint8_t bypass_is_supported(portid_t port_id);
94 #endif
95
96 /* *** Help command with introduction. *** */
97 struct cmd_help_brief_result {
98         cmdline_fixed_string_t help;
99 };
100
101 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
102                                   struct cmdline *cl,
103                                   __attribute__((unused)) void *data)
104 {
105         cmdline_printf(
106                 cl,
107                 "\n"
108                 "Help is available for the following sections:\n\n"
109                 "    help control    : Start and stop forwarding.\n"
110                 "    help display    : Displaying port, stats and config "
111                 "information.\n"
112                 "    help config     : Configuration information.\n"
113                 "    help ports      : Configuring ports.\n"
114                 "    help flowdir    : Flow Director filter help.\n"
115                 "    help registers  : Reading and setting port registers.\n"
116                 "    help all        : All of the above sections.\n\n"
117         );
118
119 }
120
121 cmdline_parse_token_string_t cmd_help_brief_help =
122         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
123
124 cmdline_parse_inst_t cmd_help_brief = {
125         .f = cmd_help_brief_parsed,
126         .data = NULL,
127         .help_str = "show help",
128         .tokens = {
129                 (void *)&cmd_help_brief_help,
130                 NULL,
131         },
132 };
133
134 /* *** Help command with help sections. *** */
135 struct cmd_help_long_result {
136         cmdline_fixed_string_t help;
137         cmdline_fixed_string_t section;
138 };
139
140 static void cmd_help_long_parsed(void *parsed_result,
141                                  struct cmdline *cl,
142                                  __attribute__((unused)) void *data)
143 {
144         int show_all = 0;
145         struct cmd_help_long_result *res = parsed_result;
146
147         if (!strcmp(res->section, "all"))
148                 show_all = 1;
149
150         if (show_all || !strcmp(res->section, "control")) {
151
152                 cmdline_printf(
153                         cl,
154                         "\n"
155                         "Control forwarding:\n"
156                         "-------------------\n\n"
157
158                         "start\n"
159                         "    Start packet forwarding with current configuration.\n\n"
160
161                         "start tx_first\n"
162                         "    Start packet forwarding with current config"
163                         " after sending one burst of packets.\n\n"
164
165                         "stop\n"
166                         "    Stop packet forwarding, and display accumulated"
167                         " statistics.\n\n"
168
169                         "quit\n"
170                         "    Quit to prompt in Linux and reboot on Baremetal.\n\n"
171                 );
172         }
173
174         if (show_all || !strcmp(res->section, "display")) {
175
176                 cmdline_printf(
177                         cl,
178                         "\n"
179                         "Display:\n"
180                         "--------\n\n"
181
182                         "show port (info|stats|fdir|stat_qmap) (port_id|all)\n"
183                         "    Display information for port_id, or all.\n\n"
184
185                         "show port rss-hash [key]\n"
186                         "    Display the RSS hash functions and RSS hash key"
187                         " of port X\n\n"
188
189                         "clear port (info|stats|fdir|stat_qmap) (port_id|all)\n"
190                         "    Clear information for port_id, or all.\n\n"
191
192                         "show config (rxtx|cores|fwd)\n"
193                         "    Display the given configuration.\n\n"
194
195                         "read rxd (port_id) (queue_id) (rxd_id)\n"
196                         "    Display an RX descriptor of a port RX queue.\n\n"
197
198                         "read txd (port_id) (queue_id) (txd_id)\n"
199                         "    Display a TX descriptor of a port TX queue.\n\n"
200                 );
201         }
202
203         if (show_all || !strcmp(res->section, "config")) {
204                 cmdline_printf(
205                         cl,
206                         "\n"
207                         "Configuration:\n"
208                         "--------------\n"
209                         "Configuration changes only become active when"
210                         " forwarding is started/restarted.\n\n"
211
212                         "set default\n"
213                         "    Reset forwarding to the default configuration.\n\n"
214
215                         "set verbose (level)\n"
216                         "    Set the debug verbosity level X.\n\n"
217
218                         "set nbport (num)\n"
219                         "    Set number of ports.\n\n"
220
221                         "set nbcore (num)\n"
222                         "    Set number of cores.\n\n"
223
224                         "set coremask (mask)\n"
225                         "    Set the forwarding cores hexadecimal mask.\n\n"
226
227                         "set portmask (mask)\n"
228                         "    Set the forwarding ports hexadecimal mask.\n\n"
229
230                         "set burst (num)\n"
231                         "    Set number of packets per burst.\n\n"
232
233                         "set burst tx delay (microseconds) retry (num)\n"
234                         "    Set the transmit delay time and number of retries"
235                         " in mac_retry forwarding mode.\n\n"
236
237                         "set txpkts (x[,y]*)\n"
238                         "    Set the length of each segment of TXONLY"
239                         " packets.\n\n"
240
241                         "set corelist (x[,y]*)\n"
242                         "    Set the list of forwarding cores.\n\n"
243
244                         "set portlist (x[,y]*)\n"
245                         "    Set the list of forwarding ports.\n\n"
246
247                         "vlan set strip (on|off) (port_id)\n"
248                         "    Set the VLAN strip on a port.\n\n"
249
250                         "vlan set stripq (on|off) (port_id,queue_id)\n"
251                         "    Set the VLAN strip for a queue on a port.\n\n"
252
253                         "vlan set filter (on|off) (port_id)\n"
254                         "    Set the VLAN filter on a port.\n\n"
255
256                         "vlan set qinq (on|off) (port_id)\n"
257                         "    Set the VLAN QinQ (extended queue in queue)"
258                         " on a port.\n\n"
259
260                         "vlan set tpid (value) (port_id)\n"
261                         "    Set the outer VLAN TPID for Packet Filtering on"
262                         " a port\n\n"
263
264                         "rx_vlan add (vlan_id|all) (port_id)\n"
265                         "    Add a vlan_id, or all identifiers, to the set"
266                         " of VLAN identifiers filtered by port_id.\n\n"
267
268                         "rx_vlan rm (vlan_id|all) (port_id)\n"
269                         "    Remove a vlan_id, or all identifiers, from the set"
270                         " of VLAN identifiers filtered by port_id.\n\n"
271
272                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
273                         "    Add a vlan_id, to the set of VLAN identifiers"
274                         "filtered for VF(s) from port_id.\n\n"
275                         
276                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
277                         "    Remove a vlan_id, to the set of VLAN identifiers"
278                         "filtered for VF(s) from port_id.\n\n"                  
279
280                         "rx_vlan set tpid (value) (port_id)\n"
281                         "    Set the outer VLAN TPID for Packet Filtering on"
282                         " a port\n\n"
283
284                         "tx_vlan set vlan_id (port_id)\n"
285                         "    Set hardware insertion of VLAN ID in packets sent"
286                         " on a port.\n\n"
287
288                         "tx_vlan reset (port_id)\n"
289                         "    Disable hardware insertion of a VLAN header in"
290                         " packets sent on a port.\n\n"
291
292                         "tx_checksum set mask (port_id)\n"
293                         "    Enable hardware insertion of checksum offload with"
294                         " the 4-bit mask, 0~0xf, in packets sent on a port.\n"
295                         "        bit 0 - insert ip   checksum offload if set\n"
296                         "        bit 1 - insert udp  checksum offload if set\n"
297                         "        bit 2 - insert tcp  checksum offload if set\n"
298                         "        bit 3 - insert sctp checksum offload if set\n"
299                         "    Please check the NIC datasheet for HW limits.\n\n"
300
301                         "set fwd (%s)\n"
302                         "    Set packet forwarding mode.\n\n"
303
304                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
305                         "    Add a MAC address on port_id.\n\n"
306
307                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
308                         "    Remove a MAC address from port_id.\n\n"
309
310                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
311                         "    Add a MAC address for a VF on the port.\n\n"
312                         
313                         "set port (port_id) uta (mac_address|all) (on|off)\n"
314                         "    Add/Remove a or all unicast hash filter(s)" 
315                         "from port X.\n\n"
316
317                         "set promisc (port_id|all) (on|off)\n"
318                         "    Set the promiscuous mode on port_id, or all.\n\n"
319
320                         "set allmulti (port_id|all) (on|off)\n"
321                         "    Set the allmulti mode on port_id, or all.\n\n"
322
323                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
324                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
325                         " (on|off) (port_id)\n"
326                         "    Set the link flow control parameter on a port.\n\n"
327
328                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
329                         " (low_water) (pause_time) (priority) (port_id)\n"
330                         "    Set the priority flow control parameter on a"
331                         " port.\n\n"
332
333                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
334                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
335                         " queue on port.\n"
336                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
337                         " on port 0 to mapping 5.\n\n"
338
339                         "set port (port_id) vf (vf_id) rx|tx on|off \n"
340                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
341
342                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
343                         "|MPE) (on|off)\n"
344                         "    AUPE:accepts untagged VLAN;"
345                         "ROPE:accept unicast hash\n\n"
346                         "    BAM:accepts broadcast packets;"
347                         "MPE:accepts all multicast packets\n\n"
348                         "    Enable/Disable a VF receive mode of a port\n\n"
349                         
350                         "set port (port_id) mirror-rule (rule_id)" 
351                         "(pool-mirror|vlan-mirror)\n"
352                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
353                         "   Set pool or vlan type mirror rule on a port.\n"
354                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
355                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
356                         " to pool 0.\n\n"
357
358                         "set port (port_id) mirror-rule (rule_id)"
359                         " (uplink-mirror|downlink-mirror) dst-pool"
360                         " (pool_id) (on|off)\n"
361                         "   Set uplink or downlink type mirror rule on a port.\n"
362                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
363                         " 0 on' enable mirror income traffic to pool 0.\n\n"
364
365                         "reset port (port_id) mirror-rule (rule_id)\n"
366                         "   Reset a mirror rule.\n\n"
367
368                         "set flush_rx (on|off)\n"
369                         "   Flush (default) or don't flush RX streams before"
370                         " forwarding. Mainly used with PCAP drivers.\n\n"
371
372                         #ifdef RTE_NIC_BYPASS
373                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
374                         "   Set the bypass mode for the lowest port on bypass enabled"
375                         " NIC.\n\n"
376
377                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
378                         "mode (normal|bypass|isolate) (port_id)\n"
379                         "   Set the event required to initiate specified bypass mode for"
380                         " the lowest port on a bypass enabled NIC where:\n"
381                         "       timeout   = enable bypass after watchdog timeout.\n"
382                         "       os_on     = enable bypass when OS/board is powered on.\n"
383                         "       os_off    = enable bypass when OS/board is powered off.\n"
384                         "       power_on  = enable bypass when power supply is turned on.\n"
385                         "       power_off = enable bypass when power supply is turned off."
386                         "\n\n"
387
388                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
389                         "   Set the bypass watchdog timeout to 'n' seconds"
390                         " where 0 = instant.\n\n"
391
392                         "show bypass config (port_id)\n"
393                         "   Show the bypass configuration for a bypass enabled NIC"
394                         " using the lowest port on the NIC.\n\n"
395 #endif
396
397                         , list_pkt_forwarding_modes()
398                 );
399         }
400
401
402         if (show_all || !strcmp(res->section, "flowdir")) {
403
404                 cmdline_printf(
405                         cl,
406                         "\n"
407                         "Flow director mode:\n"
408                         "-------------------\n\n"
409
410                         "add_signature_filter (port_id) (ip|udp|tcp|sctp)"
411                         " src (src_ip_address) (src_port)"
412                         " dst (dst_ip_address) (dst_port)"
413                         " flexbytes (flexbytes_values) vlan (vlan_id)"
414                         " queue (queue_id)\n"
415                         "    Add a signature filter.\n\n"
416
417                         "upd_signature_filter (port_id) (ip|udp|tcp|sctp)"
418                         " src (src_ip_address) (src_port)"
419                         " dst (dst_ip_address) (dst_port)"
420                         " flexbytes (flexbytes_values) vlan (vlan_id)"
421                         " queue (queue_id)\n"
422                         "    Update a signature filter.\n\n"
423
424                         "rm_signature_filter (port_id) (ip|udp|tcp|sctp)"
425                         " src (src_ip_address) (src_port)"
426                         " dst (dst_ip_address) (dst_port)"
427                         " flexbytes (flexbytes_values) vlan (vlan_id)\n"
428                         "    Remove a signature filter.\n\n"
429
430                         "add_perfect_filter (port_id) (ip|udp|tcp|sctp)"
431                         " src (src_ip_address) (src_port)"
432                         " dst (dst_ip_address) (dst_port)"
433                         " flexbytes (flexbytes_values) vlan (vlan_id)"
434                         " queue (queue_id) soft (soft_id)\n"
435                         "    Add a perfect filter.\n\n"
436
437                         "upd_perfect_filter (port_id) (ip|udp|tcp|sctp)"
438                         " src (src_ip_address) (src_port)"
439                         " dst (dst_ip_address) (dst_port)"
440                         " flexbytes (flexbytes_values) vlan (vlan_id)"
441                         " queue (queue_id)\n"
442                         "    Update a perfect filter.\n\n"
443
444                         "rm_perfect_filter (port_id) (ip|udp|tcp|sctp)"
445                         " src (src_ip_address) (src_port)"
446                         " dst (dst_ip_address) (dst_port)"
447                         " flexbytes (flexbytes_values) vlan (vlan_id)"
448                         " soft (soft_id)\n"
449                         "    Remove a perfect filter.\n\n"
450
451                         "set_masks_filter (port_id) only_ip_flow (0|1)"
452                         " src_mask (ip_src_mask) (src_port_mask)"
453                         " dst_mask (ip_dst_mask) (dst_port_mask)"
454                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)\n"
455                         "    Set IPv4 filter masks.\n\n"
456
457                         "set_ipv6_masks_filter (port_id) only_ip_flow (0|1)"
458                         " src_mask (ip_src_mask) (src_port_mask)"
459                         " dst_mask (ip_dst_mask) (dst_port_mask)"
460                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)"
461                         " compare_dst (0|1)\n"
462                         "    Set IPv6 filter masks.\n\n"
463                 );
464         }
465
466         if (show_all || !strcmp(res->section, "ports")) {
467
468                 cmdline_printf(
469                         cl,
470                         "\n"
471                         "Port Operations:\n"
472                         "----------------\n\n"
473
474                         "port start (port_id|all)\n"
475                         "    Start all ports or port_id.\n\n"
476
477                         "port stop (port_id|all)\n"
478                         "    Stop all ports or port_id.\n\n"
479
480                         "port close (port_id|all)\n"
481                         "    Close all ports or port_id.\n\n"
482
483                         "port config (port_id|all) speed (10|100|1000|10000|auto)"
484                         " duplex (half|full|auto)\n"
485                         "    Set speed and duplex for all ports or port_id\n\n"
486
487                         "port config all (rxq|txq|rxd|txd) (value)\n"
488                         "    Set number for rxq/txq/rxd/txd.\n\n"
489
490                         "port config all max-pkt-len (value)\n"
491                         "    Set the max packet length.\n\n"
492
493                         "port config all (crc-strip|rx-cksum|hw-vlan|drop-en)"
494                         " (on|off)\n"
495                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
496                         " for ports.\n\n"
497
498                         "port config all rss (ip|udp|none)\n"
499                         "    Set the RSS mode.\n\n"
500
501                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
502                         "    Set the RSS redirection table.\n\n"
503
504                         "port config (port_id) dcb vt (on|off) (traffic_class)"
505                         " pfc (on|off)\n"
506                         "    Set the DCB mode.\n\n"
507
508                         "port config all burst (value)\n"
509                         "    Set the number of packets per burst.\n\n"
510
511                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
512                         " (value)\n"
513                         "    Set the ring prefetch/host/writeback threshold"
514                         " for tx/rx queue.\n\n"
515
516                         "port config all (txfreet|txrst|rxfreet) (value)\n"
517                         "    Set free threshold for rx/tx, or set"
518                         " tx rs bit threshold.\n\n"
519                 );
520         }
521
522         if (show_all || !strcmp(res->section, "registers")) {
523
524                 cmdline_printf(
525                         cl,
526                         "\n"
527                         "Registers:\n"
528                         "----------\n\n"
529
530                         "read reg (port_id) (address)\n"
531                         "    Display value of a port register.\n\n"
532
533                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
534                         "    Display a port register bit field.\n\n"
535
536                         "read regbit (port_id) (address) (bit_x)\n"
537                         "    Display a single port register bit.\n\n"
538
539                         "write reg (port_id) (address) (value)\n"
540                         "    Set value of a port register.\n\n"
541
542                         "write regfield (port_id) (address) (bit_x) (bit_y)"
543                         " (value)\n"
544                         "    Set bit field of a port register.\n\n"
545
546                         "write regbit (port_id) (address) (bit_x) (value)\n"
547                         "    Set single bit value of a port register.\n\n"
548                 );
549         }
550 }
551
552 cmdline_parse_token_string_t cmd_help_long_help =
553         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
554
555 cmdline_parse_token_string_t cmd_help_long_section =
556         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
557                         "all#control#display#config#flowdir#"
558                         "ports#registers");
559
560 cmdline_parse_inst_t cmd_help_long = {
561         .f = cmd_help_long_parsed,
562         .data = NULL,
563         .help_str = "show help",
564         .tokens = {
565                 (void *)&cmd_help_long_help,
566                 (void *)&cmd_help_long_section,
567                 NULL,
568         },
569 };
570
571
572 /* *** start/stop/close all ports *** */
573 struct cmd_operate_port_result {
574         cmdline_fixed_string_t keyword;
575         cmdline_fixed_string_t name;
576         cmdline_fixed_string_t value;
577 };
578
579 static void cmd_operate_port_parsed(void *parsed_result,
580                                 __attribute__((unused)) struct cmdline *cl,
581                                 __attribute__((unused)) void *data)
582 {
583         struct cmd_operate_port_result *res = parsed_result;
584
585         if (!strcmp(res->name, "start"))
586                 start_port(RTE_PORT_ALL);
587         else if (!strcmp(res->name, "stop"))
588                 stop_port(RTE_PORT_ALL);
589         else if (!strcmp(res->name, "close"))
590                 close_port(RTE_PORT_ALL);
591         else
592                 printf("Unknown parameter\n");
593 }
594
595 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
596         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
597                                                                 "port");
598 cmdline_parse_token_string_t cmd_operate_port_all_port =
599         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
600                                                 "start#stop#close");
601 cmdline_parse_token_string_t cmd_operate_port_all_all =
602         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
603
604 cmdline_parse_inst_t cmd_operate_port = {
605         .f = cmd_operate_port_parsed,
606         .data = NULL,
607         .help_str = "port start|stop|close all: start/stop/close all ports",
608         .tokens = {
609                 (void *)&cmd_operate_port_all_cmd,
610                 (void *)&cmd_operate_port_all_port,
611                 (void *)&cmd_operate_port_all_all,
612                 NULL,
613         },
614 };
615
616 /* *** start/stop/close specific port *** */
617 struct cmd_operate_specific_port_result {
618         cmdline_fixed_string_t keyword;
619         cmdline_fixed_string_t name;
620         uint8_t value;
621 };
622
623 static void cmd_operate_specific_port_parsed(void *parsed_result,
624                         __attribute__((unused)) struct cmdline *cl,
625                                 __attribute__((unused)) void *data)
626 {
627         struct cmd_operate_specific_port_result *res = parsed_result;
628
629         if (!strcmp(res->name, "start"))
630                 start_port(res->value);
631         else if (!strcmp(res->name, "stop"))
632                 stop_port(res->value);
633         else if (!strcmp(res->name, "close"))
634                 close_port(res->value);
635         else
636                 printf("Unknown parameter\n");
637 }
638
639 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
640         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
641                                                         keyword, "port");
642 cmdline_parse_token_string_t cmd_operate_specific_port_port =
643         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
644                                                 name, "start#stop#close");
645 cmdline_parse_token_num_t cmd_operate_specific_port_id =
646         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
647                                                         value, UINT8);
648
649 cmdline_parse_inst_t cmd_operate_specific_port = {
650         .f = cmd_operate_specific_port_parsed,
651         .data = NULL,
652         .help_str = "port start|stop|close X: start/stop/close port X",
653         .tokens = {
654                 (void *)&cmd_operate_specific_port_cmd,
655                 (void *)&cmd_operate_specific_port_port,
656                 (void *)&cmd_operate_specific_port_id,
657                 NULL,
658         },
659 };
660
661 /* *** configure speed for all ports *** */
662 struct cmd_config_speed_all {
663         cmdline_fixed_string_t port;
664         cmdline_fixed_string_t keyword;
665         cmdline_fixed_string_t all;
666         cmdline_fixed_string_t item1;
667         cmdline_fixed_string_t item2;
668         cmdline_fixed_string_t value1;
669         cmdline_fixed_string_t value2;
670 };
671
672 static void
673 cmd_config_speed_all_parsed(void *parsed_result,
674                         __attribute__((unused)) struct cmdline *cl,
675                         __attribute__((unused)) void *data)
676 {
677         struct cmd_config_speed_all *res = parsed_result;
678         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
679         uint16_t link_duplex = 0;
680         portid_t pid;
681
682         if (!all_ports_stopped()) {
683                 printf("Please stop all ports first\n");
684                 return;
685         }
686
687         if (!strcmp(res->value1, "10"))
688                 link_speed = ETH_LINK_SPEED_10;
689         else if (!strcmp(res->value1, "100"))
690                 link_speed = ETH_LINK_SPEED_100;
691         else if (!strcmp(res->value1, "1000"))
692                 link_speed = ETH_LINK_SPEED_1000;
693         else if (!strcmp(res->value1, "10000"))
694                 link_speed = ETH_LINK_SPEED_10000;
695         else if (!strcmp(res->value1, "auto"))
696                 link_speed = ETH_LINK_SPEED_AUTONEG;
697         else {
698                 printf("Unknown parameter\n");
699                 return;
700         }
701
702         if (!strcmp(res->value2, "half"))
703                 link_duplex = ETH_LINK_HALF_DUPLEX;
704         else if (!strcmp(res->value2, "full"))
705                 link_duplex = ETH_LINK_FULL_DUPLEX;
706         else if (!strcmp(res->value2, "auto"))
707                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
708         else {
709                 printf("Unknown parameter\n");
710                 return;
711         }
712
713         for (pid = 0; pid < nb_ports; pid++) {
714                 ports[pid].dev_conf.link_speed = link_speed;
715                 ports[pid].dev_conf.link_duplex = link_duplex;
716         }
717
718         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
719 }
720
721 cmdline_parse_token_string_t cmd_config_speed_all_port =
722         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
723 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
724         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
725                                                         "config");
726 cmdline_parse_token_string_t cmd_config_speed_all_all =
727         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
728 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
730 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
732                                                 "10#100#1000#10000#auto");
733 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
734         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
735 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
736         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
737                                                 "half#full#auto");
738
739 cmdline_parse_inst_t cmd_config_speed_all = {
740         .f = cmd_config_speed_all_parsed,
741         .data = NULL,
742         .help_str = "port config all speed 10|100|1000|10000|auto duplex "
743                                                         "half|full|auto",
744         .tokens = {
745                 (void *)&cmd_config_speed_all_port,
746                 (void *)&cmd_config_speed_all_keyword,
747                 (void *)&cmd_config_speed_all_all,
748                 (void *)&cmd_config_speed_all_item1,
749                 (void *)&cmd_config_speed_all_value1,
750                 (void *)&cmd_config_speed_all_item2,
751                 (void *)&cmd_config_speed_all_value2,
752                 NULL,
753         },
754 };
755
756 /* *** configure speed for specific port *** */
757 struct cmd_config_speed_specific {
758         cmdline_fixed_string_t port;
759         cmdline_fixed_string_t keyword;
760         uint8_t id;
761         cmdline_fixed_string_t item1;
762         cmdline_fixed_string_t item2;
763         cmdline_fixed_string_t value1;
764         cmdline_fixed_string_t value2;
765 };
766
767 static void
768 cmd_config_speed_specific_parsed(void *parsed_result,
769                                 __attribute__((unused)) struct cmdline *cl,
770                                 __attribute__((unused)) void *data)
771 {
772         struct cmd_config_speed_specific *res = parsed_result;
773         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
774         uint16_t link_duplex = 0;
775
776         if (!all_ports_stopped()) {
777                 printf("Please stop all ports first\n");
778                 return;
779         }
780
781         if (res->id >= nb_ports) {
782                 printf("Port id %d must be less than %d\n", res->id, nb_ports);
783                 return;
784         }
785
786         if (!strcmp(res->value1, "10"))
787                 link_speed = ETH_LINK_SPEED_10;
788         else if (!strcmp(res->value1, "100"))
789                 link_speed = ETH_LINK_SPEED_100;
790         else if (!strcmp(res->value1, "1000"))
791                 link_speed = ETH_LINK_SPEED_1000;
792         else if (!strcmp(res->value1, "10000"))
793                 link_speed = ETH_LINK_SPEED_10000;
794         else if (!strcmp(res->value1, "auto"))
795                 link_speed = ETH_LINK_SPEED_AUTONEG;
796         else {
797                 printf("Unknown parameter\n");
798                 return;
799         }
800
801         if (!strcmp(res->value2, "half"))
802                 link_duplex = ETH_LINK_HALF_DUPLEX;
803         else if (!strcmp(res->value2, "full"))
804                 link_duplex = ETH_LINK_FULL_DUPLEX;
805         else if (!strcmp(res->value2, "auto"))
806                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
807         else {
808                 printf("Unknown parameter\n");
809                 return;
810         }
811
812         ports[res->id].dev_conf.link_speed = link_speed;
813         ports[res->id].dev_conf.link_duplex = link_duplex;
814
815         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
816 }
817
818
819 cmdline_parse_token_string_t cmd_config_speed_specific_port =
820         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
821                                                                 "port");
822 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
823         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
824                                                                 "config");
825 cmdline_parse_token_num_t cmd_config_speed_specific_id =
826         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
827 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
828         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
829                                                                 "speed");
830 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
831         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
832                                                 "10#100#1000#10000#auto");
833 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
834         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
835                                                                 "duplex");
836 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
837         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
838                                                         "half#full#auto");
839
840 cmdline_parse_inst_t cmd_config_speed_specific = {
841         .f = cmd_config_speed_specific_parsed,
842         .data = NULL,
843         .help_str = "port config X speed 10|100|1000|10000|auto duplex "
844                                                         "half|full|auto",
845         .tokens = {
846                 (void *)&cmd_config_speed_specific_port,
847                 (void *)&cmd_config_speed_specific_keyword,
848                 (void *)&cmd_config_speed_specific_id,
849                 (void *)&cmd_config_speed_specific_item1,
850                 (void *)&cmd_config_speed_specific_value1,
851                 (void *)&cmd_config_speed_specific_item2,
852                 (void *)&cmd_config_speed_specific_value2,
853                 NULL,
854         },
855 };
856
857 /* *** configure txq/rxq, txd/rxd *** */
858 struct cmd_config_rx_tx {
859         cmdline_fixed_string_t port;
860         cmdline_fixed_string_t keyword;
861         cmdline_fixed_string_t all;
862         cmdline_fixed_string_t name;
863         uint16_t value;
864 };
865
866 static void
867 cmd_config_rx_tx_parsed(void *parsed_result,
868                         __attribute__((unused)) struct cmdline *cl,
869                         __attribute__((unused)) void *data)
870 {
871         struct cmd_config_rx_tx *res = parsed_result;
872
873         if (!all_ports_stopped()) {
874                 printf("Please stop all ports first\n");
875                 return;
876         }
877
878         if (!strcmp(res->name, "rxq")) {
879                 if (res->value <= 0) {
880                         printf("rxq %d invalid - must be > 0\n", res->value);
881                         return;
882                 }
883                 nb_rxq = res->value;
884         }
885         else if (!strcmp(res->name, "txq")) {
886                 if (res->value <= 0) {
887                         printf("txq %d invalid - must be > 0\n", res->value);
888                         return;
889                 }
890                 nb_txq = res->value;
891         }
892         else if (!strcmp(res->name, "rxd")) {
893                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
894                         printf("rxd %d invalid - must be > 0 && <= %d\n",
895                                         res->value, RTE_TEST_RX_DESC_MAX);
896                         return;
897                 }
898                 nb_rxd = res->value;
899         } else if (!strcmp(res->name, "txd")) {
900                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
901                         printf("txd %d invalid - must be > 0 && <= %d\n",
902                                         res->value, RTE_TEST_TX_DESC_MAX);
903                         return;
904                 }
905                 nb_txd = res->value;
906         } else {
907                 printf("Unknown parameter\n");
908                 return;
909         }
910
911         init_port_config();
912
913         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
914 }
915
916 cmdline_parse_token_string_t cmd_config_rx_tx_port =
917         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
918 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
919         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
920 cmdline_parse_token_string_t cmd_config_rx_tx_all =
921         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
922 cmdline_parse_token_string_t cmd_config_rx_tx_name =
923         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
924                                                 "rxq#txq#rxd#txd");
925 cmdline_parse_token_num_t cmd_config_rx_tx_value =
926         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
927
928 cmdline_parse_inst_t cmd_config_rx_tx = {
929         .f = cmd_config_rx_tx_parsed,
930         .data = NULL,
931         .help_str = "port config all rxq|txq|rxd|txd value",
932         .tokens = {
933                 (void *)&cmd_config_rx_tx_port,
934                 (void *)&cmd_config_rx_tx_keyword,
935                 (void *)&cmd_config_rx_tx_all,
936                 (void *)&cmd_config_rx_tx_name,
937                 (void *)&cmd_config_rx_tx_value,
938                 NULL,
939         },
940 };
941
942 /* *** config max packet length *** */
943 struct cmd_config_max_pkt_len_result {
944         cmdline_fixed_string_t port;
945         cmdline_fixed_string_t keyword;
946         cmdline_fixed_string_t all;
947         cmdline_fixed_string_t name;
948         uint32_t value;
949 };
950
951 static void
952 cmd_config_max_pkt_len_parsed(void *parsed_result,
953                                 __attribute__((unused)) struct cmdline *cl,
954                                 __attribute__((unused)) void *data)
955 {
956         struct cmd_config_max_pkt_len_result *res = parsed_result;
957
958         if (!all_ports_stopped()) {
959                 printf("Please stop all ports first\n");
960                 return;
961         }
962
963         if (!strcmp(res->name, "max-pkt-len")) {
964                 if (res->value < ETHER_MIN_LEN) {
965                         printf("max-pkt-len can not be less than %d\n",
966                                                         ETHER_MIN_LEN);
967                         return;
968                 }
969                 if (res->value == rx_mode.max_rx_pkt_len)
970                         return;
971
972                 rx_mode.max_rx_pkt_len = res->value;
973                 if (res->value > ETHER_MAX_LEN)
974                         rx_mode.jumbo_frame = 1;
975                 else
976                         rx_mode.jumbo_frame = 0;
977         } else {
978                 printf("Unknown parameter\n");
979                 return;
980         }
981
982         init_port_config();
983
984         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
985 }
986
987 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
988         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
989                                                                 "port");
990 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
991         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
992                                                                 "config");
993 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
994         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
995                                                                 "all");
996 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
997         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
998                                                                 "max-pkt-len");
999 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1000         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1001                                                                 UINT32);
1002
1003 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1004         .f = cmd_config_max_pkt_len_parsed,
1005         .data = NULL,
1006         .help_str = "port config all max-pkt-len value",
1007         .tokens = {
1008                 (void *)&cmd_config_max_pkt_len_port,
1009                 (void *)&cmd_config_max_pkt_len_keyword,
1010                 (void *)&cmd_config_max_pkt_len_all,
1011                 (void *)&cmd_config_max_pkt_len_name,
1012                 (void *)&cmd_config_max_pkt_len_value,
1013                 NULL,
1014         },
1015 };
1016
1017 /* *** configure rx mode *** */
1018 struct cmd_config_rx_mode_flag {
1019         cmdline_fixed_string_t port;
1020         cmdline_fixed_string_t keyword;
1021         cmdline_fixed_string_t all;
1022         cmdline_fixed_string_t name;
1023         cmdline_fixed_string_t value;
1024 };
1025
1026 static void
1027 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1028                                 __attribute__((unused)) struct cmdline *cl,
1029                                 __attribute__((unused)) void *data)
1030 {
1031         struct cmd_config_rx_mode_flag *res = parsed_result;
1032
1033         if (!all_ports_stopped()) {
1034                 printf("Please stop all ports first\n");
1035                 return;
1036         }
1037
1038         if (!strcmp(res->name, "crc-strip")) {
1039                 if (!strcmp(res->value, "on"))
1040                         rx_mode.hw_strip_crc = 1;
1041                 else if (!strcmp(res->value, "off"))
1042                         rx_mode.hw_strip_crc = 0;
1043                 else {
1044                         printf("Unknown parameter\n");
1045                         return;
1046                 }
1047         } else if (!strcmp(res->name, "rx-cksum")) {
1048                 if (!strcmp(res->value, "on"))
1049                         rx_mode.hw_ip_checksum = 1;
1050                 else if (!strcmp(res->value, "off"))
1051                         rx_mode.hw_ip_checksum = 0;
1052                 else {
1053                         printf("Unknown parameter\n");
1054                         return;
1055                 }
1056         } else if (!strcmp(res->name, "hw-vlan")) {
1057                 if (!strcmp(res->value, "on")) {
1058                         rx_mode.hw_vlan_filter = 1;
1059                         rx_mode.hw_vlan_strip  = 1;
1060                 }
1061                 else if (!strcmp(res->value, "off")) {
1062                         rx_mode.hw_vlan_filter = 0;
1063                         rx_mode.hw_vlan_strip  = 0;
1064                 }
1065                 else {
1066                         printf("Unknown parameter\n");
1067                         return;
1068                 }
1069         } else if (!strcmp(res->name, "drop-en")) {
1070                 if (!strcmp(res->value, "on"))
1071                         rx_drop_en = 1;
1072                 else if (!strcmp(res->value, "off"))
1073                         rx_drop_en = 0;
1074                 else {
1075                         printf("Unknown parameter\n");
1076                         return;
1077                 }
1078         } else {
1079                 printf("Unknown parameter\n");
1080                 return;
1081         }
1082
1083         init_port_config();
1084
1085         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1086 }
1087
1088 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1089         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1090 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1091         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1092                                                                 "config");
1093 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1094         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1095 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1096         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1097                                         "crc-strip#rx-cksum#hw-vlan");
1098 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1099         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1100                                                         "on#off");
1101
1102 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1103         .f = cmd_config_rx_mode_flag_parsed,
1104         .data = NULL,
1105         .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off",
1106         .tokens = {
1107                 (void *)&cmd_config_rx_mode_flag_port,
1108                 (void *)&cmd_config_rx_mode_flag_keyword,
1109                 (void *)&cmd_config_rx_mode_flag_all,
1110                 (void *)&cmd_config_rx_mode_flag_name,
1111                 (void *)&cmd_config_rx_mode_flag_value,
1112                 NULL,
1113         },
1114 };
1115
1116 /* *** configure rss *** */
1117 struct cmd_config_rss {
1118         cmdline_fixed_string_t port;
1119         cmdline_fixed_string_t keyword;
1120         cmdline_fixed_string_t all;
1121         cmdline_fixed_string_t name;
1122         cmdline_fixed_string_t value;
1123 };
1124
1125 static void
1126 cmd_config_rss_parsed(void *parsed_result,
1127                         __attribute__((unused)) struct cmdline *cl,
1128                         __attribute__((unused)) void *data)
1129 {
1130         struct cmd_config_rss *res = parsed_result;
1131         struct rte_eth_rss_conf rss_conf;
1132         uint8_t i;
1133
1134         if (!strcmp(res->value, "ip"))
1135                 rss_conf.rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
1136         else if (!strcmp(res->value, "udp"))
1137                 rss_conf.rss_hf = ETH_RSS_IPV4_UDP | ETH_RSS_IPV6_UDP;
1138         else if (!strcmp(res->value, "none"))
1139                 rss_conf.rss_hf = 0;
1140         else {
1141                 printf("Unknown parameter\n");
1142                 return;
1143         }
1144         rss_conf.rss_key = NULL;
1145         for (i = 0; i < rte_eth_dev_count(); i++)
1146                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1147 }
1148
1149 cmdline_parse_token_string_t cmd_config_rss_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1151 cmdline_parse_token_string_t cmd_config_rss_keyword =
1152         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1153 cmdline_parse_token_string_t cmd_config_rss_all =
1154         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1155 cmdline_parse_token_string_t cmd_config_rss_name =
1156         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1157 cmdline_parse_token_string_t cmd_config_rss_value =
1158         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none");
1159
1160 cmdline_parse_inst_t cmd_config_rss = {
1161         .f = cmd_config_rss_parsed,
1162         .data = NULL,
1163         .help_str = "port config all rss ip|udp|none",
1164         .tokens = {
1165                 (void *)&cmd_config_rss_port,
1166                 (void *)&cmd_config_rss_keyword,
1167                 (void *)&cmd_config_rss_all,
1168                 (void *)&cmd_config_rss_name,
1169                 (void *)&cmd_config_rss_value,
1170                 NULL,
1171         },
1172 };
1173
1174 /* *** configure rss hash key *** */
1175 struct cmd_config_rss_hash_key {
1176         cmdline_fixed_string_t port;
1177         cmdline_fixed_string_t config;
1178         uint8_t port_id;
1179         cmdline_fixed_string_t rss_hash_key;
1180         cmdline_fixed_string_t key;
1181 };
1182
1183 #define RSS_HASH_KEY_LENGTH 40
1184 static uint8_t
1185 hexa_digit_to_value(char hexa_digit)
1186 {
1187         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1188                 return (uint8_t) (hexa_digit - '0');
1189         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1190                 return (uint8_t) ((hexa_digit - 'a') + 10);
1191         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1192                 return (uint8_t) ((hexa_digit - 'A') + 10);
1193         /* Invalid hexa digit */
1194         return 0xFF;
1195 }
1196
1197 static uint8_t
1198 parse_and_check_key_hexa_digit(char *key, int idx)
1199 {
1200         uint8_t hexa_v;
1201
1202         hexa_v = hexa_digit_to_value(key[idx]);
1203         if (hexa_v == 0xFF)
1204                 printf("invalid key: character %c at position %d is not a "
1205                        "valid hexa digit\n", key[idx], idx);
1206         return hexa_v;
1207 }
1208
1209 static void
1210 cmd_config_rss_hash_key_parsed(void *parsed_result,
1211                                __attribute__((unused)) struct cmdline *cl,
1212                                __attribute__((unused)) void *data)
1213 {
1214         struct cmd_config_rss_hash_key *res = parsed_result;
1215         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1216         uint8_t xdgt0;
1217         uint8_t xdgt1;
1218         int i;
1219
1220         /* Check the length of the RSS hash key */
1221         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1222                 printf("key length: %d invalid - key must be a string of %d"
1223                        "hexa-decimal numbers\n", (int) strlen(res->key),
1224                        RSS_HASH_KEY_LENGTH * 2);
1225                 return;
1226         }
1227         /* Translate RSS hash key into binary representation */
1228         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1229                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1230                 if (xdgt0 == 0xFF)
1231                         return;
1232                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1233                 if (xdgt1 == 0xFF)
1234                         return;
1235                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1236         }
1237         port_rss_hash_key_update(res->port_id, hash_key);
1238 }
1239
1240 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1241         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1242 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1243         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1244                                  "config");
1245 cmdline_parse_token_string_t cmd_config_rss_hash_key_port_id =
1246         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1247 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1249                                  rss_hash_key, "rss-hash-key");
1250 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1251         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1252
1253 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1254         .f = cmd_config_rss_hash_key_parsed,
1255         .data = NULL,
1256         .help_str = "port config X rss-hash-key 80 hexa digits",
1257         .tokens = {
1258                 (void *)&cmd_config_rss_hash_key_port,
1259                 (void *)&cmd_config_rss_hash_key_config,
1260                 (void *)&cmd_config_rss_hash_key_port_id,
1261                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1262                 (void *)&cmd_config_rss_hash_key_value,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** Configure RSS RETA *** */
1268 struct cmd_config_rss_reta {
1269         cmdline_fixed_string_t port;
1270         cmdline_fixed_string_t keyword;
1271         uint8_t port_id;
1272         cmdline_fixed_string_t name;
1273         cmdline_fixed_string_t list_name;
1274         cmdline_fixed_string_t list_of_items;
1275 };
1276
1277 static int
1278 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
1279 {
1280         int i;
1281         unsigned size;
1282         uint8_t hash_index;
1283         uint8_t nb_queue;
1284         char s[256];
1285         const char *p, *p0 = str;
1286         char *end;
1287         enum fieldnames {
1288                 FLD_HASH_INDEX = 0,
1289                 FLD_QUEUE,
1290                 _NUM_FLD
1291         };
1292         unsigned long int_fld[_NUM_FLD];
1293         char *str_fld[_NUM_FLD];
1294
1295         while ((p = strchr(p0,'(')) != NULL) {
1296                 ++p;
1297                 if((p0 = strchr(p,')')) == NULL)
1298                         return -1;
1299
1300                 size = p0 - p;
1301                 if(size >= sizeof(s))
1302                         return -1;
1303
1304                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
1305                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1306                         return -1;
1307                 for (i = 0; i < _NUM_FLD; i++) {
1308                         errno = 0;
1309                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1310                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1311                                 return -1;
1312                 }
1313
1314                 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX];
1315                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1316
1317                 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) {
1318                         printf("Invalid RETA hash index=%d",hash_index);
1319                         return -1;
1320                 }
1321
1322                 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2)
1323                         reta_conf->mask_lo |= (1ULL << hash_index);
1324                 else
1325                         reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2));
1326
1327                 reta_conf->reta[hash_index] = nb_queue;
1328         }
1329
1330         return 0;
1331 }
1332
1333 static void
1334 cmd_set_rss_reta_parsed(void *parsed_result,
1335                                 __attribute__((unused)) struct cmdline *cl,
1336                                 __attribute__((unused)) void *data)
1337 {
1338         int ret;
1339         struct rte_eth_rss_reta reta_conf;
1340         struct cmd_config_rss_reta *res = parsed_result;
1341
1342         memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta));
1343         if (!strcmp(res->list_name, "reta")) {
1344                 if (parse_reta_config(res->list_of_items, &reta_conf)) {
1345                         printf("Invalid RSS Redirection Table config entered\n");
1346                         return;
1347                 }
1348                 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf);
1349                 if (ret != 0)
1350                         printf("Bad redirection table parameter, return code = %d \n",ret);
1351         }
1352 }
1353
1354 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1355         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1356 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1357         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1358 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1359         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1360 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1361         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1362 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1363         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1364 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1365         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1366                                  NULL);
1367 cmdline_parse_inst_t cmd_config_rss_reta = {
1368         .f = cmd_set_rss_reta_parsed,
1369         .data = NULL,
1370         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1371         .tokens = {
1372                 (void *)&cmd_config_rss_reta_port,
1373                 (void *)&cmd_config_rss_reta_keyword,
1374                 (void *)&cmd_config_rss_reta_port_id,
1375                 (void *)&cmd_config_rss_reta_name,
1376                 (void *)&cmd_config_rss_reta_list_name,
1377                 (void *)&cmd_config_rss_reta_list_of_items,
1378                 NULL,
1379         },
1380 };
1381
1382 /* *** SHOW PORT RETA INFO *** */
1383 struct cmd_showport_reta {
1384         cmdline_fixed_string_t show;
1385         cmdline_fixed_string_t port;
1386         uint8_t port_id;
1387         cmdline_fixed_string_t rss;
1388         cmdline_fixed_string_t reta;
1389         uint64_t mask_lo;
1390         uint64_t mask_hi;
1391 };
1392
1393 static void cmd_showport_reta_parsed(void *parsed_result,
1394                                 __attribute__((unused)) struct cmdline *cl,
1395                                 __attribute__((unused)) void *data)
1396 {
1397         struct cmd_showport_reta *res = parsed_result;
1398         struct rte_eth_rss_reta reta_conf;
1399
1400         if ((res->mask_lo == 0) && (res->mask_hi == 0)) {
1401                 printf("Invalid RSS Redirection Table config entered\n");
1402                 return;
1403         }
1404
1405         reta_conf.mask_lo = res->mask_lo;
1406         reta_conf.mask_hi = res->mask_hi;
1407
1408         port_rss_reta_info(res->port_id,&reta_conf);
1409 }
1410
1411 cmdline_parse_token_string_t cmd_showport_reta_show =
1412         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1413 cmdline_parse_token_string_t cmd_showport_reta_port =
1414         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1415 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1416         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1417 cmdline_parse_token_string_t cmd_showport_reta_rss =
1418         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1419 cmdline_parse_token_string_t cmd_showport_reta_reta =
1420         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1421 cmdline_parse_token_num_t cmd_showport_reta_mask_lo =
1422         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64);
1423 cmdline_parse_token_num_t cmd_showport_reta_mask_hi =
1424         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64);
1425
1426 cmdline_parse_inst_t cmd_showport_reta = {
1427         .f = cmd_showport_reta_parsed,
1428         .data = NULL,
1429         .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\
1430                         (mask_lo and mask_hi is UINT64)",
1431         .tokens = {
1432                 (void *)&cmd_showport_reta_show,
1433                 (void *)&cmd_showport_reta_port,
1434                 (void *)&cmd_showport_reta_port_id,
1435                 (void *)&cmd_showport_reta_rss,
1436                 (void *)&cmd_showport_reta_reta,
1437                 (void *)&cmd_showport_reta_mask_lo,
1438                 (void *)&cmd_showport_reta_mask_hi,
1439                 NULL,
1440         },
1441 };
1442
1443 /* *** Show RSS hash configuration *** */
1444 struct cmd_showport_rss_hash {
1445         cmdline_fixed_string_t show;
1446         cmdline_fixed_string_t port;
1447         uint8_t port_id;
1448         cmdline_fixed_string_t rss_hash;
1449         cmdline_fixed_string_t key; /* optional argument */
1450 };
1451
1452 static void cmd_showport_rss_hash_parsed(void *parsed_result,
1453                                 __attribute__((unused)) struct cmdline *cl,
1454                                 void *show_rss_key)
1455 {
1456         struct cmd_showport_rss_hash *res = parsed_result;
1457
1458         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
1459 }
1460
1461 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
1462         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
1463 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
1464         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
1465 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
1466         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
1467 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
1468         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
1469                                  "rss-hash");
1470 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
1471         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
1472
1473 cmdline_parse_inst_t cmd_showport_rss_hash = {
1474         .f = cmd_showport_rss_hash_parsed,
1475         .data = NULL,
1476         .help_str = "show port X rss-hash (X = port number)\n",
1477         .tokens = {
1478                 (void *)&cmd_showport_rss_hash_show,
1479                 (void *)&cmd_showport_rss_hash_port,
1480                 (void *)&cmd_showport_rss_hash_port_id,
1481                 (void *)&cmd_showport_rss_hash_rss_hash,
1482                 NULL,
1483         },
1484 };
1485
1486 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
1487         .f = cmd_showport_rss_hash_parsed,
1488         .data = (void *)1,
1489         .help_str = "show port X rss-hash key (X = port number)\n",
1490         .tokens = {
1491                 (void *)&cmd_showport_rss_hash_show,
1492                 (void *)&cmd_showport_rss_hash_port,
1493                 (void *)&cmd_showport_rss_hash_port_id,
1494                 (void *)&cmd_showport_rss_hash_rss_hash,
1495                 (void *)&cmd_showport_rss_hash_rss_key,
1496                 NULL,
1497         },
1498 };
1499
1500 /* *** Configure DCB *** */
1501 struct cmd_config_dcb {
1502         cmdline_fixed_string_t port;
1503         cmdline_fixed_string_t config;
1504         uint8_t port_id;
1505         cmdline_fixed_string_t dcb;
1506         cmdline_fixed_string_t vt;
1507         cmdline_fixed_string_t vt_en;
1508         uint8_t num_tcs;
1509         cmdline_fixed_string_t pfc;
1510         cmdline_fixed_string_t pfc_en;
1511 };
1512
1513 static void
1514 cmd_config_dcb_parsed(void *parsed_result,
1515                         __attribute__((unused)) struct cmdline *cl,
1516                         __attribute__((unused)) void *data)
1517 {
1518         struct cmd_config_dcb *res = parsed_result;
1519         struct dcb_config dcb_conf;
1520         portid_t port_id = res->port_id;
1521         struct rte_port *port;
1522
1523         port = &ports[port_id];
1524         /** Check if the port is not started **/
1525         if (port->port_status != RTE_PORT_STOPPED) {
1526                 printf("Please stop port %d first\n",port_id);
1527                 return;
1528         }
1529
1530         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
1531         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
1532                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
1533                 return;
1534         }
1535
1536         /* DCB in VT mode */
1537         if (!strncmp(res->vt_en, "on",2))
1538                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
1539         else
1540                 dcb_conf.dcb_mode = DCB_ENABLED;
1541
1542         if (!strncmp(res->pfc_en, "on",2)) {
1543                 dcb_conf.pfc_en = 1;
1544         }
1545         else
1546                 dcb_conf.pfc_en = 0;
1547
1548         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
1549                 printf("Cannot initialize network ports\n");
1550                 return;
1551         }
1552
1553         cmd_reconfig_device_queue(port_id, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_dcb_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
1558 cmdline_parse_token_string_t cmd_config_dcb_config =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
1560 cmdline_parse_token_num_t cmd_config_dcb_port_id =
1561         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
1562 cmdline_parse_token_string_t cmd_config_dcb_dcb =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
1564 cmdline_parse_token_string_t cmd_config_dcb_vt =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
1566 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
1568 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
1569         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
1570 cmdline_parse_token_string_t cmd_config_dcb_pfc=
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
1572 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
1573         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
1574
1575 cmdline_parse_inst_t cmd_config_dcb = {
1576         .f = cmd_config_dcb_parsed,
1577         .data = NULL,
1578         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
1579         .tokens = {
1580                 (void *)&cmd_config_dcb_port,
1581                 (void *)&cmd_config_dcb_config,
1582                 (void *)&cmd_config_dcb_port_id,
1583                 (void *)&cmd_config_dcb_dcb,
1584                 (void *)&cmd_config_dcb_vt,
1585                 (void *)&cmd_config_dcb_vt_en,
1586                 (void *)&cmd_config_dcb_num_tcs,
1587                 (void *)&cmd_config_dcb_pfc,
1588                 (void *)&cmd_config_dcb_pfc_en,
1589                 NULL,
1590         },
1591 };
1592
1593 /* *** configure number of packets per burst *** */
1594 struct cmd_config_burst {
1595         cmdline_fixed_string_t port;
1596         cmdline_fixed_string_t keyword;
1597         cmdline_fixed_string_t all;
1598         cmdline_fixed_string_t name;
1599         uint16_t value;
1600 };
1601
1602 static void
1603 cmd_config_burst_parsed(void *parsed_result,
1604                         __attribute__((unused)) struct cmdline *cl,
1605                         __attribute__((unused)) void *data)
1606 {
1607         struct cmd_config_burst *res = parsed_result;
1608
1609         if (!all_ports_stopped()) {
1610                 printf("Please stop all ports first\n");
1611                 return;
1612         }
1613
1614         if (!strcmp(res->name, "burst")) {
1615                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
1616                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
1617                         return;
1618                 }
1619                 nb_pkt_per_burst = res->value;
1620         } else {
1621                 printf("Unknown parameter\n");
1622                 return;
1623         }
1624
1625         init_port_config();
1626
1627         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1628 }
1629
1630 cmdline_parse_token_string_t cmd_config_burst_port =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
1632 cmdline_parse_token_string_t cmd_config_burst_keyword =
1633         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
1634 cmdline_parse_token_string_t cmd_config_burst_all =
1635         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
1636 cmdline_parse_token_string_t cmd_config_burst_name =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
1638 cmdline_parse_token_num_t cmd_config_burst_value =
1639         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
1640
1641 cmdline_parse_inst_t cmd_config_burst = {
1642         .f = cmd_config_burst_parsed,
1643         .data = NULL,
1644         .help_str = "port config all burst value",
1645         .tokens = {
1646                 (void *)&cmd_config_burst_port,
1647                 (void *)&cmd_config_burst_keyword,
1648                 (void *)&cmd_config_burst_all,
1649                 (void *)&cmd_config_burst_name,
1650                 (void *)&cmd_config_burst_value,
1651                 NULL,
1652         },
1653 };
1654
1655 /* *** configure rx/tx queues *** */
1656 struct cmd_config_thresh {
1657         cmdline_fixed_string_t port;
1658         cmdline_fixed_string_t keyword;
1659         cmdline_fixed_string_t all;
1660         cmdline_fixed_string_t name;
1661         uint8_t value;
1662 };
1663
1664 static void
1665 cmd_config_thresh_parsed(void *parsed_result,
1666                         __attribute__((unused)) struct cmdline *cl,
1667                         __attribute__((unused)) void *data)
1668 {
1669         struct cmd_config_thresh *res = parsed_result;
1670
1671         if (!all_ports_stopped()) {
1672                 printf("Please stop all ports first\n");
1673                 return;
1674         }
1675
1676         if (!strcmp(res->name, "txpt"))
1677                 tx_thresh.pthresh = res->value;
1678         else if(!strcmp(res->name, "txht"))
1679                 tx_thresh.hthresh = res->value;
1680         else if(!strcmp(res->name, "txwt"))
1681                 tx_thresh.wthresh = res->value;
1682         else if(!strcmp(res->name, "rxpt"))
1683                 rx_thresh.pthresh = res->value;
1684         else if(!strcmp(res->name, "rxht"))
1685                 rx_thresh.hthresh = res->value;
1686         else if(!strcmp(res->name, "rxwt"))
1687                 rx_thresh.wthresh = res->value;
1688         else {
1689                 printf("Unknown parameter\n");
1690                 return;
1691         }
1692
1693         init_port_config();
1694
1695         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1696 }
1697
1698 cmdline_parse_token_string_t cmd_config_thresh_port =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
1700 cmdline_parse_token_string_t cmd_config_thresh_keyword =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
1702 cmdline_parse_token_string_t cmd_config_thresh_all =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
1704 cmdline_parse_token_string_t cmd_config_thresh_name =
1705         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
1706                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
1707 cmdline_parse_token_num_t cmd_config_thresh_value =
1708         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
1709
1710 cmdline_parse_inst_t cmd_config_thresh = {
1711         .f = cmd_config_thresh_parsed,
1712         .data = NULL,
1713         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1714         .tokens = {
1715                 (void *)&cmd_config_thresh_port,
1716                 (void *)&cmd_config_thresh_keyword,
1717                 (void *)&cmd_config_thresh_all,
1718                 (void *)&cmd_config_thresh_name,
1719                 (void *)&cmd_config_thresh_value,
1720                 NULL,
1721         },
1722 };
1723
1724 /* *** configure free/rs threshold *** */
1725 struct cmd_config_threshold {
1726         cmdline_fixed_string_t port;
1727         cmdline_fixed_string_t keyword;
1728         cmdline_fixed_string_t all;
1729         cmdline_fixed_string_t name;
1730         uint16_t value;
1731 };
1732
1733 static void
1734 cmd_config_threshold_parsed(void *parsed_result,
1735                         __attribute__((unused)) struct cmdline *cl,
1736                         __attribute__((unused)) void *data)
1737 {
1738         struct cmd_config_threshold *res = parsed_result;
1739
1740         if (!all_ports_stopped()) {
1741                 printf("Please stop all ports first\n");
1742                 return;
1743         }
1744
1745         if (!strcmp(res->name, "txfreet"))
1746                 tx_free_thresh = res->value;
1747         else if (!strcmp(res->name, "txrst"))
1748                 tx_rs_thresh = res->value;
1749         else if (!strcmp(res->name, "rxfreet"))
1750                 rx_free_thresh = res->value;
1751         else {
1752                 printf("Unknown parameter\n");
1753                 return;
1754         }
1755
1756         init_port_config();
1757
1758         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1759 }
1760
1761 cmdline_parse_token_string_t cmd_config_threshold_port =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1763 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1765                                                                 "config");
1766 cmdline_parse_token_string_t cmd_config_threshold_all =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1768 cmdline_parse_token_string_t cmd_config_threshold_name =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1770                                                 "txfreet#txrst#rxfreet");
1771 cmdline_parse_token_num_t cmd_config_threshold_value =
1772         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1773
1774 cmdline_parse_inst_t cmd_config_threshold = {
1775         .f = cmd_config_threshold_parsed,
1776         .data = NULL,
1777         .help_str = "port config all txfreet|txrst|rxfreet value",
1778         .tokens = {
1779                 (void *)&cmd_config_threshold_port,
1780                 (void *)&cmd_config_threshold_keyword,
1781                 (void *)&cmd_config_threshold_all,
1782                 (void *)&cmd_config_threshold_name,
1783                 (void *)&cmd_config_threshold_value,
1784                 NULL,
1785         },
1786 };
1787
1788 /* *** stop *** */
1789 struct cmd_stop_result {
1790         cmdline_fixed_string_t stop;
1791 };
1792
1793 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1794                             __attribute__((unused)) struct cmdline *cl,
1795                             __attribute__((unused)) void *data)
1796 {
1797         stop_packet_forwarding();
1798 }
1799
1800 cmdline_parse_token_string_t cmd_stop_stop =
1801         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1802
1803 cmdline_parse_inst_t cmd_stop = {
1804         .f = cmd_stop_parsed,
1805         .data = NULL,
1806         .help_str = "stop - stop packet forwarding",
1807         .tokens = {
1808                 (void *)&cmd_stop_stop,
1809                 NULL,
1810         },
1811 };
1812
1813 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1814
1815 static unsigned int
1816 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1817                 unsigned int *parsed_items, int check_unique_values)
1818 {
1819         unsigned int nb_item;
1820         unsigned int value;
1821         unsigned int i;
1822         unsigned int j;
1823         int value_ok;
1824         char c;
1825
1826         /*
1827          * First parse all items in the list and store their value.
1828          */
1829         value = 0;
1830         nb_item = 0;
1831         value_ok = 0;
1832         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1833                 c = str[i];
1834                 if ((c >= '0') && (c <= '9')) {
1835                         value = (unsigned int) (value * 10 + (c - '0'));
1836                         value_ok = 1;
1837                         continue;
1838                 }
1839                 if (c != ',') {
1840                         printf("character %c is not a decimal digit\n", c);
1841                         return (0);
1842                 }
1843                 if (! value_ok) {
1844                         printf("No valid value before comma\n");
1845                         return (0);
1846                 }
1847                 if (nb_item < max_items) {
1848                         parsed_items[nb_item] = value;
1849                         value_ok = 0;
1850                         value = 0;
1851                 }
1852                 nb_item++;
1853         }
1854         if (nb_item >= max_items) {
1855                 printf("Number of %s = %u > %u (maximum items)\n",
1856                        item_name, nb_item + 1, max_items);
1857                 return (0);
1858         }
1859         parsed_items[nb_item++] = value;
1860         if (! check_unique_values)
1861                 return (nb_item);
1862
1863         /*
1864          * Then, check that all values in the list are differents.
1865          * No optimization here...
1866          */
1867         for (i = 0; i < nb_item; i++) {
1868                 for (j = i + 1; j < nb_item; j++) {
1869                         if (parsed_items[j] == parsed_items[i]) {
1870                                 printf("duplicated %s %u at index %u and %u\n",
1871                                        item_name, parsed_items[i], i, j);
1872                                 return (0);
1873                         }
1874                 }
1875         }
1876         return (nb_item);
1877 }
1878
1879 struct cmd_set_list_result {
1880         cmdline_fixed_string_t cmd_keyword;
1881         cmdline_fixed_string_t list_name;
1882         cmdline_fixed_string_t list_of_items;
1883 };
1884
1885 static void cmd_set_list_parsed(void *parsed_result,
1886                                 __attribute__((unused)) struct cmdline *cl,
1887                                 __attribute__((unused)) void *data)
1888 {
1889         struct cmd_set_list_result *res;
1890         union {
1891                 unsigned int lcorelist[RTE_MAX_LCORE];
1892                 unsigned int portlist[RTE_MAX_ETHPORTS];
1893         } parsed_items;
1894         unsigned int nb_item;
1895
1896         res = parsed_result;
1897         if (!strcmp(res->list_name, "corelist")) {
1898                 nb_item = parse_item_list(res->list_of_items, "core",
1899                                           RTE_MAX_LCORE,
1900                                           parsed_items.lcorelist, 1);
1901                 if (nb_item > 0)
1902                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
1903                 return;
1904         }
1905         if (!strcmp(res->list_name, "portlist")) {
1906                 nb_item = parse_item_list(res->list_of_items, "port",
1907                                           RTE_MAX_ETHPORTS,
1908                                           parsed_items.portlist, 1);
1909                 if (nb_item > 0)
1910                         set_fwd_ports_list(parsed_items.portlist, nb_item);
1911         }
1912 }
1913
1914 cmdline_parse_token_string_t cmd_set_list_keyword =
1915         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
1916                                  "set");
1917 cmdline_parse_token_string_t cmd_set_list_name =
1918         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
1919                                  "corelist#portlist");
1920 cmdline_parse_token_string_t cmd_set_list_of_items =
1921         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
1922                                  NULL);
1923
1924 cmdline_parse_inst_t cmd_set_fwd_list = {
1925         .f = cmd_set_list_parsed,
1926         .data = NULL,
1927         .help_str = "set corelist|portlist x[,y]*",
1928         .tokens = {
1929                 (void *)&cmd_set_list_keyword,
1930                 (void *)&cmd_set_list_name,
1931                 (void *)&cmd_set_list_of_items,
1932                 NULL,
1933         },
1934 };
1935
1936 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
1937
1938 struct cmd_setmask_result {
1939         cmdline_fixed_string_t set;
1940         cmdline_fixed_string_t mask;
1941         uint64_t hexavalue;
1942 };
1943
1944 static void cmd_set_mask_parsed(void *parsed_result,
1945                                 __attribute__((unused)) struct cmdline *cl,
1946                                 __attribute__((unused)) void *data)
1947 {
1948         struct cmd_setmask_result *res = parsed_result;
1949
1950         if (!strcmp(res->mask, "coremask"))
1951                 set_fwd_lcores_mask(res->hexavalue);
1952         else if (!strcmp(res->mask, "portmask"))
1953                 set_fwd_ports_mask(res->hexavalue);
1954 }
1955
1956 cmdline_parse_token_string_t cmd_setmask_set =
1957         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
1958 cmdline_parse_token_string_t cmd_setmask_mask =
1959         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
1960                                  "coremask#portmask");
1961 cmdline_parse_token_num_t cmd_setmask_value =
1962         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
1963
1964 cmdline_parse_inst_t cmd_set_fwd_mask = {
1965         .f = cmd_set_mask_parsed,
1966         .data = NULL,
1967         .help_str = "set coremask|portmask hexadecimal value",
1968         .tokens = {
1969                 (void *)&cmd_setmask_set,
1970                 (void *)&cmd_setmask_mask,
1971                 (void *)&cmd_setmask_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /*
1977  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
1978  */
1979 struct cmd_set_result {
1980         cmdline_fixed_string_t set;
1981         cmdline_fixed_string_t what;
1982         uint16_t value;
1983 };
1984
1985 static void cmd_set_parsed(void *parsed_result,
1986                            __attribute__((unused)) struct cmdline *cl,
1987                            __attribute__((unused)) void *data)
1988 {
1989         struct cmd_set_result *res = parsed_result;
1990         if (!strcmp(res->what, "nbport"))
1991                 set_fwd_ports_number(res->value);
1992         else if (!strcmp(res->what, "nbcore"))
1993                 set_fwd_lcores_number(res->value);
1994         else if (!strcmp(res->what, "burst"))
1995                 set_nb_pkt_per_burst(res->value);
1996         else if (!strcmp(res->what, "verbose"))
1997                 set_verbose_level(res->value);
1998 }
1999
2000 cmdline_parse_token_string_t cmd_set_set =
2001         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2002 cmdline_parse_token_string_t cmd_set_what =
2003         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2004                                  "nbport#nbcore#burst#verbose");
2005 cmdline_parse_token_num_t cmd_set_value =
2006         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2007
2008 cmdline_parse_inst_t cmd_set_numbers = {
2009         .f = cmd_set_parsed,
2010         .data = NULL,
2011         .help_str = "set nbport|nbcore|burst|verbose value",
2012         .tokens = {
2013                 (void *)&cmd_set_set,
2014                 (void *)&cmd_set_what,
2015                 (void *)&cmd_set_value,
2016                 NULL,
2017         },
2018 };
2019
2020 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2021
2022 struct cmd_set_txpkts_result {
2023         cmdline_fixed_string_t cmd_keyword;
2024         cmdline_fixed_string_t txpkts;
2025         cmdline_fixed_string_t seg_lengths;
2026 };
2027
2028 static void
2029 cmd_set_txpkts_parsed(void *parsed_result,
2030                       __attribute__((unused)) struct cmdline *cl,
2031                       __attribute__((unused)) void *data)
2032 {
2033         struct cmd_set_txpkts_result *res;
2034         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2035         unsigned int nb_segs;
2036
2037         res = parsed_result;
2038         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2039                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2040         if (nb_segs > 0)
2041                 set_tx_pkt_segments(seg_lengths, nb_segs);
2042 }
2043
2044 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2045         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2046                                  cmd_keyword, "set");
2047 cmdline_parse_token_string_t cmd_set_txpkts_name =
2048         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2049                                  txpkts, "txpkts");
2050 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2051         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2052                                  seg_lengths, NULL);
2053
2054 cmdline_parse_inst_t cmd_set_txpkts = {
2055         .f = cmd_set_txpkts_parsed,
2056         .data = NULL,
2057         .help_str = "set txpkts x[,y]*",
2058         .tokens = {
2059                 (void *)&cmd_set_txpkts_keyword,
2060                 (void *)&cmd_set_txpkts_name,
2061                 (void *)&cmd_set_txpkts_lengths,
2062                 NULL,
2063         },
2064 };
2065
2066 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2067 struct cmd_rx_vlan_filter_all_result {
2068         cmdline_fixed_string_t rx_vlan;
2069         cmdline_fixed_string_t what;
2070         cmdline_fixed_string_t all;
2071         uint8_t port_id;
2072 };
2073
2074 static void
2075 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2076                               __attribute__((unused)) struct cmdline *cl,
2077                               __attribute__((unused)) void *data)
2078 {
2079         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2080
2081         if (!strcmp(res->what, "add"))
2082                 rx_vlan_all_filter_set(res->port_id, 1);
2083         else
2084                 rx_vlan_all_filter_set(res->port_id, 0);
2085 }
2086
2087 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2088         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2089                                  rx_vlan, "rx_vlan");
2090 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2091         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2092                                  what, "add#rm");
2093 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2094         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2095                                  all, "all");
2096 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2097         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2098                               port_id, UINT8);
2099
2100 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2101         .f = cmd_rx_vlan_filter_all_parsed,
2102         .data = NULL,
2103         .help_str = "add/remove all identifiers to/from the set of VLAN "
2104         "Identifiers filtered by a port",
2105         .tokens = {
2106                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2107                 (void *)&cmd_rx_vlan_filter_all_what,
2108                 (void *)&cmd_rx_vlan_filter_all_all,
2109                 (void *)&cmd_rx_vlan_filter_all_portid,
2110                 NULL,
2111         },
2112 };
2113
2114 /* *** VLAN OFFLOAD SET ON A PORT *** */
2115 struct cmd_vlan_offload_result {
2116         cmdline_fixed_string_t vlan;
2117         cmdline_fixed_string_t set;
2118         cmdline_fixed_string_t what;
2119         cmdline_fixed_string_t on;
2120         cmdline_fixed_string_t port_id;
2121 };
2122
2123 static void
2124 cmd_vlan_offload_parsed(void *parsed_result,
2125                           __attribute__((unused)) struct cmdline *cl,
2126                           __attribute__((unused)) void *data)
2127 {
2128         int on;
2129         struct cmd_vlan_offload_result *res = parsed_result;
2130         char *str;
2131         int i, len = 0;
2132         portid_t port_id = 0;
2133         unsigned int tmp;
2134
2135         str = res->port_id;
2136         len = strnlen(str, STR_TOKEN_SIZE);
2137         i = 0;
2138         /* Get port_id first */
2139         while(i < len){
2140                 if(str[i] == ',')
2141                         break;
2142
2143                 i++;
2144         }
2145         str[i]='\0';
2146         tmp = strtoul(str, NULL, 0);
2147         /* If port_id greater that what portid_t can represent, return */
2148         if(tmp >= RTE_MAX_ETHPORTS)
2149                 return;
2150         port_id = (portid_t)tmp;
2151
2152         if (!strcmp(res->on, "on"))
2153                 on = 1;
2154         else
2155                 on = 0;
2156
2157         if (!strcmp(res->what, "strip"))
2158                 rx_vlan_strip_set(port_id,  on);
2159         else if(!strcmp(res->what, "stripq")){
2160                 uint16_t queue_id = 0;
2161
2162                 /* No queue_id, return */
2163                 if(i + 1 >= len) {
2164                         printf("must specify (port,queue_id)\n");
2165                         return;
2166                 }
2167                 tmp = strtoul(str + i + 1, NULL, 0);
2168                 /* If queue_id greater that what 16-bits can represent, return */
2169                 if(tmp > 0xffff)
2170                         return;
2171
2172                 queue_id = (uint16_t)tmp;
2173                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2174         }
2175         else if (!strcmp(res->what, "filter"))
2176                 rx_vlan_filter_set(port_id, on);
2177         else
2178                 vlan_extend_set(port_id, on);
2179
2180         return;
2181 }
2182
2183 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2184         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2185                                  vlan, "vlan");
2186 cmdline_parse_token_string_t cmd_vlan_offload_set =
2187         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2188                                  set, "set");
2189 cmdline_parse_token_string_t cmd_vlan_offload_what =
2190         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2191                                  what, "strip#filter#qinq#stripq");
2192 cmdline_parse_token_string_t cmd_vlan_offload_on =
2193         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2194                               on, "on#off");
2195 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2196         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2197                               port_id, NULL);
2198
2199 cmdline_parse_inst_t cmd_vlan_offload = {
2200         .f = cmd_vlan_offload_parsed,
2201         .data = NULL,
2202         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2203         " qinq(extended) for both rx/tx sides ",
2204         .tokens = {
2205                 (void *)&cmd_vlan_offload_vlan,
2206                 (void *)&cmd_vlan_offload_set,
2207                 (void *)&cmd_vlan_offload_what,
2208                 (void *)&cmd_vlan_offload_on,
2209                 (void *)&cmd_vlan_offload_portid,
2210                 NULL,
2211         },
2212 };
2213
2214 /* *** VLAN TPID SET ON A PORT *** */
2215 struct cmd_vlan_tpid_result {
2216         cmdline_fixed_string_t vlan;
2217         cmdline_fixed_string_t set;
2218         cmdline_fixed_string_t what;
2219         uint16_t tp_id;
2220         uint8_t port_id;
2221 };
2222
2223 static void
2224 cmd_vlan_tpid_parsed(void *parsed_result,
2225                           __attribute__((unused)) struct cmdline *cl,
2226                           __attribute__((unused)) void *data)
2227 {
2228         struct cmd_vlan_tpid_result *res = parsed_result;
2229         vlan_tpid_set(res->port_id, res->tp_id);
2230         return;
2231 }
2232
2233 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2234         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2235                                  vlan, "vlan");
2236 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2237         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2238                                  set, "set");
2239 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2241                                  what, "tpid");
2242 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2243         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2244                               tp_id, UINT16);
2245 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2246         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2247                               port_id, UINT8);
2248
2249 cmdline_parse_inst_t cmd_vlan_tpid = {
2250         .f = cmd_vlan_tpid_parsed,
2251         .data = NULL,
2252         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2253         .tokens = {
2254                 (void *)&cmd_vlan_tpid_vlan,
2255                 (void *)&cmd_vlan_tpid_set,
2256                 (void *)&cmd_vlan_tpid_what,
2257                 (void *)&cmd_vlan_tpid_tpid,
2258                 (void *)&cmd_vlan_tpid_portid,
2259                 NULL,
2260         },
2261 };
2262
2263 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2264 struct cmd_rx_vlan_filter_result {
2265         cmdline_fixed_string_t rx_vlan;
2266         cmdline_fixed_string_t what;
2267         uint16_t vlan_id;
2268         uint8_t port_id;
2269 };
2270
2271 static void
2272 cmd_rx_vlan_filter_parsed(void *parsed_result,
2273                           __attribute__((unused)) struct cmdline *cl,
2274                           __attribute__((unused)) void *data)
2275 {
2276         struct cmd_rx_vlan_filter_result *res = parsed_result;
2277
2278         if (!strcmp(res->what, "add"))
2279                 rx_vft_set(res->port_id, res->vlan_id, 1);
2280         else
2281                 rx_vft_set(res->port_id, res->vlan_id, 0);
2282 }
2283
2284 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2285         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2286                                  rx_vlan, "rx_vlan");
2287 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2288         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2289                                  what, "add#rm");
2290 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2291         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2292                               vlan_id, UINT16);
2293 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2294         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2295                               port_id, UINT8);
2296
2297 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2298         .f = cmd_rx_vlan_filter_parsed,
2299         .data = NULL,
2300         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2301         "Identifiers filtered by a port",
2302         .tokens = {
2303                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2304                 (void *)&cmd_rx_vlan_filter_what,
2305                 (void *)&cmd_rx_vlan_filter_vlanid,
2306                 (void *)&cmd_rx_vlan_filter_portid,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2312 struct cmd_tx_vlan_set_result {
2313         cmdline_fixed_string_t tx_vlan;
2314         cmdline_fixed_string_t set;
2315         uint16_t vlan_id;
2316         uint8_t port_id;
2317 };
2318
2319 static void
2320 cmd_tx_vlan_set_parsed(void *parsed_result,
2321                        __attribute__((unused)) struct cmdline *cl,
2322                        __attribute__((unused)) void *data)
2323 {
2324         struct cmd_tx_vlan_set_result *res = parsed_result;
2325         tx_vlan_set(res->port_id, res->vlan_id);
2326 }
2327
2328 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2329         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2330                                  tx_vlan, "tx_vlan");
2331 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2332         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2333                                  set, "set");
2334 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2335         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2336                               vlan_id, UINT16);
2337 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2338         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2339                               port_id, UINT8);
2340
2341 cmdline_parse_inst_t cmd_tx_vlan_set = {
2342         .f = cmd_tx_vlan_set_parsed,
2343         .data = NULL,
2344         .help_str = "enable hardware insertion of a VLAN header with a given "
2345         "TAG Identifier in packets sent on a port",
2346         .tokens = {
2347                 (void *)&cmd_tx_vlan_set_tx_vlan,
2348                 (void *)&cmd_tx_vlan_set_set,
2349                 (void *)&cmd_tx_vlan_set_vlanid,
2350                 (void *)&cmd_tx_vlan_set_portid,
2351                 NULL,
2352         },
2353 };
2354
2355 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2356 struct cmd_tx_vlan_reset_result {
2357         cmdline_fixed_string_t tx_vlan;
2358         cmdline_fixed_string_t reset;
2359         uint8_t port_id;
2360 };
2361
2362 static void
2363 cmd_tx_vlan_reset_parsed(void *parsed_result,
2364                          __attribute__((unused)) struct cmdline *cl,
2365                          __attribute__((unused)) void *data)
2366 {
2367         struct cmd_tx_vlan_reset_result *res = parsed_result;
2368
2369         tx_vlan_reset(res->port_id);
2370 }
2371
2372 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2373         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2374                                  tx_vlan, "tx_vlan");
2375 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2376         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2377                                  reset, "reset");
2378 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2379         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2380                               port_id, UINT8);
2381
2382 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2383         .f = cmd_tx_vlan_reset_parsed,
2384         .data = NULL,
2385         .help_str = "disable hardware insertion of a VLAN header in packets "
2386         "sent on a port",
2387         .tokens = {
2388                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2389                 (void *)&cmd_tx_vlan_reset_reset,
2390                 (void *)&cmd_tx_vlan_reset_portid,
2391                 NULL,
2392         },
2393 };
2394
2395
2396 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2397 struct cmd_tx_cksum_set_result {
2398         cmdline_fixed_string_t tx_cksum;
2399         cmdline_fixed_string_t set;
2400         uint8_t cksum_mask;
2401         uint8_t port_id;
2402 };
2403
2404 static void
2405 cmd_tx_cksum_set_parsed(void *parsed_result,
2406                        __attribute__((unused)) struct cmdline *cl,
2407                        __attribute__((unused)) void *data)
2408 {
2409         struct cmd_tx_cksum_set_result *res = parsed_result;
2410
2411         tx_cksum_set(res->port_id, res->cksum_mask);
2412 }
2413
2414 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
2415         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2416                                 tx_cksum, "tx_checksum");
2417 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
2418         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2419                                 set, "set");
2420 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
2421         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2422                                 cksum_mask, UINT8);
2423 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
2424         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2425                                 port_id, UINT8);
2426
2427 cmdline_parse_inst_t cmd_tx_cksum_set = {
2428         .f = cmd_tx_cksum_set_parsed,
2429         .data = NULL,
2430         .help_str = "enable hardware insertion of L3/L4checksum with a given "
2431         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
2432         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
2433         .tokens = {
2434                 (void *)&cmd_tx_cksum_set_tx_cksum,
2435                 (void *)&cmd_tx_cksum_set_set,
2436                 (void *)&cmd_tx_cksum_set_cksum_mask,
2437                 (void *)&cmd_tx_cksum_set_portid,
2438                 NULL,
2439         },
2440 };
2441
2442 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
2443 struct cmd_set_flush_rx {
2444         cmdline_fixed_string_t set;
2445         cmdline_fixed_string_t flush_rx;
2446         cmdline_fixed_string_t mode;
2447 };
2448
2449 static void
2450 cmd_set_flush_rx_parsed(void *parsed_result,
2451                 __attribute__((unused)) struct cmdline *cl,
2452                 __attribute__((unused)) void *data)
2453 {
2454         struct cmd_set_flush_rx *res = parsed_result;
2455         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2456 }
2457
2458 cmdline_parse_token_string_t cmd_setflushrx_set =
2459         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2460                         set, "set");
2461 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
2462         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2463                         flush_rx, "flush_rx");
2464 cmdline_parse_token_string_t cmd_setflushrx_mode =
2465         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2466                         mode, "on#off");
2467
2468
2469 cmdline_parse_inst_t cmd_set_flush_rx = {
2470         .f = cmd_set_flush_rx_parsed,
2471         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
2472         .data = NULL,
2473         .tokens = {
2474                 (void *)&cmd_setflushrx_set,
2475                 (void *)&cmd_setflushrx_flush_rx,
2476                 (void *)&cmd_setflushrx_mode,
2477                 NULL,
2478         },
2479 };
2480
2481 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
2482 struct cmd_set_link_check {
2483         cmdline_fixed_string_t set;
2484         cmdline_fixed_string_t link_check;
2485         cmdline_fixed_string_t mode;
2486 };
2487
2488 static void
2489 cmd_set_link_check_parsed(void *parsed_result,
2490                 __attribute__((unused)) struct cmdline *cl,
2491                 __attribute__((unused)) void *data)
2492 {
2493         struct cmd_set_link_check *res = parsed_result;
2494         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2495 }
2496
2497 cmdline_parse_token_string_t cmd_setlinkcheck_set =
2498         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2499                         set, "set");
2500 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
2501         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2502                         link_check, "link_check");
2503 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
2504         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2505                         mode, "on#off");
2506
2507
2508 cmdline_parse_inst_t cmd_set_link_check = {
2509         .f = cmd_set_link_check_parsed,
2510         .help_str = "set link_check on|off: enable/disable link status check "
2511                     "when starting/stopping a port",
2512         .data = NULL,
2513         .tokens = {
2514                 (void *)&cmd_setlinkcheck_set,
2515                 (void *)&cmd_setlinkcheck_link_check,
2516                 (void *)&cmd_setlinkcheck_mode,
2517                 NULL,
2518         },
2519 };
2520
2521 #ifdef RTE_NIC_BYPASS
2522 /* *** SET NIC BYPASS MODE *** */
2523 struct cmd_set_bypass_mode_result {
2524         cmdline_fixed_string_t set;
2525         cmdline_fixed_string_t bypass;
2526         cmdline_fixed_string_t mode;
2527         cmdline_fixed_string_t value;
2528         uint8_t port_id;
2529 };
2530
2531 static void
2532 cmd_set_bypass_mode_parsed(void *parsed_result,
2533                 __attribute__((unused)) struct cmdline *cl,
2534                 __attribute__((unused)) void *data)
2535 {
2536         struct cmd_set_bypass_mode_result *res = parsed_result;
2537         portid_t port_id = res->port_id;
2538         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2539
2540         if (!bypass_is_supported(port_id))
2541                 return;
2542
2543         if (!strcmp(res->value, "bypass"))
2544                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2545         else if (!strcmp(res->value, "isolate"))
2546                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2547         else
2548                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2549
2550         /* Set the bypass mode for the relevant port. */
2551         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
2552                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
2553         }
2554 }
2555
2556 cmdline_parse_token_string_t cmd_setbypass_mode_set =
2557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2558                         set, "set");
2559 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
2560         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2561                         bypass, "bypass");
2562 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
2563         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2564                         mode, "mode");
2565 cmdline_parse_token_string_t cmd_setbypass_mode_value =
2566         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2567                         value, "normal#bypass#isolate");
2568 cmdline_parse_token_num_t cmd_setbypass_mode_port =
2569         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
2570                                 port_id, UINT8);
2571
2572 cmdline_parse_inst_t cmd_set_bypass_mode = {
2573         .f = cmd_set_bypass_mode_parsed,
2574         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
2575                     "Set the NIC bypass mode for port_id",
2576         .data = NULL,
2577         .tokens = {
2578                 (void *)&cmd_setbypass_mode_set,
2579                 (void *)&cmd_setbypass_mode_bypass,
2580                 (void *)&cmd_setbypass_mode_mode,
2581                 (void *)&cmd_setbypass_mode_value,
2582                 (void *)&cmd_setbypass_mode_port,
2583                 NULL,
2584         },
2585 };
2586
2587 /* *** SET NIC BYPASS EVENT *** */
2588 struct cmd_set_bypass_event_result {
2589         cmdline_fixed_string_t set;
2590         cmdline_fixed_string_t bypass;
2591         cmdline_fixed_string_t event;
2592         cmdline_fixed_string_t event_value;
2593         cmdline_fixed_string_t mode;
2594         cmdline_fixed_string_t mode_value;
2595         uint8_t port_id;
2596 };
2597
2598 static void
2599 cmd_set_bypass_event_parsed(void *parsed_result,
2600                 __attribute__((unused)) struct cmdline *cl,
2601                 __attribute__((unused)) void *data)
2602 {
2603         int32_t rc;
2604         struct cmd_set_bypass_event_result *res = parsed_result;
2605         portid_t port_id = res->port_id;
2606         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
2607         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2608
2609         if (!bypass_is_supported(port_id))
2610                 return;
2611
2612         if (!strcmp(res->event_value, "timeout"))
2613                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
2614         else if (!strcmp(res->event_value, "os_on"))
2615                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
2616         else if (!strcmp(res->event_value, "os_off"))
2617                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
2618         else if (!strcmp(res->event_value, "power_on"))
2619                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
2620         else if (!strcmp(res->event_value, "power_off"))
2621                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
2622         else
2623                 bypass_event = RTE_BYPASS_EVENT_NONE;
2624
2625         if (!strcmp(res->mode_value, "bypass"))
2626                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2627         else if (!strcmp(res->mode_value, "isolate"))
2628                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2629         else
2630                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2631
2632         /* Set the watchdog timeout. */
2633         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
2634
2635                 rc = -EINVAL;
2636                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
2637                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
2638                                 bypass_timeout)) != 0) {
2639                         printf("Failed to set timeout value %u "
2640                                 "for port %d, errto code: %d.\n",
2641                                 bypass_timeout, port_id, rc);
2642                 }
2643         }
2644
2645         /* Set the bypass event to transition to bypass mode. */
2646         if (0 != rte_eth_dev_bypass_event_store(port_id,
2647                         bypass_event, bypass_mode)) {
2648                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
2649         }
2650
2651 }
2652
2653 cmdline_parse_token_string_t cmd_setbypass_event_set =
2654         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2655                         set, "set");
2656 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
2657         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2658                         bypass, "bypass");
2659 cmdline_parse_token_string_t cmd_setbypass_event_event =
2660         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2661                         event, "event");
2662 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
2663         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2664                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
2665 cmdline_parse_token_string_t cmd_setbypass_event_mode =
2666         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2667                         mode, "mode");
2668 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
2669         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2670                         mode_value, "normal#bypass#isolate");
2671 cmdline_parse_token_num_t cmd_setbypass_event_port =
2672         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
2673                                 port_id, UINT8);
2674
2675 cmdline_parse_inst_t cmd_set_bypass_event = {
2676         .f = cmd_set_bypass_event_parsed,
2677         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
2678                     "mode (normal|bypass|isolate) (port_id): "
2679                     "Set the NIC bypass event mode for port_id",
2680         .data = NULL,
2681         .tokens = {
2682                 (void *)&cmd_setbypass_event_set,
2683                 (void *)&cmd_setbypass_event_bypass,
2684                 (void *)&cmd_setbypass_event_event,
2685                 (void *)&cmd_setbypass_event_event_value,
2686                 (void *)&cmd_setbypass_event_mode,
2687                 (void *)&cmd_setbypass_event_mode_value,
2688                 (void *)&cmd_setbypass_event_port,
2689                 NULL,
2690         },
2691 };
2692
2693
2694 /* *** SET NIC BYPASS TIMEOUT *** */
2695 struct cmd_set_bypass_timeout_result {
2696         cmdline_fixed_string_t set;
2697         cmdline_fixed_string_t bypass;
2698         cmdline_fixed_string_t timeout;
2699         cmdline_fixed_string_t value;
2700 };
2701
2702 static void
2703 cmd_set_bypass_timeout_parsed(void *parsed_result,
2704                 __attribute__((unused)) struct cmdline *cl,
2705                 __attribute__((unused)) void *data)
2706 {
2707         struct cmd_set_bypass_timeout_result *res = parsed_result;
2708
2709         if (!strcmp(res->value, "1.5"))
2710                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
2711         else if (!strcmp(res->value, "2"))
2712                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
2713         else if (!strcmp(res->value, "3"))
2714                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
2715         else if (!strcmp(res->value, "4"))
2716                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
2717         else if (!strcmp(res->value, "8"))
2718                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
2719         else if (!strcmp(res->value, "16"))
2720                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
2721         else if (!strcmp(res->value, "32"))
2722                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
2723         else
2724                 bypass_timeout = RTE_BYPASS_TMT_OFF;
2725 }
2726
2727 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
2728         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2729                         set, "set");
2730 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
2731         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2732                         bypass, "bypass");
2733 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
2734         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2735                         timeout, "timeout");
2736 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
2737         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2738                         value, "0#1.5#2#3#4#8#16#32");
2739
2740 cmdline_parse_inst_t cmd_set_bypass_timeout = {
2741         .f = cmd_set_bypass_timeout_parsed,
2742         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
2743                     "Set the NIC bypass watchdog timeout",
2744         .data = NULL,
2745         .tokens = {
2746                 (void *)&cmd_setbypass_timeout_set,
2747                 (void *)&cmd_setbypass_timeout_bypass,
2748                 (void *)&cmd_setbypass_timeout_timeout,
2749                 (void *)&cmd_setbypass_timeout_value,
2750                 NULL,
2751         },
2752 };
2753
2754 /* *** SHOW NIC BYPASS MODE *** */
2755 struct cmd_show_bypass_config_result {
2756         cmdline_fixed_string_t show;
2757         cmdline_fixed_string_t bypass;
2758         cmdline_fixed_string_t config;
2759         uint8_t port_id;
2760 };
2761
2762 static void
2763 cmd_show_bypass_config_parsed(void *parsed_result,
2764                 __attribute__((unused)) struct cmdline *cl,
2765                 __attribute__((unused)) void *data)
2766 {
2767         struct cmd_show_bypass_config_result *res = parsed_result;
2768         uint32_t event_mode;
2769         uint32_t bypass_mode;
2770         portid_t port_id = res->port_id;
2771         uint32_t timeout = bypass_timeout;
2772         int i;
2773
2774         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
2775                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
2776         static const char * const modes[RTE_BYPASS_MODE_NUM] =
2777                 {"UNKNOWN", "normal", "bypass", "isolate"};
2778         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
2779                 "NONE",
2780                 "OS/board on",
2781                 "power supply on",
2782                 "OS/board off",
2783                 "power supply off",
2784                 "timeout"};
2785         int num_events = (sizeof events) / (sizeof events[0]);
2786
2787         if (!bypass_is_supported(port_id))
2788                 return;
2789
2790         /* Display the bypass mode.*/
2791         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
2792                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
2793                 return;
2794         }
2795         else {
2796                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
2797                         bypass_mode = RTE_BYPASS_MODE_NONE;
2798
2799                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
2800         }
2801
2802         /* Display the bypass timeout.*/
2803         if (!RTE_BYPASS_TMT_VALID(timeout))
2804                 timeout = RTE_BYPASS_TMT_OFF;
2805
2806         printf("\tbypass timeout = %s\n", timeouts[timeout]);
2807
2808         /* Display the bypass events and associated modes. */
2809         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
2810
2811                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
2812                         printf("\tFailed to get bypass mode for event = %s\n",
2813                                 events[i]);
2814                 } else {
2815                         if (!RTE_BYPASS_MODE_VALID(event_mode))
2816                                 event_mode = RTE_BYPASS_MODE_NONE;
2817
2818                         printf("\tbypass event: %-16s = %s\n", events[i],
2819                                 modes[event_mode]);
2820                 }
2821         }
2822 }
2823
2824 cmdline_parse_token_string_t cmd_showbypass_config_show =
2825         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2826                         show, "show");
2827 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
2828         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2829                         bypass, "bypass");
2830 cmdline_parse_token_string_t cmd_showbypass_config_config =
2831         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2832                         config, "config");
2833 cmdline_parse_token_num_t cmd_showbypass_config_port =
2834         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
2835                                 port_id, UINT8);
2836
2837 cmdline_parse_inst_t cmd_show_bypass_config = {
2838         .f = cmd_show_bypass_config_parsed,
2839         .help_str = "show bypass config (port_id): "
2840                     "Show the NIC bypass config for port_id",
2841         .data = NULL,
2842         .tokens = {
2843                 (void *)&cmd_showbypass_config_show,
2844                 (void *)&cmd_showbypass_config_bypass,
2845                 (void *)&cmd_showbypass_config_config,
2846                 (void *)&cmd_showbypass_config_port,
2847                 NULL,
2848         },
2849 };
2850 #endif
2851
2852 /* *** SET FORWARDING MODE *** */
2853 struct cmd_set_fwd_mode_result {
2854         cmdline_fixed_string_t set;
2855         cmdline_fixed_string_t fwd;
2856         cmdline_fixed_string_t mode;
2857 };
2858
2859 static void cmd_set_fwd_mode_parsed(void *parsed_result,
2860                                     __attribute__((unused)) struct cmdline *cl,
2861                                     __attribute__((unused)) void *data)
2862 {
2863         struct cmd_set_fwd_mode_result *res = parsed_result;
2864
2865         set_pkt_forwarding_mode(res->mode);
2866 }
2867
2868 cmdline_parse_token_string_t cmd_setfwd_set =
2869         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
2870 cmdline_parse_token_string_t cmd_setfwd_fwd =
2871         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
2872 cmdline_parse_token_string_t cmd_setfwd_mode =
2873         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
2874                 "" /* defined at init */);
2875
2876 cmdline_parse_inst_t cmd_set_fwd_mode = {
2877         .f = cmd_set_fwd_mode_parsed,
2878         .data = NULL,
2879         .help_str = NULL, /* defined at init */
2880         .tokens = {
2881                 (void *)&cmd_setfwd_set,
2882                 (void *)&cmd_setfwd_fwd,
2883                 (void *)&cmd_setfwd_mode,
2884                 NULL,
2885         },
2886 };
2887
2888 static void cmd_set_fwd_mode_init(void)
2889 {
2890         char *modes, *c;
2891         static char token[128];
2892         static char help[256];
2893         cmdline_parse_token_string_t *token_struct;
2894
2895         modes = list_pkt_forwarding_modes();
2896         rte_snprintf(help, sizeof help, "set fwd %s - "
2897                 "set packet forwarding mode", modes);
2898         cmd_set_fwd_mode.help_str = help;
2899
2900         /* string token separator is # */
2901         for (c = token; *modes != '\0'; modes++)
2902                 if (*modes == '|')
2903                         *c++ = '#';
2904                 else
2905                         *c++ = *modes;
2906         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
2907         token_struct->string_data.str = token;
2908 }
2909
2910 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
2911 struct cmd_set_burst_tx_retry_result {
2912         cmdline_fixed_string_t set;
2913         cmdline_fixed_string_t burst;
2914         cmdline_fixed_string_t tx;
2915         cmdline_fixed_string_t delay;
2916         uint32_t time;
2917         cmdline_fixed_string_t retry;
2918         uint32_t retry_num;
2919 };
2920
2921 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
2922                                         __attribute__((unused)) struct cmdline *cl,
2923                                         __attribute__((unused)) void *data)
2924 {
2925         struct cmd_set_burst_tx_retry_result *res = parsed_result;
2926
2927         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
2928                 && !strcmp(res->tx, "tx")) {
2929                 if (!strcmp(res->delay, "delay"))
2930                         burst_tx_delay_time = res->time;        
2931                 if (!strcmp(res->retry, "retry"))
2932                         burst_tx_retry_num = res->retry_num;    
2933         }
2934
2935 }
2936
2937 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
2938         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
2939 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
2940         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
2941                                  "burst");
2942 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
2943         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
2944 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
2945         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
2946 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
2947         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
2948 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
2949         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
2950 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
2951         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
2952
2953 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
2954         .f = cmd_set_burst_tx_retry_parsed,
2955         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
2956         .tokens = {
2957                 (void *)&cmd_set_burst_tx_retry_set,
2958                 (void *)&cmd_set_burst_tx_retry_burst,
2959                 (void *)&cmd_set_burst_tx_retry_tx,
2960                 (void *)&cmd_set_burst_tx_retry_delay,
2961                 (void *)&cmd_set_burst_tx_retry_time,
2962                 (void *)&cmd_set_burst_tx_retry_retry,
2963                 (void *)&cmd_set_burst_tx_retry_retry_num,
2964                 NULL,
2965         },
2966 };
2967
2968 /* *** SET PROMISC MODE *** */
2969 struct cmd_set_promisc_mode_result {
2970         cmdline_fixed_string_t set;
2971         cmdline_fixed_string_t promisc;
2972         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2973         uint8_t port_num;                /* valid if "allports" argument == 0 */
2974         cmdline_fixed_string_t mode;
2975 };
2976
2977 static void cmd_set_promisc_mode_parsed(void *parsed_result,
2978                                         __attribute__((unused)) struct cmdline *cl,
2979                                         void *allports)
2980 {
2981         struct cmd_set_promisc_mode_result *res = parsed_result;
2982         int enable;
2983         portid_t i;
2984
2985         if (!strcmp(res->mode, "on"))
2986                 enable = 1;
2987         else
2988                 enable = 0;
2989
2990         /* all ports */
2991         if (allports) {
2992                 for (i = 0; i < nb_ports; i++) {
2993                         if (enable)
2994                                 rte_eth_promiscuous_enable(i);
2995                         else
2996                                 rte_eth_promiscuous_disable(i);
2997                 }
2998         }
2999         else {
3000                 if (enable)
3001                         rte_eth_promiscuous_enable(res->port_num);
3002                 else
3003                         rte_eth_promiscuous_disable(res->port_num);
3004         }
3005 }
3006
3007 cmdline_parse_token_string_t cmd_setpromisc_set =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
3009 cmdline_parse_token_string_t cmd_setpromisc_promisc =
3010         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
3011                                  "promisc");
3012 cmdline_parse_token_string_t cmd_setpromisc_portall =
3013         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
3014                                  "all");
3015 cmdline_parse_token_num_t cmd_setpromisc_portnum =
3016         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
3017                               UINT8);
3018 cmdline_parse_token_string_t cmd_setpromisc_mode =
3019         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
3020                                  "on#off");
3021
3022 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
3023         .f = cmd_set_promisc_mode_parsed,
3024         .data = (void *)1,
3025         .help_str = "set promisc all on|off: set promisc mode for all ports",
3026         .tokens = {
3027                 (void *)&cmd_setpromisc_set,
3028                 (void *)&cmd_setpromisc_promisc,
3029                 (void *)&cmd_setpromisc_portall,
3030                 (void *)&cmd_setpromisc_mode,
3031                 NULL,
3032         },
3033 };
3034
3035 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
3036         .f = cmd_set_promisc_mode_parsed,
3037         .data = (void *)0,
3038         .help_str = "set promisc X on|off: set promisc mode on port X",
3039         .tokens = {
3040                 (void *)&cmd_setpromisc_set,
3041                 (void *)&cmd_setpromisc_promisc,
3042                 (void *)&cmd_setpromisc_portnum,
3043                 (void *)&cmd_setpromisc_mode,
3044                 NULL,
3045         },
3046 };
3047
3048 /* *** SET ALLMULTI MODE *** */
3049 struct cmd_set_allmulti_mode_result {
3050         cmdline_fixed_string_t set;
3051         cmdline_fixed_string_t allmulti;
3052         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
3053         uint8_t port_num;                /* valid if "allports" argument == 0 */
3054         cmdline_fixed_string_t mode;
3055 };
3056
3057 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
3058                                         __attribute__((unused)) struct cmdline *cl,
3059                                         void *allports)
3060 {
3061         struct cmd_set_allmulti_mode_result *res = parsed_result;
3062         int enable;
3063         portid_t i;
3064
3065         if (!strcmp(res->mode, "on"))
3066                 enable = 1;
3067         else
3068                 enable = 0;
3069
3070         /* all ports */
3071         if (allports) {
3072                 for (i = 0; i < nb_ports; i++) {
3073                         if (enable)
3074                                 rte_eth_allmulticast_enable(i);
3075                         else
3076                                 rte_eth_allmulticast_disable(i);
3077                 }
3078         }
3079         else {
3080                 if (enable)
3081                         rte_eth_allmulticast_enable(res->port_num);
3082                 else
3083                         rte_eth_allmulticast_disable(res->port_num);
3084         }
3085 }
3086
3087 cmdline_parse_token_string_t cmd_setallmulti_set =
3088         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
3089 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
3090         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
3091                                  "allmulti");
3092 cmdline_parse_token_string_t cmd_setallmulti_portall =
3093         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
3094                                  "all");
3095 cmdline_parse_token_num_t cmd_setallmulti_portnum =
3096         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
3097                               UINT8);
3098 cmdline_parse_token_string_t cmd_setallmulti_mode =
3099         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
3100                                  "on#off");
3101
3102 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
3103         .f = cmd_set_allmulti_mode_parsed,
3104         .data = (void *)1,
3105         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
3106         .tokens = {
3107                 (void *)&cmd_setallmulti_set,
3108                 (void *)&cmd_setallmulti_allmulti,
3109                 (void *)&cmd_setallmulti_portall,
3110                 (void *)&cmd_setallmulti_mode,
3111                 NULL,
3112         },
3113 };
3114
3115 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
3116         .f = cmd_set_allmulti_mode_parsed,
3117         .data = (void *)0,
3118         .help_str = "set allmulti X on|off: set allmulti mode on port X",
3119         .tokens = {
3120                 (void *)&cmd_setallmulti_set,
3121                 (void *)&cmd_setallmulti_allmulti,
3122                 (void *)&cmd_setallmulti_portnum,
3123                 (void *)&cmd_setallmulti_mode,
3124                 NULL,
3125         },
3126 };
3127
3128 /* *** ADD/REMOVE A PKT FILTER *** */
3129 struct cmd_pkt_filter_result {
3130         cmdline_fixed_string_t pkt_filter;
3131         uint8_t  port_id;
3132         cmdline_fixed_string_t protocol;
3133         cmdline_fixed_string_t src;
3134         cmdline_ipaddr_t ip_src;
3135         uint16_t port_src;
3136         cmdline_fixed_string_t dst;
3137         cmdline_ipaddr_t ip_dst;
3138         uint16_t port_dst;
3139         cmdline_fixed_string_t flexbytes;
3140         uint16_t flexbytes_value;
3141         cmdline_fixed_string_t vlan;
3142         uint16_t  vlan_id;
3143         cmdline_fixed_string_t queue;
3144         int8_t  queue_id;
3145         cmdline_fixed_string_t soft;
3146         uint8_t  soft_id;
3147 };
3148
3149 static void
3150 cmd_pkt_filter_parsed(void *parsed_result,
3151                           __attribute__((unused)) struct cmdline *cl,
3152                           __attribute__((unused)) void *data)
3153 {
3154         struct rte_fdir_filter fdir_filter;
3155         struct cmd_pkt_filter_result *res = parsed_result;
3156
3157         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
3158
3159         if (res->ip_src.family == AF_INET)
3160                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
3161         else
3162                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
3163                        &(res->ip_src.addr.ipv6),
3164                        sizeof(struct in6_addr));
3165
3166         if (res->ip_dst.family == AF_INET)
3167                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
3168         else
3169                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
3170                        &(res->ip_dst.addr.ipv6),
3171                        sizeof(struct in6_addr));
3172
3173         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
3174         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
3175
3176         if (!strcmp(res->protocol, "udp"))
3177                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
3178         else if (!strcmp(res->protocol, "tcp"))
3179                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
3180         else if (!strcmp(res->protocol, "sctp"))
3181                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
3182         else /* default only IP */
3183                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
3184
3185         if (res->ip_dst.family == AF_INET6)
3186                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
3187         else
3188                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
3189
3190         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
3191         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
3192
3193         if (!strcmp(res->pkt_filter, "add_signature_filter"))
3194                 fdir_add_signature_filter(res->port_id, res->queue_id,
3195                                           &fdir_filter);
3196         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
3197                 fdir_update_signature_filter(res->port_id, res->queue_id,
3198                                              &fdir_filter);
3199         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
3200                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
3201         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
3202                 fdir_add_perfect_filter(res->port_id, res->soft_id,
3203                                         res->queue_id,
3204                                         (uint8_t) (res->queue_id < 0),
3205                                         &fdir_filter);
3206         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
3207                 fdir_update_perfect_filter(res->port_id, res->soft_id,
3208                                            res->queue_id,
3209                                            (uint8_t) (res->queue_id < 0),
3210                                            &fdir_filter);
3211         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
3212                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
3213                                            &fdir_filter);
3214
3215 }
3216
3217
3218 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
3219         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3220                               port_id, UINT8);
3221 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
3222         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3223                                  protocol, "ip#tcp#udp#sctp");
3224 cmdline_parse_token_string_t cmd_pkt_filter_src =
3225         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3226                                  src, "src");
3227 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
3228         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3229                                  ip_src);
3230 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
3231         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3232                               port_src, UINT16);
3233 cmdline_parse_token_string_t cmd_pkt_filter_dst =
3234         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3235                                  dst, "dst");
3236 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
3237         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3238                                  ip_dst);
3239 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
3240         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3241                               port_dst, UINT16);
3242 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
3243         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3244                                  flexbytes, "flexbytes");
3245 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
3246         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3247                               flexbytes_value, UINT16);
3248 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
3249         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3250                                  vlan, "vlan");
3251 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
3252         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3253                               vlan_id, UINT16);
3254 cmdline_parse_token_string_t cmd_pkt_filter_queue =
3255         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3256                                  queue, "queue");
3257 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
3258         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3259                               queue_id, INT8);
3260 cmdline_parse_token_string_t cmd_pkt_filter_soft =
3261         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3262                                  soft, "soft");
3263 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
3264         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3265                               soft_id, UINT16);
3266
3267
3268 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
3269         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3270                                  pkt_filter, "add_signature_filter");
3271 cmdline_parse_inst_t cmd_add_signature_filter = {
3272         .f = cmd_pkt_filter_parsed,
3273         .data = NULL,
3274         .help_str = "add a signature filter",
3275         .tokens = {
3276                 (void *)&cmd_pkt_filter_add_signature_filter,
3277                 (void *)&cmd_pkt_filter_port_id,
3278                 (void *)&cmd_pkt_filter_protocol,
3279                 (void *)&cmd_pkt_filter_src,
3280                 (void *)&cmd_pkt_filter_ip_src,
3281                 (void *)&cmd_pkt_filter_port_src,
3282                 (void *)&cmd_pkt_filter_dst,
3283                 (void *)&cmd_pkt_filter_ip_dst,
3284                 (void *)&cmd_pkt_filter_port_dst,
3285                 (void *)&cmd_pkt_filter_flexbytes,
3286                 (void *)&cmd_pkt_filter_flexbytes_value,
3287                 (void *)&cmd_pkt_filter_vlan,
3288                 (void *)&cmd_pkt_filter_vlan_id,
3289                 (void *)&cmd_pkt_filter_queue,
3290                 (void *)&cmd_pkt_filter_queue_id,
3291                 NULL,
3292         },
3293 };
3294
3295
3296 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
3297         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3298                                  pkt_filter, "upd_signature_filter");
3299 cmdline_parse_inst_t cmd_upd_signature_filter = {
3300         .f = cmd_pkt_filter_parsed,
3301         .data = NULL,
3302         .help_str = "update a signature filter",
3303         .tokens = {
3304                 (void *)&cmd_pkt_filter_upd_signature_filter,
3305                 (void *)&cmd_pkt_filter_port_id,
3306                 (void *)&cmd_pkt_filter_protocol,
3307                 (void *)&cmd_pkt_filter_src,
3308                 (void *)&cmd_pkt_filter_ip_src,
3309                 (void *)&cmd_pkt_filter_port_src,
3310                 (void *)&cmd_pkt_filter_dst,
3311                 (void *)&cmd_pkt_filter_ip_dst,
3312                 (void *)&cmd_pkt_filter_port_dst,
3313                 (void *)&cmd_pkt_filter_flexbytes,
3314                 (void *)&cmd_pkt_filter_flexbytes_value,
3315                 (void *)&cmd_pkt_filter_vlan,
3316                 (void *)&cmd_pkt_filter_vlan_id,
3317                 (void *)&cmd_pkt_filter_queue,
3318                 (void *)&cmd_pkt_filter_queue_id,
3319                 NULL,
3320         },
3321 };
3322
3323
3324 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
3325         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3326                                  pkt_filter, "rm_signature_filter");
3327 cmdline_parse_inst_t cmd_rm_signature_filter = {
3328         .f = cmd_pkt_filter_parsed,
3329         .data = NULL,
3330         .help_str = "remove a signature filter",
3331         .tokens = {
3332                 (void *)&cmd_pkt_filter_rm_signature_filter,
3333                 (void *)&cmd_pkt_filter_port_id,
3334                 (void *)&cmd_pkt_filter_protocol,
3335                 (void *)&cmd_pkt_filter_src,
3336                 (void *)&cmd_pkt_filter_ip_src,
3337                 (void *)&cmd_pkt_filter_port_src,
3338                 (void *)&cmd_pkt_filter_dst,
3339                 (void *)&cmd_pkt_filter_ip_dst,
3340                 (void *)&cmd_pkt_filter_port_dst,
3341                 (void *)&cmd_pkt_filter_flexbytes,
3342                 (void *)&cmd_pkt_filter_flexbytes_value,
3343                 (void *)&cmd_pkt_filter_vlan,
3344                 (void *)&cmd_pkt_filter_vlan_id,
3345                 NULL
3346                 },
3347 };
3348
3349
3350 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
3351         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3352                                  pkt_filter, "add_perfect_filter");
3353 cmdline_parse_inst_t cmd_add_perfect_filter = {
3354         .f = cmd_pkt_filter_parsed,
3355         .data = NULL,
3356         .help_str = "add a perfect filter",
3357         .tokens = {
3358                 (void *)&cmd_pkt_filter_add_perfect_filter,
3359                 (void *)&cmd_pkt_filter_port_id,
3360                 (void *)&cmd_pkt_filter_protocol,
3361                 (void *)&cmd_pkt_filter_src,
3362                 (void *)&cmd_pkt_filter_ip_src,
3363                 (void *)&cmd_pkt_filter_port_src,
3364                 (void *)&cmd_pkt_filter_dst,
3365                 (void *)&cmd_pkt_filter_ip_dst,
3366                 (void *)&cmd_pkt_filter_port_dst,
3367                 (void *)&cmd_pkt_filter_flexbytes,
3368                 (void *)&cmd_pkt_filter_flexbytes_value,
3369                 (void *)&cmd_pkt_filter_vlan,
3370                 (void *)&cmd_pkt_filter_vlan_id,
3371                 (void *)&cmd_pkt_filter_queue,
3372                 (void *)&cmd_pkt_filter_queue_id,
3373                 (void *)&cmd_pkt_filter_soft,
3374                 (void *)&cmd_pkt_filter_soft_id,
3375                 NULL,
3376         },
3377 };
3378
3379
3380 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
3381         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3382                                  pkt_filter, "upd_perfect_filter");
3383 cmdline_parse_inst_t cmd_upd_perfect_filter = {
3384         .f = cmd_pkt_filter_parsed,
3385         .data = NULL,
3386         .help_str = "update a perfect filter",
3387         .tokens = {
3388                 (void *)&cmd_pkt_filter_upd_perfect_filter,
3389                 (void *)&cmd_pkt_filter_port_id,
3390                 (void *)&cmd_pkt_filter_protocol,
3391                 (void *)&cmd_pkt_filter_src,
3392                 (void *)&cmd_pkt_filter_ip_src,
3393                 (void *)&cmd_pkt_filter_port_src,
3394                 (void *)&cmd_pkt_filter_dst,
3395                 (void *)&cmd_pkt_filter_ip_dst,
3396                 (void *)&cmd_pkt_filter_port_dst,
3397                 (void *)&cmd_pkt_filter_flexbytes,
3398                 (void *)&cmd_pkt_filter_flexbytes_value,
3399                 (void *)&cmd_pkt_filter_vlan,
3400                 (void *)&cmd_pkt_filter_vlan_id,
3401                 (void *)&cmd_pkt_filter_queue,
3402                 (void *)&cmd_pkt_filter_queue_id,
3403                 (void *)&cmd_pkt_filter_soft,
3404                 (void *)&cmd_pkt_filter_soft_id,
3405                 NULL,
3406         },
3407 };
3408
3409
3410 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
3411         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3412                                  pkt_filter, "rm_perfect_filter");
3413 cmdline_parse_inst_t cmd_rm_perfect_filter = {
3414         .f = cmd_pkt_filter_parsed,
3415         .data = NULL,
3416         .help_str = "remove a perfect filter",
3417         .tokens = {
3418                 (void *)&cmd_pkt_filter_rm_perfect_filter,
3419                 (void *)&cmd_pkt_filter_port_id,
3420                 (void *)&cmd_pkt_filter_protocol,
3421                 (void *)&cmd_pkt_filter_src,
3422                 (void *)&cmd_pkt_filter_ip_src,
3423                 (void *)&cmd_pkt_filter_port_src,
3424                 (void *)&cmd_pkt_filter_dst,
3425                 (void *)&cmd_pkt_filter_ip_dst,
3426                 (void *)&cmd_pkt_filter_port_dst,
3427                 (void *)&cmd_pkt_filter_flexbytes,
3428                 (void *)&cmd_pkt_filter_flexbytes_value,
3429                 (void *)&cmd_pkt_filter_vlan,
3430                 (void *)&cmd_pkt_filter_vlan_id,
3431                 (void *)&cmd_pkt_filter_soft,
3432                 (void *)&cmd_pkt_filter_soft_id,
3433                 NULL,
3434         },
3435 };
3436
3437 /* *** SETUP MASKS FILTER *** */
3438 struct cmd_pkt_filter_masks_result {
3439         cmdline_fixed_string_t filter_mask;
3440         uint8_t  port_id;
3441         cmdline_fixed_string_t src_mask;
3442         uint32_t ip_src_mask;
3443         uint16_t ipv6_src_mask;
3444         uint16_t port_src_mask;
3445         cmdline_fixed_string_t dst_mask;
3446         uint32_t ip_dst_mask;
3447         uint16_t ipv6_dst_mask;
3448         uint16_t port_dst_mask;
3449         cmdline_fixed_string_t flexbytes;
3450         uint8_t flexbytes_value;
3451         cmdline_fixed_string_t vlan_id;
3452         uint8_t  vlan_id_value;
3453         cmdline_fixed_string_t vlan_prio;
3454         uint8_t  vlan_prio_value;
3455         cmdline_fixed_string_t only_ip_flow;
3456         uint8_t  only_ip_flow_value;
3457         cmdline_fixed_string_t comp_ipv6_dst;
3458         uint8_t  comp_ipv6_dst_value;
3459 };
3460
3461 static void
3462 cmd_pkt_filter_masks_parsed(void *parsed_result,
3463                           __attribute__((unused)) struct cmdline *cl,
3464                           __attribute__((unused)) void *data)
3465 {
3466         struct rte_fdir_masks fdir_masks;
3467         struct cmd_pkt_filter_masks_result *res = parsed_result;
3468
3469         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3470
3471         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3472         fdir_masks.vlan_id       = res->vlan_id_value;
3473         fdir_masks.vlan_prio     = res->vlan_prio_value;
3474         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
3475         fdir_masks.src_ipv4_mask = res->ip_src_mask;
3476         fdir_masks.src_port_mask = res->port_src_mask;
3477         fdir_masks.dst_port_mask = res->port_dst_mask;
3478         fdir_masks.flexbytes     = res->flexbytes_value;
3479
3480         fdir_set_masks(res->port_id, &fdir_masks);
3481 }
3482
3483 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
3484         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3485                                  filter_mask, "set_masks_filter");
3486 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
3487         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3488                               port_id, UINT8);
3489 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
3490         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3491                                  only_ip_flow, "only_ip_flow");
3492 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
3493         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3494                               only_ip_flow_value, UINT8);
3495 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
3496         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3497                                  src_mask, "src_mask");
3498 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
3499         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3500                               ip_src_mask, UINT32);
3501 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
3502         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3503                               port_src_mask, UINT16);
3504 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
3505         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3506                                  dst_mask, "dst_mask");
3507 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
3508         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3509                               ip_dst_mask, UINT32);
3510 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
3511         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3512                               port_dst_mask, UINT16);
3513 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
3514         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3515                                  flexbytes, "flexbytes");
3516 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
3517         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3518                               flexbytes_value, UINT8);
3519 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
3520         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3521                                  vlan_id, "vlan_id");
3522 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
3523         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3524                               vlan_id_value, UINT8);
3525 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
3526         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3527                                  vlan_prio, "vlan_prio");
3528 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
3529         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3530                               vlan_prio_value, UINT8);
3531
3532 cmdline_parse_inst_t cmd_set_masks_filter = {
3533         .f = cmd_pkt_filter_masks_parsed,
3534         .data = NULL,
3535         .help_str = "setup masks filter",
3536         .tokens = {
3537                 (void *)&cmd_pkt_filter_masks_filter_mask,
3538                 (void *)&cmd_pkt_filter_masks_port_id,
3539                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3540                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3541                 (void *)&cmd_pkt_filter_masks_src_mask,
3542                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
3543                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3544                 (void *)&cmd_pkt_filter_masks_dst_mask,
3545                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
3546                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3547                 (void *)&cmd_pkt_filter_masks_flexbytes,
3548                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3549                 (void *)&cmd_pkt_filter_masks_vlan_id,
3550                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3551                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3552                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3553                 NULL,
3554         },
3555 };
3556
3557 static void
3558 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
3559                           __attribute__((unused)) struct cmdline *cl,
3560                           __attribute__((unused)) void *data)
3561 {
3562         struct rte_fdir_masks fdir_masks;
3563         struct cmd_pkt_filter_masks_result *res = parsed_result;
3564
3565         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3566
3567         fdir_masks.set_ipv6_mask = 1;
3568         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3569         fdir_masks.vlan_id       = res->vlan_id_value;
3570         fdir_masks.vlan_prio     = res->vlan_prio_value;
3571         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
3572         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
3573         fdir_masks.src_port_mask = res->port_src_mask;
3574         fdir_masks.dst_port_mask = res->port_dst_mask;
3575         fdir_masks.flexbytes     = res->flexbytes_value;
3576         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
3577
3578         fdir_set_masks(res->port_id, &fdir_masks);
3579 }
3580
3581 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
3582         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3583                                  filter_mask, "set_ipv6_masks_filter");
3584 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
3585         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3586                               ipv6_src_mask, UINT16);
3587 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
3588         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3589                               ipv6_dst_mask, UINT16);
3590
3591 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
3592         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3593                                  comp_ipv6_dst, "compare_dst");
3594 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
3595         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3596                               comp_ipv6_dst_value, UINT8);
3597
3598 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
3599         .f = cmd_pkt_filter_masks_ipv6_parsed,
3600         .data = NULL,
3601         .help_str = "setup ipv6 masks filter",
3602         .tokens = {
3603                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
3604                 (void *)&cmd_pkt_filter_masks_port_id,
3605                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3606                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3607                 (void *)&cmd_pkt_filter_masks_src_mask,
3608                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
3609                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3610                 (void *)&cmd_pkt_filter_masks_dst_mask,
3611                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
3612                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3613                 (void *)&cmd_pkt_filter_masks_flexbytes,
3614                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3615                 (void *)&cmd_pkt_filter_masks_vlan_id,
3616                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3617                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3618                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3619                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
3620                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
3621                 NULL,
3622         },
3623 };
3624
3625 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
3626 struct cmd_link_flow_ctrl_set_result {
3627         cmdline_fixed_string_t set;
3628         cmdline_fixed_string_t flow_ctrl;
3629         cmdline_fixed_string_t rx;
3630         cmdline_fixed_string_t rx_lfc_mode;
3631         cmdline_fixed_string_t tx;
3632         cmdline_fixed_string_t tx_lfc_mode;
3633         cmdline_fixed_string_t mac_ctrl_frame_fwd;
3634         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
3635         uint32_t high_water;
3636         uint32_t low_water;
3637         uint16_t pause_time;
3638         uint16_t send_xon;
3639         uint8_t  port_id;
3640 };
3641
3642 static void
3643 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
3644                        __attribute__((unused)) struct cmdline *cl,
3645                        __attribute__((unused)) void *data)
3646 {
3647         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
3648         struct rte_eth_fc_conf fc_conf;
3649         int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
3650         int ret;
3651
3652         /*
3653          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3654          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3655          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3656          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3657          */
3658         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
3659                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
3660         };
3661
3662         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
3663         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
3664         mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
3665
3666         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
3667         fc_conf.high_water = res->high_water;
3668         fc_conf.low_water  = res->low_water;
3669         fc_conf.pause_time = res->pause_time;
3670         fc_conf.send_xon   = res->send_xon;
3671         fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
3672
3673         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
3674         if (ret != 0)
3675                 printf("bad flow contrl parameter, return code = %d \n", ret);
3676 }
3677
3678 cmdline_parse_token_string_t cmd_lfc_set_set =
3679         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3680                                 set, "set");
3681 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
3682         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3683                                 flow_ctrl, "flow_ctrl");
3684 cmdline_parse_token_string_t cmd_lfc_set_rx =
3685         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3686                                 rx, "rx");
3687 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
3688         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3689                                 rx_lfc_mode, "on#off");
3690 cmdline_parse_token_string_t cmd_lfc_set_tx =
3691         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3692                                 tx, "tx");
3693 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
3694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3695                                 tx_lfc_mode, "on#off");
3696 cmdline_parse_token_num_t cmd_lfc_set_high_water =
3697         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3698                                 high_water, UINT32);
3699 cmdline_parse_token_num_t cmd_lfc_set_low_water =
3700         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3701                                 low_water, UINT32);
3702 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
3703         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3704                                 pause_time, UINT16);
3705 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
3706         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3707                                 send_xon, UINT16);
3708 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
3709         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3710                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
3711 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
3712         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3713                                 mac_ctrl_frame_fwd_mode, "on#off");
3714 cmdline_parse_token_num_t cmd_lfc_set_portid =
3715         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3716                                 port_id, UINT8);
3717
3718 cmdline_parse_inst_t cmd_link_flow_control_set = {
3719         .f = cmd_link_flow_ctrl_set_parsed,
3720         .data = NULL,
3721         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
3722 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
3723 port_id",
3724         .tokens = {
3725                 (void *)&cmd_lfc_set_set,
3726                 (void *)&cmd_lfc_set_flow_ctrl,
3727                 (void *)&cmd_lfc_set_rx,
3728                 (void *)&cmd_lfc_set_rx_mode,
3729                 (void *)&cmd_lfc_set_tx,
3730                 (void *)&cmd_lfc_set_tx_mode,
3731                 (void *)&cmd_lfc_set_high_water,
3732                 (void *)&cmd_lfc_set_low_water,
3733                 (void *)&cmd_lfc_set_pause_time,
3734                 (void *)&cmd_lfc_set_send_xon,
3735                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
3736                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
3737                 (void *)&cmd_lfc_set_portid,
3738                 NULL,
3739         },
3740 };
3741
3742 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
3743 struct cmd_priority_flow_ctrl_set_result {
3744         cmdline_fixed_string_t set;
3745         cmdline_fixed_string_t pfc_ctrl;
3746         cmdline_fixed_string_t rx;
3747         cmdline_fixed_string_t rx_pfc_mode;
3748         cmdline_fixed_string_t tx;
3749         cmdline_fixed_string_t tx_pfc_mode;
3750         uint32_t high_water;
3751         uint32_t low_water;
3752         uint16_t pause_time;
3753         uint8_t  priority;
3754         uint8_t  port_id;
3755 };
3756
3757 static void
3758 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
3759                        __attribute__((unused)) struct cmdline *cl,
3760                        __attribute__((unused)) void *data)
3761 {
3762         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
3763         struct rte_eth_pfc_conf pfc_conf;
3764         int rx_fc_enable, tx_fc_enable;
3765         int ret;
3766
3767         /*
3768          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3769          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3770          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3771          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3772          */
3773         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
3774                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3775         };
3776
3777         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
3778         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
3779         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
3780         pfc_conf.fc.high_water = res->high_water;
3781         pfc_conf.fc.low_water  = res->low_water;
3782         pfc_conf.fc.pause_time = res->pause_time;
3783         pfc_conf.priority      = res->priority;
3784
3785         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
3786         if (ret != 0)
3787                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
3788 }
3789
3790 cmdline_parse_token_string_t cmd_pfc_set_set =
3791         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3792                                 set, "set");
3793 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
3794         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3795                                 pfc_ctrl, "pfc_ctrl");
3796 cmdline_parse_token_string_t cmd_pfc_set_rx =
3797         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3798                                 rx, "rx");
3799 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
3800         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3801                                 rx_pfc_mode, "on#off");
3802 cmdline_parse_token_string_t cmd_pfc_set_tx =
3803         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3804                                 tx, "tx");
3805 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
3806         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3807                                 tx_pfc_mode, "on#off");
3808 cmdline_parse_token_num_t cmd_pfc_set_high_water =
3809         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3810                                 high_water, UINT32);
3811 cmdline_parse_token_num_t cmd_pfc_set_low_water =
3812         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3813                                 low_water, UINT32);
3814 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
3815         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3816                                 pause_time, UINT16);
3817 cmdline_parse_token_num_t cmd_pfc_set_priority =
3818         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3819                                 priority, UINT8);
3820 cmdline_parse_token_num_t cmd_pfc_set_portid =
3821         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3822                                 port_id, UINT8);
3823
3824 cmdline_parse_inst_t cmd_priority_flow_control_set = {
3825         .f = cmd_priority_flow_ctrl_set_parsed,
3826         .data = NULL,
3827         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
3828                         tx on|off high_water low_water pause_time priority port_id",
3829         .tokens = {
3830                 (void *)&cmd_pfc_set_set,
3831                 (void *)&cmd_pfc_set_flow_ctrl,
3832                 (void *)&cmd_pfc_set_rx,
3833                 (void *)&cmd_pfc_set_rx_mode,
3834                 (void *)&cmd_pfc_set_tx,
3835                 (void *)&cmd_pfc_set_tx_mode,
3836                 (void *)&cmd_pfc_set_high_water,
3837                 (void *)&cmd_pfc_set_low_water,
3838                 (void *)&cmd_pfc_set_pause_time,
3839                 (void *)&cmd_pfc_set_priority,
3840                 (void *)&cmd_pfc_set_portid,
3841                 NULL,
3842         },
3843 };
3844
3845 /* *** RESET CONFIGURATION *** */
3846 struct cmd_reset_result {
3847         cmdline_fixed_string_t reset;
3848         cmdline_fixed_string_t def;
3849 };
3850
3851 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
3852                              struct cmdline *cl,
3853                              __attribute__((unused)) void *data)
3854 {
3855         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
3856         set_def_fwd_config();
3857 }
3858
3859 cmdline_parse_token_string_t cmd_reset_set =
3860         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
3861 cmdline_parse_token_string_t cmd_reset_def =
3862         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
3863                                  "default");
3864
3865 cmdline_parse_inst_t cmd_reset = {
3866         .f = cmd_reset_parsed,
3867         .data = NULL,
3868         .help_str = "set default: reset default forwarding configuration",
3869         .tokens = {
3870                 (void *)&cmd_reset_set,
3871                 (void *)&cmd_reset_def,
3872                 NULL,
3873         },
3874 };
3875
3876 /* *** START FORWARDING *** */
3877 struct cmd_start_result {
3878         cmdline_fixed_string_t start;
3879 };
3880
3881 cmdline_parse_token_string_t cmd_start_start =
3882         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
3883
3884 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
3885                              __attribute__((unused)) struct cmdline *cl,
3886                              __attribute__((unused)) void *data)
3887 {
3888         start_packet_forwarding(0);
3889 }
3890
3891 cmdline_parse_inst_t cmd_start = {
3892         .f = cmd_start_parsed,
3893         .data = NULL,
3894         .help_str = "start packet forwarding",
3895         .tokens = {
3896                 (void *)&cmd_start_start,
3897                 NULL,
3898         },
3899 };
3900
3901 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
3902 struct cmd_start_tx_first_result {
3903         cmdline_fixed_string_t start;
3904         cmdline_fixed_string_t tx_first;
3905 };
3906
3907 static void
3908 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
3909                           __attribute__((unused)) struct cmdline *cl,
3910                           __attribute__((unused)) void *data)
3911 {
3912         start_packet_forwarding(1);
3913 }
3914
3915 cmdline_parse_token_string_t cmd_start_tx_first_start =
3916         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
3917                                  "start");
3918 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
3919         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
3920                                  tx_first, "tx_first");
3921
3922 cmdline_parse_inst_t cmd_start_tx_first = {
3923         .f = cmd_start_tx_first_parsed,
3924         .data = NULL,
3925         .help_str = "start packet forwarding, after sending 1 burst of packets",
3926         .tokens = {
3927                 (void *)&cmd_start_tx_first_start,
3928                 (void *)&cmd_start_tx_first_tx_first,
3929                 NULL,
3930         },
3931 };
3932
3933 /* *** SHOW CFG *** */
3934 struct cmd_showcfg_result {
3935         cmdline_fixed_string_t show;
3936         cmdline_fixed_string_t cfg;
3937         cmdline_fixed_string_t what;
3938 };
3939
3940 static void cmd_showcfg_parsed(void *parsed_result,
3941                                __attribute__((unused)) struct cmdline *cl,
3942                                __attribute__((unused)) void *data)
3943 {
3944         struct cmd_showcfg_result *res = parsed_result;
3945         if (!strcmp(res->what, "rxtx"))
3946                 rxtx_config_display();
3947         else if (!strcmp(res->what, "cores"))
3948                 fwd_lcores_config_display();
3949         else if (!strcmp(res->what, "fwd"))
3950                 fwd_config_display();
3951 }
3952
3953 cmdline_parse_token_string_t cmd_showcfg_show =
3954         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
3955 cmdline_parse_token_string_t cmd_showcfg_port =
3956         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
3957 cmdline_parse_token_string_t cmd_showcfg_what =
3958         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
3959                                  "rxtx#cores#fwd");
3960
3961 cmdline_parse_inst_t cmd_showcfg = {
3962         .f = cmd_showcfg_parsed,
3963         .data = NULL,
3964         .help_str = "show config rxtx|cores|fwd",
3965         .tokens = {
3966                 (void *)&cmd_showcfg_show,
3967                 (void *)&cmd_showcfg_port,
3968                 (void *)&cmd_showcfg_what,
3969                 NULL,
3970         },
3971 };
3972
3973 /* *** SHOW ALL PORT INFO *** */
3974 struct cmd_showportall_result {
3975         cmdline_fixed_string_t show;
3976         cmdline_fixed_string_t port;
3977         cmdline_fixed_string_t what;
3978         cmdline_fixed_string_t all;
3979 };
3980
3981 static void cmd_showportall_parsed(void *parsed_result,
3982                                 __attribute__((unused)) struct cmdline *cl,
3983                                 __attribute__((unused)) void *data)
3984 {
3985         portid_t i;
3986
3987         struct cmd_showportall_result *res = parsed_result;
3988         if (!strcmp(res->show, "clear")) {
3989                 if (!strcmp(res->what, "stats"))
3990                         for (i = 0; i < nb_ports; i++)
3991                                 nic_stats_clear(i);
3992         } else if (!strcmp(res->what, "info"))
3993                 for (i = 0; i < nb_ports; i++)
3994                         port_infos_display(i);
3995         else if (!strcmp(res->what, "stats"))
3996                 for (i = 0; i < nb_ports; i++)
3997                         nic_stats_display(i);
3998         else if (!strcmp(res->what, "fdir"))
3999                 for (i = 0; i < nb_ports; i++)
4000                         fdir_get_infos(i);
4001         else if (!strcmp(res->what, "stat_qmap"))
4002                 for (i = 0; i < nb_ports; i++)
4003                         nic_stats_mapping_display(i);
4004 }
4005
4006 cmdline_parse_token_string_t cmd_showportall_show =
4007         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
4008                                  "show#clear");
4009 cmdline_parse_token_string_t cmd_showportall_port =
4010         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
4011 cmdline_parse_token_string_t cmd_showportall_what =
4012         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
4013                                  "info#stats#fdir#stat_qmap");
4014 cmdline_parse_token_string_t cmd_showportall_all =
4015         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
4016 cmdline_parse_inst_t cmd_showportall = {
4017         .f = cmd_showportall_parsed,
4018         .data = NULL,
4019         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
4020         .tokens = {
4021                 (void *)&cmd_showportall_show,
4022                 (void *)&cmd_showportall_port,
4023                 (void *)&cmd_showportall_what,
4024                 (void *)&cmd_showportall_all,
4025                 NULL,
4026         },
4027 };
4028
4029 /* *** SHOW PORT INFO *** */
4030 struct cmd_showport_result {
4031         cmdline_fixed_string_t show;
4032         cmdline_fixed_string_t port;
4033         cmdline_fixed_string_t what;
4034         uint8_t portnum;
4035 };
4036
4037 static void cmd_showport_parsed(void *parsed_result,
4038                                 __attribute__((unused)) struct cmdline *cl,
4039                                 __attribute__((unused)) void *data)
4040 {
4041         struct cmd_showport_result *res = parsed_result;
4042         if (!strcmp(res->show, "clear")) {
4043                 if (!strcmp(res->what, "stats"))
4044                         nic_stats_clear(res->portnum);
4045         } else if (!strcmp(res->what, "info"))
4046                 port_infos_display(res->portnum);
4047         else if (!strcmp(res->what, "stats"))
4048                 nic_stats_display(res->portnum);
4049         else if (!strcmp(res->what, "fdir"))
4050                  fdir_get_infos(res->portnum);
4051         else if (!strcmp(res->what, "stat_qmap"))
4052                 nic_stats_mapping_display(res->portnum);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_showport_show =
4056         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
4057                                  "show#clear");
4058 cmdline_parse_token_string_t cmd_showport_port =
4059         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
4060 cmdline_parse_token_string_t cmd_showport_what =
4061         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
4062                                  "info#stats#fdir#stat_qmap");
4063 cmdline_parse_token_num_t cmd_showport_portnum =
4064         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
4065
4066 cmdline_parse_inst_t cmd_showport = {
4067         .f = cmd_showport_parsed,
4068         .data = NULL,
4069         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
4070         .tokens = {
4071                 (void *)&cmd_showport_show,
4072                 (void *)&cmd_showport_port,
4073                 (void *)&cmd_showport_what,
4074                 (void *)&cmd_showport_portnum,
4075                 NULL,
4076         },
4077 };
4078
4079 /* *** READ PORT REGISTER *** */
4080 struct cmd_read_reg_result {
4081         cmdline_fixed_string_t read;
4082         cmdline_fixed_string_t reg;
4083         uint8_t port_id;
4084         uint32_t reg_off;
4085 };
4086
4087 static void
4088 cmd_read_reg_parsed(void *parsed_result,
4089                     __attribute__((unused)) struct cmdline *cl,
4090                     __attribute__((unused)) void *data)
4091 {
4092         struct cmd_read_reg_result *res = parsed_result;
4093         port_reg_display(res->port_id, res->reg_off);
4094 }
4095
4096 cmdline_parse_token_string_t cmd_read_reg_read =
4097         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
4098 cmdline_parse_token_string_t cmd_read_reg_reg =
4099         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
4100 cmdline_parse_token_num_t cmd_read_reg_port_id =
4101         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
4102 cmdline_parse_token_num_t cmd_read_reg_reg_off =
4103         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
4104
4105 cmdline_parse_inst_t cmd_read_reg = {
4106         .f = cmd_read_reg_parsed,
4107         .data = NULL,
4108         .help_str = "read reg port_id reg_off",
4109         .tokens = {
4110                 (void *)&cmd_read_reg_read,
4111                 (void *)&cmd_read_reg_reg,
4112                 (void *)&cmd_read_reg_port_id,
4113                 (void *)&cmd_read_reg_reg_off,
4114                 NULL,
4115         },
4116 };
4117
4118 /* *** READ PORT REGISTER BIT FIELD *** */
4119 struct cmd_read_reg_bit_field_result {
4120         cmdline_fixed_string_t read;
4121         cmdline_fixed_string_t regfield;
4122         uint8_t port_id;
4123         uint32_t reg_off;
4124         uint8_t bit1_pos;
4125         uint8_t bit2_pos;
4126 };
4127
4128 static void
4129 cmd_read_reg_bit_field_parsed(void *parsed_result,
4130                               __attribute__((unused)) struct cmdline *cl,
4131                               __attribute__((unused)) void *data)
4132 {
4133         struct cmd_read_reg_bit_field_result *res = parsed_result;
4134         port_reg_bit_field_display(res->port_id, res->reg_off,
4135                                    res->bit1_pos, res->bit2_pos);
4136 }
4137
4138 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
4139         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
4140                                  "read");
4141 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
4142         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
4143                                  regfield, "regfield");
4144 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
4145         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
4146                               UINT8);
4147 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
4148         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
4149                               UINT32);
4150 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
4151         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
4152                               UINT8);
4153 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
4154         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
4155                               UINT8);
4156
4157 cmdline_parse_inst_t cmd_read_reg_bit_field = {
4158         .f = cmd_read_reg_bit_field_parsed,
4159         .data = NULL,
4160         .help_str = "read regfield port_id reg_off bit_x bit_y "
4161         "(read register bit field between bit_x and bit_y included)",
4162         .tokens = {
4163                 (void *)&cmd_read_reg_bit_field_read,
4164                 (void *)&cmd_read_reg_bit_field_regfield,
4165                 (void *)&cmd_read_reg_bit_field_port_id,
4166                 (void *)&cmd_read_reg_bit_field_reg_off,
4167                 (void *)&cmd_read_reg_bit_field_bit1_pos,
4168                 (void *)&cmd_read_reg_bit_field_bit2_pos,
4169                 NULL,
4170         },
4171 };
4172
4173 /* *** READ PORT REGISTER BIT *** */
4174 struct cmd_read_reg_bit_result {
4175         cmdline_fixed_string_t read;
4176         cmdline_fixed_string_t regbit;
4177         uint8_t port_id;
4178         uint32_t reg_off;
4179         uint8_t bit_pos;
4180 };
4181
4182 static void
4183 cmd_read_reg_bit_parsed(void *parsed_result,
4184                         __attribute__((unused)) struct cmdline *cl,
4185                         __attribute__((unused)) void *data)
4186 {
4187         struct cmd_read_reg_bit_result *res = parsed_result;
4188         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
4189 }
4190
4191 cmdline_parse_token_string_t cmd_read_reg_bit_read =
4192         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
4193 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
4194         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
4195                                  regbit, "regbit");
4196 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
4197         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
4198 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
4199         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
4200 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
4201         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
4202
4203 cmdline_parse_inst_t cmd_read_reg_bit = {
4204         .f = cmd_read_reg_bit_parsed,
4205         .data = NULL,
4206         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
4207         .tokens = {
4208                 (void *)&cmd_read_reg_bit_read,
4209                 (void *)&cmd_read_reg_bit_regbit,
4210                 (void *)&cmd_read_reg_bit_port_id,
4211                 (void *)&cmd_read_reg_bit_reg_off,
4212                 (void *)&cmd_read_reg_bit_bit_pos,
4213                 NULL,
4214         },
4215 };
4216
4217 /* *** WRITE PORT REGISTER *** */
4218 struct cmd_write_reg_result {
4219         cmdline_fixed_string_t write;
4220         cmdline_fixed_string_t reg;
4221         uint8_t port_id;
4222         uint32_t reg_off;
4223         uint32_t value;
4224 };
4225
4226 static void
4227 cmd_write_reg_parsed(void *parsed_result,
4228                      __attribute__((unused)) struct cmdline *cl,
4229                      __attribute__((unused)) void *data)
4230 {
4231         struct cmd_write_reg_result *res = parsed_result;
4232         port_reg_set(res->port_id, res->reg_off, res->value);
4233 }
4234
4235 cmdline_parse_token_string_t cmd_write_reg_write =
4236         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
4237 cmdline_parse_token_string_t cmd_write_reg_reg =
4238         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
4239 cmdline_parse_token_num_t cmd_write_reg_port_id =
4240         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
4241 cmdline_parse_token_num_t cmd_write_reg_reg_off =
4242         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
4243 cmdline_parse_token_num_t cmd_write_reg_value =
4244         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
4245
4246 cmdline_parse_inst_t cmd_write_reg = {
4247         .f = cmd_write_reg_parsed,
4248         .data = NULL,
4249         .help_str = "write reg port_id reg_off reg_value",
4250         .tokens = {
4251                 (void *)&cmd_write_reg_write,
4252                 (void *)&cmd_write_reg_reg,
4253                 (void *)&cmd_write_reg_port_id,
4254                 (void *)&cmd_write_reg_reg_off,
4255                 (void *)&cmd_write_reg_value,
4256                 NULL,
4257         },
4258 };
4259
4260 /* *** WRITE PORT REGISTER BIT FIELD *** */
4261 struct cmd_write_reg_bit_field_result {
4262         cmdline_fixed_string_t write;
4263         cmdline_fixed_string_t regfield;
4264         uint8_t port_id;
4265         uint32_t reg_off;
4266         uint8_t bit1_pos;
4267         uint8_t bit2_pos;
4268         uint32_t value;
4269 };
4270
4271 static void
4272 cmd_write_reg_bit_field_parsed(void *parsed_result,
4273                                __attribute__((unused)) struct cmdline *cl,
4274                                __attribute__((unused)) void *data)
4275 {
4276         struct cmd_write_reg_bit_field_result *res = parsed_result;
4277         port_reg_bit_field_set(res->port_id, res->reg_off,
4278                           res->bit1_pos, res->bit2_pos, res->value);
4279 }
4280
4281 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
4282         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
4283                                  "write");
4284 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
4285         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
4286                                  regfield, "regfield");
4287 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
4288         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
4289                               UINT8);
4290 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
4291         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
4292                               UINT32);
4293 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
4294         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
4295                               UINT8);
4296 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
4297         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
4298                               UINT8);
4299 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
4300         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
4301                               UINT32);
4302
4303 cmdline_parse_inst_t cmd_write_reg_bit_field = {
4304         .f = cmd_write_reg_bit_field_parsed,
4305         .data = NULL,
4306         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
4307         "(set register bit field between bit_x and bit_y included)",
4308         .tokens = {
4309                 (void *)&cmd_write_reg_bit_field_write,
4310                 (void *)&cmd_write_reg_bit_field_regfield,
4311                 (void *)&cmd_write_reg_bit_field_port_id,
4312                 (void *)&cmd_write_reg_bit_field_reg_off,
4313                 (void *)&cmd_write_reg_bit_field_bit1_pos,
4314                 (void *)&cmd_write_reg_bit_field_bit2_pos,
4315                 (void *)&cmd_write_reg_bit_field_value,
4316                 NULL,
4317         },
4318 };
4319
4320 /* *** WRITE PORT REGISTER BIT *** */
4321 struct cmd_write_reg_bit_result {
4322         cmdline_fixed_string_t write;
4323         cmdline_fixed_string_t regbit;
4324         uint8_t port_id;
4325         uint32_t reg_off;
4326         uint8_t bit_pos;
4327         uint8_t value;
4328 };
4329
4330 static void
4331 cmd_write_reg_bit_parsed(void *parsed_result,
4332                          __attribute__((unused)) struct cmdline *cl,
4333                          __attribute__((unused)) void *data)
4334 {
4335         struct cmd_write_reg_bit_result *res = parsed_result;
4336         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
4337 }
4338
4339 cmdline_parse_token_string_t cmd_write_reg_bit_write =
4340         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
4341                                  "write");
4342 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
4343         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
4344                                  regbit, "regbit");
4345 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
4346         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
4347 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
4348         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
4349 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
4350         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
4351 cmdline_parse_token_num_t cmd_write_reg_bit_value =
4352         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
4353
4354 cmdline_parse_inst_t cmd_write_reg_bit = {
4355         .f = cmd_write_reg_bit_parsed,
4356         .data = NULL,
4357         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
4358         .tokens = {
4359                 (void *)&cmd_write_reg_bit_write,
4360                 (void *)&cmd_write_reg_bit_regbit,
4361                 (void *)&cmd_write_reg_bit_port_id,
4362                 (void *)&cmd_write_reg_bit_reg_off,
4363                 (void *)&cmd_write_reg_bit_bit_pos,
4364                 (void *)&cmd_write_reg_bit_value,
4365                 NULL,
4366         },
4367 };
4368
4369 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
4370 struct cmd_read_rxd_txd_result {
4371         cmdline_fixed_string_t read;
4372         cmdline_fixed_string_t rxd_txd;
4373         uint8_t port_id;
4374         uint16_t queue_id;
4375         uint16_t desc_id;
4376 };
4377
4378 static void
4379 cmd_read_rxd_txd_parsed(void *parsed_result,
4380                         __attribute__((unused)) struct cmdline *cl,
4381                         __attribute__((unused)) void *data)
4382 {
4383         struct cmd_read_rxd_txd_result *res = parsed_result;
4384
4385         if (!strcmp(res->rxd_txd, "rxd"))
4386                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4387         else if (!strcmp(res->rxd_txd, "txd"))
4388                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4389 }
4390
4391 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
4392         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
4393 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
4394         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
4395                                  "rxd#txd");
4396 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
4397         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
4398 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
4399         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
4400 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
4401         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
4402
4403 cmdline_parse_inst_t cmd_read_rxd_txd = {
4404         .f = cmd_read_rxd_txd_parsed,
4405         .data = NULL,
4406         .help_str = "read rxd|txd port_id queue_id rxd_id",
4407         .tokens = {
4408                 (void *)&cmd_read_rxd_txd_read,
4409                 (void *)&cmd_read_rxd_txd_rxd_txd,
4410                 (void *)&cmd_read_rxd_txd_port_id,
4411                 (void *)&cmd_read_rxd_txd_queue_id,
4412                 (void *)&cmd_read_rxd_txd_desc_id,
4413                 NULL,
4414         },
4415 };
4416
4417 /* *** QUIT *** */
4418 struct cmd_quit_result {
4419         cmdline_fixed_string_t quit;
4420 };
4421
4422 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
4423                             struct cmdline *cl,
4424                             __attribute__((unused)) void *data)
4425 {
4426         pmd_test_exit();
4427         cmdline_quit(cl);
4428 }
4429
4430 cmdline_parse_token_string_t cmd_quit_quit =
4431         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
4432
4433 cmdline_parse_inst_t cmd_quit = {
4434         .f = cmd_quit_parsed,
4435         .data = NULL,
4436         .help_str = "exit application",
4437         .tokens = {
4438                 (void *)&cmd_quit_quit,
4439                 NULL,
4440         },
4441 };
4442
4443 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
4444 struct cmd_mac_addr_result {
4445         cmdline_fixed_string_t mac_addr_cmd;
4446         cmdline_fixed_string_t what;
4447         uint8_t port_num;
4448         struct ether_addr address;
4449 };
4450
4451 static void cmd_mac_addr_parsed(void *parsed_result,
4452                 __attribute__((unused)) struct cmdline *cl,
4453                 __attribute__((unused)) void *data)
4454 {
4455         struct cmd_mac_addr_result *res = parsed_result;
4456         int ret;
4457
4458         if (strcmp(res->what, "add") == 0)
4459                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
4460         else
4461                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
4462
4463         /* check the return value and print it if is < 0 */
4464         if(ret < 0)
4465                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
4466
4467 }
4468
4469 cmdline_parse_token_string_t cmd_mac_addr_cmd =
4470         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
4471                                 "mac_addr");
4472 cmdline_parse_token_string_t cmd_mac_addr_what =
4473         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
4474                                 "add#remove");
4475 cmdline_parse_token_num_t cmd_mac_addr_portnum =
4476                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
4477 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
4478                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
4479
4480 cmdline_parse_inst_t cmd_mac_addr = {
4481         .f = cmd_mac_addr_parsed,
4482         .data = (void *)0,
4483         .help_str = "mac_addr add|remove X <address>: "
4484                         "add/remove MAC address on port X",
4485         .tokens = {
4486                 (void *)&cmd_mac_addr_cmd,
4487                 (void *)&cmd_mac_addr_what,
4488                 (void *)&cmd_mac_addr_portnum,
4489                 (void *)&cmd_mac_addr_addr,
4490                 NULL,
4491         },
4492 };
4493
4494
4495 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
4496 struct cmd_set_qmap_result {
4497         cmdline_fixed_string_t set;
4498         cmdline_fixed_string_t qmap;
4499         cmdline_fixed_string_t what;
4500         uint8_t port_id;
4501         uint16_t queue_id;
4502         uint8_t map_value;
4503 };
4504
4505 static void
4506 cmd_set_qmap_parsed(void *parsed_result,
4507                        __attribute__((unused)) struct cmdline *cl,
4508                        __attribute__((unused)) void *data)
4509 {
4510         struct cmd_set_qmap_result *res = parsed_result;
4511         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
4512
4513         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
4514 }
4515
4516 cmdline_parse_token_string_t cmd_setqmap_set =
4517         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4518                                  set, "set");
4519 cmdline_parse_token_string_t cmd_setqmap_qmap =
4520         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4521                                  qmap, "stat_qmap");
4522 cmdline_parse_token_string_t cmd_setqmap_what =
4523         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4524                                  what, "tx#rx");
4525 cmdline_parse_token_num_t cmd_setqmap_portid =
4526         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4527                               port_id, UINT8);
4528 cmdline_parse_token_num_t cmd_setqmap_queueid =
4529         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4530                               queue_id, UINT16);
4531 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
4532         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4533                               map_value, UINT8);
4534
4535 cmdline_parse_inst_t cmd_set_qmap = {
4536         .f = cmd_set_qmap_parsed,
4537         .data = NULL,
4538         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
4539         .tokens = {
4540                 (void *)&cmd_setqmap_set,
4541                 (void *)&cmd_setqmap_qmap,
4542                 (void *)&cmd_setqmap_what,
4543                 (void *)&cmd_setqmap_portid,
4544                 (void *)&cmd_setqmap_queueid,
4545                 (void *)&cmd_setqmap_mapvalue,
4546                 NULL,
4547         },
4548 };
4549
4550 /* *** CONFIGURE UNICAST HASH TABLE *** */
4551 struct cmd_set_uc_hash_table {
4552         cmdline_fixed_string_t set;
4553         cmdline_fixed_string_t port;
4554         uint8_t port_id;
4555         cmdline_fixed_string_t what;
4556         struct ether_addr address;
4557         cmdline_fixed_string_t mode;
4558 };
4559
4560 static void
4561 cmd_set_uc_hash_parsed(void *parsed_result,
4562                        __attribute__((unused)) struct cmdline *cl,
4563                        __attribute__((unused)) void *data)
4564 {
4565         int ret=0;
4566         struct cmd_set_uc_hash_table *res = parsed_result;
4567         
4568         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4569         
4570         if (strcmp(res->what, "uta") == 0)
4571                 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 
4572                                                 &res->address,(uint8_t)is_on);
4573         if (ret < 0)
4574                 printf("bad unicast hash table parameter, return code = %d \n", ret);
4575         
4576 }
4577
4578 cmdline_parse_token_string_t cmd_set_uc_hash_set =
4579         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4580                                  set, "set");
4581 cmdline_parse_token_string_t cmd_set_uc_hash_port =
4582         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4583                                  port, "port");
4584 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
4585         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
4586                               port_id, UINT8);
4587 cmdline_parse_token_string_t cmd_set_uc_hash_what =
4588         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4589                                  what, "uta");
4590 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
4591         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 
4592                                 address);
4593 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
4594         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4595                                  mode, "on#off");
4596
4597 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
4598         .f = cmd_set_uc_hash_parsed,
4599         .data = NULL,
4600         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
4601         .tokens = {
4602                 (void *)&cmd_set_uc_hash_set,
4603                 (void *)&cmd_set_uc_hash_port,
4604                 (void *)&cmd_set_uc_hash_portid,
4605                 (void *)&cmd_set_uc_hash_what,
4606                 (void *)&cmd_set_uc_hash_mac,
4607                 (void *)&cmd_set_uc_hash_mode,
4608                 NULL,
4609         },
4610 };
4611
4612 struct cmd_set_uc_all_hash_table {
4613         cmdline_fixed_string_t set;
4614         cmdline_fixed_string_t port;
4615         uint8_t port_id;
4616         cmdline_fixed_string_t what;
4617         cmdline_fixed_string_t value;
4618         cmdline_fixed_string_t mode;
4619 };
4620
4621 static void
4622 cmd_set_uc_all_hash_parsed(void *parsed_result,
4623                        __attribute__((unused)) struct cmdline *cl,
4624                        __attribute__((unused)) void *data)
4625 {
4626         int ret=0;
4627         struct cmd_set_uc_all_hash_table *res = parsed_result;
4628         
4629         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4630         
4631         if ((strcmp(res->what, "uta") == 0) && 
4632                 (strcmp(res->value, "all") == 0))
4633                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
4634         if (ret < 0)
4635                 printf("bad unicast hash table parameter," 
4636                         "return code = %d \n", ret);
4637 }
4638
4639 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
4640         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4641                                  set, "set");
4642 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
4643         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4644                                  port, "port");
4645 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
4646         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
4647                               port_id, UINT8);
4648 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
4649         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4650                                  what, "uta");
4651 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
4652         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 
4653                                 value,"all");
4654 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
4655         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4656                                  mode, "on#off");
4657
4658 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
4659         .f = cmd_set_uc_all_hash_parsed,
4660         .data = NULL,
4661         .help_str = "set port X uta all on|off (X = port number)",
4662         .tokens = {
4663                 (void *)&cmd_set_uc_all_hash_set,
4664                 (void *)&cmd_set_uc_all_hash_port,
4665                 (void *)&cmd_set_uc_all_hash_portid,
4666                 (void *)&cmd_set_uc_all_hash_what,
4667                 (void *)&cmd_set_uc_all_hash_value,
4668                 (void *)&cmd_set_uc_all_hash_mode,
4669                 NULL,
4670         },
4671 };
4672
4673 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
4674 struct cmd_set_vf_traffic {
4675         cmdline_fixed_string_t set;
4676         cmdline_fixed_string_t port;
4677         uint8_t port_id;
4678         cmdline_fixed_string_t vf;
4679         uint8_t vf_id;
4680         cmdline_fixed_string_t what;
4681         cmdline_fixed_string_t mode;
4682 };
4683
4684 static void
4685 cmd_set_vf_traffic_parsed(void *parsed_result,
4686                        __attribute__((unused)) struct cmdline *cl,
4687                        __attribute__((unused)) void *data)
4688 {
4689         struct cmd_set_vf_traffic *res = parsed_result;
4690         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
4691         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4692
4693         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
4694 }
4695
4696 cmdline_parse_token_string_t cmd_setvf_traffic_set =
4697         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4698                                  set, "set");
4699 cmdline_parse_token_string_t cmd_setvf_traffic_port =
4700         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4701                                  port, "port");
4702 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
4703         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4704                               port_id, UINT8);
4705 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
4706         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4707                                  vf, "vf");
4708 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
4709         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4710                               vf_id, UINT8);
4711 cmdline_parse_token_string_t cmd_setvf_traffic_what =
4712         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4713                                  what, "tx#rx");
4714 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
4715         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4716                                  mode, "on#off");
4717
4718 cmdline_parse_inst_t cmd_set_vf_traffic = {
4719         .f = cmd_set_vf_traffic_parsed,
4720         .data = NULL,
4721         .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)",
4722         .tokens = {
4723                 (void *)&cmd_setvf_traffic_set,
4724                 (void *)&cmd_setvf_traffic_port,
4725                 (void *)&cmd_setvf_traffic_portid,
4726                 (void *)&cmd_setvf_traffic_vf,
4727                 (void *)&cmd_setvf_traffic_vfid,
4728                 (void *)&cmd_setvf_traffic_what,
4729                 (void *)&cmd_setvf_traffic_mode,
4730                 NULL,
4731         },
4732 };
4733
4734 /* *** CONFIGURE VF RECEIVE MODE *** */
4735 struct cmd_set_vf_rxmode {
4736         cmdline_fixed_string_t set;
4737         cmdline_fixed_string_t port;
4738         uint8_t port_id;
4739         cmdline_fixed_string_t vf;
4740         uint8_t vf_id;
4741         cmdline_fixed_string_t what;
4742         cmdline_fixed_string_t mode;
4743         cmdline_fixed_string_t on;
4744 };
4745
4746 static void
4747 cmd_set_vf_rxmode_parsed(void *parsed_result,
4748                        __attribute__((unused)) struct cmdline *cl,
4749                        __attribute__((unused)) void *data)
4750 {
4751         int ret;
4752         uint16_t rx_mode = 0;
4753         struct cmd_set_vf_rxmode *res = parsed_result;
4754         
4755         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
4756         if (!strcmp(res->what,"rxmode")) {
4757                 if (!strcmp(res->mode, "AUPE"))
4758                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
4759                 else if (!strcmp(res->mode, "ROPE"))
4760                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
4761                 else if (!strcmp(res->mode, "BAM"))
4762                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
4763                 else if (!strncmp(res->mode, "MPE",3))
4764                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
4765         }
4766
4767         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
4768         if (ret < 0)
4769                 printf("bad VF receive mode parameter, return code = %d \n",
4770                 ret);
4771 }
4772
4773 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
4774         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4775                                  set, "set");
4776 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
4777         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4778                                  port, "port");
4779 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
4780         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4781                               port_id, UINT8);
4782 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
4783         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4784                                  vf, "vf");
4785 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
4786         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4787                               vf_id, UINT8);
4788 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
4789         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4790                                  what, "rxmode");
4791 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
4792         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4793                                  mode, "AUPE#ROPE#BAM#MPE");
4794 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
4795         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4796                                  on, "on#off");
4797
4798 cmdline_parse_inst_t cmd_set_vf_rxmode = {
4799         .f = cmd_set_vf_rxmode_parsed,
4800         .data = NULL,
4801         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
4802         .tokens = {
4803                 (void *)&cmd_set_vf_rxmode_set,
4804                 (void *)&cmd_set_vf_rxmode_port,
4805                 (void *)&cmd_set_vf_rxmode_portid,
4806                 (void *)&cmd_set_vf_rxmode_vf,
4807                 (void *)&cmd_set_vf_rxmode_vfid,
4808                 (void *)&cmd_set_vf_rxmode_what,
4809                 (void *)&cmd_set_vf_rxmode_mode,
4810                 (void *)&cmd_set_vf_rxmode_on,
4811                 NULL,
4812         },
4813 };
4814
4815 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
4816 struct cmd_vf_mac_addr_result {
4817         cmdline_fixed_string_t mac_addr_cmd;
4818         cmdline_fixed_string_t what;
4819         cmdline_fixed_string_t port;
4820         uint8_t port_num;
4821         cmdline_fixed_string_t vf;
4822         uint8_t vf_num;
4823         struct ether_addr address;
4824 };
4825
4826 static void cmd_vf_mac_addr_parsed(void *parsed_result,
4827                 __attribute__((unused)) struct cmdline *cl,
4828                 __attribute__((unused)) void *data)
4829 {
4830         struct cmd_vf_mac_addr_result *res = parsed_result;
4831         int ret = 0;
4832
4833         if (strcmp(res->what, "add") == 0)
4834                 ret = rte_eth_dev_mac_addr_add(res->port_num, 
4835                                         &res->address, res->vf_num);
4836         if(ret < 0)
4837                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
4838
4839 }
4840
4841 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
4842         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4843                                 mac_addr_cmd,"mac_addr");
4844 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
4845         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4846                                 what,"add");
4847 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
4848         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4849                                 port,"port");
4850 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
4851         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 
4852                                 port_num, UINT8);
4853 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
4854         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4855                                 vf,"vf");
4856 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
4857         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
4858                                 vf_num, UINT8);
4859 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
4860         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 
4861                                 address);
4862
4863 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
4864         .f = cmd_vf_mac_addr_parsed,
4865         .data = (void *)0,
4866         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
4867         "Y = VF number)add MAC address filtering for a VF on port X",
4868         .tokens = {
4869                 (void *)&cmd_vf_mac_addr_cmd,
4870                 (void *)&cmd_vf_mac_addr_what,
4871                 (void *)&cmd_vf_mac_addr_port,
4872                 (void *)&cmd_vf_mac_addr_portnum,
4873                 (void *)&cmd_vf_mac_addr_vf,
4874                 (void *)&cmd_vf_mac_addr_vfnum,
4875                 (void *)&cmd_vf_mac_addr_addr,
4876                 NULL,
4877         },
4878 };
4879
4880 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4881 struct cmd_vf_rx_vlan_filter {
4882         cmdline_fixed_string_t rx_vlan;
4883         cmdline_fixed_string_t what;
4884         uint16_t vlan_id;
4885         cmdline_fixed_string_t port;
4886         uint8_t port_id;
4887         cmdline_fixed_string_t vf;
4888         uint64_t vf_mask;
4889 };
4890
4891 static void
4892 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
4893                           __attribute__((unused)) struct cmdline *cl,
4894                           __attribute__((unused)) void *data)
4895 {
4896         struct cmd_vf_rx_vlan_filter *res = parsed_result;
4897
4898         if (!strcmp(res->what, "add"))
4899                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
4900         else
4901                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
4902 }
4903
4904 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
4905         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4906                                  rx_vlan, "rx_vlan");
4907 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
4908         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4909                                  what, "add#rm");
4910 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
4911         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4912                               vlan_id, UINT16);
4913 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
4914         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4915                                  port, "port");
4916 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
4917         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4918                               port_id, UINT8);
4919 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
4920         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4921                                  vf, "vf");
4922 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
4923         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4924                               vf_mask, UINT64);
4925
4926 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
4927         .f = cmd_vf_rx_vlan_filter_parsed,
4928         .data = NULL,
4929         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
4930                 "Y = port number,Z = hexadecimal VF mask)",
4931         .tokens = {
4932                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
4933                 (void *)&cmd_vf_rx_vlan_filter_what,
4934                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
4935                 (void *)&cmd_vf_rx_vlan_filter_port,
4936                 (void *)&cmd_vf_rx_vlan_filter_portid,
4937                 (void *)&cmd_vf_rx_vlan_filter_vf,
4938                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
4939                 NULL,
4940         },
4941 };
4942
4943 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
4944 struct cmd_set_mirror_mask_result {
4945         cmdline_fixed_string_t set;
4946         cmdline_fixed_string_t port;
4947         uint8_t port_id;
4948         cmdline_fixed_string_t mirror;
4949         uint8_t rule_id;
4950         cmdline_fixed_string_t what;
4951         cmdline_fixed_string_t value;
4952         cmdline_fixed_string_t dstpool;
4953         uint8_t dstpool_id;
4954         cmdline_fixed_string_t on;
4955 };
4956
4957 cmdline_parse_token_string_t cmd_mirror_mask_set =
4958         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4959                                 set, "set");
4960 cmdline_parse_token_string_t cmd_mirror_mask_port =
4961         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4962                                 port, "port");
4963 cmdline_parse_token_string_t cmd_mirror_mask_portid =
4964         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4965                                 port_id, UINT8);
4966 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
4967         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4968                                 mirror, "mirror-rule");
4969 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
4970         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4971                                 rule_id, UINT8);
4972 cmdline_parse_token_string_t cmd_mirror_mask_what =
4973         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4974                                 what, "pool-mirror#vlan-mirror");
4975 cmdline_parse_token_string_t cmd_mirror_mask_value =
4976         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4977                                 value, NULL);
4978 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
4979         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4980                                 dstpool, "dst-pool");
4981 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
4982         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4983                                 dstpool_id, UINT8);
4984 cmdline_parse_token_string_t cmd_mirror_mask_on =
4985         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4986                                 on, "on#off");
4987
4988 static void
4989 cmd_set_mirror_mask_parsed(void *parsed_result,
4990                        __attribute__((unused)) struct cmdline *cl,
4991                        __attribute__((unused)) void *data)
4992 {
4993         int ret,nb_item,i;
4994         struct cmd_set_mirror_mask_result *res = parsed_result;
4995         struct rte_eth_vmdq_mirror_conf mr_conf;
4996
4997         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
4998
4999         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
5000
5001         mr_conf.dst_pool = res->dstpool_id;
5002
5003         if (!strcmp(res->what, "pool-mirror")) {
5004                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
5005                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
5006         } else if(!strcmp(res->what, "vlan-mirror")) {
5007                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
5008                 nb_item = parse_item_list(res->value, "core",
5009                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
5010                 if (nb_item <= 0)
5011                         return;
5012
5013                 for(i=0; i < nb_item; i++) {
5014                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
5015                                 printf("Invalid vlan_id: must be < 4096\n");
5016                                 return;
5017                         }
5018
5019                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
5020                         mr_conf.vlan.vlan_mask |= 1ULL << i;
5021                 }
5022         }
5023
5024         if(!strcmp(res->on, "on"))
5025                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5026                                                 res->rule_id, 1);
5027         else
5028                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5029                                                 res->rule_id, 0);
5030         if(ret < 0)
5031                 printf("mirror rule add error: (%s)\n", strerror(-ret));
5032 }
5033
5034 cmdline_parse_inst_t cmd_set_mirror_mask = {
5035                 .f = cmd_set_mirror_mask_parsed,
5036                 .data = NULL,
5037                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror " 
5038                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
5039                 .tokens = {
5040                         (void *)&cmd_mirror_mask_set,
5041                         (void *)&cmd_mirror_mask_port,
5042                         (void *)&cmd_mirror_mask_portid,
5043                         (void *)&cmd_mirror_mask_mirror,
5044                         (void *)&cmd_mirror_mask_ruleid,
5045                         (void *)&cmd_mirror_mask_what,
5046                         (void *)&cmd_mirror_mask_value,
5047                         (void *)&cmd_mirror_mask_dstpool,
5048                         (void *)&cmd_mirror_mask_poolid,
5049                         (void *)&cmd_mirror_mask_on,
5050                         NULL,
5051                 },
5052 };
5053
5054 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
5055 struct cmd_set_mirror_link_result {
5056         cmdline_fixed_string_t set;
5057         cmdline_fixed_string_t port;
5058         uint8_t port_id;
5059         cmdline_fixed_string_t mirror;
5060         uint8_t rule_id;
5061         cmdline_fixed_string_t what;
5062         cmdline_fixed_string_t dstpool;
5063         uint8_t dstpool_id;
5064         cmdline_fixed_string_t on;
5065 };
5066
5067 cmdline_parse_token_string_t cmd_mirror_link_set =
5068         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5069                                  set, "set");
5070 cmdline_parse_token_string_t cmd_mirror_link_port =
5071         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5072                                 port, "port");
5073 cmdline_parse_token_string_t cmd_mirror_link_portid =
5074         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5075                                 port_id, UINT8);
5076 cmdline_parse_token_string_t cmd_mirror_link_mirror =
5077         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5078                                 mirror, "mirror-rule");
5079 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
5080         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5081                             rule_id, UINT8);
5082 cmdline_parse_token_string_t cmd_mirror_link_what =
5083         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5084                                 what, "uplink-mirror#downlink-mirror");
5085 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
5086         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5087                                 dstpool, "dst-pool");
5088 cmdline_parse_token_num_t cmd_mirror_link_poolid =
5089         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5090                                 dstpool_id, UINT8);
5091 cmdline_parse_token_string_t cmd_mirror_link_on =
5092         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5093                                 on, "on#off");
5094
5095 static void
5096 cmd_set_mirror_link_parsed(void *parsed_result,
5097                        __attribute__((unused)) struct cmdline *cl,
5098                        __attribute__((unused)) void *data)
5099 {
5100         int ret;
5101         struct cmd_set_mirror_link_result *res = parsed_result;
5102         struct rte_eth_vmdq_mirror_conf mr_conf;
5103
5104         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
5105         if(!strcmp(res->what, "uplink-mirror")) {
5106                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
5107         }else if(!strcmp(res->what, "downlink-mirror"))
5108                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
5109
5110         mr_conf.dst_pool = res->dstpool_id;
5111
5112         if(!strcmp(res->on, "on"))
5113                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5114                                                 res->rule_id, 1);
5115         else
5116                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5117                                                 res->rule_id, 0);
5118
5119         /* check the return value and print it if is < 0 */
5120         if(ret < 0)
5121                 printf("mirror rule add error: (%s)\n", strerror(-ret));
5122
5123 }
5124
5125 cmdline_parse_inst_t cmd_set_mirror_link = {
5126                 .f = cmd_set_mirror_link_parsed,
5127                 .data = NULL,
5128                 .help_str = "set port X mirror-rule Y uplink-mirror|"
5129                         "downlink-mirror dst-pool Z on|off",
5130                 .tokens = {
5131                         (void *)&cmd_mirror_link_set,
5132                         (void *)&cmd_mirror_link_port,
5133                         (void *)&cmd_mirror_link_portid,
5134                         (void *)&cmd_mirror_link_mirror,
5135                         (void *)&cmd_mirror_link_ruleid,
5136                         (void *)&cmd_mirror_link_what,
5137                         (void *)&cmd_mirror_link_dstpool,
5138                         (void *)&cmd_mirror_link_poolid,
5139                         (void *)&cmd_mirror_link_on,
5140                         NULL,
5141                 },
5142 };
5143
5144 /* *** RESET VM MIRROR RULE *** */
5145 struct cmd_rm_mirror_rule_result {
5146         cmdline_fixed_string_t reset;
5147         cmdline_fixed_string_t port;
5148         uint8_t port_id;
5149         cmdline_fixed_string_t mirror;
5150         uint8_t rule_id;
5151 };
5152
5153 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
5154         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5155                                  reset, "reset");
5156 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
5157         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5158                                 port, "port");
5159 cmdline_parse_token_string_t cmd_rm_mirror_rule_portid =
5160         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
5161                                 port_id, UINT8);
5162 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
5163         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5164                                 mirror, "mirror-rule");
5165 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
5166         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
5167                                 rule_id, UINT8);
5168
5169 static void
5170 cmd_reset_mirror_rule_parsed(void *parsed_result,
5171                        __attribute__((unused)) struct cmdline *cl,
5172                        __attribute__((unused)) void *data)
5173 {
5174         int ret;
5175         struct cmd_set_mirror_link_result *res = parsed_result;
5176         /* check rule_id */
5177         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
5178         if(ret < 0)
5179                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
5180 }
5181
5182 cmdline_parse_inst_t cmd_reset_mirror_rule = {
5183                 .f = cmd_reset_mirror_rule_parsed,
5184                 .data = NULL,
5185                 .help_str = "reset port X mirror-rule Y",
5186                 .tokens = {
5187                         (void *)&cmd_rm_mirror_rule_reset,
5188                         (void *)&cmd_rm_mirror_rule_port,
5189                         (void *)&cmd_rm_mirror_rule_portid,
5190                         (void *)&cmd_rm_mirror_rule_mirror,
5191                         (void *)&cmd_rm_mirror_rule_ruleid,
5192                         NULL,
5193                 },
5194 };
5195
5196 /* ******************************************************************************** */
5197
5198 struct cmd_dump_result {
5199         cmdline_fixed_string_t dump;
5200 };
5201
5202 static void
5203 dump_struct_sizes(void)
5204 {
5205 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
5206         DUMP_SIZE(struct rte_mbuf);
5207         DUMP_SIZE(struct rte_pktmbuf);
5208         DUMP_SIZE(struct rte_ctrlmbuf);
5209         DUMP_SIZE(struct rte_mempool);
5210         DUMP_SIZE(struct rte_ring);
5211 #undef DUMP_SIZE
5212 }
5213
5214 static void cmd_dump_parsed(void *parsed_result,
5215                             __attribute__((unused)) struct cmdline *cl,
5216                             __attribute__((unused)) void *data)
5217 {
5218         struct cmd_dump_result *res = parsed_result;
5219
5220         if (!strcmp(res->dump, "dump_physmem"))
5221                 rte_dump_physmem_layout(stdout);
5222         else if (!strcmp(res->dump, "dump_memzone"))
5223                 rte_memzone_dump(stdout);
5224         else if (!strcmp(res->dump, "dump_log_history"))
5225                 rte_log_dump_history(stdout);
5226         else if (!strcmp(res->dump, "dump_struct_sizes"))
5227                 dump_struct_sizes();
5228         else if (!strcmp(res->dump, "dump_ring"))
5229                 rte_ring_list_dump(stdout);
5230         else if (!strcmp(res->dump, "dump_mempool"))
5231                 rte_mempool_list_dump(stdout);
5232         else if (!strcmp(res->dump, "dump_devargs"))
5233                 rte_eal_devargs_dump(stdout);
5234 }
5235
5236 cmdline_parse_token_string_t cmd_dump_dump =
5237         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
5238                 "dump_physmem#"
5239                 "dump_memzone#"
5240                 "dump_log_history#"
5241                 "dump_struct_sizes#"
5242                 "dump_ring#"
5243                 "dump_mempool#"
5244                 "dump_devargs");
5245
5246 cmdline_parse_inst_t cmd_dump = {
5247         .f = cmd_dump_parsed,  /* function to call */
5248         .data = NULL,      /* 2nd arg of func */
5249         .help_str = "dump status",
5250         .tokens = {        /* token list, NULL terminated */
5251                 (void *)&cmd_dump_dump,
5252                 NULL,
5253         },
5254 };
5255
5256 /* ******************************************************************************** */
5257
5258 struct cmd_dump_one_result {
5259         cmdline_fixed_string_t dump;
5260         cmdline_fixed_string_t name;
5261 };
5262
5263 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
5264                                 __attribute__((unused)) void *data)
5265 {
5266         struct cmd_dump_one_result *res = parsed_result;
5267
5268         if (!strcmp(res->dump, "dump_ring")) {
5269                 struct rte_ring *r;
5270                 r = rte_ring_lookup(res->name);
5271                 if (r == NULL) {
5272                         cmdline_printf(cl, "Cannot find ring\n");
5273                         return;
5274                 }
5275                 rte_ring_dump(stdout, r);
5276         } else if (!strcmp(res->dump, "dump_mempool")) {
5277                 struct rte_mempool *mp;
5278                 mp = rte_mempool_lookup(res->name);
5279                 if (mp == NULL) {
5280                         cmdline_printf(cl, "Cannot find mempool\n");
5281                         return;
5282                 }
5283                 rte_mempool_dump(stdout, mp);
5284         }
5285 }
5286
5287 cmdline_parse_token_string_t cmd_dump_one_dump =
5288         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
5289                                  "dump_ring#dump_mempool");
5290
5291 cmdline_parse_token_string_t cmd_dump_one_name =
5292         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
5293
5294 cmdline_parse_inst_t cmd_dump_one = {
5295         .f = cmd_dump_one_parsed,  /* function to call */
5296         .data = NULL,      /* 2nd arg of func */
5297         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
5298         .tokens = {        /* token list, NULL terminated */
5299                 (void *)&cmd_dump_one_dump,
5300                 (void *)&cmd_dump_one_name,
5301                 NULL,
5302         },
5303 };
5304
5305 /* ******************************************************************************** */
5306
5307 /* list of instructions */
5308 cmdline_parse_ctx_t main_ctx[] = {
5309         (cmdline_parse_inst_t *)&cmd_help_brief,
5310         (cmdline_parse_inst_t *)&cmd_help_long,
5311         (cmdline_parse_inst_t *)&cmd_quit,
5312         (cmdline_parse_inst_t *)&cmd_showport,
5313         (cmdline_parse_inst_t *)&cmd_showportall,
5314         (cmdline_parse_inst_t *)&cmd_showcfg,
5315         (cmdline_parse_inst_t *)&cmd_start,
5316         (cmdline_parse_inst_t *)&cmd_start_tx_first,
5317         (cmdline_parse_inst_t *)&cmd_reset,
5318         (cmdline_parse_inst_t *)&cmd_set_numbers,
5319         (cmdline_parse_inst_t *)&cmd_set_txpkts,
5320         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
5321         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
5322         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
5323         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
5324         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
5325         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
5326         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
5327         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
5328         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
5329         (cmdline_parse_inst_t *)&cmd_set_link_check,
5330 #ifdef RTE_NIC_BYPASS
5331         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
5332         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
5333         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
5334         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
5335 #endif
5336         (cmdline_parse_inst_t *)&cmd_vlan_offload,
5337         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
5338         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
5339         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
5340         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
5341         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
5342         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
5343         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
5344         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
5345         (cmdline_parse_inst_t *)&cmd_config_dcb,
5346         (cmdline_parse_inst_t *)&cmd_read_reg,
5347         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
5348         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
5349         (cmdline_parse_inst_t *)&cmd_write_reg,
5350         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
5351         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
5352         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
5353         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
5354         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
5355         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
5356         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
5357         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
5358         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
5359         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
5360         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
5361         (cmdline_parse_inst_t *)&cmd_stop,
5362         (cmdline_parse_inst_t *)&cmd_mac_addr,
5363         (cmdline_parse_inst_t *)&cmd_set_qmap,
5364         (cmdline_parse_inst_t *)&cmd_operate_port,
5365         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
5366         (cmdline_parse_inst_t *)&cmd_config_speed_all,
5367         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
5368         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
5369         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
5370         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
5371         (cmdline_parse_inst_t *)&cmd_config_rss,
5372         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
5373         (cmdline_parse_inst_t *)&cmd_showport_reta,
5374         (cmdline_parse_inst_t *)&cmd_config_burst,
5375         (cmdline_parse_inst_t *)&cmd_config_thresh,
5376         (cmdline_parse_inst_t *)&cmd_config_threshold,
5377         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
5378         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
5379         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
5380         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
5381         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
5382         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
5383         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
5384         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
5385         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
5386         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
5387         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
5388         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
5389         (cmdline_parse_inst_t *)&cmd_dump,
5390         (cmdline_parse_inst_t *)&cmd_dump_one,
5391         NULL,
5392 };
5393
5394 /* prompt function, called from main on MASTER lcore */
5395 void
5396 prompt(void)
5397 {
5398         struct cmdline *cl;
5399
5400         /* initialize non-constant commands */
5401         cmd_set_fwd_mode_init();
5402
5403         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
5404         if (cl == NULL) {
5405                 return;
5406         }
5407         cmdline_interact(cl);
5408         cmdline_stdin_exit(cl);
5409 }
5410
5411 static void
5412 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
5413 {
5414         if (id < nb_ports) {
5415                 /* check if need_reconfig has been set to 1 */
5416                 if (ports[id].need_reconfig == 0)
5417                         ports[id].need_reconfig = dev;
5418                 /* check if need_reconfig_queues has been set to 1 */
5419                 if (ports[id].need_reconfig_queues == 0)
5420                         ports[id].need_reconfig_queues = queue;
5421         } else {
5422                 portid_t pid;
5423
5424                 for (pid = 0; pid < nb_ports; pid++) {
5425                         /* check if need_reconfig has been set to 1 */
5426                         if (ports[pid].need_reconfig == 0)
5427                                 ports[pid].need_reconfig = dev;
5428                         /* check if need_reconfig_queues has been set to 1 */
5429                         if (ports[pid].need_reconfig_queues == 0)
5430                                 ports[pid].need_reconfig_queues = queue;
5431                 }
5432         }
5433 }
5434
5435 #ifdef RTE_NIC_BYPASS
5436 uint8_t
5437 bypass_is_supported(portid_t port_id)
5438 {
5439         struct rte_port   *port;
5440         struct rte_pci_id *pci_id;
5441
5442         if (port_id >= nb_ports) {
5443                 printf("\tPort id must be less than %d.\n", nb_ports);
5444                 return 0;
5445         }
5446
5447         /* Get the device id. */
5448         port    = &ports[port_id];
5449         pci_id = &port->dev_info.pci_dev->id;
5450
5451         /* Check if NIC supports bypass. */
5452         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
5453                 return 1;
5454         }
5455         else {
5456                 printf("\tBypass not supported for port_id = %d.\n", port_id);
5457                 return 0;
5458         }
5459 }
5460 #endif