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