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