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