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