9c1bda9b5d3d7aaab4d0a3d2f1b5829530f2b340
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
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 #include <net/socket.h>
46 #endif
47 #include <netinet/in.h>
48
49 #include <sys/queue.h>
50
51 #include <rte_common.h>
52 #include <rte_byteorder.h>
53 #include <rte_log.h>
54 #include <rte_debug.h>
55 #include <rte_cycles.h>
56 #include <rte_memory.h>
57 #include <rte_memzone.h>
58 #include <rte_launch.h>
59 #include <rte_tailq.h>
60 #include <rte_eal.h>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.h>
65 #include <rte_ring.h>
66 #include <rte_mempool.h>
67 #include <rte_interrupts.h>
68 #include <rte_pci.h>
69 #include <rte_ether.h>
70 #include <rte_ethdev.h>
71 #include <rte_string_fns.h>
72
73 #include <cmdline_rdline.h>
74 #include <cmdline_parse.h>
75 #include <cmdline_parse_num.h>
76 #include <cmdline_parse_string.h>
77 #include <cmdline_parse_ipaddr.h>
78 #include <cmdline_parse_etheraddr.h>
79 #include <cmdline_socket.h>
80 #include <cmdline.h>
81
82 #include "testpmd.h"
83
84 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
85
86 /* *** Help command with introduction. *** */
87 struct cmd_help_brief_result {
88         cmdline_fixed_string_t help;
89 };
90
91 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
92                                   struct cmdline *cl,
93                                   __attribute__((unused)) void *data)
94 {
95         cmdline_printf(
96                 cl,
97                 "\n"
98                 "Help is available for the following sections:\n\n"
99                 "    help control    : Start and stop forwarding.\n"
100                 "    help display    : Displaying port, stats and config "
101                 "information.\n"
102                 "    help config     : Configuration information.\n"
103                 "    help ports      : Configuring ports.\n"
104                 "    help flowdir    : Flow Director filter help.\n"
105                 "    help registers  : Reading and setting port registers.\n"
106                 "    help all        : All of the above sections.\n\n"
107         );
108
109 }
110
111 cmdline_parse_token_string_t cmd_help_brief_help =
112         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
113
114 cmdline_parse_inst_t cmd_help_brief = {
115         .f = cmd_help_brief_parsed,
116         .data = NULL,
117         .help_str = "show help",
118         .tokens = {
119                 (void *)&cmd_help_brief_help,
120                 NULL,
121         },
122 };
123
124 /* *** Help command with help sections. *** */
125 struct cmd_help_long_result {
126         cmdline_fixed_string_t help;
127         cmdline_fixed_string_t section;
128 };
129
130 static void cmd_help_long_parsed(void *parsed_result,
131                                  struct cmdline *cl,
132                                  __attribute__((unused)) void *data)
133 {
134         int show_all = 0;
135         struct cmd_help_long_result *res = parsed_result;
136
137         if (!strcmp(res->section, "all"))
138                 show_all = 1;
139
140         if (show_all || !strcmp(res->section, "control")) {
141
142                 cmdline_printf(
143                         cl,
144                         "\n"
145                         "Control forwarding:\n"
146                         "-------------------\n\n"
147
148                         "start\n"
149                         "    Start packet forwarding with current configuration.\n\n"
150
151                         "start tx_first\n"
152                         "    Start packet forwarding with current config"
153                         " after sending one burst of packets.\n\n"
154
155                         "stop\n"
156                         "    Stop packet forwarding, and display accumulated"
157                         " statistics.\n\n"
158
159                         "quit\n"
160                         "    Quit to prompt in Linux and reboot on Baremetal.\n\n"
161                 );
162         }
163
164         if (show_all || !strcmp(res->section, "display")) {
165
166                 cmdline_printf(
167                         cl,
168                         "\n"
169                         "Display:\n"
170                         "--------\n\n"
171
172                         "show port (info|stats|fdir|stat_qmap) (port_id|all)\n"
173                         "    Display information for port_id, or all.\n\n"
174
175                         "clear port (info|stats|fdir|stat_qmap) (port_id|all)\n"
176                         "    Clear information for port_id, or all.\n\n"
177
178                         "show config (rxtx|cores|fwd)\n"
179                         "    Display the given configuration.\n\n"
180
181                         "read rxd (port_id) (queue_id) (rxd_id)\n"
182                         "    Display an RX descriptor of a port RX queue.\n\n"
183
184                         "read txd (port_id) (queue_id) (txd_id)\n"
185                         "    Display a TX descriptor of a port TX queue.\n\n"
186                 );
187         }
188
189         if (show_all || !strcmp(res->section, "config")) {
190                 cmdline_printf(
191                         cl,
192                         "\n"
193                         "Configuration:\n"
194                         "--------------\n"
195                         "Configuration changes only become active when"
196                         " forwarding is started/restarted.\n\n"
197
198                         "set default\n"
199                         "    Reset forwarding to the default configuration.\n\n"
200
201                         "set verbose (level)\n"
202                         "    Set the debug verbosity level X.\n\n"
203
204                         "set nbport (num)\n"
205                         "    Set number of ports.\n\n"
206
207                         "set nbcore (num)\n"
208                         "    Set number of cores.\n\n"
209
210                         "set coremask (mask)\n"
211                         "    Set the forwarding cores hexadecimal mask.\n\n"
212
213                         "set portmask (mask)\n"
214                         "    Set the forwarding ports hexadecimal mask.\n\n"
215
216                         "set burst (num)\n"
217                         "    Set number of packets per burst.\n\n"
218
219                         "set txpkts (x[,y]*)\n"
220                         "    Set the length of each segment of TXONLY"
221                         " packets.\n\n"
222
223                         "set corelist (x[,y]*)\n"
224                         "    Set the list of forwarding cores.\n\n"
225
226                         "set portlist (x[,y]*)\n"
227                         "    Set the list of forwarding ports.\n\n"
228
229                         "vlan set strip (on|off) (port_id)\n"
230                         "    Set the VLAN strip on a port.\n\n"
231
232                         "vlan set filter (on|off) (port_id)\n"
233                         "    Set the VLAN filter on a port.\n\n"
234
235                         "vlan set qinq (on|off) (port_id)\n"
236                         "    Set the VLAN QinQ (extended queue in queue)"
237                         " on a port.\n\n"
238
239                         "vlan set tpid (value) (port_id)\n"
240                         "    Set the outer VLAN TPID for Packet Filtering on"
241                         " a port\n\n"
242
243                         "rx_vlan add (vlan_id|all) (port_id)\n"
244                         "    Add a vlan_id, or all identifiers, to the set"
245                         " of VLAN identifiers filtered by port_id.\n\n"
246
247                         "rx_vlan rm (vlan_id|all) (port_id)\n"
248                         "    Remove a vlan_id, or all identifiers, from the set"
249                         " of VLAN identifiers filtered by port_id.\n\n"
250
251                         "tx_vlan set vlan_id (port_id)\n"
252                         "    Set hardware insertion of VLAN ID in packets sent"
253                         " on a port.\n\n"
254
255                         "tx_vlan reset (port_id)\n"
256                         "    Disable hardware insertion of a VLAN header in"
257                         " packets sent on a port.\n\n"
258
259                         "tx_checksum set mask (port_id)\n"
260                         "    Enable hardware insertion of checksum offload with"
261                         " the 4-bit mask, 0~0xf, in packets sent on a port.\n"
262                         "        bit 0 - insert ip   checksum offload if set\n"
263                         "        bit 1 - insert udp  checksum offload if set\n"
264                         "        bit 2 - insert tcp  checksum offload if set\n"
265                         "        bit 3 - insert sctp checksum offload if set\n"
266                         "    Please check the NIC datasheet for HW limits.\n\n"
267
268 #ifdef RTE_LIBRTE_IEEE1588
269                         "set fwd (io|mac|rxonly|txonly|csum|ieee1588)\n"
270                         "    Set IO, MAC, RXONLY, CSUM or TXONLY or ieee1588"
271                         " packet forwarding mode.\n\n"
272
273 #else
274                         "set fwd (io|mac|rxonly|txonly|csum)\n"
275                         "    Set IO, MAC, RXONLY, CSUM or TXONLY packet"
276                         " forwarding mode.\n\n"
277
278 #endif
279                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
280                         "    Add a MAC address on port_id.\n\n"
281
282                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
283                         "    Remove a MAC address from port_id.\n\n"
284
285                         "set promisc (port_id|all) (on|off)\n"
286                         "    Set the promiscuous mode on port_id, or all.\n\n"
287
288                         "set allmulti (port_id|all) (on|off)\n"
289                         "    Set the allmulti mode on port_id, or all.\n\n"
290
291                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
292                         " (low_water) (pause_time) (send_xon) (port_id)\n"
293                         "    Set the link flow control parameter on a port.\n\n"
294
295                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
296                         " (low_water) (pause_time) (priority) (port_id)\n"
297                         "    Set the priority flow control parameter on a"
298                         " port.\n\n"
299
300                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
301                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
302                         " queue on port.\n"
303                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
304                         " on port 0 to mapping 5.\n\n"
305                 );
306         }
307
308
309         if (show_all || !strcmp(res->section, "flowdir")) {
310
311                 cmdline_printf(
312                         cl,
313                         "\n"
314                         "Flow director mode:\n"
315                         "-------------------\n\n"
316
317                         "add_signature_filter (port_id) (ip|udp|tcp|sctp)"
318                         " src (src_ip_address) (src_port)"
319                         " dst (dst_ip_address) (dst_port)"
320                         " flexbytes (flexbytes_values) vlan (vlan_id)"
321                         " queue (queue_id)\n"
322                         "    Add a signature filter.\n\n"
323
324                         "upd_signature_filter (port_id) (ip|udp|tcp|sctp)"
325                         " src (src_ip_address) (src_port)"
326                         " dst (dst_ip_address) (dst_port)"
327                         " flexbytes (flexbytes_values) vlan (vlan_id)"
328                         " queue (queue_id)\n"
329                         "    Update a signature filter.\n\n"
330
331                         "rm_signature_filter (port_id) (ip|udp|tcp|sctp)"
332                         " src (src_ip_address) (src_port)"
333                         " dst (dst_ip_address) (dst_port)"
334                         " flexbytes (flexbytes_values) vlan (vlan_id)\n"
335                         "    Remove a signature filter.\n\n"
336
337                         "add_perfect_filter (port_id) (ip|udp|tcp|sctp)"
338                         " src (src_ip_address) (src_port)"
339                         " dst (dst_ip_address) (dst_port)"
340                         " flexbytes (flexbytes_values) vlan (vlan_id)"
341                         " queue (queue_id) soft (soft_id)\n"
342                         "    Add a perfect filter.\n\n"
343
344                         "upd_perfect_filter (port_id) (ip|udp|tcp|sctp)"
345                         " src (src_ip_address) (src_port)"
346                         " dst (dst_ip_address) (dst_port)"
347                         " flexbytes (flexbytes_values) vlan (vlan_id)"
348                         " queue (queue_id)\n"
349                         "    Update a perfect filter.\n\n"
350
351                         "rm_perfect_filter (port_id) (ip|udp|tcp|sctp)"
352                         " src (src_ip_address) (src_port)"
353                         " dst (dst_ip_address) (dst_port)"
354                         " flexbytes (flexbytes_values) vlan (vlan_id)"
355                         " soft (soft_id)\n"
356                         "    Remove a perfect filter.\n\n"
357
358                         "set_masks_filter (port_id) only_ip_flow (0|1)"
359                         " src_mask (ip_src_mask) (src_port_mask)"
360                         " dst_mask (ip_dst_mask) (dst_port_mask)"
361                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)\n"
362                         "    Set IPv4 filter masks.\n\n"
363
364                         "set_ipv6_masks_filter (port_id) only_ip_flow (0|1)"
365                         " src_mask (ip_src_mask) (src_port_mask)"
366                         " dst_mask (ip_dst_mask) (dst_port_mask)"
367                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)"
368                         " compare_dst (0|1)\n"
369                         "    Set IPv6 filter masks.\n\n"
370                 );
371         }
372
373         if (show_all || !strcmp(res->section, "ports")) {
374
375                 cmdline_printf(
376                         cl,
377                         "\n"
378                         "Port Operations:\n"
379                         "----------------\n\n"
380
381                         "port start (port_id|all)\n"
382                         "    Start all ports or port_id.\n\n"
383
384                         "port stop (port_id|all)\n"
385                         "    Stop all ports or port_id.\n\n"
386
387                         "port close (port_id|all)\n"
388                         "    Close all ports or port_id.\n\n"
389
390                         "port config (port_id|all) speed (10|100|1000|10000|auto)"
391                         " duplex (half|full|auto)\n"
392                         "    Set speed and duplex for all ports or port_id\n\n"
393
394                         "port config all (rxq|txq|rxd|txd) (value)\n"
395                         "    Set number for rxq/txq/rxd/txd.\n\n"
396
397                         "port config all max-pkt-len (value)\n"
398                         "    Set the max packet length.\n\n"
399
400                         "port config all (crc-strip|rx-cksum|hw-vlan|drop-en)"
401                         " (on|off)\n"
402                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
403                         " for ports.\n\n"
404
405                         "port config all rss (ip|udp|none)\n"
406                         "    Set the RSS mode.\n\n"
407
408                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
409                         "    Set the RSS redirection table.\n\n"
410
411                         "port config (port_id) dcb vt (on|off) (traffic_class)"
412                         " pfc (on|off)\n"
413                         "    Set the DCB mode.\n\n"
414
415                         "port config all burst (value)\n"
416                         "    Set the number of packets per burst.\n\n"
417
418                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
419                         " (value)\n"
420                         "    Set the ring prefetch/host/writeback threshold"
421                         " for tx/rx queue.\n\n"
422
423                         "port config all (txfreet|txrst|rxfreet) (value)\n"
424                         "    Set free threshold for rx/tx, or set"
425                         " tx rs bit threshold.\n\n"
426                 );
427         }
428
429         if (show_all || !strcmp(res->section, "registers")) {
430
431                 cmdline_printf(
432                         cl,
433                         "\n"
434                         "Registers:\n"
435                         "----------\n\n"
436
437                         "read reg (port_id) (address)\n"
438                         "    Display value of a port register.\n\n"
439
440                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
441                         "    Display a port register bit field.\n\n"
442
443                         "read regbit (port_id) (address) (bit_x)\n"
444                         "    Display a single port register bit.\n\n"
445
446                         "write reg (port_id) (address) (value)\n"
447                         "    Set value of a port register.\n\n"
448
449                         "write regfield (port_id) (address) (bit_x) (bit_y)"
450                         " (value)\n"
451                         "    Set bit field of a port register.\n\n"
452
453                         "write regbit (port_id) (address) (bit_x) (value)\n"
454                         "    Set single bit value of a port register.\n\n"
455                 );
456         }
457 }
458
459 cmdline_parse_token_string_t cmd_help_long_help =
460         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
461
462 cmdline_parse_token_string_t cmd_help_long_section =
463         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
464                         "all#control#display#config#flowdir#"
465                         "ports#registers");
466
467 cmdline_parse_inst_t cmd_help_long = {
468         .f = cmd_help_long_parsed,
469         .data = NULL,
470         .help_str = "show help",
471         .tokens = {
472                 (void *)&cmd_help_long_help,
473                 (void *)&cmd_help_long_section,
474                 NULL,
475         },
476 };
477
478
479 /* *** start/stop/close all ports *** */
480 struct cmd_operate_port_result {
481         cmdline_fixed_string_t keyword;
482         cmdline_fixed_string_t name;
483         cmdline_fixed_string_t value;
484 };
485
486 static void cmd_operate_port_parsed(void *parsed_result,
487                                 __attribute__((unused)) struct cmdline *cl,
488                                 __attribute__((unused)) void *data)
489 {
490         struct cmd_operate_port_result *res = parsed_result;
491
492         if (!strcmp(res->name, "start"))
493                 start_port(RTE_PORT_ALL);
494         else if (!strcmp(res->name, "stop"))
495                 stop_port(RTE_PORT_ALL);
496         else if (!strcmp(res->name, "close"))
497                 close_port(RTE_PORT_ALL);
498         else
499                 printf("Unknown parameter\n");
500 }
501
502 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
503         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
504                                                                 "port");
505 cmdline_parse_token_string_t cmd_operate_port_all_port =
506         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
507                                                 "start#stop#close");
508 cmdline_parse_token_string_t cmd_operate_port_all_all =
509         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
510
511 cmdline_parse_inst_t cmd_operate_port = {
512         .f = cmd_operate_port_parsed,
513         .data = NULL,
514         .help_str = "port start|stop|close all: start/stop/close all ports",
515         .tokens = {
516                 (void *)&cmd_operate_port_all_cmd,
517                 (void *)&cmd_operate_port_all_port,
518                 (void *)&cmd_operate_port_all_all,
519                 NULL,
520         },
521 };
522
523 /* *** start/stop/close specific port *** */
524 struct cmd_operate_specific_port_result {
525         cmdline_fixed_string_t keyword;
526         cmdline_fixed_string_t name;
527         uint8_t value;
528 };
529
530 static void cmd_operate_specific_port_parsed(void *parsed_result,
531                         __attribute__((unused)) struct cmdline *cl,
532                                 __attribute__((unused)) void *data)
533 {
534         struct cmd_operate_specific_port_result *res = parsed_result;
535
536         if (!strcmp(res->name, "start"))
537                 start_port(res->value);
538         else if (!strcmp(res->name, "stop"))
539                 stop_port(res->value);
540         else if (!strcmp(res->name, "close"))
541                 close_port(res->value);
542         else
543                 printf("Unknown parameter\n");
544 }
545
546 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
547         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
548                                                         keyword, "port");
549 cmdline_parse_token_string_t cmd_operate_specific_port_port =
550         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
551                                                 name, "start#stop#close");
552 cmdline_parse_token_num_t cmd_operate_specific_port_id =
553         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
554                                                         value, UINT8);
555
556 cmdline_parse_inst_t cmd_operate_specific_port = {
557         .f = cmd_operate_specific_port_parsed,
558         .data = NULL,
559         .help_str = "port start|stop|close X: start/stop/close port X",
560         .tokens = {
561                 (void *)&cmd_operate_specific_port_cmd,
562                 (void *)&cmd_operate_specific_port_port,
563                 (void *)&cmd_operate_specific_port_id,
564                 NULL,
565         },
566 };
567
568 /* *** configure speed for all ports *** */
569 struct cmd_config_speed_all {
570         cmdline_fixed_string_t port;
571         cmdline_fixed_string_t keyword;
572         cmdline_fixed_string_t all;
573         cmdline_fixed_string_t item1;
574         cmdline_fixed_string_t item2;
575         cmdline_fixed_string_t value1;
576         cmdline_fixed_string_t value2;
577 };
578
579 static void
580 cmd_config_speed_all_parsed(void *parsed_result,
581                         __attribute__((unused)) struct cmdline *cl,
582                         __attribute__((unused)) void *data)
583 {
584         struct cmd_config_speed_all *res = parsed_result;
585         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
586         uint16_t link_duplex = 0;
587         portid_t pid;
588
589         if (!all_ports_stopped()) {
590                 printf("Please stop all ports first\n");
591                 return;
592         }
593
594         if (!strcmp(res->value1, "10"))
595                 link_speed = ETH_LINK_SPEED_10;
596         else if (!strcmp(res->value1, "100"))
597                 link_speed = ETH_LINK_SPEED_100;
598         else if (!strcmp(res->value1, "1000"))
599                 link_speed = ETH_LINK_SPEED_1000;
600         else if (!strcmp(res->value1, "10000"))
601                 link_speed = ETH_LINK_SPEED_10000;
602         else if (!strcmp(res->value1, "auto"))
603                 link_speed = ETH_LINK_SPEED_AUTONEG;
604         else {
605                 printf("Unknown parameter\n");
606                 return;
607         }
608
609         if (!strcmp(res->value2, "half"))
610                 link_duplex = ETH_LINK_HALF_DUPLEX;
611         else if (!strcmp(res->value2, "full"))
612                 link_duplex = ETH_LINK_FULL_DUPLEX;
613         else if (!strcmp(res->value2, "auto"))
614                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
615         else {
616                 printf("Unknown parameter\n");
617                 return;
618         }
619
620         for (pid = 0; pid < nb_ports; pid++) {
621                 ports[pid].dev_conf.link_speed = link_speed;
622                 ports[pid].dev_conf.link_duplex = link_duplex;
623         }
624
625         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
626 }
627
628 cmdline_parse_token_string_t cmd_config_speed_all_port =
629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
630 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
631         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
632                                                         "config");
633 cmdline_parse_token_string_t cmd_config_speed_all_all =
634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
635 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
636         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
637 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
638         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
639                                                 "10#100#1000#10000#auto");
640 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
641         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
642 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
644                                                 "half#full#auto");
645
646 cmdline_parse_inst_t cmd_config_speed_all = {
647         .f = cmd_config_speed_all_parsed,
648         .data = NULL,
649         .help_str = "port config all speed 10|100|1000|10000|auto duplex "
650                                                         "half|full|auto",
651         .tokens = {
652                 (void *)&cmd_config_speed_all_port,
653                 (void *)&cmd_config_speed_all_keyword,
654                 (void *)&cmd_config_speed_all_all,
655                 (void *)&cmd_config_speed_all_item1,
656                 (void *)&cmd_config_speed_all_value1,
657                 (void *)&cmd_config_speed_all_item2,
658                 (void *)&cmd_config_speed_all_value2,
659                 NULL,
660         },
661 };
662
663 /* *** configure speed for specific port *** */
664 struct cmd_config_speed_specific {
665         cmdline_fixed_string_t port;
666         cmdline_fixed_string_t keyword;
667         uint8_t id;
668         cmdline_fixed_string_t item1;
669         cmdline_fixed_string_t item2;
670         cmdline_fixed_string_t value1;
671         cmdline_fixed_string_t value2;
672 };
673
674 static void
675 cmd_config_speed_specific_parsed(void *parsed_result,
676                                 __attribute__((unused)) struct cmdline *cl,
677                                 __attribute__((unused)) void *data)
678 {
679         struct cmd_config_speed_specific *res = parsed_result;
680         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
681         uint16_t link_duplex = 0;
682
683         if (!all_ports_stopped()) {
684                 printf("Please stop all ports first\n");
685                 return;
686         }
687
688         if (res->id >= nb_ports) {
689                 printf("Port id %d must be less than %d\n", res->id, nb_ports);
690                 return;
691         }
692
693         if (!strcmp(res->value1, "10"))
694                 link_speed = ETH_LINK_SPEED_10;
695         else if (!strcmp(res->value1, "100"))
696                 link_speed = ETH_LINK_SPEED_100;
697         else if (!strcmp(res->value1, "1000"))
698                 link_speed = ETH_LINK_SPEED_1000;
699         else if (!strcmp(res->value1, "10000"))
700                 link_speed = ETH_LINK_SPEED_10000;
701         else if (!strcmp(res->value1, "auto"))
702                 link_speed = ETH_LINK_SPEED_AUTONEG;
703         else {
704                 printf("Unknown parameter\n");
705                 return;
706         }
707
708         if (!strcmp(res->value2, "half"))
709                 link_duplex = ETH_LINK_HALF_DUPLEX;
710         else if (!strcmp(res->value2, "full"))
711                 link_duplex = ETH_LINK_FULL_DUPLEX;
712         else if (!strcmp(res->value2, "auto"))
713                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
714         else {
715                 printf("Unknown parameter\n");
716                 return;
717         }
718
719         ports[res->id].dev_conf.link_speed = link_speed;
720         ports[res->id].dev_conf.link_duplex = link_duplex;
721
722         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
723 }
724
725
726 cmdline_parse_token_string_t cmd_config_speed_specific_port =
727         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
728                                                                 "port");
729 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
730         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
731                                                                 "config");
732 cmdline_parse_token_num_t cmd_config_speed_specific_id =
733         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
734 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
736                                                                 "speed");
737 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
739                                                 "10#100#1000#10000#auto");
740 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
742                                                                 "duplex");
743 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
744         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
745                                                         "half#full#auto");
746
747 cmdline_parse_inst_t cmd_config_speed_specific = {
748         .f = cmd_config_speed_specific_parsed,
749         .data = NULL,
750         .help_str = "port config X speed 10|100|1000|10000|auto duplex "
751                                                         "half|full|auto",
752         .tokens = {
753                 (void *)&cmd_config_speed_specific_port,
754                 (void *)&cmd_config_speed_specific_keyword,
755                 (void *)&cmd_config_speed_specific_id,
756                 (void *)&cmd_config_speed_specific_item1,
757                 (void *)&cmd_config_speed_specific_value1,
758                 (void *)&cmd_config_speed_specific_item2,
759                 (void *)&cmd_config_speed_specific_value2,
760                 NULL,
761         },
762 };
763
764 /* *** configure txq/rxq, txd/rxd *** */
765 struct cmd_config_rx_tx {
766         cmdline_fixed_string_t port;
767         cmdline_fixed_string_t keyword;
768         cmdline_fixed_string_t all;
769         cmdline_fixed_string_t name;
770         uint16_t value;
771 };
772
773 static void
774 cmd_config_rx_tx_parsed(void *parsed_result,
775                         __attribute__((unused)) struct cmdline *cl,
776                         __attribute__((unused)) void *data)
777 {
778         struct cmd_config_rx_tx *res = parsed_result;
779
780         if (!all_ports_stopped()) {
781                 printf("Please stop all ports first\n");
782                 return;
783         }
784
785         if (!strcmp(res->name, "rxq")) {
786                 if (res->value <= 0) {
787                         printf("rxq %d invalid - must be > 0\n", res->value);
788                         return;
789                 }
790                 nb_rxq = res->value;
791         }
792         else if (!strcmp(res->name, "txq")) {
793                 if (res->value <= 0) {
794                         printf("txq %d invalid - must be > 0\n", res->value);
795                         return;
796                 }
797                 nb_txq = res->value;
798         }
799         else if (!strcmp(res->name, "rxd")) {
800                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
801                         printf("rxd %d invalid - must be > 0 && <= %d\n",
802                                         res->value, RTE_TEST_RX_DESC_MAX);
803                         return;
804                 }
805                 nb_rxd = res->value;
806         } else if (!strcmp(res->name, "txd")) {
807                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
808                         printf("txd %d invalid - must be > 0 && <= %d\n",
809                                         res->value, RTE_TEST_TX_DESC_MAX);
810                         return;
811                 }
812                 nb_txd = res->value;
813         } else {
814                 printf("Unknown parameter\n");
815                 return;
816         }
817
818         init_port_config();
819
820         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
821 }
822
823 cmdline_parse_token_string_t cmd_config_rx_tx_port =
824         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
825 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
826         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
827 cmdline_parse_token_string_t cmd_config_rx_tx_all =
828         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
829 cmdline_parse_token_string_t cmd_config_rx_tx_name =
830         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
831                                                 "rxq#txq#rxd#txd");
832 cmdline_parse_token_num_t cmd_config_rx_tx_value =
833         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
834
835 cmdline_parse_inst_t cmd_config_rx_tx = {
836         .f = cmd_config_rx_tx_parsed,
837         .data = NULL,
838         .help_str = "port config all rxq|txq|rxd|txd value",
839         .tokens = {
840                 (void *)&cmd_config_rx_tx_port,
841                 (void *)&cmd_config_rx_tx_keyword,
842                 (void *)&cmd_config_rx_tx_all,
843                 (void *)&cmd_config_rx_tx_name,
844                 (void *)&cmd_config_rx_tx_value,
845                 NULL,
846         },
847 };
848
849 /* *** config max packet length *** */
850 struct cmd_config_max_pkt_len_result {
851         cmdline_fixed_string_t port;
852         cmdline_fixed_string_t keyword;
853         cmdline_fixed_string_t all;
854         cmdline_fixed_string_t name;
855         uint32_t value;
856 };
857
858 static void
859 cmd_config_max_pkt_len_parsed(void *parsed_result,
860                                 __attribute__((unused)) struct cmdline *cl,
861                                 __attribute__((unused)) void *data)
862 {
863         struct cmd_config_max_pkt_len_result *res = parsed_result;
864
865         if (!all_ports_stopped()) {
866                 printf("Please stop all ports first\n");
867                 return;
868         }
869
870         if (!strcmp(res->name, "max-pkt-len")) {
871                 if (res->value < ETHER_MIN_LEN) {
872                         printf("max-pkt-len can not be less than %d\n",
873                                                         ETHER_MIN_LEN);
874                         return;
875                 }
876                 if (res->value == rx_mode.max_rx_pkt_len)
877                         return;
878
879                 rx_mode.max_rx_pkt_len = res->value;
880                 if (res->value > ETHER_MAX_LEN)
881                         rx_mode.jumbo_frame = 1;
882                 else
883                         rx_mode.jumbo_frame = 0;
884         } else {
885                 printf("Unknown parameter\n");
886                 return;
887         }
888
889         init_port_config();
890
891         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
892 }
893
894 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
895         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
896                                                                 "port");
897 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
898         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
899                                                                 "config");
900 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
901         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
902                                                                 "all");
903 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
904         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
905                                                                 "max-pkt-len");
906 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
907         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
908                                                                 UINT32);
909
910 cmdline_parse_inst_t cmd_config_max_pkt_len = {
911         .f = cmd_config_max_pkt_len_parsed,
912         .data = NULL,
913         .help_str = "port config all max-pkt-len value",
914         .tokens = {
915                 (void *)&cmd_config_max_pkt_len_port,
916                 (void *)&cmd_config_max_pkt_len_keyword,
917                 (void *)&cmd_config_max_pkt_len_all,
918                 (void *)&cmd_config_max_pkt_len_name,
919                 (void *)&cmd_config_max_pkt_len_value,
920                 NULL,
921         },
922 };
923
924 /* *** configure rx mode *** */
925 struct cmd_config_rx_mode_flag {
926         cmdline_fixed_string_t port;
927         cmdline_fixed_string_t keyword;
928         cmdline_fixed_string_t all;
929         cmdline_fixed_string_t name;
930         cmdline_fixed_string_t value;
931 };
932
933 static void
934 cmd_config_rx_mode_flag_parsed(void *parsed_result,
935                                 __attribute__((unused)) struct cmdline *cl,
936                                 __attribute__((unused)) void *data)
937 {
938         struct cmd_config_rx_mode_flag *res = parsed_result;
939
940         if (!all_ports_stopped()) {
941                 printf("Please stop all ports first\n");
942                 return;
943         }
944
945         if (!strcmp(res->name, "crc-strip")) {
946                 if (!strcmp(res->value, "on"))
947                         rx_mode.hw_strip_crc = 1;
948                 else if (!strcmp(res->value, "off"))
949                         rx_mode.hw_strip_crc = 0;
950                 else {
951                         printf("Unknown parameter\n");
952                         return;
953                 }
954         } else if (!strcmp(res->name, "rx-cksum")) {
955                 if (!strcmp(res->value, "on"))
956                         rx_mode.hw_ip_checksum = 1;
957                 else if (!strcmp(res->value, "off"))
958                         rx_mode.hw_ip_checksum = 0;
959                 else {
960                         printf("Unknown parameter\n");
961                         return;
962                 }
963         } else if (!strcmp(res->name, "hw-vlan")) {
964                 if (!strcmp(res->value, "on")) {
965                         rx_mode.hw_vlan_filter = 1;
966                         rx_mode.hw_vlan_strip  = 1;
967                 }
968                 else if (!strcmp(res->value, "off")) {
969                         rx_mode.hw_vlan_filter = 0;
970                         rx_mode.hw_vlan_strip  = 0;
971                 }
972                 else {
973                         printf("Unknown parameter\n");
974                         return;
975                 }
976         } else if (!strcmp(res->name, "drop-en")) {
977                 if (!strcmp(res->value, "on"))
978                         rx_drop_en = 1;
979                 else if (!strcmp(res->value, "off"))
980                         rx_drop_en = 0;
981                 else {
982                         printf("Unknown parameter\n");
983                         return;
984                 }
985         } else {
986                 printf("Unknown parameter\n");
987                 return;
988         }
989
990         init_port_config();
991
992         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
993 }
994
995 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
996         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
997 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
998         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
999                                                                 "config");
1000 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1001         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1002 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1003         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1004                                         "crc-strip#rx-cksum#hw-vlan");
1005 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1006         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1007                                                         "on#off");
1008
1009 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1010         .f = cmd_config_rx_mode_flag_parsed,
1011         .data = NULL,
1012         .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off",
1013         .tokens = {
1014                 (void *)&cmd_config_rx_mode_flag_port,
1015                 (void *)&cmd_config_rx_mode_flag_keyword,
1016                 (void *)&cmd_config_rx_mode_flag_all,
1017                 (void *)&cmd_config_rx_mode_flag_name,
1018                 (void *)&cmd_config_rx_mode_flag_value,
1019                 NULL,
1020         },
1021 };
1022
1023 /* *** configure rss *** */
1024 struct cmd_config_rss {
1025         cmdline_fixed_string_t port;
1026         cmdline_fixed_string_t keyword;
1027         cmdline_fixed_string_t all;
1028         cmdline_fixed_string_t name;
1029         cmdline_fixed_string_t value;
1030 };
1031
1032 static void
1033 cmd_config_rss_parsed(void *parsed_result,
1034                         __attribute__((unused)) struct cmdline *cl,
1035                         __attribute__((unused)) void *data)
1036 {
1037         struct cmd_config_rss *res = parsed_result;
1038
1039         if (!all_ports_stopped()) {
1040                 printf("Please stop all ports first\n");
1041                 return;
1042         }
1043
1044         if (!strcmp(res->value, "ip"))
1045                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
1046         else if (!strcmp(res->value, "udp"))
1047                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP;
1048         else if (!strcmp(res->value, "none"))
1049                 rss_hf = 0;
1050         else {
1051                 printf("Unknown parameter\n");
1052                 return;
1053         }
1054
1055         init_port_config();
1056
1057         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1058 }
1059
1060 cmdline_parse_token_string_t cmd_config_rss_port =
1061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1062 cmdline_parse_token_string_t cmd_config_rss_keyword =
1063         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1064 cmdline_parse_token_string_t cmd_config_rss_all =
1065         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1066 cmdline_parse_token_string_t cmd_config_rss_name =
1067         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1068 cmdline_parse_token_string_t cmd_config_rss_value =
1069         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none");
1070
1071 cmdline_parse_inst_t cmd_config_rss = {
1072         .f = cmd_config_rss_parsed,
1073         .data = NULL,
1074         .help_str = "port config all rss ip|udp|none",
1075         .tokens = {
1076                 (void *)&cmd_config_rss_port,
1077                 (void *)&cmd_config_rss_keyword,
1078                 (void *)&cmd_config_rss_all,
1079                 (void *)&cmd_config_rss_name,
1080                 (void *)&cmd_config_rss_value,
1081                 NULL,
1082         },
1083 };
1084
1085 /* *** Configure RSS RETA *** */
1086 struct cmd_config_rss_reta {
1087         cmdline_fixed_string_t port;
1088         cmdline_fixed_string_t keyword;
1089         uint8_t port_id;
1090         cmdline_fixed_string_t name;
1091         cmdline_fixed_string_t list_name;
1092         cmdline_fixed_string_t list_of_items;
1093 };
1094
1095 static int
1096 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
1097 {
1098         int i;
1099         unsigned size;
1100         uint8_t hash_index;
1101         uint8_t nb_queue;
1102         char s[256];
1103         const char *p, *p0 = str;
1104         char *end;
1105         enum fieldnames {
1106                 FLD_HASH_INDEX = 0,
1107                 FLD_QUEUE,
1108                 _NUM_FLD
1109         };
1110         unsigned long int_fld[_NUM_FLD];
1111         char *str_fld[_NUM_FLD];
1112
1113         while ((p = strchr(p0,'(')) != NULL) {
1114                 ++p;
1115                 if((p0 = strchr(p,')')) == NULL)
1116                         return -1;
1117
1118                 size = p0 - p;
1119                 if(size >= sizeof(s))
1120                         return -1;
1121
1122                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
1123                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1124                         return -1;
1125                 for (i = 0; i < _NUM_FLD; i++) {
1126                         errno = 0;
1127                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1128                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1129                                 return -1;
1130                 }
1131
1132                 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX];
1133                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1134
1135                 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) {
1136                         printf("Invalid RETA hash index=%d",hash_index);
1137                         return -1;
1138                 }
1139
1140                 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2)
1141                         reta_conf->mask_lo |= (1ULL << hash_index);
1142                 else
1143                         reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2));
1144
1145                 reta_conf->reta[hash_index] = nb_queue;
1146         }
1147
1148         return 0;
1149 }
1150
1151 static void
1152 cmd_set_rss_reta_parsed(void *parsed_result,
1153                                 __attribute__((unused)) struct cmdline *cl,
1154                                 __attribute__((unused)) void *data)
1155 {
1156         int ret;
1157         struct rte_eth_rss_reta reta_conf;
1158         struct cmd_config_rss_reta *res = parsed_result;
1159
1160         memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta));
1161         if (!strcmp(res->list_name, "reta")) {
1162                 if (parse_reta_config(res->list_of_items, &reta_conf)) {
1163                         printf("Invalid RSS Redirection Table config entered\n");
1164                         return;
1165                 }
1166                 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf);
1167                 if (ret != 0)
1168                         printf("Bad redirection table parameter, return code = %d \n",ret);
1169         }
1170 }
1171
1172 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1173         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1174 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1175         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1176 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1177         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1178 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1179         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1180 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1181         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1182 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1183         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1184                                  NULL);
1185 cmdline_parse_inst_t cmd_config_rss_reta = {
1186         .f = cmd_set_rss_reta_parsed,
1187         .data = NULL,
1188         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1189         .tokens = {
1190                 (void *)&cmd_config_rss_reta_port,
1191                 (void *)&cmd_config_rss_reta_keyword,
1192                 (void *)&cmd_config_rss_reta_port_id,
1193                 (void *)&cmd_config_rss_reta_name,
1194                 (void *)&cmd_config_rss_reta_list_name,
1195                 (void *)&cmd_config_rss_reta_list_of_items,
1196                 NULL,
1197         },
1198 };
1199
1200 /* *** SHOW PORT INFO *** */
1201 struct cmd_showport_reta {
1202         cmdline_fixed_string_t show;
1203         cmdline_fixed_string_t port;
1204         uint8_t port_id;
1205         cmdline_fixed_string_t rss;
1206         cmdline_fixed_string_t reta;
1207         uint64_t mask_lo;
1208         uint64_t mask_hi;
1209 };
1210
1211 static void cmd_showport_reta_parsed(void *parsed_result,
1212                                 __attribute__((unused)) struct cmdline *cl,
1213                                 __attribute__((unused)) void *data)
1214 {
1215         struct cmd_showport_reta *res = parsed_result;
1216         struct rte_eth_rss_reta reta_conf;
1217
1218         if ((res->mask_lo == 0) && (res->mask_hi == 0)) {
1219                 printf("Invalid RSS Redirection Table config entered\n");
1220                 return;
1221         }
1222
1223         reta_conf.mask_lo = res->mask_lo;
1224         reta_conf.mask_hi = res->mask_hi;
1225
1226         port_rss_reta_info(res->port_id,&reta_conf);
1227 }
1228
1229 cmdline_parse_token_string_t cmd_showport_reta_show =
1230         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1231 cmdline_parse_token_string_t cmd_showport_reta_port =
1232         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1233 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1234         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1235 cmdline_parse_token_string_t cmd_showport_reta_rss =
1236         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1237 cmdline_parse_token_string_t cmd_showport_reta_reta =
1238         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1239 cmdline_parse_token_num_t cmd_showport_reta_mask_lo =
1240         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64);
1241 cmdline_parse_token_num_t cmd_showport_reta_mask_hi =
1242         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64);
1243
1244 cmdline_parse_inst_t cmd_showport_reta = {
1245         .f = cmd_showport_reta_parsed,
1246         .data = NULL,
1247         .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\
1248                         (mask_lo and mask_hi is UINT64)",
1249         .tokens = {
1250                 (void *)&cmd_showport_reta_show,
1251                 (void *)&cmd_showport_reta_port,
1252                 (void *)&cmd_showport_reta_port_id,
1253                 (void *)&cmd_showport_reta_rss,
1254                 (void *)&cmd_showport_reta_reta,
1255                 (void *)&cmd_showport_reta_mask_lo,
1256                 (void *)&cmd_showport_reta_mask_hi,
1257                 NULL,
1258         },
1259 };
1260
1261 /* *** Configure DCB *** */
1262 struct cmd_config_dcb {
1263         cmdline_fixed_string_t port;
1264         cmdline_fixed_string_t config;
1265         uint8_t port_id;
1266         cmdline_fixed_string_t dcb;
1267         cmdline_fixed_string_t vt;
1268         cmdline_fixed_string_t vt_en;
1269         uint8_t num_tcs;
1270         cmdline_fixed_string_t pfc;
1271         cmdline_fixed_string_t pfc_en;
1272 };
1273
1274 static void
1275 cmd_config_dcb_parsed(void *parsed_result,
1276                         __attribute__((unused)) struct cmdline *cl,
1277                         __attribute__((unused)) void *data)
1278 {
1279         struct cmd_config_dcb *res = parsed_result;
1280         struct dcb_config dcb_conf;
1281         portid_t port_id = res->port_id;
1282         struct rte_port *port;
1283
1284         port = &ports[port_id];
1285         /** Check if the port is not started **/
1286         if (port->port_status != RTE_PORT_STOPPED) {
1287                 printf("Please stop port %d first\n",port_id);
1288                 return;
1289         }
1290
1291         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
1292         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
1293                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
1294                 return;
1295         }
1296
1297         /* DCB in VT mode */
1298         if (!strncmp(res->vt_en, "on",2))
1299                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
1300         else
1301                 dcb_conf.dcb_mode = DCB_ENABLED;
1302
1303         if (!strncmp(res->pfc_en, "on",2)) {
1304                 dcb_conf.pfc_en = 1;
1305         }
1306         else
1307                 dcb_conf.pfc_en = 0;
1308
1309         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
1310                 printf("Cannot initialize network ports\n");
1311                 return;
1312         }
1313
1314         cmd_reconfig_device_queue(port_id, 1, 1);
1315 }
1316
1317 cmdline_parse_token_string_t cmd_config_dcb_port =
1318         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
1319 cmdline_parse_token_string_t cmd_config_dcb_config =
1320         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
1321 cmdline_parse_token_num_t cmd_config_dcb_port_id =
1322         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
1323 cmdline_parse_token_string_t cmd_config_dcb_dcb =
1324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
1325 cmdline_parse_token_string_t cmd_config_dcb_vt =
1326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
1327 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
1328         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
1329 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
1330         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
1331 cmdline_parse_token_string_t cmd_config_dcb_pfc=
1332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
1333 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
1334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
1335
1336 cmdline_parse_inst_t cmd_config_dcb = {
1337         .f = cmd_config_dcb_parsed,
1338         .data = NULL,
1339         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
1340         .tokens = {
1341                 (void *)&cmd_config_dcb_port,
1342                 (void *)&cmd_config_dcb_config,
1343                 (void *)&cmd_config_dcb_port_id,
1344                 (void *)&cmd_config_dcb_dcb,
1345                 (void *)&cmd_config_dcb_vt,
1346                 (void *)&cmd_config_dcb_vt_en,
1347                 (void *)&cmd_config_dcb_num_tcs,
1348                 (void *)&cmd_config_dcb_pfc,
1349                 (void *)&cmd_config_dcb_pfc_en,
1350                 NULL,
1351         },
1352 };
1353
1354 /* *** configure number of packets per burst *** */
1355 struct cmd_config_burst {
1356         cmdline_fixed_string_t port;
1357         cmdline_fixed_string_t keyword;
1358         cmdline_fixed_string_t all;
1359         cmdline_fixed_string_t name;
1360         uint16_t value;
1361 };
1362
1363 static void
1364 cmd_config_burst_parsed(void *parsed_result,
1365                         __attribute__((unused)) struct cmdline *cl,
1366                         __attribute__((unused)) void *data)
1367 {
1368         struct cmd_config_burst *res = parsed_result;
1369
1370         if (!all_ports_stopped()) {
1371                 printf("Please stop all ports first\n");
1372                 return;
1373         }
1374
1375         if (!strcmp(res->name, "burst")) {
1376                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
1377                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
1378                         return;
1379                 }
1380                 nb_pkt_per_burst = res->value;
1381         } else {
1382                 printf("Unknown parameter\n");
1383                 return;
1384         }
1385
1386         init_port_config();
1387
1388         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1389 }
1390
1391 cmdline_parse_token_string_t cmd_config_burst_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
1393 cmdline_parse_token_string_t cmd_config_burst_keyword =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
1395 cmdline_parse_token_string_t cmd_config_burst_all =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
1397 cmdline_parse_token_string_t cmd_config_burst_name =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
1399 cmdline_parse_token_num_t cmd_config_burst_value =
1400         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
1401
1402 cmdline_parse_inst_t cmd_config_burst = {
1403         .f = cmd_config_burst_parsed,
1404         .data = NULL,
1405         .help_str = "port config all burst value",
1406         .tokens = {
1407                 (void *)&cmd_config_burst_port,
1408                 (void *)&cmd_config_burst_keyword,
1409                 (void *)&cmd_config_burst_all,
1410                 (void *)&cmd_config_burst_name,
1411                 (void *)&cmd_config_burst_value,
1412                 NULL,
1413         },
1414 };
1415
1416 /* *** configure rx/tx queues *** */
1417 struct cmd_config_thresh {
1418         cmdline_fixed_string_t port;
1419         cmdline_fixed_string_t keyword;
1420         cmdline_fixed_string_t all;
1421         cmdline_fixed_string_t name;
1422         uint8_t value;
1423 };
1424
1425 static void
1426 cmd_config_thresh_parsed(void *parsed_result,
1427                         __attribute__((unused)) struct cmdline *cl,
1428                         __attribute__((unused)) void *data)
1429 {
1430         struct cmd_config_thresh *res = parsed_result;
1431
1432         if (!all_ports_stopped()) {
1433                 printf("Please stop all ports first\n");
1434                 return;
1435         }
1436
1437         if (!strcmp(res->name, "txpt"))
1438                 tx_thresh.pthresh = res->value;
1439         else if(!strcmp(res->name, "txht"))
1440                 tx_thresh.hthresh = res->value;
1441         else if(!strcmp(res->name, "txwt"))
1442                 tx_thresh.wthresh = res->value;
1443         else if(!strcmp(res->name, "rxpt"))
1444                 rx_thresh.pthresh = res->value;
1445         else if(!strcmp(res->name, "rxht"))
1446                 rx_thresh.hthresh = res->value;
1447         else if(!strcmp(res->name, "rxwt"))
1448                 rx_thresh.wthresh = res->value;
1449         else {
1450                 printf("Unknown parameter\n");
1451                 return;
1452         }
1453
1454         init_port_config();
1455
1456         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1457 }
1458
1459 cmdline_parse_token_string_t cmd_config_thresh_port =
1460         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
1461 cmdline_parse_token_string_t cmd_config_thresh_keyword =
1462         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
1463 cmdline_parse_token_string_t cmd_config_thresh_all =
1464         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
1465 cmdline_parse_token_string_t cmd_config_thresh_name =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
1467                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
1468 cmdline_parse_token_num_t cmd_config_thresh_value =
1469         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
1470
1471 cmdline_parse_inst_t cmd_config_thresh = {
1472         .f = cmd_config_thresh_parsed,
1473         .data = NULL,
1474         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1475         .tokens = {
1476                 (void *)&cmd_config_thresh_port,
1477                 (void *)&cmd_config_thresh_keyword,
1478                 (void *)&cmd_config_thresh_all,
1479                 (void *)&cmd_config_thresh_name,
1480                 (void *)&cmd_config_thresh_value,
1481                 NULL,
1482         },
1483 };
1484
1485 /* *** configure free/rs threshold *** */
1486 struct cmd_config_threshold {
1487         cmdline_fixed_string_t port;
1488         cmdline_fixed_string_t keyword;
1489         cmdline_fixed_string_t all;
1490         cmdline_fixed_string_t name;
1491         uint16_t value;
1492 };
1493
1494 static void
1495 cmd_config_threshold_parsed(void *parsed_result,
1496                         __attribute__((unused)) struct cmdline *cl,
1497                         __attribute__((unused)) void *data)
1498 {
1499         struct cmd_config_threshold *res = parsed_result;
1500
1501         if (!all_ports_stopped()) {
1502                 printf("Please stop all ports first\n");
1503                 return;
1504         }
1505
1506         if (!strcmp(res->name, "txfreet"))
1507                 tx_free_thresh = res->value;
1508         else if (!strcmp(res->name, "txrst"))
1509                 tx_rs_thresh = res->value;
1510         else if (!strcmp(res->name, "rxfreet"))
1511                 rx_free_thresh = res->value;
1512         else {
1513                 printf("Unknown parameter\n");
1514                 return;
1515         }
1516
1517         init_port_config();
1518
1519         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1520 }
1521
1522 cmdline_parse_token_string_t cmd_config_threshold_port =
1523         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1524 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1525         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1526                                                                 "config");
1527 cmdline_parse_token_string_t cmd_config_threshold_all =
1528         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1529 cmdline_parse_token_string_t cmd_config_threshold_name =
1530         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1531                                                 "txfreet#txrst#rxfreet");
1532 cmdline_parse_token_num_t cmd_config_threshold_value =
1533         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1534
1535 cmdline_parse_inst_t cmd_config_threshold = {
1536         .f = cmd_config_threshold_parsed,
1537         .data = NULL,
1538         .help_str = "port config all txfreet|txrst|rxfreet value",
1539         .tokens = {
1540                 (void *)&cmd_config_threshold_port,
1541                 (void *)&cmd_config_threshold_keyword,
1542                 (void *)&cmd_config_threshold_all,
1543                 (void *)&cmd_config_threshold_name,
1544                 (void *)&cmd_config_threshold_value,
1545                 NULL,
1546         },
1547 };
1548
1549 /* *** stop *** */
1550 struct cmd_stop_result {
1551         cmdline_fixed_string_t stop;
1552 };
1553
1554 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1555                             __attribute__((unused)) struct cmdline *cl,
1556                             __attribute__((unused)) void *data)
1557 {
1558         stop_packet_forwarding();
1559 }
1560
1561 cmdline_parse_token_string_t cmd_stop_stop =
1562         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1563
1564 cmdline_parse_inst_t cmd_stop = {
1565         .f = cmd_stop_parsed,
1566         .data = NULL,
1567         .help_str = "stop - stop packet forwarding",
1568         .tokens = {
1569                 (void *)&cmd_stop_stop,
1570                 NULL,
1571         },
1572 };
1573
1574 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1575
1576 static unsigned int
1577 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1578                 unsigned int *parsed_items, int check_unique_values)
1579 {
1580         unsigned int nb_item;
1581         unsigned int value;
1582         unsigned int i;
1583         unsigned int j;
1584         int value_ok;
1585         char c;
1586
1587         /*
1588          * First parse all items in the list and store their value.
1589          */
1590         value = 0;
1591         nb_item = 0;
1592         value_ok = 0;
1593         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1594                 c = str[i];
1595                 if ((c >= '0') && (c <= '9')) {
1596                         value = (unsigned int) (value * 10 + (c - '0'));
1597                         value_ok = 1;
1598                         continue;
1599                 }
1600                 if (c != ',') {
1601                         printf("character %c is not a decimal digit\n", c);
1602                         return (0);
1603                 }
1604                 if (! value_ok) {
1605                         printf("No valid value before comma\n");
1606                         return (0);
1607                 }
1608                 if (nb_item < max_items) {
1609                         parsed_items[nb_item] = value;
1610                         value_ok = 0;
1611                         value = 0;
1612                 }
1613                 nb_item++;
1614         }
1615         if (nb_item >= max_items) {
1616                 printf("Number of %s = %u > %u (maximum items)\n",
1617                        item_name, nb_item + 1, max_items);
1618                 return (0);
1619         }
1620         parsed_items[nb_item++] = value;
1621         if (! check_unique_values)
1622                 return (nb_item);
1623
1624         /*
1625          * Then, check that all values in the list are differents.
1626          * No optimization here...
1627          */
1628         for (i = 0; i < nb_item; i++) {
1629                 for (j = i + 1; j < nb_item; j++) {
1630                         if (parsed_items[j] == parsed_items[i]) {
1631                                 printf("duplicated %s %u at index %u and %u\n",
1632                                        item_name, parsed_items[i], i, j);
1633                                 return (0);
1634                         }
1635                 }
1636         }
1637         return (nb_item);
1638 }
1639
1640 struct cmd_set_list_result {
1641         cmdline_fixed_string_t cmd_keyword;
1642         cmdline_fixed_string_t list_name;
1643         cmdline_fixed_string_t list_of_items;
1644 };
1645
1646 static void cmd_set_list_parsed(void *parsed_result,
1647                                 __attribute__((unused)) struct cmdline *cl,
1648                                 __attribute__((unused)) void *data)
1649 {
1650         struct cmd_set_list_result *res;
1651         union {
1652                 unsigned int lcorelist[RTE_MAX_LCORE];
1653                 unsigned int portlist[RTE_MAX_ETHPORTS];
1654         } parsed_items;
1655         unsigned int nb_item;
1656
1657         res = parsed_result;
1658         if (!strcmp(res->list_name, "corelist")) {
1659                 nb_item = parse_item_list(res->list_of_items, "core",
1660                                           RTE_MAX_LCORE,
1661                                           parsed_items.lcorelist, 1);
1662                 if (nb_item > 0)
1663                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
1664                 return;
1665         }
1666         if (!strcmp(res->list_name, "portlist")) {
1667                 nb_item = parse_item_list(res->list_of_items, "port",
1668                                           RTE_MAX_ETHPORTS,
1669                                           parsed_items.portlist, 1);
1670                 if (nb_item > 0)
1671                         set_fwd_ports_list(parsed_items.portlist, nb_item);
1672         }
1673 }
1674
1675 cmdline_parse_token_string_t cmd_set_list_keyword =
1676         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
1677                                  "set");
1678 cmdline_parse_token_string_t cmd_set_list_name =
1679         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
1680                                  "corelist#portlist");
1681 cmdline_parse_token_string_t cmd_set_list_of_items =
1682         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
1683                                  NULL);
1684
1685 cmdline_parse_inst_t cmd_set_fwd_list = {
1686         .f = cmd_set_list_parsed,
1687         .data = NULL,
1688         .help_str = "set corelist|portlist x[,y]*",
1689         .tokens = {
1690                 (void *)&cmd_set_list_keyword,
1691                 (void *)&cmd_set_list_name,
1692                 (void *)&cmd_set_list_of_items,
1693                 NULL,
1694         },
1695 };
1696
1697 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
1698
1699 struct cmd_setmask_result {
1700         cmdline_fixed_string_t set;
1701         cmdline_fixed_string_t mask;
1702         uint64_t hexavalue;
1703 };
1704
1705 static void cmd_set_mask_parsed(void *parsed_result,
1706                                 __attribute__((unused)) struct cmdline *cl,
1707                                 __attribute__((unused)) void *data)
1708 {
1709         struct cmd_setmask_result *res = parsed_result;
1710
1711         if (!strcmp(res->mask, "coremask"))
1712                 set_fwd_lcores_mask(res->hexavalue);
1713         else if (!strcmp(res->mask, "portmask"))
1714                 set_fwd_ports_mask(res->hexavalue);
1715 }
1716
1717 cmdline_parse_token_string_t cmd_setmask_set =
1718         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
1719 cmdline_parse_token_string_t cmd_setmask_mask =
1720         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
1721                                  "coremask#portmask");
1722 cmdline_parse_token_num_t cmd_setmask_value =
1723         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
1724
1725 cmdline_parse_inst_t cmd_set_fwd_mask = {
1726         .f = cmd_set_mask_parsed,
1727         .data = NULL,
1728         .help_str = "set coremask|portmask hexadecimal value",
1729         .tokens = {
1730                 (void *)&cmd_setmask_set,
1731                 (void *)&cmd_setmask_mask,
1732                 (void *)&cmd_setmask_value,
1733                 NULL,
1734         },
1735 };
1736
1737 /*
1738  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
1739  */
1740 struct cmd_set_result {
1741         cmdline_fixed_string_t set;
1742         cmdline_fixed_string_t what;
1743         uint16_t value;
1744 };
1745
1746 static void cmd_set_parsed(void *parsed_result,
1747                            __attribute__((unused)) struct cmdline *cl,
1748                            __attribute__((unused)) void *data)
1749 {
1750         struct cmd_set_result *res = parsed_result;
1751         if (!strcmp(res->what, "nbport"))
1752                 set_fwd_ports_number(res->value);
1753         else if (!strcmp(res->what, "nbcore"))
1754                 set_fwd_lcores_number(res->value);
1755         else if (!strcmp(res->what, "burst"))
1756                 set_nb_pkt_per_burst(res->value);
1757         else if (!strcmp(res->what, "verbose"))
1758                 set_verbose_level(res->value);
1759 }
1760
1761 cmdline_parse_token_string_t cmd_set_set =
1762         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
1763 cmdline_parse_token_string_t cmd_set_what =
1764         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
1765                                  "nbport#nbcore#burst#verbose");
1766 cmdline_parse_token_num_t cmd_set_value =
1767         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
1768
1769 cmdline_parse_inst_t cmd_set_numbers = {
1770         .f = cmd_set_parsed,
1771         .data = NULL,
1772         .help_str = "set nbport|nbcore|burst|verbose value",
1773         .tokens = {
1774                 (void *)&cmd_set_set,
1775                 (void *)&cmd_set_what,
1776                 (void *)&cmd_set_value,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
1782
1783 struct cmd_set_txpkts_result {
1784         cmdline_fixed_string_t cmd_keyword;
1785         cmdline_fixed_string_t txpkts;
1786         cmdline_fixed_string_t seg_lengths;
1787 };
1788
1789 static void
1790 cmd_set_txpkts_parsed(void *parsed_result,
1791                       __attribute__((unused)) struct cmdline *cl,
1792                       __attribute__((unused)) void *data)
1793 {
1794         struct cmd_set_txpkts_result *res;
1795         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1796         unsigned int nb_segs;
1797
1798         res = parsed_result;
1799         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
1800                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1801         if (nb_segs > 0)
1802                 set_tx_pkt_segments(seg_lengths, nb_segs);
1803 }
1804
1805 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
1806         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1807                                  cmd_keyword, "set");
1808 cmdline_parse_token_string_t cmd_set_txpkts_name =
1809         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1810                                  txpkts, "txpkts");
1811 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
1812         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1813                                  seg_lengths, NULL);
1814
1815 cmdline_parse_inst_t cmd_set_txpkts = {
1816         .f = cmd_set_txpkts_parsed,
1817         .data = NULL,
1818         .help_str = "set txpkts x[,y]*",
1819         .tokens = {
1820                 (void *)&cmd_set_txpkts_keyword,
1821                 (void *)&cmd_set_txpkts_name,
1822                 (void *)&cmd_set_txpkts_lengths,
1823                 NULL,
1824         },
1825 };
1826
1827 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
1828 struct cmd_rx_vlan_filter_all_result {
1829         cmdline_fixed_string_t rx_vlan;
1830         cmdline_fixed_string_t what;
1831         cmdline_fixed_string_t all;
1832         uint8_t port_id;
1833 };
1834
1835 static void
1836 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
1837                               __attribute__((unused)) struct cmdline *cl,
1838                               __attribute__((unused)) void *data)
1839 {
1840         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
1841
1842         if (!strcmp(res->what, "add"))
1843                 rx_vlan_all_filter_set(res->port_id, 1);
1844         else
1845                 rx_vlan_all_filter_set(res->port_id, 0);
1846 }
1847
1848 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
1849         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1850                                  rx_vlan, "rx_vlan");
1851 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
1852         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1853                                  what, "add#rm");
1854 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
1855         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1856                                  all, "all");
1857 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
1858         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1859                               port_id, UINT8);
1860
1861 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
1862         .f = cmd_rx_vlan_filter_all_parsed,
1863         .data = NULL,
1864         .help_str = "add/remove all identifiers to/from the set of VLAN "
1865         "Identifiers filtered by a port",
1866         .tokens = {
1867                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
1868                 (void *)&cmd_rx_vlan_filter_all_what,
1869                 (void *)&cmd_rx_vlan_filter_all_all,
1870                 (void *)&cmd_rx_vlan_filter_all_portid,
1871                 NULL,
1872         },
1873 };
1874
1875 /* *** VLAN OFFLOAD SET ON A PORT *** */
1876 struct cmd_vlan_offload_result {
1877         cmdline_fixed_string_t vlan;
1878         cmdline_fixed_string_t set;
1879         cmdline_fixed_string_t what;
1880         cmdline_fixed_string_t on;
1881         cmdline_fixed_string_t port_id;
1882 };
1883
1884 static void
1885 cmd_vlan_offload_parsed(void *parsed_result,
1886                           __attribute__((unused)) struct cmdline *cl,
1887                           __attribute__((unused)) void *data)
1888 {
1889         int on;
1890         struct cmd_vlan_offload_result *res = parsed_result;
1891         char *str;
1892         int i, len = 0;
1893         portid_t port_id = 0;
1894         unsigned int tmp;
1895
1896         str = res->port_id;
1897         len = strnlen(str, STR_TOKEN_SIZE);
1898         i = 0;
1899         /* Get port_id first */
1900         while(i < len){
1901                 if(str[i] == ',')
1902                         break;
1903
1904                 i++;
1905         }
1906         str[i]='\0';
1907         tmp = strtoul(str, NULL, 0);
1908         /* If port_id greater that what portid_t can represent, return */
1909         if(tmp >= RTE_MAX_ETHPORTS)
1910                 return;
1911         port_id = (portid_t)tmp;
1912
1913         if (!strcmp(res->on, "on"))
1914                 on = 1;
1915         else
1916                 on = 0;
1917
1918         if (!strcmp(res->what, "strip"))
1919                 rx_vlan_strip_set(port_id,  on);
1920         else if(!strcmp(res->what, "stripq")){
1921                 uint16_t queue_id = 0;
1922
1923                 /* No queue_id, return */
1924                 if(i + 1 >= len)
1925                         return;
1926                 tmp = strtoul(str + i + 1, NULL, 0);
1927                 /* If queue_id greater that what 16-bits can represent, return */
1928                 if(tmp > 0xffff)
1929                         return;
1930
1931                 queue_id = (uint16_t)tmp;
1932                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
1933         }
1934         else if (!strcmp(res->what, "filter"))
1935                 rx_vlan_filter_set(port_id, on);
1936         else
1937                 vlan_extend_set(port_id, on);
1938
1939         return;
1940 }
1941
1942 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
1943         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1944                                  vlan, "vlan");
1945 cmdline_parse_token_string_t cmd_vlan_offload_set =
1946         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1947                                  set, "set");
1948 cmdline_parse_token_string_t cmd_vlan_offload_what =
1949         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1950                                  what, "strip#filter#qinq#stripq");
1951 cmdline_parse_token_string_t cmd_vlan_offload_on =
1952         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1953                               on, "on#off");
1954 cmdline_parse_token_string_t cmd_vlan_offload_portid =
1955         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
1956                               port_id, NULL);
1957
1958 cmdline_parse_inst_t cmd_vlan_offload = {
1959         .f = cmd_vlan_offload_parsed,
1960         .data = NULL,
1961         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
1962         " qinq(extended) for both rx/tx sides ",
1963         .tokens = {
1964                 (void *)&cmd_vlan_offload_vlan,
1965                 (void *)&cmd_vlan_offload_set,
1966                 (void *)&cmd_vlan_offload_what,
1967                 (void *)&cmd_vlan_offload_on,
1968                 (void *)&cmd_vlan_offload_portid,
1969                 NULL,
1970         },
1971 };
1972
1973 /* *** VLAN TPID SET ON A PORT *** */
1974 struct cmd_vlan_tpid_result {
1975         cmdline_fixed_string_t vlan;
1976         cmdline_fixed_string_t set;
1977         cmdline_fixed_string_t what;
1978         uint16_t tp_id;
1979         uint8_t port_id;
1980 };
1981
1982 static void
1983 cmd_vlan_tpid_parsed(void *parsed_result,
1984                           __attribute__((unused)) struct cmdline *cl,
1985                           __attribute__((unused)) void *data)
1986 {
1987         struct cmd_vlan_tpid_result *res = parsed_result;
1988         vlan_tpid_set(res->port_id, res->tp_id);
1989         return;
1990 }
1991
1992 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
1993         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
1994                                  vlan, "vlan");
1995 cmdline_parse_token_string_t cmd_vlan_tpid_set =
1996         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
1997                                  set, "set");
1998 cmdline_parse_token_string_t cmd_vlan_tpid_what =
1999         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2000                                  what, "tpid");
2001 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2002         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2003                               tp_id, UINT16);
2004 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2005         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2006                               port_id, UINT8);
2007
2008 cmdline_parse_inst_t cmd_vlan_tpid = {
2009         .f = cmd_vlan_tpid_parsed,
2010         .data = NULL,
2011         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2012         .tokens = {
2013                 (void *)&cmd_vlan_tpid_vlan,
2014                 (void *)&cmd_vlan_tpid_set,
2015                 (void *)&cmd_vlan_tpid_what,
2016                 (void *)&cmd_vlan_tpid_tpid,
2017                 (void *)&cmd_vlan_tpid_portid,
2018                 NULL,
2019         },
2020 };
2021
2022 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2023 struct cmd_rx_vlan_filter_result {
2024         cmdline_fixed_string_t rx_vlan;
2025         cmdline_fixed_string_t what;
2026         uint16_t vlan_id;
2027         uint8_t port_id;
2028 };
2029
2030 static void
2031 cmd_rx_vlan_filter_parsed(void *parsed_result,
2032                           __attribute__((unused)) struct cmdline *cl,
2033                           __attribute__((unused)) void *data)
2034 {
2035         struct cmd_rx_vlan_filter_result *res = parsed_result;
2036
2037         if (!strcmp(res->what, "add"))
2038                 rx_vft_set(res->port_id, res->vlan_id, 1);
2039         else
2040                 rx_vft_set(res->port_id, res->vlan_id, 0);
2041 }
2042
2043 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2044         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2045                                  rx_vlan, "rx_vlan");
2046 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2047         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2048                                  what, "add#rm");
2049 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2050         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2051                               vlan_id, UINT16);
2052 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2053         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2054                               port_id, UINT8);
2055
2056 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2057         .f = cmd_rx_vlan_filter_parsed,
2058         .data = NULL,
2059         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2060         "Identifiers filtered by a port",
2061         .tokens = {
2062                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2063                 (void *)&cmd_rx_vlan_filter_what,
2064                 (void *)&cmd_rx_vlan_filter_vlanid,
2065                 (void *)&cmd_rx_vlan_filter_portid,
2066                 NULL,
2067         },
2068 };
2069
2070 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2071 struct cmd_tx_vlan_set_result {
2072         cmdline_fixed_string_t tx_vlan;
2073         cmdline_fixed_string_t set;
2074         uint16_t vlan_id;
2075         uint8_t port_id;
2076 };
2077
2078 static void
2079 cmd_tx_vlan_set_parsed(void *parsed_result,
2080                        __attribute__((unused)) struct cmdline *cl,
2081                        __attribute__((unused)) void *data)
2082 {
2083         struct cmd_tx_vlan_set_result *res = parsed_result;
2084         tx_vlan_set(res->port_id, res->vlan_id);
2085 }
2086
2087 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2088         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2089                                  tx_vlan, "tx_vlan");
2090 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2091         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2092                                  set, "set");
2093 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2094         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2095                               vlan_id, UINT16);
2096 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2097         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2098                               port_id, UINT8);
2099
2100 cmdline_parse_inst_t cmd_tx_vlan_set = {
2101         .f = cmd_tx_vlan_set_parsed,
2102         .data = NULL,
2103         .help_str = "enable hardware insertion of a VLAN header with a given "
2104         "TAG Identifier in packets sent on a port",
2105         .tokens = {
2106                 (void *)&cmd_tx_vlan_set_tx_vlan,
2107                 (void *)&cmd_tx_vlan_set_set,
2108                 (void *)&cmd_tx_vlan_set_vlanid,
2109                 (void *)&cmd_tx_vlan_set_portid,
2110                 NULL,
2111         },
2112 };
2113
2114 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2115 struct cmd_tx_vlan_reset_result {
2116         cmdline_fixed_string_t tx_vlan;
2117         cmdline_fixed_string_t reset;
2118         uint8_t port_id;
2119 };
2120
2121 static void
2122 cmd_tx_vlan_reset_parsed(void *parsed_result,
2123                          __attribute__((unused)) struct cmdline *cl,
2124                          __attribute__((unused)) void *data)
2125 {
2126         struct cmd_tx_vlan_reset_result *res = parsed_result;
2127
2128         tx_vlan_reset(res->port_id);
2129 }
2130
2131 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2132         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2133                                  tx_vlan, "tx_vlan");
2134 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2135         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2136                                  reset, "reset");
2137 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2138         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2139                               port_id, UINT8);
2140
2141 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2142         .f = cmd_tx_vlan_reset_parsed,
2143         .data = NULL,
2144         .help_str = "disable hardware insertion of a VLAN header in packets "
2145         "sent on a port",
2146         .tokens = {
2147                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2148                 (void *)&cmd_tx_vlan_reset_reset,
2149                 (void *)&cmd_tx_vlan_reset_portid,
2150                 NULL,
2151         },
2152 };
2153
2154
2155 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2156 struct cmd_tx_cksum_set_result {
2157         cmdline_fixed_string_t tx_cksum;
2158         cmdline_fixed_string_t set;
2159         uint8_t cksum_mask;
2160         uint8_t port_id;
2161 };
2162
2163 static void
2164 cmd_tx_cksum_set_parsed(void *parsed_result,
2165                        __attribute__((unused)) struct cmdline *cl,
2166                        __attribute__((unused)) void *data)
2167 {
2168         struct cmd_tx_cksum_set_result *res = parsed_result;
2169
2170         tx_cksum_set(res->port_id, res->cksum_mask);
2171 }
2172
2173 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
2174         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2175                                 tx_cksum, "tx_checksum");
2176 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
2177         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2178                                 set, "set");
2179 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
2180         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2181                                 cksum_mask, UINT8);
2182 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
2183         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2184                                 port_id, UINT8);
2185
2186 cmdline_parse_inst_t cmd_tx_cksum_set = {
2187         .f = cmd_tx_cksum_set_parsed,
2188         .data = NULL,
2189         .help_str = "enable hardware insertion of L3/L4checksum with a given "
2190         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
2191         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
2192         .tokens = {
2193                 (void *)&cmd_tx_cksum_set_tx_cksum,
2194                 (void *)&cmd_tx_cksum_set_set,
2195                 (void *)&cmd_tx_cksum_set_cksum_mask,
2196                 (void *)&cmd_tx_cksum_set_portid,
2197                 NULL,
2198         },
2199 };
2200
2201 /* *** SET FORWARDING MODE *** */
2202 struct cmd_set_fwd_mode_result {
2203         cmdline_fixed_string_t set;
2204         cmdline_fixed_string_t fwd;
2205         cmdline_fixed_string_t mode;
2206 };
2207
2208 static void cmd_set_fwd_mode_parsed(void *parsed_result,
2209                                     __attribute__((unused)) struct cmdline *cl,
2210                                     __attribute__((unused)) void *data)
2211 {
2212         struct cmd_set_fwd_mode_result *res = parsed_result;
2213
2214         set_pkt_forwarding_mode(res->mode);
2215 }
2216
2217 cmdline_parse_token_string_t cmd_setfwd_set =
2218         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
2219 cmdline_parse_token_string_t cmd_setfwd_fwd =
2220         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
2221 cmdline_parse_token_string_t cmd_setfwd_mode =
2222         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
2223 #ifdef RTE_LIBRTE_IEEE1588
2224                                  "io#mac#rxonly#txonly#csum#ieee1588");
2225 #else
2226                                  "io#mac#rxonly#txonly#csum");
2227 #endif
2228
2229 cmdline_parse_inst_t cmd_set_fwd_mode = {
2230         .f = cmd_set_fwd_mode_parsed,
2231         .data = NULL,
2232 #ifdef RTE_LIBRTE_IEEE1588
2233         .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
2234         " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
2235 #else
2236         .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
2237         " RXONLY, CSUM or TXONLY packet forwarding mode",
2238 #endif
2239         .tokens = {
2240                 (void *)&cmd_setfwd_set,
2241                 (void *)&cmd_setfwd_fwd,
2242                 (void *)&cmd_setfwd_mode,
2243                 NULL,
2244         },
2245 };
2246
2247 /* *** SET PROMISC MODE *** */
2248 struct cmd_set_promisc_mode_result {
2249         cmdline_fixed_string_t set;
2250         cmdline_fixed_string_t promisc;
2251         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2252         uint8_t port_num;                /* valid if "allports" argument == 0 */
2253         cmdline_fixed_string_t mode;
2254 };
2255
2256 static void cmd_set_promisc_mode_parsed(void *parsed_result,
2257                                         __attribute__((unused)) struct cmdline *cl,
2258                                         void *allports)
2259 {
2260         struct cmd_set_promisc_mode_result *res = parsed_result;
2261         int enable;
2262         portid_t i;
2263
2264         if (!strcmp(res->mode, "on"))
2265                 enable = 1;
2266         else
2267                 enable = 0;
2268
2269         /* all ports */
2270         if (allports) {
2271                 for (i = 0; i < nb_ports; i++) {
2272                         if (enable)
2273                                 rte_eth_promiscuous_enable(i);
2274                         else
2275                                 rte_eth_promiscuous_disable(i);
2276                 }
2277         }
2278         else {
2279                 if (enable)
2280                         rte_eth_promiscuous_enable(res->port_num);
2281                 else
2282                         rte_eth_promiscuous_disable(res->port_num);
2283         }
2284 }
2285
2286 cmdline_parse_token_string_t cmd_setpromisc_set =
2287         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
2288 cmdline_parse_token_string_t cmd_setpromisc_promisc =
2289         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
2290                                  "promisc");
2291 cmdline_parse_token_string_t cmd_setpromisc_portall =
2292         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
2293                                  "all");
2294 cmdline_parse_token_num_t cmd_setpromisc_portnum =
2295         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
2296                               UINT8);
2297 cmdline_parse_token_string_t cmd_setpromisc_mode =
2298         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
2299                                  "on#off");
2300
2301 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
2302         .f = cmd_set_promisc_mode_parsed,
2303         .data = (void *)1,
2304         .help_str = "set promisc all on|off: set promisc mode for all ports",
2305         .tokens = {
2306                 (void *)&cmd_setpromisc_set,
2307                 (void *)&cmd_setpromisc_promisc,
2308                 (void *)&cmd_setpromisc_portall,
2309                 (void *)&cmd_setpromisc_mode,
2310                 NULL,
2311         },
2312 };
2313
2314 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
2315         .f = cmd_set_promisc_mode_parsed,
2316         .data = (void *)0,
2317         .help_str = "set promisc X on|off: set promisc mode on port X",
2318         .tokens = {
2319                 (void *)&cmd_setpromisc_set,
2320                 (void *)&cmd_setpromisc_promisc,
2321                 (void *)&cmd_setpromisc_portnum,
2322                 (void *)&cmd_setpromisc_mode,
2323                 NULL,
2324         },
2325 };
2326
2327 /* *** SET ALLMULTI MODE *** */
2328 struct cmd_set_allmulti_mode_result {
2329         cmdline_fixed_string_t set;
2330         cmdline_fixed_string_t allmulti;
2331         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2332         uint8_t port_num;                /* valid if "allports" argument == 0 */
2333         cmdline_fixed_string_t mode;
2334 };
2335
2336 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
2337                                         __attribute__((unused)) struct cmdline *cl,
2338                                         void *allports)
2339 {
2340         struct cmd_set_allmulti_mode_result *res = parsed_result;
2341         int enable;
2342         portid_t i;
2343
2344         if (!strcmp(res->mode, "on"))
2345                 enable = 1;
2346         else
2347                 enable = 0;
2348
2349         /* all ports */
2350         if (allports) {
2351                 for (i = 0; i < nb_ports; i++) {
2352                         if (enable)
2353                                 rte_eth_allmulticast_enable(i);
2354                         else
2355                                 rte_eth_allmulticast_disable(i);
2356                 }
2357         }
2358         else {
2359                 if (enable)
2360                         rte_eth_allmulticast_enable(res->port_num);
2361                 else
2362                         rte_eth_allmulticast_disable(res->port_num);
2363         }
2364 }
2365
2366 cmdline_parse_token_string_t cmd_setallmulti_set =
2367         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
2368 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
2369         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
2370                                  "allmulti");
2371 cmdline_parse_token_string_t cmd_setallmulti_portall =
2372         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
2373                                  "all");
2374 cmdline_parse_token_num_t cmd_setallmulti_portnum =
2375         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
2376                               UINT8);
2377 cmdline_parse_token_string_t cmd_setallmulti_mode =
2378         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
2379                                  "on#off");
2380
2381 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
2382         .f = cmd_set_allmulti_mode_parsed,
2383         .data = (void *)1,
2384         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
2385         .tokens = {
2386                 (void *)&cmd_setallmulti_set,
2387                 (void *)&cmd_setallmulti_allmulti,
2388                 (void *)&cmd_setallmulti_portall,
2389                 (void *)&cmd_setallmulti_mode,
2390                 NULL,
2391         },
2392 };
2393
2394 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
2395         .f = cmd_set_allmulti_mode_parsed,
2396         .data = (void *)0,
2397         .help_str = "set allmulti X on|off: set allmulti mode on port X",
2398         .tokens = {
2399                 (void *)&cmd_setallmulti_set,
2400                 (void *)&cmd_setallmulti_allmulti,
2401                 (void *)&cmd_setallmulti_portnum,
2402                 (void *)&cmd_setallmulti_mode,
2403                 NULL,
2404         },
2405 };
2406
2407 /* *** ADD/REMOVE A PKT FILTER *** */
2408 struct cmd_pkt_filter_result {
2409         cmdline_fixed_string_t pkt_filter;
2410         uint8_t  port_id;
2411         cmdline_fixed_string_t protocol;
2412         cmdline_fixed_string_t src;
2413         cmdline_ipaddr_t ip_src;
2414         uint16_t port_src;
2415         cmdline_fixed_string_t dst;
2416         cmdline_ipaddr_t ip_dst;
2417         uint16_t port_dst;
2418         cmdline_fixed_string_t flexbytes;
2419         uint16_t flexbytes_value;
2420         cmdline_fixed_string_t vlan;
2421         uint16_t  vlan_id;
2422         cmdline_fixed_string_t queue;
2423         int8_t  queue_id;
2424         cmdline_fixed_string_t soft;
2425         uint8_t  soft_id;
2426 };
2427
2428 static void
2429 cmd_pkt_filter_parsed(void *parsed_result,
2430                           __attribute__((unused)) struct cmdline *cl,
2431                           __attribute__((unused)) void *data)
2432 {
2433         struct rte_fdir_filter fdir_filter;
2434         struct cmd_pkt_filter_result *res = parsed_result;
2435
2436         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
2437
2438         if (res->ip_src.family == AF_INET)
2439                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
2440         else
2441                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
2442                        &(res->ip_src.addr.ipv6),
2443                        sizeof(struct in6_addr));
2444
2445         if (res->ip_dst.family == AF_INET)
2446                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
2447         else
2448                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
2449                        &(res->ip_dst.addr.ipv6),
2450                        sizeof(struct in6_addr));
2451
2452         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
2453         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
2454
2455         if (!strcmp(res->protocol, "udp"))
2456                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
2457         else if (!strcmp(res->protocol, "tcp"))
2458                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
2459         else if (!strcmp(res->protocol, "sctp"))
2460                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
2461         else /* default only IP */
2462                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
2463
2464         if (res->ip_dst.family == AF_INET6)
2465                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
2466         else
2467                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
2468
2469         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
2470         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
2471
2472         if (!strcmp(res->pkt_filter, "add_signature_filter"))
2473                 fdir_add_signature_filter(res->port_id, res->queue_id,
2474                                           &fdir_filter);
2475         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
2476                 fdir_update_signature_filter(res->port_id, res->queue_id,
2477                                              &fdir_filter);
2478         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
2479                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
2480         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
2481                 fdir_add_perfect_filter(res->port_id, res->soft_id,
2482                                         res->queue_id,
2483                                         (uint8_t) (res->queue_id < 0),
2484                                         &fdir_filter);
2485         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
2486                 fdir_update_perfect_filter(res->port_id, res->soft_id,
2487                                            res->queue_id,
2488                                            (uint8_t) (res->queue_id < 0),
2489                                            &fdir_filter);
2490         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
2491                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
2492                                            &fdir_filter);
2493
2494 }
2495
2496
2497 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
2498         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2499                               port_id, UINT8);
2500 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
2501         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2502                                  protocol, "ip#tcp#udp#sctp");
2503 cmdline_parse_token_string_t cmd_pkt_filter_src =
2504         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2505                                  src, "src");
2506 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
2507         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2508                                  ip_src);
2509 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
2510         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2511                               port_src, UINT16);
2512 cmdline_parse_token_string_t cmd_pkt_filter_dst =
2513         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2514                                  dst, "dst");
2515 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
2516         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2517                                  ip_dst);
2518 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
2519         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2520                               port_dst, UINT16);
2521 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
2522         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2523                                  flexbytes, "flexbytes");
2524 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
2525         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2526                               flexbytes_value, UINT16);
2527 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
2528         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2529                                  vlan, "vlan");
2530 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
2531         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2532                               vlan_id, UINT16);
2533 cmdline_parse_token_string_t cmd_pkt_filter_queue =
2534         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2535                                  queue, "queue");
2536 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
2537         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2538                               queue_id, INT8);
2539 cmdline_parse_token_string_t cmd_pkt_filter_soft =
2540         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2541                                  soft, "soft");
2542 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
2543         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2544                               soft_id, UINT16);
2545
2546
2547 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
2548         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2549                                  pkt_filter, "add_signature_filter");
2550 cmdline_parse_inst_t cmd_add_signature_filter = {
2551         .f = cmd_pkt_filter_parsed,
2552         .data = NULL,
2553         .help_str = "add a signature filter",
2554         .tokens = {
2555                 (void *)&cmd_pkt_filter_add_signature_filter,
2556                 (void *)&cmd_pkt_filter_port_id,
2557                 (void *)&cmd_pkt_filter_protocol,
2558                 (void *)&cmd_pkt_filter_src,
2559                 (void *)&cmd_pkt_filter_ip_src,
2560                 (void *)&cmd_pkt_filter_port_src,
2561                 (void *)&cmd_pkt_filter_dst,
2562                 (void *)&cmd_pkt_filter_ip_dst,
2563                 (void *)&cmd_pkt_filter_port_dst,
2564                 (void *)&cmd_pkt_filter_flexbytes,
2565                 (void *)&cmd_pkt_filter_flexbytes_value,
2566                 (void *)&cmd_pkt_filter_vlan,
2567                 (void *)&cmd_pkt_filter_vlan_id,
2568                 (void *)&cmd_pkt_filter_queue,
2569                 (void *)&cmd_pkt_filter_queue_id,
2570                 NULL,
2571         },
2572 };
2573
2574
2575 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
2576         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2577                                  pkt_filter, "upd_signature_filter");
2578 cmdline_parse_inst_t cmd_upd_signature_filter = {
2579         .f = cmd_pkt_filter_parsed,
2580         .data = NULL,
2581         .help_str = "update a signature filter",
2582         .tokens = {
2583                 (void *)&cmd_pkt_filter_upd_signature_filter,
2584                 (void *)&cmd_pkt_filter_port_id,
2585                 (void *)&cmd_pkt_filter_protocol,
2586                 (void *)&cmd_pkt_filter_src,
2587                 (void *)&cmd_pkt_filter_ip_src,
2588                 (void *)&cmd_pkt_filter_port_src,
2589                 (void *)&cmd_pkt_filter_dst,
2590                 (void *)&cmd_pkt_filter_ip_dst,
2591                 (void *)&cmd_pkt_filter_port_dst,
2592                 (void *)&cmd_pkt_filter_flexbytes,
2593                 (void *)&cmd_pkt_filter_flexbytes_value,
2594                 (void *)&cmd_pkt_filter_vlan,
2595                 (void *)&cmd_pkt_filter_vlan_id,
2596                 (void *)&cmd_pkt_filter_queue,
2597                 (void *)&cmd_pkt_filter_queue_id,
2598                 NULL,
2599         },
2600 };
2601
2602
2603 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
2604         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2605                                  pkt_filter, "rm_signature_filter");
2606 cmdline_parse_inst_t cmd_rm_signature_filter = {
2607         .f = cmd_pkt_filter_parsed,
2608         .data = NULL,
2609         .help_str = "remove a signature filter",
2610         .tokens = {
2611                 (void *)&cmd_pkt_filter_rm_signature_filter,
2612                 (void *)&cmd_pkt_filter_port_id,
2613                 (void *)&cmd_pkt_filter_protocol,
2614                 (void *)&cmd_pkt_filter_src,
2615                 (void *)&cmd_pkt_filter_ip_src,
2616                 (void *)&cmd_pkt_filter_port_src,
2617                 (void *)&cmd_pkt_filter_dst,
2618                 (void *)&cmd_pkt_filter_ip_dst,
2619                 (void *)&cmd_pkt_filter_port_dst,
2620                 (void *)&cmd_pkt_filter_flexbytes,
2621                 (void *)&cmd_pkt_filter_flexbytes_value,
2622                 (void *)&cmd_pkt_filter_vlan,
2623                 (void *)&cmd_pkt_filter_vlan_id,
2624                 NULL
2625                 },
2626 };
2627
2628
2629 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
2630         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2631                                  pkt_filter, "add_perfect_filter");
2632 cmdline_parse_inst_t cmd_add_perfect_filter = {
2633         .f = cmd_pkt_filter_parsed,
2634         .data = NULL,
2635         .help_str = "add a perfect filter",
2636         .tokens = {
2637                 (void *)&cmd_pkt_filter_add_perfect_filter,
2638                 (void *)&cmd_pkt_filter_port_id,
2639                 (void *)&cmd_pkt_filter_protocol,
2640                 (void *)&cmd_pkt_filter_src,
2641                 (void *)&cmd_pkt_filter_ip_src,
2642                 (void *)&cmd_pkt_filter_port_src,
2643                 (void *)&cmd_pkt_filter_dst,
2644                 (void *)&cmd_pkt_filter_ip_dst,
2645                 (void *)&cmd_pkt_filter_port_dst,
2646                 (void *)&cmd_pkt_filter_flexbytes,
2647                 (void *)&cmd_pkt_filter_flexbytes_value,
2648                 (void *)&cmd_pkt_filter_vlan,
2649                 (void *)&cmd_pkt_filter_vlan_id,
2650                 (void *)&cmd_pkt_filter_queue,
2651                 (void *)&cmd_pkt_filter_queue_id,
2652                 (void *)&cmd_pkt_filter_soft,
2653                 (void *)&cmd_pkt_filter_soft_id,
2654                 NULL,
2655         },
2656 };
2657
2658
2659 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
2660         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2661                                  pkt_filter, "upd_perfect_filter");
2662 cmdline_parse_inst_t cmd_upd_perfect_filter = {
2663         .f = cmd_pkt_filter_parsed,
2664         .data = NULL,
2665         .help_str = "update a perfect filter",
2666         .tokens = {
2667                 (void *)&cmd_pkt_filter_upd_perfect_filter,
2668                 (void *)&cmd_pkt_filter_port_id,
2669                 (void *)&cmd_pkt_filter_protocol,
2670                 (void *)&cmd_pkt_filter_src,
2671                 (void *)&cmd_pkt_filter_ip_src,
2672                 (void *)&cmd_pkt_filter_port_src,
2673                 (void *)&cmd_pkt_filter_dst,
2674                 (void *)&cmd_pkt_filter_ip_dst,
2675                 (void *)&cmd_pkt_filter_port_dst,
2676                 (void *)&cmd_pkt_filter_flexbytes,
2677                 (void *)&cmd_pkt_filter_flexbytes_value,
2678                 (void *)&cmd_pkt_filter_vlan,
2679                 (void *)&cmd_pkt_filter_vlan_id,
2680                 (void *)&cmd_pkt_filter_queue,
2681                 (void *)&cmd_pkt_filter_queue_id,
2682                 (void *)&cmd_pkt_filter_soft,
2683                 (void *)&cmd_pkt_filter_soft_id,
2684                 NULL,
2685         },
2686 };
2687
2688
2689 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
2690         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2691                                  pkt_filter, "rm_perfect_filter");
2692 cmdline_parse_inst_t cmd_rm_perfect_filter = {
2693         .f = cmd_pkt_filter_parsed,
2694         .data = NULL,
2695         .help_str = "remove a perfect filter",
2696         .tokens = {
2697                 (void *)&cmd_pkt_filter_rm_perfect_filter,
2698                 (void *)&cmd_pkt_filter_port_id,
2699                 (void *)&cmd_pkt_filter_protocol,
2700                 (void *)&cmd_pkt_filter_src,
2701                 (void *)&cmd_pkt_filter_ip_src,
2702                 (void *)&cmd_pkt_filter_port_src,
2703                 (void *)&cmd_pkt_filter_dst,
2704                 (void *)&cmd_pkt_filter_ip_dst,
2705                 (void *)&cmd_pkt_filter_port_dst,
2706                 (void *)&cmd_pkt_filter_flexbytes,
2707                 (void *)&cmd_pkt_filter_flexbytes_value,
2708                 (void *)&cmd_pkt_filter_vlan,
2709                 (void *)&cmd_pkt_filter_vlan_id,
2710                 (void *)&cmd_pkt_filter_soft,
2711                 (void *)&cmd_pkt_filter_soft_id,
2712                 NULL,
2713         },
2714 };
2715
2716 /* *** SETUP MASKS FILTER *** */
2717 struct cmd_pkt_filter_masks_result {
2718         cmdline_fixed_string_t filter_mask;
2719         uint8_t  port_id;
2720         cmdline_fixed_string_t src_mask;
2721         uint32_t ip_src_mask;
2722         uint16_t ipv6_src_mask;
2723         uint16_t port_src_mask;
2724         cmdline_fixed_string_t dst_mask;
2725         uint32_t ip_dst_mask;
2726         uint16_t ipv6_dst_mask;
2727         uint16_t port_dst_mask;
2728         cmdline_fixed_string_t flexbytes;
2729         uint8_t flexbytes_value;
2730         cmdline_fixed_string_t vlan_id;
2731         uint8_t  vlan_id_value;
2732         cmdline_fixed_string_t vlan_prio;
2733         uint8_t  vlan_prio_value;
2734         cmdline_fixed_string_t only_ip_flow;
2735         uint8_t  only_ip_flow_value;
2736         cmdline_fixed_string_t comp_ipv6_dst;
2737         uint8_t  comp_ipv6_dst_value;
2738 };
2739
2740 static void
2741 cmd_pkt_filter_masks_parsed(void *parsed_result,
2742                           __attribute__((unused)) struct cmdline *cl,
2743                           __attribute__((unused)) void *data)
2744 {
2745         struct rte_fdir_masks fdir_masks;
2746         struct cmd_pkt_filter_masks_result *res = parsed_result;
2747
2748         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
2749
2750         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
2751         fdir_masks.vlan_id       = res->vlan_id_value;
2752         fdir_masks.vlan_prio     = res->vlan_prio_value;
2753         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
2754         fdir_masks.src_ipv4_mask = res->ip_src_mask;
2755         fdir_masks.src_port_mask = res->port_src_mask;
2756         fdir_masks.dst_port_mask = res->port_dst_mask;
2757         fdir_masks.flexbytes     = res->flexbytes_value;
2758
2759         fdir_set_masks(res->port_id, &fdir_masks);
2760 }
2761
2762 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
2763         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2764                                  filter_mask, "set_masks_filter");
2765 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
2766         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2767                               port_id, UINT8);
2768 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
2769         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2770                                  only_ip_flow, "only_ip_flow");
2771 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
2772         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2773                               only_ip_flow_value, UINT8);
2774 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
2775         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2776                                  src_mask, "src_mask");
2777 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
2778         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2779                               ip_src_mask, UINT32);
2780 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
2781         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2782                               port_src_mask, UINT16);
2783 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
2784         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2785                                  dst_mask, "dst_mask");
2786 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
2787         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2788                               ip_dst_mask, UINT32);
2789 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
2790         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2791                               port_dst_mask, UINT16);
2792 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
2793         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2794                                  flexbytes, "flexbytes");
2795 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
2796         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2797                               flexbytes_value, UINT8);
2798 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
2799         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2800                                  vlan_id, "vlan_id");
2801 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
2802         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2803                               vlan_id_value, UINT8);
2804 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
2805         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2806                                  vlan_prio, "vlan_prio");
2807 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
2808         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2809                               vlan_prio_value, UINT8);
2810
2811 cmdline_parse_inst_t cmd_set_masks_filter = {
2812         .f = cmd_pkt_filter_masks_parsed,
2813         .data = NULL,
2814         .help_str = "setup masks filter",
2815         .tokens = {
2816                 (void *)&cmd_pkt_filter_masks_filter_mask,
2817                 (void *)&cmd_pkt_filter_masks_port_id,
2818                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
2819                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
2820                 (void *)&cmd_pkt_filter_masks_src_mask,
2821                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
2822                 (void *)&cmd_pkt_filter_masks_port_src_mask,
2823                 (void *)&cmd_pkt_filter_masks_dst_mask,
2824                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
2825                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
2826                 (void *)&cmd_pkt_filter_masks_flexbytes,
2827                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
2828                 (void *)&cmd_pkt_filter_masks_vlan_id,
2829                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
2830                 (void *)&cmd_pkt_filter_masks_vlan_prio,
2831                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
2832                 NULL,
2833         },
2834 };
2835
2836 static void
2837 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
2838                           __attribute__((unused)) struct cmdline *cl,
2839                           __attribute__((unused)) void *data)
2840 {
2841         struct rte_fdir_masks fdir_masks;
2842         struct cmd_pkt_filter_masks_result *res = parsed_result;
2843
2844         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
2845
2846         fdir_masks.set_ipv6_mask = 1;
2847         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
2848         fdir_masks.vlan_id       = res->vlan_id_value;
2849         fdir_masks.vlan_prio     = res->vlan_prio_value;
2850         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
2851         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
2852         fdir_masks.src_port_mask = res->port_src_mask;
2853         fdir_masks.dst_port_mask = res->port_dst_mask;
2854         fdir_masks.flexbytes     = res->flexbytes_value;
2855         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
2856
2857         fdir_set_masks(res->port_id, &fdir_masks);
2858 }
2859
2860 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
2861         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2862                                  filter_mask, "set_ipv6_masks_filter");
2863 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
2864         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2865                               ipv6_src_mask, UINT16);
2866 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
2867         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2868                               ipv6_dst_mask, UINT16);
2869
2870 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
2871         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
2872                                  comp_ipv6_dst, "compare_dst");
2873 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
2874         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
2875                               comp_ipv6_dst_value, UINT8);
2876
2877 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
2878         .f = cmd_pkt_filter_masks_ipv6_parsed,
2879         .data = NULL,
2880         .help_str = "setup ipv6 masks filter",
2881         .tokens = {
2882                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
2883                 (void *)&cmd_pkt_filter_masks_port_id,
2884                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
2885                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
2886                 (void *)&cmd_pkt_filter_masks_src_mask,
2887                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
2888                 (void *)&cmd_pkt_filter_masks_port_src_mask,
2889                 (void *)&cmd_pkt_filter_masks_dst_mask,
2890                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
2891                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
2892                 (void *)&cmd_pkt_filter_masks_flexbytes,
2893                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
2894                 (void *)&cmd_pkt_filter_masks_vlan_id,
2895                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
2896                 (void *)&cmd_pkt_filter_masks_vlan_prio,
2897                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
2898                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
2899                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
2900                 NULL,
2901         },
2902 };
2903
2904 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
2905 struct cmd_link_flow_ctrl_set_result {
2906         cmdline_fixed_string_t set;
2907         cmdline_fixed_string_t flow_ctrl;
2908         cmdline_fixed_string_t rx;
2909         cmdline_fixed_string_t rx_lfc_mode;
2910         cmdline_fixed_string_t tx;
2911         cmdline_fixed_string_t tx_lfc_mode;
2912         uint32_t high_water;
2913         uint32_t low_water;
2914         uint16_t pause_time;
2915         uint16_t send_xon;
2916         uint8_t  port_id;
2917 };
2918
2919 static void
2920 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
2921                        __attribute__((unused)) struct cmdline *cl,
2922                        __attribute__((unused)) void *data)
2923 {
2924         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
2925         struct rte_eth_fc_conf fc_conf;
2926         int rx_fc_enable, tx_fc_enable;
2927         int ret;
2928
2929         /*
2930          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
2931          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
2932          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
2933          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
2934          */
2935         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
2936                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
2937         };
2938
2939         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
2940         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
2941
2942         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
2943         fc_conf.high_water = res->high_water;
2944         fc_conf.low_water  = res->low_water;
2945         fc_conf.pause_time = res->pause_time;
2946         fc_conf.send_xon   = res->send_xon;
2947
2948         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
2949         if (ret != 0)
2950                 printf("bad flow contrl parameter, return code = %d \n", ret);
2951 }
2952
2953 cmdline_parse_token_string_t cmd_lfc_set_set =
2954         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2955                                 set, "set");
2956 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
2957         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2958                                 flow_ctrl, "flow_ctrl");
2959 cmdline_parse_token_string_t cmd_lfc_set_rx =
2960         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2961                                 rx, "rx");
2962 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
2963         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2964                                 rx_lfc_mode, "on#off");
2965 cmdline_parse_token_string_t cmd_lfc_set_tx =
2966         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2967                                 tx, "tx");
2968 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
2969         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2970                                 tx_lfc_mode, "on#off");
2971 cmdline_parse_token_num_t cmd_lfc_set_high_water =
2972         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2973                                 high_water, UINT32);
2974 cmdline_parse_token_num_t cmd_lfc_set_low_water =
2975         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2976                                 low_water, UINT32);
2977 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
2978         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2979                                 pause_time, UINT16);
2980 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
2981         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2982                                 send_xon, UINT16);
2983 cmdline_parse_token_num_t cmd_lfc_set_portid =
2984         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
2985                                 port_id, UINT8);
2986
2987 cmdline_parse_inst_t cmd_link_flow_control_set = {
2988         .f = cmd_link_flow_ctrl_set_parsed,
2989         .data = NULL,
2990         .help_str = "Configure the Ethernet link flow control...",
2991         .tokens = {
2992                 (void *)&cmd_lfc_set_set,
2993                 (void *)&cmd_lfc_set_flow_ctrl,
2994                 (void *)&cmd_lfc_set_rx,
2995                 (void *)&cmd_lfc_set_rx_mode,
2996                 (void *)&cmd_lfc_set_tx,
2997                 (void *)&cmd_lfc_set_tx_mode,
2998                 (void *)&cmd_lfc_set_high_water,
2999                 (void *)&cmd_lfc_set_low_water,
3000                 (void *)&cmd_lfc_set_pause_time,
3001                 (void *)&cmd_lfc_set_send_xon,
3002                 (void *)&cmd_lfc_set_portid,
3003                 NULL,
3004         },
3005 };
3006
3007 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
3008 struct cmd_priority_flow_ctrl_set_result {
3009         cmdline_fixed_string_t set;
3010         cmdline_fixed_string_t pfc_ctrl;
3011         cmdline_fixed_string_t rx;
3012         cmdline_fixed_string_t rx_pfc_mode;
3013         cmdline_fixed_string_t tx;
3014         cmdline_fixed_string_t tx_pfc_mode;
3015         uint32_t high_water;
3016         uint32_t low_water;
3017         uint16_t pause_time;
3018         uint8_t  priority;
3019         uint8_t  port_id;
3020 };
3021
3022 static void
3023 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
3024                        __attribute__((unused)) struct cmdline *cl,
3025                        __attribute__((unused)) void *data)
3026 {
3027         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
3028         struct rte_eth_pfc_conf pfc_conf;
3029         int rx_fc_enable, tx_fc_enable;
3030         int ret;
3031
3032         /*
3033          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3034          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3035          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3036          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3037          */
3038         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
3039                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3040         };
3041
3042         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
3043         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
3044         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
3045         pfc_conf.fc.high_water = res->high_water;
3046         pfc_conf.fc.low_water  = res->low_water;
3047         pfc_conf.fc.pause_time = res->pause_time;
3048         pfc_conf.priority      = res->priority;
3049
3050         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
3051         if (ret != 0)
3052                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
3053 }
3054
3055 cmdline_parse_token_string_t cmd_pfc_set_set =
3056         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3057                                 set, "set");
3058 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
3059         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3060                                 pfc_ctrl, "pfc_ctrl");
3061 cmdline_parse_token_string_t cmd_pfc_set_rx =
3062         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3063                                 rx, "rx");
3064 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
3065         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3066                                 rx_pfc_mode, "on#off");
3067 cmdline_parse_token_string_t cmd_pfc_set_tx =
3068         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3069                                 tx, "tx");
3070 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
3071         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3072                                 tx_pfc_mode, "on#off");
3073 cmdline_parse_token_num_t cmd_pfc_set_high_water =
3074         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3075                                 high_water, UINT32);
3076 cmdline_parse_token_num_t cmd_pfc_set_low_water =
3077         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3078                                 low_water, UINT32);
3079 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
3080         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3081                                 pause_time, UINT16);
3082 cmdline_parse_token_num_t cmd_pfc_set_priority =
3083         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3084                                 priority, UINT8);
3085 cmdline_parse_token_num_t cmd_pfc_set_portid =
3086         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3087                                 port_id, UINT8);
3088
3089 cmdline_parse_inst_t cmd_priority_flow_control_set = {
3090         .f = cmd_priority_flow_ctrl_set_parsed,
3091         .data = NULL,
3092         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
3093                         tx on|off high_water low_water pause_time priority port_id",
3094         .tokens = {
3095                 (void *)&cmd_pfc_set_set,
3096                 (void *)&cmd_pfc_set_flow_ctrl,
3097                 (void *)&cmd_pfc_set_rx,
3098                 (void *)&cmd_pfc_set_rx_mode,
3099                 (void *)&cmd_pfc_set_tx,
3100                 (void *)&cmd_pfc_set_tx_mode,
3101                 (void *)&cmd_pfc_set_high_water,
3102                 (void *)&cmd_pfc_set_low_water,
3103                 (void *)&cmd_pfc_set_pause_time,
3104                 (void *)&cmd_pfc_set_priority,
3105                 (void *)&cmd_pfc_set_portid,
3106                 NULL,
3107         },
3108 };
3109
3110 /* *** RESET CONFIGURATION *** */
3111 struct cmd_reset_result {
3112         cmdline_fixed_string_t reset;
3113         cmdline_fixed_string_t def;
3114 };
3115
3116 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
3117                              struct cmdline *cl,
3118                              __attribute__((unused)) void *data)
3119 {
3120         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
3121         set_def_fwd_config();
3122 }
3123
3124 cmdline_parse_token_string_t cmd_reset_set =
3125         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
3126 cmdline_parse_token_string_t cmd_reset_def =
3127         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
3128                                  "default");
3129
3130 cmdline_parse_inst_t cmd_reset = {
3131         .f = cmd_reset_parsed,
3132         .data = NULL,
3133         .help_str = "set default: reset default forwarding configuration",
3134         .tokens = {
3135                 (void *)&cmd_reset_set,
3136                 (void *)&cmd_reset_def,
3137                 NULL,
3138         },
3139 };
3140
3141 /* *** START FORWARDING *** */
3142 struct cmd_start_result {
3143         cmdline_fixed_string_t start;
3144 };
3145
3146 cmdline_parse_token_string_t cmd_start_start =
3147         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
3148
3149 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
3150                              __attribute__((unused)) struct cmdline *cl,
3151                              __attribute__((unused)) void *data)
3152 {
3153         start_packet_forwarding(0);
3154 }
3155
3156 cmdline_parse_inst_t cmd_start = {
3157         .f = cmd_start_parsed,
3158         .data = NULL,
3159         .help_str = "start packet forwarding",
3160         .tokens = {
3161                 (void *)&cmd_start_start,
3162                 NULL,
3163         },
3164 };
3165
3166 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
3167 struct cmd_start_tx_first_result {
3168         cmdline_fixed_string_t start;
3169         cmdline_fixed_string_t tx_first;
3170 };
3171
3172 static void
3173 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
3174                           __attribute__((unused)) struct cmdline *cl,
3175                           __attribute__((unused)) void *data)
3176 {
3177         start_packet_forwarding(1);
3178 }
3179
3180 cmdline_parse_token_string_t cmd_start_tx_first_start =
3181         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
3182                                  "start");
3183 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
3184         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
3185                                  tx_first, "tx_first");
3186
3187 cmdline_parse_inst_t cmd_start_tx_first = {
3188         .f = cmd_start_tx_first_parsed,
3189         .data = NULL,
3190         .help_str = "start packet forwarding, after sending 1 burst of packets",
3191         .tokens = {
3192                 (void *)&cmd_start_tx_first_start,
3193                 (void *)&cmd_start_tx_first_tx_first,
3194                 NULL,
3195         },
3196 };
3197
3198 /* *** SHOW CFG *** */
3199 struct cmd_showcfg_result {
3200         cmdline_fixed_string_t show;
3201         cmdline_fixed_string_t cfg;
3202         cmdline_fixed_string_t what;
3203 };
3204
3205 static void cmd_showcfg_parsed(void *parsed_result,
3206                                __attribute__((unused)) struct cmdline *cl,
3207                                __attribute__((unused)) void *data)
3208 {
3209         struct cmd_showcfg_result *res = parsed_result;
3210         if (!strcmp(res->what, "rxtx"))
3211                 rxtx_config_display();
3212         else if (!strcmp(res->what, "cores"))
3213                 fwd_lcores_config_display();
3214         else if (!strcmp(res->what, "fwd"))
3215                 fwd_config_display();
3216 }
3217
3218 cmdline_parse_token_string_t cmd_showcfg_show =
3219         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
3220 cmdline_parse_token_string_t cmd_showcfg_port =
3221         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
3222 cmdline_parse_token_string_t cmd_showcfg_what =
3223         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
3224                                  "rxtx#cores#fwd");
3225
3226 cmdline_parse_inst_t cmd_showcfg = {
3227         .f = cmd_showcfg_parsed,
3228         .data = NULL,
3229         .help_str = "show config rxtx|cores|fwd",
3230         .tokens = {
3231                 (void *)&cmd_showcfg_show,
3232                 (void *)&cmd_showcfg_port,
3233                 (void *)&cmd_showcfg_what,
3234                 NULL,
3235         },
3236 };
3237
3238 /* *** SHOW ALL PORT INFO *** */
3239 struct cmd_showportall_result {
3240         cmdline_fixed_string_t show;
3241         cmdline_fixed_string_t port;
3242         cmdline_fixed_string_t what;
3243         cmdline_fixed_string_t all;
3244 };
3245
3246 static void cmd_showportall_parsed(void *parsed_result,
3247                                 __attribute__((unused)) struct cmdline *cl,
3248                                 __attribute__((unused)) void *data)
3249 {
3250         portid_t i;
3251
3252         struct cmd_showportall_result *res = parsed_result;
3253         if (!strcmp(res->show, "clear")) {
3254                 if (!strcmp(res->what, "stats"))
3255                         for (i = 0; i < nb_ports; i++)
3256                                 nic_stats_clear(i);
3257         } else if (!strcmp(res->what, "info"))
3258                 for (i = 0; i < nb_ports; i++)
3259                         port_infos_display(i);
3260         else if (!strcmp(res->what, "stats"))
3261                 for (i = 0; i < nb_ports; i++)
3262                         nic_stats_display(i);
3263         else if (!strcmp(res->what, "fdir"))
3264                 for (i = 0; i < nb_ports; i++)
3265                         fdir_get_infos(i);
3266         else if (!strcmp(res->what, "stat_qmap"))
3267                 for (i = 0; i < nb_ports; i++)
3268                         nic_stats_mapping_display(i);
3269 }
3270
3271 cmdline_parse_token_string_t cmd_showportall_show =
3272         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
3273                                  "show#clear");
3274 cmdline_parse_token_string_t cmd_showportall_port =
3275         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
3276 cmdline_parse_token_string_t cmd_showportall_what =
3277         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
3278                                  "info#stats#fdir#stat_qmap");
3279 cmdline_parse_token_string_t cmd_showportall_all =
3280         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
3281 cmdline_parse_inst_t cmd_showportall = {
3282         .f = cmd_showportall_parsed,
3283         .data = NULL,
3284         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
3285         .tokens = {
3286                 (void *)&cmd_showportall_show,
3287                 (void *)&cmd_showportall_port,
3288                 (void *)&cmd_showportall_what,
3289                 (void *)&cmd_showportall_all,
3290                 NULL,
3291         },
3292 };
3293
3294 /* *** SHOW PORT INFO *** */
3295 struct cmd_showport_result {
3296         cmdline_fixed_string_t show;
3297         cmdline_fixed_string_t port;
3298         cmdline_fixed_string_t what;
3299         uint8_t portnum;
3300 };
3301
3302 static void cmd_showport_parsed(void *parsed_result,
3303                                 __attribute__((unused)) struct cmdline *cl,
3304                                 __attribute__((unused)) void *data)
3305 {
3306         struct cmd_showport_result *res = parsed_result;
3307         if (!strcmp(res->show, "clear")) {
3308                 if (!strcmp(res->what, "stats"))
3309                         nic_stats_clear(res->portnum);
3310         } else if (!strcmp(res->what, "info"))
3311                 port_infos_display(res->portnum);
3312         else if (!strcmp(res->what, "stats"))
3313                 nic_stats_display(res->portnum);
3314         else if (!strcmp(res->what, "fdir"))
3315                  fdir_get_infos(res->portnum);
3316         else if (!strcmp(res->what, "stat_qmap"))
3317                 nic_stats_mapping_display(res->portnum);
3318 }
3319
3320 cmdline_parse_token_string_t cmd_showport_show =
3321         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
3322                                  "show#clear");
3323 cmdline_parse_token_string_t cmd_showport_port =
3324         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
3325 cmdline_parse_token_string_t cmd_showport_what =
3326         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
3327                                  "info#stats#fdir#stat_qmap");
3328 cmdline_parse_token_num_t cmd_showport_portnum =
3329         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
3330
3331 cmdline_parse_inst_t cmd_showport = {
3332         .f = cmd_showport_parsed,
3333         .data = NULL,
3334         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
3335         .tokens = {
3336                 (void *)&cmd_showport_show,
3337                 (void *)&cmd_showport_port,
3338                 (void *)&cmd_showport_what,
3339                 (void *)&cmd_showport_portnum,
3340                 NULL,
3341         },
3342 };
3343
3344 /* *** READ PORT REGISTER *** */
3345 struct cmd_read_reg_result {
3346         cmdline_fixed_string_t read;
3347         cmdline_fixed_string_t reg;
3348         uint8_t port_id;
3349         uint32_t reg_off;
3350 };
3351
3352 static void
3353 cmd_read_reg_parsed(void *parsed_result,
3354                     __attribute__((unused)) struct cmdline *cl,
3355                     __attribute__((unused)) void *data)
3356 {
3357         struct cmd_read_reg_result *res = parsed_result;
3358         port_reg_display(res->port_id, res->reg_off);
3359 }
3360
3361 cmdline_parse_token_string_t cmd_read_reg_read =
3362         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
3363 cmdline_parse_token_string_t cmd_read_reg_reg =
3364         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
3365 cmdline_parse_token_num_t cmd_read_reg_port_id =
3366         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
3367 cmdline_parse_token_num_t cmd_read_reg_reg_off =
3368         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
3369
3370 cmdline_parse_inst_t cmd_read_reg = {
3371         .f = cmd_read_reg_parsed,
3372         .data = NULL,
3373         .help_str = "read reg port_id reg_off",
3374         .tokens = {
3375                 (void *)&cmd_read_reg_read,
3376                 (void *)&cmd_read_reg_reg,
3377                 (void *)&cmd_read_reg_port_id,
3378                 (void *)&cmd_read_reg_reg_off,
3379                 NULL,
3380         },
3381 };
3382
3383 /* *** READ PORT REGISTER BIT FIELD *** */
3384 struct cmd_read_reg_bit_field_result {
3385         cmdline_fixed_string_t read;
3386         cmdline_fixed_string_t regfield;
3387         uint8_t port_id;
3388         uint32_t reg_off;
3389         uint8_t bit1_pos;
3390         uint8_t bit2_pos;
3391 };
3392
3393 static void
3394 cmd_read_reg_bit_field_parsed(void *parsed_result,
3395                               __attribute__((unused)) struct cmdline *cl,
3396                               __attribute__((unused)) void *data)
3397 {
3398         struct cmd_read_reg_bit_field_result *res = parsed_result;
3399         port_reg_bit_field_display(res->port_id, res->reg_off,
3400                                    res->bit1_pos, res->bit2_pos);
3401 }
3402
3403 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
3404         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
3405                                  "read");
3406 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
3407         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
3408                                  regfield, "regfield");
3409 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
3410         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
3411                               UINT8);
3412 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
3413         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
3414                               UINT32);
3415 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
3416         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
3417                               UINT8);
3418 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
3419         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
3420                               UINT8);
3421
3422 cmdline_parse_inst_t cmd_read_reg_bit_field = {
3423         .f = cmd_read_reg_bit_field_parsed,
3424         .data = NULL,
3425         .help_str = "read regfield port_id reg_off bit_x bit_y "
3426         "(read register bit field between bit_x and bit_y included)",
3427         .tokens = {
3428                 (void *)&cmd_read_reg_bit_field_read,
3429                 (void *)&cmd_read_reg_bit_field_regfield,
3430                 (void *)&cmd_read_reg_bit_field_port_id,
3431                 (void *)&cmd_read_reg_bit_field_reg_off,
3432                 (void *)&cmd_read_reg_bit_field_bit1_pos,
3433                 (void *)&cmd_read_reg_bit_field_bit2_pos,
3434                 NULL,
3435         },
3436 };
3437
3438 /* *** READ PORT REGISTER BIT *** */
3439 struct cmd_read_reg_bit_result {
3440         cmdline_fixed_string_t read;
3441         cmdline_fixed_string_t regbit;
3442         uint8_t port_id;
3443         uint32_t reg_off;
3444         uint8_t bit_pos;
3445 };
3446
3447 static void
3448 cmd_read_reg_bit_parsed(void *parsed_result,
3449                         __attribute__((unused)) struct cmdline *cl,
3450                         __attribute__((unused)) void *data)
3451 {
3452         struct cmd_read_reg_bit_result *res = parsed_result;
3453         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
3454 }
3455
3456 cmdline_parse_token_string_t cmd_read_reg_bit_read =
3457         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
3458 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
3459         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
3460                                  regbit, "regbit");
3461 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
3462         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
3463 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
3464         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
3465 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
3466         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
3467
3468 cmdline_parse_inst_t cmd_read_reg_bit = {
3469         .f = cmd_read_reg_bit_parsed,
3470         .data = NULL,
3471         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
3472         .tokens = {
3473                 (void *)&cmd_read_reg_bit_read,
3474                 (void *)&cmd_read_reg_bit_regbit,
3475                 (void *)&cmd_read_reg_bit_port_id,
3476                 (void *)&cmd_read_reg_bit_reg_off,
3477                 (void *)&cmd_read_reg_bit_bit_pos,
3478                 NULL,
3479         },
3480 };
3481
3482 /* *** WRITE PORT REGISTER *** */
3483 struct cmd_write_reg_result {
3484         cmdline_fixed_string_t write;
3485         cmdline_fixed_string_t reg;
3486         uint8_t port_id;
3487         uint32_t reg_off;
3488         uint32_t value;
3489 };
3490
3491 static void
3492 cmd_write_reg_parsed(void *parsed_result,
3493                      __attribute__((unused)) struct cmdline *cl,
3494                      __attribute__((unused)) void *data)
3495 {
3496         struct cmd_write_reg_result *res = parsed_result;
3497         port_reg_set(res->port_id, res->reg_off, res->value);
3498 }
3499
3500 cmdline_parse_token_string_t cmd_write_reg_write =
3501         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
3502 cmdline_parse_token_string_t cmd_write_reg_reg =
3503         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
3504 cmdline_parse_token_num_t cmd_write_reg_port_id =
3505         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
3506 cmdline_parse_token_num_t cmd_write_reg_reg_off =
3507         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
3508 cmdline_parse_token_num_t cmd_write_reg_value =
3509         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
3510
3511 cmdline_parse_inst_t cmd_write_reg = {
3512         .f = cmd_write_reg_parsed,
3513         .data = NULL,
3514         .help_str = "write reg port_id reg_off reg_value",
3515         .tokens = {
3516                 (void *)&cmd_write_reg_write,
3517                 (void *)&cmd_write_reg_reg,
3518                 (void *)&cmd_write_reg_port_id,
3519                 (void *)&cmd_write_reg_reg_off,
3520                 (void *)&cmd_write_reg_value,
3521                 NULL,
3522         },
3523 };
3524
3525 /* *** WRITE PORT REGISTER BIT FIELD *** */
3526 struct cmd_write_reg_bit_field_result {
3527         cmdline_fixed_string_t write;
3528         cmdline_fixed_string_t regfield;
3529         uint8_t port_id;
3530         uint32_t reg_off;
3531         uint8_t bit1_pos;
3532         uint8_t bit2_pos;
3533         uint32_t value;
3534 };
3535
3536 static void
3537 cmd_write_reg_bit_field_parsed(void *parsed_result,
3538                                __attribute__((unused)) struct cmdline *cl,
3539                                __attribute__((unused)) void *data)
3540 {
3541         struct cmd_write_reg_bit_field_result *res = parsed_result;
3542         port_reg_bit_field_set(res->port_id, res->reg_off,
3543                           res->bit1_pos, res->bit2_pos, res->value);
3544 }
3545
3546 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
3547         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
3548                                  "write");
3549 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
3550         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
3551                                  regfield, "regfield");
3552 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
3553         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
3554                               UINT8);
3555 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
3556         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
3557                               UINT32);
3558 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
3559         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
3560                               UINT8);
3561 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
3562         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
3563                               UINT8);
3564 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
3565         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
3566                               UINT32);
3567
3568 cmdline_parse_inst_t cmd_write_reg_bit_field = {
3569         .f = cmd_write_reg_bit_field_parsed,
3570         .data = NULL,
3571         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
3572         "(set register bit field between bit_x and bit_y included)",
3573         .tokens = {
3574                 (void *)&cmd_write_reg_bit_field_write,
3575                 (void *)&cmd_write_reg_bit_field_regfield,
3576                 (void *)&cmd_write_reg_bit_field_port_id,
3577                 (void *)&cmd_write_reg_bit_field_reg_off,
3578                 (void *)&cmd_write_reg_bit_field_bit1_pos,
3579                 (void *)&cmd_write_reg_bit_field_bit2_pos,
3580                 (void *)&cmd_write_reg_bit_field_value,
3581                 NULL,
3582         },
3583 };
3584
3585 /* *** WRITE PORT REGISTER BIT *** */
3586 struct cmd_write_reg_bit_result {
3587         cmdline_fixed_string_t write;
3588         cmdline_fixed_string_t regbit;
3589         uint8_t port_id;
3590         uint32_t reg_off;
3591         uint8_t bit_pos;
3592         uint8_t value;
3593 };
3594
3595 static void
3596 cmd_write_reg_bit_parsed(void *parsed_result,
3597                          __attribute__((unused)) struct cmdline *cl,
3598                          __attribute__((unused)) void *data)
3599 {
3600         struct cmd_write_reg_bit_result *res = parsed_result;
3601         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
3602 }
3603
3604 cmdline_parse_token_string_t cmd_write_reg_bit_write =
3605         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
3606                                  "write");
3607 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
3608         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
3609                                  regbit, "regbit");
3610 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
3611         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
3612 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
3613         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
3614 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
3615         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
3616 cmdline_parse_token_num_t cmd_write_reg_bit_value =
3617         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
3618
3619 cmdline_parse_inst_t cmd_write_reg_bit = {
3620         .f = cmd_write_reg_bit_parsed,
3621         .data = NULL,
3622         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
3623         .tokens = {
3624                 (void *)&cmd_write_reg_bit_write,
3625                 (void *)&cmd_write_reg_bit_regbit,
3626                 (void *)&cmd_write_reg_bit_port_id,
3627                 (void *)&cmd_write_reg_bit_reg_off,
3628                 (void *)&cmd_write_reg_bit_bit_pos,
3629                 (void *)&cmd_write_reg_bit_value,
3630                 NULL,
3631         },
3632 };
3633
3634 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
3635 struct cmd_read_rxd_txd_result {
3636         cmdline_fixed_string_t read;
3637         cmdline_fixed_string_t rxd_txd;
3638         uint8_t port_id;
3639         uint16_t queue_id;
3640         uint16_t desc_id;
3641 };
3642
3643 static void
3644 cmd_read_rxd_txd_parsed(void *parsed_result,
3645                         __attribute__((unused)) struct cmdline *cl,
3646                         __attribute__((unused)) void *data)
3647 {
3648         struct cmd_read_rxd_txd_result *res = parsed_result;
3649
3650         if (!strcmp(res->rxd_txd, "rxd"))
3651                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
3652         else if (!strcmp(res->rxd_txd, "txd"))
3653                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
3654 }
3655
3656 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
3657         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
3658 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
3659         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
3660                                  "rxd#txd");
3661 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
3662         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
3663 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
3664         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
3665 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
3666         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
3667
3668 cmdline_parse_inst_t cmd_read_rxd_txd = {
3669         .f = cmd_read_rxd_txd_parsed,
3670         .data = NULL,
3671         .help_str = "read rxd|txd port_id queue_id rxd_id",
3672         .tokens = {
3673                 (void *)&cmd_read_rxd_txd_read,
3674                 (void *)&cmd_read_rxd_txd_rxd_txd,
3675                 (void *)&cmd_read_rxd_txd_port_id,
3676                 (void *)&cmd_read_rxd_txd_queue_id,
3677                 (void *)&cmd_read_rxd_txd_desc_id,
3678                 NULL,
3679         },
3680 };
3681
3682 /* *** QUIT *** */
3683 struct cmd_quit_result {
3684         cmdline_fixed_string_t quit;
3685 };
3686
3687 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
3688                             struct cmdline *cl,
3689                             __attribute__((unused)) void *data)
3690 {
3691         pmd_test_exit();
3692         cmdline_quit(cl);
3693 }
3694
3695 cmdline_parse_token_string_t cmd_quit_quit =
3696         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
3697
3698 cmdline_parse_inst_t cmd_quit = {
3699         .f = cmd_quit_parsed,
3700         .data = NULL,
3701         .help_str = "exit application",
3702         .tokens = {
3703                 (void *)&cmd_quit_quit,
3704                 NULL,
3705         },
3706 };
3707
3708 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
3709 struct cmd_mac_addr_result {
3710         cmdline_fixed_string_t mac_addr_cmd;
3711         cmdline_fixed_string_t what;
3712         uint8_t port_num;
3713         struct ether_addr address;
3714 };
3715
3716 static void cmd_mac_addr_parsed(void *parsed_result,
3717                 __attribute__((unused)) struct cmdline *cl,
3718                 __attribute__((unused)) void *data)
3719 {
3720         struct cmd_mac_addr_result *res = parsed_result;
3721         int ret;
3722
3723         if (strcmp(res->what, "add") == 0)
3724                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
3725         else
3726                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
3727
3728         /* check the return value and print it if is < 0 */
3729         if(ret < 0)
3730                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
3731
3732 }
3733
3734 cmdline_parse_token_string_t cmd_mac_addr_cmd =
3735         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
3736                                 "mac_addr");
3737 cmdline_parse_token_string_t cmd_mac_addr_what =
3738         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
3739                                 "add#remove");
3740 cmdline_parse_token_num_t cmd_mac_addr_portnum =
3741                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
3742 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
3743                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
3744
3745 cmdline_parse_inst_t cmd_mac_addr = {
3746         .f = cmd_mac_addr_parsed,
3747         .data = (void *)0,
3748         .help_str = "mac_addr add|remove X <address>: "
3749                         "add/remove MAC address on port X",
3750         .tokens = {
3751                 (void *)&cmd_mac_addr_cmd,
3752                 (void *)&cmd_mac_addr_what,
3753                 (void *)&cmd_mac_addr_portnum,
3754                 (void *)&cmd_mac_addr_addr,
3755                 NULL,
3756         },
3757 };
3758
3759
3760 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
3761 struct cmd_set_qmap_result {
3762         cmdline_fixed_string_t set;
3763         cmdline_fixed_string_t qmap;
3764         cmdline_fixed_string_t what;
3765         uint8_t port_id;
3766         uint16_t queue_id;
3767         uint8_t map_value;
3768 };
3769
3770 static void
3771 cmd_set_qmap_parsed(void *parsed_result,
3772                        __attribute__((unused)) struct cmdline *cl,
3773                        __attribute__((unused)) void *data)
3774 {
3775         struct cmd_set_qmap_result *res = parsed_result;
3776         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
3777
3778         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
3779 }
3780
3781 cmdline_parse_token_string_t cmd_setqmap_set =
3782         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3783                                  set, "set");
3784 cmdline_parse_token_string_t cmd_setqmap_qmap =
3785         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3786                                  qmap, "stat_qmap");
3787 cmdline_parse_token_string_t cmd_setqmap_what =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
3789                                  what, "tx#rx");
3790 cmdline_parse_token_num_t cmd_setqmap_portid =
3791         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3792                               port_id, UINT8);
3793 cmdline_parse_token_num_t cmd_setqmap_queueid =
3794         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3795                               queue_id, UINT16);
3796 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
3797         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
3798                               map_value, UINT8);
3799
3800 cmdline_parse_inst_t cmd_set_qmap = {
3801         .f = cmd_set_qmap_parsed,
3802         .data = NULL,
3803         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
3804         .tokens = {
3805                 (void *)&cmd_setqmap_set,
3806                 (void *)&cmd_setqmap_qmap,
3807                 (void *)&cmd_setqmap_what,
3808                 (void *)&cmd_setqmap_portid,
3809                 (void *)&cmd_setqmap_queueid,
3810                 (void *)&cmd_setqmap_mapvalue,
3811                 NULL,
3812         },
3813 };
3814
3815 /* ******************************************************************************** */
3816
3817 /* list of instructions */
3818 cmdline_parse_ctx_t main_ctx[] = {
3819         (cmdline_parse_inst_t *)&cmd_help_brief,
3820         (cmdline_parse_inst_t *)&cmd_help_long,
3821         (cmdline_parse_inst_t *)&cmd_quit,
3822         (cmdline_parse_inst_t *)&cmd_showport,
3823         (cmdline_parse_inst_t *)&cmd_showportall,
3824         (cmdline_parse_inst_t *)&cmd_showcfg,
3825         (cmdline_parse_inst_t *)&cmd_start,
3826         (cmdline_parse_inst_t *)&cmd_start_tx_first,
3827         (cmdline_parse_inst_t *)&cmd_reset,
3828         (cmdline_parse_inst_t *)&cmd_set_numbers,
3829         (cmdline_parse_inst_t *)&cmd_set_txpkts,
3830         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
3831         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
3832         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
3833         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
3834         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
3835         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
3836         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
3837         (cmdline_parse_inst_t *)&cmd_vlan_offload,
3838         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
3839         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
3840         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
3841         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
3842         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
3843         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
3844         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
3845         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
3846         (cmdline_parse_inst_t *)&cmd_config_dcb,
3847         (cmdline_parse_inst_t *)&cmd_read_reg,
3848         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
3849         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
3850         (cmdline_parse_inst_t *)&cmd_write_reg,
3851         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
3852         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
3853         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
3854         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
3855         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
3856         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
3857         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
3858         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
3859         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
3860         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
3861         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
3862         (cmdline_parse_inst_t *)&cmd_stop,
3863         (cmdline_parse_inst_t *)&cmd_mac_addr,
3864         (cmdline_parse_inst_t *)&cmd_set_qmap,
3865         (cmdline_parse_inst_t *)&cmd_operate_port,
3866         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
3867         (cmdline_parse_inst_t *)&cmd_config_speed_all,
3868         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
3869         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
3870         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
3871         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
3872         (cmdline_parse_inst_t *)&cmd_config_rss,
3873         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
3874         (cmdline_parse_inst_t *)&cmd_showport_reta,
3875         (cmdline_parse_inst_t *)&cmd_config_burst,
3876         (cmdline_parse_inst_t *)&cmd_config_thresh,
3877         (cmdline_parse_inst_t *)&cmd_config_threshold,
3878         NULL,
3879 };
3880
3881 /* prompt function, called from main on MASTER lcore */
3882 void
3883 prompt(void)
3884 {
3885         struct cmdline *cl;
3886
3887         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
3888         if (cl == NULL) {
3889                 return;
3890         }
3891         cmdline_interact(cl);
3892         cmdline_stdin_exit(cl);
3893 }
3894
3895 static void
3896 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
3897 {
3898         if (id < nb_ports) {
3899                 /* check if need_reconfig has been set to 1 */
3900                 if (ports[id].need_reconfig == 0)
3901                         ports[id].need_reconfig = dev;
3902                 /* check if need_reconfig_queues has been set to 1 */
3903                 if (ports[id].need_reconfig_queues == 0)
3904                         ports[id].need_reconfig_queues = queue;
3905         } else {
3906                 portid_t pid;
3907
3908                 for (pid = 0; pid < nb_ports; pid++) {
3909                         /* check if need_reconfig has been set to 1 */
3910                         if (ports[pid].need_reconfig == 0)
3911                                 ports[pid].need_reconfig = dev;
3912                         /* check if need_reconfig_queues has been set to 1 */
3913                         if (ports[pid].need_reconfig_queues == 0)
3914                                 ports[pid].need_reconfig_queues = queue;
3915                 }
3916         }
3917 }