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