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