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