app/testpmd: add stats per queue
[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 /* *** HELP *** */
85 struct cmd_help_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
90                             struct cmdline *cl,
91                             __attribute__((unused)) void *data)
92 {
93         cmdline_printf(cl,
94                        "\n"
95                        "TEST PMD\n"
96                        "--------\n"
97                        "\n"
98                        "This commandline can be used to configure forwarding\n"
99                        "\n");
100         cmdline_printf(cl,
101                        "Display informations:\n"
102                        "---------------------\n"
103                        "- show port info|stats|fdir|stat_qmap X|all\n"
104                        "    Diplays information or stats or stats queue mapping on port X, or all\n"
105                        "- clear port stats X|all\n"
106                        "    Clear stats for port X, or all\n"
107                        "- show config rxtx|cores|fwd\n"
108                        "    Displays the given configuration\n"
109                        "- read reg port_id reg_off\n"
110                        "    Displays value of a port register\n"
111                        "- read regfield port_id reg_off bit_x bit_y\n"
112                        "    Displays value of a port register bit field\n"
113                        "- read regbit port_id reg_off bit_x\n"
114                        "    Displays value of a port register bit\n"
115                        "- read rxd port_id queue_id rxd_id\n"
116                        "    Displays a RX descriptor of a port RX queue\n"
117                        "- read txd port_id queue_id txd_id\n"
118                        "    Displays a TX descriptor of a port TX queue\n"
119                        "\n");
120         cmdline_printf(cl,
121                        "Configure:\n"
122                        "----------\n"
123                        "Modifications are taken into account once "
124                        "forwarding is restarted.\n"
125                        "- set default\n"
126                        "    Set forwarding to default configuration\n"
127                        "- set nbport|nbcore|burst|verbose X\n"
128                        "    Set number of ports, number of cores, number "
129                        "of packets per burst,\n    or verbose level to X\n"
130                        "- set txpkts x[,y]*\n"
131                        "    Set the length of each segment of TXONLY packets\n"
132                        "- set coremask|portmask X\n"
133                        "    Set the hexadecimal mask of forwarding cores / "
134                        "forwarding ports\n"
135                        "- set corelist|portlist x[,y]*\n"
136                        "    Set the list of forwarding cores / forwarding "
137                        "ports\n"
138                        "- rx_vlan add/rm vlan_id|all port_id\n"
139                        "    Add/remove vlan_id, or all identifiers, to/from "
140                        "the set of VLAN Identifiers\n    filtered by port_id\n"
141                        "- tx_vlan set vlan_id port_id\n"
142                        "    Enable hardware insertion of a VLAN header with "
143                        "the Tag Identifier vlan_id\n    in packets sent on"
144                        "port_id\n"
145                        "- tx_vlan reset port_id\n"
146                        "    Disable hardware insertion of a VLAN header in "
147                        "packets sent on port_id\n"
148                        "- tx_checksum set mask port_id\n"
149                        "    Enable hardware insertion of checksum offload with "
150                        "the 4-bit mask (0~0xf)\n    in packets sent on port_id\n"
151                        "    Please check the NIC datasheet for HW limits\n"
152                        "      bit 0 - insert ip checksum offload if set \n"
153                        "      bit 1 - insert udp checksum offload if set \n"
154                        "      bit 2 - insert tcp checksum offload if set\n"
155                        "      bit 3 - insert sctp checksum offload if set\n"
156 #ifdef RTE_LIBRTE_IEEE1588
157                        "- set fwd io|mac|rxonly|txonly|csum|ieee1588\n"
158                        "    Set IO, MAC, RXONLY, TXONLY, CSUM or IEEE1588 "
159                        "packet forwarding mode\n"
160 #else
161                        "- set fwd io|mac|rxonly|txonly|csum\n"
162                        "    Set IO, MAC, RXONLY, CSUM or TXONLY packet "
163                        "forwarding mode\n"
164 #endif
165                        "- mac_addr add|remove X <xx:xx:xx:xx:xx:xx>\n"
166                        "    Add/Remove the MAC address <xx:xx:xx:xx:xx:xx> on port X\n"
167                        "- set promisc|allmulti [all|X] on|off\n"
168                        "    Set/unset promisc|allmulti mode on port X, or all\n"
169                        "- set flow_ctrl rx on|off tx on|off high_water low_water "
170                                                 "pause_time send_xon port_id \n"
171                        "    Set the link flow control parameter on the port \n"
172                        "- write reg port_id reg_off value\n"
173                        "    Set value of a port register\n"
174                        "- write regfield port_id reg_off bit_x bit_y value\n"
175                        "    Set bit field value of a port register\n"
176                        "- write regbit port_id reg_off bit_x value\n"
177                        "    Set bit value of a port register\n"
178                        "- set stat_qmap tx|rx port_id queue_id qmapping\n"
179                        "    Set statistics mapping (qmapping 0..15) for tx|rx queue_id on port_id\n"
180                        "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2 on port 0 to mapping 5\n"
181                        "\n");
182         cmdline_printf(cl,
183                        "Control forwarding:\n"
184                        "-------------------\n"
185                        "- start\n"
186                        "    Start packet forwarding with current config\n"
187                        "- start tx_first\n"
188                        "    Start packet forwarding with current config"
189                        " after sending one burst\n    of packets\n"
190                        "- stop\n"
191                        "    Stop packet forwarding, and displays accumulated"
192                        " stats\n"
193                        "\n");
194         cmdline_printf(cl,
195                        "Flow director mode:\n"
196                        "-------------------\n"
197                        "- add_signature_filter port_id ip|udp|tcp|sctp src\n"
198                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
199                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
200                        "- upd_signature_filter port_id ip|udp|tcp|sctp src \n"
201                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
202                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
203                        "- rm_signature_filter port_id ip|udp|tcp|sctp src\n"
204                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
205                        "    flexbytes flexbytes_values vlan vlan_id\n"
206                        "- add_perfect_filter port_id ip|udp|tcp|sctp src\n"
207                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
208                        "    flexbytes flexbytes_values vlan vlan_id queue \n"
209                        "    queue_id soft soft_id\n"
210                        "- upd_perfect_filter port_id ip|udp|tcp|sctp src\n"
211                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
212                        "    flexbytes flexbytes_values vlan vlan_id queue queue_id\n"
213                        "- rm_perfect_filter port_id ip|udp|tcp|sctp src\n"
214                        "    ip_src_address port_src dst ip_dst_address port_dst\n"
215                        "    flexbytes flexbytes_values vlan vlan_id soft soft_id\n"
216                        "- set_masks_filter port_id only_ip_flow 0|1 src_mask\n"
217                        "    ip_src_mask  port_src_mask dst_mask ip_dst_mask\n"
218                        "    port_dst_mask flexbytes 0|1 vlan_id 0|1 vlan_prio 0|1\n"
219                        "\n");
220         cmdline_printf(cl,
221                        "Misc:\n"
222                        "-----\n"
223                        "- quit\n"
224                        "    Quit to prompt in linux, and reboot on baremetal\n"
225                        "\n");
226 }
227
228 cmdline_parse_token_string_t cmd_help_help =
229         TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
230
231 cmdline_parse_inst_t cmd_help = {
232         .f = cmd_help_parsed,
233         .data = NULL,
234         .help_str = "show help",
235         .tokens = {
236                 (void *)&cmd_help_help,
237                 NULL,
238         },
239 };
240
241 /* *** stop *** */
242 struct cmd_stop_result {
243         cmdline_fixed_string_t stop;
244 };
245
246 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
247                             __attribute__((unused)) struct cmdline *cl,
248                             __attribute__((unused)) void *data)
249 {
250         stop_packet_forwarding();
251 }
252
253 cmdline_parse_token_string_t cmd_stop_stop =
254         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
255
256 cmdline_parse_inst_t cmd_stop = {
257         .f = cmd_stop_parsed,
258         .data = NULL,
259         .help_str = "stop - stop packet forwarding",
260         .tokens = {
261                 (void *)&cmd_stop_stop,
262                 NULL,
263         },
264 };
265
266 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
267
268 static unsigned int
269 parse_item_list(char* str, const char* item_name, unsigned int max_items,
270                 unsigned int *parsed_items, int check_unique_values)
271 {
272         unsigned int nb_item;
273         unsigned int value;
274         unsigned int i;
275         unsigned int j;
276         int value_ok;
277         char c;
278
279         /*
280          * First parse all items in the list and store their value.
281          */
282         value = 0;
283         nb_item = 0;
284         value_ok = 0;
285         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
286                 c = str[i];
287                 if ((c >= '0') && (c <= '9')) {
288                         value = (unsigned int) (value * 10 + (c - '0'));
289                         value_ok = 1;
290                         continue;
291                 }
292                 if (c != ',') {
293                         printf("character %c is not a decimal digit\n", c);
294                         return (0);
295                 }
296                 if (! value_ok) {
297                         printf("No valid value before comma\n");
298                         return (0);
299                 }
300                 if (nb_item < max_items) {
301                         parsed_items[nb_item] = value;
302                         value_ok = 0;
303                         value = 0;
304                 }
305                 nb_item++;
306         }
307         if (nb_item >= max_items) {
308                 printf("Number of %s = %u > %u (maximum items)\n",
309                        item_name, nb_item + 1, max_items);
310                 return (0);
311         }
312         parsed_items[nb_item++] = value;
313         if (! check_unique_values)
314                 return (nb_item);
315
316         /*
317          * Then, check that all values in the list are differents.
318          * No optimization here...
319          */
320         for (i = 0; i < nb_item; i++) {
321                 for (j = i + 1; j < nb_item; j++) {
322                         if (parsed_items[j] == parsed_items[i]) {
323                                 printf("duplicated %s %u at index %u and %u\n",
324                                        item_name, parsed_items[i], i, j);
325                                 return (0);
326                         }
327                 }
328         }
329         return (nb_item);
330 }
331
332 struct cmd_set_list_result {
333         cmdline_fixed_string_t cmd_keyword;
334         cmdline_fixed_string_t list_name;
335         cmdline_fixed_string_t list_of_items;
336 };
337
338 static void cmd_set_list_parsed(void *parsed_result,
339                                 __attribute__((unused)) struct cmdline *cl,
340                                 __attribute__((unused)) void *data)
341 {
342         struct cmd_set_list_result *res;
343         union {
344                 unsigned int lcorelist[RTE_MAX_LCORE];
345                 unsigned int portlist[RTE_MAX_ETHPORTS];
346         } parsed_items;
347         unsigned int nb_item;
348
349         res = parsed_result;
350         if (!strcmp(res->list_name, "corelist")) {
351                 nb_item = parse_item_list(res->list_of_items, "core",
352                                           RTE_MAX_LCORE,
353                                           parsed_items.lcorelist, 1);
354                 if (nb_item > 0)
355                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
356                 return;
357         }
358         if (!strcmp(res->list_name, "portlist")) {
359                 nb_item = parse_item_list(res->list_of_items, "port",
360                                           RTE_MAX_ETHPORTS,
361                                           parsed_items.portlist, 1);
362                 if (nb_item > 0)
363                         set_fwd_ports_list(parsed_items.portlist, nb_item);
364         }
365 }
366
367 cmdline_parse_token_string_t cmd_set_list_keyword =
368         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
369                                  "set");
370 cmdline_parse_token_string_t cmd_set_list_name =
371         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
372                                  "corelist#portlist");
373 cmdline_parse_token_string_t cmd_set_list_of_items =
374         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
375                                  NULL);
376
377 cmdline_parse_inst_t cmd_set_fwd_list = {
378         .f = cmd_set_list_parsed,
379         .data = NULL,
380         .help_str = "set corelist|portlist x[,y]*",
381         .tokens = {
382                 (void *)&cmd_set_list_keyword,
383                 (void *)&cmd_set_list_name,
384                 (void *)&cmd_set_list_of_items,
385                 NULL,
386         },
387 };
388
389 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
390
391 struct cmd_setmask_result {
392         cmdline_fixed_string_t set;
393         cmdline_fixed_string_t mask;
394         uint64_t hexavalue;
395 };
396
397 static void cmd_set_mask_parsed(void *parsed_result,
398                                 __attribute__((unused)) struct cmdline *cl,
399                                 __attribute__((unused)) void *data)
400 {
401         struct cmd_setmask_result *res = parsed_result;
402
403         if (!strcmp(res->mask, "coremask"))
404                 set_fwd_lcores_mask(res->hexavalue);
405         else if (!strcmp(res->mask, "portmask"))
406                 set_fwd_ports_mask(res->hexavalue);
407 }
408
409 cmdline_parse_token_string_t cmd_setmask_set =
410         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
411 cmdline_parse_token_string_t cmd_setmask_mask =
412         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
413                                  "coremask#portmask");
414 cmdline_parse_token_num_t cmd_setmask_value =
415         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
416
417 cmdline_parse_inst_t cmd_set_fwd_mask = {
418         .f = cmd_set_mask_parsed,
419         .data = NULL,
420         .help_str = "set coremask|portmask hexadecimal value",
421         .tokens = {
422                 (void *)&cmd_setmask_set,
423                 (void *)&cmd_setmask_mask,
424                 (void *)&cmd_setmask_value,
425                 NULL,
426         },
427 };
428
429 /*
430  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
431  */
432 struct cmd_set_result {
433         cmdline_fixed_string_t set;
434         cmdline_fixed_string_t what;
435         uint16_t value;
436 };
437
438 static void cmd_set_parsed(void *parsed_result,
439                            __attribute__((unused)) struct cmdline *cl,
440                            __attribute__((unused)) void *data)
441 {
442         struct cmd_set_result *res = parsed_result;
443         if (!strcmp(res->what, "nbport"))
444                 set_fwd_ports_number(res->value);
445         else if (!strcmp(res->what, "nbcore"))
446                 set_fwd_lcores_number(res->value);
447         else if (!strcmp(res->what, "burst"))
448                 set_nb_pkt_per_burst(res->value);
449         else if (!strcmp(res->what, "verbose"))
450                 set_verbose_level(res->value);
451 }
452
453 cmdline_parse_token_string_t cmd_set_set =
454         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
455 cmdline_parse_token_string_t cmd_set_what =
456         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
457                                  "nbport#nbcore#burst#verbose");
458 cmdline_parse_token_num_t cmd_set_value =
459         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
460
461 cmdline_parse_inst_t cmd_set_numbers = {
462         .f = cmd_set_parsed,
463         .data = NULL,
464         .help_str = "set nbport|nbcore|burst|verbose value",
465         .tokens = {
466                 (void *)&cmd_set_set,
467                 (void *)&cmd_set_what,
468                 (void *)&cmd_set_value,
469                 NULL,
470         },
471 };
472
473 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
474
475 struct cmd_set_txpkts_result {
476         cmdline_fixed_string_t cmd_keyword;
477         cmdline_fixed_string_t txpkts;
478         cmdline_fixed_string_t seg_lengths;
479 };
480
481 static void
482 cmd_set_txpkts_parsed(void *parsed_result,
483                       __attribute__((unused)) struct cmdline *cl,
484                       __attribute__((unused)) void *data)
485 {
486         struct cmd_set_txpkts_result *res;
487         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
488         unsigned int nb_segs;
489
490         res = parsed_result;
491         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
492                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
493         if (nb_segs > 0)
494                 set_tx_pkt_segments(seg_lengths, nb_segs);
495 }
496
497 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
498         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
499                                  cmd_keyword, "set");
500 cmdline_parse_token_string_t cmd_set_txpkts_name =
501         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
502                                  txpkts, "txpkts");
503 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
504         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
505                                  seg_lengths, NULL);
506
507 cmdline_parse_inst_t cmd_set_txpkts = {
508         .f = cmd_set_txpkts_parsed,
509         .data = NULL,
510         .help_str = "set txpkts x[,y]*",
511         .tokens = {
512                 (void *)&cmd_set_txpkts_keyword,
513                 (void *)&cmd_set_txpkts_name,
514                 (void *)&cmd_set_txpkts_lengths,
515                 NULL,
516         },
517 };
518
519 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
520 struct cmd_rx_vlan_filter_all_result {
521         cmdline_fixed_string_t rx_vlan;
522         cmdline_fixed_string_t what;
523         cmdline_fixed_string_t all;
524         uint8_t port_id;
525 };
526
527 static void
528 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
529                               __attribute__((unused)) struct cmdline *cl,
530                               __attribute__((unused)) void *data)
531 {
532         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
533
534         if (!strcmp(res->what, "add"))
535                 rx_vlan_all_filter_set(res->port_id, 1);
536         else
537                 rx_vlan_all_filter_set(res->port_id, 0);
538 }
539
540 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
541         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
542                                  rx_vlan, "rx_vlan");
543 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
544         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
545                                  what, "add#rm");
546 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
547         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
548                                  all, "all");
549 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
550         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
551                               port_id, UINT8);
552
553 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
554         .f = cmd_rx_vlan_filter_all_parsed,
555         .data = NULL,
556         .help_str = "add/remove all identifiers to/from the set of VLAN "
557         "Identifiers filtered by a port",
558         .tokens = {
559                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
560                 (void *)&cmd_rx_vlan_filter_all_what,
561                 (void *)&cmd_rx_vlan_filter_all_all,
562                 (void *)&cmd_rx_vlan_filter_all_portid,
563                 NULL,
564         },
565 };
566
567 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
568 struct cmd_rx_vlan_filter_result {
569         cmdline_fixed_string_t rx_vlan;
570         cmdline_fixed_string_t what;
571         uint16_t vlan_id;
572         uint8_t port_id;
573 };
574
575 static void
576 cmd_rx_vlan_filter_parsed(void *parsed_result,
577                           __attribute__((unused)) struct cmdline *cl,
578                           __attribute__((unused)) void *data)
579 {
580         struct cmd_rx_vlan_filter_result *res = parsed_result;
581
582         if (!strcmp(res->what, "add"))
583                 rx_vlan_filter_set(res->port_id, res->vlan_id, 1);
584         else
585                 rx_vlan_filter_set(res->port_id, res->vlan_id, 0);
586 }
587
588 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
589         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
590                                  rx_vlan, "rx_vlan");
591 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
592         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
593                                  what, "add#rm");
594 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
595         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
596                               vlan_id, UINT16);
597 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
598         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
599                               port_id, UINT8);
600
601 cmdline_parse_inst_t cmd_rx_vlan_filter = {
602         .f = cmd_rx_vlan_filter_parsed,
603         .data = NULL,
604         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
605         "Identifiers filtered by a port",
606         .tokens = {
607                 (void *)&cmd_rx_vlan_filter_rx_vlan,
608                 (void *)&cmd_rx_vlan_filter_what,
609                 (void *)&cmd_rx_vlan_filter_vlanid,
610                 (void *)&cmd_rx_vlan_filter_portid,
611                 NULL,
612         },
613 };
614
615 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
616 struct cmd_tx_vlan_set_result {
617         cmdline_fixed_string_t tx_vlan;
618         cmdline_fixed_string_t set;
619         uint16_t vlan_id;
620         uint8_t port_id;
621 };
622
623 static void
624 cmd_tx_vlan_set_parsed(void *parsed_result,
625                        __attribute__((unused)) struct cmdline *cl,
626                        __attribute__((unused)) void *data)
627 {
628         struct cmd_tx_vlan_set_result *res = parsed_result;
629
630         tx_vlan_set(res->port_id, res->vlan_id);
631 }
632
633 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
634         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
635                                  tx_vlan, "tx_vlan");
636 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
637         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
638                                  set, "set");
639 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
640         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
641                               vlan_id, UINT16);
642 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
643         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
644                               port_id, UINT8);
645
646 cmdline_parse_inst_t cmd_tx_vlan_set = {
647         .f = cmd_tx_vlan_set_parsed,
648         .data = NULL,
649         .help_str = "enable hardware insertion of a VLAN header with a given "
650         "TAG Identifier in packets sent on a port",
651         .tokens = {
652                 (void *)&cmd_tx_vlan_set_tx_vlan,
653                 (void *)&cmd_tx_vlan_set_set,
654                 (void *)&cmd_tx_vlan_set_vlanid,
655                 (void *)&cmd_tx_vlan_set_portid,
656                 NULL,
657         },
658 };
659
660 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
661 struct cmd_tx_vlan_reset_result {
662         cmdline_fixed_string_t tx_vlan;
663         cmdline_fixed_string_t reset;
664         uint8_t port_id;
665 };
666
667 static void
668 cmd_tx_vlan_reset_parsed(void *parsed_result,
669                          __attribute__((unused)) struct cmdline *cl,
670                          __attribute__((unused)) void *data)
671 {
672         struct cmd_tx_vlan_reset_result *res = parsed_result;
673
674         tx_vlan_reset(res->port_id);
675 }
676
677 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
678         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
679                                  tx_vlan, "tx_vlan");
680 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
681         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
682                                  reset, "reset");
683 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
684         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
685                               port_id, UINT8);
686
687 cmdline_parse_inst_t cmd_tx_vlan_reset = {
688         .f = cmd_tx_vlan_reset_parsed,
689         .data = NULL,
690         .help_str = "disable hardware insertion of a VLAN header in packets "
691         "sent on a port",
692         .tokens = {
693                 (void *)&cmd_tx_vlan_reset_tx_vlan,
694                 (void *)&cmd_tx_vlan_reset_reset,
695                 (void *)&cmd_tx_vlan_reset_portid,
696                 NULL,
697         },
698 };
699
700
701 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
702 struct cmd_tx_cksum_set_result {
703         cmdline_fixed_string_t tx_cksum;
704         cmdline_fixed_string_t set;
705         uint8_t cksum_mask;
706         uint8_t port_id;
707 };
708
709 static void
710 cmd_tx_cksum_set_parsed(void *parsed_result,
711                        __attribute__((unused)) struct cmdline *cl,
712                        __attribute__((unused)) void *data)
713 {
714         struct cmd_tx_cksum_set_result *res = parsed_result;
715
716         tx_cksum_set(res->port_id, res->cksum_mask);
717 }
718
719 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
720         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
721                                 tx_cksum, "tx_checksum");
722 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
723         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
724                                 set, "set");
725 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
726         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
727                                 cksum_mask, UINT8);
728 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
729         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
730                                 port_id, UINT8);
731
732 cmdline_parse_inst_t cmd_tx_cksum_set = {
733         .f = cmd_tx_cksum_set_parsed,
734         .data = NULL,
735         .help_str = "enable hardware insertion of L3/L4checksum with a given "
736         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
737         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
738         .tokens = {
739                 (void *)&cmd_tx_cksum_set_tx_cksum,
740                 (void *)&cmd_tx_cksum_set_set,
741                 (void *)&cmd_tx_cksum_set_cksum_mask,
742                 (void *)&cmd_tx_cksum_set_portid,
743                 NULL,
744         },
745 };
746
747 /* *** SET FORWARDING MODE *** */
748 struct cmd_set_fwd_mode_result {
749         cmdline_fixed_string_t set;
750         cmdline_fixed_string_t fwd;
751         cmdline_fixed_string_t mode;
752 };
753
754 static void cmd_set_fwd_mode_parsed(void *parsed_result,
755                                     __attribute__((unused)) struct cmdline *cl,
756                                     __attribute__((unused)) void *data)
757 {
758         struct cmd_set_fwd_mode_result *res = parsed_result;
759
760         set_pkt_forwarding_mode(res->mode);
761 }
762
763 cmdline_parse_token_string_t cmd_setfwd_set =
764         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
765 cmdline_parse_token_string_t cmd_setfwd_fwd =
766         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
767 cmdline_parse_token_string_t cmd_setfwd_mode =
768         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
769 #ifdef RTE_LIBRTE_IEEE1588
770                                  "io#mac#rxonly#txonly#csum#ieee1588");
771 #else
772                                  "io#mac#rxonly#txonly#csum");
773 #endif
774
775 cmdline_parse_inst_t cmd_set_fwd_mode = {
776         .f = cmd_set_fwd_mode_parsed,
777         .data = NULL,
778 #ifdef RTE_LIBRTE_IEEE1588
779         .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
780         " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
781 #else
782         .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
783         " RXONLY, CSUM or TXONLY packet forwarding mode",
784 #endif
785         .tokens = {
786                 (void *)&cmd_setfwd_set,
787                 (void *)&cmd_setfwd_fwd,
788                 (void *)&cmd_setfwd_mode,
789                 NULL,
790         },
791 };
792
793 /* *** SET PROMISC MODE *** */
794 struct cmd_set_promisc_mode_result {
795         cmdline_fixed_string_t set;
796         cmdline_fixed_string_t promisc;
797         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
798         uint8_t port_num;                /* valid if "allports" argument == 0 */
799         cmdline_fixed_string_t mode;
800 };
801
802 static void cmd_set_promisc_mode_parsed(void *parsed_result,
803                                         __attribute__((unused)) struct cmdline *cl,
804                                         void *allports)
805 {
806         struct cmd_set_promisc_mode_result *res = parsed_result;
807         int enable;
808         portid_t i;
809
810         if (!strcmp(res->mode, "on"))
811                 enable = 1;
812         else
813                 enable = 0;
814
815         /* all ports */
816         if (allports) {
817                 for (i = 0; i < nb_ports; i++) {
818                         if (enable)
819                                 rte_eth_promiscuous_enable(i);
820                         else
821                                 rte_eth_promiscuous_disable(i);
822                 }
823         }
824         else {
825                 if (enable)
826                         rte_eth_promiscuous_enable(res->port_num);
827                 else
828                         rte_eth_promiscuous_disable(res->port_num);
829         }
830 }
831
832 cmdline_parse_token_string_t cmd_setpromisc_set =
833         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
834 cmdline_parse_token_string_t cmd_setpromisc_promisc =
835         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
836                                  "promisc");
837 cmdline_parse_token_string_t cmd_setpromisc_portall =
838         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
839                                  "all");
840 cmdline_parse_token_num_t cmd_setpromisc_portnum =
841         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
842                               UINT8);
843 cmdline_parse_token_string_t cmd_setpromisc_mode =
844         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
845                                  "on#off");
846
847 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
848         .f = cmd_set_promisc_mode_parsed,
849         .data = (void *)1,
850         .help_str = "set promisc all on|off: set promisc mode for all ports",
851         .tokens = {
852                 (void *)&cmd_setpromisc_set,
853                 (void *)&cmd_setpromisc_promisc,
854                 (void *)&cmd_setpromisc_portall,
855                 (void *)&cmd_setpromisc_mode,
856                 NULL,
857         },
858 };
859
860 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
861         .f = cmd_set_promisc_mode_parsed,
862         .data = (void *)0,
863         .help_str = "set promisc X on|off: set promisc mode on port X",
864         .tokens = {
865                 (void *)&cmd_setpromisc_set,
866                 (void *)&cmd_setpromisc_promisc,
867                 (void *)&cmd_setpromisc_portnum,
868                 (void *)&cmd_setpromisc_mode,
869                 NULL,
870         },
871 };
872
873 /* *** SET ALLMULTI MODE *** */
874 struct cmd_set_allmulti_mode_result {
875         cmdline_fixed_string_t set;
876         cmdline_fixed_string_t allmulti;
877         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
878         uint8_t port_num;                /* valid if "allports" argument == 0 */
879         cmdline_fixed_string_t mode;
880 };
881
882 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
883                                         __attribute__((unused)) struct cmdline *cl,
884                                         void *allports)
885 {
886         struct cmd_set_allmulti_mode_result *res = parsed_result;
887         int enable;
888         portid_t i;
889
890         if (!strcmp(res->mode, "on"))
891                 enable = 1;
892         else
893                 enable = 0;
894
895         /* all ports */
896         if (allports) {
897                 for (i = 0; i < nb_ports; i++) {
898                         if (enable)
899                                 rte_eth_allmulticast_enable(i);
900                         else
901                                 rte_eth_allmulticast_disable(i);
902                 }
903         }
904         else {
905                 if (enable)
906                         rte_eth_allmulticast_enable(res->port_num);
907                 else
908                         rte_eth_allmulticast_disable(res->port_num);
909         }
910 }
911
912 cmdline_parse_token_string_t cmd_setallmulti_set =
913         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
914 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
915         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
916                                  "allmulti");
917 cmdline_parse_token_string_t cmd_setallmulti_portall =
918         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
919                                  "all");
920 cmdline_parse_token_num_t cmd_setallmulti_portnum =
921         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
922                               UINT8);
923 cmdline_parse_token_string_t cmd_setallmulti_mode =
924         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
925                                  "on#off");
926
927 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
928         .f = cmd_set_allmulti_mode_parsed,
929         .data = (void *)1,
930         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
931         .tokens = {
932                 (void *)&cmd_setallmulti_set,
933                 (void *)&cmd_setallmulti_allmulti,
934                 (void *)&cmd_setallmulti_portall,
935                 (void *)&cmd_setallmulti_mode,
936                 NULL,
937         },
938 };
939
940 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
941         .f = cmd_set_allmulti_mode_parsed,
942         .data = (void *)0,
943         .help_str = "set allmulti X on|off: set allmulti mode on port X",
944         .tokens = {
945                 (void *)&cmd_setallmulti_set,
946                 (void *)&cmd_setallmulti_allmulti,
947                 (void *)&cmd_setallmulti_portnum,
948                 (void *)&cmd_setallmulti_mode,
949                 NULL,
950         },
951 };
952
953 /* *** ADD/REMOVE A PKT FILTER *** */
954 struct cmd_pkt_filter_result {
955         cmdline_fixed_string_t pkt_filter;
956         uint8_t  port_id;
957         cmdline_fixed_string_t protocol;
958         cmdline_fixed_string_t src;
959         cmdline_ipaddr_t ip_src;
960         uint16_t port_src;
961         cmdline_fixed_string_t dst;
962         cmdline_ipaddr_t ip_dst;
963         uint16_t port_dst;
964         cmdline_fixed_string_t flexbytes;
965         uint16_t flexbytes_value;
966         cmdline_fixed_string_t vlan;
967         uint16_t  vlan_id;
968         cmdline_fixed_string_t queue;
969         int8_t  queue_id;
970         cmdline_fixed_string_t soft;
971         uint8_t  soft_id;
972 };
973
974 static void
975 cmd_pkt_filter_parsed(void *parsed_result,
976                           __attribute__((unused)) struct cmdline *cl,
977                           __attribute__((unused)) void *data)
978 {
979         struct rte_fdir_filter fdir_filter;
980         struct cmd_pkt_filter_result *res = parsed_result;
981
982         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
983
984         if (res->ip_src.family == AF_INET)
985                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
986         else
987                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
988                        &(res->ip_src.addr.ipv6),
989                        sizeof(struct in6_addr));
990
991         if (res->ip_dst.family == AF_INET)
992                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
993         else
994                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
995                        &(res->ip_dst.addr.ipv6),
996                        sizeof(struct in6_addr));
997
998         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
999         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
1000
1001         if (!strcmp(res->protocol, "udp"))
1002                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
1003         else if (!strcmp(res->protocol, "tcp"))
1004                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
1005         else if (!strcmp(res->protocol, "sctp"))
1006                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
1007         else /* default only IP */
1008                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
1009
1010         if (res->ip_dst.family == AF_INET6)
1011                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
1012         else
1013                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
1014
1015         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
1016         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
1017
1018         if (!strcmp(res->pkt_filter, "add_signature_filter"))
1019                 fdir_add_signature_filter(res->port_id, res->queue_id,
1020                                           &fdir_filter);
1021         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
1022                 fdir_update_signature_filter(res->port_id, res->queue_id,
1023                                              &fdir_filter);
1024         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
1025                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
1026         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
1027                 fdir_add_perfect_filter(res->port_id, res->soft_id,
1028                                         res->queue_id,
1029                                         (uint8_t) (res->queue_id < 0),
1030                                         &fdir_filter);
1031         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
1032                 fdir_update_perfect_filter(res->port_id, res->soft_id,
1033                                            res->queue_id,
1034                                            (uint8_t) (res->queue_id < 0),
1035                                            &fdir_filter);
1036         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
1037                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
1038                                            &fdir_filter);
1039
1040 }
1041
1042
1043 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
1044         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1045                               port_id, UINT8);
1046 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
1047         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1048                                  protocol, "ip#tcp#udp#sctp");
1049 cmdline_parse_token_string_t cmd_pkt_filter_src =
1050         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1051                                  src, "src");
1052 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
1053         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1054                                  ip_src);
1055 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
1056         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1057                               port_src, UINT16);
1058 cmdline_parse_token_string_t cmd_pkt_filter_dst =
1059         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1060                                  dst, "dst");
1061 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
1062         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
1063                                  ip_dst);
1064 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
1065         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1066                               port_dst, UINT16);
1067 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
1068         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1069                                  flexbytes, "flexbytes");
1070 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
1071         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1072                               flexbytes_value, UINT16);
1073 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
1074         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1075                                  vlan, "vlan");
1076 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
1077         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1078                               vlan_id, UINT16);
1079 cmdline_parse_token_string_t cmd_pkt_filter_queue =
1080         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1081                                  queue, "queue");
1082 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
1083         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1084                               queue_id, INT8);
1085 cmdline_parse_token_string_t cmd_pkt_filter_soft =
1086         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1087                                  soft, "soft");
1088 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
1089         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
1090                               soft_id, UINT16);
1091
1092
1093 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
1094         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1095                                  pkt_filter, "add_signature_filter");
1096 cmdline_parse_inst_t cmd_add_signature_filter = {
1097         .f = cmd_pkt_filter_parsed,
1098         .data = NULL,
1099         .help_str = "add a signature filter",
1100         .tokens = {
1101                 (void *)&cmd_pkt_filter_add_signature_filter,
1102                 (void *)&cmd_pkt_filter_port_id,
1103                 (void *)&cmd_pkt_filter_protocol,
1104                 (void *)&cmd_pkt_filter_src,
1105                 (void *)&cmd_pkt_filter_ip_src,
1106                 (void *)&cmd_pkt_filter_port_src,
1107                 (void *)&cmd_pkt_filter_dst,
1108                 (void *)&cmd_pkt_filter_ip_dst,
1109                 (void *)&cmd_pkt_filter_port_dst,
1110                 (void *)&cmd_pkt_filter_flexbytes,
1111                 (void *)&cmd_pkt_filter_flexbytes_value,
1112                 (void *)&cmd_pkt_filter_vlan,
1113                 (void *)&cmd_pkt_filter_vlan_id,
1114                 (void *)&cmd_pkt_filter_queue,
1115                 (void *)&cmd_pkt_filter_queue_id,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
1122         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1123                                  pkt_filter, "upd_signature_filter");
1124 cmdline_parse_inst_t cmd_upd_signature_filter = {
1125         .f = cmd_pkt_filter_parsed,
1126         .data = NULL,
1127         .help_str = "update a signature filter",
1128         .tokens = {
1129                 (void *)&cmd_pkt_filter_upd_signature_filter,
1130                 (void *)&cmd_pkt_filter_port_id,
1131                 (void *)&cmd_pkt_filter_protocol,
1132                 (void *)&cmd_pkt_filter_src,
1133                 (void *)&cmd_pkt_filter_ip_src,
1134                 (void *)&cmd_pkt_filter_port_src,
1135                 (void *)&cmd_pkt_filter_dst,
1136                 (void *)&cmd_pkt_filter_ip_dst,
1137                 (void *)&cmd_pkt_filter_port_dst,
1138                 (void *)&cmd_pkt_filter_flexbytes,
1139                 (void *)&cmd_pkt_filter_flexbytes_value,
1140                 (void *)&cmd_pkt_filter_vlan,
1141                 (void *)&cmd_pkt_filter_vlan_id,
1142                 (void *)&cmd_pkt_filter_queue,
1143                 (void *)&cmd_pkt_filter_queue_id,
1144                 NULL,
1145         },
1146 };
1147
1148
1149 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
1150         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1151                                  pkt_filter, "rm_signature_filter");
1152 cmdline_parse_inst_t cmd_rm_signature_filter = {
1153         .f = cmd_pkt_filter_parsed,
1154         .data = NULL,
1155         .help_str = "remove a signature filter",
1156         .tokens = {
1157                 (void *)&cmd_pkt_filter_rm_signature_filter,
1158                 (void *)&cmd_pkt_filter_port_id,
1159                 (void *)&cmd_pkt_filter_protocol,
1160                 (void *)&cmd_pkt_filter_src,
1161                 (void *)&cmd_pkt_filter_ip_src,
1162                 (void *)&cmd_pkt_filter_port_src,
1163                 (void *)&cmd_pkt_filter_dst,
1164                 (void *)&cmd_pkt_filter_ip_dst,
1165                 (void *)&cmd_pkt_filter_port_dst,
1166                 (void *)&cmd_pkt_filter_flexbytes,
1167                 (void *)&cmd_pkt_filter_flexbytes_value,
1168                 (void *)&cmd_pkt_filter_vlan,
1169                 (void *)&cmd_pkt_filter_vlan_id,
1170                 NULL
1171                 },
1172 };
1173
1174
1175 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
1176         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1177                                  pkt_filter, "add_perfect_filter");
1178 cmdline_parse_inst_t cmd_add_perfect_filter = {
1179         .f = cmd_pkt_filter_parsed,
1180         .data = NULL,
1181         .help_str = "add a perfect filter",
1182         .tokens = {
1183                 (void *)&cmd_pkt_filter_add_perfect_filter,
1184                 (void *)&cmd_pkt_filter_port_id,
1185                 (void *)&cmd_pkt_filter_protocol,
1186                 (void *)&cmd_pkt_filter_src,
1187                 (void *)&cmd_pkt_filter_ip_src,
1188                 (void *)&cmd_pkt_filter_port_src,
1189                 (void *)&cmd_pkt_filter_dst,
1190                 (void *)&cmd_pkt_filter_ip_dst,
1191                 (void *)&cmd_pkt_filter_port_dst,
1192                 (void *)&cmd_pkt_filter_flexbytes,
1193                 (void *)&cmd_pkt_filter_flexbytes_value,
1194                 (void *)&cmd_pkt_filter_vlan,
1195                 (void *)&cmd_pkt_filter_vlan_id,
1196                 (void *)&cmd_pkt_filter_queue,
1197                 (void *)&cmd_pkt_filter_queue_id,
1198                 (void *)&cmd_pkt_filter_soft,
1199                 (void *)&cmd_pkt_filter_soft_id,
1200                 NULL,
1201         },
1202 };
1203
1204
1205 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
1206         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1207                                  pkt_filter, "upd_perfect_filter");
1208 cmdline_parse_inst_t cmd_upd_perfect_filter = {
1209         .f = cmd_pkt_filter_parsed,
1210         .data = NULL,
1211         .help_str = "update a perfect filter",
1212         .tokens = {
1213                 (void *)&cmd_pkt_filter_upd_perfect_filter,
1214                 (void *)&cmd_pkt_filter_port_id,
1215                 (void *)&cmd_pkt_filter_protocol,
1216                 (void *)&cmd_pkt_filter_src,
1217                 (void *)&cmd_pkt_filter_ip_src,
1218                 (void *)&cmd_pkt_filter_port_src,
1219                 (void *)&cmd_pkt_filter_dst,
1220                 (void *)&cmd_pkt_filter_ip_dst,
1221                 (void *)&cmd_pkt_filter_port_dst,
1222                 (void *)&cmd_pkt_filter_flexbytes,
1223                 (void *)&cmd_pkt_filter_flexbytes_value,
1224                 (void *)&cmd_pkt_filter_vlan,
1225                 (void *)&cmd_pkt_filter_vlan_id,
1226                 (void *)&cmd_pkt_filter_queue,
1227                 (void *)&cmd_pkt_filter_queue_id,
1228                 (void *)&cmd_pkt_filter_soft,
1229                 (void *)&cmd_pkt_filter_soft_id,
1230                 NULL,
1231         },
1232 };
1233
1234
1235 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
1236         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
1237                                  pkt_filter, "rm_perfect_filter");
1238 cmdline_parse_inst_t cmd_rm_perfect_filter = {
1239         .f = cmd_pkt_filter_parsed,
1240         .data = NULL,
1241         .help_str = "remove a perfect filter",
1242         .tokens = {
1243                 (void *)&cmd_pkt_filter_rm_perfect_filter,
1244                 (void *)&cmd_pkt_filter_port_id,
1245                 (void *)&cmd_pkt_filter_protocol,
1246                 (void *)&cmd_pkt_filter_src,
1247                 (void *)&cmd_pkt_filter_ip_src,
1248                 (void *)&cmd_pkt_filter_port_src,
1249                 (void *)&cmd_pkt_filter_dst,
1250                 (void *)&cmd_pkt_filter_ip_dst,
1251                 (void *)&cmd_pkt_filter_port_dst,
1252                 (void *)&cmd_pkt_filter_flexbytes,
1253                 (void *)&cmd_pkt_filter_flexbytes_value,
1254                 (void *)&cmd_pkt_filter_vlan,
1255                 (void *)&cmd_pkt_filter_vlan_id,
1256                 (void *)&cmd_pkt_filter_soft,
1257                 (void *)&cmd_pkt_filter_soft_id,
1258                 NULL,
1259         },
1260 };
1261
1262 /* *** SETUP MASKS FILTER *** */
1263 struct cmd_pkt_filter_masks_result {
1264         cmdline_fixed_string_t filter_mask;
1265         uint8_t  port_id;
1266         cmdline_fixed_string_t src_mask;
1267         uint32_t ip_src_mask;
1268         uint16_t port_src_mask;
1269         cmdline_fixed_string_t dst_mask;
1270         uint32_t ip_dst_mask;
1271         uint16_t port_dst_mask;
1272         cmdline_fixed_string_t flexbytes;
1273         uint8_t flexbytes_value;
1274         cmdline_fixed_string_t vlan_id;
1275         uint8_t  vlan_id_value;
1276         cmdline_fixed_string_t vlan_prio;
1277         uint8_t  vlan_prio_value;
1278         cmdline_fixed_string_t only_ip_flow;
1279         uint8_t  only_ip_flow_value;
1280 };
1281
1282 static void
1283 cmd_pkt_filter_masks_parsed(void *parsed_result,
1284                           __attribute__((unused)) struct cmdline *cl,
1285                           __attribute__((unused)) void *data)
1286 {
1287         struct rte_fdir_masks fdir_masks;
1288         struct cmd_pkt_filter_masks_result *res = parsed_result;
1289
1290         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
1291
1292         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
1293         fdir_masks.vlan_id       = res->vlan_id_value;
1294         fdir_masks.vlan_prio     = res->vlan_prio_value;
1295         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
1296         fdir_masks.src_ipv4_mask = res->ip_src_mask;
1297         fdir_masks.src_port_mask = res->port_src_mask;
1298         fdir_masks.dst_port_mask = res->port_dst_mask;
1299         fdir_masks.flexbytes     = res->flexbytes_value;
1300
1301         fdir_set_masks(res->port_id, &fdir_masks);
1302 }
1303
1304 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
1305         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1306                                  filter_mask, "set_masks_filter");
1307 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
1308         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1309                               port_id, UINT8);
1310 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
1311         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1312                                  only_ip_flow, "only_ip_flow");
1313 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
1314         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1315                               only_ip_flow_value, UINT8);
1316 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
1317         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1318                                  src_mask, "src_mask");
1319 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
1320         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1321                               ip_src_mask, UINT32);
1322 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
1323         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1324                               port_src_mask, UINT16);
1325 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
1326         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1327                                  src_mask, "dst_mask");
1328 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
1329         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1330                               ip_dst_mask, UINT32);
1331 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
1332         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1333                               port_dst_mask, UINT16);
1334 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
1335         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1336                                  flexbytes, "flexbytes");
1337 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
1338         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1339                               flexbytes_value, UINT8);
1340 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
1341         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1342                                  vlan_id, "vlan_id");
1343 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
1344         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1345                               vlan_id_value, UINT8);
1346 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
1347         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
1348                                  vlan_prio, "vlan_prio");
1349 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
1350         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
1351                               vlan_prio_value, UINT8);
1352
1353 cmdline_parse_inst_t cmd_set_masks_filter = {
1354         .f = cmd_pkt_filter_masks_parsed,
1355         .data = NULL,
1356         .help_str = "setup masks filter",
1357         .tokens = {
1358                 (void *)&cmd_pkt_filter_masks_filter_mask,
1359                 (void *)&cmd_pkt_filter_masks_port_id,
1360                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
1361                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
1362                 (void *)&cmd_pkt_filter_masks_src_mask,
1363                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
1364                 (void *)&cmd_pkt_filter_masks_port_src_mask,
1365                 (void *)&cmd_pkt_filter_masks_dst_mask,
1366                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
1367                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
1368                 (void *)&cmd_pkt_filter_masks_flexbytes,
1369                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
1370                 (void *)&cmd_pkt_filter_masks_vlan_id,
1371                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
1372                 (void *)&cmd_pkt_filter_masks_vlan_prio,
1373                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
1374                 NULL,
1375         },
1376 };
1377
1378 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
1379 struct cmd_link_flow_ctrl_set_result {
1380         cmdline_fixed_string_t set;
1381         cmdline_fixed_string_t flow_ctrl;
1382         cmdline_fixed_string_t rx;
1383         cmdline_fixed_string_t rx_lfc_mode;
1384         cmdline_fixed_string_t tx;
1385         cmdline_fixed_string_t tx_lfc_mode;
1386         uint32_t high_water;
1387         uint32_t low_water;
1388         uint16_t pause_time;
1389         uint16_t send_xon;
1390         uint8_t  port_id;
1391 };
1392
1393 static void
1394 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
1395                        __attribute__((unused)) struct cmdline *cl,
1396                        __attribute__((unused)) void *data)
1397 {
1398         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
1399         struct rte_eth_fc_conf fc_conf;
1400         int rx_fc_enable, tx_fc_enable;
1401         int ret;
1402
1403         /*
1404          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
1405          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
1406          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
1407          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
1408          */
1409         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
1410                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
1411         };
1412
1413         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
1414         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
1415
1416         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
1417         fc_conf.high_water = res->high_water;
1418         fc_conf.low_water  = res->low_water;
1419         fc_conf.pause_time = res->pause_time;
1420         fc_conf.send_xon   = res->send_xon;
1421
1422         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
1423         if (ret != 0)
1424                 printf("bad flow contrl parameter, return code = %d \n", ret);
1425 }
1426
1427 cmdline_parse_token_string_t cmd_lfc_set_set =
1428         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1429                                 set, "set");
1430 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
1431         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1432                                 flow_ctrl, "flow_ctrl");
1433 cmdline_parse_token_string_t cmd_lfc_set_rx =
1434         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1435                                 rx, "rx");
1436 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
1437         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1438                                 rx_lfc_mode, "on#off");
1439 cmdline_parse_token_string_t cmd_lfc_set_tx =
1440         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1441                                 tx, "tx");
1442 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
1443         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1444                                 tx_lfc_mode, "on#off");
1445 cmdline_parse_token_num_t cmd_lfc_set_high_water =
1446         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1447                                 high_water, UINT32);
1448 cmdline_parse_token_num_t cmd_lfc_set_low_water =
1449         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1450                                 low_water, UINT32);
1451 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
1452         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1453                                 pause_time, UINT16);
1454 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
1455         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1456                                 send_xon, UINT16);
1457 cmdline_parse_token_num_t cmd_lfc_set_portid =
1458         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
1459                                 port_id, UINT8);
1460
1461 cmdline_parse_inst_t cmd_link_flow_control_set = {
1462         .f = cmd_link_flow_ctrl_set_parsed,
1463         .data = NULL,
1464         .help_str = "Configure the Ethernet link flow control...",
1465         .tokens = {
1466                 (void *)&cmd_lfc_set_set,
1467                 (void *)&cmd_lfc_set_flow_ctrl,
1468                 (void *)&cmd_lfc_set_rx,
1469                 (void *)&cmd_lfc_set_rx_mode,
1470                 (void *)&cmd_lfc_set_tx,
1471                 (void *)&cmd_lfc_set_tx_mode,
1472                 (void *)&cmd_lfc_set_high_water,
1473                 (void *)&cmd_lfc_set_low_water,
1474                 (void *)&cmd_lfc_set_pause_time,
1475                 (void *)&cmd_lfc_set_send_xon,
1476                 (void *)&cmd_lfc_set_portid,
1477                 NULL,
1478         },
1479 };
1480
1481 /* *** RESET CONFIGURATION *** */
1482 struct cmd_reset_result {
1483         cmdline_fixed_string_t reset;
1484         cmdline_fixed_string_t def;
1485 };
1486
1487 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
1488                              struct cmdline *cl,
1489                              __attribute__((unused)) void *data)
1490 {
1491         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
1492         set_def_fwd_config();
1493 }
1494
1495 cmdline_parse_token_string_t cmd_reset_set =
1496         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
1497 cmdline_parse_token_string_t cmd_reset_def =
1498         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
1499                                  "default");
1500
1501 cmdline_parse_inst_t cmd_reset = {
1502         .f = cmd_reset_parsed,
1503         .data = NULL,
1504         .help_str = "set default: reset default forwarding configuration",
1505         .tokens = {
1506                 (void *)&cmd_reset_set,
1507                 (void *)&cmd_reset_def,
1508                 NULL,
1509         },
1510 };
1511
1512 /* *** START FORWARDING *** */
1513 struct cmd_start_result {
1514         cmdline_fixed_string_t start;
1515 };
1516
1517 cmdline_parse_token_string_t cmd_start_start =
1518         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
1519
1520 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
1521                              __attribute__((unused)) struct cmdline *cl,
1522                              __attribute__((unused)) void *data)
1523 {
1524         start_packet_forwarding(0);
1525 }
1526
1527 cmdline_parse_inst_t cmd_start = {
1528         .f = cmd_start_parsed,
1529         .data = NULL,
1530         .help_str = "start packet forwarding",
1531         .tokens = {
1532                 (void *)&cmd_start_start,
1533                 NULL,
1534         },
1535 };
1536
1537 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
1538 struct cmd_start_tx_first_result {
1539         cmdline_fixed_string_t start;
1540         cmdline_fixed_string_t tx_first;
1541 };
1542
1543 static void
1544 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
1545                           __attribute__((unused)) struct cmdline *cl,
1546                           __attribute__((unused)) void *data)
1547 {
1548         start_packet_forwarding(1);
1549 }
1550
1551 cmdline_parse_token_string_t cmd_start_tx_first_start =
1552         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
1553                                  "start");
1554 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
1555         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
1556                                  tx_first, "tx_first");
1557
1558 cmdline_parse_inst_t cmd_start_tx_first = {
1559         .f = cmd_start_tx_first_parsed,
1560         .data = NULL,
1561         .help_str = "start packet forwarding, after sending 1 burst of packets",
1562         .tokens = {
1563                 (void *)&cmd_start_tx_first_start,
1564                 (void *)&cmd_start_tx_first_tx_first,
1565                 NULL,
1566         },
1567 };
1568
1569 /* *** SHOW CFG *** */
1570 struct cmd_showcfg_result {
1571         cmdline_fixed_string_t show;
1572         cmdline_fixed_string_t cfg;
1573         cmdline_fixed_string_t what;
1574 };
1575
1576 static void cmd_showcfg_parsed(void *parsed_result,
1577                                __attribute__((unused)) struct cmdline *cl,
1578                                __attribute__((unused)) void *data)
1579 {
1580         struct cmd_showcfg_result *res = parsed_result;
1581         if (!strcmp(res->what, "rxtx"))
1582                 rxtx_config_display();
1583         else if (!strcmp(res->what, "cores"))
1584                 fwd_lcores_config_display();
1585         else if (!strcmp(res->what, "fwd"))
1586                 fwd_config_display();
1587 }
1588
1589 cmdline_parse_token_string_t cmd_showcfg_show =
1590         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
1591 cmdline_parse_token_string_t cmd_showcfg_port =
1592         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
1593 cmdline_parse_token_string_t cmd_showcfg_what =
1594         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
1595                                  "rxtx#cores#fwd");
1596
1597 cmdline_parse_inst_t cmd_showcfg = {
1598         .f = cmd_showcfg_parsed,
1599         .data = NULL,
1600         .help_str = "show config rxtx|cores|fwd",
1601         .tokens = {
1602                 (void *)&cmd_showcfg_show,
1603                 (void *)&cmd_showcfg_port,
1604                 (void *)&cmd_showcfg_what,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** SHOW ALL PORT INFO *** */
1610 struct cmd_showportall_result {
1611         cmdline_fixed_string_t show;
1612         cmdline_fixed_string_t port;
1613         cmdline_fixed_string_t what;
1614         cmdline_fixed_string_t all;
1615 };
1616
1617 static void cmd_showportall_parsed(void *parsed_result,
1618                                 __attribute__((unused)) struct cmdline *cl,
1619                                 __attribute__((unused)) void *data)
1620 {
1621         portid_t i;
1622
1623         struct cmd_showportall_result *res = parsed_result;
1624         if (!strcmp(res->show, "clear")) {
1625                 if (!strcmp(res->what, "stats"))
1626                         for (i = 0; i < nb_ports; i++)
1627                                 nic_stats_clear(i);
1628         } else if (!strcmp(res->what, "info"))
1629                 for (i = 0; i < nb_ports; i++)
1630                         port_infos_display(i);
1631         else if (!strcmp(res->what, "stats"))
1632                 for (i = 0; i < nb_ports; i++)
1633                         nic_stats_display(i);
1634         else if (!strcmp(res->what, "fdir"))
1635                 for (i = 0; i < nb_ports; i++)
1636                         fdir_get_infos(i);
1637         else if (!strcmp(res->what, "stat_qmap"))
1638                 for (i = 0; i < nb_ports; i++)
1639                         nic_stats_mapping_display(i);
1640 }
1641
1642 cmdline_parse_token_string_t cmd_showportall_show =
1643         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
1644                                  "show#clear");
1645 cmdline_parse_token_string_t cmd_showportall_port =
1646         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
1647 cmdline_parse_token_string_t cmd_showportall_what =
1648         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
1649                                  "info#stats#fdir#stat_qmap");
1650 cmdline_parse_token_string_t cmd_showportall_all =
1651         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
1652 cmdline_parse_inst_t cmd_showportall = {
1653         .f = cmd_showportall_parsed,
1654         .data = NULL,
1655         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
1656         .tokens = {
1657                 (void *)&cmd_showportall_show,
1658                 (void *)&cmd_showportall_port,
1659                 (void *)&cmd_showportall_what,
1660                 (void *)&cmd_showportall_all,
1661                 NULL,
1662         },
1663 };
1664
1665 /* *** SHOW PORT INFO *** */
1666 struct cmd_showport_result {
1667         cmdline_fixed_string_t show;
1668         cmdline_fixed_string_t port;
1669         cmdline_fixed_string_t what;
1670         uint8_t portnum;
1671 };
1672
1673 static void cmd_showport_parsed(void *parsed_result,
1674                                 __attribute__((unused)) struct cmdline *cl,
1675                                 __attribute__((unused)) void *data)
1676 {
1677         struct cmd_showport_result *res = parsed_result;
1678         if (!strcmp(res->show, "clear")) {
1679                 if (!strcmp(res->what, "stats"))
1680                         nic_stats_clear(res->portnum);
1681         } else if (!strcmp(res->what, "info"))
1682                 port_infos_display(res->portnum);
1683         else if (!strcmp(res->what, "stats"))
1684                 nic_stats_display(res->portnum);
1685         else if (!strcmp(res->what, "fdir"))
1686                  fdir_get_infos(res->portnum);
1687         else if (!strcmp(res->what, "stat_qmap"))
1688                 nic_stats_mapping_display(res->portnum);
1689 }
1690
1691 cmdline_parse_token_string_t cmd_showport_show =
1692         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
1693                                  "show#clear");
1694 cmdline_parse_token_string_t cmd_showport_port =
1695         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
1696 cmdline_parse_token_string_t cmd_showport_what =
1697         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
1698                                  "info#stats#fdir#stat_qmap");
1699 cmdline_parse_token_num_t cmd_showport_portnum =
1700         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
1701
1702 cmdline_parse_inst_t cmd_showport = {
1703         .f = cmd_showport_parsed,
1704         .data = NULL,
1705         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
1706         .tokens = {
1707                 (void *)&cmd_showport_show,
1708                 (void *)&cmd_showport_port,
1709                 (void *)&cmd_showport_what,
1710                 (void *)&cmd_showport_portnum,
1711                 NULL,
1712         },
1713 };
1714
1715 /* *** READ PORT REGISTER *** */
1716 struct cmd_read_reg_result {
1717         cmdline_fixed_string_t read;
1718         cmdline_fixed_string_t reg;
1719         uint8_t port_id;
1720         uint32_t reg_off;
1721 };
1722
1723 static void
1724 cmd_read_reg_parsed(void *parsed_result,
1725                     __attribute__((unused)) struct cmdline *cl,
1726                     __attribute__((unused)) void *data)
1727 {
1728         struct cmd_read_reg_result *res = parsed_result;
1729         port_reg_display(res->port_id, res->reg_off);
1730 }
1731
1732 cmdline_parse_token_string_t cmd_read_reg_read =
1733         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
1734 cmdline_parse_token_string_t cmd_read_reg_reg =
1735         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
1736 cmdline_parse_token_num_t cmd_read_reg_port_id =
1737         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
1738 cmdline_parse_token_num_t cmd_read_reg_reg_off =
1739         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
1740
1741 cmdline_parse_inst_t cmd_read_reg = {
1742         .f = cmd_read_reg_parsed,
1743         .data = NULL,
1744         .help_str = "read reg port_id reg_off",
1745         .tokens = {
1746                 (void *)&cmd_read_reg_read,
1747                 (void *)&cmd_read_reg_reg,
1748                 (void *)&cmd_read_reg_port_id,
1749                 (void *)&cmd_read_reg_reg_off,
1750                 NULL,
1751         },
1752 };
1753
1754 /* *** READ PORT REGISTER BIT FIELD *** */
1755 struct cmd_read_reg_bit_field_result {
1756         cmdline_fixed_string_t read;
1757         cmdline_fixed_string_t regfield;
1758         uint8_t port_id;
1759         uint32_t reg_off;
1760         uint8_t bit1_pos;
1761         uint8_t bit2_pos;
1762 };
1763
1764 static void
1765 cmd_read_reg_bit_field_parsed(void *parsed_result,
1766                               __attribute__((unused)) struct cmdline *cl,
1767                               __attribute__((unused)) void *data)
1768 {
1769         struct cmd_read_reg_bit_field_result *res = parsed_result;
1770         port_reg_bit_field_display(res->port_id, res->reg_off,
1771                                    res->bit1_pos, res->bit2_pos);
1772 }
1773
1774 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
1775         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
1776                                  "read");
1777 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
1778         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
1779                                  regfield, "regfield");
1780 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
1781         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
1782                               UINT8);
1783 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
1784         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
1785                               UINT32);
1786 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
1787         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
1788                               UINT8);
1789 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
1790         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
1791                               UINT8);
1792
1793 cmdline_parse_inst_t cmd_read_reg_bit_field = {
1794         .f = cmd_read_reg_bit_field_parsed,
1795         .data = NULL,
1796         .help_str = "read regfield port_id reg_off bit_x bit_y "
1797         "(read register bit field between bit_x and bit_y included)",
1798         .tokens = {
1799                 (void *)&cmd_read_reg_bit_field_read,
1800                 (void *)&cmd_read_reg_bit_field_regfield,
1801                 (void *)&cmd_read_reg_bit_field_port_id,
1802                 (void *)&cmd_read_reg_bit_field_reg_off,
1803                 (void *)&cmd_read_reg_bit_field_bit1_pos,
1804                 (void *)&cmd_read_reg_bit_field_bit2_pos,
1805                 NULL,
1806         },
1807 };
1808
1809 /* *** READ PORT REGISTER BIT *** */
1810 struct cmd_read_reg_bit_result {
1811         cmdline_fixed_string_t read;
1812         cmdline_fixed_string_t regbit;
1813         uint8_t port_id;
1814         uint32_t reg_off;
1815         uint8_t bit_pos;
1816 };
1817
1818 static void
1819 cmd_read_reg_bit_parsed(void *parsed_result,
1820                         __attribute__((unused)) struct cmdline *cl,
1821                         __attribute__((unused)) void *data)
1822 {
1823         struct cmd_read_reg_bit_result *res = parsed_result;
1824         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
1825 }
1826
1827 cmdline_parse_token_string_t cmd_read_reg_bit_read =
1828         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
1829 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
1830         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
1831                                  regbit, "regbit");
1832 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
1833         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
1834 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
1835         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
1836 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
1837         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
1838
1839 cmdline_parse_inst_t cmd_read_reg_bit = {
1840         .f = cmd_read_reg_bit_parsed,
1841         .data = NULL,
1842         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
1843         .tokens = {
1844                 (void *)&cmd_read_reg_bit_read,
1845                 (void *)&cmd_read_reg_bit_regbit,
1846                 (void *)&cmd_read_reg_bit_port_id,
1847                 (void *)&cmd_read_reg_bit_reg_off,
1848                 (void *)&cmd_read_reg_bit_bit_pos,
1849                 NULL,
1850         },
1851 };
1852
1853 /* *** WRITE PORT REGISTER *** */
1854 struct cmd_write_reg_result {
1855         cmdline_fixed_string_t write;
1856         cmdline_fixed_string_t reg;
1857         uint8_t port_id;
1858         uint32_t reg_off;
1859         uint32_t value;
1860 };
1861
1862 static void
1863 cmd_write_reg_parsed(void *parsed_result,
1864                      __attribute__((unused)) struct cmdline *cl,
1865                      __attribute__((unused)) void *data)
1866 {
1867         struct cmd_write_reg_result *res = parsed_result;
1868         port_reg_set(res->port_id, res->reg_off, res->value);
1869 }
1870
1871 cmdline_parse_token_string_t cmd_write_reg_write =
1872         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
1873 cmdline_parse_token_string_t cmd_write_reg_reg =
1874         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
1875 cmdline_parse_token_num_t cmd_write_reg_port_id =
1876         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
1877 cmdline_parse_token_num_t cmd_write_reg_reg_off =
1878         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
1879 cmdline_parse_token_num_t cmd_write_reg_value =
1880         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
1881
1882 cmdline_parse_inst_t cmd_write_reg = {
1883         .f = cmd_write_reg_parsed,
1884         .data = NULL,
1885         .help_str = "write reg port_id reg_off reg_value",
1886         .tokens = {
1887                 (void *)&cmd_write_reg_write,
1888                 (void *)&cmd_write_reg_reg,
1889                 (void *)&cmd_write_reg_port_id,
1890                 (void *)&cmd_write_reg_reg_off,
1891                 (void *)&cmd_write_reg_value,
1892                 NULL,
1893         },
1894 };
1895
1896 /* *** WRITE PORT REGISTER BIT FIELD *** */
1897 struct cmd_write_reg_bit_field_result {
1898         cmdline_fixed_string_t write;
1899         cmdline_fixed_string_t regfield;
1900         uint8_t port_id;
1901         uint32_t reg_off;
1902         uint8_t bit1_pos;
1903         uint8_t bit2_pos;
1904         uint32_t value;
1905 };
1906
1907 static void
1908 cmd_write_reg_bit_field_parsed(void *parsed_result,
1909                                __attribute__((unused)) struct cmdline *cl,
1910                                __attribute__((unused)) void *data)
1911 {
1912         struct cmd_write_reg_bit_field_result *res = parsed_result;
1913         port_reg_bit_field_set(res->port_id, res->reg_off,
1914                           res->bit1_pos, res->bit2_pos, res->value);
1915 }
1916
1917 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
1918         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
1919                                  "write");
1920 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
1921         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
1922                                  regfield, "regfield");
1923 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
1924         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
1925                               UINT8);
1926 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
1927         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
1928                               UINT32);
1929 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
1930         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
1931                               UINT8);
1932 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
1933         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
1934                               UINT8);
1935 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
1936         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
1937                               UINT32);
1938
1939 cmdline_parse_inst_t cmd_write_reg_bit_field = {
1940         .f = cmd_write_reg_bit_field_parsed,
1941         .data = NULL,
1942         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
1943         "(set register bit field between bit_x and bit_y included)",
1944         .tokens = {
1945                 (void *)&cmd_write_reg_bit_field_write,
1946                 (void *)&cmd_write_reg_bit_field_regfield,
1947                 (void *)&cmd_write_reg_bit_field_port_id,
1948                 (void *)&cmd_write_reg_bit_field_reg_off,
1949                 (void *)&cmd_write_reg_bit_field_bit1_pos,
1950                 (void *)&cmd_write_reg_bit_field_bit2_pos,
1951                 (void *)&cmd_write_reg_bit_field_value,
1952                 NULL,
1953         },
1954 };
1955
1956 /* *** WRITE PORT REGISTER BIT *** */
1957 struct cmd_write_reg_bit_result {
1958         cmdline_fixed_string_t write;
1959         cmdline_fixed_string_t regbit;
1960         uint8_t port_id;
1961         uint32_t reg_off;
1962         uint8_t bit_pos;
1963         uint8_t value;
1964 };
1965
1966 static void
1967 cmd_write_reg_bit_parsed(void *parsed_result,
1968                          __attribute__((unused)) struct cmdline *cl,
1969                          __attribute__((unused)) void *data)
1970 {
1971         struct cmd_write_reg_bit_result *res = parsed_result;
1972         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
1973 }
1974
1975 cmdline_parse_token_string_t cmd_write_reg_bit_write =
1976         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
1977                                  "write");
1978 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
1979         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
1980                                  regbit, "regbit");
1981 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
1982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
1983 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
1984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
1985 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
1986         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
1987 cmdline_parse_token_num_t cmd_write_reg_bit_value =
1988         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
1989
1990 cmdline_parse_inst_t cmd_write_reg_bit = {
1991         .f = cmd_write_reg_bit_parsed,
1992         .data = NULL,
1993         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
1994         .tokens = {
1995                 (void *)&cmd_write_reg_bit_write,
1996                 (void *)&cmd_write_reg_bit_regbit,
1997                 (void *)&cmd_write_reg_bit_port_id,
1998                 (void *)&cmd_write_reg_bit_reg_off,
1999                 (void *)&cmd_write_reg_bit_bit_pos,
2000                 (void *)&cmd_write_reg_bit_value,
2001                 NULL,
2002         },
2003 };
2004
2005 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
2006 struct cmd_read_rxd_txd_result {
2007         cmdline_fixed_string_t read;
2008         cmdline_fixed_string_t rxd_txd;
2009         uint8_t port_id;
2010         uint16_t queue_id;
2011         uint16_t desc_id;
2012 };
2013
2014 static void
2015 cmd_read_rxd_txd_parsed(void *parsed_result,
2016                         __attribute__((unused)) struct cmdline *cl,
2017                         __attribute__((unused)) void *data)
2018 {
2019         struct cmd_read_rxd_txd_result *res = parsed_result;
2020
2021         if (!strcmp(res->rxd_txd, "rxd"))
2022                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2023         else if (!strcmp(res->rxd_txd, "txd"))
2024                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
2025 }
2026
2027 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
2028         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
2029 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
2030         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
2031                                  "rxd#txd");
2032 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
2033         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
2034 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
2035         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
2036 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
2037         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
2038
2039 cmdline_parse_inst_t cmd_read_rxd_txd = {
2040         .f = cmd_read_rxd_txd_parsed,
2041         .data = NULL,
2042         .help_str = "read rxd|txd port_id queue_id rxd_id",
2043         .tokens = {
2044                 (void *)&cmd_read_rxd_txd_read,
2045                 (void *)&cmd_read_rxd_txd_rxd_txd,
2046                 (void *)&cmd_read_rxd_txd_port_id,
2047                 (void *)&cmd_read_rxd_txd_queue_id,
2048                 (void *)&cmd_read_rxd_txd_desc_id,
2049                 NULL,
2050         },
2051 };
2052
2053 /* *** QUIT *** */
2054 struct cmd_quit_result {
2055         cmdline_fixed_string_t quit;
2056 };
2057
2058 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
2059                             struct cmdline *cl,
2060                             __attribute__((unused)) void *data)
2061 {
2062         pmd_test_exit();
2063         cmdline_quit(cl);
2064 }
2065
2066 cmdline_parse_token_string_t cmd_quit_quit =
2067         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
2068
2069 cmdline_parse_inst_t cmd_quit = {
2070         .f = cmd_quit_parsed,
2071         .data = NULL,
2072         .help_str = "exit application",
2073         .tokens = {
2074                 (void *)&cmd_quit_quit,
2075                 NULL,
2076         },
2077 };
2078
2079 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
2080 struct cmd_mac_addr_result {
2081         cmdline_fixed_string_t mac_addr_cmd;
2082         cmdline_fixed_string_t what;
2083         uint8_t port_num;
2084         struct ether_addr address;
2085 };
2086
2087 static void cmd_mac_addr_parsed(void *parsed_result,
2088                 __attribute__((unused)) struct cmdline *cl,
2089                 __attribute__((unused)) void *data)
2090 {
2091         struct cmd_mac_addr_result *res = parsed_result;
2092         int ret;
2093
2094         if (strcmp(res->what, "add") == 0)
2095                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
2096         else
2097                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
2098
2099         /* check the return value and print it if is < 0 */
2100         if(ret < 0)
2101                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
2102
2103 }
2104
2105 cmdline_parse_token_string_t cmd_mac_addr_cmd =
2106         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
2107                                 "mac_addr");
2108 cmdline_parse_token_string_t cmd_mac_addr_what =
2109         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
2110                                 "add#remove");
2111 cmdline_parse_token_num_t cmd_mac_addr_portnum =
2112                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
2113 cmdline_parse_token_string_t cmd_mac_addr_addr =
2114                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
2115
2116 cmdline_parse_inst_t cmd_mac_addr = {
2117         .f = cmd_mac_addr_parsed,
2118         .data = (void *)0,
2119         .help_str = "mac_addr add|remove X <address>: "
2120                         "add/remove MAC address on port X",
2121         .tokens = {
2122                 (void *)&cmd_mac_addr_cmd,
2123                 (void *)&cmd_mac_addr_what,
2124                 (void *)&cmd_mac_addr_portnum,
2125                 (void *)&cmd_mac_addr_addr,
2126                 NULL,
2127         },
2128 };
2129
2130
2131 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
2132 struct cmd_set_qmap_result {
2133         cmdline_fixed_string_t set;
2134         cmdline_fixed_string_t qmap;
2135         cmdline_fixed_string_t what;
2136         uint8_t port_id;
2137         uint16_t queue_id;
2138         uint8_t map_value;
2139 };
2140
2141 static void
2142 cmd_set_qmap_parsed(void *parsed_result,
2143                        __attribute__((unused)) struct cmdline *cl,
2144                        __attribute__((unused)) void *data)
2145 {
2146         struct cmd_set_qmap_result *res = parsed_result;
2147         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
2148
2149         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
2150 }
2151
2152 cmdline_parse_token_string_t cmd_setqmap_set =
2153         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2154                                  set, "set");
2155 cmdline_parse_token_string_t cmd_setqmap_qmap =
2156         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2157                                  qmap, "stat_qmap");
2158 cmdline_parse_token_string_t cmd_setqmap_what =
2159         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
2160                                  what, "tx#rx");
2161 cmdline_parse_token_num_t cmd_setqmap_portid =
2162         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2163                               port_id, UINT8);
2164 cmdline_parse_token_num_t cmd_setqmap_queueid =
2165         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2166                               queue_id, UINT16);
2167 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
2168         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
2169                               map_value, UINT8);
2170
2171 cmdline_parse_inst_t cmd_set_qmap = {
2172         .f = cmd_set_qmap_parsed,
2173         .data = NULL,
2174         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
2175         .tokens = {
2176                 (void *)&cmd_setqmap_set,
2177                 (void *)&cmd_setqmap_qmap,
2178                 (void *)&cmd_setqmap_what,
2179                 (void *)&cmd_setqmap_portid,
2180                 (void *)&cmd_setqmap_queueid,
2181                 (void *)&cmd_setqmap_mapvalue,
2182                 NULL,
2183         },
2184 };
2185
2186 /* ******************************************************************************** */
2187
2188 /* list of instructions */
2189 cmdline_parse_ctx_t main_ctx[] = {
2190         (cmdline_parse_inst_t *)&cmd_help,
2191         (cmdline_parse_inst_t *)&cmd_quit,
2192         (cmdline_parse_inst_t *)&cmd_showport,
2193         (cmdline_parse_inst_t *)&cmd_showportall,
2194         (cmdline_parse_inst_t *)&cmd_showcfg,
2195         (cmdline_parse_inst_t *)&cmd_start,
2196         (cmdline_parse_inst_t *)&cmd_start_tx_first,
2197         (cmdline_parse_inst_t *)&cmd_reset,
2198         (cmdline_parse_inst_t *)&cmd_set_numbers,
2199         (cmdline_parse_inst_t *)&cmd_set_txpkts,
2200         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
2201         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
2202         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
2203         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
2204         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
2205         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
2206         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
2207         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
2208         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
2209         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
2210         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
2211         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
2212         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
2213         (cmdline_parse_inst_t *)&cmd_read_reg,
2214         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
2215         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
2216         (cmdline_parse_inst_t *)&cmd_write_reg,
2217         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
2218         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
2219         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
2220         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
2221         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
2222         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
2223         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
2224         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
2225         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
2226         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
2227         (cmdline_parse_inst_t *)&cmd_stop,
2228         (cmdline_parse_inst_t *)&cmd_mac_addr,
2229         (cmdline_parse_inst_t *)&cmd_set_qmap,
2230         NULL,
2231 };
2232
2233 /* prompt function, called from main on MASTER lcore */
2234 void
2235 prompt(void)
2236 {
2237         struct cmdline *cl;
2238
2239         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
2240         if (cl == NULL) {
2241                 return;
2242         }
2243         cmdline_interact(cl);
2244         cmdline_stdin_exit(cl);
2245 }