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