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