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