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