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