app/testpmd: list forwarding engines
[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 #ifdef RTE_NIC_BYPASS
2332 /* *** SET NIC BYPASS MODE *** */
2333 struct cmd_set_bypass_mode_result {
2334         cmdline_fixed_string_t set;
2335         cmdline_fixed_string_t bypass;
2336         cmdline_fixed_string_t mode;
2337         cmdline_fixed_string_t value;
2338         uint8_t port_id;
2339 };
2340
2341 static void
2342 cmd_set_bypass_mode_parsed(void *parsed_result,
2343                 __attribute__((unused)) struct cmdline *cl,
2344                 __attribute__((unused)) void *data)
2345 {
2346         struct cmd_set_bypass_mode_result *res = parsed_result;
2347         portid_t port_id = res->port_id;
2348         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2349
2350         if (!bypass_is_supported(port_id))
2351                 return;
2352
2353         if (!strcmp(res->value, "bypass"))
2354                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2355         else if (!strcmp(res->value, "isolate"))
2356                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2357         else
2358                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2359
2360         /* Set the bypass mode for the relevant port. */
2361         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
2362                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
2363         }
2364 }
2365
2366 cmdline_parse_token_string_t cmd_setbypass_mode_set =
2367         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2368                         set, "set");
2369 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
2370         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2371                         bypass, "bypass");
2372 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
2373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2374                         mode, "mode");
2375 cmdline_parse_token_string_t cmd_setbypass_mode_value =
2376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2377                         value, "normal#bypass#isolate");
2378 cmdline_parse_token_num_t cmd_setbypass_mode_port =
2379         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
2380                                 port_id, UINT8);
2381
2382 cmdline_parse_inst_t cmd_set_bypass_mode = {
2383         .f = cmd_set_bypass_mode_parsed,
2384         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
2385                     "Set the NIC bypass mode for port_id",
2386         .data = NULL,
2387         .tokens = {
2388                 (void *)&cmd_setbypass_mode_set,
2389                 (void *)&cmd_setbypass_mode_bypass,
2390                 (void *)&cmd_setbypass_mode_mode,
2391                 (void *)&cmd_setbypass_mode_value,
2392                 (void *)&cmd_setbypass_mode_port,
2393                 NULL,
2394         },
2395 };
2396
2397 /* *** SET NIC BYPASS EVENT *** */
2398 struct cmd_set_bypass_event_result {
2399         cmdline_fixed_string_t set;
2400         cmdline_fixed_string_t bypass;
2401         cmdline_fixed_string_t event;
2402         cmdline_fixed_string_t event_value;
2403         cmdline_fixed_string_t mode;
2404         cmdline_fixed_string_t mode_value;
2405         uint8_t port_id;
2406 };
2407
2408 static void
2409 cmd_set_bypass_event_parsed(void *parsed_result,
2410                 __attribute__((unused)) struct cmdline *cl,
2411                 __attribute__((unused)) void *data)
2412 {
2413         int32_t rc;
2414         struct cmd_set_bypass_event_result *res = parsed_result;
2415         portid_t port_id = res->port_id;
2416         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
2417         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2418
2419         if (!bypass_is_supported(port_id))
2420                 return;
2421
2422         if (!strcmp(res->event_value, "timeout"))
2423                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
2424         else if (!strcmp(res->event_value, "os_on"))
2425                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
2426         else if (!strcmp(res->event_value, "os_off"))
2427                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
2428         else if (!strcmp(res->event_value, "power_on"))
2429                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
2430         else if (!strcmp(res->event_value, "power_off"))
2431                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
2432         else
2433                 bypass_event = RTE_BYPASS_EVENT_NONE;
2434
2435         if (!strcmp(res->mode_value, "bypass"))
2436                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2437         else if (!strcmp(res->mode_value, "isolate"))
2438                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2439         else
2440                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2441
2442         /* Set the watchdog timeout. */
2443         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
2444
2445                 rc = -EINVAL;
2446                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
2447                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
2448                                 bypass_timeout)) != 0) {
2449                         printf("Failed to set timeout value %u "
2450                                 "for port %d, errto code: %d.\n",
2451                                 bypass_timeout, port_id, rc);
2452                 }
2453         }
2454
2455         /* Set the bypass event to transition to bypass mode. */
2456         if (0 != rte_eth_dev_bypass_event_store(port_id,
2457                         bypass_event, bypass_mode)) {
2458                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
2459         }
2460
2461 }
2462
2463 cmdline_parse_token_string_t cmd_setbypass_event_set =
2464         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2465                         set, "set");
2466 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
2467         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2468                         bypass, "bypass");
2469 cmdline_parse_token_string_t cmd_setbypass_event_event =
2470         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2471                         event, "event");
2472 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
2473         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2474                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
2475 cmdline_parse_token_string_t cmd_setbypass_event_mode =
2476         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2477                         mode, "mode");
2478 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
2479         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2480                         mode_value, "normal#bypass#isolate");
2481 cmdline_parse_token_num_t cmd_setbypass_event_port =
2482         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
2483                                 port_id, UINT8);
2484
2485 cmdline_parse_inst_t cmd_set_bypass_event = {
2486         .f = cmd_set_bypass_event_parsed,
2487         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
2488                     "mode (normal|bypass|isolate) (port_id): "
2489                     "Set the NIC bypass event mode for port_id",
2490         .data = NULL,
2491         .tokens = {
2492                 (void *)&cmd_setbypass_event_set,
2493                 (void *)&cmd_setbypass_event_bypass,
2494                 (void *)&cmd_setbypass_event_event,
2495                 (void *)&cmd_setbypass_event_event_value,
2496                 (void *)&cmd_setbypass_event_mode,
2497                 (void *)&cmd_setbypass_event_mode_value,
2498                 (void *)&cmd_setbypass_event_port,
2499                 NULL,
2500         },
2501 };
2502
2503
2504 /* *** SET NIC BYPASS TIMEOUT *** */
2505 struct cmd_set_bypass_timeout_result {
2506         cmdline_fixed_string_t set;
2507         cmdline_fixed_string_t bypass;
2508         cmdline_fixed_string_t timeout;
2509         cmdline_fixed_string_t value;
2510 };
2511
2512 static void
2513 cmd_set_bypass_timeout_parsed(void *parsed_result,
2514                 __attribute__((unused)) struct cmdline *cl,
2515                 __attribute__((unused)) void *data)
2516 {
2517         struct cmd_set_bypass_timeout_result *res = parsed_result;
2518
2519         if (!strcmp(res->value, "1.5"))
2520                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
2521         else if (!strcmp(res->value, "2"))
2522                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
2523         else if (!strcmp(res->value, "3"))
2524                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
2525         else if (!strcmp(res->value, "4"))
2526                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
2527         else if (!strcmp(res->value, "8"))
2528                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
2529         else if (!strcmp(res->value, "16"))
2530                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
2531         else if (!strcmp(res->value, "32"))
2532                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
2533         else
2534                 bypass_timeout = RTE_BYPASS_TMT_OFF;
2535 }
2536
2537 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
2538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2539                         set, "set");
2540 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
2541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2542                         bypass, "bypass");
2543 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
2544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2545                         timeout, "timeout");
2546 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
2547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2548                         value, "0#1.5#2#3#4#8#16#32");
2549
2550 cmdline_parse_inst_t cmd_set_bypass_timeout = {
2551         .f = cmd_set_bypass_timeout_parsed,
2552         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
2553                     "Set the NIC bypass watchdog timeout",
2554         .data = NULL,
2555         .tokens = {
2556                 (void *)&cmd_setbypass_timeout_set,
2557                 (void *)&cmd_setbypass_timeout_bypass,
2558                 (void *)&cmd_setbypass_timeout_timeout,
2559                 (void *)&cmd_setbypass_timeout_value,
2560                 NULL,
2561         },
2562 };
2563
2564 /* *** SHOW NIC BYPASS MODE *** */
2565 struct cmd_show_bypass_config_result {
2566         cmdline_fixed_string_t show;
2567         cmdline_fixed_string_t bypass;
2568         cmdline_fixed_string_t config;
2569         uint8_t port_id;
2570 };
2571
2572 static void
2573 cmd_show_bypass_config_parsed(void *parsed_result,
2574                 __attribute__((unused)) struct cmdline *cl,
2575                 __attribute__((unused)) void *data)
2576 {
2577         struct cmd_show_bypass_config_result *res = parsed_result;
2578         uint32_t event_mode;
2579         uint32_t bypass_mode;
2580         portid_t port_id = res->port_id;
2581         uint32_t timeout = bypass_timeout;
2582         int i;
2583
2584         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
2585                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
2586         static const char * const modes[RTE_BYPASS_MODE_NUM] =
2587                 {"UNKNOWN", "normal", "bypass", "isolate"};
2588         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
2589                 "NONE",
2590                 "OS/board on",
2591                 "power supply on",
2592                 "OS/board off",
2593                 "power supply off",
2594                 "timeout"};
2595         int num_events = (sizeof events) / (sizeof events[0]);
2596
2597         if (!bypass_is_supported(port_id))
2598                 return;
2599
2600         /* Display the bypass mode.*/
2601         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
2602                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
2603                 return;
2604         }
2605         else {
2606                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
2607                         bypass_mode = RTE_BYPASS_MODE_NONE;
2608
2609                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
2610         }
2611
2612         /* Display the bypass timeout.*/
2613         if (!RTE_BYPASS_TMT_VALID(timeout))
2614                 timeout = RTE_BYPASS_TMT_OFF;
2615
2616         printf("\tbypass timeout = %s\n", timeouts[timeout]);
2617
2618         /* Display the bypass events and associated modes. */
2619         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
2620
2621                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
2622                         printf("\tFailed to get bypass mode for event = %s\n",
2623                                 events[i]);
2624                 } else {
2625                         if (!RTE_BYPASS_MODE_VALID(event_mode))
2626                                 event_mode = RTE_BYPASS_MODE_NONE;
2627
2628                         printf("\tbypass event: %-16s = %s\n", events[i],
2629                                 modes[event_mode]);
2630                 }
2631         }
2632 }
2633
2634 cmdline_parse_token_string_t cmd_showbypass_config_show =
2635         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2636                         show, "show");
2637 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
2638         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2639                         bypass, "bypass");
2640 cmdline_parse_token_string_t cmd_showbypass_config_config =
2641         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2642                         config, "config");
2643 cmdline_parse_token_num_t cmd_showbypass_config_port =
2644         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
2645                                 port_id, UINT8);
2646
2647 cmdline_parse_inst_t cmd_show_bypass_config = {
2648         .f = cmd_show_bypass_config_parsed,
2649         .help_str = "show bypass config (port_id): "
2650                     "Show the NIC bypass config for port_id",
2651         .data = NULL,
2652         .tokens = {
2653                 (void *)&cmd_showbypass_config_show,
2654                 (void *)&cmd_showbypass_config_bypass,
2655                 (void *)&cmd_showbypass_config_config,
2656                 (void *)&cmd_showbypass_config_port,
2657                 NULL,
2658         },
2659 };
2660 #endif
2661
2662 /* *** SET FORWARDING MODE *** */
2663 struct cmd_set_fwd_mode_result {
2664         cmdline_fixed_string_t set;
2665         cmdline_fixed_string_t fwd;
2666         cmdline_fixed_string_t mode;
2667 };
2668
2669 static void cmd_set_fwd_mode_parsed(void *parsed_result,
2670                                     __attribute__((unused)) struct cmdline *cl,
2671                                     __attribute__((unused)) void *data)
2672 {
2673         struct cmd_set_fwd_mode_result *res = parsed_result;
2674
2675         set_pkt_forwarding_mode(res->mode);
2676 }
2677
2678 cmdline_parse_token_string_t cmd_setfwd_set =
2679         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
2680 cmdline_parse_token_string_t cmd_setfwd_fwd =
2681         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
2682 cmdline_parse_token_string_t cmd_setfwd_mode =
2683         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
2684                 "" /* defined at init */);
2685
2686 cmdline_parse_inst_t cmd_set_fwd_mode = {
2687         .f = cmd_set_fwd_mode_parsed,
2688         .data = NULL,
2689         .help_str = NULL, /* defined at init */
2690         .tokens = {
2691                 (void *)&cmd_setfwd_set,
2692                 (void *)&cmd_setfwd_fwd,
2693                 (void *)&cmd_setfwd_mode,
2694                 NULL,
2695         },
2696 };
2697
2698 static void cmd_set_fwd_mode_init(void)
2699 {
2700         char *modes, *c;
2701         static char token[128];
2702         static char help[256];
2703         cmdline_parse_token_string_t *token_struct;
2704
2705         modes = list_pkt_forwarding_modes();
2706         rte_snprintf(help, sizeof help, "set fwd %s - "
2707                 "set packet forwarding mode", modes);
2708         cmd_set_fwd_mode.help_str = help;
2709
2710         /* string token separator is # */
2711         for (c = token; *modes != '\0'; modes++)
2712                 if (*modes == '|')
2713                         *c++ = '#';
2714                 else
2715                         *c++ = *modes;
2716         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
2717         token_struct->string_data.str = token;
2718 }
2719
2720 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
2721 struct cmd_set_burst_tx_retry_result {
2722         cmdline_fixed_string_t set;
2723         cmdline_fixed_string_t burst;
2724         cmdline_fixed_string_t tx;
2725         cmdline_fixed_string_t delay;
2726         uint32_t time;
2727         cmdline_fixed_string_t retry;
2728         uint32_t retry_num;
2729 };
2730
2731 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
2732                                         __attribute__((unused)) struct cmdline *cl,
2733                                         __attribute__((unused)) void *data)
2734 {
2735         struct cmd_set_burst_tx_retry_result *res = parsed_result;
2736
2737         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
2738                 && !strcmp(res->tx, "tx")) {
2739                 if (!strcmp(res->delay, "delay"))
2740                         burst_tx_delay_time = res->time;        
2741                 if (!strcmp(res->retry, "retry"))
2742                         burst_tx_retry_num = res->retry_num;    
2743         }
2744
2745 }
2746
2747 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
2748         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
2749 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
2750         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
2751                                  "burst");
2752 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
2753         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
2754 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
2755         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
2756 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
2757         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
2758 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
2759         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
2760 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
2761         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
2762
2763 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
2764         .f = cmd_set_burst_tx_retry_parsed,
2765         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
2766         .tokens = {
2767                 (void *)&cmd_set_burst_tx_retry_set,
2768                 (void *)&cmd_set_burst_tx_retry_burst,
2769                 (void *)&cmd_set_burst_tx_retry_tx,
2770                 (void *)&cmd_set_burst_tx_retry_delay,
2771                 (void *)&cmd_set_burst_tx_retry_time,
2772                 (void *)&cmd_set_burst_tx_retry_retry,
2773                 (void *)&cmd_set_burst_tx_retry_retry_num,
2774                 NULL,
2775         },
2776 };
2777
2778 /* *** SET PROMISC MODE *** */
2779 struct cmd_set_promisc_mode_result {
2780         cmdline_fixed_string_t set;
2781         cmdline_fixed_string_t promisc;
2782         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2783         uint8_t port_num;                /* valid if "allports" argument == 0 */
2784         cmdline_fixed_string_t mode;
2785 };
2786
2787 static void cmd_set_promisc_mode_parsed(void *parsed_result,
2788                                         __attribute__((unused)) struct cmdline *cl,
2789                                         void *allports)
2790 {
2791         struct cmd_set_promisc_mode_result *res = parsed_result;
2792         int enable;
2793         portid_t i;
2794
2795         if (!strcmp(res->mode, "on"))
2796                 enable = 1;
2797         else
2798                 enable = 0;
2799
2800         /* all ports */
2801         if (allports) {
2802                 for (i = 0; i < nb_ports; i++) {
2803                         if (enable)
2804                                 rte_eth_promiscuous_enable(i);
2805                         else
2806                                 rte_eth_promiscuous_disable(i);
2807                 }
2808         }
2809         else {
2810                 if (enable)
2811                         rte_eth_promiscuous_enable(res->port_num);
2812                 else
2813                         rte_eth_promiscuous_disable(res->port_num);
2814         }
2815 }
2816
2817 cmdline_parse_token_string_t cmd_setpromisc_set =
2818         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
2819 cmdline_parse_token_string_t cmd_setpromisc_promisc =
2820         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
2821                                  "promisc");
2822 cmdline_parse_token_string_t cmd_setpromisc_portall =
2823         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
2824                                  "all");
2825 cmdline_parse_token_num_t cmd_setpromisc_portnum =
2826         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
2827                               UINT8);
2828 cmdline_parse_token_string_t cmd_setpromisc_mode =
2829         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
2830                                  "on#off");
2831
2832 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
2833         .f = cmd_set_promisc_mode_parsed,
2834         .data = (void *)1,
2835         .help_str = "set promisc all on|off: set promisc mode for all ports",
2836         .tokens = {
2837                 (void *)&cmd_setpromisc_set,
2838                 (void *)&cmd_setpromisc_promisc,
2839                 (void *)&cmd_setpromisc_portall,
2840                 (void *)&cmd_setpromisc_mode,
2841                 NULL,
2842         },
2843 };
2844
2845 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
2846         .f = cmd_set_promisc_mode_parsed,
2847         .data = (void *)0,
2848         .help_str = "set promisc X on|off: set promisc mode on port X",
2849         .tokens = {
2850                 (void *)&cmd_setpromisc_set,
2851                 (void *)&cmd_setpromisc_promisc,
2852                 (void *)&cmd_setpromisc_portnum,
2853                 (void *)&cmd_setpromisc_mode,
2854                 NULL,
2855         },
2856 };
2857
2858 /* *** SET ALLMULTI MODE *** */
2859 struct cmd_set_allmulti_mode_result {
2860         cmdline_fixed_string_t set;
2861         cmdline_fixed_string_t allmulti;
2862         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2863         uint8_t port_num;                /* valid if "allports" argument == 0 */
2864         cmdline_fixed_string_t mode;
2865 };
2866
2867 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
2868                                         __attribute__((unused)) struct cmdline *cl,
2869                                         void *allports)
2870 {
2871         struct cmd_set_allmulti_mode_result *res = parsed_result;
2872         int enable;
2873         portid_t i;
2874
2875         if (!strcmp(res->mode, "on"))
2876                 enable = 1;
2877         else
2878                 enable = 0;
2879
2880         /* all ports */
2881         if (allports) {
2882                 for (i = 0; i < nb_ports; i++) {
2883                         if (enable)
2884                                 rte_eth_allmulticast_enable(i);
2885                         else
2886                                 rte_eth_allmulticast_disable(i);
2887                 }
2888         }
2889         else {
2890                 if (enable)
2891                         rte_eth_allmulticast_enable(res->port_num);
2892                 else
2893                         rte_eth_allmulticast_disable(res->port_num);
2894         }
2895 }
2896
2897 cmdline_parse_token_string_t cmd_setallmulti_set =
2898         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
2899 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
2900         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
2901                                  "allmulti");
2902 cmdline_parse_token_string_t cmd_setallmulti_portall =
2903         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
2904                                  "all");
2905 cmdline_parse_token_num_t cmd_setallmulti_portnum =
2906         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
2907                               UINT8);
2908 cmdline_parse_token_string_t cmd_setallmulti_mode =
2909         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
2910                                  "on#off");
2911
2912 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
2913         .f = cmd_set_allmulti_mode_parsed,
2914         .data = (void *)1,
2915         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
2916         .tokens = {
2917                 (void *)&cmd_setallmulti_set,
2918                 (void *)&cmd_setallmulti_allmulti,
2919                 (void *)&cmd_setallmulti_portall,
2920                 (void *)&cmd_setallmulti_mode,
2921                 NULL,
2922         },
2923 };
2924
2925 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
2926         .f = cmd_set_allmulti_mode_parsed,
2927         .data = (void *)0,
2928         .help_str = "set allmulti X on|off: set allmulti mode on port X",
2929         .tokens = {
2930                 (void *)&cmd_setallmulti_set,
2931                 (void *)&cmd_setallmulti_allmulti,
2932                 (void *)&cmd_setallmulti_portnum,
2933                 (void *)&cmd_setallmulti_mode,
2934                 NULL,
2935         },
2936 };
2937
2938 /* *** ADD/REMOVE A PKT FILTER *** */
2939 struct cmd_pkt_filter_result {
2940         cmdline_fixed_string_t pkt_filter;
2941         uint8_t  port_id;
2942         cmdline_fixed_string_t protocol;
2943         cmdline_fixed_string_t src;
2944         cmdline_ipaddr_t ip_src;
2945         uint16_t port_src;
2946         cmdline_fixed_string_t dst;
2947         cmdline_ipaddr_t ip_dst;
2948         uint16_t port_dst;
2949         cmdline_fixed_string_t flexbytes;
2950         uint16_t flexbytes_value;
2951         cmdline_fixed_string_t vlan;
2952         uint16_t  vlan_id;
2953         cmdline_fixed_string_t queue;
2954         int8_t  queue_id;
2955         cmdline_fixed_string_t soft;
2956         uint8_t  soft_id;
2957 };
2958
2959 static void
2960 cmd_pkt_filter_parsed(void *parsed_result,
2961                           __attribute__((unused)) struct cmdline *cl,
2962                           __attribute__((unused)) void *data)
2963 {
2964         struct rte_fdir_filter fdir_filter;
2965         struct cmd_pkt_filter_result *res = parsed_result;
2966
2967         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
2968
2969         if (res->ip_src.family == AF_INET)
2970                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
2971         else
2972                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
2973                        &(res->ip_src.addr.ipv6),
2974                        sizeof(struct in6_addr));
2975
2976         if (res->ip_dst.family == AF_INET)
2977                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
2978         else
2979                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
2980                        &(res->ip_dst.addr.ipv6),
2981                        sizeof(struct in6_addr));
2982
2983         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
2984         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
2985
2986         if (!strcmp(res->protocol, "udp"))
2987                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
2988         else if (!strcmp(res->protocol, "tcp"))
2989                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
2990         else if (!strcmp(res->protocol, "sctp"))
2991                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
2992         else /* default only IP */
2993                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
2994
2995         if (res->ip_dst.family == AF_INET6)
2996                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
2997         else
2998                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
2999
3000         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
3001         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
3002
3003         if (!strcmp(res->pkt_filter, "add_signature_filter"))
3004                 fdir_add_signature_filter(res->port_id, res->queue_id,
3005                                           &fdir_filter);
3006         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
3007                 fdir_update_signature_filter(res->port_id, res->queue_id,
3008                                              &fdir_filter);
3009         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
3010                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
3011         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
3012                 fdir_add_perfect_filter(res->port_id, res->soft_id,
3013                                         res->queue_id,
3014                                         (uint8_t) (res->queue_id < 0),
3015                                         &fdir_filter);
3016         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
3017                 fdir_update_perfect_filter(res->port_id, res->soft_id,
3018                                            res->queue_id,
3019                                            (uint8_t) (res->queue_id < 0),
3020                                            &fdir_filter);
3021         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
3022                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
3023                                            &fdir_filter);
3024
3025 }
3026
3027
3028 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
3029         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3030                               port_id, UINT8);
3031 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
3032         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3033                                  protocol, "ip#tcp#udp#sctp");
3034 cmdline_parse_token_string_t cmd_pkt_filter_src =
3035         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3036                                  src, "src");
3037 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
3038         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3039                                  ip_src);
3040 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
3041         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3042                               port_src, UINT16);
3043 cmdline_parse_token_string_t cmd_pkt_filter_dst =
3044         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3045                                  dst, "dst");
3046 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
3047         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3048                                  ip_dst);
3049 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
3050         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3051                               port_dst, UINT16);
3052 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
3053         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3054                                  flexbytes, "flexbytes");
3055 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
3056         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3057                               flexbytes_value, UINT16);
3058 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
3059         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3060                                  vlan, "vlan");
3061 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
3062         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3063                               vlan_id, UINT16);
3064 cmdline_parse_token_string_t cmd_pkt_filter_queue =
3065         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3066                                  queue, "queue");
3067 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
3068         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3069                               queue_id, INT8);
3070 cmdline_parse_token_string_t cmd_pkt_filter_soft =
3071         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3072                                  soft, "soft");
3073 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3075                               soft_id, UINT16);
3076
3077
3078 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
3079         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3080                                  pkt_filter, "add_signature_filter");
3081 cmdline_parse_inst_t cmd_add_signature_filter = {
3082         .f = cmd_pkt_filter_parsed,
3083         .data = NULL,
3084         .help_str = "add a signature filter",
3085         .tokens = {
3086                 (void *)&cmd_pkt_filter_add_signature_filter,
3087                 (void *)&cmd_pkt_filter_port_id,
3088                 (void *)&cmd_pkt_filter_protocol,
3089                 (void *)&cmd_pkt_filter_src,
3090                 (void *)&cmd_pkt_filter_ip_src,
3091                 (void *)&cmd_pkt_filter_port_src,
3092                 (void *)&cmd_pkt_filter_dst,
3093                 (void *)&cmd_pkt_filter_ip_dst,
3094                 (void *)&cmd_pkt_filter_port_dst,
3095                 (void *)&cmd_pkt_filter_flexbytes,
3096                 (void *)&cmd_pkt_filter_flexbytes_value,
3097                 (void *)&cmd_pkt_filter_vlan,
3098                 (void *)&cmd_pkt_filter_vlan_id,
3099                 (void *)&cmd_pkt_filter_queue,
3100                 (void *)&cmd_pkt_filter_queue_id,
3101                 NULL,
3102         },
3103 };
3104
3105
3106 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
3107         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3108                                  pkt_filter, "upd_signature_filter");
3109 cmdline_parse_inst_t cmd_upd_signature_filter = {
3110         .f = cmd_pkt_filter_parsed,
3111         .data = NULL,
3112         .help_str = "update a signature filter",
3113         .tokens = {
3114                 (void *)&cmd_pkt_filter_upd_signature_filter,
3115                 (void *)&cmd_pkt_filter_port_id,
3116                 (void *)&cmd_pkt_filter_protocol,
3117                 (void *)&cmd_pkt_filter_src,
3118                 (void *)&cmd_pkt_filter_ip_src,
3119                 (void *)&cmd_pkt_filter_port_src,
3120                 (void *)&cmd_pkt_filter_dst,
3121                 (void *)&cmd_pkt_filter_ip_dst,
3122                 (void *)&cmd_pkt_filter_port_dst,
3123                 (void *)&cmd_pkt_filter_flexbytes,
3124                 (void *)&cmd_pkt_filter_flexbytes_value,
3125                 (void *)&cmd_pkt_filter_vlan,
3126                 (void *)&cmd_pkt_filter_vlan_id,
3127                 (void *)&cmd_pkt_filter_queue,
3128                 (void *)&cmd_pkt_filter_queue_id,
3129                 NULL,
3130         },
3131 };
3132
3133
3134 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
3135         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3136                                  pkt_filter, "rm_signature_filter");
3137 cmdline_parse_inst_t cmd_rm_signature_filter = {
3138         .f = cmd_pkt_filter_parsed,
3139         .data = NULL,
3140         .help_str = "remove a signature filter",
3141         .tokens = {
3142                 (void *)&cmd_pkt_filter_rm_signature_filter,
3143                 (void *)&cmd_pkt_filter_port_id,
3144                 (void *)&cmd_pkt_filter_protocol,
3145                 (void *)&cmd_pkt_filter_src,
3146                 (void *)&cmd_pkt_filter_ip_src,
3147                 (void *)&cmd_pkt_filter_port_src,
3148                 (void *)&cmd_pkt_filter_dst,
3149                 (void *)&cmd_pkt_filter_ip_dst,
3150                 (void *)&cmd_pkt_filter_port_dst,
3151                 (void *)&cmd_pkt_filter_flexbytes,
3152                 (void *)&cmd_pkt_filter_flexbytes_value,
3153                 (void *)&cmd_pkt_filter_vlan,
3154                 (void *)&cmd_pkt_filter_vlan_id,
3155                 NULL
3156                 },
3157 };
3158
3159
3160 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
3161         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3162                                  pkt_filter, "add_perfect_filter");
3163 cmdline_parse_inst_t cmd_add_perfect_filter = {
3164         .f = cmd_pkt_filter_parsed,
3165         .data = NULL,
3166         .help_str = "add a perfect filter",
3167         .tokens = {
3168                 (void *)&cmd_pkt_filter_add_perfect_filter,
3169                 (void *)&cmd_pkt_filter_port_id,
3170                 (void *)&cmd_pkt_filter_protocol,
3171                 (void *)&cmd_pkt_filter_src,
3172                 (void *)&cmd_pkt_filter_ip_src,
3173                 (void *)&cmd_pkt_filter_port_src,
3174                 (void *)&cmd_pkt_filter_dst,
3175                 (void *)&cmd_pkt_filter_ip_dst,
3176                 (void *)&cmd_pkt_filter_port_dst,
3177                 (void *)&cmd_pkt_filter_flexbytes,
3178                 (void *)&cmd_pkt_filter_flexbytes_value,
3179                 (void *)&cmd_pkt_filter_vlan,
3180                 (void *)&cmd_pkt_filter_vlan_id,
3181                 (void *)&cmd_pkt_filter_queue,
3182                 (void *)&cmd_pkt_filter_queue_id,
3183                 (void *)&cmd_pkt_filter_soft,
3184                 (void *)&cmd_pkt_filter_soft_id,
3185                 NULL,
3186         },
3187 };
3188
3189
3190 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
3191         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3192                                  pkt_filter, "upd_perfect_filter");
3193 cmdline_parse_inst_t cmd_upd_perfect_filter = {
3194         .f = cmd_pkt_filter_parsed,
3195         .data = NULL,
3196         .help_str = "update a perfect filter",
3197         .tokens = {
3198                 (void *)&cmd_pkt_filter_upd_perfect_filter,
3199                 (void *)&cmd_pkt_filter_port_id,
3200                 (void *)&cmd_pkt_filter_protocol,
3201                 (void *)&cmd_pkt_filter_src,
3202                 (void *)&cmd_pkt_filter_ip_src,
3203                 (void *)&cmd_pkt_filter_port_src,
3204                 (void *)&cmd_pkt_filter_dst,
3205                 (void *)&cmd_pkt_filter_ip_dst,
3206                 (void *)&cmd_pkt_filter_port_dst,
3207                 (void *)&cmd_pkt_filter_flexbytes,
3208                 (void *)&cmd_pkt_filter_flexbytes_value,
3209                 (void *)&cmd_pkt_filter_vlan,
3210                 (void *)&cmd_pkt_filter_vlan_id,
3211                 (void *)&cmd_pkt_filter_queue,
3212                 (void *)&cmd_pkt_filter_queue_id,
3213                 (void *)&cmd_pkt_filter_soft,
3214                 (void *)&cmd_pkt_filter_soft_id,
3215                 NULL,
3216         },
3217 };
3218
3219
3220 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
3221         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3222                                  pkt_filter, "rm_perfect_filter");
3223 cmdline_parse_inst_t cmd_rm_perfect_filter = {
3224         .f = cmd_pkt_filter_parsed,
3225         .data = NULL,
3226         .help_str = "remove a perfect filter",
3227         .tokens = {
3228                 (void *)&cmd_pkt_filter_rm_perfect_filter,
3229                 (void *)&cmd_pkt_filter_port_id,
3230                 (void *)&cmd_pkt_filter_protocol,
3231                 (void *)&cmd_pkt_filter_src,
3232                 (void *)&cmd_pkt_filter_ip_src,
3233                 (void *)&cmd_pkt_filter_port_src,
3234                 (void *)&cmd_pkt_filter_dst,
3235                 (void *)&cmd_pkt_filter_ip_dst,
3236                 (void *)&cmd_pkt_filter_port_dst,
3237                 (void *)&cmd_pkt_filter_flexbytes,
3238                 (void *)&cmd_pkt_filter_flexbytes_value,
3239                 (void *)&cmd_pkt_filter_vlan,
3240                 (void *)&cmd_pkt_filter_vlan_id,
3241                 (void *)&cmd_pkt_filter_soft,
3242                 (void *)&cmd_pkt_filter_soft_id,
3243                 NULL,
3244         },
3245 };
3246
3247 /* *** SETUP MASKS FILTER *** */
3248 struct cmd_pkt_filter_masks_result {
3249         cmdline_fixed_string_t filter_mask;
3250         uint8_t  port_id;
3251         cmdline_fixed_string_t src_mask;
3252         uint32_t ip_src_mask;
3253         uint16_t ipv6_src_mask;
3254         uint16_t port_src_mask;
3255         cmdline_fixed_string_t dst_mask;
3256         uint32_t ip_dst_mask;
3257         uint16_t ipv6_dst_mask;
3258         uint16_t port_dst_mask;
3259         cmdline_fixed_string_t flexbytes;
3260         uint8_t flexbytes_value;
3261         cmdline_fixed_string_t vlan_id;
3262         uint8_t  vlan_id_value;
3263         cmdline_fixed_string_t vlan_prio;
3264         uint8_t  vlan_prio_value;
3265         cmdline_fixed_string_t only_ip_flow;
3266         uint8_t  only_ip_flow_value;
3267         cmdline_fixed_string_t comp_ipv6_dst;
3268         uint8_t  comp_ipv6_dst_value;
3269 };
3270
3271 static void
3272 cmd_pkt_filter_masks_parsed(void *parsed_result,
3273                           __attribute__((unused)) struct cmdline *cl,
3274                           __attribute__((unused)) void *data)
3275 {
3276         struct rte_fdir_masks fdir_masks;
3277         struct cmd_pkt_filter_masks_result *res = parsed_result;
3278
3279         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3280
3281         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3282         fdir_masks.vlan_id       = res->vlan_id_value;
3283         fdir_masks.vlan_prio     = res->vlan_prio_value;
3284         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
3285         fdir_masks.src_ipv4_mask = res->ip_src_mask;
3286         fdir_masks.src_port_mask = res->port_src_mask;
3287         fdir_masks.dst_port_mask = res->port_dst_mask;
3288         fdir_masks.flexbytes     = res->flexbytes_value;
3289
3290         fdir_set_masks(res->port_id, &fdir_masks);
3291 }
3292
3293 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
3294         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3295                                  filter_mask, "set_masks_filter");
3296 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
3297         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3298                               port_id, UINT8);
3299 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
3300         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3301                                  only_ip_flow, "only_ip_flow");
3302 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
3303         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3304                               only_ip_flow_value, UINT8);
3305 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
3306         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3307                                  src_mask, "src_mask");
3308 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
3309         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3310                               ip_src_mask, UINT32);
3311 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
3312         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3313                               port_src_mask, UINT16);
3314 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
3315         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3316                                  dst_mask, "dst_mask");
3317 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
3318         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3319                               ip_dst_mask, UINT32);
3320 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
3321         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3322                               port_dst_mask, UINT16);
3323 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
3324         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3325                                  flexbytes, "flexbytes");
3326 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
3327         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3328                               flexbytes_value, UINT8);
3329 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
3330         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3331                                  vlan_id, "vlan_id");
3332 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
3333         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3334                               vlan_id_value, UINT8);
3335 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
3336         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3337                                  vlan_prio, "vlan_prio");
3338 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
3339         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3340                               vlan_prio_value, UINT8);
3341
3342 cmdline_parse_inst_t cmd_set_masks_filter = {
3343         .f = cmd_pkt_filter_masks_parsed,
3344         .data = NULL,
3345         .help_str = "setup masks filter",
3346         .tokens = {
3347                 (void *)&cmd_pkt_filter_masks_filter_mask,
3348                 (void *)&cmd_pkt_filter_masks_port_id,
3349                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3350                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3351                 (void *)&cmd_pkt_filter_masks_src_mask,
3352                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
3353                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3354                 (void *)&cmd_pkt_filter_masks_dst_mask,
3355                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
3356                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3357                 (void *)&cmd_pkt_filter_masks_flexbytes,
3358                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3359                 (void *)&cmd_pkt_filter_masks_vlan_id,
3360                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3361                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3362                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3363                 NULL,
3364         },
3365 };
3366
3367 static void
3368 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
3369                           __attribute__((unused)) struct cmdline *cl,
3370                           __attribute__((unused)) void *data)
3371 {
3372         struct rte_fdir_masks fdir_masks;
3373         struct cmd_pkt_filter_masks_result *res = parsed_result;
3374
3375         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3376
3377         fdir_masks.set_ipv6_mask = 1;
3378         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3379         fdir_masks.vlan_id       = res->vlan_id_value;
3380         fdir_masks.vlan_prio     = res->vlan_prio_value;
3381         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
3382         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
3383         fdir_masks.src_port_mask = res->port_src_mask;
3384         fdir_masks.dst_port_mask = res->port_dst_mask;
3385         fdir_masks.flexbytes     = res->flexbytes_value;
3386         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
3387
3388         fdir_set_masks(res->port_id, &fdir_masks);
3389 }
3390
3391 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
3392         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3393                                  filter_mask, "set_ipv6_masks_filter");
3394 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
3395         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3396                               ipv6_src_mask, UINT16);
3397 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
3398         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3399                               ipv6_dst_mask, UINT16);
3400
3401 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
3402         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3403                                  comp_ipv6_dst, "compare_dst");
3404 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
3405         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3406                               comp_ipv6_dst_value, UINT8);
3407
3408 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
3409         .f = cmd_pkt_filter_masks_ipv6_parsed,
3410         .data = NULL,
3411         .help_str = "setup ipv6 masks filter",
3412         .tokens = {
3413                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
3414                 (void *)&cmd_pkt_filter_masks_port_id,
3415                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3416                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3417                 (void *)&cmd_pkt_filter_masks_src_mask,
3418                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
3419                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3420                 (void *)&cmd_pkt_filter_masks_dst_mask,
3421                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
3422                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3423                 (void *)&cmd_pkt_filter_masks_flexbytes,
3424                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3425                 (void *)&cmd_pkt_filter_masks_vlan_id,
3426                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3427                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3428                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3429                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
3430                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
3431                 NULL,
3432         },
3433 };
3434
3435 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
3436 struct cmd_link_flow_ctrl_set_result {
3437         cmdline_fixed_string_t set;
3438         cmdline_fixed_string_t flow_ctrl;
3439         cmdline_fixed_string_t rx;
3440         cmdline_fixed_string_t rx_lfc_mode;
3441         cmdline_fixed_string_t tx;
3442         cmdline_fixed_string_t tx_lfc_mode;
3443         cmdline_fixed_string_t mac_ctrl_frame_fwd;
3444         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
3445         uint32_t high_water;
3446         uint32_t low_water;
3447         uint16_t pause_time;
3448         uint16_t send_xon;
3449         uint8_t  port_id;
3450 };
3451
3452 static void
3453 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
3454                        __attribute__((unused)) struct cmdline *cl,
3455                        __attribute__((unused)) void *data)
3456 {
3457         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
3458         struct rte_eth_fc_conf fc_conf;
3459         int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
3460         int ret;
3461
3462         /*
3463          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3464          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3465          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3466          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3467          */
3468         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
3469                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
3470         };
3471
3472         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
3473         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
3474         mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
3475
3476         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
3477         fc_conf.high_water = res->high_water;
3478         fc_conf.low_water  = res->low_water;
3479         fc_conf.pause_time = res->pause_time;
3480         fc_conf.send_xon   = res->send_xon;
3481         fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
3482
3483         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
3484         if (ret != 0)
3485                 printf("bad flow contrl parameter, return code = %d \n", ret);
3486 }
3487
3488 cmdline_parse_token_string_t cmd_lfc_set_set =
3489         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3490                                 set, "set");
3491 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
3492         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3493                                 flow_ctrl, "flow_ctrl");
3494 cmdline_parse_token_string_t cmd_lfc_set_rx =
3495         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3496                                 rx, "rx");
3497 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
3498         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3499                                 rx_lfc_mode, "on#off");
3500 cmdline_parse_token_string_t cmd_lfc_set_tx =
3501         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3502                                 tx, "tx");
3503 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
3504         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3505                                 tx_lfc_mode, "on#off");
3506 cmdline_parse_token_num_t cmd_lfc_set_high_water =
3507         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3508                                 high_water, UINT32);
3509 cmdline_parse_token_num_t cmd_lfc_set_low_water =
3510         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3511                                 low_water, UINT32);
3512 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
3513         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3514                                 pause_time, UINT16);
3515 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
3516         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3517                                 send_xon, UINT16);
3518 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
3519         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3520                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
3521 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
3522         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3523                                 mac_ctrl_frame_fwd_mode, "on#off");
3524 cmdline_parse_token_num_t cmd_lfc_set_portid =
3525         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3526                                 port_id, UINT8);
3527
3528 cmdline_parse_inst_t cmd_link_flow_control_set = {
3529         .f = cmd_link_flow_ctrl_set_parsed,
3530         .data = NULL,
3531         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
3532 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
3533 port_id",
3534         .tokens = {
3535                 (void *)&cmd_lfc_set_set,
3536                 (void *)&cmd_lfc_set_flow_ctrl,
3537                 (void *)&cmd_lfc_set_rx,
3538                 (void *)&cmd_lfc_set_rx_mode,
3539                 (void *)&cmd_lfc_set_tx,
3540                 (void *)&cmd_lfc_set_tx_mode,
3541                 (void *)&cmd_lfc_set_high_water,
3542                 (void *)&cmd_lfc_set_low_water,
3543                 (void *)&cmd_lfc_set_pause_time,
3544                 (void *)&cmd_lfc_set_send_xon,
3545                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
3546                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
3547                 (void *)&cmd_lfc_set_portid,
3548                 NULL,
3549         },
3550 };
3551
3552 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
3553 struct cmd_priority_flow_ctrl_set_result {
3554         cmdline_fixed_string_t set;
3555         cmdline_fixed_string_t pfc_ctrl;
3556         cmdline_fixed_string_t rx;
3557         cmdline_fixed_string_t rx_pfc_mode;
3558         cmdline_fixed_string_t tx;
3559         cmdline_fixed_string_t tx_pfc_mode;
3560         uint32_t high_water;
3561         uint32_t low_water;
3562         uint16_t pause_time;
3563         uint8_t  priority;
3564         uint8_t  port_id;
3565 };
3566
3567 static void
3568 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
3569                        __attribute__((unused)) struct cmdline *cl,
3570                        __attribute__((unused)) void *data)
3571 {
3572         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
3573         struct rte_eth_pfc_conf pfc_conf;
3574         int rx_fc_enable, tx_fc_enable;
3575         int ret;
3576
3577         /*
3578          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3579          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3580          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3581          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3582          */
3583         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
3584                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3585         };
3586
3587         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
3588         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
3589         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
3590         pfc_conf.fc.high_water = res->high_water;
3591         pfc_conf.fc.low_water  = res->low_water;
3592         pfc_conf.fc.pause_time = res->pause_time;
3593         pfc_conf.priority      = res->priority;
3594
3595         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
3596         if (ret != 0)
3597                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
3598 }
3599
3600 cmdline_parse_token_string_t cmd_pfc_set_set =
3601         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3602                                 set, "set");
3603 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
3604         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3605                                 pfc_ctrl, "pfc_ctrl");
3606 cmdline_parse_token_string_t cmd_pfc_set_rx =
3607         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3608                                 rx, "rx");
3609 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
3610         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3611                                 rx_pfc_mode, "on#off");
3612 cmdline_parse_token_string_t cmd_pfc_set_tx =
3613         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3614                                 tx, "tx");
3615 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
3616         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3617                                 tx_pfc_mode, "on#off");
3618 cmdline_parse_token_num_t cmd_pfc_set_high_water =
3619         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3620                                 high_water, UINT32);
3621 cmdline_parse_token_num_t cmd_pfc_set_low_water =
3622         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3623                                 low_water, UINT32);
3624 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
3625         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3626                                 pause_time, UINT16);
3627 cmdline_parse_token_num_t cmd_pfc_set_priority =
3628         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3629                                 priority, UINT8);
3630 cmdline_parse_token_num_t cmd_pfc_set_portid =
3631         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3632                                 port_id, UINT8);
3633
3634 cmdline_parse_inst_t cmd_priority_flow_control_set = {
3635         .f = cmd_priority_flow_ctrl_set_parsed,
3636         .data = NULL,
3637         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
3638                         tx on|off high_water low_water pause_time priority port_id",
3639         .tokens = {
3640                 (void *)&cmd_pfc_set_set,
3641                 (void *)&cmd_pfc_set_flow_ctrl,
3642                 (void *)&cmd_pfc_set_rx,
3643                 (void *)&cmd_pfc_set_rx_mode,
3644                 (void *)&cmd_pfc_set_tx,
3645                 (void *)&cmd_pfc_set_tx_mode,
3646                 (void *)&cmd_pfc_set_high_water,
3647                 (void *)&cmd_pfc_set_low_water,
3648                 (void *)&cmd_pfc_set_pause_time,
3649                 (void *)&cmd_pfc_set_priority,
3650                 (void *)&cmd_pfc_set_portid,
3651                 NULL,
3652         },
3653 };
3654
3655 /* *** RESET CONFIGURATION *** */
3656 struct cmd_reset_result {
3657         cmdline_fixed_string_t reset;
3658         cmdline_fixed_string_t def;
3659 };
3660
3661 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
3662                              struct cmdline *cl,
3663                              __attribute__((unused)) void *data)
3664 {
3665         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
3666         set_def_fwd_config();
3667 }
3668
3669 cmdline_parse_token_string_t cmd_reset_set =
3670         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
3671 cmdline_parse_token_string_t cmd_reset_def =
3672         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
3673                                  "default");
3674
3675 cmdline_parse_inst_t cmd_reset = {
3676         .f = cmd_reset_parsed,
3677         .data = NULL,
3678         .help_str = "set default: reset default forwarding configuration",
3679         .tokens = {
3680                 (void *)&cmd_reset_set,
3681                 (void *)&cmd_reset_def,
3682                 NULL,
3683         },
3684 };
3685
3686 /* *** START FORWARDING *** */
3687 struct cmd_start_result {
3688         cmdline_fixed_string_t start;
3689 };
3690
3691 cmdline_parse_token_string_t cmd_start_start =
3692         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
3693
3694 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
3695                              __attribute__((unused)) struct cmdline *cl,
3696                              __attribute__((unused)) void *data)
3697 {
3698         start_packet_forwarding(0);
3699 }
3700
3701 cmdline_parse_inst_t cmd_start = {
3702         .f = cmd_start_parsed,
3703         .data = NULL,
3704         .help_str = "start packet forwarding",
3705         .tokens = {
3706                 (void *)&cmd_start_start,
3707                 NULL,
3708         },
3709 };
3710
3711 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
3712 struct cmd_start_tx_first_result {
3713         cmdline_fixed_string_t start;
3714         cmdline_fixed_string_t tx_first;
3715 };
3716
3717 static void
3718 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
3719                           __attribute__((unused)) struct cmdline *cl,
3720                           __attribute__((unused)) void *data)
3721 {
3722         start_packet_forwarding(1);
3723 }
3724
3725 cmdline_parse_token_string_t cmd_start_tx_first_start =
3726         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
3727                                  "start");
3728 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
3729         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
3730                                  tx_first, "tx_first");
3731
3732 cmdline_parse_inst_t cmd_start_tx_first = {
3733         .f = cmd_start_tx_first_parsed,
3734         .data = NULL,
3735         .help_str = "start packet forwarding, after sending 1 burst of packets",
3736         .tokens = {
3737                 (void *)&cmd_start_tx_first_start,
3738                 (void *)&cmd_start_tx_first_tx_first,
3739                 NULL,
3740         },
3741 };
3742
3743 /* *** SHOW CFG *** */
3744 struct cmd_showcfg_result {
3745         cmdline_fixed_string_t show;
3746         cmdline_fixed_string_t cfg;
3747         cmdline_fixed_string_t what;
3748 };
3749
3750 static void cmd_showcfg_parsed(void *parsed_result,
3751                                __attribute__((unused)) struct cmdline *cl,
3752                                __attribute__((unused)) void *data)
3753 {
3754         struct cmd_showcfg_result *res = parsed_result;
3755         if (!strcmp(res->what, "rxtx"))
3756                 rxtx_config_display();
3757         else if (!strcmp(res->what, "cores"))
3758                 fwd_lcores_config_display();
3759         else if (!strcmp(res->what, "fwd"))
3760                 fwd_config_display();
3761 }
3762
3763 cmdline_parse_token_string_t cmd_showcfg_show =
3764         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
3765 cmdline_parse_token_string_t cmd_showcfg_port =
3766         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
3767 cmdline_parse_token_string_t cmd_showcfg_what =
3768         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
3769                                  "rxtx#cores#fwd");
3770
3771 cmdline_parse_inst_t cmd_showcfg = {
3772         .f = cmd_showcfg_parsed,
3773         .data = NULL,
3774         .help_str = "show config rxtx|cores|fwd",
3775         .tokens = {
3776                 (void *)&cmd_showcfg_show,
3777                 (void *)&cmd_showcfg_port,
3778                 (void *)&cmd_showcfg_what,
3779                 NULL,
3780         },
3781 };
3782
3783 /* *** SHOW ALL PORT INFO *** */
3784 struct cmd_showportall_result {
3785         cmdline_fixed_string_t show;
3786         cmdline_fixed_string_t port;
3787         cmdline_fixed_string_t what;
3788         cmdline_fixed_string_t all;
3789 };
3790
3791 static void cmd_showportall_parsed(void *parsed_result,
3792                                 __attribute__((unused)) struct cmdline *cl,
3793                                 __attribute__((unused)) void *data)
3794 {
3795         portid_t i;
3796
3797         struct cmd_showportall_result *res = parsed_result;
3798         if (!strcmp(res->show, "clear")) {
3799                 if (!strcmp(res->what, "stats"))
3800                         for (i = 0; i < nb_ports; i++)
3801                                 nic_stats_clear(i);
3802         } else if (!strcmp(res->what, "info"))
3803                 for (i = 0; i < nb_ports; i++)
3804                         port_infos_display(i);
3805         else if (!strcmp(res->what, "stats"))
3806                 for (i = 0; i < nb_ports; i++)
3807                         nic_stats_display(i);
3808         else if (!strcmp(res->what, "fdir"))
3809                 for (i = 0; i < nb_ports; i++)
3810                         fdir_get_infos(i);
3811         else if (!strcmp(res->what, "stat_qmap"))
3812                 for (i = 0; i < nb_ports; i++)
3813                         nic_stats_mapping_display(i);
3814 }
3815
3816 cmdline_parse_token_string_t cmd_showportall_show =
3817         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
3818                                  "show#clear");
3819 cmdline_parse_token_string_t cmd_showportall_port =
3820         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
3821 cmdline_parse_token_string_t cmd_showportall_what =
3822         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
3823                                  "info#stats#fdir#stat_qmap");
3824 cmdline_parse_token_string_t cmd_showportall_all =
3825         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
3826 cmdline_parse_inst_t cmd_showportall = {
3827         .f = cmd_showportall_parsed,
3828         .data = NULL,
3829         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
3830         .tokens = {
3831                 (void *)&cmd_showportall_show,
3832                 (void *)&cmd_showportall_port,
3833                 (void *)&cmd_showportall_what,
3834                 (void *)&cmd_showportall_all,
3835                 NULL,
3836         },
3837 };
3838
3839 /* *** SHOW PORT INFO *** */
3840 struct cmd_showport_result {
3841         cmdline_fixed_string_t show;
3842         cmdline_fixed_string_t port;
3843         cmdline_fixed_string_t what;
3844         uint8_t portnum;
3845 };
3846
3847 static void cmd_showport_parsed(void *parsed_result,
3848                                 __attribute__((unused)) struct cmdline *cl,
3849                                 __attribute__((unused)) void *data)
3850 {
3851         struct cmd_showport_result *res = parsed_result;
3852         if (!strcmp(res->show, "clear")) {
3853                 if (!strcmp(res->what, "stats"))
3854                         nic_stats_clear(res->portnum);
3855         } else if (!strcmp(res->what, "info"))
3856                 port_infos_display(res->portnum);
3857         else if (!strcmp(res->what, "stats"))
3858                 nic_stats_display(res->portnum);
3859         else if (!strcmp(res->what, "fdir"))
3860                  fdir_get_infos(res->portnum);
3861         else if (!strcmp(res->what, "stat_qmap"))
3862                 nic_stats_mapping_display(res->portnum);
3863 }
3864
3865 cmdline_parse_token_string_t cmd_showport_show =
3866         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
3867                                  "show#clear");
3868 cmdline_parse_token_string_t cmd_showport_port =
3869         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
3870 cmdline_parse_token_string_t cmd_showport_what =
3871         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
3872                                  "info#stats#fdir#stat_qmap");
3873 cmdline_parse_token_num_t cmd_showport_portnum =
3874         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
3875
3876 cmdline_parse_inst_t cmd_showport = {
3877         .f = cmd_showport_parsed,
3878         .data = NULL,
3879         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
3880         .tokens = {
3881                 (void *)&cmd_showport_show,
3882                 (void *)&cmd_showport_port,
3883                 (void *)&cmd_showport_what,
3884                 (void *)&cmd_showport_portnum,
3885                 NULL,
3886         },
3887 };
3888
3889 /* *** READ PORT REGISTER *** */
3890 struct cmd_read_reg_result {
3891         cmdline_fixed_string_t read;
3892         cmdline_fixed_string_t reg;
3893         uint8_t port_id;
3894         uint32_t reg_off;
3895 };
3896
3897 static void
3898 cmd_read_reg_parsed(void *parsed_result,
3899                     __attribute__((unused)) struct cmdline *cl,
3900                     __attribute__((unused)) void *data)
3901 {
3902         struct cmd_read_reg_result *res = parsed_result;
3903         port_reg_display(res->port_id, res->reg_off);
3904 }
3905
3906 cmdline_parse_token_string_t cmd_read_reg_read =
3907         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
3908 cmdline_parse_token_string_t cmd_read_reg_reg =
3909         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
3910 cmdline_parse_token_num_t cmd_read_reg_port_id =
3911         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
3912 cmdline_parse_token_num_t cmd_read_reg_reg_off =
3913         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
3914
3915 cmdline_parse_inst_t cmd_read_reg = {
3916         .f = cmd_read_reg_parsed,
3917         .data = NULL,
3918         .help_str = "read reg port_id reg_off",
3919         .tokens = {
3920                 (void *)&cmd_read_reg_read,
3921                 (void *)&cmd_read_reg_reg,
3922                 (void *)&cmd_read_reg_port_id,
3923                 (void *)&cmd_read_reg_reg_off,
3924                 NULL,
3925         },
3926 };
3927
3928 /* *** READ PORT REGISTER BIT FIELD *** */
3929 struct cmd_read_reg_bit_field_result {
3930         cmdline_fixed_string_t read;
3931         cmdline_fixed_string_t regfield;
3932         uint8_t port_id;
3933         uint32_t reg_off;
3934         uint8_t bit1_pos;
3935         uint8_t bit2_pos;
3936 };
3937
3938 static void
3939 cmd_read_reg_bit_field_parsed(void *parsed_result,
3940                               __attribute__((unused)) struct cmdline *cl,
3941                               __attribute__((unused)) void *data)
3942 {
3943         struct cmd_read_reg_bit_field_result *res = parsed_result;
3944         port_reg_bit_field_display(res->port_id, res->reg_off,
3945                                    res->bit1_pos, res->bit2_pos);
3946 }
3947
3948 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
3949         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
3950                                  "read");
3951 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
3952         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
3953                                  regfield, "regfield");
3954 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
3955         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
3956                               UINT8);
3957 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
3958         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
3959                               UINT32);
3960 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
3961         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
3962                               UINT8);
3963 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
3964         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
3965                               UINT8);
3966
3967 cmdline_parse_inst_t cmd_read_reg_bit_field = {
3968         .f = cmd_read_reg_bit_field_parsed,
3969         .data = NULL,
3970         .help_str = "read regfield port_id reg_off bit_x bit_y "
3971         "(read register bit field between bit_x and bit_y included)",
3972         .tokens = {
3973                 (void *)&cmd_read_reg_bit_field_read,
3974                 (void *)&cmd_read_reg_bit_field_regfield,
3975                 (void *)&cmd_read_reg_bit_field_port_id,
3976                 (void *)&cmd_read_reg_bit_field_reg_off,
3977                 (void *)&cmd_read_reg_bit_field_bit1_pos,
3978                 (void *)&cmd_read_reg_bit_field_bit2_pos,
3979                 NULL,
3980         },
3981 };
3982
3983 /* *** READ PORT REGISTER BIT *** */
3984 struct cmd_read_reg_bit_result {
3985         cmdline_fixed_string_t read;
3986         cmdline_fixed_string_t regbit;
3987         uint8_t port_id;
3988         uint32_t reg_off;
3989         uint8_t bit_pos;
3990 };
3991
3992 static void
3993 cmd_read_reg_bit_parsed(void *parsed_result,
3994                         __attribute__((unused)) struct cmdline *cl,
3995                         __attribute__((unused)) void *data)
3996 {
3997         struct cmd_read_reg_bit_result *res = parsed_result;
3998         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
3999 }
4000
4001 cmdline_parse_token_string_t cmd_read_reg_bit_read =
4002         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
4003 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
4004         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
4005                                  regbit, "regbit");
4006 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
4007         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
4008 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
4009         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
4010 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
4011         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
4012
4013 cmdline_parse_inst_t cmd_read_reg_bit = {
4014         .f = cmd_read_reg_bit_parsed,
4015         .data = NULL,
4016         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
4017         .tokens = {
4018                 (void *)&cmd_read_reg_bit_read,
4019                 (void *)&cmd_read_reg_bit_regbit,
4020                 (void *)&cmd_read_reg_bit_port_id,
4021                 (void *)&cmd_read_reg_bit_reg_off,
4022                 (void *)&cmd_read_reg_bit_bit_pos,
4023                 NULL,
4024         },
4025 };
4026
4027 /* *** WRITE PORT REGISTER *** */
4028 struct cmd_write_reg_result {
4029         cmdline_fixed_string_t write;
4030         cmdline_fixed_string_t reg;
4031         uint8_t port_id;
4032         uint32_t reg_off;
4033         uint32_t value;
4034 };
4035
4036 static void
4037 cmd_write_reg_parsed(void *parsed_result,
4038                      __attribute__((unused)) struct cmdline *cl,
4039                      __attribute__((unused)) void *data)
4040 {
4041         struct cmd_write_reg_result *res = parsed_result;
4042         port_reg_set(res->port_id, res->reg_off, res->value);
4043 }
4044
4045 cmdline_parse_token_string_t cmd_write_reg_write =
4046         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
4047 cmdline_parse_token_string_t cmd_write_reg_reg =
4048         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
4049 cmdline_parse_token_num_t cmd_write_reg_port_id =
4050         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
4051 cmdline_parse_token_num_t cmd_write_reg_reg_off =
4052         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
4053 cmdline_parse_token_num_t cmd_write_reg_value =
4054         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
4055
4056 cmdline_parse_inst_t cmd_write_reg = {
4057         .f = cmd_write_reg_parsed,
4058         .data = NULL,
4059         .help_str = "write reg port_id reg_off reg_value",
4060         .tokens = {
4061                 (void *)&cmd_write_reg_write,
4062                 (void *)&cmd_write_reg_reg,
4063                 (void *)&cmd_write_reg_port_id,
4064                 (void *)&cmd_write_reg_reg_off,
4065                 (void *)&cmd_write_reg_value,
4066                 NULL,
4067         },
4068 };
4069
4070 /* *** WRITE PORT REGISTER BIT FIELD *** */
4071 struct cmd_write_reg_bit_field_result {
4072         cmdline_fixed_string_t write;
4073         cmdline_fixed_string_t regfield;
4074         uint8_t port_id;
4075         uint32_t reg_off;
4076         uint8_t bit1_pos;
4077         uint8_t bit2_pos;
4078         uint32_t value;
4079 };
4080
4081 static void
4082 cmd_write_reg_bit_field_parsed(void *parsed_result,
4083                                __attribute__((unused)) struct cmdline *cl,
4084                                __attribute__((unused)) void *data)
4085 {
4086         struct cmd_write_reg_bit_field_result *res = parsed_result;
4087         port_reg_bit_field_set(res->port_id, res->reg_off,
4088                           res->bit1_pos, res->bit2_pos, res->value);
4089 }
4090
4091 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
4092         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
4093                                  "write");
4094 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
4095         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
4096                                  regfield, "regfield");
4097 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
4098         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
4099                               UINT8);
4100 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
4101         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
4102                               UINT32);
4103 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
4104         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
4105                               UINT8);
4106 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
4107         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
4108                               UINT8);
4109 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
4110         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
4111                               UINT32);
4112
4113 cmdline_parse_inst_t cmd_write_reg_bit_field = {
4114         .f = cmd_write_reg_bit_field_parsed,
4115         .data = NULL,
4116         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
4117         "(set register bit field between bit_x and bit_y included)",
4118         .tokens = {
4119                 (void *)&cmd_write_reg_bit_field_write,
4120                 (void *)&cmd_write_reg_bit_field_regfield,
4121                 (void *)&cmd_write_reg_bit_field_port_id,
4122                 (void *)&cmd_write_reg_bit_field_reg_off,
4123                 (void *)&cmd_write_reg_bit_field_bit1_pos,
4124                 (void *)&cmd_write_reg_bit_field_bit2_pos,
4125                 (void *)&cmd_write_reg_bit_field_value,
4126                 NULL,
4127         },
4128 };
4129
4130 /* *** WRITE PORT REGISTER BIT *** */
4131 struct cmd_write_reg_bit_result {
4132         cmdline_fixed_string_t write;
4133         cmdline_fixed_string_t regbit;
4134         uint8_t port_id;
4135         uint32_t reg_off;
4136         uint8_t bit_pos;
4137         uint8_t value;
4138 };
4139
4140 static void
4141 cmd_write_reg_bit_parsed(void *parsed_result,
4142                          __attribute__((unused)) struct cmdline *cl,
4143                          __attribute__((unused)) void *data)
4144 {
4145         struct cmd_write_reg_bit_result *res = parsed_result;
4146         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
4147 }
4148
4149 cmdline_parse_token_string_t cmd_write_reg_bit_write =
4150         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
4151                                  "write");
4152 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
4153         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
4154                                  regbit, "regbit");
4155 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
4156         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
4157 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
4158         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
4159 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
4160         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
4161 cmdline_parse_token_num_t cmd_write_reg_bit_value =
4162         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
4163
4164 cmdline_parse_inst_t cmd_write_reg_bit = {
4165         .f = cmd_write_reg_bit_parsed,
4166         .data = NULL,
4167         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
4168         .tokens = {
4169                 (void *)&cmd_write_reg_bit_write,
4170                 (void *)&cmd_write_reg_bit_regbit,
4171                 (void *)&cmd_write_reg_bit_port_id,
4172                 (void *)&cmd_write_reg_bit_reg_off,
4173                 (void *)&cmd_write_reg_bit_bit_pos,
4174                 (void *)&cmd_write_reg_bit_value,
4175                 NULL,
4176         },
4177 };
4178
4179 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
4180 struct cmd_read_rxd_txd_result {
4181         cmdline_fixed_string_t read;
4182         cmdline_fixed_string_t rxd_txd;
4183         uint8_t port_id;
4184         uint16_t queue_id;
4185         uint16_t desc_id;
4186 };
4187
4188 static void
4189 cmd_read_rxd_txd_parsed(void *parsed_result,
4190                         __attribute__((unused)) struct cmdline *cl,
4191                         __attribute__((unused)) void *data)
4192 {
4193         struct cmd_read_rxd_txd_result *res = parsed_result;
4194
4195         if (!strcmp(res->rxd_txd, "rxd"))
4196                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4197         else if (!strcmp(res->rxd_txd, "txd"))
4198                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4199 }
4200
4201 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
4202         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
4203 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
4204         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
4205                                  "rxd#txd");
4206 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
4207         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
4208 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
4209         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
4210 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
4211         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
4212
4213 cmdline_parse_inst_t cmd_read_rxd_txd = {
4214         .f = cmd_read_rxd_txd_parsed,
4215         .data = NULL,
4216         .help_str = "read rxd|txd port_id queue_id rxd_id",
4217         .tokens = {
4218                 (void *)&cmd_read_rxd_txd_read,
4219                 (void *)&cmd_read_rxd_txd_rxd_txd,
4220                 (void *)&cmd_read_rxd_txd_port_id,
4221                 (void *)&cmd_read_rxd_txd_queue_id,
4222                 (void *)&cmd_read_rxd_txd_desc_id,
4223                 NULL,
4224         },
4225 };
4226
4227 /* *** QUIT *** */
4228 struct cmd_quit_result {
4229         cmdline_fixed_string_t quit;
4230 };
4231
4232 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
4233                             struct cmdline *cl,
4234                             __attribute__((unused)) void *data)
4235 {
4236         pmd_test_exit();
4237         cmdline_quit(cl);
4238 }
4239
4240 cmdline_parse_token_string_t cmd_quit_quit =
4241         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
4242
4243 cmdline_parse_inst_t cmd_quit = {
4244         .f = cmd_quit_parsed,
4245         .data = NULL,
4246         .help_str = "exit application",
4247         .tokens = {
4248                 (void *)&cmd_quit_quit,
4249                 NULL,
4250         },
4251 };
4252
4253 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
4254 struct cmd_mac_addr_result {
4255         cmdline_fixed_string_t mac_addr_cmd;
4256         cmdline_fixed_string_t what;
4257         uint8_t port_num;
4258         struct ether_addr address;
4259 };
4260
4261 static void cmd_mac_addr_parsed(void *parsed_result,
4262                 __attribute__((unused)) struct cmdline *cl,
4263                 __attribute__((unused)) void *data)
4264 {
4265         struct cmd_mac_addr_result *res = parsed_result;
4266         int ret;
4267
4268         if (strcmp(res->what, "add") == 0)
4269                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
4270         else
4271                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
4272
4273         /* check the return value and print it if is < 0 */
4274         if(ret < 0)
4275                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
4276
4277 }
4278
4279 cmdline_parse_token_string_t cmd_mac_addr_cmd =
4280         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
4281                                 "mac_addr");
4282 cmdline_parse_token_string_t cmd_mac_addr_what =
4283         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
4284                                 "add#remove");
4285 cmdline_parse_token_num_t cmd_mac_addr_portnum =
4286                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
4287 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
4288                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
4289
4290 cmdline_parse_inst_t cmd_mac_addr = {
4291         .f = cmd_mac_addr_parsed,
4292         .data = (void *)0,
4293         .help_str = "mac_addr add|remove X <address>: "
4294                         "add/remove MAC address on port X",
4295         .tokens = {
4296                 (void *)&cmd_mac_addr_cmd,
4297                 (void *)&cmd_mac_addr_what,
4298                 (void *)&cmd_mac_addr_portnum,
4299                 (void *)&cmd_mac_addr_addr,
4300                 NULL,
4301         },
4302 };
4303
4304
4305 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
4306 struct cmd_set_qmap_result {
4307         cmdline_fixed_string_t set;
4308         cmdline_fixed_string_t qmap;
4309         cmdline_fixed_string_t what;
4310         uint8_t port_id;
4311         uint16_t queue_id;
4312         uint8_t map_value;
4313 };
4314
4315 static void
4316 cmd_set_qmap_parsed(void *parsed_result,
4317                        __attribute__((unused)) struct cmdline *cl,
4318                        __attribute__((unused)) void *data)
4319 {
4320         struct cmd_set_qmap_result *res = parsed_result;
4321         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
4322
4323         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
4324 }
4325
4326 cmdline_parse_token_string_t cmd_setqmap_set =
4327         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4328                                  set, "set");
4329 cmdline_parse_token_string_t cmd_setqmap_qmap =
4330         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4331                                  qmap, "stat_qmap");
4332 cmdline_parse_token_string_t cmd_setqmap_what =
4333         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4334                                  what, "tx#rx");
4335 cmdline_parse_token_num_t cmd_setqmap_portid =
4336         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4337                               port_id, UINT8);
4338 cmdline_parse_token_num_t cmd_setqmap_queueid =
4339         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4340                               queue_id, UINT16);
4341 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
4342         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4343                               map_value, UINT8);
4344
4345 cmdline_parse_inst_t cmd_set_qmap = {
4346         .f = cmd_set_qmap_parsed,
4347         .data = NULL,
4348         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
4349         .tokens = {
4350                 (void *)&cmd_setqmap_set,
4351                 (void *)&cmd_setqmap_qmap,
4352                 (void *)&cmd_setqmap_what,
4353                 (void *)&cmd_setqmap_portid,
4354                 (void *)&cmd_setqmap_queueid,
4355                 (void *)&cmd_setqmap_mapvalue,
4356                 NULL,
4357         },
4358 };
4359
4360 /* *** CONFIGURE UNICAST HASH TABLE *** */
4361 struct cmd_set_uc_hash_table {
4362         cmdline_fixed_string_t set;
4363         cmdline_fixed_string_t port;
4364         uint8_t port_id;
4365         cmdline_fixed_string_t what;
4366         struct ether_addr address;
4367         cmdline_fixed_string_t mode;
4368 };
4369
4370 static void
4371 cmd_set_uc_hash_parsed(void *parsed_result,
4372                        __attribute__((unused)) struct cmdline *cl,
4373                        __attribute__((unused)) void *data)
4374 {
4375         int ret=0;
4376         struct cmd_set_uc_hash_table *res = parsed_result;
4377         
4378         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4379         
4380         if (strcmp(res->what, "uta") == 0)
4381                 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 
4382                                                 &res->address,(uint8_t)is_on);
4383         if (ret < 0)
4384                 printf("bad unicast hash table parameter, return code = %d \n", ret);
4385         
4386 }
4387
4388 cmdline_parse_token_string_t cmd_set_uc_hash_set =
4389         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4390                                  set, "set");
4391 cmdline_parse_token_string_t cmd_set_uc_hash_port =
4392         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4393                                  port, "port");
4394 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
4395         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
4396                               port_id, UINT8);
4397 cmdline_parse_token_string_t cmd_set_uc_hash_what =
4398         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4399                                  what, "uta");
4400 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
4401         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 
4402                                 address);
4403 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
4404         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4405                                  mode, "on#off");
4406
4407 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
4408         .f = cmd_set_uc_hash_parsed,
4409         .data = NULL,
4410         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
4411         .tokens = {
4412                 (void *)&cmd_set_uc_hash_set,
4413                 (void *)&cmd_set_uc_hash_port,
4414                 (void *)&cmd_set_uc_hash_portid,
4415                 (void *)&cmd_set_uc_hash_what,
4416                 (void *)&cmd_set_uc_hash_mac,
4417                 (void *)&cmd_set_uc_hash_mode,
4418                 NULL,
4419         },
4420 };
4421
4422 struct cmd_set_uc_all_hash_table {
4423         cmdline_fixed_string_t set;
4424         cmdline_fixed_string_t port;
4425         uint8_t port_id;
4426         cmdline_fixed_string_t what;
4427         cmdline_fixed_string_t value;
4428         cmdline_fixed_string_t mode;
4429 };
4430
4431 static void
4432 cmd_set_uc_all_hash_parsed(void *parsed_result,
4433                        __attribute__((unused)) struct cmdline *cl,
4434                        __attribute__((unused)) void *data)
4435 {
4436         int ret=0;
4437         struct cmd_set_uc_all_hash_table *res = parsed_result;
4438         
4439         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4440         
4441         if ((strcmp(res->what, "uta") == 0) && 
4442                 (strcmp(res->value, "all") == 0))
4443                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
4444         if (ret < 0)
4445                 printf("bad unicast hash table parameter," 
4446                         "return code = %d \n", ret);
4447 }
4448
4449 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
4450         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4451                                  set, "set");
4452 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
4453         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4454                                  port, "port");
4455 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
4456         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
4457                               port_id, UINT8);
4458 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
4459         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4460                                  what, "uta");
4461 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
4462         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 
4463                                 value,"all");
4464 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
4465         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4466                                  mode, "on#off");
4467
4468 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
4469         .f = cmd_set_uc_all_hash_parsed,
4470         .data = NULL,
4471         .help_str = "set port X uta all on|off (X = port number)",
4472         .tokens = {
4473                 (void *)&cmd_set_uc_all_hash_set,
4474                 (void *)&cmd_set_uc_all_hash_port,
4475                 (void *)&cmd_set_uc_all_hash_portid,
4476                 (void *)&cmd_set_uc_all_hash_what,
4477                 (void *)&cmd_set_uc_all_hash_value,
4478                 (void *)&cmd_set_uc_all_hash_mode,
4479                 NULL,
4480         },
4481 };
4482
4483 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
4484 struct cmd_set_vf_traffic {
4485         cmdline_fixed_string_t set;
4486         cmdline_fixed_string_t port;
4487         uint8_t port_id;
4488         cmdline_fixed_string_t vf;
4489         uint8_t vf_id;
4490         cmdline_fixed_string_t what;
4491         cmdline_fixed_string_t mode;
4492 };
4493
4494 static void
4495 cmd_set_vf_traffic_parsed(void *parsed_result,
4496                        __attribute__((unused)) struct cmdline *cl,
4497                        __attribute__((unused)) void *data)
4498 {
4499         struct cmd_set_vf_traffic *res = parsed_result;
4500         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
4501         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4502
4503         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
4504 }
4505
4506 cmdline_parse_token_string_t cmd_setvf_traffic_set =
4507         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4508                                  set, "set");
4509 cmdline_parse_token_string_t cmd_setvf_traffic_port =
4510         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4511                                  port, "port");
4512 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
4513         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4514                               port_id, UINT8);
4515 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
4516         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4517                                  vf, "vf");
4518 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
4519         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4520                               vf_id, UINT8);
4521 cmdline_parse_token_string_t cmd_setvf_traffic_what =
4522         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4523                                  what, "tx#rx");
4524 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
4525         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4526                                  mode, "on#off");
4527
4528 cmdline_parse_inst_t cmd_set_vf_traffic = {
4529         .f = cmd_set_vf_traffic_parsed,
4530         .data = NULL,
4531         .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)",
4532         .tokens = {
4533                 (void *)&cmd_setvf_traffic_set,
4534                 (void *)&cmd_setvf_traffic_port,
4535                 (void *)&cmd_setvf_traffic_portid,
4536                 (void *)&cmd_setvf_traffic_vf,
4537                 (void *)&cmd_setvf_traffic_vfid,
4538                 (void *)&cmd_setvf_traffic_what,
4539                 (void *)&cmd_setvf_traffic_mode,
4540                 NULL,
4541         },
4542 };
4543
4544 /* *** CONFIGURE VF RECEIVE MODE *** */
4545 struct cmd_set_vf_rxmode {
4546         cmdline_fixed_string_t set;
4547         cmdline_fixed_string_t port;
4548         uint8_t port_id;
4549         cmdline_fixed_string_t vf;
4550         uint8_t vf_id;
4551         cmdline_fixed_string_t what;
4552         cmdline_fixed_string_t mode;
4553         cmdline_fixed_string_t on;
4554 };
4555
4556 static void
4557 cmd_set_vf_rxmode_parsed(void *parsed_result,
4558                        __attribute__((unused)) struct cmdline *cl,
4559                        __attribute__((unused)) void *data)
4560 {
4561         int ret;
4562         uint16_t rx_mode = 0;
4563         struct cmd_set_vf_rxmode *res = parsed_result;
4564         
4565         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
4566         if (!strcmp(res->what,"rxmode")) {
4567                 if (!strcmp(res->mode, "AUPE"))
4568                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
4569                 else if (!strcmp(res->mode, "ROPE"))
4570                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
4571                 else if (!strcmp(res->mode, "BAM"))
4572                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
4573                 else if (!strncmp(res->mode, "MPE",3))
4574                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
4575         }
4576
4577         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
4578         if (ret < 0)
4579                 printf("bad VF receive mode parameter, return code = %d \n",
4580                 ret);
4581 }
4582
4583 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
4584         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4585                                  set, "set");
4586 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
4587         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4588                                  port, "port");
4589 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
4590         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4591                               port_id, UINT8);
4592 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
4593         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4594                                  vf, "vf");
4595 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
4596         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4597                               vf_id, UINT8);
4598 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
4599         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4600                                  what, "rxmode");
4601 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
4602         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4603                                  mode, "AUPE#ROPE#BAM#MPE");
4604 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
4605         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4606                                  on, "on#off");
4607
4608 cmdline_parse_inst_t cmd_set_vf_rxmode = {
4609         .f = cmd_set_vf_rxmode_parsed,
4610         .data = NULL,
4611         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
4612         .tokens = {
4613                 (void *)&cmd_set_vf_rxmode_set,
4614                 (void *)&cmd_set_vf_rxmode_port,
4615                 (void *)&cmd_set_vf_rxmode_portid,
4616                 (void *)&cmd_set_vf_rxmode_vf,
4617                 (void *)&cmd_set_vf_rxmode_vfid,
4618                 (void *)&cmd_set_vf_rxmode_what,
4619                 (void *)&cmd_set_vf_rxmode_mode,
4620                 (void *)&cmd_set_vf_rxmode_on,
4621                 NULL,
4622         },
4623 };
4624
4625 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
4626 struct cmd_vf_mac_addr_result {
4627         cmdline_fixed_string_t mac_addr_cmd;
4628         cmdline_fixed_string_t what;
4629         cmdline_fixed_string_t port;
4630         uint8_t port_num;
4631         cmdline_fixed_string_t vf;
4632         uint8_t vf_num;
4633         struct ether_addr address;
4634 };
4635
4636 static void cmd_vf_mac_addr_parsed(void *parsed_result,
4637                 __attribute__((unused)) struct cmdline *cl,
4638                 __attribute__((unused)) void *data)
4639 {
4640         struct cmd_vf_mac_addr_result *res = parsed_result;
4641         int ret = 0;
4642
4643         if (strcmp(res->what, "add") == 0)
4644                 ret = rte_eth_dev_mac_addr_add(res->port_num, 
4645                                         &res->address, res->vf_num);
4646         if(ret < 0)
4647                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
4648
4649 }
4650
4651 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
4652         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4653                                 mac_addr_cmd,"mac_addr");
4654 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
4655         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4656                                 what,"add");
4657 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
4658         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4659                                 port,"port");
4660 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
4661         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 
4662                                 port_num, UINT8);
4663 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
4664         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4665                                 vf,"vf");
4666 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
4667         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
4668                                 vf_num, UINT8);
4669 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
4670         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 
4671                                 address);
4672
4673 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
4674         .f = cmd_vf_mac_addr_parsed,
4675         .data = (void *)0,
4676         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
4677         "Y = VF number)add MAC address filtering for a VF on port X",
4678         .tokens = {
4679                 (void *)&cmd_vf_mac_addr_cmd,
4680                 (void *)&cmd_vf_mac_addr_what,
4681                 (void *)&cmd_vf_mac_addr_port,
4682                 (void *)&cmd_vf_mac_addr_portnum,
4683                 (void *)&cmd_vf_mac_addr_vf,
4684                 (void *)&cmd_vf_mac_addr_vfnum,
4685                 (void *)&cmd_vf_mac_addr_addr,
4686                 NULL,
4687         },
4688 };
4689
4690 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4691 struct cmd_vf_rx_vlan_filter {
4692         cmdline_fixed_string_t rx_vlan;
4693         cmdline_fixed_string_t what;
4694         uint16_t vlan_id;
4695         cmdline_fixed_string_t port;
4696         uint8_t port_id;
4697         cmdline_fixed_string_t vf;
4698         uint64_t vf_mask;
4699 };
4700
4701 static void
4702 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
4703                           __attribute__((unused)) struct cmdline *cl,
4704                           __attribute__((unused)) void *data)
4705 {
4706         struct cmd_vf_rx_vlan_filter *res = parsed_result;
4707
4708         if (!strcmp(res->what, "add"))
4709                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
4710         else
4711                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
4712 }
4713
4714 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
4715         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4716                                  rx_vlan, "rx_vlan");
4717 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
4718         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4719                                  what, "add#rm");
4720 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
4721         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4722                               vlan_id, UINT16);
4723 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
4724         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4725                                  port, "port");
4726 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
4727         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4728                               port_id, UINT8);
4729 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
4730         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4731                                  vf, "vf");
4732 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
4733         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4734                               vf_mask, UINT64);
4735
4736 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
4737         .f = cmd_vf_rx_vlan_filter_parsed,
4738         .data = NULL,
4739         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
4740                 "Y = port number,Z = hexadecimal VF mask)",
4741         .tokens = {
4742                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
4743                 (void *)&cmd_vf_rx_vlan_filter_what,
4744                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
4745                 (void *)&cmd_vf_rx_vlan_filter_port,
4746                 (void *)&cmd_vf_rx_vlan_filter_portid,
4747                 (void *)&cmd_vf_rx_vlan_filter_vf,
4748                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
4749                 NULL,
4750         },
4751 };
4752
4753 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
4754 struct cmd_set_mirror_mask_result {
4755         cmdline_fixed_string_t set;
4756         cmdline_fixed_string_t port;
4757         uint8_t port_id;
4758         cmdline_fixed_string_t mirror;
4759         uint8_t rule_id;
4760         cmdline_fixed_string_t what;
4761         cmdline_fixed_string_t value;
4762         cmdline_fixed_string_t dstpool;
4763         uint8_t dstpool_id;
4764         cmdline_fixed_string_t on;
4765 };
4766
4767 cmdline_parse_token_string_t cmd_mirror_mask_set =
4768         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4769                                 set, "set");
4770 cmdline_parse_token_string_t cmd_mirror_mask_port =
4771         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4772                                 port, "port");
4773 cmdline_parse_token_string_t cmd_mirror_mask_portid =
4774         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4775                                 port_id, UINT8);
4776 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
4777         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4778                                 mirror, "mirror-rule");
4779 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
4780         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4781                                 rule_id, UINT8);
4782 cmdline_parse_token_string_t cmd_mirror_mask_what =
4783         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4784                                 what, "pool-mirror#vlan-mirror");
4785 cmdline_parse_token_string_t cmd_mirror_mask_value =
4786         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4787                                 value, NULL);
4788 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
4789         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4790                                 dstpool, "dst-pool");
4791 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
4792         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4793                                 dstpool_id, UINT8);
4794 cmdline_parse_token_string_t cmd_mirror_mask_on =
4795         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4796                                 on, "on#off");
4797
4798 static void
4799 cmd_set_mirror_mask_parsed(void *parsed_result,
4800                        __attribute__((unused)) struct cmdline *cl,
4801                        __attribute__((unused)) void *data)
4802 {
4803         int ret,nb_item,i;
4804         struct cmd_set_mirror_mask_result *res = parsed_result;
4805         struct rte_eth_vmdq_mirror_conf mr_conf;
4806
4807         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
4808
4809         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
4810
4811         mr_conf.dst_pool = res->dstpool_id;
4812
4813         if (!strcmp(res->what, "pool-mirror")) {
4814                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
4815                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
4816         } else if(!strcmp(res->what, "vlan-mirror")) {
4817                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
4818                 nb_item = parse_item_list(res->value, "core",
4819                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
4820                 if (nb_item <= 0)
4821                         return;
4822
4823                 for(i=0; i < nb_item; i++) {
4824                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
4825                                 printf("Invalid vlan_id: must be < 4096\n");
4826                                 return;
4827                         }
4828
4829                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
4830                         mr_conf.vlan.vlan_mask |= 1ULL << i;
4831                 }
4832         }
4833
4834         if(!strcmp(res->on, "on"))
4835                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4836                                                 res->rule_id, 1);
4837         else
4838                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4839                                                 res->rule_id, 0);
4840         if(ret < 0)
4841                 printf("mirror rule add error: (%s)\n", strerror(-ret));
4842 }
4843
4844 cmdline_parse_inst_t cmd_set_mirror_mask = {
4845                 .f = cmd_set_mirror_mask_parsed,
4846                 .data = NULL,
4847                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror " 
4848                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
4849                 .tokens = {
4850                         (void *)&cmd_mirror_mask_set,
4851                         (void *)&cmd_mirror_mask_port,
4852                         (void *)&cmd_mirror_mask_portid,
4853                         (void *)&cmd_mirror_mask_mirror,
4854                         (void *)&cmd_mirror_mask_ruleid,
4855                         (void *)&cmd_mirror_mask_what,
4856                         (void *)&cmd_mirror_mask_value,
4857                         (void *)&cmd_mirror_mask_dstpool,
4858                         (void *)&cmd_mirror_mask_poolid,
4859                         (void *)&cmd_mirror_mask_on,
4860                         NULL,
4861                 },
4862 };
4863
4864 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
4865 struct cmd_set_mirror_link_result {
4866         cmdline_fixed_string_t set;
4867         cmdline_fixed_string_t port;
4868         uint8_t port_id;
4869         cmdline_fixed_string_t mirror;
4870         uint8_t rule_id;
4871         cmdline_fixed_string_t what;
4872         cmdline_fixed_string_t dstpool;
4873         uint8_t dstpool_id;
4874         cmdline_fixed_string_t on;
4875 };
4876
4877 cmdline_parse_token_string_t cmd_mirror_link_set =
4878         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4879                                  set, "set");
4880 cmdline_parse_token_string_t cmd_mirror_link_port =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4882                                 port, "port");
4883 cmdline_parse_token_string_t cmd_mirror_link_portid =
4884         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4885                                 port_id, UINT8);
4886 cmdline_parse_token_string_t cmd_mirror_link_mirror =
4887         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4888                                 mirror, "mirror-rule");
4889 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
4890         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4891                             rule_id, UINT8);
4892 cmdline_parse_token_string_t cmd_mirror_link_what =
4893         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4894                                 what, "uplink-mirror#downlink-mirror");
4895 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
4896         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4897                                 dstpool, "dst-pool");
4898 cmdline_parse_token_num_t cmd_mirror_link_poolid =
4899         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4900                                 dstpool_id, UINT8);
4901 cmdline_parse_token_string_t cmd_mirror_link_on =
4902         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4903                                 on, "on#off");
4904
4905 static void
4906 cmd_set_mirror_link_parsed(void *parsed_result,
4907                        __attribute__((unused)) struct cmdline *cl,
4908                        __attribute__((unused)) void *data)
4909 {
4910         int ret;
4911         struct cmd_set_mirror_link_result *res = parsed_result;
4912         struct rte_eth_vmdq_mirror_conf mr_conf;
4913
4914         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
4915         if(!strcmp(res->what, "uplink-mirror")) {
4916                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
4917         }else if(!strcmp(res->what, "downlink-mirror"))
4918                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
4919
4920         mr_conf.dst_pool = res->dstpool_id;
4921
4922         if(!strcmp(res->on, "on"))
4923                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4924                                                 res->rule_id, 1);
4925         else
4926                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4927                                                 res->rule_id, 0);
4928
4929         /* check the return value and print it if is < 0 */
4930         if(ret < 0)
4931                 printf("mirror rule add error: (%s)\n", strerror(-ret));
4932
4933 }
4934
4935 cmdline_parse_inst_t cmd_set_mirror_link = {
4936                 .f = cmd_set_mirror_link_parsed,
4937                 .data = NULL,
4938                 .help_str = "set port X mirror-rule Y uplink-mirror|"
4939                         "downlink-mirror dst-pool Z on|off",
4940                 .tokens = {
4941                         (void *)&cmd_mirror_link_set,
4942                         (void *)&cmd_mirror_link_port,
4943                         (void *)&cmd_mirror_link_portid,
4944                         (void *)&cmd_mirror_link_mirror,
4945                         (void *)&cmd_mirror_link_ruleid,
4946                         (void *)&cmd_mirror_link_what,
4947                         (void *)&cmd_mirror_link_dstpool,
4948                         (void *)&cmd_mirror_link_poolid,
4949                         (void *)&cmd_mirror_link_on,
4950                         NULL,
4951                 },
4952 };
4953
4954 /* *** RESET VM MIRROR RULE *** */
4955 struct cmd_rm_mirror_rule_result {
4956         cmdline_fixed_string_t reset;
4957         cmdline_fixed_string_t port;
4958         uint8_t port_id;
4959         cmdline_fixed_string_t mirror;
4960         uint8_t rule_id;
4961 };
4962
4963 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
4964         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4965                                  reset, "reset");
4966 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
4967         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4968                                 port, "port");
4969 cmdline_parse_token_string_t cmd_rm_mirror_rule_portid =
4970         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
4971                                 port_id, UINT8);
4972 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
4973         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4974                                 mirror, "mirror-rule");
4975 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
4976         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
4977                                 rule_id, UINT8);
4978
4979 static void
4980 cmd_reset_mirror_rule_parsed(void *parsed_result,
4981                        __attribute__((unused)) struct cmdline *cl,
4982                        __attribute__((unused)) void *data)
4983 {
4984         int ret;
4985         struct cmd_set_mirror_link_result *res = parsed_result;
4986         /* check rule_id */
4987         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
4988         if(ret < 0)
4989                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
4990 }
4991
4992 cmdline_parse_inst_t cmd_reset_mirror_rule = {
4993                 .f = cmd_reset_mirror_rule_parsed,
4994                 .data = NULL,
4995                 .help_str = "reset port X mirror-rule Y",
4996                 .tokens = {
4997                         (void *)&cmd_rm_mirror_rule_reset,
4998                         (void *)&cmd_rm_mirror_rule_port,
4999                         (void *)&cmd_rm_mirror_rule_portid,
5000                         (void *)&cmd_rm_mirror_rule_mirror,
5001                         (void *)&cmd_rm_mirror_rule_ruleid,
5002                         NULL,
5003                 },
5004 };
5005
5006 /* ******************************************************************************** */
5007
5008 struct cmd_dump_result {
5009         cmdline_fixed_string_t dump;
5010 };
5011
5012 static void
5013 dump_struct_sizes(void)
5014 {
5015 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
5016         DUMP_SIZE(struct rte_mbuf);
5017         DUMP_SIZE(struct rte_pktmbuf);
5018         DUMP_SIZE(struct rte_ctrlmbuf);
5019         DUMP_SIZE(struct rte_mempool);
5020         DUMP_SIZE(struct rte_ring);
5021 #undef DUMP_SIZE
5022 }
5023
5024 static void cmd_dump_parsed(void *parsed_result,
5025                             __attribute__((unused)) struct cmdline *cl,
5026                             __attribute__((unused)) void *data)
5027 {
5028         struct cmd_dump_result *res = parsed_result;
5029
5030         if (!strcmp(res->dump, "dump_physmem"))
5031                 rte_dump_physmem_layout();
5032         else if (!strcmp(res->dump, "dump_memzone"))
5033                 rte_memzone_dump();
5034         else if (!strcmp(res->dump, "dump_log_history"))
5035                 rte_log_dump_history();
5036         else if (!strcmp(res->dump, "dump_struct_sizes"))
5037                 dump_struct_sizes();
5038         else if (!strcmp(res->dump, "dump_ring"))
5039                 rte_ring_list_dump();
5040         else if (!strcmp(res->dump, "dump_mempool"))
5041                 rte_mempool_list_dump();
5042         else if (!strcmp(res->dump, "dump_devargs"))
5043                 rte_eal_devargs_dump();
5044 }
5045
5046 cmdline_parse_token_string_t cmd_dump_dump =
5047         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
5048                 "dump_physmem#"
5049                 "dump_memzone#"
5050                 "dump_log_history#"
5051                 "dump_struct_sizes#"
5052                 "dump_ring#"
5053                 "dump_mempool#"
5054                 "dump_devargs");
5055
5056 cmdline_parse_inst_t cmd_dump = {
5057         .f = cmd_dump_parsed,  /* function to call */
5058         .data = NULL,      /* 2nd arg of func */
5059         .help_str = "dump status",
5060         .tokens = {        /* token list, NULL terminated */
5061                 (void *)&cmd_dump_dump,
5062                 NULL,
5063         },
5064 };
5065
5066 /* ******************************************************************************** */
5067
5068 struct cmd_dump_one_result {
5069         cmdline_fixed_string_t dump;
5070         cmdline_fixed_string_t name;
5071 };
5072
5073 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
5074                                 __attribute__((unused)) void *data)
5075 {
5076         struct cmd_dump_one_result *res = parsed_result;
5077
5078         if (!strcmp(res->dump, "dump_ring")) {
5079                 struct rte_ring *r;
5080                 r = rte_ring_lookup(res->name);
5081                 if (r == NULL) {
5082                         cmdline_printf(cl, "Cannot find ring\n");
5083                         return;
5084                 }
5085                 rte_ring_dump(r);
5086         } else if (!strcmp(res->dump, "dump_mempool")) {
5087                 struct rte_mempool *mp;
5088                 mp = rte_mempool_lookup(res->name);
5089                 if (mp == NULL) {
5090                         cmdline_printf(cl, "Cannot find mempool\n");
5091                         return;
5092                 }
5093                 rte_mempool_dump(mp);
5094         }
5095 }
5096
5097 cmdline_parse_token_string_t cmd_dump_one_dump =
5098         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
5099                                  "dump_ring#dump_mempool");
5100
5101 cmdline_parse_token_string_t cmd_dump_one_name =
5102         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
5103
5104 cmdline_parse_inst_t cmd_dump_one = {
5105         .f = cmd_dump_one_parsed,  /* function to call */
5106         .data = NULL,      /* 2nd arg of func */
5107         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
5108         .tokens = {        /* token list, NULL terminated */
5109                 (void *)&cmd_dump_one_dump,
5110                 (void *)&cmd_dump_one_name,
5111                 NULL,
5112         },
5113 };
5114
5115 /* ******************************************************************************** */
5116
5117 /* list of instructions */
5118 cmdline_parse_ctx_t main_ctx[] = {
5119         (cmdline_parse_inst_t *)&cmd_help_brief,
5120         (cmdline_parse_inst_t *)&cmd_help_long,
5121         (cmdline_parse_inst_t *)&cmd_quit,
5122         (cmdline_parse_inst_t *)&cmd_showport,
5123         (cmdline_parse_inst_t *)&cmd_showportall,
5124         (cmdline_parse_inst_t *)&cmd_showcfg,
5125         (cmdline_parse_inst_t *)&cmd_start,
5126         (cmdline_parse_inst_t *)&cmd_start_tx_first,
5127         (cmdline_parse_inst_t *)&cmd_reset,
5128         (cmdline_parse_inst_t *)&cmd_set_numbers,
5129         (cmdline_parse_inst_t *)&cmd_set_txpkts,
5130         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
5131         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
5132         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
5133         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
5134         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
5135         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
5136         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
5137         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
5138         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
5139 #ifdef RTE_NIC_BYPASS
5140         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
5141         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
5142         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
5143         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
5144 #endif
5145         (cmdline_parse_inst_t *)&cmd_vlan_offload,
5146         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
5147         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
5148         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
5149         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
5150         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
5151         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
5152         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
5153         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
5154         (cmdline_parse_inst_t *)&cmd_config_dcb,
5155         (cmdline_parse_inst_t *)&cmd_read_reg,
5156         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
5157         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
5158         (cmdline_parse_inst_t *)&cmd_write_reg,
5159         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
5160         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
5161         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
5162         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
5163         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
5164         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
5165         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
5166         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
5167         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
5168         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
5169         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
5170         (cmdline_parse_inst_t *)&cmd_stop,
5171         (cmdline_parse_inst_t *)&cmd_mac_addr,
5172         (cmdline_parse_inst_t *)&cmd_set_qmap,
5173         (cmdline_parse_inst_t *)&cmd_operate_port,
5174         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
5175         (cmdline_parse_inst_t *)&cmd_config_speed_all,
5176         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
5177         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
5178         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
5179         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
5180         (cmdline_parse_inst_t *)&cmd_config_rss,
5181         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
5182         (cmdline_parse_inst_t *)&cmd_showport_reta,
5183         (cmdline_parse_inst_t *)&cmd_config_burst,
5184         (cmdline_parse_inst_t *)&cmd_config_thresh,
5185         (cmdline_parse_inst_t *)&cmd_config_threshold,
5186         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
5187         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
5188         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
5189         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
5190         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
5191         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
5192         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
5193         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
5194         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
5195         (cmdline_parse_inst_t *)&cmd_dump,
5196         (cmdline_parse_inst_t *)&cmd_dump_one,
5197         NULL,
5198 };
5199
5200 /* prompt function, called from main on MASTER lcore */
5201 void
5202 prompt(void)
5203 {
5204         struct cmdline *cl;
5205
5206         /* initialize non-constant commands */
5207         cmd_set_fwd_mode_init();
5208
5209         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
5210         if (cl == NULL) {
5211                 return;
5212         }
5213         cmdline_interact(cl);
5214         cmdline_stdin_exit(cl);
5215 }
5216
5217 static void
5218 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
5219 {
5220         if (id < nb_ports) {
5221                 /* check if need_reconfig has been set to 1 */
5222                 if (ports[id].need_reconfig == 0)
5223                         ports[id].need_reconfig = dev;
5224                 /* check if need_reconfig_queues has been set to 1 */
5225                 if (ports[id].need_reconfig_queues == 0)
5226                         ports[id].need_reconfig_queues = queue;
5227         } else {
5228                 portid_t pid;
5229
5230                 for (pid = 0; pid < nb_ports; pid++) {
5231                         /* check if need_reconfig has been set to 1 */
5232                         if (ports[pid].need_reconfig == 0)
5233                                 ports[pid].need_reconfig = dev;
5234                         /* check if need_reconfig_queues has been set to 1 */
5235                         if (ports[pid].need_reconfig_queues == 0)
5236                                 ports[pid].need_reconfig_queues = queue;
5237                 }
5238         }
5239 }
5240
5241 #ifdef RTE_NIC_BYPASS
5242 uint8_t
5243 bypass_is_supported(portid_t port_id)
5244 {
5245         struct rte_port   *port;
5246         struct rte_pci_id *pci_id;
5247
5248         if (port_id >= nb_ports) {
5249                 printf("\tPort id must be less than %d.\n", nb_ports);
5250                 return 0;
5251         }
5252
5253         /* Get the device id. */
5254         port    = &ports[port_id];
5255         pci_id = &port->dev_info.pci_dev->id;
5256
5257         /* Check if NIC supports bypass. */
5258         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
5259                 return 1;
5260         }
5261         else {
5262                 printf("\tBypass not supported for port_id = %d.\n", port_id);
5263                 return 0;
5264         }
5265 }
5266 #endif