app/testpmd: add MAC control forward
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 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 #include <stdarg.h>
35 #include <errno.h>
36 #include <stdio.h>
37 #include <stdint.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #include <net/socket.h>
45 #endif
46 #include <netinet/in.h>
47
48 #include <sys/queue.h>
49
50 #include <rte_common.h>
51 #include <rte_byteorder.h>
52 #include <rte_log.h>
53 #include <rte_debug.h>
54 #include <rte_cycles.h>
55 #include <rte_memory.h>
56 #include <rte_memzone.h>
57 #include <rte_launch.h>
58 #include <rte_tailq.h>
59 #include <rte_eal.h>
60 #include <rte_per_lcore.h>
61 #include <rte_lcore.h>
62 #include <rte_atomic.h>
63 #include <rte_branch_prediction.h>
64 #include <rte_ring.h>
65 #include <rte_mempool.h>
66 #include <rte_interrupts.h>
67 #include <rte_pci.h>
68 #include <rte_ether.h>
69 #include <rte_ethdev.h>
70 #include <rte_string_fns.h>
71
72 #include <cmdline_rdline.h>
73 #include <cmdline_parse.h>
74 #include <cmdline_parse_num.h>
75 #include <cmdline_parse_string.h>
76 #include <cmdline_parse_ipaddr.h>
77 #include <cmdline_parse_etheraddr.h>
78 #include <cmdline_socket.h>
79 #include <cmdline.h>
80 #include <rte_pci_dev_ids.h>
81
82 #include "testpmd.h"
83
84 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
85
86 #ifdef RTE_NIC_BYPASS
87 uint8_t bypass_is_supported(portid_t port_id);
88 #endif
89
90 /* *** Help command with introduction. *** */
91 struct cmd_help_brief_result {
92         cmdline_fixed_string_t help;
93 };
94
95 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
96                                   struct cmdline *cl,
97                                   __attribute__((unused)) void *data)
98 {
99         cmdline_printf(
100                 cl,
101                 "\n"
102                 "Help is available for the following sections:\n\n"
103                 "    help control    : Start and stop forwarding.\n"
104                 "    help display    : Displaying port, stats and config "
105                 "information.\n"
106                 "    help config     : Configuration information.\n"
107                 "    help ports      : Configuring ports.\n"
108                 "    help flowdir    : Flow Director filter help.\n"
109                 "    help registers  : Reading and setting port registers.\n"
110                 "    help all        : All of the above sections.\n\n"
111         );
112
113 }
114
115 cmdline_parse_token_string_t cmd_help_brief_help =
116         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
117
118 cmdline_parse_inst_t cmd_help_brief = {
119         .f = cmd_help_brief_parsed,
120         .data = NULL,
121         .help_str = "show help",
122         .tokens = {
123                 (void *)&cmd_help_brief_help,
124                 NULL,
125         },
126 };
127
128 /* *** Help command with help sections. *** */
129 struct cmd_help_long_result {
130         cmdline_fixed_string_t help;
131         cmdline_fixed_string_t section;
132 };
133
134 static void cmd_help_long_parsed(void *parsed_result,
135                                  struct cmdline *cl,
136                                  __attribute__((unused)) void *data)
137 {
138         int show_all = 0;
139         struct cmd_help_long_result *res = parsed_result;
140
141         if (!strcmp(res->section, "all"))
142                 show_all = 1;
143
144         if (show_all || !strcmp(res->section, "control")) {
145
146                 cmdline_printf(
147                         cl,
148                         "\n"
149                         "Control forwarding:\n"
150                         "-------------------\n\n"
151
152                         "start\n"
153                         "    Start packet forwarding with current configuration.\n\n"
154
155                         "start tx_first\n"
156                         "    Start packet forwarding with current config"
157                         " after sending one burst of packets.\n\n"
158
159                         "stop\n"
160                         "    Stop packet forwarding, and display accumulated"
161                         " statistics.\n\n"
162
163                         "quit\n"
164                         "    Quit to prompt in Linux and reboot on Baremetal.\n\n"
165                 );
166         }
167
168         if (show_all || !strcmp(res->section, "display")) {
169
170                 cmdline_printf(
171                         cl,
172                         "\n"
173                         "Display:\n"
174                         "--------\n\n"
175
176                         "show port (info|stats|fdir|stat_qmap) (port_id|all)\n"
177                         "    Display information for port_id, or all.\n\n"
178
179                         "clear port (info|stats|fdir|stat_qmap) (port_id|all)\n"
180                         "    Clear information for port_id, or all.\n\n"
181
182                         "show config (rxtx|cores|fwd)\n"
183                         "    Display the given configuration.\n\n"
184
185                         "read rxd (port_id) (queue_id) (rxd_id)\n"
186                         "    Display an RX descriptor of a port RX queue.\n\n"
187
188                         "read txd (port_id) (queue_id) (txd_id)\n"
189                         "    Display a TX descriptor of a port TX queue.\n\n"
190                 );
191         }
192
193         if (show_all || !strcmp(res->section, "config")) {
194                 cmdline_printf(
195                         cl,
196                         "\n"
197                         "Configuration:\n"
198                         "--------------\n"
199                         "Configuration changes only become active when"
200                         " forwarding is started/restarted.\n\n"
201
202                         "set default\n"
203                         "    Reset forwarding to the default configuration.\n\n"
204
205                         "set verbose (level)\n"
206                         "    Set the debug verbosity level X.\n\n"
207
208                         "set nbport (num)\n"
209                         "    Set number of ports.\n\n"
210
211                         "set nbcore (num)\n"
212                         "    Set number of cores.\n\n"
213
214                         "set coremask (mask)\n"
215                         "    Set the forwarding cores hexadecimal mask.\n\n"
216
217                         "set portmask (mask)\n"
218                         "    Set the forwarding ports hexadecimal mask.\n\n"
219
220                         "set burst (num)\n"
221                         "    Set number of packets per burst.\n\n"
222
223                         "set txpkts (x[,y]*)\n"
224                         "    Set the length of each segment of TXONLY"
225                         " packets.\n\n"
226
227                         "set corelist (x[,y]*)\n"
228                         "    Set the list of forwarding cores.\n\n"
229
230                         "set portlist (x[,y]*)\n"
231                         "    Set the list of forwarding ports.\n\n"
232
233                         "vlan set strip (on|off) (port_id)\n"
234                         "    Set the VLAN strip on a port.\n\n"
235
236                         "vlan set filter (on|off) (port_id)\n"
237                         "    Set the VLAN filter on a port.\n\n"
238
239                         "vlan set qinq (on|off) (port_id)\n"
240                         "    Set the VLAN QinQ (extended queue in queue)"
241                         " on a port.\n\n"
242
243                         "vlan set tpid (value) (port_id)\n"
244                         "    Set the outer VLAN TPID for Packet Filtering on"
245                         " a port\n\n"
246
247                         "rx_vlan add (vlan_id|all) (port_id)\n"
248                         "    Add a vlan_id, or all identifiers, to the set"
249                         " of VLAN identifiers filtered by port_id.\n\n"
250
251                         "rx_vlan rm (vlan_id|all) (port_id)\n"
252                         "    Remove a vlan_id, or all identifiers, from the set"
253                         " of VLAN identifiers filtered by port_id.\n\n"
254
255                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
256                         "    Add a vlan_id, to the set of VLAN identifiers"
257                         "filtered for VF(s) from port_id.\n\n"
258                         
259                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
260                         "    Remove a vlan_id, to the set of VLAN identifiers"
261                         "filtered for VF(s) from port_id.\n\n"                  
262
263                         "rx_vlan set tpid (value) (port_id)\n"
264                         "    Set the outer VLAN TPID for Packet Filtering on"
265                         " a port\n\n"
266
267                         "tx_vlan set vlan_id (port_id)\n"
268                         "    Set hardware insertion of VLAN ID in packets sent"
269                         " on a port.\n\n"
270
271                         "tx_vlan reset (port_id)\n"
272                         "    Disable hardware insertion of a VLAN header in"
273                         " packets sent on a port.\n\n"
274
275                         "tx_checksum set mask (port_id)\n"
276                         "    Enable hardware insertion of checksum offload with"
277                         " the 4-bit mask, 0~0xf, in packets sent on a port.\n"
278                         "        bit 0 - insert ip   checksum offload if set\n"
279                         "        bit 1 - insert udp  checksum offload if set\n"
280                         "        bit 2 - insert tcp  checksum offload if set\n"
281                         "        bit 3 - insert sctp checksum offload if set\n"
282                         "    Please check the NIC datasheet for HW limits.\n\n"
283
284 #ifdef RTE_LIBRTE_IEEE1588
285                         "set fwd (io|mac|rxonly|txonly|csum|ieee1588)\n"
286                         "    Set IO, MAC, RXONLY, CSUM or TXONLY or ieee1588"
287                         " packet forwarding mode.\n\n"
288
289 #else
290                         "set fwd (io|mac|rxonly|txonly|csum)\n"
291                         "    Set IO, MAC, RXONLY, CSUM or TXONLY packet"
292                         " forwarding mode.\n\n"
293
294 #endif
295                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
296                         "    Add a MAC address on port_id.\n\n"
297
298                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
299                         "    Remove a MAC address from port_id.\n\n"
300
301                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
302                         "    Add a MAC address for a VF on the port.\n\n"
303                         
304                         "set port (port_id) uta (mac_address|all) (on|off)\n"
305                         "    Add/Remove a or all unicast hash filter(s)" 
306                         "from port X.\n\n"
307
308                         "set promisc (port_id|all) (on|off)\n"
309                         "    Set the promiscuous mode on port_id, or all.\n\n"
310
311                         "set allmulti (port_id|all) (on|off)\n"
312                         "    Set the allmulti mode on port_id, or all.\n\n"
313
314                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
315                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
316                         " (on|off) (port_id)\n"
317                         "    Set the link flow control parameter on a port.\n\n"
318
319                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
320                         " (low_water) (pause_time) (priority) (port_id)\n"
321                         "    Set the priority flow control parameter on a"
322                         " port.\n\n"
323
324                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
325                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
326                         " queue on port.\n"
327                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
328                         " on port 0 to mapping 5.\n\n"
329
330                         "set port (port_id) vf (vf_id) rx|tx on|off \n"
331                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
332
333                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
334                         "|MPE) (on|off)\n"
335                         "    AUPE:accepts untagged VLAN;"
336                         "ROPE:accept unicast hash\n\n"
337                         "    BAM:accepts broadcast packets;"
338                         "MPE:accepts all multicast packets\n\n"
339                         "    Enable/Disable a VF receive mode of a port\n\n"
340                         
341                         "set port (port_id) mirror-rule (rule_id)" 
342                         "(pool-mirror|vlan-mirror)\n"
343                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
344                         "   Set pool or vlan type mirror rule on a port.\n"
345                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
346                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
347                         " to pool 0.\n\n"
348
349                         "set port (port_id) mirror-rule (rule_id)"
350                         "(uplink-mirror|downlink-mirror) dst-pool"
351                         "(pool_id) (on|off)\n"
352                         "   Set uplink or downlink type mirror rule on a port.\n"
353                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
354                         " 0 on' enable mirror income traffic to pool 0.\n\n"
355
356                         "reset port (port_id) mirror-rule (rule_id)\n"
357                         "   Reset a mirror rule.\n\n"
358
359                         "set flush_rx (on|off)\n"
360                         "   Flush (default) or don't flush RX streams before"
361                         " forwarding. Mainly used with PCAP drivers.\n\n"
362
363                         #ifdef RTE_NIC_BYPASS
364                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
365                         "   Set the bypass mode for the lowest port on bypass enabled"
366                         " NIC.\n\n"
367
368                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
369                         "mode (normal|bypass|isolate) (port_id)\n"
370                         "   Set the event required to initiate specified bypass mode for"
371                         " the lowest port on a bypass enabled NIC where:\n"
372                         "       timeout   = enable bypass after watchdog timeout.\n"
373                         "       os_on     = enable bypass when OS/board is powered on.\n"
374                         "       os_off    = enable bypass when OS/board is powered off.\n"
375                         "       power_on  = enable bypass when power supply is turned on.\n"
376                         "       power_off = enable bypass when power supply is turned off."
377                         "\n\n"
378
379                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
380                         "   Set the bypass watchdog timeout to 'n' seconds"
381                         " where 0 = instant.\n\n"
382
383                         "show bypass config (port_id)\n"
384                         "   Show the bypass configuration for a bypass enabled NIC"
385                         " using the lowest port on the NIC.\n\n"
386 #endif
387
388                 );
389         }
390
391
392         if (show_all || !strcmp(res->section, "flowdir")) {
393
394                 cmdline_printf(
395                         cl,
396                         "\n"
397                         "Flow director mode:\n"
398                         "-------------------\n\n"
399
400                         "add_signature_filter (port_id) (ip|udp|tcp|sctp)"
401                         " src (src_ip_address) (src_port)"
402                         " dst (dst_ip_address) (dst_port)"
403                         " flexbytes (flexbytes_values) vlan (vlan_id)"
404                         " queue (queue_id)\n"
405                         "    Add a signature filter.\n\n"
406
407                         "upd_signature_filter (port_id) (ip|udp|tcp|sctp)"
408                         " src (src_ip_address) (src_port)"
409                         " dst (dst_ip_address) (dst_port)"
410                         " flexbytes (flexbytes_values) vlan (vlan_id)"
411                         " queue (queue_id)\n"
412                         "    Update a signature filter.\n\n"
413
414                         "rm_signature_filter (port_id) (ip|udp|tcp|sctp)"
415                         " src (src_ip_address) (src_port)"
416                         " dst (dst_ip_address) (dst_port)"
417                         " flexbytes (flexbytes_values) vlan (vlan_id)\n"
418                         "    Remove a signature filter.\n\n"
419
420                         "add_perfect_filter (port_id) (ip|udp|tcp|sctp)"
421                         " src (src_ip_address) (src_port)"
422                         " dst (dst_ip_address) (dst_port)"
423                         " flexbytes (flexbytes_values) vlan (vlan_id)"
424                         " queue (queue_id) soft (soft_id)\n"
425                         "    Add a perfect filter.\n\n"
426
427                         "upd_perfect_filter (port_id) (ip|udp|tcp|sctp)"
428                         " src (src_ip_address) (src_port)"
429                         " dst (dst_ip_address) (dst_port)"
430                         " flexbytes (flexbytes_values) vlan (vlan_id)"
431                         " queue (queue_id)\n"
432                         "    Update a perfect filter.\n\n"
433
434                         "rm_perfect_filter (port_id) (ip|udp|tcp|sctp)"
435                         " src (src_ip_address) (src_port)"
436                         " dst (dst_ip_address) (dst_port)"
437                         " flexbytes (flexbytes_values) vlan (vlan_id)"
438                         " soft (soft_id)\n"
439                         "    Remove a perfect filter.\n\n"
440
441                         "set_masks_filter (port_id) only_ip_flow (0|1)"
442                         " src_mask (ip_src_mask) (src_port_mask)"
443                         " dst_mask (ip_dst_mask) (dst_port_mask)"
444                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)\n"
445                         "    Set IPv4 filter masks.\n\n"
446
447                         "set_ipv6_masks_filter (port_id) only_ip_flow (0|1)"
448                         " src_mask (ip_src_mask) (src_port_mask)"
449                         " dst_mask (ip_dst_mask) (dst_port_mask)"
450                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)"
451                         " compare_dst (0|1)\n"
452                         "    Set IPv6 filter masks.\n\n"
453                 );
454         }
455
456         if (show_all || !strcmp(res->section, "ports")) {
457
458                 cmdline_printf(
459                         cl,
460                         "\n"
461                         "Port Operations:\n"
462                         "----------------\n\n"
463
464                         "port start (port_id|all)\n"
465                         "    Start all ports or port_id.\n\n"
466
467                         "port stop (port_id|all)\n"
468                         "    Stop all ports or port_id.\n\n"
469
470                         "port close (port_id|all)\n"
471                         "    Close all ports or port_id.\n\n"
472
473                         "port config (port_id|all) speed (10|100|1000|10000|auto)"
474                         " duplex (half|full|auto)\n"
475                         "    Set speed and duplex for all ports or port_id\n\n"
476
477                         "port config all (rxq|txq|rxd|txd) (value)\n"
478                         "    Set number for rxq/txq/rxd/txd.\n\n"
479
480                         "port config all max-pkt-len (value)\n"
481                         "    Set the max packet length.\n\n"
482
483                         "port config all (crc-strip|rx-cksum|hw-vlan|drop-en)"
484                         " (on|off)\n"
485                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
486                         " for ports.\n\n"
487
488                         "port config all rss (ip|udp|none)\n"
489                         "    Set the RSS mode.\n\n"
490
491                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
492                         "    Set the RSS redirection table.\n\n"
493
494                         "port config (port_id) dcb vt (on|off) (traffic_class)"
495                         " pfc (on|off)\n"
496                         "    Set the DCB mode.\n\n"
497
498                         "port config all burst (value)\n"
499                         "    Set the number of packets per burst.\n\n"
500
501                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
502                         " (value)\n"
503                         "    Set the ring prefetch/host/writeback threshold"
504                         " for tx/rx queue.\n\n"
505
506                         "port config all (txfreet|txrst|rxfreet) (value)\n"
507                         "    Set free threshold for rx/tx, or set"
508                         " tx rs bit threshold.\n\n"
509                 );
510         }
511
512         if (show_all || !strcmp(res->section, "registers")) {
513
514                 cmdline_printf(
515                         cl,
516                         "\n"
517                         "Registers:\n"
518                         "----------\n\n"
519
520                         "read reg (port_id) (address)\n"
521                         "    Display value of a port register.\n\n"
522
523                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
524                         "    Display a port register bit field.\n\n"
525
526                         "read regbit (port_id) (address) (bit_x)\n"
527                         "    Display a single port register bit.\n\n"
528
529                         "write reg (port_id) (address) (value)\n"
530                         "    Set value of a port register.\n\n"
531
532                         "write regfield (port_id) (address) (bit_x) (bit_y)"
533                         " (value)\n"
534                         "    Set bit field of a port register.\n\n"
535
536                         "write regbit (port_id) (address) (bit_x) (value)\n"
537                         "    Set single bit value of a port register.\n\n"
538                 );
539         }
540 }
541
542 cmdline_parse_token_string_t cmd_help_long_help =
543         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
544
545 cmdline_parse_token_string_t cmd_help_long_section =
546         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
547                         "all#control#display#config#flowdir#"
548                         "ports#registers");
549
550 cmdline_parse_inst_t cmd_help_long = {
551         .f = cmd_help_long_parsed,
552         .data = NULL,
553         .help_str = "show help",
554         .tokens = {
555                 (void *)&cmd_help_long_help,
556                 (void *)&cmd_help_long_section,
557                 NULL,
558         },
559 };
560
561
562 /* *** start/stop/close all ports *** */
563 struct cmd_operate_port_result {
564         cmdline_fixed_string_t keyword;
565         cmdline_fixed_string_t name;
566         cmdline_fixed_string_t value;
567 };
568
569 static void cmd_operate_port_parsed(void *parsed_result,
570                                 __attribute__((unused)) struct cmdline *cl,
571                                 __attribute__((unused)) void *data)
572 {
573         struct cmd_operate_port_result *res = parsed_result;
574
575         if (!strcmp(res->name, "start"))
576                 start_port(RTE_PORT_ALL);
577         else if (!strcmp(res->name, "stop"))
578                 stop_port(RTE_PORT_ALL);
579         else if (!strcmp(res->name, "close"))
580                 close_port(RTE_PORT_ALL);
581         else
582                 printf("Unknown parameter\n");
583 }
584
585 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
586         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
587                                                                 "port");
588 cmdline_parse_token_string_t cmd_operate_port_all_port =
589         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
590                                                 "start#stop#close");
591 cmdline_parse_token_string_t cmd_operate_port_all_all =
592         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
593
594 cmdline_parse_inst_t cmd_operate_port = {
595         .f = cmd_operate_port_parsed,
596         .data = NULL,
597         .help_str = "port start|stop|close all: start/stop/close all ports",
598         .tokens = {
599                 (void *)&cmd_operate_port_all_cmd,
600                 (void *)&cmd_operate_port_all_port,
601                 (void *)&cmd_operate_port_all_all,
602                 NULL,
603         },
604 };
605
606 /* *** start/stop/close specific port *** */
607 struct cmd_operate_specific_port_result {
608         cmdline_fixed_string_t keyword;
609         cmdline_fixed_string_t name;
610         uint8_t value;
611 };
612
613 static void cmd_operate_specific_port_parsed(void *parsed_result,
614                         __attribute__((unused)) struct cmdline *cl,
615                                 __attribute__((unused)) void *data)
616 {
617         struct cmd_operate_specific_port_result *res = parsed_result;
618
619         if (!strcmp(res->name, "start"))
620                 start_port(res->value);
621         else if (!strcmp(res->name, "stop"))
622                 stop_port(res->value);
623         else if (!strcmp(res->name, "close"))
624                 close_port(res->value);
625         else
626                 printf("Unknown parameter\n");
627 }
628
629 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
630         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
631                                                         keyword, "port");
632 cmdline_parse_token_string_t cmd_operate_specific_port_port =
633         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
634                                                 name, "start#stop#close");
635 cmdline_parse_token_num_t cmd_operate_specific_port_id =
636         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
637                                                         value, UINT8);
638
639 cmdline_parse_inst_t cmd_operate_specific_port = {
640         .f = cmd_operate_specific_port_parsed,
641         .data = NULL,
642         .help_str = "port start|stop|close X: start/stop/close port X",
643         .tokens = {
644                 (void *)&cmd_operate_specific_port_cmd,
645                 (void *)&cmd_operate_specific_port_port,
646                 (void *)&cmd_operate_specific_port_id,
647                 NULL,
648         },
649 };
650
651 /* *** configure speed for all ports *** */
652 struct cmd_config_speed_all {
653         cmdline_fixed_string_t port;
654         cmdline_fixed_string_t keyword;
655         cmdline_fixed_string_t all;
656         cmdline_fixed_string_t item1;
657         cmdline_fixed_string_t item2;
658         cmdline_fixed_string_t value1;
659         cmdline_fixed_string_t value2;
660 };
661
662 static void
663 cmd_config_speed_all_parsed(void *parsed_result,
664                         __attribute__((unused)) struct cmdline *cl,
665                         __attribute__((unused)) void *data)
666 {
667         struct cmd_config_speed_all *res = parsed_result;
668         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
669         uint16_t link_duplex = 0;
670         portid_t pid;
671
672         if (!all_ports_stopped()) {
673                 printf("Please stop all ports first\n");
674                 return;
675         }
676
677         if (!strcmp(res->value1, "10"))
678                 link_speed = ETH_LINK_SPEED_10;
679         else if (!strcmp(res->value1, "100"))
680                 link_speed = ETH_LINK_SPEED_100;
681         else if (!strcmp(res->value1, "1000"))
682                 link_speed = ETH_LINK_SPEED_1000;
683         else if (!strcmp(res->value1, "10000"))
684                 link_speed = ETH_LINK_SPEED_10000;
685         else if (!strcmp(res->value1, "auto"))
686                 link_speed = ETH_LINK_SPEED_AUTONEG;
687         else {
688                 printf("Unknown parameter\n");
689                 return;
690         }
691
692         if (!strcmp(res->value2, "half"))
693                 link_duplex = ETH_LINK_HALF_DUPLEX;
694         else if (!strcmp(res->value2, "full"))
695                 link_duplex = ETH_LINK_FULL_DUPLEX;
696         else if (!strcmp(res->value2, "auto"))
697                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
698         else {
699                 printf("Unknown parameter\n");
700                 return;
701         }
702
703         for (pid = 0; pid < nb_ports; pid++) {
704                 ports[pid].dev_conf.link_speed = link_speed;
705                 ports[pid].dev_conf.link_duplex = link_duplex;
706         }
707
708         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
709 }
710
711 cmdline_parse_token_string_t cmd_config_speed_all_port =
712         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
713 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
715                                                         "config");
716 cmdline_parse_token_string_t cmd_config_speed_all_all =
717         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
718 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
719         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
720 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
722                                                 "10#100#1000#10000#auto");
723 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
724         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
725 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
727                                                 "half#full#auto");
728
729 cmdline_parse_inst_t cmd_config_speed_all = {
730         .f = cmd_config_speed_all_parsed,
731         .data = NULL,
732         .help_str = "port config all speed 10|100|1000|10000|auto duplex "
733                                                         "half|full|auto",
734         .tokens = {
735                 (void *)&cmd_config_speed_all_port,
736                 (void *)&cmd_config_speed_all_keyword,
737                 (void *)&cmd_config_speed_all_all,
738                 (void *)&cmd_config_speed_all_item1,
739                 (void *)&cmd_config_speed_all_value1,
740                 (void *)&cmd_config_speed_all_item2,
741                 (void *)&cmd_config_speed_all_value2,
742                 NULL,
743         },
744 };
745
746 /* *** configure speed for specific port *** */
747 struct cmd_config_speed_specific {
748         cmdline_fixed_string_t port;
749         cmdline_fixed_string_t keyword;
750         uint8_t id;
751         cmdline_fixed_string_t item1;
752         cmdline_fixed_string_t item2;
753         cmdline_fixed_string_t value1;
754         cmdline_fixed_string_t value2;
755 };
756
757 static void
758 cmd_config_speed_specific_parsed(void *parsed_result,
759                                 __attribute__((unused)) struct cmdline *cl,
760                                 __attribute__((unused)) void *data)
761 {
762         struct cmd_config_speed_specific *res = parsed_result;
763         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
764         uint16_t link_duplex = 0;
765
766         if (!all_ports_stopped()) {
767                 printf("Please stop all ports first\n");
768                 return;
769         }
770
771         if (res->id >= nb_ports) {
772                 printf("Port id %d must be less than %d\n", res->id, nb_ports);
773                 return;
774         }
775
776         if (!strcmp(res->value1, "10"))
777                 link_speed = ETH_LINK_SPEED_10;
778         else if (!strcmp(res->value1, "100"))
779                 link_speed = ETH_LINK_SPEED_100;
780         else if (!strcmp(res->value1, "1000"))
781                 link_speed = ETH_LINK_SPEED_1000;
782         else if (!strcmp(res->value1, "10000"))
783                 link_speed = ETH_LINK_SPEED_10000;
784         else if (!strcmp(res->value1, "auto"))
785                 link_speed = ETH_LINK_SPEED_AUTONEG;
786         else {
787                 printf("Unknown parameter\n");
788                 return;
789         }
790
791         if (!strcmp(res->value2, "half"))
792                 link_duplex = ETH_LINK_HALF_DUPLEX;
793         else if (!strcmp(res->value2, "full"))
794                 link_duplex = ETH_LINK_FULL_DUPLEX;
795         else if (!strcmp(res->value2, "auto"))
796                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
797         else {
798                 printf("Unknown parameter\n");
799                 return;
800         }
801
802         ports[res->id].dev_conf.link_speed = link_speed;
803         ports[res->id].dev_conf.link_duplex = link_duplex;
804
805         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
806 }
807
808
809 cmdline_parse_token_string_t cmd_config_speed_specific_port =
810         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
811                                                                 "port");
812 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
813         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
814                                                                 "config");
815 cmdline_parse_token_num_t cmd_config_speed_specific_id =
816         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
817 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
818         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
819                                                                 "speed");
820 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
821         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
822                                                 "10#100#1000#10000#auto");
823 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
824         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
825                                                                 "duplex");
826 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
827         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
828                                                         "half#full#auto");
829
830 cmdline_parse_inst_t cmd_config_speed_specific = {
831         .f = cmd_config_speed_specific_parsed,
832         .data = NULL,
833         .help_str = "port config X speed 10|100|1000|10000|auto duplex "
834                                                         "half|full|auto",
835         .tokens = {
836                 (void *)&cmd_config_speed_specific_port,
837                 (void *)&cmd_config_speed_specific_keyword,
838                 (void *)&cmd_config_speed_specific_id,
839                 (void *)&cmd_config_speed_specific_item1,
840                 (void *)&cmd_config_speed_specific_value1,
841                 (void *)&cmd_config_speed_specific_item2,
842                 (void *)&cmd_config_speed_specific_value2,
843                 NULL,
844         },
845 };
846
847 /* *** configure txq/rxq, txd/rxd *** */
848 struct cmd_config_rx_tx {
849         cmdline_fixed_string_t port;
850         cmdline_fixed_string_t keyword;
851         cmdline_fixed_string_t all;
852         cmdline_fixed_string_t name;
853         uint16_t value;
854 };
855
856 static void
857 cmd_config_rx_tx_parsed(void *parsed_result,
858                         __attribute__((unused)) struct cmdline *cl,
859                         __attribute__((unused)) void *data)
860 {
861         struct cmd_config_rx_tx *res = parsed_result;
862
863         if (!all_ports_stopped()) {
864                 printf("Please stop all ports first\n");
865                 return;
866         }
867
868         if (!strcmp(res->name, "rxq")) {
869                 if (res->value <= 0) {
870                         printf("rxq %d invalid - must be > 0\n", res->value);
871                         return;
872                 }
873                 nb_rxq = res->value;
874         }
875         else if (!strcmp(res->name, "txq")) {
876                 if (res->value <= 0) {
877                         printf("txq %d invalid - must be > 0\n", res->value);
878                         return;
879                 }
880                 nb_txq = res->value;
881         }
882         else if (!strcmp(res->name, "rxd")) {
883                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
884                         printf("rxd %d invalid - must be > 0 && <= %d\n",
885                                         res->value, RTE_TEST_RX_DESC_MAX);
886                         return;
887                 }
888                 nb_rxd = res->value;
889         } else if (!strcmp(res->name, "txd")) {
890                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
891                         printf("txd %d invalid - must be > 0 && <= %d\n",
892                                         res->value, RTE_TEST_TX_DESC_MAX);
893                         return;
894                 }
895                 nb_txd = res->value;
896         } else {
897                 printf("Unknown parameter\n");
898                 return;
899         }
900
901         init_port_config();
902
903         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
904 }
905
906 cmdline_parse_token_string_t cmd_config_rx_tx_port =
907         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
908 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
909         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
910 cmdline_parse_token_string_t cmd_config_rx_tx_all =
911         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
912 cmdline_parse_token_string_t cmd_config_rx_tx_name =
913         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
914                                                 "rxq#txq#rxd#txd");
915 cmdline_parse_token_num_t cmd_config_rx_tx_value =
916         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
917
918 cmdline_parse_inst_t cmd_config_rx_tx = {
919         .f = cmd_config_rx_tx_parsed,
920         .data = NULL,
921         .help_str = "port config all rxq|txq|rxd|txd value",
922         .tokens = {
923                 (void *)&cmd_config_rx_tx_port,
924                 (void *)&cmd_config_rx_tx_keyword,
925                 (void *)&cmd_config_rx_tx_all,
926                 (void *)&cmd_config_rx_tx_name,
927                 (void *)&cmd_config_rx_tx_value,
928                 NULL,
929         },
930 };
931
932 /* *** config max packet length *** */
933 struct cmd_config_max_pkt_len_result {
934         cmdline_fixed_string_t port;
935         cmdline_fixed_string_t keyword;
936         cmdline_fixed_string_t all;
937         cmdline_fixed_string_t name;
938         uint32_t value;
939 };
940
941 static void
942 cmd_config_max_pkt_len_parsed(void *parsed_result,
943                                 __attribute__((unused)) struct cmdline *cl,
944                                 __attribute__((unused)) void *data)
945 {
946         struct cmd_config_max_pkt_len_result *res = parsed_result;
947
948         if (!all_ports_stopped()) {
949                 printf("Please stop all ports first\n");
950                 return;
951         }
952
953         if (!strcmp(res->name, "max-pkt-len")) {
954                 if (res->value < ETHER_MIN_LEN) {
955                         printf("max-pkt-len can not be less than %d\n",
956                                                         ETHER_MIN_LEN);
957                         return;
958                 }
959                 if (res->value == rx_mode.max_rx_pkt_len)
960                         return;
961
962                 rx_mode.max_rx_pkt_len = res->value;
963                 if (res->value > ETHER_MAX_LEN)
964                         rx_mode.jumbo_frame = 1;
965                 else
966                         rx_mode.jumbo_frame = 0;
967         } else {
968                 printf("Unknown parameter\n");
969                 return;
970         }
971
972         init_port_config();
973
974         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
975 }
976
977 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
978         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
979                                                                 "port");
980 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
981         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
982                                                                 "config");
983 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
984         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
985                                                                 "all");
986 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
987         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
988                                                                 "max-pkt-len");
989 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
990         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
991                                                                 UINT32);
992
993 cmdline_parse_inst_t cmd_config_max_pkt_len = {
994         .f = cmd_config_max_pkt_len_parsed,
995         .data = NULL,
996         .help_str = "port config all max-pkt-len value",
997         .tokens = {
998                 (void *)&cmd_config_max_pkt_len_port,
999                 (void *)&cmd_config_max_pkt_len_keyword,
1000                 (void *)&cmd_config_max_pkt_len_all,
1001                 (void *)&cmd_config_max_pkt_len_name,
1002                 (void *)&cmd_config_max_pkt_len_value,
1003                 NULL,
1004         },
1005 };
1006
1007 /* *** configure rx mode *** */
1008 struct cmd_config_rx_mode_flag {
1009         cmdline_fixed_string_t port;
1010         cmdline_fixed_string_t keyword;
1011         cmdline_fixed_string_t all;
1012         cmdline_fixed_string_t name;
1013         cmdline_fixed_string_t value;
1014 };
1015
1016 static void
1017 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1018                                 __attribute__((unused)) struct cmdline *cl,
1019                                 __attribute__((unused)) void *data)
1020 {
1021         struct cmd_config_rx_mode_flag *res = parsed_result;
1022
1023         if (!all_ports_stopped()) {
1024                 printf("Please stop all ports first\n");
1025                 return;
1026         }
1027
1028         if (!strcmp(res->name, "crc-strip")) {
1029                 if (!strcmp(res->value, "on"))
1030                         rx_mode.hw_strip_crc = 1;
1031                 else if (!strcmp(res->value, "off"))
1032                         rx_mode.hw_strip_crc = 0;
1033                 else {
1034                         printf("Unknown parameter\n");
1035                         return;
1036                 }
1037         } else if (!strcmp(res->name, "rx-cksum")) {
1038                 if (!strcmp(res->value, "on"))
1039                         rx_mode.hw_ip_checksum = 1;
1040                 else if (!strcmp(res->value, "off"))
1041                         rx_mode.hw_ip_checksum = 0;
1042                 else {
1043                         printf("Unknown parameter\n");
1044                         return;
1045                 }
1046         } else if (!strcmp(res->name, "hw-vlan")) {
1047                 if (!strcmp(res->value, "on")) {
1048                         rx_mode.hw_vlan_filter = 1;
1049                         rx_mode.hw_vlan_strip  = 1;
1050                 }
1051                 else if (!strcmp(res->value, "off")) {
1052                         rx_mode.hw_vlan_filter = 0;
1053                         rx_mode.hw_vlan_strip  = 0;
1054                 }
1055                 else {
1056                         printf("Unknown parameter\n");
1057                         return;
1058                 }
1059         } else if (!strcmp(res->name, "drop-en")) {
1060                 if (!strcmp(res->value, "on"))
1061                         rx_drop_en = 1;
1062                 else if (!strcmp(res->value, "off"))
1063                         rx_drop_en = 0;
1064                 else {
1065                         printf("Unknown parameter\n");
1066                         return;
1067                 }
1068         } else {
1069                 printf("Unknown parameter\n");
1070                 return;
1071         }
1072
1073         init_port_config();
1074
1075         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1076 }
1077
1078 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1079         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1080 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1081         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1082                                                                 "config");
1083 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1084         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1085 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1086         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1087                                         "crc-strip#rx-cksum#hw-vlan");
1088 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1089         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1090                                                         "on#off");
1091
1092 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1093         .f = cmd_config_rx_mode_flag_parsed,
1094         .data = NULL,
1095         .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off",
1096         .tokens = {
1097                 (void *)&cmd_config_rx_mode_flag_port,
1098                 (void *)&cmd_config_rx_mode_flag_keyword,
1099                 (void *)&cmd_config_rx_mode_flag_all,
1100                 (void *)&cmd_config_rx_mode_flag_name,
1101                 (void *)&cmd_config_rx_mode_flag_value,
1102                 NULL,
1103         },
1104 };
1105
1106 /* *** configure rss *** */
1107 struct cmd_config_rss {
1108         cmdline_fixed_string_t port;
1109         cmdline_fixed_string_t keyword;
1110         cmdline_fixed_string_t all;
1111         cmdline_fixed_string_t name;
1112         cmdline_fixed_string_t value;
1113 };
1114
1115 static void
1116 cmd_config_rss_parsed(void *parsed_result,
1117                         __attribute__((unused)) struct cmdline *cl,
1118                         __attribute__((unused)) void *data)
1119 {
1120         struct cmd_config_rss *res = parsed_result;
1121
1122         if (!all_ports_stopped()) {
1123                 printf("Please stop all ports first\n");
1124                 return;
1125         }
1126
1127         if (!strcmp(res->value, "ip"))
1128                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
1129         else if (!strcmp(res->value, "udp"))
1130                 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP;
1131         else if (!strcmp(res->value, "none"))
1132                 rss_hf = 0;
1133         else {
1134                 printf("Unknown parameter\n");
1135                 return;
1136         }
1137
1138         init_port_config();
1139
1140         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1141 }
1142
1143 cmdline_parse_token_string_t cmd_config_rss_port =
1144         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1145 cmdline_parse_token_string_t cmd_config_rss_keyword =
1146         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1147 cmdline_parse_token_string_t cmd_config_rss_all =
1148         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1149 cmdline_parse_token_string_t cmd_config_rss_name =
1150         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1151 cmdline_parse_token_string_t cmd_config_rss_value =
1152         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none");
1153
1154 cmdline_parse_inst_t cmd_config_rss = {
1155         .f = cmd_config_rss_parsed,
1156         .data = NULL,
1157         .help_str = "port config all rss ip|udp|none",
1158         .tokens = {
1159                 (void *)&cmd_config_rss_port,
1160                 (void *)&cmd_config_rss_keyword,
1161                 (void *)&cmd_config_rss_all,
1162                 (void *)&cmd_config_rss_name,
1163                 (void *)&cmd_config_rss_value,
1164                 NULL,
1165         },
1166 };
1167
1168 /* *** Configure RSS RETA *** */
1169 struct cmd_config_rss_reta {
1170         cmdline_fixed_string_t port;
1171         cmdline_fixed_string_t keyword;
1172         uint8_t port_id;
1173         cmdline_fixed_string_t name;
1174         cmdline_fixed_string_t list_name;
1175         cmdline_fixed_string_t list_of_items;
1176 };
1177
1178 static int
1179 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
1180 {
1181         int i;
1182         unsigned size;
1183         uint8_t hash_index;
1184         uint8_t nb_queue;
1185         char s[256];
1186         const char *p, *p0 = str;
1187         char *end;
1188         enum fieldnames {
1189                 FLD_HASH_INDEX = 0,
1190                 FLD_QUEUE,
1191                 _NUM_FLD
1192         };
1193         unsigned long int_fld[_NUM_FLD];
1194         char *str_fld[_NUM_FLD];
1195
1196         while ((p = strchr(p0,'(')) != NULL) {
1197                 ++p;
1198                 if((p0 = strchr(p,')')) == NULL)
1199                         return -1;
1200
1201                 size = p0 - p;
1202                 if(size >= sizeof(s))
1203                         return -1;
1204
1205                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
1206                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1207                         return -1;
1208                 for (i = 0; i < _NUM_FLD; i++) {
1209                         errno = 0;
1210                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1211                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1212                                 return -1;
1213                 }
1214
1215                 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX];
1216                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1217
1218                 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) {
1219                         printf("Invalid RETA hash index=%d",hash_index);
1220                         return -1;
1221                 }
1222
1223                 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2)
1224                         reta_conf->mask_lo |= (1ULL << hash_index);
1225                 else
1226                         reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2));
1227
1228                 reta_conf->reta[hash_index] = nb_queue;
1229         }
1230
1231         return 0;
1232 }
1233
1234 static void
1235 cmd_set_rss_reta_parsed(void *parsed_result,
1236                                 __attribute__((unused)) struct cmdline *cl,
1237                                 __attribute__((unused)) void *data)
1238 {
1239         int ret;
1240         struct rte_eth_rss_reta reta_conf;
1241         struct cmd_config_rss_reta *res = parsed_result;
1242
1243         memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta));
1244         if (!strcmp(res->list_name, "reta")) {
1245                 if (parse_reta_config(res->list_of_items, &reta_conf)) {
1246                         printf("Invalid RSS Redirection Table config entered\n");
1247                         return;
1248                 }
1249                 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf);
1250                 if (ret != 0)
1251                         printf("Bad redirection table parameter, return code = %d \n",ret);
1252         }
1253 }
1254
1255 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1257 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1258         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1259 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1260         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1261 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1262         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1263 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1264         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1265 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1266         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1267                                  NULL);
1268 cmdline_parse_inst_t cmd_config_rss_reta = {
1269         .f = cmd_set_rss_reta_parsed,
1270         .data = NULL,
1271         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1272         .tokens = {
1273                 (void *)&cmd_config_rss_reta_port,
1274                 (void *)&cmd_config_rss_reta_keyword,
1275                 (void *)&cmd_config_rss_reta_port_id,
1276                 (void *)&cmd_config_rss_reta_name,
1277                 (void *)&cmd_config_rss_reta_list_name,
1278                 (void *)&cmd_config_rss_reta_list_of_items,
1279                 NULL,
1280         },
1281 };
1282
1283 /* *** SHOW PORT INFO *** */
1284 struct cmd_showport_reta {
1285         cmdline_fixed_string_t show;
1286         cmdline_fixed_string_t port;
1287         uint8_t port_id;
1288         cmdline_fixed_string_t rss;
1289         cmdline_fixed_string_t reta;
1290         uint64_t mask_lo;
1291         uint64_t mask_hi;
1292 };
1293
1294 static void cmd_showport_reta_parsed(void *parsed_result,
1295                                 __attribute__((unused)) struct cmdline *cl,
1296                                 __attribute__((unused)) void *data)
1297 {
1298         struct cmd_showport_reta *res = parsed_result;
1299         struct rte_eth_rss_reta reta_conf;
1300
1301         if ((res->mask_lo == 0) && (res->mask_hi == 0)) {
1302                 printf("Invalid RSS Redirection Table config entered\n");
1303                 return;
1304         }
1305
1306         reta_conf.mask_lo = res->mask_lo;
1307         reta_conf.mask_hi = res->mask_hi;
1308
1309         port_rss_reta_info(res->port_id,&reta_conf);
1310 }
1311
1312 cmdline_parse_token_string_t cmd_showport_reta_show =
1313         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1314 cmdline_parse_token_string_t cmd_showport_reta_port =
1315         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1316 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1317         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1318 cmdline_parse_token_string_t cmd_showport_reta_rss =
1319         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1320 cmdline_parse_token_string_t cmd_showport_reta_reta =
1321         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1322 cmdline_parse_token_num_t cmd_showport_reta_mask_lo =
1323         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64);
1324 cmdline_parse_token_num_t cmd_showport_reta_mask_hi =
1325         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64);
1326
1327 cmdline_parse_inst_t cmd_showport_reta = {
1328         .f = cmd_showport_reta_parsed,
1329         .data = NULL,
1330         .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\
1331                         (mask_lo and mask_hi is UINT64)",
1332         .tokens = {
1333                 (void *)&cmd_showport_reta_show,
1334                 (void *)&cmd_showport_reta_port,
1335                 (void *)&cmd_showport_reta_port_id,
1336                 (void *)&cmd_showport_reta_rss,
1337                 (void *)&cmd_showport_reta_reta,
1338                 (void *)&cmd_showport_reta_mask_lo,
1339                 (void *)&cmd_showport_reta_mask_hi,
1340                 NULL,
1341         },
1342 };
1343
1344 /* *** Configure DCB *** */
1345 struct cmd_config_dcb {
1346         cmdline_fixed_string_t port;
1347         cmdline_fixed_string_t config;
1348         uint8_t port_id;
1349         cmdline_fixed_string_t dcb;
1350         cmdline_fixed_string_t vt;
1351         cmdline_fixed_string_t vt_en;
1352         uint8_t num_tcs;
1353         cmdline_fixed_string_t pfc;
1354         cmdline_fixed_string_t pfc_en;
1355 };
1356
1357 static void
1358 cmd_config_dcb_parsed(void *parsed_result,
1359                         __attribute__((unused)) struct cmdline *cl,
1360                         __attribute__((unused)) void *data)
1361 {
1362         struct cmd_config_dcb *res = parsed_result;
1363         struct dcb_config dcb_conf;
1364         portid_t port_id = res->port_id;
1365         struct rte_port *port;
1366
1367         port = &ports[port_id];
1368         /** Check if the port is not started **/
1369         if (port->port_status != RTE_PORT_STOPPED) {
1370                 printf("Please stop port %d first\n",port_id);
1371                 return;
1372         }
1373
1374         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
1375         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
1376                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
1377                 return;
1378         }
1379
1380         /* DCB in VT mode */
1381         if (!strncmp(res->vt_en, "on",2))
1382                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
1383         else
1384                 dcb_conf.dcb_mode = DCB_ENABLED;
1385
1386         if (!strncmp(res->pfc_en, "on",2)) {
1387                 dcb_conf.pfc_en = 1;
1388         }
1389         else
1390                 dcb_conf.pfc_en = 0;
1391
1392         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
1393                 printf("Cannot initialize network ports\n");
1394                 return;
1395         }
1396
1397         cmd_reconfig_device_queue(port_id, 1, 1);
1398 }
1399
1400 cmdline_parse_token_string_t cmd_config_dcb_port =
1401         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
1402 cmdline_parse_token_string_t cmd_config_dcb_config =
1403         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
1404 cmdline_parse_token_num_t cmd_config_dcb_port_id =
1405         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
1406 cmdline_parse_token_string_t cmd_config_dcb_dcb =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
1408 cmdline_parse_token_string_t cmd_config_dcb_vt =
1409         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
1410 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
1411         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
1412 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
1413         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
1414 cmdline_parse_token_string_t cmd_config_dcb_pfc=
1415         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
1416 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
1418
1419 cmdline_parse_inst_t cmd_config_dcb = {
1420         .f = cmd_config_dcb_parsed,
1421         .data = NULL,
1422         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
1423         .tokens = {
1424                 (void *)&cmd_config_dcb_port,
1425                 (void *)&cmd_config_dcb_config,
1426                 (void *)&cmd_config_dcb_port_id,
1427                 (void *)&cmd_config_dcb_dcb,
1428                 (void *)&cmd_config_dcb_vt,
1429                 (void *)&cmd_config_dcb_vt_en,
1430                 (void *)&cmd_config_dcb_num_tcs,
1431                 (void *)&cmd_config_dcb_pfc,
1432                 (void *)&cmd_config_dcb_pfc_en,
1433                 NULL,
1434         },
1435 };
1436
1437 /* *** configure number of packets per burst *** */
1438 struct cmd_config_burst {
1439         cmdline_fixed_string_t port;
1440         cmdline_fixed_string_t keyword;
1441         cmdline_fixed_string_t all;
1442         cmdline_fixed_string_t name;
1443         uint16_t value;
1444 };
1445
1446 static void
1447 cmd_config_burst_parsed(void *parsed_result,
1448                         __attribute__((unused)) struct cmdline *cl,
1449                         __attribute__((unused)) void *data)
1450 {
1451         struct cmd_config_burst *res = parsed_result;
1452
1453         if (!all_ports_stopped()) {
1454                 printf("Please stop all ports first\n");
1455                 return;
1456         }
1457
1458         if (!strcmp(res->name, "burst")) {
1459                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
1460                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
1461                         return;
1462                 }
1463                 nb_pkt_per_burst = res->value;
1464         } else {
1465                 printf("Unknown parameter\n");
1466                 return;
1467         }
1468
1469         init_port_config();
1470
1471         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1472 }
1473
1474 cmdline_parse_token_string_t cmd_config_burst_port =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
1476 cmdline_parse_token_string_t cmd_config_burst_keyword =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
1478 cmdline_parse_token_string_t cmd_config_burst_all =
1479         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
1480 cmdline_parse_token_string_t cmd_config_burst_name =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
1482 cmdline_parse_token_num_t cmd_config_burst_value =
1483         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
1484
1485 cmdline_parse_inst_t cmd_config_burst = {
1486         .f = cmd_config_burst_parsed,
1487         .data = NULL,
1488         .help_str = "port config all burst value",
1489         .tokens = {
1490                 (void *)&cmd_config_burst_port,
1491                 (void *)&cmd_config_burst_keyword,
1492                 (void *)&cmd_config_burst_all,
1493                 (void *)&cmd_config_burst_name,
1494                 (void *)&cmd_config_burst_value,
1495                 NULL,
1496         },
1497 };
1498
1499 /* *** configure rx/tx queues *** */
1500 struct cmd_config_thresh {
1501         cmdline_fixed_string_t port;
1502         cmdline_fixed_string_t keyword;
1503         cmdline_fixed_string_t all;
1504         cmdline_fixed_string_t name;
1505         uint8_t value;
1506 };
1507
1508 static void
1509 cmd_config_thresh_parsed(void *parsed_result,
1510                         __attribute__((unused)) struct cmdline *cl,
1511                         __attribute__((unused)) void *data)
1512 {
1513         struct cmd_config_thresh *res = parsed_result;
1514
1515         if (!all_ports_stopped()) {
1516                 printf("Please stop all ports first\n");
1517                 return;
1518         }
1519
1520         if (!strcmp(res->name, "txpt"))
1521                 tx_thresh.pthresh = res->value;
1522         else if(!strcmp(res->name, "txht"))
1523                 tx_thresh.hthresh = res->value;
1524         else if(!strcmp(res->name, "txwt"))
1525                 tx_thresh.wthresh = res->value;
1526         else if(!strcmp(res->name, "rxpt"))
1527                 rx_thresh.pthresh = res->value;
1528         else if(!strcmp(res->name, "rxht"))
1529                 rx_thresh.hthresh = res->value;
1530         else if(!strcmp(res->name, "rxwt"))
1531                 rx_thresh.wthresh = res->value;
1532         else {
1533                 printf("Unknown parameter\n");
1534                 return;
1535         }
1536
1537         init_port_config();
1538
1539         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1540 }
1541
1542 cmdline_parse_token_string_t cmd_config_thresh_port =
1543         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
1544 cmdline_parse_token_string_t cmd_config_thresh_keyword =
1545         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
1546 cmdline_parse_token_string_t cmd_config_thresh_all =
1547         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
1548 cmdline_parse_token_string_t cmd_config_thresh_name =
1549         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
1550                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
1551 cmdline_parse_token_num_t cmd_config_thresh_value =
1552         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
1553
1554 cmdline_parse_inst_t cmd_config_thresh = {
1555         .f = cmd_config_thresh_parsed,
1556         .data = NULL,
1557         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1558         .tokens = {
1559                 (void *)&cmd_config_thresh_port,
1560                 (void *)&cmd_config_thresh_keyword,
1561                 (void *)&cmd_config_thresh_all,
1562                 (void *)&cmd_config_thresh_name,
1563                 (void *)&cmd_config_thresh_value,
1564                 NULL,
1565         },
1566 };
1567
1568 /* *** configure free/rs threshold *** */
1569 struct cmd_config_threshold {
1570         cmdline_fixed_string_t port;
1571         cmdline_fixed_string_t keyword;
1572         cmdline_fixed_string_t all;
1573         cmdline_fixed_string_t name;
1574         uint16_t value;
1575 };
1576
1577 static void
1578 cmd_config_threshold_parsed(void *parsed_result,
1579                         __attribute__((unused)) struct cmdline *cl,
1580                         __attribute__((unused)) void *data)
1581 {
1582         struct cmd_config_threshold *res = parsed_result;
1583
1584         if (!all_ports_stopped()) {
1585                 printf("Please stop all ports first\n");
1586                 return;
1587         }
1588
1589         if (!strcmp(res->name, "txfreet"))
1590                 tx_free_thresh = res->value;
1591         else if (!strcmp(res->name, "txrst"))
1592                 tx_rs_thresh = res->value;
1593         else if (!strcmp(res->name, "rxfreet"))
1594                 rx_free_thresh = res->value;
1595         else {
1596                 printf("Unknown parameter\n");
1597                 return;
1598         }
1599
1600         init_port_config();
1601
1602         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1603 }
1604
1605 cmdline_parse_token_string_t cmd_config_threshold_port =
1606         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1607 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1608         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1609                                                                 "config");
1610 cmdline_parse_token_string_t cmd_config_threshold_all =
1611         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1612 cmdline_parse_token_string_t cmd_config_threshold_name =
1613         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1614                                                 "txfreet#txrst#rxfreet");
1615 cmdline_parse_token_num_t cmd_config_threshold_value =
1616         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1617
1618 cmdline_parse_inst_t cmd_config_threshold = {
1619         .f = cmd_config_threshold_parsed,
1620         .data = NULL,
1621         .help_str = "port config all txfreet|txrst|rxfreet value",
1622         .tokens = {
1623                 (void *)&cmd_config_threshold_port,
1624                 (void *)&cmd_config_threshold_keyword,
1625                 (void *)&cmd_config_threshold_all,
1626                 (void *)&cmd_config_threshold_name,
1627                 (void *)&cmd_config_threshold_value,
1628                 NULL,
1629         },
1630 };
1631
1632 /* *** stop *** */
1633 struct cmd_stop_result {
1634         cmdline_fixed_string_t stop;
1635 };
1636
1637 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1638                             __attribute__((unused)) struct cmdline *cl,
1639                             __attribute__((unused)) void *data)
1640 {
1641         stop_packet_forwarding();
1642 }
1643
1644 cmdline_parse_token_string_t cmd_stop_stop =
1645         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1646
1647 cmdline_parse_inst_t cmd_stop = {
1648         .f = cmd_stop_parsed,
1649         .data = NULL,
1650         .help_str = "stop - stop packet forwarding",
1651         .tokens = {
1652                 (void *)&cmd_stop_stop,
1653                 NULL,
1654         },
1655 };
1656
1657 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1658
1659 static unsigned int
1660 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1661                 unsigned int *parsed_items, int check_unique_values)
1662 {
1663         unsigned int nb_item;
1664         unsigned int value;
1665         unsigned int i;
1666         unsigned int j;
1667         int value_ok;
1668         char c;
1669
1670         /*
1671          * First parse all items in the list and store their value.
1672          */
1673         value = 0;
1674         nb_item = 0;
1675         value_ok = 0;
1676         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1677                 c = str[i];
1678                 if ((c >= '0') && (c <= '9')) {
1679                         value = (unsigned int) (value * 10 + (c - '0'));
1680                         value_ok = 1;
1681                         continue;
1682                 }
1683                 if (c != ',') {
1684                         printf("character %c is not a decimal digit\n", c);
1685                         return (0);
1686                 }
1687                 if (! value_ok) {
1688                         printf("No valid value before comma\n");
1689                         return (0);
1690                 }
1691                 if (nb_item < max_items) {
1692                         parsed_items[nb_item] = value;
1693                         value_ok = 0;
1694                         value = 0;
1695                 }
1696                 nb_item++;
1697         }
1698         if (nb_item >= max_items) {
1699                 printf("Number of %s = %u > %u (maximum items)\n",
1700                        item_name, nb_item + 1, max_items);
1701                 return (0);
1702         }
1703         parsed_items[nb_item++] = value;
1704         if (! check_unique_values)
1705                 return (nb_item);
1706
1707         /*
1708          * Then, check that all values in the list are differents.
1709          * No optimization here...
1710          */
1711         for (i = 0; i < nb_item; i++) {
1712                 for (j = i + 1; j < nb_item; j++) {
1713                         if (parsed_items[j] == parsed_items[i]) {
1714                                 printf("duplicated %s %u at index %u and %u\n",
1715                                        item_name, parsed_items[i], i, j);
1716                                 return (0);
1717                         }
1718                 }
1719         }
1720         return (nb_item);
1721 }
1722
1723 struct cmd_set_list_result {
1724         cmdline_fixed_string_t cmd_keyword;
1725         cmdline_fixed_string_t list_name;
1726         cmdline_fixed_string_t list_of_items;
1727 };
1728
1729 static void cmd_set_list_parsed(void *parsed_result,
1730                                 __attribute__((unused)) struct cmdline *cl,
1731                                 __attribute__((unused)) void *data)
1732 {
1733         struct cmd_set_list_result *res;
1734         union {
1735                 unsigned int lcorelist[RTE_MAX_LCORE];
1736                 unsigned int portlist[RTE_MAX_ETHPORTS];
1737         } parsed_items;
1738         unsigned int nb_item;
1739
1740         res = parsed_result;
1741         if (!strcmp(res->list_name, "corelist")) {
1742                 nb_item = parse_item_list(res->list_of_items, "core",
1743                                           RTE_MAX_LCORE,
1744                                           parsed_items.lcorelist, 1);
1745                 if (nb_item > 0)
1746                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
1747                 return;
1748         }
1749         if (!strcmp(res->list_name, "portlist")) {
1750                 nb_item = parse_item_list(res->list_of_items, "port",
1751                                           RTE_MAX_ETHPORTS,
1752                                           parsed_items.portlist, 1);
1753                 if (nb_item > 0)
1754                         set_fwd_ports_list(parsed_items.portlist, nb_item);
1755         }
1756 }
1757
1758 cmdline_parse_token_string_t cmd_set_list_keyword =
1759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
1760                                  "set");
1761 cmdline_parse_token_string_t cmd_set_list_name =
1762         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
1763                                  "corelist#portlist");
1764 cmdline_parse_token_string_t cmd_set_list_of_items =
1765         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
1766                                  NULL);
1767
1768 cmdline_parse_inst_t cmd_set_fwd_list = {
1769         .f = cmd_set_list_parsed,
1770         .data = NULL,
1771         .help_str = "set corelist|portlist x[,y]*",
1772         .tokens = {
1773                 (void *)&cmd_set_list_keyword,
1774                 (void *)&cmd_set_list_name,
1775                 (void *)&cmd_set_list_of_items,
1776                 NULL,
1777         },
1778 };
1779
1780 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
1781
1782 struct cmd_setmask_result {
1783         cmdline_fixed_string_t set;
1784         cmdline_fixed_string_t mask;
1785         uint64_t hexavalue;
1786 };
1787
1788 static void cmd_set_mask_parsed(void *parsed_result,
1789                                 __attribute__((unused)) struct cmdline *cl,
1790                                 __attribute__((unused)) void *data)
1791 {
1792         struct cmd_setmask_result *res = parsed_result;
1793
1794         if (!strcmp(res->mask, "coremask"))
1795                 set_fwd_lcores_mask(res->hexavalue);
1796         else if (!strcmp(res->mask, "portmask"))
1797                 set_fwd_ports_mask(res->hexavalue);
1798 }
1799
1800 cmdline_parse_token_string_t cmd_setmask_set =
1801         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
1802 cmdline_parse_token_string_t cmd_setmask_mask =
1803         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
1804                                  "coremask#portmask");
1805 cmdline_parse_token_num_t cmd_setmask_value =
1806         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
1807
1808 cmdline_parse_inst_t cmd_set_fwd_mask = {
1809         .f = cmd_set_mask_parsed,
1810         .data = NULL,
1811         .help_str = "set coremask|portmask hexadecimal value",
1812         .tokens = {
1813                 (void *)&cmd_setmask_set,
1814                 (void *)&cmd_setmask_mask,
1815                 (void *)&cmd_setmask_value,
1816                 NULL,
1817         },
1818 };
1819
1820 /*
1821  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
1822  */
1823 struct cmd_set_result {
1824         cmdline_fixed_string_t set;
1825         cmdline_fixed_string_t what;
1826         uint16_t value;
1827 };
1828
1829 static void cmd_set_parsed(void *parsed_result,
1830                            __attribute__((unused)) struct cmdline *cl,
1831                            __attribute__((unused)) void *data)
1832 {
1833         struct cmd_set_result *res = parsed_result;
1834         if (!strcmp(res->what, "nbport"))
1835                 set_fwd_ports_number(res->value);
1836         else if (!strcmp(res->what, "nbcore"))
1837                 set_fwd_lcores_number(res->value);
1838         else if (!strcmp(res->what, "burst"))
1839                 set_nb_pkt_per_burst(res->value);
1840         else if (!strcmp(res->what, "verbose"))
1841                 set_verbose_level(res->value);
1842 }
1843
1844 cmdline_parse_token_string_t cmd_set_set =
1845         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
1846 cmdline_parse_token_string_t cmd_set_what =
1847         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
1848                                  "nbport#nbcore#burst#verbose");
1849 cmdline_parse_token_num_t cmd_set_value =
1850         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
1851
1852 cmdline_parse_inst_t cmd_set_numbers = {
1853         .f = cmd_set_parsed,
1854         .data = NULL,
1855         .help_str = "set nbport|nbcore|burst|verbose value",
1856         .tokens = {
1857                 (void *)&cmd_set_set,
1858                 (void *)&cmd_set_what,
1859                 (void *)&cmd_set_value,
1860                 NULL,
1861         },
1862 };
1863
1864 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
1865
1866 struct cmd_set_txpkts_result {
1867         cmdline_fixed_string_t cmd_keyword;
1868         cmdline_fixed_string_t txpkts;
1869         cmdline_fixed_string_t seg_lengths;
1870 };
1871
1872 static void
1873 cmd_set_txpkts_parsed(void *parsed_result,
1874                       __attribute__((unused)) struct cmdline *cl,
1875                       __attribute__((unused)) void *data)
1876 {
1877         struct cmd_set_txpkts_result *res;
1878         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1879         unsigned int nb_segs;
1880
1881         res = parsed_result;
1882         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
1883                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1884         if (nb_segs > 0)
1885                 set_tx_pkt_segments(seg_lengths, nb_segs);
1886 }
1887
1888 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
1889         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1890                                  cmd_keyword, "set");
1891 cmdline_parse_token_string_t cmd_set_txpkts_name =
1892         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1893                                  txpkts, "txpkts");
1894 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
1895         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
1896                                  seg_lengths, NULL);
1897
1898 cmdline_parse_inst_t cmd_set_txpkts = {
1899         .f = cmd_set_txpkts_parsed,
1900         .data = NULL,
1901         .help_str = "set txpkts x[,y]*",
1902         .tokens = {
1903                 (void *)&cmd_set_txpkts_keyword,
1904                 (void *)&cmd_set_txpkts_name,
1905                 (void *)&cmd_set_txpkts_lengths,
1906                 NULL,
1907         },
1908 };
1909
1910 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
1911 struct cmd_rx_vlan_filter_all_result {
1912         cmdline_fixed_string_t rx_vlan;
1913         cmdline_fixed_string_t what;
1914         cmdline_fixed_string_t all;
1915         uint8_t port_id;
1916 };
1917
1918 static void
1919 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
1920                               __attribute__((unused)) struct cmdline *cl,
1921                               __attribute__((unused)) void *data)
1922 {
1923         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
1924
1925         if (!strcmp(res->what, "add"))
1926                 rx_vlan_all_filter_set(res->port_id, 1);
1927         else
1928                 rx_vlan_all_filter_set(res->port_id, 0);
1929 }
1930
1931 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
1932         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1933                                  rx_vlan, "rx_vlan");
1934 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
1935         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1936                                  what, "add#rm");
1937 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
1938         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1939                                  all, "all");
1940 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
1941         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
1942                               port_id, UINT8);
1943
1944 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
1945         .f = cmd_rx_vlan_filter_all_parsed,
1946         .data = NULL,
1947         .help_str = "add/remove all identifiers to/from the set of VLAN "
1948         "Identifiers filtered by a port",
1949         .tokens = {
1950                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
1951                 (void *)&cmd_rx_vlan_filter_all_what,
1952                 (void *)&cmd_rx_vlan_filter_all_all,
1953                 (void *)&cmd_rx_vlan_filter_all_portid,
1954                 NULL,
1955         },
1956 };
1957
1958 /* *** VLAN OFFLOAD SET ON A PORT *** */
1959 struct cmd_vlan_offload_result {
1960         cmdline_fixed_string_t vlan;
1961         cmdline_fixed_string_t set;
1962         cmdline_fixed_string_t what;
1963         cmdline_fixed_string_t on;
1964         cmdline_fixed_string_t port_id;
1965 };
1966
1967 static void
1968 cmd_vlan_offload_parsed(void *parsed_result,
1969                           __attribute__((unused)) struct cmdline *cl,
1970                           __attribute__((unused)) void *data)
1971 {
1972         int on;
1973         struct cmd_vlan_offload_result *res = parsed_result;
1974         char *str;
1975         int i, len = 0;
1976         portid_t port_id = 0;
1977         unsigned int tmp;
1978
1979         str = res->port_id;
1980         len = strnlen(str, STR_TOKEN_SIZE);
1981         i = 0;
1982         /* Get port_id first */
1983         while(i < len){
1984                 if(str[i] == ',')
1985                         break;
1986
1987                 i++;
1988         }
1989         str[i]='\0';
1990         tmp = strtoul(str, NULL, 0);
1991         /* If port_id greater that what portid_t can represent, return */
1992         if(tmp >= RTE_MAX_ETHPORTS)
1993                 return;
1994         port_id = (portid_t)tmp;
1995
1996         if (!strcmp(res->on, "on"))
1997                 on = 1;
1998         else
1999                 on = 0;
2000
2001         if (!strcmp(res->what, "strip"))
2002                 rx_vlan_strip_set(port_id,  on);
2003         else if(!strcmp(res->what, "stripq")){
2004                 uint16_t queue_id = 0;
2005
2006                 /* No queue_id, return */
2007                 if(i + 1 >= len)
2008                         return;
2009                 tmp = strtoul(str + i + 1, NULL, 0);
2010                 /* If queue_id greater that what 16-bits can represent, return */
2011                 if(tmp > 0xffff)
2012                         return;
2013
2014                 queue_id = (uint16_t)tmp;
2015                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2016         }
2017         else if (!strcmp(res->what, "filter"))
2018                 rx_vlan_filter_set(port_id, on);
2019         else
2020                 vlan_extend_set(port_id, on);
2021
2022         return;
2023 }
2024
2025 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2026         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2027                                  vlan, "vlan");
2028 cmdline_parse_token_string_t cmd_vlan_offload_set =
2029         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2030                                  set, "set");
2031 cmdline_parse_token_string_t cmd_vlan_offload_what =
2032         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2033                                  what, "strip#filter#qinq#stripq");
2034 cmdline_parse_token_string_t cmd_vlan_offload_on =
2035         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2036                               on, "on#off");
2037 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2038         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2039                               port_id, NULL);
2040
2041 cmdline_parse_inst_t cmd_vlan_offload = {
2042         .f = cmd_vlan_offload_parsed,
2043         .data = NULL,
2044         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2045         " qinq(extended) for both rx/tx sides ",
2046         .tokens = {
2047                 (void *)&cmd_vlan_offload_vlan,
2048                 (void *)&cmd_vlan_offload_set,
2049                 (void *)&cmd_vlan_offload_what,
2050                 (void *)&cmd_vlan_offload_on,
2051                 (void *)&cmd_vlan_offload_portid,
2052                 NULL,
2053         },
2054 };
2055
2056 /* *** VLAN TPID SET ON A PORT *** */
2057 struct cmd_vlan_tpid_result {
2058         cmdline_fixed_string_t vlan;
2059         cmdline_fixed_string_t set;
2060         cmdline_fixed_string_t what;
2061         uint16_t tp_id;
2062         uint8_t port_id;
2063 };
2064
2065 static void
2066 cmd_vlan_tpid_parsed(void *parsed_result,
2067                           __attribute__((unused)) struct cmdline *cl,
2068                           __attribute__((unused)) void *data)
2069 {
2070         struct cmd_vlan_tpid_result *res = parsed_result;
2071         vlan_tpid_set(res->port_id, res->tp_id);
2072         return;
2073 }
2074
2075 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2076         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2077                                  vlan, "vlan");
2078 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2079         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2080                                  set, "set");
2081 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2082         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2083                                  what, "tpid");
2084 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2085         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2086                               tp_id, UINT16);
2087 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2088         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2089                               port_id, UINT8);
2090
2091 cmdline_parse_inst_t cmd_vlan_tpid = {
2092         .f = cmd_vlan_tpid_parsed,
2093         .data = NULL,
2094         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2095         .tokens = {
2096                 (void *)&cmd_vlan_tpid_vlan,
2097                 (void *)&cmd_vlan_tpid_set,
2098                 (void *)&cmd_vlan_tpid_what,
2099                 (void *)&cmd_vlan_tpid_tpid,
2100                 (void *)&cmd_vlan_tpid_portid,
2101                 NULL,
2102         },
2103 };
2104
2105 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2106 struct cmd_rx_vlan_filter_result {
2107         cmdline_fixed_string_t rx_vlan;
2108         cmdline_fixed_string_t what;
2109         uint16_t vlan_id;
2110         uint8_t port_id;
2111 };
2112
2113 static void
2114 cmd_rx_vlan_filter_parsed(void *parsed_result,
2115                           __attribute__((unused)) struct cmdline *cl,
2116                           __attribute__((unused)) void *data)
2117 {
2118         struct cmd_rx_vlan_filter_result *res = parsed_result;
2119
2120         if (!strcmp(res->what, "add"))
2121                 rx_vft_set(res->port_id, res->vlan_id, 1);
2122         else
2123                 rx_vft_set(res->port_id, res->vlan_id, 0);
2124 }
2125
2126 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2127         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2128                                  rx_vlan, "rx_vlan");
2129 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2130         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2131                                  what, "add#rm");
2132 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2133         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2134                               vlan_id, UINT16);
2135 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2136         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2137                               port_id, UINT8);
2138
2139 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2140         .f = cmd_rx_vlan_filter_parsed,
2141         .data = NULL,
2142         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2143         "Identifiers filtered by a port",
2144         .tokens = {
2145                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2146                 (void *)&cmd_rx_vlan_filter_what,
2147                 (void *)&cmd_rx_vlan_filter_vlanid,
2148                 (void *)&cmd_rx_vlan_filter_portid,
2149                 NULL,
2150         },
2151 };
2152
2153 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2154 struct cmd_tx_vlan_set_result {
2155         cmdline_fixed_string_t tx_vlan;
2156         cmdline_fixed_string_t set;
2157         uint16_t vlan_id;
2158         uint8_t port_id;
2159 };
2160
2161 static void
2162 cmd_tx_vlan_set_parsed(void *parsed_result,
2163                        __attribute__((unused)) struct cmdline *cl,
2164                        __attribute__((unused)) void *data)
2165 {
2166         struct cmd_tx_vlan_set_result *res = parsed_result;
2167         tx_vlan_set(res->port_id, res->vlan_id);
2168 }
2169
2170 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2171         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2172                                  tx_vlan, "tx_vlan");
2173 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2174         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2175                                  set, "set");
2176 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2177         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2178                               vlan_id, UINT16);
2179 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2180         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2181                               port_id, UINT8);
2182
2183 cmdline_parse_inst_t cmd_tx_vlan_set = {
2184         .f = cmd_tx_vlan_set_parsed,
2185         .data = NULL,
2186         .help_str = "enable hardware insertion of a VLAN header with a given "
2187         "TAG Identifier in packets sent on a port",
2188         .tokens = {
2189                 (void *)&cmd_tx_vlan_set_tx_vlan,
2190                 (void *)&cmd_tx_vlan_set_set,
2191                 (void *)&cmd_tx_vlan_set_vlanid,
2192                 (void *)&cmd_tx_vlan_set_portid,
2193                 NULL,
2194         },
2195 };
2196
2197 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2198 struct cmd_tx_vlan_reset_result {
2199         cmdline_fixed_string_t tx_vlan;
2200         cmdline_fixed_string_t reset;
2201         uint8_t port_id;
2202 };
2203
2204 static void
2205 cmd_tx_vlan_reset_parsed(void *parsed_result,
2206                          __attribute__((unused)) struct cmdline *cl,
2207                          __attribute__((unused)) void *data)
2208 {
2209         struct cmd_tx_vlan_reset_result *res = parsed_result;
2210
2211         tx_vlan_reset(res->port_id);
2212 }
2213
2214 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2215         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2216                                  tx_vlan, "tx_vlan");
2217 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2218         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2219                                  reset, "reset");
2220 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2221         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2222                               port_id, UINT8);
2223
2224 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2225         .f = cmd_tx_vlan_reset_parsed,
2226         .data = NULL,
2227         .help_str = "disable hardware insertion of a VLAN header in packets "
2228         "sent on a port",
2229         .tokens = {
2230                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2231                 (void *)&cmd_tx_vlan_reset_reset,
2232                 (void *)&cmd_tx_vlan_reset_portid,
2233                 NULL,
2234         },
2235 };
2236
2237
2238 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2239 struct cmd_tx_cksum_set_result {
2240         cmdline_fixed_string_t tx_cksum;
2241         cmdline_fixed_string_t set;
2242         uint8_t cksum_mask;
2243         uint8_t port_id;
2244 };
2245
2246 static void
2247 cmd_tx_cksum_set_parsed(void *parsed_result,
2248                        __attribute__((unused)) struct cmdline *cl,
2249                        __attribute__((unused)) void *data)
2250 {
2251         struct cmd_tx_cksum_set_result *res = parsed_result;
2252
2253         tx_cksum_set(res->port_id, res->cksum_mask);
2254 }
2255
2256 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
2257         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2258                                 tx_cksum, "tx_checksum");
2259 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
2260         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2261                                 set, "set");
2262 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
2263         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2264                                 cksum_mask, UINT8);
2265 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
2266         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2267                                 port_id, UINT8);
2268
2269 cmdline_parse_inst_t cmd_tx_cksum_set = {
2270         .f = cmd_tx_cksum_set_parsed,
2271         .data = NULL,
2272         .help_str = "enable hardware insertion of L3/L4checksum with a given "
2273         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
2274         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
2275         .tokens = {
2276                 (void *)&cmd_tx_cksum_set_tx_cksum,
2277                 (void *)&cmd_tx_cksum_set_set,
2278                 (void *)&cmd_tx_cksum_set_cksum_mask,
2279                 (void *)&cmd_tx_cksum_set_portid,
2280                 NULL,
2281         },
2282 };
2283
2284 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
2285 struct cmd_set_flush_rx {
2286         cmdline_fixed_string_t set;
2287         cmdline_fixed_string_t flush_rx;
2288         cmdline_fixed_string_t mode;
2289 };
2290
2291 static void
2292 cmd_set_flush_rx_parsed(void *parsed_result,
2293                 __attribute__((unused)) struct cmdline *cl,
2294                 __attribute__((unused)) void *data)
2295 {
2296         struct cmd_set_flush_rx *res = parsed_result;
2297         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2298 }
2299
2300 cmdline_parse_token_string_t cmd_setflushrx_set =
2301         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2302                         set, "set");
2303 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
2304         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2305                         flush_rx, "flush_rx");
2306 cmdline_parse_token_string_t cmd_setflushrx_mode =
2307         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2308                         mode, "on#off");
2309
2310
2311 cmdline_parse_inst_t cmd_set_flush_rx = {
2312         .f = cmd_set_flush_rx_parsed,
2313         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
2314         .data = NULL,
2315         .tokens = {
2316                 (void *)&cmd_setflushrx_set,
2317                 (void *)&cmd_setflushrx_flush_rx,
2318                 (void *)&cmd_setflushrx_mode,
2319                 NULL,
2320         },
2321 };
2322
2323 #ifdef RTE_NIC_BYPASS
2324 /* *** SET NIC BYPASS MODE *** */
2325 struct cmd_set_bypass_mode_result {
2326         cmdline_fixed_string_t set;
2327         cmdline_fixed_string_t bypass;
2328         cmdline_fixed_string_t mode;
2329         cmdline_fixed_string_t value;
2330         uint8_t port_id;
2331 };
2332
2333 static void
2334 cmd_set_bypass_mode_parsed(void *parsed_result,
2335                 __attribute__((unused)) struct cmdline *cl,
2336                 __attribute__((unused)) void *data)
2337 {
2338         struct cmd_set_bypass_mode_result *res = parsed_result;
2339         portid_t port_id = res->port_id;
2340         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2341
2342         if (!bypass_is_supported(port_id))
2343                 return;
2344
2345         if (!strcmp(res->value, "bypass"))
2346                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2347         else if (!strcmp(res->value, "isolate"))
2348                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2349         else
2350                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2351
2352         /* Set the bypass mode for the relevant port. */
2353         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
2354                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
2355         }
2356 }
2357
2358 cmdline_parse_token_string_t cmd_setbypass_mode_set =
2359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2360                         set, "set");
2361 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
2362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2363                         bypass, "bypass");
2364 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
2365         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2366                         mode, "mode");
2367 cmdline_parse_token_string_t cmd_setbypass_mode_value =
2368         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2369                         value, "normal#bypass#isolate");
2370 cmdline_parse_token_num_t cmd_setbypass_mode_port =
2371         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
2372                                 port_id, UINT8);
2373
2374 cmdline_parse_inst_t cmd_set_bypass_mode = {
2375         .f = cmd_set_bypass_mode_parsed,
2376         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
2377                     "Set the NIC bypass mode for port_id",
2378         .data = NULL,
2379         .tokens = {
2380                 (void *)&cmd_setbypass_mode_set,
2381                 (void *)&cmd_setbypass_mode_bypass,
2382                 (void *)&cmd_setbypass_mode_mode,
2383                 (void *)&cmd_setbypass_mode_value,
2384                 (void *)&cmd_setbypass_mode_port,
2385                 NULL,
2386         },
2387 };
2388
2389 /* *** SET NIC BYPASS EVENT *** */
2390 struct cmd_set_bypass_event_result {
2391         cmdline_fixed_string_t set;
2392         cmdline_fixed_string_t bypass;
2393         cmdline_fixed_string_t event;
2394         cmdline_fixed_string_t event_value;
2395         cmdline_fixed_string_t mode;
2396         cmdline_fixed_string_t mode_value;
2397         uint8_t port_id;
2398 };
2399
2400 static void
2401 cmd_set_bypass_event_parsed(void *parsed_result,
2402                 __attribute__((unused)) struct cmdline *cl,
2403                 __attribute__((unused)) void *data)
2404 {
2405         int32_t rc;
2406         struct cmd_set_bypass_event_result *res = parsed_result;
2407         portid_t port_id = res->port_id;
2408         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
2409         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2410
2411         if (!bypass_is_supported(port_id))
2412                 return;
2413
2414         if (!strcmp(res->event_value, "timeout"))
2415                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
2416         else if (!strcmp(res->event_value, "os_on"))
2417                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
2418         else if (!strcmp(res->event_value, "os_off"))
2419                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
2420         else if (!strcmp(res->event_value, "power_on"))
2421                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
2422         else if (!strcmp(res->event_value, "power_off"))
2423                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
2424         else
2425                 bypass_event = RTE_BYPASS_EVENT_NONE;
2426
2427         if (!strcmp(res->mode_value, "bypass"))
2428                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2429         else if (!strcmp(res->mode_value, "isolate"))
2430                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2431         else
2432                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2433
2434         /* Set the watchdog timeout. */
2435         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
2436
2437                 rc = -EINVAL;
2438                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
2439                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
2440                                 bypass_timeout)) != 0) {
2441                         printf("Failed to set timeout value %u "
2442                                 "for port %d, errto code: %d.\n",
2443                                 bypass_timeout, port_id, rc);
2444                 }
2445         }
2446
2447         /* Set the bypass event to transition to bypass mode. */
2448         if (0 != rte_eth_dev_bypass_event_store(port_id,
2449                         bypass_event, bypass_mode)) {
2450                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
2451         }
2452
2453 }
2454
2455 cmdline_parse_token_string_t cmd_setbypass_event_set =
2456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2457                         set, "set");
2458 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
2459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2460                         bypass, "bypass");
2461 cmdline_parse_token_string_t cmd_setbypass_event_event =
2462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2463                         event, "event");
2464 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
2465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2466                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
2467 cmdline_parse_token_string_t cmd_setbypass_event_mode =
2468         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2469                         mode, "mode");
2470 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
2471         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2472                         mode_value, "normal#bypass#isolate");
2473 cmdline_parse_token_num_t cmd_setbypass_event_port =
2474         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
2475                                 port_id, UINT8);
2476
2477 cmdline_parse_inst_t cmd_set_bypass_event = {
2478         .f = cmd_set_bypass_event_parsed,
2479         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
2480                     "mode (normal|bypass|isolate) (port_id): "
2481                     "Set the NIC bypass event mode for port_id",
2482         .data = NULL,
2483         .tokens = {
2484                 (void *)&cmd_setbypass_event_set,
2485                 (void *)&cmd_setbypass_event_bypass,
2486                 (void *)&cmd_setbypass_event_event,
2487                 (void *)&cmd_setbypass_event_event_value,
2488                 (void *)&cmd_setbypass_event_mode,
2489                 (void *)&cmd_setbypass_event_mode_value,
2490                 (void *)&cmd_setbypass_event_port,
2491                 NULL,
2492         },
2493 };
2494
2495
2496 /* *** SET NIC BYPASS TIMEOUT *** */
2497 struct cmd_set_bypass_timeout_result {
2498         cmdline_fixed_string_t set;
2499         cmdline_fixed_string_t bypass;
2500         cmdline_fixed_string_t timeout;
2501         cmdline_fixed_string_t value;
2502 };
2503
2504 static void
2505 cmd_set_bypass_timeout_parsed(void *parsed_result,
2506                 __attribute__((unused)) struct cmdline *cl,
2507                 __attribute__((unused)) void *data)
2508 {
2509         struct cmd_set_bypass_timeout_result *res = parsed_result;
2510
2511         if (!strcmp(res->value, "1.5"))
2512                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
2513         else if (!strcmp(res->value, "2"))
2514                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
2515         else if (!strcmp(res->value, "3"))
2516                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
2517         else if (!strcmp(res->value, "4"))
2518                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
2519         else if (!strcmp(res->value, "8"))
2520                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
2521         else if (!strcmp(res->value, "16"))
2522                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
2523         else if (!strcmp(res->value, "32"))
2524                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
2525         else
2526                 bypass_timeout = RTE_BYPASS_TMT_OFF;
2527 }
2528
2529 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
2530         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2531                         set, "set");
2532 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
2533         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2534                         bypass, "bypass");
2535 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
2536         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2537                         timeout, "timeout");
2538 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
2539         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2540                         value, "0#1.5#2#3#4#8#16#32");
2541
2542 cmdline_parse_inst_t cmd_set_bypass_timeout = {
2543         .f = cmd_set_bypass_timeout_parsed,
2544         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
2545                     "Set the NIC bypass watchdog timeout",
2546         .data = NULL,
2547         .tokens = {
2548                 (void *)&cmd_setbypass_timeout_set,
2549                 (void *)&cmd_setbypass_timeout_bypass,
2550                 (void *)&cmd_setbypass_timeout_timeout,
2551                 (void *)&cmd_setbypass_timeout_value,
2552                 NULL,
2553         },
2554 };
2555
2556 /* *** SHOW NIC BYPASS MODE *** */
2557 struct cmd_show_bypass_config_result {
2558         cmdline_fixed_string_t show;
2559         cmdline_fixed_string_t bypass;
2560         cmdline_fixed_string_t config;
2561         uint8_t port_id;
2562 };
2563
2564 static void
2565 cmd_show_bypass_config_parsed(void *parsed_result,
2566                 __attribute__((unused)) struct cmdline *cl,
2567                 __attribute__((unused)) void *data)
2568 {
2569         struct cmd_show_bypass_config_result *res = parsed_result;
2570         uint32_t event_mode;
2571         uint32_t bypass_mode;
2572         portid_t port_id = res->port_id;
2573         uint32_t timeout = bypass_timeout;
2574         int i;
2575
2576         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
2577                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
2578         static const char * const modes[RTE_BYPASS_MODE_NUM] =
2579                 {"UNKNOWN", "normal", "bypass", "isolate"};
2580         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
2581                 "NONE",
2582                 "OS/board on",
2583                 "power supply on",
2584                 "OS/board off",
2585                 "power supply off",
2586                 "timeout"};
2587         int num_events = (sizeof events) / (sizeof events[0]);
2588
2589         if (!bypass_is_supported(port_id))
2590                 return;
2591
2592         /* Display the bypass mode.*/
2593         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
2594                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
2595                 return;
2596         }
2597         else {
2598                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
2599                         bypass_mode = RTE_BYPASS_MODE_NONE;
2600
2601                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
2602         }
2603
2604         /* Display the bypass timeout.*/
2605         if (!RTE_BYPASS_TMT_VALID(timeout))
2606                 timeout = RTE_BYPASS_TMT_OFF;
2607
2608         printf("\tbypass timeout = %s\n", timeouts[timeout]);
2609
2610         /* Display the bypass events and associated modes. */
2611         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
2612
2613                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
2614                         printf("\tFailed to get bypass mode for event = %s\n",
2615                                 events[i]);
2616                 } else {
2617                         if (!RTE_BYPASS_MODE_VALID(event_mode))
2618                                 event_mode = RTE_BYPASS_MODE_NONE;
2619
2620                         printf("\tbypass event: %-16s = %s\n", events[i],
2621                                 modes[event_mode]);
2622                 }
2623         }
2624 }
2625
2626 cmdline_parse_token_string_t cmd_showbypass_config_show =
2627         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2628                         show, "show");
2629 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
2630         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2631                         bypass, "bypass");
2632 cmdline_parse_token_string_t cmd_showbypass_config_config =
2633         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2634                         config, "config");
2635 cmdline_parse_token_num_t cmd_showbypass_config_port =
2636         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
2637                                 port_id, UINT8);
2638
2639 cmdline_parse_inst_t cmd_show_bypass_config = {
2640         .f = cmd_show_bypass_config_parsed,
2641         .help_str = "show bypass config (port_id): "
2642                     "Show the NIC bypass config for port_id",
2643         .data = NULL,
2644         .tokens = {
2645                 (void *)&cmd_showbypass_config_show,
2646                 (void *)&cmd_showbypass_config_bypass,
2647                 (void *)&cmd_showbypass_config_config,
2648                 (void *)&cmd_showbypass_config_port,
2649                 NULL,
2650         },
2651 };
2652 #endif
2653
2654 /* *** SET FORWARDING MODE *** */
2655 struct cmd_set_fwd_mode_result {
2656         cmdline_fixed_string_t set;
2657         cmdline_fixed_string_t fwd;
2658         cmdline_fixed_string_t mode;
2659 };
2660
2661 static void cmd_set_fwd_mode_parsed(void *parsed_result,
2662                                     __attribute__((unused)) struct cmdline *cl,
2663                                     __attribute__((unused)) void *data)
2664 {
2665         struct cmd_set_fwd_mode_result *res = parsed_result;
2666
2667         set_pkt_forwarding_mode(res->mode);
2668 }
2669
2670 cmdline_parse_token_string_t cmd_setfwd_set =
2671         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
2672 cmdline_parse_token_string_t cmd_setfwd_fwd =
2673         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
2674 cmdline_parse_token_string_t cmd_setfwd_mode =
2675         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
2676 #ifdef RTE_LIBRTE_IEEE1588
2677                                  "io#mac#rxonly#txonly#csum#ieee1588");
2678 #else
2679                                  "io#mac#rxonly#txonly#csum");
2680 #endif
2681
2682 cmdline_parse_inst_t cmd_set_fwd_mode = {
2683         .f = cmd_set_fwd_mode_parsed,
2684         .data = NULL,
2685 #ifdef RTE_LIBRTE_IEEE1588
2686         .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
2687         " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
2688 #else
2689         .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC,"
2690         " RXONLY, CSUM or TXONLY packet forwarding mode",
2691 #endif
2692         .tokens = {
2693                 (void *)&cmd_setfwd_set,
2694                 (void *)&cmd_setfwd_fwd,
2695                 (void *)&cmd_setfwd_mode,
2696                 NULL,
2697         },
2698 };
2699
2700 /* *** SET PROMISC MODE *** */
2701 struct cmd_set_promisc_mode_result {
2702         cmdline_fixed_string_t set;
2703         cmdline_fixed_string_t promisc;
2704         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2705         uint8_t port_num;                /* valid if "allports" argument == 0 */
2706         cmdline_fixed_string_t mode;
2707 };
2708
2709 static void cmd_set_promisc_mode_parsed(void *parsed_result,
2710                                         __attribute__((unused)) struct cmdline *cl,
2711                                         void *allports)
2712 {
2713         struct cmd_set_promisc_mode_result *res = parsed_result;
2714         int enable;
2715         portid_t i;
2716
2717         if (!strcmp(res->mode, "on"))
2718                 enable = 1;
2719         else
2720                 enable = 0;
2721
2722         /* all ports */
2723         if (allports) {
2724                 for (i = 0; i < nb_ports; i++) {
2725                         if (enable)
2726                                 rte_eth_promiscuous_enable(i);
2727                         else
2728                                 rte_eth_promiscuous_disable(i);
2729                 }
2730         }
2731         else {
2732                 if (enable)
2733                         rte_eth_promiscuous_enable(res->port_num);
2734                 else
2735                         rte_eth_promiscuous_disable(res->port_num);
2736         }
2737 }
2738
2739 cmdline_parse_token_string_t cmd_setpromisc_set =
2740         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
2741 cmdline_parse_token_string_t cmd_setpromisc_promisc =
2742         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
2743                                  "promisc");
2744 cmdline_parse_token_string_t cmd_setpromisc_portall =
2745         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
2746                                  "all");
2747 cmdline_parse_token_num_t cmd_setpromisc_portnum =
2748         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
2749                               UINT8);
2750 cmdline_parse_token_string_t cmd_setpromisc_mode =
2751         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
2752                                  "on#off");
2753
2754 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
2755         .f = cmd_set_promisc_mode_parsed,
2756         .data = (void *)1,
2757         .help_str = "set promisc all on|off: set promisc mode for all ports",
2758         .tokens = {
2759                 (void *)&cmd_setpromisc_set,
2760                 (void *)&cmd_setpromisc_promisc,
2761                 (void *)&cmd_setpromisc_portall,
2762                 (void *)&cmd_setpromisc_mode,
2763                 NULL,
2764         },
2765 };
2766
2767 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
2768         .f = cmd_set_promisc_mode_parsed,
2769         .data = (void *)0,
2770         .help_str = "set promisc X on|off: set promisc mode on port X",
2771         .tokens = {
2772                 (void *)&cmd_setpromisc_set,
2773                 (void *)&cmd_setpromisc_promisc,
2774                 (void *)&cmd_setpromisc_portnum,
2775                 (void *)&cmd_setpromisc_mode,
2776                 NULL,
2777         },
2778 };
2779
2780 /* *** SET ALLMULTI MODE *** */
2781 struct cmd_set_allmulti_mode_result {
2782         cmdline_fixed_string_t set;
2783         cmdline_fixed_string_t allmulti;
2784         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2785         uint8_t port_num;                /* valid if "allports" argument == 0 */
2786         cmdline_fixed_string_t mode;
2787 };
2788
2789 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
2790                                         __attribute__((unused)) struct cmdline *cl,
2791                                         void *allports)
2792 {
2793         struct cmd_set_allmulti_mode_result *res = parsed_result;
2794         int enable;
2795         portid_t i;
2796
2797         if (!strcmp(res->mode, "on"))
2798                 enable = 1;
2799         else
2800                 enable = 0;
2801
2802         /* all ports */
2803         if (allports) {
2804                 for (i = 0; i < nb_ports; i++) {
2805                         if (enable)
2806                                 rte_eth_allmulticast_enable(i);
2807                         else
2808                                 rte_eth_allmulticast_disable(i);
2809                 }
2810         }
2811         else {
2812                 if (enable)
2813                         rte_eth_allmulticast_enable(res->port_num);
2814                 else
2815                         rte_eth_allmulticast_disable(res->port_num);
2816         }
2817 }
2818
2819 cmdline_parse_token_string_t cmd_setallmulti_set =
2820         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
2821 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
2822         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
2823                                  "allmulti");
2824 cmdline_parse_token_string_t cmd_setallmulti_portall =
2825         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
2826                                  "all");
2827 cmdline_parse_token_num_t cmd_setallmulti_portnum =
2828         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
2829                               UINT8);
2830 cmdline_parse_token_string_t cmd_setallmulti_mode =
2831         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
2832                                  "on#off");
2833
2834 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
2835         .f = cmd_set_allmulti_mode_parsed,
2836         .data = (void *)1,
2837         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
2838         .tokens = {
2839                 (void *)&cmd_setallmulti_set,
2840                 (void *)&cmd_setallmulti_allmulti,
2841                 (void *)&cmd_setallmulti_portall,
2842                 (void *)&cmd_setallmulti_mode,
2843                 NULL,
2844         },
2845 };
2846
2847 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
2848         .f = cmd_set_allmulti_mode_parsed,
2849         .data = (void *)0,
2850         .help_str = "set allmulti X on|off: set allmulti mode on port X",
2851         .tokens = {
2852                 (void *)&cmd_setallmulti_set,
2853                 (void *)&cmd_setallmulti_allmulti,
2854                 (void *)&cmd_setallmulti_portnum,
2855                 (void *)&cmd_setallmulti_mode,
2856                 NULL,
2857         },
2858 };
2859
2860 /* *** ADD/REMOVE A PKT FILTER *** */
2861 struct cmd_pkt_filter_result {
2862         cmdline_fixed_string_t pkt_filter;
2863         uint8_t  port_id;
2864         cmdline_fixed_string_t protocol;
2865         cmdline_fixed_string_t src;
2866         cmdline_ipaddr_t ip_src;
2867         uint16_t port_src;
2868         cmdline_fixed_string_t dst;
2869         cmdline_ipaddr_t ip_dst;
2870         uint16_t port_dst;
2871         cmdline_fixed_string_t flexbytes;
2872         uint16_t flexbytes_value;
2873         cmdline_fixed_string_t vlan;
2874         uint16_t  vlan_id;
2875         cmdline_fixed_string_t queue;
2876         int8_t  queue_id;
2877         cmdline_fixed_string_t soft;
2878         uint8_t  soft_id;
2879 };
2880
2881 static void
2882 cmd_pkt_filter_parsed(void *parsed_result,
2883                           __attribute__((unused)) struct cmdline *cl,
2884                           __attribute__((unused)) void *data)
2885 {
2886         struct rte_fdir_filter fdir_filter;
2887         struct cmd_pkt_filter_result *res = parsed_result;
2888
2889         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
2890
2891         if (res->ip_src.family == AF_INET)
2892                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
2893         else
2894                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
2895                        &(res->ip_src.addr.ipv6),
2896                        sizeof(struct in6_addr));
2897
2898         if (res->ip_dst.family == AF_INET)
2899                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
2900         else
2901                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
2902                        &(res->ip_dst.addr.ipv6),
2903                        sizeof(struct in6_addr));
2904
2905         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
2906         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
2907
2908         if (!strcmp(res->protocol, "udp"))
2909                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
2910         else if (!strcmp(res->protocol, "tcp"))
2911                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
2912         else if (!strcmp(res->protocol, "sctp"))
2913                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
2914         else /* default only IP */
2915                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
2916
2917         if (res->ip_dst.family == AF_INET6)
2918                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
2919         else
2920                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
2921
2922         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
2923         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
2924
2925         if (!strcmp(res->pkt_filter, "add_signature_filter"))
2926                 fdir_add_signature_filter(res->port_id, res->queue_id,
2927                                           &fdir_filter);
2928         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
2929                 fdir_update_signature_filter(res->port_id, res->queue_id,
2930                                              &fdir_filter);
2931         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
2932                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
2933         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
2934                 fdir_add_perfect_filter(res->port_id, res->soft_id,
2935                                         res->queue_id,
2936                                         (uint8_t) (res->queue_id < 0),
2937                                         &fdir_filter);
2938         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
2939                 fdir_update_perfect_filter(res->port_id, res->soft_id,
2940                                            res->queue_id,
2941                                            (uint8_t) (res->queue_id < 0),
2942                                            &fdir_filter);
2943         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
2944                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
2945                                            &fdir_filter);
2946
2947 }
2948
2949
2950 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
2951         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2952                               port_id, UINT8);
2953 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
2954         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2955                                  protocol, "ip#tcp#udp#sctp");
2956 cmdline_parse_token_string_t cmd_pkt_filter_src =
2957         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2958                                  src, "src");
2959 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
2960         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2961                                  ip_src);
2962 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
2963         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2964                               port_src, UINT16);
2965 cmdline_parse_token_string_t cmd_pkt_filter_dst =
2966         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2967                                  dst, "dst");
2968 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
2969         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
2970                                  ip_dst);
2971 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
2972         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2973                               port_dst, UINT16);
2974 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
2975         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2976                                  flexbytes, "flexbytes");
2977 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
2978         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2979                               flexbytes_value, UINT16);
2980 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
2981         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2982                                  vlan, "vlan");
2983 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
2984         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2985                               vlan_id, UINT16);
2986 cmdline_parse_token_string_t cmd_pkt_filter_queue =
2987         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2988                                  queue, "queue");
2989 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
2990         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2991                               queue_id, INT8);
2992 cmdline_parse_token_string_t cmd_pkt_filter_soft =
2993         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
2994                                  soft, "soft");
2995 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
2996         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
2997                               soft_id, UINT16);
2998
2999
3000 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
3001         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3002                                  pkt_filter, "add_signature_filter");
3003 cmdline_parse_inst_t cmd_add_signature_filter = {
3004         .f = cmd_pkt_filter_parsed,
3005         .data = NULL,
3006         .help_str = "add a signature filter",
3007         .tokens = {
3008                 (void *)&cmd_pkt_filter_add_signature_filter,
3009                 (void *)&cmd_pkt_filter_port_id,
3010                 (void *)&cmd_pkt_filter_protocol,
3011                 (void *)&cmd_pkt_filter_src,
3012                 (void *)&cmd_pkt_filter_ip_src,
3013                 (void *)&cmd_pkt_filter_port_src,
3014                 (void *)&cmd_pkt_filter_dst,
3015                 (void *)&cmd_pkt_filter_ip_dst,
3016                 (void *)&cmd_pkt_filter_port_dst,
3017                 (void *)&cmd_pkt_filter_flexbytes,
3018                 (void *)&cmd_pkt_filter_flexbytes_value,
3019                 (void *)&cmd_pkt_filter_vlan,
3020                 (void *)&cmd_pkt_filter_vlan_id,
3021                 (void *)&cmd_pkt_filter_queue,
3022                 (void *)&cmd_pkt_filter_queue_id,
3023                 NULL,
3024         },
3025 };
3026
3027
3028 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
3029         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3030                                  pkt_filter, "upd_signature_filter");
3031 cmdline_parse_inst_t cmd_upd_signature_filter = {
3032         .f = cmd_pkt_filter_parsed,
3033         .data = NULL,
3034         .help_str = "update a signature filter",
3035         .tokens = {
3036                 (void *)&cmd_pkt_filter_upd_signature_filter,
3037                 (void *)&cmd_pkt_filter_port_id,
3038                 (void *)&cmd_pkt_filter_protocol,
3039                 (void *)&cmd_pkt_filter_src,
3040                 (void *)&cmd_pkt_filter_ip_src,
3041                 (void *)&cmd_pkt_filter_port_src,
3042                 (void *)&cmd_pkt_filter_dst,
3043                 (void *)&cmd_pkt_filter_ip_dst,
3044                 (void *)&cmd_pkt_filter_port_dst,
3045                 (void *)&cmd_pkt_filter_flexbytes,
3046                 (void *)&cmd_pkt_filter_flexbytes_value,
3047                 (void *)&cmd_pkt_filter_vlan,
3048                 (void *)&cmd_pkt_filter_vlan_id,
3049                 (void *)&cmd_pkt_filter_queue,
3050                 (void *)&cmd_pkt_filter_queue_id,
3051                 NULL,
3052         },
3053 };
3054
3055
3056 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
3057         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3058                                  pkt_filter, "rm_signature_filter");
3059 cmdline_parse_inst_t cmd_rm_signature_filter = {
3060         .f = cmd_pkt_filter_parsed,
3061         .data = NULL,
3062         .help_str = "remove a signature filter",
3063         .tokens = {
3064                 (void *)&cmd_pkt_filter_rm_signature_filter,
3065                 (void *)&cmd_pkt_filter_port_id,
3066                 (void *)&cmd_pkt_filter_protocol,
3067                 (void *)&cmd_pkt_filter_src,
3068                 (void *)&cmd_pkt_filter_ip_src,
3069                 (void *)&cmd_pkt_filter_port_src,
3070                 (void *)&cmd_pkt_filter_dst,
3071                 (void *)&cmd_pkt_filter_ip_dst,
3072                 (void *)&cmd_pkt_filter_port_dst,
3073                 (void *)&cmd_pkt_filter_flexbytes,
3074                 (void *)&cmd_pkt_filter_flexbytes_value,
3075                 (void *)&cmd_pkt_filter_vlan,
3076                 (void *)&cmd_pkt_filter_vlan_id,
3077                 NULL
3078                 },
3079 };
3080
3081
3082 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
3083         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3084                                  pkt_filter, "add_perfect_filter");
3085 cmdline_parse_inst_t cmd_add_perfect_filter = {
3086         .f = cmd_pkt_filter_parsed,
3087         .data = NULL,
3088         .help_str = "add a perfect filter",
3089         .tokens = {
3090                 (void *)&cmd_pkt_filter_add_perfect_filter,
3091                 (void *)&cmd_pkt_filter_port_id,
3092                 (void *)&cmd_pkt_filter_protocol,
3093                 (void *)&cmd_pkt_filter_src,
3094                 (void *)&cmd_pkt_filter_ip_src,
3095                 (void *)&cmd_pkt_filter_port_src,
3096                 (void *)&cmd_pkt_filter_dst,
3097                 (void *)&cmd_pkt_filter_ip_dst,
3098                 (void *)&cmd_pkt_filter_port_dst,
3099                 (void *)&cmd_pkt_filter_flexbytes,
3100                 (void *)&cmd_pkt_filter_flexbytes_value,
3101                 (void *)&cmd_pkt_filter_vlan,
3102                 (void *)&cmd_pkt_filter_vlan_id,
3103                 (void *)&cmd_pkt_filter_queue,
3104                 (void *)&cmd_pkt_filter_queue_id,
3105                 (void *)&cmd_pkt_filter_soft,
3106                 (void *)&cmd_pkt_filter_soft_id,
3107                 NULL,
3108         },
3109 };
3110
3111
3112 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
3113         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3114                                  pkt_filter, "upd_perfect_filter");
3115 cmdline_parse_inst_t cmd_upd_perfect_filter = {
3116         .f = cmd_pkt_filter_parsed,
3117         .data = NULL,
3118         .help_str = "update a perfect filter",
3119         .tokens = {
3120                 (void *)&cmd_pkt_filter_upd_perfect_filter,
3121                 (void *)&cmd_pkt_filter_port_id,
3122                 (void *)&cmd_pkt_filter_protocol,
3123                 (void *)&cmd_pkt_filter_src,
3124                 (void *)&cmd_pkt_filter_ip_src,
3125                 (void *)&cmd_pkt_filter_port_src,
3126                 (void *)&cmd_pkt_filter_dst,
3127                 (void *)&cmd_pkt_filter_ip_dst,
3128                 (void *)&cmd_pkt_filter_port_dst,
3129                 (void *)&cmd_pkt_filter_flexbytes,
3130                 (void *)&cmd_pkt_filter_flexbytes_value,
3131                 (void *)&cmd_pkt_filter_vlan,
3132                 (void *)&cmd_pkt_filter_vlan_id,
3133                 (void *)&cmd_pkt_filter_queue,
3134                 (void *)&cmd_pkt_filter_queue_id,
3135                 (void *)&cmd_pkt_filter_soft,
3136                 (void *)&cmd_pkt_filter_soft_id,
3137                 NULL,
3138         },
3139 };
3140
3141
3142 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
3143         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3144                                  pkt_filter, "rm_perfect_filter");
3145 cmdline_parse_inst_t cmd_rm_perfect_filter = {
3146         .f = cmd_pkt_filter_parsed,
3147         .data = NULL,
3148         .help_str = "remove a perfect filter",
3149         .tokens = {
3150                 (void *)&cmd_pkt_filter_rm_perfect_filter,
3151                 (void *)&cmd_pkt_filter_port_id,
3152                 (void *)&cmd_pkt_filter_protocol,
3153                 (void *)&cmd_pkt_filter_src,
3154                 (void *)&cmd_pkt_filter_ip_src,
3155                 (void *)&cmd_pkt_filter_port_src,
3156                 (void *)&cmd_pkt_filter_dst,
3157                 (void *)&cmd_pkt_filter_ip_dst,
3158                 (void *)&cmd_pkt_filter_port_dst,
3159                 (void *)&cmd_pkt_filter_flexbytes,
3160                 (void *)&cmd_pkt_filter_flexbytes_value,
3161                 (void *)&cmd_pkt_filter_vlan,
3162                 (void *)&cmd_pkt_filter_vlan_id,
3163                 (void *)&cmd_pkt_filter_soft,
3164                 (void *)&cmd_pkt_filter_soft_id,
3165                 NULL,
3166         },
3167 };
3168
3169 /* *** SETUP MASKS FILTER *** */
3170 struct cmd_pkt_filter_masks_result {
3171         cmdline_fixed_string_t filter_mask;
3172         uint8_t  port_id;
3173         cmdline_fixed_string_t src_mask;
3174         uint32_t ip_src_mask;
3175         uint16_t ipv6_src_mask;
3176         uint16_t port_src_mask;
3177         cmdline_fixed_string_t dst_mask;
3178         uint32_t ip_dst_mask;
3179         uint16_t ipv6_dst_mask;
3180         uint16_t port_dst_mask;
3181         cmdline_fixed_string_t flexbytes;
3182         uint8_t flexbytes_value;
3183         cmdline_fixed_string_t vlan_id;
3184         uint8_t  vlan_id_value;
3185         cmdline_fixed_string_t vlan_prio;
3186         uint8_t  vlan_prio_value;
3187         cmdline_fixed_string_t only_ip_flow;
3188         uint8_t  only_ip_flow_value;
3189         cmdline_fixed_string_t comp_ipv6_dst;
3190         uint8_t  comp_ipv6_dst_value;
3191 };
3192
3193 static void
3194 cmd_pkt_filter_masks_parsed(void *parsed_result,
3195                           __attribute__((unused)) struct cmdline *cl,
3196                           __attribute__((unused)) void *data)
3197 {
3198         struct rte_fdir_masks fdir_masks;
3199         struct cmd_pkt_filter_masks_result *res = parsed_result;
3200
3201         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3202
3203         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3204         fdir_masks.vlan_id       = res->vlan_id_value;
3205         fdir_masks.vlan_prio     = res->vlan_prio_value;
3206         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
3207         fdir_masks.src_ipv4_mask = res->ip_src_mask;
3208         fdir_masks.src_port_mask = res->port_src_mask;
3209         fdir_masks.dst_port_mask = res->port_dst_mask;
3210         fdir_masks.flexbytes     = res->flexbytes_value;
3211
3212         fdir_set_masks(res->port_id, &fdir_masks);
3213 }
3214
3215 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
3216         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3217                                  filter_mask, "set_masks_filter");
3218 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
3219         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3220                               port_id, UINT8);
3221 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
3222         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3223                                  only_ip_flow, "only_ip_flow");
3224 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
3225         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3226                               only_ip_flow_value, UINT8);
3227 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
3228         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3229                                  src_mask, "src_mask");
3230 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
3231         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3232                               ip_src_mask, UINT32);
3233 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
3234         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3235                               port_src_mask, UINT16);
3236 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
3237         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3238                                  dst_mask, "dst_mask");
3239 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
3240         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3241                               ip_dst_mask, UINT32);
3242 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
3243         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3244                               port_dst_mask, UINT16);
3245 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
3246         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3247                                  flexbytes, "flexbytes");
3248 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
3249         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3250                               flexbytes_value, UINT8);
3251 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
3252         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3253                                  vlan_id, "vlan_id");
3254 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
3255         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3256                               vlan_id_value, UINT8);
3257 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
3258         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3259                                  vlan_prio, "vlan_prio");
3260 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
3261         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3262                               vlan_prio_value, UINT8);
3263
3264 cmdline_parse_inst_t cmd_set_masks_filter = {
3265         .f = cmd_pkt_filter_masks_parsed,
3266         .data = NULL,
3267         .help_str = "setup masks filter",
3268         .tokens = {
3269                 (void *)&cmd_pkt_filter_masks_filter_mask,
3270                 (void *)&cmd_pkt_filter_masks_port_id,
3271                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3272                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3273                 (void *)&cmd_pkt_filter_masks_src_mask,
3274                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
3275                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3276                 (void *)&cmd_pkt_filter_masks_dst_mask,
3277                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
3278                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3279                 (void *)&cmd_pkt_filter_masks_flexbytes,
3280                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3281                 (void *)&cmd_pkt_filter_masks_vlan_id,
3282                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3283                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3284                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3285                 NULL,
3286         },
3287 };
3288
3289 static void
3290 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
3291                           __attribute__((unused)) struct cmdline *cl,
3292                           __attribute__((unused)) void *data)
3293 {
3294         struct rte_fdir_masks fdir_masks;
3295         struct cmd_pkt_filter_masks_result *res = parsed_result;
3296
3297         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3298
3299         fdir_masks.set_ipv6_mask = 1;
3300         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3301         fdir_masks.vlan_id       = res->vlan_id_value;
3302         fdir_masks.vlan_prio     = res->vlan_prio_value;
3303         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
3304         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
3305         fdir_masks.src_port_mask = res->port_src_mask;
3306         fdir_masks.dst_port_mask = res->port_dst_mask;
3307         fdir_masks.flexbytes     = res->flexbytes_value;
3308         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
3309
3310         fdir_set_masks(res->port_id, &fdir_masks);
3311 }
3312
3313 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
3314         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3315                                  filter_mask, "set_ipv6_masks_filter");
3316 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
3317         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3318                               ipv6_src_mask, UINT16);
3319 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
3320         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3321                               ipv6_dst_mask, UINT16);
3322
3323 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
3324         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3325                                  comp_ipv6_dst, "compare_dst");
3326 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
3327         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3328                               comp_ipv6_dst_value, UINT8);
3329
3330 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
3331         .f = cmd_pkt_filter_masks_ipv6_parsed,
3332         .data = NULL,
3333         .help_str = "setup ipv6 masks filter",
3334         .tokens = {
3335                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
3336                 (void *)&cmd_pkt_filter_masks_port_id,
3337                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3338                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3339                 (void *)&cmd_pkt_filter_masks_src_mask,
3340                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
3341                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3342                 (void *)&cmd_pkt_filter_masks_dst_mask,
3343                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
3344                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3345                 (void *)&cmd_pkt_filter_masks_flexbytes,
3346                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3347                 (void *)&cmd_pkt_filter_masks_vlan_id,
3348                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3349                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3350                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3351                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
3352                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
3353                 NULL,
3354         },
3355 };
3356
3357 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
3358 struct cmd_link_flow_ctrl_set_result {
3359         cmdline_fixed_string_t set;
3360         cmdline_fixed_string_t flow_ctrl;
3361         cmdline_fixed_string_t rx;
3362         cmdline_fixed_string_t rx_lfc_mode;
3363         cmdline_fixed_string_t tx;
3364         cmdline_fixed_string_t tx_lfc_mode;
3365         cmdline_fixed_string_t mac_ctrl_frame_fwd;
3366         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
3367         uint32_t high_water;
3368         uint32_t low_water;
3369         uint16_t pause_time;
3370         uint16_t send_xon;
3371         uint8_t  port_id;
3372 };
3373
3374 static void
3375 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
3376                        __attribute__((unused)) struct cmdline *cl,
3377                        __attribute__((unused)) void *data)
3378 {
3379         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
3380         struct rte_eth_fc_conf fc_conf;
3381         int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
3382         int ret;
3383
3384         /*
3385          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3386          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3387          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3388          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3389          */
3390         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
3391                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3392         };
3393
3394         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
3395         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
3396         mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
3397
3398         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
3399         fc_conf.high_water = res->high_water;
3400         fc_conf.low_water  = res->low_water;
3401         fc_conf.pause_time = res->pause_time;
3402         fc_conf.send_xon   = res->send_xon;
3403         fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
3404
3405         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
3406         if (ret != 0)
3407                 printf("bad flow contrl parameter, return code = %d \n", ret);
3408 }
3409
3410 cmdline_parse_token_string_t cmd_lfc_set_set =
3411         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3412                                 set, "set");
3413 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
3414         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3415                                 flow_ctrl, "flow_ctrl");
3416 cmdline_parse_token_string_t cmd_lfc_set_rx =
3417         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3418                                 rx, "rx");
3419 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
3420         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3421                                 rx_lfc_mode, "on#off");
3422 cmdline_parse_token_string_t cmd_lfc_set_tx =
3423         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3424                                 tx, "tx");
3425 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
3426         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3427                                 tx_lfc_mode, "on#off");
3428 cmdline_parse_token_num_t cmd_lfc_set_high_water =
3429         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3430                                 high_water, UINT32);
3431 cmdline_parse_token_num_t cmd_lfc_set_low_water =
3432         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3433                                 low_water, UINT32);
3434 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
3435         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3436                                 pause_time, UINT16);
3437 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
3438         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3439                                 send_xon, UINT16);
3440 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
3441         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3442                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
3443 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
3444         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3445                                 mac_ctrl_frame_fwd_mode, "on#off");
3446 cmdline_parse_token_num_t cmd_lfc_set_portid =
3447         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3448                                 port_id, UINT8);
3449
3450 cmdline_parse_inst_t cmd_link_flow_control_set = {
3451         .f = cmd_link_flow_ctrl_set_parsed,
3452         .data = NULL,
3453         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
3454 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
3455 port_id",
3456         .tokens = {
3457                 (void *)&cmd_lfc_set_set,
3458                 (void *)&cmd_lfc_set_flow_ctrl,
3459                 (void *)&cmd_lfc_set_rx,
3460                 (void *)&cmd_lfc_set_rx_mode,
3461                 (void *)&cmd_lfc_set_tx,
3462                 (void *)&cmd_lfc_set_tx_mode,
3463                 (void *)&cmd_lfc_set_high_water,
3464                 (void *)&cmd_lfc_set_low_water,
3465                 (void *)&cmd_lfc_set_pause_time,
3466                 (void *)&cmd_lfc_set_send_xon,
3467                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
3468                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
3469                 (void *)&cmd_lfc_set_portid,
3470                 NULL,
3471         },
3472 };
3473
3474 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
3475 struct cmd_priority_flow_ctrl_set_result {
3476         cmdline_fixed_string_t set;
3477         cmdline_fixed_string_t pfc_ctrl;
3478         cmdline_fixed_string_t rx;
3479         cmdline_fixed_string_t rx_pfc_mode;
3480         cmdline_fixed_string_t tx;
3481         cmdline_fixed_string_t tx_pfc_mode;
3482         uint32_t high_water;
3483         uint32_t low_water;
3484         uint16_t pause_time;
3485         uint8_t  priority;
3486         uint8_t  port_id;
3487 };
3488
3489 static void
3490 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
3491                        __attribute__((unused)) struct cmdline *cl,
3492                        __attribute__((unused)) void *data)
3493 {
3494         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
3495         struct rte_eth_pfc_conf pfc_conf;
3496         int rx_fc_enable, tx_fc_enable;
3497         int ret;
3498
3499         /*
3500          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3501          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3502          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3503          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3504          */
3505         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
3506                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3507         };
3508
3509         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
3510         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
3511         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
3512         pfc_conf.fc.high_water = res->high_water;
3513         pfc_conf.fc.low_water  = res->low_water;
3514         pfc_conf.fc.pause_time = res->pause_time;
3515         pfc_conf.priority      = res->priority;
3516
3517         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
3518         if (ret != 0)
3519                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
3520 }
3521
3522 cmdline_parse_token_string_t cmd_pfc_set_set =
3523         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3524                                 set, "set");
3525 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
3526         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3527                                 pfc_ctrl, "pfc_ctrl");
3528 cmdline_parse_token_string_t cmd_pfc_set_rx =
3529         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3530                                 rx, "rx");
3531 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
3532         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3533                                 rx_pfc_mode, "on#off");
3534 cmdline_parse_token_string_t cmd_pfc_set_tx =
3535         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3536                                 tx, "tx");
3537 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
3538         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3539                                 tx_pfc_mode, "on#off");
3540 cmdline_parse_token_num_t cmd_pfc_set_high_water =
3541         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3542                                 high_water, UINT32);
3543 cmdline_parse_token_num_t cmd_pfc_set_low_water =
3544         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3545                                 low_water, UINT32);
3546 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
3547         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3548                                 pause_time, UINT16);
3549 cmdline_parse_token_num_t cmd_pfc_set_priority =
3550         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3551                                 priority, UINT8);
3552 cmdline_parse_token_num_t cmd_pfc_set_portid =
3553         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3554                                 port_id, UINT8);
3555
3556 cmdline_parse_inst_t cmd_priority_flow_control_set = {
3557         .f = cmd_priority_flow_ctrl_set_parsed,
3558         .data = NULL,
3559         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
3560                         tx on|off high_water low_water pause_time priority port_id",
3561         .tokens = {
3562                 (void *)&cmd_pfc_set_set,
3563                 (void *)&cmd_pfc_set_flow_ctrl,
3564                 (void *)&cmd_pfc_set_rx,
3565                 (void *)&cmd_pfc_set_rx_mode,
3566                 (void *)&cmd_pfc_set_tx,
3567                 (void *)&cmd_pfc_set_tx_mode,
3568                 (void *)&cmd_pfc_set_high_water,
3569                 (void *)&cmd_pfc_set_low_water,
3570                 (void *)&cmd_pfc_set_pause_time,
3571                 (void *)&cmd_pfc_set_priority,
3572                 (void *)&cmd_pfc_set_portid,
3573                 NULL,
3574         },
3575 };
3576
3577 /* *** RESET CONFIGURATION *** */
3578 struct cmd_reset_result {
3579         cmdline_fixed_string_t reset;
3580         cmdline_fixed_string_t def;
3581 };
3582
3583 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
3584                              struct cmdline *cl,
3585                              __attribute__((unused)) void *data)
3586 {
3587         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
3588         set_def_fwd_config();
3589 }
3590
3591 cmdline_parse_token_string_t cmd_reset_set =
3592         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
3593 cmdline_parse_token_string_t cmd_reset_def =
3594         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
3595                                  "default");
3596
3597 cmdline_parse_inst_t cmd_reset = {
3598         .f = cmd_reset_parsed,
3599         .data = NULL,
3600         .help_str = "set default: reset default forwarding configuration",
3601         .tokens = {
3602                 (void *)&cmd_reset_set,
3603                 (void *)&cmd_reset_def,
3604                 NULL,
3605         },
3606 };
3607
3608 /* *** START FORWARDING *** */
3609 struct cmd_start_result {
3610         cmdline_fixed_string_t start;
3611 };
3612
3613 cmdline_parse_token_string_t cmd_start_start =
3614         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
3615
3616 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
3617                              __attribute__((unused)) struct cmdline *cl,
3618                              __attribute__((unused)) void *data)
3619 {
3620         start_packet_forwarding(0);
3621 }
3622
3623 cmdline_parse_inst_t cmd_start = {
3624         .f = cmd_start_parsed,
3625         .data = NULL,
3626         .help_str = "start packet forwarding",
3627         .tokens = {
3628                 (void *)&cmd_start_start,
3629                 NULL,
3630         },
3631 };
3632
3633 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
3634 struct cmd_start_tx_first_result {
3635         cmdline_fixed_string_t start;
3636         cmdline_fixed_string_t tx_first;
3637 };
3638
3639 static void
3640 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
3641                           __attribute__((unused)) struct cmdline *cl,
3642                           __attribute__((unused)) void *data)
3643 {
3644         start_packet_forwarding(1);
3645 }
3646
3647 cmdline_parse_token_string_t cmd_start_tx_first_start =
3648         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
3649                                  "start");
3650 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
3651         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
3652                                  tx_first, "tx_first");
3653
3654 cmdline_parse_inst_t cmd_start_tx_first = {
3655         .f = cmd_start_tx_first_parsed,
3656         .data = NULL,
3657         .help_str = "start packet forwarding, after sending 1 burst of packets",
3658         .tokens = {
3659                 (void *)&cmd_start_tx_first_start,
3660                 (void *)&cmd_start_tx_first_tx_first,
3661                 NULL,
3662         },
3663 };
3664
3665 /* *** SHOW CFG *** */
3666 struct cmd_showcfg_result {
3667         cmdline_fixed_string_t show;
3668         cmdline_fixed_string_t cfg;
3669         cmdline_fixed_string_t what;
3670 };
3671
3672 static void cmd_showcfg_parsed(void *parsed_result,
3673                                __attribute__((unused)) struct cmdline *cl,
3674                                __attribute__((unused)) void *data)
3675 {
3676         struct cmd_showcfg_result *res = parsed_result;
3677         if (!strcmp(res->what, "rxtx"))
3678                 rxtx_config_display();
3679         else if (!strcmp(res->what, "cores"))
3680                 fwd_lcores_config_display();
3681         else if (!strcmp(res->what, "fwd"))
3682                 fwd_config_display();
3683 }
3684
3685 cmdline_parse_token_string_t cmd_showcfg_show =
3686         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
3687 cmdline_parse_token_string_t cmd_showcfg_port =
3688         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
3689 cmdline_parse_token_string_t cmd_showcfg_what =
3690         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
3691                                  "rxtx#cores#fwd");
3692
3693 cmdline_parse_inst_t cmd_showcfg = {
3694         .f = cmd_showcfg_parsed,
3695         .data = NULL,
3696         .help_str = "show config rxtx|cores|fwd",
3697         .tokens = {
3698                 (void *)&cmd_showcfg_show,
3699                 (void *)&cmd_showcfg_port,
3700                 (void *)&cmd_showcfg_what,
3701                 NULL,
3702         },
3703 };
3704
3705 /* *** SHOW ALL PORT INFO *** */
3706 struct cmd_showportall_result {
3707         cmdline_fixed_string_t show;
3708         cmdline_fixed_string_t port;
3709         cmdline_fixed_string_t what;
3710         cmdline_fixed_string_t all;
3711 };
3712
3713 static void cmd_showportall_parsed(void *parsed_result,
3714                                 __attribute__((unused)) struct cmdline *cl,
3715                                 __attribute__((unused)) void *data)
3716 {
3717         portid_t i;
3718
3719         struct cmd_showportall_result *res = parsed_result;
3720         if (!strcmp(res->show, "clear")) {
3721                 if (!strcmp(res->what, "stats"))
3722                         for (i = 0; i < nb_ports; i++)
3723                                 nic_stats_clear(i);
3724         } else if (!strcmp(res->what, "info"))
3725                 for (i = 0; i < nb_ports; i++)
3726                         port_infos_display(i);
3727         else if (!strcmp(res->what, "stats"))
3728                 for (i = 0; i < nb_ports; i++)
3729                         nic_stats_display(i);
3730         else if (!strcmp(res->what, "fdir"))
3731                 for (i = 0; i < nb_ports; i++)
3732                         fdir_get_infos(i);
3733         else if (!strcmp(res->what, "stat_qmap"))
3734                 for (i = 0; i < nb_ports; i++)
3735                         nic_stats_mapping_display(i);
3736 }
3737
3738 cmdline_parse_token_string_t cmd_showportall_show =
3739         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
3740                                  "show#clear");
3741 cmdline_parse_token_string_t cmd_showportall_port =
3742         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
3743 cmdline_parse_token_string_t cmd_showportall_what =
3744         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
3745                                  "info#stats#fdir#stat_qmap");
3746 cmdline_parse_token_string_t cmd_showportall_all =
3747         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
3748 cmdline_parse_inst_t cmd_showportall = {
3749         .f = cmd_showportall_parsed,
3750         .data = NULL,
3751         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
3752         .tokens = {
3753                 (void *)&cmd_showportall_show,
3754                 (void *)&cmd_showportall_port,
3755                 (void *)&cmd_showportall_what,
3756                 (void *)&cmd_showportall_all,
3757                 NULL,
3758         },
3759 };
3760
3761 /* *** SHOW PORT INFO *** */
3762 struct cmd_showport_result {
3763         cmdline_fixed_string_t show;
3764         cmdline_fixed_string_t port;
3765         cmdline_fixed_string_t what;
3766         uint8_t portnum;
3767 };
3768
3769 static void cmd_showport_parsed(void *parsed_result,
3770                                 __attribute__((unused)) struct cmdline *cl,
3771                                 __attribute__((unused)) void *data)
3772 {
3773         struct cmd_showport_result *res = parsed_result;
3774         if (!strcmp(res->show, "clear")) {
3775                 if (!strcmp(res->what, "stats"))
3776                         nic_stats_clear(res->portnum);
3777         } else if (!strcmp(res->what, "info"))
3778                 port_infos_display(res->portnum);
3779         else if (!strcmp(res->what, "stats"))
3780                 nic_stats_display(res->portnum);
3781         else if (!strcmp(res->what, "fdir"))
3782                  fdir_get_infos(res->portnum);
3783         else if (!strcmp(res->what, "stat_qmap"))
3784                 nic_stats_mapping_display(res->portnum);
3785 }
3786
3787 cmdline_parse_token_string_t cmd_showport_show =
3788         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
3789                                  "show#clear");
3790 cmdline_parse_token_string_t cmd_showport_port =
3791         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
3792 cmdline_parse_token_string_t cmd_showport_what =
3793         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
3794                                  "info#stats#fdir#stat_qmap");
3795 cmdline_parse_token_num_t cmd_showport_portnum =
3796         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
3797
3798 cmdline_parse_inst_t cmd_showport = {
3799         .f = cmd_showport_parsed,
3800         .data = NULL,
3801         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
3802         .tokens = {
3803                 (void *)&cmd_showport_show,
3804                 (void *)&cmd_showport_port,
3805                 (void *)&cmd_showport_what,
3806                 (void *)&cmd_showport_portnum,
3807                 NULL,
3808         },
3809 };
3810
3811 /* *** READ PORT REGISTER *** */
3812 struct cmd_read_reg_result {
3813         cmdline_fixed_string_t read;
3814         cmdline_fixed_string_t reg;
3815         uint8_t port_id;
3816         uint32_t reg_off;
3817 };
3818
3819 static void
3820 cmd_read_reg_parsed(void *parsed_result,
3821                     __attribute__((unused)) struct cmdline *cl,
3822                     __attribute__((unused)) void *data)
3823 {
3824         struct cmd_read_reg_result *res = parsed_result;
3825         port_reg_display(res->port_id, res->reg_off);
3826 }
3827
3828 cmdline_parse_token_string_t cmd_read_reg_read =
3829         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
3830 cmdline_parse_token_string_t cmd_read_reg_reg =
3831         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
3832 cmdline_parse_token_num_t cmd_read_reg_port_id =
3833         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
3834 cmdline_parse_token_num_t cmd_read_reg_reg_off =
3835         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
3836
3837 cmdline_parse_inst_t cmd_read_reg = {
3838         .f = cmd_read_reg_parsed,
3839         .data = NULL,
3840         .help_str = "read reg port_id reg_off",
3841         .tokens = {
3842                 (void *)&cmd_read_reg_read,
3843                 (void *)&cmd_read_reg_reg,
3844                 (void *)&cmd_read_reg_port_id,
3845                 (void *)&cmd_read_reg_reg_off,
3846                 NULL,
3847         },
3848 };
3849
3850 /* *** READ PORT REGISTER BIT FIELD *** */
3851 struct cmd_read_reg_bit_field_result {
3852         cmdline_fixed_string_t read;
3853         cmdline_fixed_string_t regfield;
3854         uint8_t port_id;
3855         uint32_t reg_off;
3856         uint8_t bit1_pos;
3857         uint8_t bit2_pos;
3858 };
3859
3860 static void
3861 cmd_read_reg_bit_field_parsed(void *parsed_result,
3862                               __attribute__((unused)) struct cmdline *cl,
3863                               __attribute__((unused)) void *data)
3864 {
3865         struct cmd_read_reg_bit_field_result *res = parsed_result;
3866         port_reg_bit_field_display(res->port_id, res->reg_off,
3867                                    res->bit1_pos, res->bit2_pos);
3868 }
3869
3870 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
3871         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
3872                                  "read");
3873 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
3874         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
3875                                  regfield, "regfield");
3876 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
3877         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
3878                               UINT8);
3879 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
3880         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
3881                               UINT32);
3882 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
3883         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
3884                               UINT8);
3885 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
3886         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
3887                               UINT8);
3888
3889 cmdline_parse_inst_t cmd_read_reg_bit_field = {
3890         .f = cmd_read_reg_bit_field_parsed,
3891         .data = NULL,
3892         .help_str = "read regfield port_id reg_off bit_x bit_y "
3893         "(read register bit field between bit_x and bit_y included)",
3894         .tokens = {
3895                 (void *)&cmd_read_reg_bit_field_read,
3896                 (void *)&cmd_read_reg_bit_field_regfield,
3897                 (void *)&cmd_read_reg_bit_field_port_id,
3898                 (void *)&cmd_read_reg_bit_field_reg_off,
3899                 (void *)&cmd_read_reg_bit_field_bit1_pos,
3900                 (void *)&cmd_read_reg_bit_field_bit2_pos,
3901                 NULL,
3902         },
3903 };
3904
3905 /* *** READ PORT REGISTER BIT *** */
3906 struct cmd_read_reg_bit_result {
3907         cmdline_fixed_string_t read;
3908         cmdline_fixed_string_t regbit;
3909         uint8_t port_id;
3910         uint32_t reg_off;
3911         uint8_t bit_pos;
3912 };
3913
3914 static void
3915 cmd_read_reg_bit_parsed(void *parsed_result,
3916                         __attribute__((unused)) struct cmdline *cl,
3917                         __attribute__((unused)) void *data)
3918 {
3919         struct cmd_read_reg_bit_result *res = parsed_result;
3920         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
3921 }
3922
3923 cmdline_parse_token_string_t cmd_read_reg_bit_read =
3924         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
3925 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
3926         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
3927                                  regbit, "regbit");
3928 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
3929         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
3930 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
3931         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
3932 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
3933         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
3934
3935 cmdline_parse_inst_t cmd_read_reg_bit = {
3936         .f = cmd_read_reg_bit_parsed,
3937         .data = NULL,
3938         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
3939         .tokens = {
3940                 (void *)&cmd_read_reg_bit_read,
3941                 (void *)&cmd_read_reg_bit_regbit,
3942                 (void *)&cmd_read_reg_bit_port_id,
3943                 (void *)&cmd_read_reg_bit_reg_off,
3944                 (void *)&cmd_read_reg_bit_bit_pos,
3945                 NULL,
3946         },
3947 };
3948
3949 /* *** WRITE PORT REGISTER *** */
3950 struct cmd_write_reg_result {
3951         cmdline_fixed_string_t write;
3952         cmdline_fixed_string_t reg;
3953         uint8_t port_id;
3954         uint32_t reg_off;
3955         uint32_t value;
3956 };
3957
3958 static void
3959 cmd_write_reg_parsed(void *parsed_result,
3960                      __attribute__((unused)) struct cmdline *cl,
3961                      __attribute__((unused)) void *data)
3962 {
3963         struct cmd_write_reg_result *res = parsed_result;
3964         port_reg_set(res->port_id, res->reg_off, res->value);
3965 }
3966
3967 cmdline_parse_token_string_t cmd_write_reg_write =
3968         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
3969 cmdline_parse_token_string_t cmd_write_reg_reg =
3970         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
3971 cmdline_parse_token_num_t cmd_write_reg_port_id =
3972         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
3973 cmdline_parse_token_num_t cmd_write_reg_reg_off =
3974         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
3975 cmdline_parse_token_num_t cmd_write_reg_value =
3976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
3977
3978 cmdline_parse_inst_t cmd_write_reg = {
3979         .f = cmd_write_reg_parsed,
3980         .data = NULL,
3981         .help_str = "write reg port_id reg_off reg_value",
3982         .tokens = {
3983                 (void *)&cmd_write_reg_write,
3984                 (void *)&cmd_write_reg_reg,
3985                 (void *)&cmd_write_reg_port_id,
3986                 (void *)&cmd_write_reg_reg_off,
3987                 (void *)&cmd_write_reg_value,
3988                 NULL,
3989         },
3990 };
3991
3992 /* *** WRITE PORT REGISTER BIT FIELD *** */
3993 struct cmd_write_reg_bit_field_result {
3994         cmdline_fixed_string_t write;
3995         cmdline_fixed_string_t regfield;
3996         uint8_t port_id;
3997         uint32_t reg_off;
3998         uint8_t bit1_pos;
3999         uint8_t bit2_pos;
4000         uint32_t value;
4001 };
4002
4003 static void
4004 cmd_write_reg_bit_field_parsed(void *parsed_result,
4005                                __attribute__((unused)) struct cmdline *cl,
4006                                __attribute__((unused)) void *data)
4007 {
4008         struct cmd_write_reg_bit_field_result *res = parsed_result;
4009         port_reg_bit_field_set(res->port_id, res->reg_off,
4010                           res->bit1_pos, res->bit2_pos, res->value);
4011 }
4012
4013 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
4014         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
4015                                  "write");
4016 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
4017         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
4018                                  regfield, "regfield");
4019 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
4020         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
4021                               UINT8);
4022 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
4023         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
4024                               UINT32);
4025 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
4026         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
4027                               UINT8);
4028 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
4029         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
4030                               UINT8);
4031 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
4032         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
4033                               UINT32);
4034
4035 cmdline_parse_inst_t cmd_write_reg_bit_field = {
4036         .f = cmd_write_reg_bit_field_parsed,
4037         .data = NULL,
4038         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
4039         "(set register bit field between bit_x and bit_y included)",
4040         .tokens = {
4041                 (void *)&cmd_write_reg_bit_field_write,
4042                 (void *)&cmd_write_reg_bit_field_regfield,
4043                 (void *)&cmd_write_reg_bit_field_port_id,
4044                 (void *)&cmd_write_reg_bit_field_reg_off,
4045                 (void *)&cmd_write_reg_bit_field_bit1_pos,
4046                 (void *)&cmd_write_reg_bit_field_bit2_pos,
4047                 (void *)&cmd_write_reg_bit_field_value,
4048                 NULL,
4049         },
4050 };
4051
4052 /* *** WRITE PORT REGISTER BIT *** */
4053 struct cmd_write_reg_bit_result {
4054         cmdline_fixed_string_t write;
4055         cmdline_fixed_string_t regbit;
4056         uint8_t port_id;
4057         uint32_t reg_off;
4058         uint8_t bit_pos;
4059         uint8_t value;
4060 };
4061
4062 static void
4063 cmd_write_reg_bit_parsed(void *parsed_result,
4064                          __attribute__((unused)) struct cmdline *cl,
4065                          __attribute__((unused)) void *data)
4066 {
4067         struct cmd_write_reg_bit_result *res = parsed_result;
4068         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
4069 }
4070
4071 cmdline_parse_token_string_t cmd_write_reg_bit_write =
4072         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
4073                                  "write");
4074 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
4075         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
4076                                  regbit, "regbit");
4077 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
4078         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
4079 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
4080         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
4081 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
4082         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
4083 cmdline_parse_token_num_t cmd_write_reg_bit_value =
4084         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
4085
4086 cmdline_parse_inst_t cmd_write_reg_bit = {
4087         .f = cmd_write_reg_bit_parsed,
4088         .data = NULL,
4089         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
4090         .tokens = {
4091                 (void *)&cmd_write_reg_bit_write,
4092                 (void *)&cmd_write_reg_bit_regbit,
4093                 (void *)&cmd_write_reg_bit_port_id,
4094                 (void *)&cmd_write_reg_bit_reg_off,
4095                 (void *)&cmd_write_reg_bit_bit_pos,
4096                 (void *)&cmd_write_reg_bit_value,
4097                 NULL,
4098         },
4099 };
4100
4101 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
4102 struct cmd_read_rxd_txd_result {
4103         cmdline_fixed_string_t read;
4104         cmdline_fixed_string_t rxd_txd;
4105         uint8_t port_id;
4106         uint16_t queue_id;
4107         uint16_t desc_id;
4108 };
4109
4110 static void
4111 cmd_read_rxd_txd_parsed(void *parsed_result,
4112                         __attribute__((unused)) struct cmdline *cl,
4113                         __attribute__((unused)) void *data)
4114 {
4115         struct cmd_read_rxd_txd_result *res = parsed_result;
4116
4117         if (!strcmp(res->rxd_txd, "rxd"))
4118                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4119         else if (!strcmp(res->rxd_txd, "txd"))
4120                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4121 }
4122
4123 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
4124         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
4125 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
4126         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
4127                                  "rxd#txd");
4128 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
4129         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
4130 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
4131         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
4132 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
4133         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
4134
4135 cmdline_parse_inst_t cmd_read_rxd_txd = {
4136         .f = cmd_read_rxd_txd_parsed,
4137         .data = NULL,
4138         .help_str = "read rxd|txd port_id queue_id rxd_id",
4139         .tokens = {
4140                 (void *)&cmd_read_rxd_txd_read,
4141                 (void *)&cmd_read_rxd_txd_rxd_txd,
4142                 (void *)&cmd_read_rxd_txd_port_id,
4143                 (void *)&cmd_read_rxd_txd_queue_id,
4144                 (void *)&cmd_read_rxd_txd_desc_id,
4145                 NULL,
4146         },
4147 };
4148
4149 /* *** QUIT *** */
4150 struct cmd_quit_result {
4151         cmdline_fixed_string_t quit;
4152 };
4153
4154 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
4155                             struct cmdline *cl,
4156                             __attribute__((unused)) void *data)
4157 {
4158         pmd_test_exit();
4159         cmdline_quit(cl);
4160 }
4161
4162 cmdline_parse_token_string_t cmd_quit_quit =
4163         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
4164
4165 cmdline_parse_inst_t cmd_quit = {
4166         .f = cmd_quit_parsed,
4167         .data = NULL,
4168         .help_str = "exit application",
4169         .tokens = {
4170                 (void *)&cmd_quit_quit,
4171                 NULL,
4172         },
4173 };
4174
4175 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
4176 struct cmd_mac_addr_result {
4177         cmdline_fixed_string_t mac_addr_cmd;
4178         cmdline_fixed_string_t what;
4179         uint8_t port_num;
4180         struct ether_addr address;
4181 };
4182
4183 static void cmd_mac_addr_parsed(void *parsed_result,
4184                 __attribute__((unused)) struct cmdline *cl,
4185                 __attribute__((unused)) void *data)
4186 {
4187         struct cmd_mac_addr_result *res = parsed_result;
4188         int ret;
4189
4190         if (strcmp(res->what, "add") == 0)
4191                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
4192         else
4193                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
4194
4195         /* check the return value and print it if is < 0 */
4196         if(ret < 0)
4197                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
4198
4199 }
4200
4201 cmdline_parse_token_string_t cmd_mac_addr_cmd =
4202         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
4203                                 "mac_addr");
4204 cmdline_parse_token_string_t cmd_mac_addr_what =
4205         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
4206                                 "add#remove");
4207 cmdline_parse_token_num_t cmd_mac_addr_portnum =
4208                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
4209 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
4210                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
4211
4212 cmdline_parse_inst_t cmd_mac_addr = {
4213         .f = cmd_mac_addr_parsed,
4214         .data = (void *)0,
4215         .help_str = "mac_addr add|remove X <address>: "
4216                         "add/remove MAC address on port X",
4217         .tokens = {
4218                 (void *)&cmd_mac_addr_cmd,
4219                 (void *)&cmd_mac_addr_what,
4220                 (void *)&cmd_mac_addr_portnum,
4221                 (void *)&cmd_mac_addr_addr,
4222                 NULL,
4223         },
4224 };
4225
4226
4227 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
4228 struct cmd_set_qmap_result {
4229         cmdline_fixed_string_t set;
4230         cmdline_fixed_string_t qmap;
4231         cmdline_fixed_string_t what;
4232         uint8_t port_id;
4233         uint16_t queue_id;
4234         uint8_t map_value;
4235 };
4236
4237 static void
4238 cmd_set_qmap_parsed(void *parsed_result,
4239                        __attribute__((unused)) struct cmdline *cl,
4240                        __attribute__((unused)) void *data)
4241 {
4242         struct cmd_set_qmap_result *res = parsed_result;
4243         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
4244
4245         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
4246 }
4247
4248 cmdline_parse_token_string_t cmd_setqmap_set =
4249         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4250                                  set, "set");
4251 cmdline_parse_token_string_t cmd_setqmap_qmap =
4252         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4253                                  qmap, "stat_qmap");
4254 cmdline_parse_token_string_t cmd_setqmap_what =
4255         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4256                                  what, "tx#rx");
4257 cmdline_parse_token_num_t cmd_setqmap_portid =
4258         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4259                               port_id, UINT8);
4260 cmdline_parse_token_num_t cmd_setqmap_queueid =
4261         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4262                               queue_id, UINT16);
4263 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
4264         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4265                               map_value, UINT8);
4266
4267 cmdline_parse_inst_t cmd_set_qmap = {
4268         .f = cmd_set_qmap_parsed,
4269         .data = NULL,
4270         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
4271         .tokens = {
4272                 (void *)&cmd_setqmap_set,
4273                 (void *)&cmd_setqmap_qmap,
4274                 (void *)&cmd_setqmap_what,
4275                 (void *)&cmd_setqmap_portid,
4276                 (void *)&cmd_setqmap_queueid,
4277                 (void *)&cmd_setqmap_mapvalue,
4278                 NULL,
4279         },
4280 };
4281
4282 /* *** CONFIGURE UNICAST HASH TABLE *** */
4283 struct cmd_set_uc_hash_table {
4284         cmdline_fixed_string_t set;
4285         cmdline_fixed_string_t port;
4286         uint8_t port_id;
4287         cmdline_fixed_string_t what;
4288         struct ether_addr address;
4289         cmdline_fixed_string_t mode;
4290 };
4291
4292 static void
4293 cmd_set_uc_hash_parsed(void *parsed_result,
4294                        __attribute__((unused)) struct cmdline *cl,
4295                        __attribute__((unused)) void *data)
4296 {
4297         int ret=0;
4298         struct cmd_set_uc_hash_table *res = parsed_result;
4299         
4300         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4301         
4302         if (strcmp(res->what, "uta") == 0)
4303                 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 
4304                                                 &res->address,(uint8_t)is_on);
4305         if (ret < 0)
4306                 printf("bad unicast hash table parameter, return code = %d \n", ret);
4307         
4308 }
4309
4310 cmdline_parse_token_string_t cmd_set_uc_hash_set =
4311         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4312                                  set, "set");
4313 cmdline_parse_token_string_t cmd_set_uc_hash_port =
4314         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4315                                  port, "port");
4316 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
4317         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
4318                               port_id, UINT8);
4319 cmdline_parse_token_string_t cmd_set_uc_hash_what =
4320         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4321                                  what, "uta");
4322 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
4323         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 
4324                                 address);
4325 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
4326         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4327                                  mode, "on#off");
4328
4329 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
4330         .f = cmd_set_uc_hash_parsed,
4331         .data = NULL,
4332         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
4333         .tokens = {
4334                 (void *)&cmd_set_uc_hash_set,
4335                 (void *)&cmd_set_uc_hash_port,
4336                 (void *)&cmd_set_uc_hash_portid,
4337                 (void *)&cmd_set_uc_hash_what,
4338                 (void *)&cmd_set_uc_hash_mac,
4339                 (void *)&cmd_set_uc_hash_mode,
4340                 NULL,
4341         },
4342 };
4343
4344 struct cmd_set_uc_all_hash_table {
4345         cmdline_fixed_string_t set;
4346         cmdline_fixed_string_t port;
4347         uint8_t port_id;
4348         cmdline_fixed_string_t what;
4349         cmdline_fixed_string_t value;
4350         cmdline_fixed_string_t mode;
4351 };
4352
4353 static void
4354 cmd_set_uc_all_hash_parsed(void *parsed_result,
4355                        __attribute__((unused)) struct cmdline *cl,
4356                        __attribute__((unused)) void *data)
4357 {
4358         int ret=0;
4359         struct cmd_set_uc_all_hash_table *res = parsed_result;
4360         
4361         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4362         
4363         if ((strcmp(res->what, "uta") == 0) && 
4364                 (strcmp(res->value, "all") == 0))
4365                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
4366         if (ret < 0)
4367                 printf("bad unicast hash table parameter," 
4368                         "return code = %d \n", ret);
4369 }
4370
4371 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
4372         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4373                                  set, "set");
4374 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
4375         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4376                                  port, "port");
4377 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
4378         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
4379                               port_id, UINT8);
4380 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
4381         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4382                                  what, "uta");
4383 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
4384         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 
4385                                 value,"all");
4386 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
4387         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4388                                  mode, "on#off");
4389
4390 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
4391         .f = cmd_set_uc_all_hash_parsed,
4392         .data = NULL,
4393         .help_str = "set port X uta all on|off (X = port number)",
4394         .tokens = {
4395                 (void *)&cmd_set_uc_all_hash_set,
4396                 (void *)&cmd_set_uc_all_hash_port,
4397                 (void *)&cmd_set_uc_all_hash_portid,
4398                 (void *)&cmd_set_uc_all_hash_what,
4399                 (void *)&cmd_set_uc_all_hash_value,
4400                 (void *)&cmd_set_uc_all_hash_mode,
4401                 NULL,
4402         },
4403 };
4404
4405 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
4406 struct cmd_set_vf_traffic {
4407         cmdline_fixed_string_t set;
4408         cmdline_fixed_string_t port;
4409         uint8_t port_id;
4410         cmdline_fixed_string_t vf;
4411         uint8_t vf_id;
4412         cmdline_fixed_string_t what;
4413         cmdline_fixed_string_t mode;
4414 };
4415
4416 static void
4417 cmd_set_vf_traffic_parsed(void *parsed_result,
4418                        __attribute__((unused)) struct cmdline *cl,
4419                        __attribute__((unused)) void *data)
4420 {
4421         struct cmd_set_vf_traffic *res = parsed_result;
4422         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
4423         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4424
4425         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
4426 }
4427
4428 cmdline_parse_token_string_t cmd_setvf_traffic_set =
4429         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4430                                  set, "set");
4431 cmdline_parse_token_string_t cmd_setvf_traffic_port =
4432         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4433                                  port, "port");
4434 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
4435         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4436                               port_id, UINT8);
4437 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
4438         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4439                                  vf, "vf");
4440 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
4441         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4442                               vf_id, UINT8);
4443 cmdline_parse_token_string_t cmd_setvf_traffic_what =
4444         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4445                                  what, "tx#rx");
4446 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
4447         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4448                                  mode, "on#off");
4449
4450 cmdline_parse_inst_t cmd_set_vf_traffic = {
4451         .f = cmd_set_vf_traffic_parsed,
4452         .data = NULL,
4453         .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)",
4454         .tokens = {
4455                 (void *)&cmd_setvf_traffic_set,
4456                 (void *)&cmd_setvf_traffic_port,
4457                 (void *)&cmd_setvf_traffic_portid,
4458                 (void *)&cmd_setvf_traffic_vf,
4459                 (void *)&cmd_setvf_traffic_vfid,
4460                 (void *)&cmd_setvf_traffic_what,
4461                 (void *)&cmd_setvf_traffic_mode,
4462                 NULL,
4463         },
4464 };
4465
4466 /* *** CONFIGURE VF RECEIVE MODE *** */
4467 struct cmd_set_vf_rxmode {
4468         cmdline_fixed_string_t set;
4469         cmdline_fixed_string_t port;
4470         uint8_t port_id;
4471         cmdline_fixed_string_t vf;
4472         uint8_t vf_id;
4473         cmdline_fixed_string_t what;
4474         cmdline_fixed_string_t mode;
4475         cmdline_fixed_string_t on;
4476 };
4477
4478 static void
4479 cmd_set_vf_rxmode_parsed(void *parsed_result,
4480                        __attribute__((unused)) struct cmdline *cl,
4481                        __attribute__((unused)) void *data)
4482 {
4483         int ret;
4484         uint16_t rx_mode = 0;
4485         struct cmd_set_vf_rxmode *res = parsed_result;
4486         
4487         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
4488         if (!strcmp(res->what,"rxmode")) {
4489                 if (!strcmp(res->mode, "AUPE"))
4490                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
4491                 else if (!strcmp(res->mode, "ROPE"))
4492                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
4493                 else if (!strcmp(res->mode, "BAM"))
4494                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
4495                 else if (!strncmp(res->mode, "MPE",3))
4496                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
4497         }
4498
4499         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
4500         if (ret < 0)
4501                 printf("bad VF receive mode parameter, return code = %d \n",
4502                 ret);
4503 }
4504
4505 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
4506         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4507                                  set, "set");
4508 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
4509         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4510                                  port, "port");
4511 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
4512         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4513                               port_id, UINT8);
4514 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
4515         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4516                                  vf, "vf");
4517 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
4518         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4519                               vf_id, UINT8);
4520 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
4521         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4522                                  what, "rxmode");
4523 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
4524         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4525                                  mode, "AUPE#ROPE#BAM#MPE");
4526 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
4527         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4528                                  on, "on#off");
4529
4530 cmdline_parse_inst_t cmd_set_vf_rxmode = {
4531         .f = cmd_set_vf_rxmode_parsed,
4532         .data = NULL,
4533         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
4534         .tokens = {
4535                 (void *)&cmd_set_vf_rxmode_set,
4536                 (void *)&cmd_set_vf_rxmode_port,
4537                 (void *)&cmd_set_vf_rxmode_portid,
4538                 (void *)&cmd_set_vf_rxmode_vf,
4539                 (void *)&cmd_set_vf_rxmode_vfid,
4540                 (void *)&cmd_set_vf_rxmode_what,
4541                 (void *)&cmd_set_vf_rxmode_mode,
4542                 (void *)&cmd_set_vf_rxmode_on,
4543                 NULL,
4544         },
4545 };
4546
4547 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
4548 struct cmd_vf_mac_addr_result {
4549         cmdline_fixed_string_t mac_addr_cmd;
4550         cmdline_fixed_string_t what;
4551         cmdline_fixed_string_t port;
4552         uint8_t port_num;
4553         cmdline_fixed_string_t vf;
4554         uint8_t vf_num;
4555         struct ether_addr address;
4556 };
4557
4558 static void cmd_vf_mac_addr_parsed(void *parsed_result,
4559                 __attribute__((unused)) struct cmdline *cl,
4560                 __attribute__((unused)) void *data)
4561 {
4562         struct cmd_vf_mac_addr_result *res = parsed_result;
4563         int ret = 0;
4564
4565         if (strcmp(res->what, "add") == 0)
4566                 ret = rte_eth_dev_mac_addr_add(res->port_num, 
4567                                         &res->address, res->vf_num);
4568         if(ret < 0)
4569                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
4570
4571 }
4572
4573 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
4574         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4575                                 mac_addr_cmd,"mac_addr");
4576 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
4577         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4578                                 what,"add");
4579 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
4580         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4581                                 port,"port");
4582 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
4583         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 
4584                                 port_num, UINT8);
4585 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
4586         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 
4587                                 vf,"vf");
4588 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
4589         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
4590                                 vf_num, UINT8);
4591 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
4592         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 
4593                                 address);
4594
4595 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
4596         .f = cmd_vf_mac_addr_parsed,
4597         .data = (void *)0,
4598         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
4599         "Y = VF number)add MAC address filtering for a VF on port X",
4600         .tokens = {
4601                 (void *)&cmd_vf_mac_addr_cmd,
4602                 (void *)&cmd_vf_mac_addr_what,
4603                 (void *)&cmd_vf_mac_addr_port,
4604                 (void *)&cmd_vf_mac_addr_portnum,
4605                 (void *)&cmd_vf_mac_addr_vf,
4606                 (void *)&cmd_vf_mac_addr_vfnum,
4607                 (void *)&cmd_vf_mac_addr_addr,
4608                 NULL,
4609         },
4610 };
4611
4612 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4613 struct cmd_vf_rx_vlan_filter {
4614         cmdline_fixed_string_t rx_vlan;
4615         cmdline_fixed_string_t what;
4616         uint16_t vlan_id;
4617         cmdline_fixed_string_t port;
4618         uint8_t port_id;
4619         cmdline_fixed_string_t vf;
4620         uint64_t vf_mask;
4621 };
4622
4623 static void
4624 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
4625                           __attribute__((unused)) struct cmdline *cl,
4626                           __attribute__((unused)) void *data)
4627 {
4628         struct cmd_vf_rx_vlan_filter *res = parsed_result;
4629
4630         if (!strcmp(res->what, "add"))
4631                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
4632         else
4633                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
4634 }
4635
4636 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
4637         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4638                                  rx_vlan, "rx_vlan");
4639 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
4640         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4641                                  what, "add#rm");
4642 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
4643         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4644                               vlan_id, UINT16);
4645 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
4646         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4647                                  port, "port");
4648 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
4649         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4650                               port_id, UINT8);
4651 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
4652         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4653                                  vf, "vf");
4654 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
4655         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4656                               vf_mask, UINT64);
4657
4658 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
4659         .f = cmd_vf_rx_vlan_filter_parsed,
4660         .data = NULL,
4661         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
4662                 "Y = port number,Z = hexadecimal VF mask)",
4663         .tokens = {
4664                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
4665                 (void *)&cmd_vf_rx_vlan_filter_what,
4666                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
4667                 (void *)&cmd_vf_rx_vlan_filter_port,
4668                 (void *)&cmd_vf_rx_vlan_filter_portid,
4669                 (void *)&cmd_vf_rx_vlan_filter_vf,
4670                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
4671                 NULL,
4672         },
4673 };
4674
4675 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
4676 struct cmd_set_mirror_mask_result {
4677         cmdline_fixed_string_t set;
4678         cmdline_fixed_string_t port;
4679         uint8_t port_id;
4680         cmdline_fixed_string_t mirror;
4681         uint8_t rule_id;
4682         cmdline_fixed_string_t what;
4683         cmdline_fixed_string_t value;
4684         cmdline_fixed_string_t dstpool;
4685         uint8_t dstpool_id;
4686         cmdline_fixed_string_t on;
4687 };
4688
4689 cmdline_parse_token_string_t cmd_mirror_mask_set =
4690         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4691                                 set, "set");
4692 cmdline_parse_token_string_t cmd_mirror_mask_port =
4693         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4694                                 port, "port");
4695 cmdline_parse_token_string_t cmd_mirror_mask_portid =
4696         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4697                                 port_id, UINT8);
4698 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
4699         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4700                                 mirror, "mirror-rule");
4701 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
4702         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4703                                 rule_id, UINT8);
4704 cmdline_parse_token_string_t cmd_mirror_mask_what =
4705         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4706                                 what, "pool-mirror#vlan-mirror");
4707 cmdline_parse_token_string_t cmd_mirror_mask_value =
4708         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4709                                 value, NULL);
4710 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
4711         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4712                                 dstpool, "dst-pool");
4713 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
4714         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
4715                                 dstpool_id, UINT8);
4716 cmdline_parse_token_string_t cmd_mirror_mask_on =
4717         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
4718                                 on, "on#off");
4719
4720 static void
4721 cmd_set_mirror_mask_parsed(void *parsed_result,
4722                        __attribute__((unused)) struct cmdline *cl,
4723                        __attribute__((unused)) void *data)
4724 {
4725         int ret,nb_item,i;
4726         struct cmd_set_mirror_mask_result *res = parsed_result;
4727         struct rte_eth_vmdq_mirror_conf mr_conf;
4728
4729         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
4730
4731         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
4732
4733         mr_conf.dst_pool = res->dstpool_id;
4734
4735         if (!strcmp(res->what, "pool-mirror")) {
4736                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
4737                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
4738         } else if(!strcmp(res->what, "vlan-mirror")) {
4739                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
4740                 nb_item = parse_item_list(res->value, "core",
4741                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
4742                 if (nb_item <= 0)
4743                         return;
4744
4745                 for(i=0; i < nb_item; i++) {
4746                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
4747                                 printf("Invalid vlan_id: must be < 4096\n");
4748                                 return;
4749                         }
4750
4751                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
4752                         mr_conf.vlan.vlan_mask |= 1ULL << i;
4753                 }
4754         }
4755
4756         if(!strcmp(res->on, "on"))
4757                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4758                                                 res->rule_id, 1);
4759         else
4760                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4761                                                 res->rule_id, 0);
4762         if(ret < 0)
4763                 printf("mirror rule add error: (%s)\n", strerror(-ret));
4764 }
4765
4766 cmdline_parse_inst_t cmd_set_mirror_mask = {
4767                 .f = cmd_set_mirror_mask_parsed,
4768                 .data = NULL,
4769                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror " 
4770                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
4771                 .tokens = {
4772                         (void *)&cmd_mirror_mask_set,
4773                         (void *)&cmd_mirror_mask_port,
4774                         (void *)&cmd_mirror_mask_portid,
4775                         (void *)&cmd_mirror_mask_mirror,
4776                         (void *)&cmd_mirror_mask_ruleid,
4777                         (void *)&cmd_mirror_mask_what,
4778                         (void *)&cmd_mirror_mask_value,
4779                         (void *)&cmd_mirror_mask_dstpool,
4780                         (void *)&cmd_mirror_mask_poolid,
4781                         (void *)&cmd_mirror_mask_on,
4782                         NULL,
4783                 },
4784 };
4785
4786 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
4787 struct cmd_set_mirror_link_result {
4788         cmdline_fixed_string_t set;
4789         cmdline_fixed_string_t port;
4790         uint8_t port_id;
4791         cmdline_fixed_string_t mirror;
4792         uint8_t rule_id;
4793         cmdline_fixed_string_t what;
4794         cmdline_fixed_string_t dstpool;
4795         uint8_t dstpool_id;
4796         cmdline_fixed_string_t on;
4797 };
4798
4799 cmdline_parse_token_string_t cmd_mirror_link_set =
4800         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4801                                  set, "set");
4802 cmdline_parse_token_string_t cmd_mirror_link_port =
4803         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4804                                 port, "port");
4805 cmdline_parse_token_string_t cmd_mirror_link_portid =
4806         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4807                                 port_id, UINT8);
4808 cmdline_parse_token_string_t cmd_mirror_link_mirror =
4809         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4810                                 mirror, "mirror-rule");
4811 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
4812         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4813                             rule_id, UINT8);
4814 cmdline_parse_token_string_t cmd_mirror_link_what =
4815         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4816                                 what, "uplink-mirror#downlink-mirror");
4817 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
4818         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4819                                 dstpool, "dst-pool");
4820 cmdline_parse_token_num_t cmd_mirror_link_poolid =
4821         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
4822                                 dstpool_id, UINT8);
4823 cmdline_parse_token_string_t cmd_mirror_link_on =
4824         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
4825                                 on, "on#off");
4826
4827 static void
4828 cmd_set_mirror_link_parsed(void *parsed_result,
4829                        __attribute__((unused)) struct cmdline *cl,
4830                        __attribute__((unused)) void *data)
4831 {
4832         int ret;
4833         struct cmd_set_mirror_link_result *res = parsed_result;
4834         struct rte_eth_vmdq_mirror_conf mr_conf;
4835
4836         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
4837         if(!strcmp(res->what, "uplink-mirror")) {
4838                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
4839         }else if(!strcmp(res->what, "downlink-mirror"))
4840                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
4841
4842         mr_conf.dst_pool = res->dstpool_id;
4843
4844         if(!strcmp(res->on, "on"))
4845                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4846                                                 res->rule_id, 1);
4847         else
4848                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
4849                                                 res->rule_id, 0);
4850
4851         /* check the return value and print it if is < 0 */
4852         if(ret < 0)
4853                 printf("mirror rule add error: (%s)\n", strerror(-ret));
4854
4855 }
4856
4857 cmdline_parse_inst_t cmd_set_mirror_link = {
4858                 .f = cmd_set_mirror_link_parsed,
4859                 .data = NULL,
4860                 .help_str = "set port X mirror-rule Y uplink-mirror|"
4861                         "downlink-mirror dst-pool Z on|off",
4862                 .tokens = {
4863                         (void *)&cmd_mirror_link_set,
4864                         (void *)&cmd_mirror_link_port,
4865                         (void *)&cmd_mirror_link_portid,
4866                         (void *)&cmd_mirror_link_mirror,
4867                         (void *)&cmd_mirror_link_ruleid,
4868                         (void *)&cmd_mirror_link_what,
4869                         (void *)&cmd_mirror_link_dstpool,
4870                         (void *)&cmd_mirror_link_poolid,
4871                         (void *)&cmd_mirror_link_on,
4872                         NULL,
4873                 },
4874 };
4875
4876 /* *** RESET VM MIRROR RULE *** */
4877 struct cmd_rm_mirror_rule_result {
4878         cmdline_fixed_string_t reset;
4879         cmdline_fixed_string_t port;
4880         uint8_t port_id;
4881         cmdline_fixed_string_t mirror;
4882         uint8_t rule_id;
4883 };
4884
4885 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
4886         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4887                                  reset, "reset");
4888 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
4889         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4890                                 port, "port");
4891 cmdline_parse_token_string_t cmd_rm_mirror_rule_portid =
4892         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
4893                                 port_id, UINT8);
4894 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
4895         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
4896                                 mirror, "mirror-rule");
4897 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
4898         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
4899                                 rule_id, UINT8);
4900
4901 static void
4902 cmd_reset_mirror_rule_parsed(void *parsed_result,
4903                        __attribute__((unused)) struct cmdline *cl,
4904                        __attribute__((unused)) void *data)
4905 {
4906         int ret;
4907         struct cmd_set_mirror_link_result *res = parsed_result;
4908         /* check rule_id */
4909         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
4910         if(ret < 0)
4911                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
4912 }
4913
4914 cmdline_parse_inst_t cmd_reset_mirror_rule = {
4915                 .f = cmd_reset_mirror_rule_parsed,
4916                 .data = NULL,
4917                 .help_str = "reset port X mirror-rule Y",
4918                 .tokens = {
4919                         (void *)&cmd_rm_mirror_rule_reset,
4920                         (void *)&cmd_rm_mirror_rule_port,
4921                         (void *)&cmd_rm_mirror_rule_portid,
4922                         (void *)&cmd_rm_mirror_rule_mirror,
4923                         (void *)&cmd_rm_mirror_rule_ruleid,
4924                         NULL,
4925                 },
4926 };
4927
4928 /* ******************************************************************************** */
4929
4930 /* list of instructions */
4931 cmdline_parse_ctx_t main_ctx[] = {
4932         (cmdline_parse_inst_t *)&cmd_help_brief,
4933         (cmdline_parse_inst_t *)&cmd_help_long,
4934         (cmdline_parse_inst_t *)&cmd_quit,
4935         (cmdline_parse_inst_t *)&cmd_showport,
4936         (cmdline_parse_inst_t *)&cmd_showportall,
4937         (cmdline_parse_inst_t *)&cmd_showcfg,
4938         (cmdline_parse_inst_t *)&cmd_start,
4939         (cmdline_parse_inst_t *)&cmd_start_tx_first,
4940         (cmdline_parse_inst_t *)&cmd_reset,
4941         (cmdline_parse_inst_t *)&cmd_set_numbers,
4942         (cmdline_parse_inst_t *)&cmd_set_txpkts,
4943         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
4944         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
4945         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
4946         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
4947         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
4948         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
4949         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
4950         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
4951 #ifdef RTE_NIC_BYPASS
4952         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
4953         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
4954         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
4955         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
4956 #endif
4957         (cmdline_parse_inst_t *)&cmd_vlan_offload,
4958         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
4959         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
4960         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
4961         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
4962         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
4963         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
4964         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
4965         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
4966         (cmdline_parse_inst_t *)&cmd_config_dcb,
4967         (cmdline_parse_inst_t *)&cmd_read_reg,
4968         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
4969         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
4970         (cmdline_parse_inst_t *)&cmd_write_reg,
4971         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
4972         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
4973         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
4974         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
4975         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
4976         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
4977         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
4978         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
4979         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
4980         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
4981         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
4982         (cmdline_parse_inst_t *)&cmd_stop,
4983         (cmdline_parse_inst_t *)&cmd_mac_addr,
4984         (cmdline_parse_inst_t *)&cmd_set_qmap,
4985         (cmdline_parse_inst_t *)&cmd_operate_port,
4986         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
4987         (cmdline_parse_inst_t *)&cmd_config_speed_all,
4988         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
4989         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
4990         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
4991         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
4992         (cmdline_parse_inst_t *)&cmd_config_rss,
4993         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
4994         (cmdline_parse_inst_t *)&cmd_showport_reta,
4995         (cmdline_parse_inst_t *)&cmd_config_burst,
4996         (cmdline_parse_inst_t *)&cmd_config_thresh,
4997         (cmdline_parse_inst_t *)&cmd_config_threshold,
4998         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
4999         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
5000         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
5001         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
5002         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
5003         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
5004         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
5005         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
5006         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
5007         NULL,
5008 };
5009
5010 /* prompt function, called from main on MASTER lcore */
5011 void
5012 prompt(void)
5013 {
5014         struct cmdline *cl;
5015
5016         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
5017         if (cl == NULL) {
5018                 return;
5019         }
5020         cmdline_interact(cl);
5021         cmdline_stdin_exit(cl);
5022 }
5023
5024 static void
5025 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
5026 {
5027         if (id < nb_ports) {
5028                 /* check if need_reconfig has been set to 1 */
5029                 if (ports[id].need_reconfig == 0)
5030                         ports[id].need_reconfig = dev;
5031                 /* check if need_reconfig_queues has been set to 1 */
5032                 if (ports[id].need_reconfig_queues == 0)
5033                         ports[id].need_reconfig_queues = queue;
5034         } else {
5035                 portid_t pid;
5036
5037                 for (pid = 0; pid < nb_ports; pid++) {
5038                         /* check if need_reconfig has been set to 1 */
5039                         if (ports[pid].need_reconfig == 0)
5040                                 ports[pid].need_reconfig = dev;
5041                         /* check if need_reconfig_queues has been set to 1 */
5042                         if (ports[pid].need_reconfig_queues == 0)
5043                                 ports[pid].need_reconfig_queues = queue;
5044                 }
5045         }
5046 }
5047
5048 #ifdef RTE_NIC_BYPASS
5049 uint8_t
5050 bypass_is_supported(portid_t port_id)
5051 {
5052         struct rte_port   *port;
5053         struct rte_pci_id *pci_id;
5054
5055         if (port_id >= nb_ports) {
5056                 printf("\tPort id must be less than %d.\n", nb_ports);
5057                 return 0;
5058         }
5059
5060         /* Get the device id. */
5061         port    = &ports[port_id];
5062         pci_id = &port->dev_info.pci_dev->id;
5063
5064         /* Check if NIC supports bypass. */
5065         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
5066                 return 1;
5067         }
5068         else {
5069                 printf("\tBypass not supported for port_id = %d.\n", port_id);
5070                 return 0;
5071         }
5072 }
5073 #endif