app/testpmd: add commands for link up and down
[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 hash key *** */
1175 struct cmd_config_rss_hash_key {
1176         cmdline_fixed_string_t port;
1177         cmdline_fixed_string_t config;
1178         uint8_t port_id;
1179         cmdline_fixed_string_t rss_hash_key;
1180         cmdline_fixed_string_t key;
1181 };
1182
1183 #define RSS_HASH_KEY_LENGTH 40
1184 static uint8_t
1185 hexa_digit_to_value(char hexa_digit)
1186 {
1187         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1188                 return (uint8_t) (hexa_digit - '0');
1189         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1190                 return (uint8_t) ((hexa_digit - 'a') + 10);
1191         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1192                 return (uint8_t) ((hexa_digit - 'A') + 10);
1193         /* Invalid hexa digit */
1194         return 0xFF;
1195 }
1196
1197 static uint8_t
1198 parse_and_check_key_hexa_digit(char *key, int idx)
1199 {
1200         uint8_t hexa_v;
1201
1202         hexa_v = hexa_digit_to_value(key[idx]);
1203         if (hexa_v == 0xFF)
1204                 printf("invalid key: character %c at position %d is not a "
1205                        "valid hexa digit\n", key[idx], idx);
1206         return hexa_v;
1207 }
1208
1209 static void
1210 cmd_config_rss_hash_key_parsed(void *parsed_result,
1211                                __attribute__((unused)) struct cmdline *cl,
1212                                __attribute__((unused)) void *data)
1213 {
1214         struct cmd_config_rss_hash_key *res = parsed_result;
1215         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1216         uint8_t xdgt0;
1217         uint8_t xdgt1;
1218         int i;
1219
1220         /* Check the length of the RSS hash key */
1221         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1222                 printf("key length: %d invalid - key must be a string of %d"
1223                        "hexa-decimal numbers\n", (int) strlen(res->key),
1224                        RSS_HASH_KEY_LENGTH * 2);
1225                 return;
1226         }
1227         /* Translate RSS hash key into binary representation */
1228         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1229                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1230                 if (xdgt0 == 0xFF)
1231                         return;
1232                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1233                 if (xdgt1 == 0xFF)
1234                         return;
1235                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1236         }
1237         port_rss_hash_key_update(res->port_id, hash_key);
1238 }
1239
1240 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1241         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1242 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1243         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1244                                  "config");
1245 cmdline_parse_token_string_t cmd_config_rss_hash_key_port_id =
1246         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1247 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1249                                  rss_hash_key, "rss-hash-key");
1250 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1251         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1252
1253 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1254         .f = cmd_config_rss_hash_key_parsed,
1255         .data = NULL,
1256         .help_str = "port config X rss-hash-key 80 hexa digits",
1257         .tokens = {
1258                 (void *)&cmd_config_rss_hash_key_port,
1259                 (void *)&cmd_config_rss_hash_key_config,
1260                 (void *)&cmd_config_rss_hash_key_port_id,
1261                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1262                 (void *)&cmd_config_rss_hash_key_value,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** Configure RSS RETA *** */
1268 struct cmd_config_rss_reta {
1269         cmdline_fixed_string_t port;
1270         cmdline_fixed_string_t keyword;
1271         uint8_t port_id;
1272         cmdline_fixed_string_t name;
1273         cmdline_fixed_string_t list_name;
1274         cmdline_fixed_string_t list_of_items;
1275 };
1276
1277 static int
1278 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
1279 {
1280         int i;
1281         unsigned size;
1282         uint8_t hash_index;
1283         uint8_t nb_queue;
1284         char s[256];
1285         const char *p, *p0 = str;
1286         char *end;
1287         enum fieldnames {
1288                 FLD_HASH_INDEX = 0,
1289                 FLD_QUEUE,
1290                 _NUM_FLD
1291         };
1292         unsigned long int_fld[_NUM_FLD];
1293         char *str_fld[_NUM_FLD];
1294
1295         while ((p = strchr(p0,'(')) != NULL) {
1296                 ++p;
1297                 if((p0 = strchr(p,')')) == NULL)
1298                         return -1;
1299
1300                 size = p0 - p;
1301                 if(size >= sizeof(s))
1302                         return -1;
1303
1304                 rte_snprintf(s, sizeof(s), "%.*s", size, p);
1305                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1306                         return -1;
1307                 for (i = 0; i < _NUM_FLD; i++) {
1308                         errno = 0;
1309                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1310                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1311                                 return -1;
1312                 }
1313
1314                 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX];
1315                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1316
1317                 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) {
1318                         printf("Invalid RETA hash index=%d",hash_index);
1319                         return -1;
1320                 }
1321
1322                 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2)
1323                         reta_conf->mask_lo |= (1ULL << hash_index);
1324                 else
1325                         reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2));
1326
1327                 reta_conf->reta[hash_index] = nb_queue;
1328         }
1329
1330         return 0;
1331 }
1332
1333 static void
1334 cmd_set_rss_reta_parsed(void *parsed_result,
1335                                 __attribute__((unused)) struct cmdline *cl,
1336                                 __attribute__((unused)) void *data)
1337 {
1338         int ret;
1339         struct rte_eth_rss_reta reta_conf;
1340         struct cmd_config_rss_reta *res = parsed_result;
1341
1342         memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta));
1343         if (!strcmp(res->list_name, "reta")) {
1344                 if (parse_reta_config(res->list_of_items, &reta_conf)) {
1345                         printf("Invalid RSS Redirection Table config entered\n");
1346                         return;
1347                 }
1348                 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf);
1349                 if (ret != 0)
1350                         printf("Bad redirection table parameter, return code = %d \n",ret);
1351         }
1352 }
1353
1354 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1355         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1356 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1357         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1358 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1359         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1360 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1361         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1362 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1363         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1364 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1365         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1366                                  NULL);
1367 cmdline_parse_inst_t cmd_config_rss_reta = {
1368         .f = cmd_set_rss_reta_parsed,
1369         .data = NULL,
1370         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1371         .tokens = {
1372                 (void *)&cmd_config_rss_reta_port,
1373                 (void *)&cmd_config_rss_reta_keyword,
1374                 (void *)&cmd_config_rss_reta_port_id,
1375                 (void *)&cmd_config_rss_reta_name,
1376                 (void *)&cmd_config_rss_reta_list_name,
1377                 (void *)&cmd_config_rss_reta_list_of_items,
1378                 NULL,
1379         },
1380 };
1381
1382 /* *** SHOW PORT RETA INFO *** */
1383 struct cmd_showport_reta {
1384         cmdline_fixed_string_t show;
1385         cmdline_fixed_string_t port;
1386         uint8_t port_id;
1387         cmdline_fixed_string_t rss;
1388         cmdline_fixed_string_t reta;
1389         uint64_t mask_lo;
1390         uint64_t mask_hi;
1391 };
1392
1393 static void cmd_showport_reta_parsed(void *parsed_result,
1394                                 __attribute__((unused)) struct cmdline *cl,
1395                                 __attribute__((unused)) void *data)
1396 {
1397         struct cmd_showport_reta *res = parsed_result;
1398         struct rte_eth_rss_reta reta_conf;
1399
1400         if ((res->mask_lo == 0) && (res->mask_hi == 0)) {
1401                 printf("Invalid RSS Redirection Table config entered\n");
1402                 return;
1403         }
1404
1405         reta_conf.mask_lo = res->mask_lo;
1406         reta_conf.mask_hi = res->mask_hi;
1407
1408         port_rss_reta_info(res->port_id,&reta_conf);
1409 }
1410
1411 cmdline_parse_token_string_t cmd_showport_reta_show =
1412         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1413 cmdline_parse_token_string_t cmd_showport_reta_port =
1414         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1415 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1416         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1417 cmdline_parse_token_string_t cmd_showport_reta_rss =
1418         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1419 cmdline_parse_token_string_t cmd_showport_reta_reta =
1420         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1421 cmdline_parse_token_num_t cmd_showport_reta_mask_lo =
1422         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64);
1423 cmdline_parse_token_num_t cmd_showport_reta_mask_hi =
1424         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64);
1425
1426 cmdline_parse_inst_t cmd_showport_reta = {
1427         .f = cmd_showport_reta_parsed,
1428         .data = NULL,
1429         .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\
1430                         (mask_lo and mask_hi is UINT64)",
1431         .tokens = {
1432                 (void *)&cmd_showport_reta_show,
1433                 (void *)&cmd_showport_reta_port,
1434                 (void *)&cmd_showport_reta_port_id,
1435                 (void *)&cmd_showport_reta_rss,
1436                 (void *)&cmd_showport_reta_reta,
1437                 (void *)&cmd_showport_reta_mask_lo,
1438                 (void *)&cmd_showport_reta_mask_hi,
1439                 NULL,
1440         },
1441 };
1442
1443 /* *** Show RSS hash configuration *** */
1444 struct cmd_showport_rss_hash {
1445         cmdline_fixed_string_t show;
1446         cmdline_fixed_string_t port;
1447         uint8_t port_id;
1448         cmdline_fixed_string_t rss_hash;
1449         cmdline_fixed_string_t key; /* optional argument */
1450 };
1451
1452 static void cmd_showport_rss_hash_parsed(void *parsed_result,
1453                                 __attribute__((unused)) struct cmdline *cl,
1454                                 void *show_rss_key)
1455 {
1456         struct cmd_showport_rss_hash *res = parsed_result;
1457
1458         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
1459 }
1460
1461 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
1462         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
1463 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
1464         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
1465 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
1466         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
1467 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
1468         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
1469                                  "rss-hash");
1470 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
1471         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
1472
1473 cmdline_parse_inst_t cmd_showport_rss_hash = {
1474         .f = cmd_showport_rss_hash_parsed,
1475         .data = NULL,
1476         .help_str = "show port X rss-hash (X = port number)\n",
1477         .tokens = {
1478                 (void *)&cmd_showport_rss_hash_show,
1479                 (void *)&cmd_showport_rss_hash_port,
1480                 (void *)&cmd_showport_rss_hash_port_id,
1481                 (void *)&cmd_showport_rss_hash_rss_hash,
1482                 NULL,
1483         },
1484 };
1485
1486 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
1487         .f = cmd_showport_rss_hash_parsed,
1488         .data = (void *)1,
1489         .help_str = "show port X rss-hash key (X = port number)\n",
1490         .tokens = {
1491                 (void *)&cmd_showport_rss_hash_show,
1492                 (void *)&cmd_showport_rss_hash_port,
1493                 (void *)&cmd_showport_rss_hash_port_id,
1494                 (void *)&cmd_showport_rss_hash_rss_hash,
1495                 (void *)&cmd_showport_rss_hash_rss_key,
1496                 NULL,
1497         },
1498 };
1499
1500 /* *** Configure DCB *** */
1501 struct cmd_config_dcb {
1502         cmdline_fixed_string_t port;
1503         cmdline_fixed_string_t config;
1504         uint8_t port_id;
1505         cmdline_fixed_string_t dcb;
1506         cmdline_fixed_string_t vt;
1507         cmdline_fixed_string_t vt_en;
1508         uint8_t num_tcs;
1509         cmdline_fixed_string_t pfc;
1510         cmdline_fixed_string_t pfc_en;
1511 };
1512
1513 static void
1514 cmd_config_dcb_parsed(void *parsed_result,
1515                         __attribute__((unused)) struct cmdline *cl,
1516                         __attribute__((unused)) void *data)
1517 {
1518         struct cmd_config_dcb *res = parsed_result;
1519         struct dcb_config dcb_conf;
1520         portid_t port_id = res->port_id;
1521         struct rte_port *port;
1522
1523         port = &ports[port_id];
1524         /** Check if the port is not started **/
1525         if (port->port_status != RTE_PORT_STOPPED) {
1526                 printf("Please stop port %d first\n",port_id);
1527                 return;
1528         }
1529
1530         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
1531         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
1532                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
1533                 return;
1534         }
1535
1536         /* DCB in VT mode */
1537         if (!strncmp(res->vt_en, "on",2))
1538                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
1539         else
1540                 dcb_conf.dcb_mode = DCB_ENABLED;
1541
1542         if (!strncmp(res->pfc_en, "on",2)) {
1543                 dcb_conf.pfc_en = 1;
1544         }
1545         else
1546                 dcb_conf.pfc_en = 0;
1547
1548         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
1549                 printf("Cannot initialize network ports\n");
1550                 return;
1551         }
1552
1553         cmd_reconfig_device_queue(port_id, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_dcb_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
1558 cmdline_parse_token_string_t cmd_config_dcb_config =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
1560 cmdline_parse_token_num_t cmd_config_dcb_port_id =
1561         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
1562 cmdline_parse_token_string_t cmd_config_dcb_dcb =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
1564 cmdline_parse_token_string_t cmd_config_dcb_vt =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
1566 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
1568 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
1569         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
1570 cmdline_parse_token_string_t cmd_config_dcb_pfc=
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
1572 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
1573         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
1574
1575 cmdline_parse_inst_t cmd_config_dcb = {
1576         .f = cmd_config_dcb_parsed,
1577         .data = NULL,
1578         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
1579         .tokens = {
1580                 (void *)&cmd_config_dcb_port,
1581                 (void *)&cmd_config_dcb_config,
1582                 (void *)&cmd_config_dcb_port_id,
1583                 (void *)&cmd_config_dcb_dcb,
1584                 (void *)&cmd_config_dcb_vt,
1585                 (void *)&cmd_config_dcb_vt_en,
1586                 (void *)&cmd_config_dcb_num_tcs,
1587                 (void *)&cmd_config_dcb_pfc,
1588                 (void *)&cmd_config_dcb_pfc_en,
1589                 NULL,
1590         },
1591 };
1592
1593 /* *** configure number of packets per burst *** */
1594 struct cmd_config_burst {
1595         cmdline_fixed_string_t port;
1596         cmdline_fixed_string_t keyword;
1597         cmdline_fixed_string_t all;
1598         cmdline_fixed_string_t name;
1599         uint16_t value;
1600 };
1601
1602 static void
1603 cmd_config_burst_parsed(void *parsed_result,
1604                         __attribute__((unused)) struct cmdline *cl,
1605                         __attribute__((unused)) void *data)
1606 {
1607         struct cmd_config_burst *res = parsed_result;
1608
1609         if (!all_ports_stopped()) {
1610                 printf("Please stop all ports first\n");
1611                 return;
1612         }
1613
1614         if (!strcmp(res->name, "burst")) {
1615                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
1616                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
1617                         return;
1618                 }
1619                 nb_pkt_per_burst = res->value;
1620         } else {
1621                 printf("Unknown parameter\n");
1622                 return;
1623         }
1624
1625         init_port_config();
1626
1627         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1628 }
1629
1630 cmdline_parse_token_string_t cmd_config_burst_port =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
1632 cmdline_parse_token_string_t cmd_config_burst_keyword =
1633         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
1634 cmdline_parse_token_string_t cmd_config_burst_all =
1635         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
1636 cmdline_parse_token_string_t cmd_config_burst_name =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
1638 cmdline_parse_token_num_t cmd_config_burst_value =
1639         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
1640
1641 cmdline_parse_inst_t cmd_config_burst = {
1642         .f = cmd_config_burst_parsed,
1643         .data = NULL,
1644         .help_str = "port config all burst value",
1645         .tokens = {
1646                 (void *)&cmd_config_burst_port,
1647                 (void *)&cmd_config_burst_keyword,
1648                 (void *)&cmd_config_burst_all,
1649                 (void *)&cmd_config_burst_name,
1650                 (void *)&cmd_config_burst_value,
1651                 NULL,
1652         },
1653 };
1654
1655 /* *** configure rx/tx queues *** */
1656 struct cmd_config_thresh {
1657         cmdline_fixed_string_t port;
1658         cmdline_fixed_string_t keyword;
1659         cmdline_fixed_string_t all;
1660         cmdline_fixed_string_t name;
1661         uint8_t value;
1662 };
1663
1664 static void
1665 cmd_config_thresh_parsed(void *parsed_result,
1666                         __attribute__((unused)) struct cmdline *cl,
1667                         __attribute__((unused)) void *data)
1668 {
1669         struct cmd_config_thresh *res = parsed_result;
1670
1671         if (!all_ports_stopped()) {
1672                 printf("Please stop all ports first\n");
1673                 return;
1674         }
1675
1676         if (!strcmp(res->name, "txpt"))
1677                 tx_thresh.pthresh = res->value;
1678         else if(!strcmp(res->name, "txht"))
1679                 tx_thresh.hthresh = res->value;
1680         else if(!strcmp(res->name, "txwt"))
1681                 tx_thresh.wthresh = res->value;
1682         else if(!strcmp(res->name, "rxpt"))
1683                 rx_thresh.pthresh = res->value;
1684         else if(!strcmp(res->name, "rxht"))
1685                 rx_thresh.hthresh = res->value;
1686         else if(!strcmp(res->name, "rxwt"))
1687                 rx_thresh.wthresh = res->value;
1688         else {
1689                 printf("Unknown parameter\n");
1690                 return;
1691         }
1692
1693         init_port_config();
1694
1695         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1696 }
1697
1698 cmdline_parse_token_string_t cmd_config_thresh_port =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
1700 cmdline_parse_token_string_t cmd_config_thresh_keyword =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
1702 cmdline_parse_token_string_t cmd_config_thresh_all =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
1704 cmdline_parse_token_string_t cmd_config_thresh_name =
1705         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
1706                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
1707 cmdline_parse_token_num_t cmd_config_thresh_value =
1708         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
1709
1710 cmdline_parse_inst_t cmd_config_thresh = {
1711         .f = cmd_config_thresh_parsed,
1712         .data = NULL,
1713         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1714         .tokens = {
1715                 (void *)&cmd_config_thresh_port,
1716                 (void *)&cmd_config_thresh_keyword,
1717                 (void *)&cmd_config_thresh_all,
1718                 (void *)&cmd_config_thresh_name,
1719                 (void *)&cmd_config_thresh_value,
1720                 NULL,
1721         },
1722 };
1723
1724 /* *** configure free/rs threshold *** */
1725 struct cmd_config_threshold {
1726         cmdline_fixed_string_t port;
1727         cmdline_fixed_string_t keyword;
1728         cmdline_fixed_string_t all;
1729         cmdline_fixed_string_t name;
1730         uint16_t value;
1731 };
1732
1733 static void
1734 cmd_config_threshold_parsed(void *parsed_result,
1735                         __attribute__((unused)) struct cmdline *cl,
1736                         __attribute__((unused)) void *data)
1737 {
1738         struct cmd_config_threshold *res = parsed_result;
1739
1740         if (!all_ports_stopped()) {
1741                 printf("Please stop all ports first\n");
1742                 return;
1743         }
1744
1745         if (!strcmp(res->name, "txfreet"))
1746                 tx_free_thresh = res->value;
1747         else if (!strcmp(res->name, "txrst"))
1748                 tx_rs_thresh = res->value;
1749         else if (!strcmp(res->name, "rxfreet"))
1750                 rx_free_thresh = res->value;
1751         else {
1752                 printf("Unknown parameter\n");
1753                 return;
1754         }
1755
1756         init_port_config();
1757
1758         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1759 }
1760
1761 cmdline_parse_token_string_t cmd_config_threshold_port =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1763 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1765                                                                 "config");
1766 cmdline_parse_token_string_t cmd_config_threshold_all =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1768 cmdline_parse_token_string_t cmd_config_threshold_name =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1770                                                 "txfreet#txrst#rxfreet");
1771 cmdline_parse_token_num_t cmd_config_threshold_value =
1772         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1773
1774 cmdline_parse_inst_t cmd_config_threshold = {
1775         .f = cmd_config_threshold_parsed,
1776         .data = NULL,
1777         .help_str = "port config all txfreet|txrst|rxfreet value",
1778         .tokens = {
1779                 (void *)&cmd_config_threshold_port,
1780                 (void *)&cmd_config_threshold_keyword,
1781                 (void *)&cmd_config_threshold_all,
1782                 (void *)&cmd_config_threshold_name,
1783                 (void *)&cmd_config_threshold_value,
1784                 NULL,
1785         },
1786 };
1787
1788 /* *** stop *** */
1789 struct cmd_stop_result {
1790         cmdline_fixed_string_t stop;
1791 };
1792
1793 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1794                             __attribute__((unused)) struct cmdline *cl,
1795                             __attribute__((unused)) void *data)
1796 {
1797         stop_packet_forwarding();
1798 }
1799
1800 cmdline_parse_token_string_t cmd_stop_stop =
1801         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1802
1803 cmdline_parse_inst_t cmd_stop = {
1804         .f = cmd_stop_parsed,
1805         .data = NULL,
1806         .help_str = "stop - stop packet forwarding",
1807         .tokens = {
1808                 (void *)&cmd_stop_stop,
1809                 NULL,
1810         },
1811 };
1812
1813 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1814
1815 static unsigned int
1816 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1817                 unsigned int *parsed_items, int check_unique_values)
1818 {
1819         unsigned int nb_item;
1820         unsigned int value;
1821         unsigned int i;
1822         unsigned int j;
1823         int value_ok;
1824         char c;
1825
1826         /*
1827          * First parse all items in the list and store their value.
1828          */
1829         value = 0;
1830         nb_item = 0;
1831         value_ok = 0;
1832         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1833                 c = str[i];
1834                 if ((c >= '0') && (c <= '9')) {
1835                         value = (unsigned int) (value * 10 + (c - '0'));
1836                         value_ok = 1;
1837                         continue;
1838                 }
1839                 if (c != ',') {
1840                         printf("character %c is not a decimal digit\n", c);
1841                         return (0);
1842                 }
1843                 if (! value_ok) {
1844                         printf("No valid value before comma\n");
1845                         return (0);
1846                 }
1847                 if (nb_item < max_items) {
1848                         parsed_items[nb_item] = value;
1849                         value_ok = 0;
1850                         value = 0;
1851                 }
1852                 nb_item++;
1853         }
1854         if (nb_item >= max_items) {
1855                 printf("Number of %s = %u > %u (maximum items)\n",
1856                        item_name, nb_item + 1, max_items);
1857                 return (0);
1858         }
1859         parsed_items[nb_item++] = value;
1860         if (! check_unique_values)
1861                 return (nb_item);
1862
1863         /*
1864          * Then, check that all values in the list are differents.
1865          * No optimization here...
1866          */
1867         for (i = 0; i < nb_item; i++) {
1868                 for (j = i + 1; j < nb_item; j++) {
1869                         if (parsed_items[j] == parsed_items[i]) {
1870                                 printf("duplicated %s %u at index %u and %u\n",
1871                                        item_name, parsed_items[i], i, j);
1872                                 return (0);
1873                         }
1874                 }
1875         }
1876         return (nb_item);
1877 }
1878
1879 struct cmd_set_list_result {
1880         cmdline_fixed_string_t cmd_keyword;
1881         cmdline_fixed_string_t list_name;
1882         cmdline_fixed_string_t list_of_items;
1883 };
1884
1885 static void cmd_set_list_parsed(void *parsed_result,
1886                                 __attribute__((unused)) struct cmdline *cl,
1887                                 __attribute__((unused)) void *data)
1888 {
1889         struct cmd_set_list_result *res;
1890         union {
1891                 unsigned int lcorelist[RTE_MAX_LCORE];
1892                 unsigned int portlist[RTE_MAX_ETHPORTS];
1893         } parsed_items;
1894         unsigned int nb_item;
1895
1896         res = parsed_result;
1897         if (!strcmp(res->list_name, "corelist")) {
1898                 nb_item = parse_item_list(res->list_of_items, "core",
1899                                           RTE_MAX_LCORE,
1900                                           parsed_items.lcorelist, 1);
1901                 if (nb_item > 0)
1902                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
1903                 return;
1904         }
1905         if (!strcmp(res->list_name, "portlist")) {
1906                 nb_item = parse_item_list(res->list_of_items, "port",
1907                                           RTE_MAX_ETHPORTS,
1908                                           parsed_items.portlist, 1);
1909                 if (nb_item > 0)
1910                         set_fwd_ports_list(parsed_items.portlist, nb_item);
1911         }
1912 }
1913
1914 cmdline_parse_token_string_t cmd_set_list_keyword =
1915         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
1916                                  "set");
1917 cmdline_parse_token_string_t cmd_set_list_name =
1918         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
1919                                  "corelist#portlist");
1920 cmdline_parse_token_string_t cmd_set_list_of_items =
1921         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
1922                                  NULL);
1923
1924 cmdline_parse_inst_t cmd_set_fwd_list = {
1925         .f = cmd_set_list_parsed,
1926         .data = NULL,
1927         .help_str = "set corelist|portlist x[,y]*",
1928         .tokens = {
1929                 (void *)&cmd_set_list_keyword,
1930                 (void *)&cmd_set_list_name,
1931                 (void *)&cmd_set_list_of_items,
1932                 NULL,
1933         },
1934 };
1935
1936 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
1937
1938 struct cmd_setmask_result {
1939         cmdline_fixed_string_t set;
1940         cmdline_fixed_string_t mask;
1941         uint64_t hexavalue;
1942 };
1943
1944 static void cmd_set_mask_parsed(void *parsed_result,
1945                                 __attribute__((unused)) struct cmdline *cl,
1946                                 __attribute__((unused)) void *data)
1947 {
1948         struct cmd_setmask_result *res = parsed_result;
1949
1950         if (!strcmp(res->mask, "coremask"))
1951                 set_fwd_lcores_mask(res->hexavalue);
1952         else if (!strcmp(res->mask, "portmask"))
1953                 set_fwd_ports_mask(res->hexavalue);
1954 }
1955
1956 cmdline_parse_token_string_t cmd_setmask_set =
1957         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
1958 cmdline_parse_token_string_t cmd_setmask_mask =
1959         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
1960                                  "coremask#portmask");
1961 cmdline_parse_token_num_t cmd_setmask_value =
1962         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
1963
1964 cmdline_parse_inst_t cmd_set_fwd_mask = {
1965         .f = cmd_set_mask_parsed,
1966         .data = NULL,
1967         .help_str = "set coremask|portmask hexadecimal value",
1968         .tokens = {
1969                 (void *)&cmd_setmask_set,
1970                 (void *)&cmd_setmask_mask,
1971                 (void *)&cmd_setmask_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /*
1977  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
1978  */
1979 struct cmd_set_result {
1980         cmdline_fixed_string_t set;
1981         cmdline_fixed_string_t what;
1982         uint16_t value;
1983 };
1984
1985 static void cmd_set_parsed(void *parsed_result,
1986                            __attribute__((unused)) struct cmdline *cl,
1987                            __attribute__((unused)) void *data)
1988 {
1989         struct cmd_set_result *res = parsed_result;
1990         if (!strcmp(res->what, "nbport"))
1991                 set_fwd_ports_number(res->value);
1992         else if (!strcmp(res->what, "nbcore"))
1993                 set_fwd_lcores_number(res->value);
1994         else if (!strcmp(res->what, "burst"))
1995                 set_nb_pkt_per_burst(res->value);
1996         else if (!strcmp(res->what, "verbose"))
1997                 set_verbose_level(res->value);
1998 }
1999
2000 cmdline_parse_token_string_t cmd_set_set =
2001         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2002 cmdline_parse_token_string_t cmd_set_what =
2003         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2004                                  "nbport#nbcore#burst#verbose");
2005 cmdline_parse_token_num_t cmd_set_value =
2006         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2007
2008 cmdline_parse_inst_t cmd_set_numbers = {
2009         .f = cmd_set_parsed,
2010         .data = NULL,
2011         .help_str = "set nbport|nbcore|burst|verbose value",
2012         .tokens = {
2013                 (void *)&cmd_set_set,
2014                 (void *)&cmd_set_what,
2015                 (void *)&cmd_set_value,
2016                 NULL,
2017         },
2018 };
2019
2020 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2021
2022 struct cmd_set_txpkts_result {
2023         cmdline_fixed_string_t cmd_keyword;
2024         cmdline_fixed_string_t txpkts;
2025         cmdline_fixed_string_t seg_lengths;
2026 };
2027
2028 static void
2029 cmd_set_txpkts_parsed(void *parsed_result,
2030                       __attribute__((unused)) struct cmdline *cl,
2031                       __attribute__((unused)) void *data)
2032 {
2033         struct cmd_set_txpkts_result *res;
2034         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2035         unsigned int nb_segs;
2036
2037         res = parsed_result;
2038         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2039                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2040         if (nb_segs > 0)
2041                 set_tx_pkt_segments(seg_lengths, nb_segs);
2042 }
2043
2044 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2045         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2046                                  cmd_keyword, "set");
2047 cmdline_parse_token_string_t cmd_set_txpkts_name =
2048         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2049                                  txpkts, "txpkts");
2050 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2051         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2052                                  seg_lengths, NULL);
2053
2054 cmdline_parse_inst_t cmd_set_txpkts = {
2055         .f = cmd_set_txpkts_parsed,
2056         .data = NULL,
2057         .help_str = "set txpkts x[,y]*",
2058         .tokens = {
2059                 (void *)&cmd_set_txpkts_keyword,
2060                 (void *)&cmd_set_txpkts_name,
2061                 (void *)&cmd_set_txpkts_lengths,
2062                 NULL,
2063         },
2064 };
2065
2066 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2067 struct cmd_rx_vlan_filter_all_result {
2068         cmdline_fixed_string_t rx_vlan;
2069         cmdline_fixed_string_t what;
2070         cmdline_fixed_string_t all;
2071         uint8_t port_id;
2072 };
2073
2074 static void
2075 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2076                               __attribute__((unused)) struct cmdline *cl,
2077                               __attribute__((unused)) void *data)
2078 {
2079         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2080
2081         if (!strcmp(res->what, "add"))
2082                 rx_vlan_all_filter_set(res->port_id, 1);
2083         else
2084                 rx_vlan_all_filter_set(res->port_id, 0);
2085 }
2086
2087 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2088         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2089                                  rx_vlan, "rx_vlan");
2090 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2091         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2092                                  what, "add#rm");
2093 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2094         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2095                                  all, "all");
2096 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2097         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2098                               port_id, UINT8);
2099
2100 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2101         .f = cmd_rx_vlan_filter_all_parsed,
2102         .data = NULL,
2103         .help_str = "add/remove all identifiers to/from the set of VLAN "
2104         "Identifiers filtered by a port",
2105         .tokens = {
2106                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2107                 (void *)&cmd_rx_vlan_filter_all_what,
2108                 (void *)&cmd_rx_vlan_filter_all_all,
2109                 (void *)&cmd_rx_vlan_filter_all_portid,
2110                 NULL,
2111         },
2112 };
2113
2114 /* *** VLAN OFFLOAD SET ON A PORT *** */
2115 struct cmd_vlan_offload_result {
2116         cmdline_fixed_string_t vlan;
2117         cmdline_fixed_string_t set;
2118         cmdline_fixed_string_t what;
2119         cmdline_fixed_string_t on;
2120         cmdline_fixed_string_t port_id;
2121 };
2122
2123 static void
2124 cmd_vlan_offload_parsed(void *parsed_result,
2125                           __attribute__((unused)) struct cmdline *cl,
2126                           __attribute__((unused)) void *data)
2127 {
2128         int on;
2129         struct cmd_vlan_offload_result *res = parsed_result;
2130         char *str;
2131         int i, len = 0;
2132         portid_t port_id = 0;
2133         unsigned int tmp;
2134
2135         str = res->port_id;
2136         len = strnlen(str, STR_TOKEN_SIZE);
2137         i = 0;
2138         /* Get port_id first */
2139         while(i < len){
2140                 if(str[i] == ',')
2141                         break;
2142
2143                 i++;
2144         }
2145         str[i]='\0';
2146         tmp = strtoul(str, NULL, 0);
2147         /* If port_id greater that what portid_t can represent, return */
2148         if(tmp >= RTE_MAX_ETHPORTS)
2149                 return;
2150         port_id = (portid_t)tmp;
2151
2152         if (!strcmp(res->on, "on"))
2153                 on = 1;
2154         else
2155                 on = 0;
2156
2157         if (!strcmp(res->what, "strip"))
2158                 rx_vlan_strip_set(port_id,  on);
2159         else if(!strcmp(res->what, "stripq")){
2160                 uint16_t queue_id = 0;
2161
2162                 /* No queue_id, return */
2163                 if(i + 1 >= len) {
2164                         printf("must specify (port,queue_id)\n");
2165                         return;
2166                 }
2167                 tmp = strtoul(str + i + 1, NULL, 0);
2168                 /* If queue_id greater that what 16-bits can represent, return */
2169                 if(tmp > 0xffff)
2170                         return;
2171
2172                 queue_id = (uint16_t)tmp;
2173                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2174         }
2175         else if (!strcmp(res->what, "filter"))
2176                 rx_vlan_filter_set(port_id, on);
2177         else
2178                 vlan_extend_set(port_id, on);
2179
2180         return;
2181 }
2182
2183 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2184         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2185                                  vlan, "vlan");
2186 cmdline_parse_token_string_t cmd_vlan_offload_set =
2187         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2188                                  set, "set");
2189 cmdline_parse_token_string_t cmd_vlan_offload_what =
2190         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2191                                  what, "strip#filter#qinq#stripq");
2192 cmdline_parse_token_string_t cmd_vlan_offload_on =
2193         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2194                               on, "on#off");
2195 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2196         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2197                               port_id, NULL);
2198
2199 cmdline_parse_inst_t cmd_vlan_offload = {
2200         .f = cmd_vlan_offload_parsed,
2201         .data = NULL,
2202         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2203         " qinq(extended) for both rx/tx sides ",
2204         .tokens = {
2205                 (void *)&cmd_vlan_offload_vlan,
2206                 (void *)&cmd_vlan_offload_set,
2207                 (void *)&cmd_vlan_offload_what,
2208                 (void *)&cmd_vlan_offload_on,
2209                 (void *)&cmd_vlan_offload_portid,
2210                 NULL,
2211         },
2212 };
2213
2214 /* *** VLAN TPID SET ON A PORT *** */
2215 struct cmd_vlan_tpid_result {
2216         cmdline_fixed_string_t vlan;
2217         cmdline_fixed_string_t set;
2218         cmdline_fixed_string_t what;
2219         uint16_t tp_id;
2220         uint8_t port_id;
2221 };
2222
2223 static void
2224 cmd_vlan_tpid_parsed(void *parsed_result,
2225                           __attribute__((unused)) struct cmdline *cl,
2226                           __attribute__((unused)) void *data)
2227 {
2228         struct cmd_vlan_tpid_result *res = parsed_result;
2229         vlan_tpid_set(res->port_id, res->tp_id);
2230         return;
2231 }
2232
2233 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2234         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2235                                  vlan, "vlan");
2236 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2237         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2238                                  set, "set");
2239 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2241                                  what, "tpid");
2242 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2243         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2244                               tp_id, UINT16);
2245 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2246         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2247                               port_id, UINT8);
2248
2249 cmdline_parse_inst_t cmd_vlan_tpid = {
2250         .f = cmd_vlan_tpid_parsed,
2251         .data = NULL,
2252         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2253         .tokens = {
2254                 (void *)&cmd_vlan_tpid_vlan,
2255                 (void *)&cmd_vlan_tpid_set,
2256                 (void *)&cmd_vlan_tpid_what,
2257                 (void *)&cmd_vlan_tpid_tpid,
2258                 (void *)&cmd_vlan_tpid_portid,
2259                 NULL,
2260         },
2261 };
2262
2263 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2264 struct cmd_rx_vlan_filter_result {
2265         cmdline_fixed_string_t rx_vlan;
2266         cmdline_fixed_string_t what;
2267         uint16_t vlan_id;
2268         uint8_t port_id;
2269 };
2270
2271 static void
2272 cmd_rx_vlan_filter_parsed(void *parsed_result,
2273                           __attribute__((unused)) struct cmdline *cl,
2274                           __attribute__((unused)) void *data)
2275 {
2276         struct cmd_rx_vlan_filter_result *res = parsed_result;
2277
2278         if (!strcmp(res->what, "add"))
2279                 rx_vft_set(res->port_id, res->vlan_id, 1);
2280         else
2281                 rx_vft_set(res->port_id, res->vlan_id, 0);
2282 }
2283
2284 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2285         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2286                                  rx_vlan, "rx_vlan");
2287 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2288         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2289                                  what, "add#rm");
2290 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2291         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2292                               vlan_id, UINT16);
2293 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2294         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2295                               port_id, UINT8);
2296
2297 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2298         .f = cmd_rx_vlan_filter_parsed,
2299         .data = NULL,
2300         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2301         "Identifiers filtered by a port",
2302         .tokens = {
2303                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2304                 (void *)&cmd_rx_vlan_filter_what,
2305                 (void *)&cmd_rx_vlan_filter_vlanid,
2306                 (void *)&cmd_rx_vlan_filter_portid,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2312 struct cmd_tx_vlan_set_result {
2313         cmdline_fixed_string_t tx_vlan;
2314         cmdline_fixed_string_t set;
2315         uint16_t vlan_id;
2316         uint8_t port_id;
2317 };
2318
2319 static void
2320 cmd_tx_vlan_set_parsed(void *parsed_result,
2321                        __attribute__((unused)) struct cmdline *cl,
2322                        __attribute__((unused)) void *data)
2323 {
2324         struct cmd_tx_vlan_set_result *res = parsed_result;
2325         tx_vlan_set(res->port_id, res->vlan_id);
2326 }
2327
2328 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2329         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2330                                  tx_vlan, "tx_vlan");
2331 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2332         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2333                                  set, "set");
2334 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2335         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2336                               vlan_id, UINT16);
2337 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2338         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2339                               port_id, UINT8);
2340
2341 cmdline_parse_inst_t cmd_tx_vlan_set = {
2342         .f = cmd_tx_vlan_set_parsed,
2343         .data = NULL,
2344         .help_str = "enable hardware insertion of a VLAN header with a given "
2345         "TAG Identifier in packets sent on a port",
2346         .tokens = {
2347                 (void *)&cmd_tx_vlan_set_tx_vlan,
2348                 (void *)&cmd_tx_vlan_set_set,
2349                 (void *)&cmd_tx_vlan_set_vlanid,
2350                 (void *)&cmd_tx_vlan_set_portid,
2351                 NULL,
2352         },
2353 };
2354
2355 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2356 struct cmd_tx_vlan_reset_result {
2357         cmdline_fixed_string_t tx_vlan;
2358         cmdline_fixed_string_t reset;
2359         uint8_t port_id;
2360 };
2361
2362 static void
2363 cmd_tx_vlan_reset_parsed(void *parsed_result,
2364                          __attribute__((unused)) struct cmdline *cl,
2365                          __attribute__((unused)) void *data)
2366 {
2367         struct cmd_tx_vlan_reset_result *res = parsed_result;
2368
2369         tx_vlan_reset(res->port_id);
2370 }
2371
2372 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2373         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2374                                  tx_vlan, "tx_vlan");
2375 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2376         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2377                                  reset, "reset");
2378 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2379         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2380                               port_id, UINT8);
2381
2382 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2383         .f = cmd_tx_vlan_reset_parsed,
2384         .data = NULL,
2385         .help_str = "disable hardware insertion of a VLAN header in packets "
2386         "sent on a port",
2387         .tokens = {
2388                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2389                 (void *)&cmd_tx_vlan_reset_reset,
2390                 (void *)&cmd_tx_vlan_reset_portid,
2391                 NULL,
2392         },
2393 };
2394
2395
2396 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2397 struct cmd_tx_cksum_set_result {
2398         cmdline_fixed_string_t tx_cksum;
2399         cmdline_fixed_string_t set;
2400         uint8_t cksum_mask;
2401         uint8_t port_id;
2402 };
2403
2404 static void
2405 cmd_tx_cksum_set_parsed(void *parsed_result,
2406                        __attribute__((unused)) struct cmdline *cl,
2407                        __attribute__((unused)) void *data)
2408 {
2409         struct cmd_tx_cksum_set_result *res = parsed_result;
2410
2411         tx_cksum_set(res->port_id, res->cksum_mask);
2412 }
2413
2414 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
2415         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2416                                 tx_cksum, "tx_checksum");
2417 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
2418         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2419                                 set, "set");
2420 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
2421         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2422                                 cksum_mask, UINT8);
2423 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
2424         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2425                                 port_id, UINT8);
2426
2427 cmdline_parse_inst_t cmd_tx_cksum_set = {
2428         .f = cmd_tx_cksum_set_parsed,
2429         .data = NULL,
2430         .help_str = "enable hardware insertion of L3/L4checksum with a given "
2431         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
2432         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
2433         .tokens = {
2434                 (void *)&cmd_tx_cksum_set_tx_cksum,
2435                 (void *)&cmd_tx_cksum_set_set,
2436                 (void *)&cmd_tx_cksum_set_cksum_mask,
2437                 (void *)&cmd_tx_cksum_set_portid,
2438                 NULL,
2439         },
2440 };
2441
2442 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
2443 struct cmd_set_flush_rx {
2444         cmdline_fixed_string_t set;
2445         cmdline_fixed_string_t flush_rx;
2446         cmdline_fixed_string_t mode;
2447 };
2448
2449 static void
2450 cmd_set_flush_rx_parsed(void *parsed_result,
2451                 __attribute__((unused)) struct cmdline *cl,
2452                 __attribute__((unused)) void *data)
2453 {
2454         struct cmd_set_flush_rx *res = parsed_result;
2455         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2456 }
2457
2458 cmdline_parse_token_string_t cmd_setflushrx_set =
2459         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2460                         set, "set");
2461 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
2462         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2463                         flush_rx, "flush_rx");
2464 cmdline_parse_token_string_t cmd_setflushrx_mode =
2465         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2466                         mode, "on#off");
2467
2468
2469 cmdline_parse_inst_t cmd_set_flush_rx = {
2470         .f = cmd_set_flush_rx_parsed,
2471         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
2472         .data = NULL,
2473         .tokens = {
2474                 (void *)&cmd_setflushrx_set,
2475                 (void *)&cmd_setflushrx_flush_rx,
2476                 (void *)&cmd_setflushrx_mode,
2477                 NULL,
2478         },
2479 };
2480
2481 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
2482 struct cmd_set_link_check {
2483         cmdline_fixed_string_t set;
2484         cmdline_fixed_string_t link_check;
2485         cmdline_fixed_string_t mode;
2486 };
2487
2488 static void
2489 cmd_set_link_check_parsed(void *parsed_result,
2490                 __attribute__((unused)) struct cmdline *cl,
2491                 __attribute__((unused)) void *data)
2492 {
2493         struct cmd_set_link_check *res = parsed_result;
2494         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2495 }
2496
2497 cmdline_parse_token_string_t cmd_setlinkcheck_set =
2498         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2499                         set, "set");
2500 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
2501         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2502                         link_check, "link_check");
2503 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
2504         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2505                         mode, "on#off");
2506
2507
2508 cmdline_parse_inst_t cmd_set_link_check = {
2509         .f = cmd_set_link_check_parsed,
2510         .help_str = "set link_check on|off: enable/disable link status check "
2511                     "when starting/stopping a port",
2512         .data = NULL,
2513         .tokens = {
2514                 (void *)&cmd_setlinkcheck_set,
2515                 (void *)&cmd_setlinkcheck_link_check,
2516                 (void *)&cmd_setlinkcheck_mode,
2517                 NULL,
2518         },
2519 };
2520
2521 #ifdef RTE_NIC_BYPASS
2522 /* *** SET NIC BYPASS MODE *** */
2523 struct cmd_set_bypass_mode_result {
2524         cmdline_fixed_string_t set;
2525         cmdline_fixed_string_t bypass;
2526         cmdline_fixed_string_t mode;
2527         cmdline_fixed_string_t value;
2528         uint8_t port_id;
2529 };
2530
2531 static void
2532 cmd_set_bypass_mode_parsed(void *parsed_result,
2533                 __attribute__((unused)) struct cmdline *cl,
2534                 __attribute__((unused)) void *data)
2535 {
2536         struct cmd_set_bypass_mode_result *res = parsed_result;
2537         portid_t port_id = res->port_id;
2538         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2539
2540         if (!bypass_is_supported(port_id))
2541                 return;
2542
2543         if (!strcmp(res->value, "bypass"))
2544                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2545         else if (!strcmp(res->value, "isolate"))
2546                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2547         else
2548                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2549
2550         /* Set the bypass mode for the relevant port. */
2551         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
2552                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
2553         }
2554 }
2555
2556 cmdline_parse_token_string_t cmd_setbypass_mode_set =
2557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2558                         set, "set");
2559 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
2560         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2561                         bypass, "bypass");
2562 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
2563         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2564                         mode, "mode");
2565 cmdline_parse_token_string_t cmd_setbypass_mode_value =
2566         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2567                         value, "normal#bypass#isolate");
2568 cmdline_parse_token_num_t cmd_setbypass_mode_port =
2569         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
2570                                 port_id, UINT8);
2571
2572 cmdline_parse_inst_t cmd_set_bypass_mode = {
2573         .f = cmd_set_bypass_mode_parsed,
2574         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
2575                     "Set the NIC bypass mode for port_id",
2576         .data = NULL,
2577         .tokens = {
2578                 (void *)&cmd_setbypass_mode_set,
2579                 (void *)&cmd_setbypass_mode_bypass,
2580                 (void *)&cmd_setbypass_mode_mode,
2581                 (void *)&cmd_setbypass_mode_value,
2582                 (void *)&cmd_setbypass_mode_port,
2583                 NULL,
2584         },
2585 };
2586
2587 /* *** SET NIC BYPASS EVENT *** */
2588 struct cmd_set_bypass_event_result {
2589         cmdline_fixed_string_t set;
2590         cmdline_fixed_string_t bypass;
2591         cmdline_fixed_string_t event;
2592         cmdline_fixed_string_t event_value;
2593         cmdline_fixed_string_t mode;
2594         cmdline_fixed_string_t mode_value;
2595         uint8_t port_id;
2596 };
2597
2598 static void
2599 cmd_set_bypass_event_parsed(void *parsed_result,
2600                 __attribute__((unused)) struct cmdline *cl,
2601                 __attribute__((unused)) void *data)
2602 {
2603         int32_t rc;
2604         struct cmd_set_bypass_event_result *res = parsed_result;
2605         portid_t port_id = res->port_id;
2606         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
2607         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2608
2609         if (!bypass_is_supported(port_id))
2610                 return;
2611
2612         if (!strcmp(res->event_value, "timeout"))
2613                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
2614         else if (!strcmp(res->event_value, "os_on"))
2615                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
2616         else if (!strcmp(res->event_value, "os_off"))
2617                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
2618         else if (!strcmp(res->event_value, "power_on"))
2619                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
2620         else if (!strcmp(res->event_value, "power_off"))
2621                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
2622         else
2623                 bypass_event = RTE_BYPASS_EVENT_NONE;
2624
2625         if (!strcmp(res->mode_value, "bypass"))
2626                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2627         else if (!strcmp(res->mode_value, "isolate"))
2628                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2629         else
2630                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2631
2632         /* Set the watchdog timeout. */
2633         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
2634
2635                 rc = -EINVAL;
2636                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
2637                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
2638                                 bypass_timeout)) != 0) {
2639                         printf("Failed to set timeout value %u "
2640                                 "for port %d, errto code: %d.\n",
2641                                 bypass_timeout, port_id, rc);
2642                 }
2643         }
2644
2645         /* Set the bypass event to transition to bypass mode. */
2646         if (0 != rte_eth_dev_bypass_event_store(port_id,
2647                         bypass_event, bypass_mode)) {
2648                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
2649         }
2650
2651 }
2652
2653 cmdline_parse_token_string_t cmd_setbypass_event_set =
2654         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2655                         set, "set");
2656 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
2657         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2658                         bypass, "bypass");
2659 cmdline_parse_token_string_t cmd_setbypass_event_event =
2660         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2661                         event, "event");
2662 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
2663         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2664                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
2665 cmdline_parse_token_string_t cmd_setbypass_event_mode =
2666         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2667                         mode, "mode");
2668 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
2669         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2670                         mode_value, "normal#bypass#isolate");
2671 cmdline_parse_token_num_t cmd_setbypass_event_port =
2672         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
2673                                 port_id, UINT8);
2674
2675 cmdline_parse_inst_t cmd_set_bypass_event = {
2676         .f = cmd_set_bypass_event_parsed,
2677         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
2678                     "mode (normal|bypass|isolate) (port_id): "
2679                     "Set the NIC bypass event mode for port_id",
2680         .data = NULL,
2681         .tokens = {
2682                 (void *)&cmd_setbypass_event_set,
2683                 (void *)&cmd_setbypass_event_bypass,
2684                 (void *)&cmd_setbypass_event_event,
2685                 (void *)&cmd_setbypass_event_event_value,
2686                 (void *)&cmd_setbypass_event_mode,
2687                 (void *)&cmd_setbypass_event_mode_value,
2688                 (void *)&cmd_setbypass_event_port,
2689                 NULL,
2690         },
2691 };
2692
2693
2694 /* *** SET NIC BYPASS TIMEOUT *** */
2695 struct cmd_set_bypass_timeout_result {
2696         cmdline_fixed_string_t set;
2697         cmdline_fixed_string_t bypass;
2698         cmdline_fixed_string_t timeout;
2699         cmdline_fixed_string_t value;
2700 };
2701
2702 static void
2703 cmd_set_bypass_timeout_parsed(void *parsed_result,
2704                 __attribute__((unused)) struct cmdline *cl,
2705                 __attribute__((unused)) void *data)
2706 {
2707         struct cmd_set_bypass_timeout_result *res = parsed_result;
2708
2709         if (!strcmp(res->value, "1.5"))
2710                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
2711         else if (!strcmp(res->value, "2"))
2712                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
2713         else if (!strcmp(res->value, "3"))
2714                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
2715         else if (!strcmp(res->value, "4"))
2716                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
2717         else if (!strcmp(res->value, "8"))
2718                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
2719         else if (!strcmp(res->value, "16"))
2720                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
2721         else if (!strcmp(res->value, "32"))
2722                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
2723         else
2724                 bypass_timeout = RTE_BYPASS_TMT_OFF;
2725 }
2726
2727 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
2728         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2729                         set, "set");
2730 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
2731         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2732                         bypass, "bypass");
2733 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
2734         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2735                         timeout, "timeout");
2736 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
2737         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2738                         value, "0#1.5#2#3#4#8#16#32");
2739
2740 cmdline_parse_inst_t cmd_set_bypass_timeout = {
2741         .f = cmd_set_bypass_timeout_parsed,
2742         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
2743                     "Set the NIC bypass watchdog timeout",
2744         .data = NULL,
2745         .tokens = {
2746                 (void *)&cmd_setbypass_timeout_set,
2747                 (void *)&cmd_setbypass_timeout_bypass,
2748                 (void *)&cmd_setbypass_timeout_timeout,
2749                 (void *)&cmd_setbypass_timeout_value,
2750                 NULL,
2751         },
2752 };
2753
2754 /* *** SHOW NIC BYPASS MODE *** */
2755 struct cmd_show_bypass_config_result {
2756         cmdline_fixed_string_t show;
2757         cmdline_fixed_string_t bypass;
2758         cmdline_fixed_string_t config;
2759         uint8_t port_id;
2760 };
2761
2762 static void
2763 cmd_show_bypass_config_parsed(void *parsed_result,
2764                 __attribute__((unused)) struct cmdline *cl,
2765                 __attribute__((unused)) void *data)
2766 {
2767         struct cmd_show_bypass_config_result *res = parsed_result;
2768         uint32_t event_mode;
2769         uint32_t bypass_mode;
2770         portid_t port_id = res->port_id;
2771         uint32_t timeout = bypass_timeout;
2772         int i;
2773
2774         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
2775                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
2776         static const char * const modes[RTE_BYPASS_MODE_NUM] =
2777                 {"UNKNOWN", "normal", "bypass", "isolate"};
2778         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
2779                 "NONE",
2780                 "OS/board on",
2781                 "power supply on",
2782                 "OS/board off",
2783                 "power supply off",
2784                 "timeout"};
2785         int num_events = (sizeof events) / (sizeof events[0]);
2786
2787         if (!bypass_is_supported(port_id))
2788                 return;
2789
2790         /* Display the bypass mode.*/
2791         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
2792                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
2793                 return;
2794         }
2795         else {
2796                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
2797                         bypass_mode = RTE_BYPASS_MODE_NONE;
2798
2799                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
2800         }
2801
2802         /* Display the bypass timeout.*/
2803         if (!RTE_BYPASS_TMT_VALID(timeout))
2804                 timeout = RTE_BYPASS_TMT_OFF;
2805
2806         printf("\tbypass timeout = %s\n", timeouts[timeout]);
2807
2808         /* Display the bypass events and associated modes. */
2809         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
2810
2811                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
2812                         printf("\tFailed to get bypass mode for event = %s\n",
2813                                 events[i]);
2814                 } else {
2815                         if (!RTE_BYPASS_MODE_VALID(event_mode))
2816                                 event_mode = RTE_BYPASS_MODE_NONE;
2817
2818                         printf("\tbypass event: %-16s = %s\n", events[i],
2819                                 modes[event_mode]);
2820                 }
2821         }
2822 }
2823
2824 cmdline_parse_token_string_t cmd_showbypass_config_show =
2825         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2826                         show, "show");
2827 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
2828         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2829                         bypass, "bypass");
2830 cmdline_parse_token_string_t cmd_showbypass_config_config =
2831         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
2832                         config, "config");
2833 cmdline_parse_token_num_t cmd_showbypass_config_port =
2834         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
2835                                 port_id, UINT8);
2836
2837 cmdline_parse_inst_t cmd_show_bypass_config = {
2838         .f = cmd_show_bypass_config_parsed,
2839         .help_str = "show bypass config (port_id): "
2840                     "Show the NIC bypass config for port_id",
2841         .data = NULL,
2842         .tokens = {
2843                 (void *)&cmd_showbypass_config_show,
2844                 (void *)&cmd_showbypass_config_bypass,
2845                 (void *)&cmd_showbypass_config_config,
2846                 (void *)&cmd_showbypass_config_port,
2847                 NULL,
2848         },
2849 };
2850 #endif
2851
2852 /* *** SET FORWARDING MODE *** */
2853 struct cmd_set_fwd_mode_result {
2854         cmdline_fixed_string_t set;
2855         cmdline_fixed_string_t fwd;
2856         cmdline_fixed_string_t mode;
2857 };
2858
2859 static void cmd_set_fwd_mode_parsed(void *parsed_result,
2860                                     __attribute__((unused)) struct cmdline *cl,
2861                                     __attribute__((unused)) void *data)
2862 {
2863         struct cmd_set_fwd_mode_result *res = parsed_result;
2864
2865         set_pkt_forwarding_mode(res->mode);
2866 }
2867
2868 cmdline_parse_token_string_t cmd_setfwd_set =
2869         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
2870 cmdline_parse_token_string_t cmd_setfwd_fwd =
2871         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
2872 cmdline_parse_token_string_t cmd_setfwd_mode =
2873         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
2874                 "" /* defined at init */);
2875
2876 cmdline_parse_inst_t cmd_set_fwd_mode = {
2877         .f = cmd_set_fwd_mode_parsed,
2878         .data = NULL,
2879         .help_str = NULL, /* defined at init */
2880         .tokens = {
2881                 (void *)&cmd_setfwd_set,
2882                 (void *)&cmd_setfwd_fwd,
2883                 (void *)&cmd_setfwd_mode,
2884                 NULL,
2885         },
2886 };
2887
2888 static void cmd_set_fwd_mode_init(void)
2889 {
2890         char *modes, *c;
2891         static char token[128];
2892         static char help[256];
2893         cmdline_parse_token_string_t *token_struct;
2894
2895         modes = list_pkt_forwarding_modes();
2896         rte_snprintf(help, sizeof help, "set fwd %s - "
2897                 "set packet forwarding mode", modes);
2898         cmd_set_fwd_mode.help_str = help;
2899
2900         /* string token separator is # */
2901         for (c = token; *modes != '\0'; modes++)
2902                 if (*modes == '|')
2903                         *c++ = '#';
2904                 else
2905                         *c++ = *modes;
2906         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
2907         token_struct->string_data.str = token;
2908 }
2909
2910 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
2911 struct cmd_set_burst_tx_retry_result {
2912         cmdline_fixed_string_t set;
2913         cmdline_fixed_string_t burst;
2914         cmdline_fixed_string_t tx;
2915         cmdline_fixed_string_t delay;
2916         uint32_t time;
2917         cmdline_fixed_string_t retry;
2918         uint32_t retry_num;
2919 };
2920
2921 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
2922                                         __attribute__((unused)) struct cmdline *cl,
2923                                         __attribute__((unused)) void *data)
2924 {
2925         struct cmd_set_burst_tx_retry_result *res = parsed_result;
2926
2927         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
2928                 && !strcmp(res->tx, "tx")) {
2929                 if (!strcmp(res->delay, "delay"))
2930                         burst_tx_delay_time = res->time;
2931                 if (!strcmp(res->retry, "retry"))
2932                         burst_tx_retry_num = res->retry_num;
2933         }
2934
2935 }
2936
2937 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
2938         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
2939 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
2940         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
2941                                  "burst");
2942 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
2943         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
2944 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
2945         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
2946 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
2947         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
2948 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
2949         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
2950 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
2951         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
2952
2953 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
2954         .f = cmd_set_burst_tx_retry_parsed,
2955         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
2956         .tokens = {
2957                 (void *)&cmd_set_burst_tx_retry_set,
2958                 (void *)&cmd_set_burst_tx_retry_burst,
2959                 (void *)&cmd_set_burst_tx_retry_tx,
2960                 (void *)&cmd_set_burst_tx_retry_delay,
2961                 (void *)&cmd_set_burst_tx_retry_time,
2962                 (void *)&cmd_set_burst_tx_retry_retry,
2963                 (void *)&cmd_set_burst_tx_retry_retry_num,
2964                 NULL,
2965         },
2966 };
2967
2968 /* *** SET PROMISC MODE *** */
2969 struct cmd_set_promisc_mode_result {
2970         cmdline_fixed_string_t set;
2971         cmdline_fixed_string_t promisc;
2972         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
2973         uint8_t port_num;                /* valid if "allports" argument == 0 */
2974         cmdline_fixed_string_t mode;
2975 };
2976
2977 static void cmd_set_promisc_mode_parsed(void *parsed_result,
2978                                         __attribute__((unused)) struct cmdline *cl,
2979                                         void *allports)
2980 {
2981         struct cmd_set_promisc_mode_result *res = parsed_result;
2982         int enable;
2983         portid_t i;
2984
2985         if (!strcmp(res->mode, "on"))
2986                 enable = 1;
2987         else
2988                 enable = 0;
2989
2990         /* all ports */
2991         if (allports) {
2992                 for (i = 0; i < nb_ports; i++) {
2993                         if (enable)
2994                                 rte_eth_promiscuous_enable(i);
2995                         else
2996                                 rte_eth_promiscuous_disable(i);
2997                 }
2998         }
2999         else {
3000                 if (enable)
3001                         rte_eth_promiscuous_enable(res->port_num);
3002                 else
3003                         rte_eth_promiscuous_disable(res->port_num);
3004         }
3005 }
3006
3007 cmdline_parse_token_string_t cmd_setpromisc_set =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
3009 cmdline_parse_token_string_t cmd_setpromisc_promisc =
3010         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
3011                                  "promisc");
3012 cmdline_parse_token_string_t cmd_setpromisc_portall =
3013         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
3014                                  "all");
3015 cmdline_parse_token_num_t cmd_setpromisc_portnum =
3016         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
3017                               UINT8);
3018 cmdline_parse_token_string_t cmd_setpromisc_mode =
3019         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
3020                                  "on#off");
3021
3022 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
3023         .f = cmd_set_promisc_mode_parsed,
3024         .data = (void *)1,
3025         .help_str = "set promisc all on|off: set promisc mode for all ports",
3026         .tokens = {
3027                 (void *)&cmd_setpromisc_set,
3028                 (void *)&cmd_setpromisc_promisc,
3029                 (void *)&cmd_setpromisc_portall,
3030                 (void *)&cmd_setpromisc_mode,
3031                 NULL,
3032         },
3033 };
3034
3035 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
3036         .f = cmd_set_promisc_mode_parsed,
3037         .data = (void *)0,
3038         .help_str = "set promisc X on|off: set promisc mode on port X",
3039         .tokens = {
3040                 (void *)&cmd_setpromisc_set,
3041                 (void *)&cmd_setpromisc_promisc,
3042                 (void *)&cmd_setpromisc_portnum,
3043                 (void *)&cmd_setpromisc_mode,
3044                 NULL,
3045         },
3046 };
3047
3048 /* *** SET ALLMULTI MODE *** */
3049 struct cmd_set_allmulti_mode_result {
3050         cmdline_fixed_string_t set;
3051         cmdline_fixed_string_t allmulti;
3052         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
3053         uint8_t port_num;                /* valid if "allports" argument == 0 */
3054         cmdline_fixed_string_t mode;
3055 };
3056
3057 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
3058                                         __attribute__((unused)) struct cmdline *cl,
3059                                         void *allports)
3060 {
3061         struct cmd_set_allmulti_mode_result *res = parsed_result;
3062         int enable;
3063         portid_t i;
3064
3065         if (!strcmp(res->mode, "on"))
3066                 enable = 1;
3067         else
3068                 enable = 0;
3069
3070         /* all ports */
3071         if (allports) {
3072                 for (i = 0; i < nb_ports; i++) {
3073                         if (enable)
3074                                 rte_eth_allmulticast_enable(i);
3075                         else
3076                                 rte_eth_allmulticast_disable(i);
3077                 }
3078         }
3079         else {
3080                 if (enable)
3081                         rte_eth_allmulticast_enable(res->port_num);
3082                 else
3083                         rte_eth_allmulticast_disable(res->port_num);
3084         }
3085 }
3086
3087 cmdline_parse_token_string_t cmd_setallmulti_set =
3088         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
3089 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
3090         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
3091                                  "allmulti");
3092 cmdline_parse_token_string_t cmd_setallmulti_portall =
3093         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
3094                                  "all");
3095 cmdline_parse_token_num_t cmd_setallmulti_portnum =
3096         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
3097                               UINT8);
3098 cmdline_parse_token_string_t cmd_setallmulti_mode =
3099         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
3100                                  "on#off");
3101
3102 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
3103         .f = cmd_set_allmulti_mode_parsed,
3104         .data = (void *)1,
3105         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
3106         .tokens = {
3107                 (void *)&cmd_setallmulti_set,
3108                 (void *)&cmd_setallmulti_allmulti,
3109                 (void *)&cmd_setallmulti_portall,
3110                 (void *)&cmd_setallmulti_mode,
3111                 NULL,
3112         },
3113 };
3114
3115 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
3116         .f = cmd_set_allmulti_mode_parsed,
3117         .data = (void *)0,
3118         .help_str = "set allmulti X on|off: set allmulti mode on port X",
3119         .tokens = {
3120                 (void *)&cmd_setallmulti_set,
3121                 (void *)&cmd_setallmulti_allmulti,
3122                 (void *)&cmd_setallmulti_portnum,
3123                 (void *)&cmd_setallmulti_mode,
3124                 NULL,
3125         },
3126 };
3127
3128 /* *** ADD/REMOVE A PKT FILTER *** */
3129 struct cmd_pkt_filter_result {
3130         cmdline_fixed_string_t pkt_filter;
3131         uint8_t  port_id;
3132         cmdline_fixed_string_t protocol;
3133         cmdline_fixed_string_t src;
3134         cmdline_ipaddr_t ip_src;
3135         uint16_t port_src;
3136         cmdline_fixed_string_t dst;
3137         cmdline_ipaddr_t ip_dst;
3138         uint16_t port_dst;
3139         cmdline_fixed_string_t flexbytes;
3140         uint16_t flexbytes_value;
3141         cmdline_fixed_string_t vlan;
3142         uint16_t  vlan_id;
3143         cmdline_fixed_string_t queue;
3144         int8_t  queue_id;
3145         cmdline_fixed_string_t soft;
3146         uint8_t  soft_id;
3147 };
3148
3149 static void
3150 cmd_pkt_filter_parsed(void *parsed_result,
3151                           __attribute__((unused)) struct cmdline *cl,
3152                           __attribute__((unused)) void *data)
3153 {
3154         struct rte_fdir_filter fdir_filter;
3155         struct cmd_pkt_filter_result *res = parsed_result;
3156
3157         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
3158
3159         if (res->ip_src.family == AF_INET)
3160                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
3161         else
3162                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
3163                        &(res->ip_src.addr.ipv6),
3164                        sizeof(struct in6_addr));
3165
3166         if (res->ip_dst.family == AF_INET)
3167                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
3168         else
3169                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
3170                        &(res->ip_dst.addr.ipv6),
3171                        sizeof(struct in6_addr));
3172
3173         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
3174         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
3175
3176         if (!strcmp(res->protocol, "udp"))
3177                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
3178         else if (!strcmp(res->protocol, "tcp"))
3179                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
3180         else if (!strcmp(res->protocol, "sctp"))
3181                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
3182         else /* default only IP */
3183                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
3184
3185         if (res->ip_dst.family == AF_INET6)
3186                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
3187         else
3188                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
3189
3190         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
3191         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
3192
3193         if (!strcmp(res->pkt_filter, "add_signature_filter"))
3194                 fdir_add_signature_filter(res->port_id, res->queue_id,
3195                                           &fdir_filter);
3196         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
3197                 fdir_update_signature_filter(res->port_id, res->queue_id,
3198                                              &fdir_filter);
3199         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
3200                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
3201         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
3202                 fdir_add_perfect_filter(res->port_id, res->soft_id,
3203                                         res->queue_id,
3204                                         (uint8_t) (res->queue_id < 0),
3205                                         &fdir_filter);
3206         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
3207                 fdir_update_perfect_filter(res->port_id, res->soft_id,
3208                                            res->queue_id,
3209                                            (uint8_t) (res->queue_id < 0),
3210                                            &fdir_filter);
3211         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
3212                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
3213                                            &fdir_filter);
3214
3215 }
3216
3217
3218 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
3219         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3220                               port_id, UINT8);
3221 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
3222         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3223                                  protocol, "ip#tcp#udp#sctp");
3224 cmdline_parse_token_string_t cmd_pkt_filter_src =
3225         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3226                                  src, "src");
3227 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
3228         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3229                                  ip_src);
3230 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
3231         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3232                               port_src, UINT16);
3233 cmdline_parse_token_string_t cmd_pkt_filter_dst =
3234         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3235                                  dst, "dst");
3236 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
3237         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3238                                  ip_dst);
3239 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
3240         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3241                               port_dst, UINT16);
3242 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
3243         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3244                                  flexbytes, "flexbytes");
3245 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
3246         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3247                               flexbytes_value, UINT16);
3248 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
3249         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3250                                  vlan, "vlan");
3251 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
3252         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3253                               vlan_id, UINT16);
3254 cmdline_parse_token_string_t cmd_pkt_filter_queue =
3255         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3256                                  queue, "queue");
3257 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
3258         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3259                               queue_id, INT8);
3260 cmdline_parse_token_string_t cmd_pkt_filter_soft =
3261         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3262                                  soft, "soft");
3263 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
3264         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3265                               soft_id, UINT16);
3266
3267
3268 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
3269         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3270                                  pkt_filter, "add_signature_filter");
3271 cmdline_parse_inst_t cmd_add_signature_filter = {
3272         .f = cmd_pkt_filter_parsed,
3273         .data = NULL,
3274         .help_str = "add a signature filter",
3275         .tokens = {
3276                 (void *)&cmd_pkt_filter_add_signature_filter,
3277                 (void *)&cmd_pkt_filter_port_id,
3278                 (void *)&cmd_pkt_filter_protocol,
3279                 (void *)&cmd_pkt_filter_src,
3280                 (void *)&cmd_pkt_filter_ip_src,
3281                 (void *)&cmd_pkt_filter_port_src,
3282                 (void *)&cmd_pkt_filter_dst,
3283                 (void *)&cmd_pkt_filter_ip_dst,
3284                 (void *)&cmd_pkt_filter_port_dst,
3285                 (void *)&cmd_pkt_filter_flexbytes,
3286                 (void *)&cmd_pkt_filter_flexbytes_value,
3287                 (void *)&cmd_pkt_filter_vlan,
3288                 (void *)&cmd_pkt_filter_vlan_id,
3289                 (void *)&cmd_pkt_filter_queue,
3290                 (void *)&cmd_pkt_filter_queue_id,
3291                 NULL,
3292         },
3293 };
3294
3295
3296 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
3297         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3298                                  pkt_filter, "upd_signature_filter");
3299 cmdline_parse_inst_t cmd_upd_signature_filter = {
3300         .f = cmd_pkt_filter_parsed,
3301         .data = NULL,
3302         .help_str = "update a signature filter",
3303         .tokens = {
3304                 (void *)&cmd_pkt_filter_upd_signature_filter,
3305                 (void *)&cmd_pkt_filter_port_id,
3306                 (void *)&cmd_pkt_filter_protocol,
3307                 (void *)&cmd_pkt_filter_src,
3308                 (void *)&cmd_pkt_filter_ip_src,
3309                 (void *)&cmd_pkt_filter_port_src,
3310                 (void *)&cmd_pkt_filter_dst,
3311                 (void *)&cmd_pkt_filter_ip_dst,
3312                 (void *)&cmd_pkt_filter_port_dst,
3313                 (void *)&cmd_pkt_filter_flexbytes,
3314                 (void *)&cmd_pkt_filter_flexbytes_value,
3315                 (void *)&cmd_pkt_filter_vlan,
3316                 (void *)&cmd_pkt_filter_vlan_id,
3317                 (void *)&cmd_pkt_filter_queue,
3318                 (void *)&cmd_pkt_filter_queue_id,
3319                 NULL,
3320         },
3321 };
3322
3323
3324 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
3325         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3326                                  pkt_filter, "rm_signature_filter");
3327 cmdline_parse_inst_t cmd_rm_signature_filter = {
3328         .f = cmd_pkt_filter_parsed,
3329         .data = NULL,
3330         .help_str = "remove a signature filter",
3331         .tokens = {
3332                 (void *)&cmd_pkt_filter_rm_signature_filter,
3333                 (void *)&cmd_pkt_filter_port_id,
3334                 (void *)&cmd_pkt_filter_protocol,
3335                 (void *)&cmd_pkt_filter_src,
3336                 (void *)&cmd_pkt_filter_ip_src,
3337                 (void *)&cmd_pkt_filter_port_src,
3338                 (void *)&cmd_pkt_filter_dst,
3339                 (void *)&cmd_pkt_filter_ip_dst,
3340                 (void *)&cmd_pkt_filter_port_dst,
3341                 (void *)&cmd_pkt_filter_flexbytes,
3342                 (void *)&cmd_pkt_filter_flexbytes_value,
3343                 (void *)&cmd_pkt_filter_vlan,
3344                 (void *)&cmd_pkt_filter_vlan_id,
3345                 NULL
3346                 },
3347 };
3348
3349
3350 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
3351         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3352                                  pkt_filter, "add_perfect_filter");
3353 cmdline_parse_inst_t cmd_add_perfect_filter = {
3354         .f = cmd_pkt_filter_parsed,
3355         .data = NULL,
3356         .help_str = "add a perfect filter",
3357         .tokens = {
3358                 (void *)&cmd_pkt_filter_add_perfect_filter,
3359                 (void *)&cmd_pkt_filter_port_id,
3360                 (void *)&cmd_pkt_filter_protocol,
3361                 (void *)&cmd_pkt_filter_src,
3362                 (void *)&cmd_pkt_filter_ip_src,
3363                 (void *)&cmd_pkt_filter_port_src,
3364                 (void *)&cmd_pkt_filter_dst,
3365                 (void *)&cmd_pkt_filter_ip_dst,
3366                 (void *)&cmd_pkt_filter_port_dst,
3367                 (void *)&cmd_pkt_filter_flexbytes,
3368                 (void *)&cmd_pkt_filter_flexbytes_value,
3369                 (void *)&cmd_pkt_filter_vlan,
3370                 (void *)&cmd_pkt_filter_vlan_id,
3371                 (void *)&cmd_pkt_filter_queue,
3372                 (void *)&cmd_pkt_filter_queue_id,
3373                 (void *)&cmd_pkt_filter_soft,
3374                 (void *)&cmd_pkt_filter_soft_id,
3375                 NULL,
3376         },
3377 };
3378
3379
3380 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
3381         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3382                                  pkt_filter, "upd_perfect_filter");
3383 cmdline_parse_inst_t cmd_upd_perfect_filter = {
3384         .f = cmd_pkt_filter_parsed,
3385         .data = NULL,
3386         .help_str = "update a perfect filter",
3387         .tokens = {
3388                 (void *)&cmd_pkt_filter_upd_perfect_filter,
3389                 (void *)&cmd_pkt_filter_port_id,
3390                 (void *)&cmd_pkt_filter_protocol,
3391                 (void *)&cmd_pkt_filter_src,
3392                 (void *)&cmd_pkt_filter_ip_src,
3393                 (void *)&cmd_pkt_filter_port_src,
3394                 (void *)&cmd_pkt_filter_dst,
3395                 (void *)&cmd_pkt_filter_ip_dst,
3396                 (void *)&cmd_pkt_filter_port_dst,
3397                 (void *)&cmd_pkt_filter_flexbytes,
3398                 (void *)&cmd_pkt_filter_flexbytes_value,
3399                 (void *)&cmd_pkt_filter_vlan,
3400                 (void *)&cmd_pkt_filter_vlan_id,
3401                 (void *)&cmd_pkt_filter_queue,
3402                 (void *)&cmd_pkt_filter_queue_id,
3403                 (void *)&cmd_pkt_filter_soft,
3404                 (void *)&cmd_pkt_filter_soft_id,
3405                 NULL,
3406         },
3407 };
3408
3409
3410 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
3411         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3412                                  pkt_filter, "rm_perfect_filter");
3413 cmdline_parse_inst_t cmd_rm_perfect_filter = {
3414         .f = cmd_pkt_filter_parsed,
3415         .data = NULL,
3416         .help_str = "remove a perfect filter",
3417         .tokens = {
3418                 (void *)&cmd_pkt_filter_rm_perfect_filter,
3419                 (void *)&cmd_pkt_filter_port_id,
3420                 (void *)&cmd_pkt_filter_protocol,
3421                 (void *)&cmd_pkt_filter_src,
3422                 (void *)&cmd_pkt_filter_ip_src,
3423                 (void *)&cmd_pkt_filter_port_src,
3424                 (void *)&cmd_pkt_filter_dst,
3425                 (void *)&cmd_pkt_filter_ip_dst,
3426                 (void *)&cmd_pkt_filter_port_dst,
3427                 (void *)&cmd_pkt_filter_flexbytes,
3428                 (void *)&cmd_pkt_filter_flexbytes_value,
3429                 (void *)&cmd_pkt_filter_vlan,
3430                 (void *)&cmd_pkt_filter_vlan_id,
3431                 (void *)&cmd_pkt_filter_soft,
3432                 (void *)&cmd_pkt_filter_soft_id,
3433                 NULL,
3434         },
3435 };
3436
3437 /* *** SETUP MASKS FILTER *** */
3438 struct cmd_pkt_filter_masks_result {
3439         cmdline_fixed_string_t filter_mask;
3440         uint8_t  port_id;
3441         cmdline_fixed_string_t src_mask;
3442         uint32_t ip_src_mask;
3443         uint16_t ipv6_src_mask;
3444         uint16_t port_src_mask;
3445         cmdline_fixed_string_t dst_mask;
3446         uint32_t ip_dst_mask;
3447         uint16_t ipv6_dst_mask;
3448         uint16_t port_dst_mask;
3449         cmdline_fixed_string_t flexbytes;
3450         uint8_t flexbytes_value;
3451         cmdline_fixed_string_t vlan_id;
3452         uint8_t  vlan_id_value;
3453         cmdline_fixed_string_t vlan_prio;
3454         uint8_t  vlan_prio_value;
3455         cmdline_fixed_string_t only_ip_flow;
3456         uint8_t  only_ip_flow_value;
3457         cmdline_fixed_string_t comp_ipv6_dst;
3458         uint8_t  comp_ipv6_dst_value;
3459 };
3460
3461 static void
3462 cmd_pkt_filter_masks_parsed(void *parsed_result,
3463                           __attribute__((unused)) struct cmdline *cl,
3464                           __attribute__((unused)) void *data)
3465 {
3466         struct rte_fdir_masks fdir_masks;
3467         struct cmd_pkt_filter_masks_result *res = parsed_result;
3468
3469         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3470
3471         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3472         fdir_masks.vlan_id       = res->vlan_id_value;
3473         fdir_masks.vlan_prio     = res->vlan_prio_value;
3474         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
3475         fdir_masks.src_ipv4_mask = res->ip_src_mask;
3476         fdir_masks.src_port_mask = res->port_src_mask;
3477         fdir_masks.dst_port_mask = res->port_dst_mask;
3478         fdir_masks.flexbytes     = res->flexbytes_value;
3479
3480         fdir_set_masks(res->port_id, &fdir_masks);
3481 }
3482
3483 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
3484         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3485                                  filter_mask, "set_masks_filter");
3486 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
3487         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3488                               port_id, UINT8);
3489 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
3490         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3491                                  only_ip_flow, "only_ip_flow");
3492 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
3493         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3494                               only_ip_flow_value, UINT8);
3495 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
3496         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3497                                  src_mask, "src_mask");
3498 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
3499         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3500                               ip_src_mask, UINT32);
3501 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
3502         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3503                               port_src_mask, UINT16);
3504 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
3505         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3506                                  dst_mask, "dst_mask");
3507 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
3508         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3509                               ip_dst_mask, UINT32);
3510 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
3511         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3512                               port_dst_mask, UINT16);
3513 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
3514         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3515                                  flexbytes, "flexbytes");
3516 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
3517         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3518                               flexbytes_value, UINT8);
3519 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
3520         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3521                                  vlan_id, "vlan_id");
3522 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
3523         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3524                               vlan_id_value, UINT8);
3525 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
3526         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3527                                  vlan_prio, "vlan_prio");
3528 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
3529         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3530                               vlan_prio_value, UINT8);
3531
3532 cmdline_parse_inst_t cmd_set_masks_filter = {
3533         .f = cmd_pkt_filter_masks_parsed,
3534         .data = NULL,
3535         .help_str = "setup masks filter",
3536         .tokens = {
3537                 (void *)&cmd_pkt_filter_masks_filter_mask,
3538                 (void *)&cmd_pkt_filter_masks_port_id,
3539                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3540                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3541                 (void *)&cmd_pkt_filter_masks_src_mask,
3542                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
3543                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3544                 (void *)&cmd_pkt_filter_masks_dst_mask,
3545                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
3546                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3547                 (void *)&cmd_pkt_filter_masks_flexbytes,
3548                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3549                 (void *)&cmd_pkt_filter_masks_vlan_id,
3550                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3551                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3552                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3553                 NULL,
3554         },
3555 };
3556
3557 static void
3558 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
3559                           __attribute__((unused)) struct cmdline *cl,
3560                           __attribute__((unused)) void *data)
3561 {
3562         struct rte_fdir_masks fdir_masks;
3563         struct cmd_pkt_filter_masks_result *res = parsed_result;
3564
3565         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
3566
3567         fdir_masks.set_ipv6_mask = 1;
3568         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
3569         fdir_masks.vlan_id       = res->vlan_id_value;
3570         fdir_masks.vlan_prio     = res->vlan_prio_value;
3571         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
3572         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
3573         fdir_masks.src_port_mask = res->port_src_mask;
3574         fdir_masks.dst_port_mask = res->port_dst_mask;
3575         fdir_masks.flexbytes     = res->flexbytes_value;
3576         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
3577
3578         fdir_set_masks(res->port_id, &fdir_masks);
3579 }
3580
3581 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
3582         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3583                                  filter_mask, "set_ipv6_masks_filter");
3584 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
3585         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3586                               ipv6_src_mask, UINT16);
3587 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
3588         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3589                               ipv6_dst_mask, UINT16);
3590
3591 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
3592         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
3593                                  comp_ipv6_dst, "compare_dst");
3594 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
3595         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
3596                               comp_ipv6_dst_value, UINT8);
3597
3598 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
3599         .f = cmd_pkt_filter_masks_ipv6_parsed,
3600         .data = NULL,
3601         .help_str = "setup ipv6 masks filter",
3602         .tokens = {
3603                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
3604                 (void *)&cmd_pkt_filter_masks_port_id,
3605                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
3606                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
3607                 (void *)&cmd_pkt_filter_masks_src_mask,
3608                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
3609                 (void *)&cmd_pkt_filter_masks_port_src_mask,
3610                 (void *)&cmd_pkt_filter_masks_dst_mask,
3611                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
3612                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
3613                 (void *)&cmd_pkt_filter_masks_flexbytes,
3614                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
3615                 (void *)&cmd_pkt_filter_masks_vlan_id,
3616                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
3617                 (void *)&cmd_pkt_filter_masks_vlan_prio,
3618                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
3619                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
3620                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
3621                 NULL,
3622         },
3623 };
3624
3625 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
3626 struct cmd_link_flow_ctrl_set_result {
3627         cmdline_fixed_string_t set;
3628         cmdline_fixed_string_t flow_ctrl;
3629         cmdline_fixed_string_t rx;
3630         cmdline_fixed_string_t rx_lfc_mode;
3631         cmdline_fixed_string_t tx;
3632         cmdline_fixed_string_t tx_lfc_mode;
3633         cmdline_fixed_string_t mac_ctrl_frame_fwd;
3634         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
3635         uint32_t high_water;
3636         uint32_t low_water;
3637         uint16_t pause_time;
3638         uint16_t send_xon;
3639         uint8_t  port_id;
3640 };
3641
3642 static void
3643 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
3644                        __attribute__((unused)) struct cmdline *cl,
3645                        __attribute__((unused)) void *data)
3646 {
3647         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
3648         struct rte_eth_fc_conf fc_conf;
3649         int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
3650         int ret;
3651
3652         /*
3653          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3654          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3655          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3656          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3657          */
3658         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
3659                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
3660         };
3661
3662         rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
3663         tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
3664         mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
3665
3666         fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
3667         fc_conf.high_water = res->high_water;
3668         fc_conf.low_water  = res->low_water;
3669         fc_conf.pause_time = res->pause_time;
3670         fc_conf.send_xon   = res->send_xon;
3671         fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
3672
3673         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
3674         if (ret != 0)
3675                 printf("bad flow contrl parameter, return code = %d \n", ret);
3676 }
3677
3678 cmdline_parse_token_string_t cmd_lfc_set_set =
3679         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3680                                 set, "set");
3681 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
3682         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3683                                 flow_ctrl, "flow_ctrl");
3684 cmdline_parse_token_string_t cmd_lfc_set_rx =
3685         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3686                                 rx, "rx");
3687 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
3688         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3689                                 rx_lfc_mode, "on#off");
3690 cmdline_parse_token_string_t cmd_lfc_set_tx =
3691         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3692                                 tx, "tx");
3693 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
3694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3695                                 tx_lfc_mode, "on#off");
3696 cmdline_parse_token_num_t cmd_lfc_set_high_water =
3697         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3698                                 high_water, UINT32);
3699 cmdline_parse_token_num_t cmd_lfc_set_low_water =
3700         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3701                                 low_water, UINT32);
3702 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
3703         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3704                                 pause_time, UINT16);
3705 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
3706         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3707                                 send_xon, UINT16);
3708 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
3709         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3710                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
3711 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
3712         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3713                                 mac_ctrl_frame_fwd_mode, "on#off");
3714 cmdline_parse_token_num_t cmd_lfc_set_portid =
3715         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
3716                                 port_id, UINT8);
3717
3718 cmdline_parse_inst_t cmd_link_flow_control_set = {
3719         .f = cmd_link_flow_ctrl_set_parsed,
3720         .data = NULL,
3721         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
3722 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
3723 port_id",
3724         .tokens = {
3725                 (void *)&cmd_lfc_set_set,
3726                 (void *)&cmd_lfc_set_flow_ctrl,
3727                 (void *)&cmd_lfc_set_rx,
3728                 (void *)&cmd_lfc_set_rx_mode,
3729                 (void *)&cmd_lfc_set_tx,
3730                 (void *)&cmd_lfc_set_tx_mode,
3731                 (void *)&cmd_lfc_set_high_water,
3732                 (void *)&cmd_lfc_set_low_water,
3733                 (void *)&cmd_lfc_set_pause_time,
3734                 (void *)&cmd_lfc_set_send_xon,
3735                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
3736                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
3737                 (void *)&cmd_lfc_set_portid,
3738                 NULL,
3739         },
3740 };
3741
3742 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
3743 struct cmd_priority_flow_ctrl_set_result {
3744         cmdline_fixed_string_t set;
3745         cmdline_fixed_string_t pfc_ctrl;
3746         cmdline_fixed_string_t rx;
3747         cmdline_fixed_string_t rx_pfc_mode;
3748         cmdline_fixed_string_t tx;
3749         cmdline_fixed_string_t tx_pfc_mode;
3750         uint32_t high_water;
3751         uint32_t low_water;
3752         uint16_t pause_time;
3753         uint8_t  priority;
3754         uint8_t  port_id;
3755 };
3756
3757 static void
3758 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
3759                        __attribute__((unused)) struct cmdline *cl,
3760                        __attribute__((unused)) void *data)
3761 {
3762         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
3763         struct rte_eth_pfc_conf pfc_conf;
3764         int rx_fc_enable, tx_fc_enable;
3765         int ret;
3766
3767         /*
3768          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
3769          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
3770          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
3771          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
3772          */
3773         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
3774                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
3775         };
3776
3777         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
3778         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
3779         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
3780         pfc_conf.fc.high_water = res->high_water;
3781         pfc_conf.fc.low_water  = res->low_water;
3782         pfc_conf.fc.pause_time = res->pause_time;
3783         pfc_conf.priority      = res->priority;
3784
3785         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
3786         if (ret != 0)
3787                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
3788 }
3789
3790 cmdline_parse_token_string_t cmd_pfc_set_set =
3791         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3792                                 set, "set");
3793 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
3794         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3795                                 pfc_ctrl, "pfc_ctrl");
3796 cmdline_parse_token_string_t cmd_pfc_set_rx =
3797         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3798                                 rx, "rx");
3799 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
3800         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3801                                 rx_pfc_mode, "on#off");
3802 cmdline_parse_token_string_t cmd_pfc_set_tx =
3803         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3804                                 tx, "tx");
3805 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
3806         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3807                                 tx_pfc_mode, "on#off");
3808 cmdline_parse_token_num_t cmd_pfc_set_high_water =
3809         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3810                                 high_water, UINT32);
3811 cmdline_parse_token_num_t cmd_pfc_set_low_water =
3812         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3813                                 low_water, UINT32);
3814 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
3815         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3816                                 pause_time, UINT16);
3817 cmdline_parse_token_num_t cmd_pfc_set_priority =
3818         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3819                                 priority, UINT8);
3820 cmdline_parse_token_num_t cmd_pfc_set_portid =
3821         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
3822                                 port_id, UINT8);
3823
3824 cmdline_parse_inst_t cmd_priority_flow_control_set = {
3825         .f = cmd_priority_flow_ctrl_set_parsed,
3826         .data = NULL,
3827         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
3828                         tx on|off high_water low_water pause_time priority port_id",
3829         .tokens = {
3830                 (void *)&cmd_pfc_set_set,
3831                 (void *)&cmd_pfc_set_flow_ctrl,
3832                 (void *)&cmd_pfc_set_rx,
3833                 (void *)&cmd_pfc_set_rx_mode,
3834                 (void *)&cmd_pfc_set_tx,
3835                 (void *)&cmd_pfc_set_tx_mode,
3836                 (void *)&cmd_pfc_set_high_water,
3837                 (void *)&cmd_pfc_set_low_water,
3838                 (void *)&cmd_pfc_set_pause_time,
3839                 (void *)&cmd_pfc_set_priority,
3840                 (void *)&cmd_pfc_set_portid,
3841                 NULL,
3842         },
3843 };
3844
3845 /* *** RESET CONFIGURATION *** */
3846 struct cmd_reset_result {
3847         cmdline_fixed_string_t reset;
3848         cmdline_fixed_string_t def;
3849 };
3850
3851 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
3852                              struct cmdline *cl,
3853                              __attribute__((unused)) void *data)
3854 {
3855         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
3856         set_def_fwd_config();
3857 }
3858
3859 cmdline_parse_token_string_t cmd_reset_set =
3860         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
3861 cmdline_parse_token_string_t cmd_reset_def =
3862         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
3863                                  "default");
3864
3865 cmdline_parse_inst_t cmd_reset = {
3866         .f = cmd_reset_parsed,
3867         .data = NULL,
3868         .help_str = "set default: reset default forwarding configuration",
3869         .tokens = {
3870                 (void *)&cmd_reset_set,
3871                 (void *)&cmd_reset_def,
3872                 NULL,
3873         },
3874 };
3875
3876 /* *** START FORWARDING *** */
3877 struct cmd_start_result {
3878         cmdline_fixed_string_t start;
3879 };
3880
3881 cmdline_parse_token_string_t cmd_start_start =
3882         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
3883
3884 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
3885                              __attribute__((unused)) struct cmdline *cl,
3886                              __attribute__((unused)) void *data)
3887 {
3888         start_packet_forwarding(0);
3889 }
3890
3891 cmdline_parse_inst_t cmd_start = {
3892         .f = cmd_start_parsed,
3893         .data = NULL,
3894         .help_str = "start packet forwarding",
3895         .tokens = {
3896                 (void *)&cmd_start_start,
3897                 NULL,
3898         },
3899 };
3900
3901 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
3902 struct cmd_start_tx_first_result {
3903         cmdline_fixed_string_t start;
3904         cmdline_fixed_string_t tx_first;
3905 };
3906
3907 static void
3908 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
3909                           __attribute__((unused)) struct cmdline *cl,
3910                           __attribute__((unused)) void *data)
3911 {
3912         start_packet_forwarding(1);
3913 }
3914
3915 cmdline_parse_token_string_t cmd_start_tx_first_start =
3916         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
3917                                  "start");
3918 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
3919         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
3920                                  tx_first, "tx_first");
3921
3922 cmdline_parse_inst_t cmd_start_tx_first = {
3923         .f = cmd_start_tx_first_parsed,
3924         .data = NULL,
3925         .help_str = "start packet forwarding, after sending 1 burst of packets",
3926         .tokens = {
3927                 (void *)&cmd_start_tx_first_start,
3928                 (void *)&cmd_start_tx_first_tx_first,
3929                 NULL,
3930         },
3931 };
3932
3933 /* *** SET LINK UP *** */
3934 struct cmd_set_link_up_result {
3935         cmdline_fixed_string_t set;
3936         cmdline_fixed_string_t link_up;
3937         cmdline_fixed_string_t port;
3938         uint8_t port_id;
3939 };
3940
3941 cmdline_parse_token_string_t cmd_set_link_up_set =
3942         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
3943 cmdline_parse_token_string_t cmd_set_link_up_link_up =
3944         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
3945                                 "link-up");
3946 cmdline_parse_token_string_t cmd_set_link_up_port =
3947         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
3948 cmdline_parse_token_num_t cmd_set_link_up_port_id =
3949         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
3950
3951 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
3952                              __attribute__((unused)) struct cmdline *cl,
3953                              __attribute__((unused)) void *data)
3954 {
3955         struct cmd_set_link_up_result *res = parsed_result;
3956         dev_set_link_up(res->port_id);
3957 }
3958
3959 cmdline_parse_inst_t cmd_set_link_up = {
3960         .f = cmd_set_link_up_parsed,
3961         .data = NULL,
3962         .help_str = "set link-up port (port id)",
3963         .tokens = {
3964                 (void *)&cmd_set_link_up_set,
3965                 (void *)&cmd_set_link_up_link_up,
3966                 (void *)&cmd_set_link_up_port,
3967                 (void *)&cmd_set_link_up_port_id,
3968                 NULL,
3969         },
3970 };
3971
3972 /* *** SET LINK DOWN *** */
3973 struct cmd_set_link_down_result {
3974         cmdline_fixed_string_t set;
3975         cmdline_fixed_string_t link_down;
3976         cmdline_fixed_string_t port;
3977         uint8_t port_id;
3978 };
3979
3980 cmdline_parse_token_string_t cmd_set_link_down_set =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
3982 cmdline_parse_token_string_t cmd_set_link_down_link_down =
3983         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
3984                                 "link-down");
3985 cmdline_parse_token_string_t cmd_set_link_down_port =
3986         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
3987 cmdline_parse_token_num_t cmd_set_link_down_port_id =
3988         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
3989
3990 static void cmd_set_link_down_parsed(
3991                                 __attribute__((unused)) void *parsed_result,
3992                                 __attribute__((unused)) struct cmdline *cl,
3993                                 __attribute__((unused)) void *data)
3994 {
3995         struct cmd_set_link_down_result *res = parsed_result;
3996         dev_set_link_down(res->port_id);
3997 }
3998
3999 cmdline_parse_inst_t cmd_set_link_down = {
4000         .f = cmd_set_link_down_parsed,
4001         .data = NULL,
4002         .help_str = "set link-down port (port id)",
4003         .tokens = {
4004                 (void *)&cmd_set_link_down_set,
4005                 (void *)&cmd_set_link_down_link_down,
4006                 (void *)&cmd_set_link_down_port,
4007                 (void *)&cmd_set_link_down_port_id,
4008                 NULL,
4009         },
4010 };
4011
4012 /* *** SHOW CFG *** */
4013 struct cmd_showcfg_result {
4014         cmdline_fixed_string_t show;
4015         cmdline_fixed_string_t cfg;
4016         cmdline_fixed_string_t what;
4017 };
4018
4019 static void cmd_showcfg_parsed(void *parsed_result,
4020                                __attribute__((unused)) struct cmdline *cl,
4021                                __attribute__((unused)) void *data)
4022 {
4023         struct cmd_showcfg_result *res = parsed_result;
4024         if (!strcmp(res->what, "rxtx"))
4025                 rxtx_config_display();
4026         else if (!strcmp(res->what, "cores"))
4027                 fwd_lcores_config_display();
4028         else if (!strcmp(res->what, "fwd"))
4029                 fwd_config_display();
4030 }
4031
4032 cmdline_parse_token_string_t cmd_showcfg_show =
4033         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
4034 cmdline_parse_token_string_t cmd_showcfg_port =
4035         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
4036 cmdline_parse_token_string_t cmd_showcfg_what =
4037         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
4038                                  "rxtx#cores#fwd");
4039
4040 cmdline_parse_inst_t cmd_showcfg = {
4041         .f = cmd_showcfg_parsed,
4042         .data = NULL,
4043         .help_str = "show config rxtx|cores|fwd",
4044         .tokens = {
4045                 (void *)&cmd_showcfg_show,
4046                 (void *)&cmd_showcfg_port,
4047                 (void *)&cmd_showcfg_what,
4048                 NULL,
4049         },
4050 };
4051
4052 /* *** SHOW ALL PORT INFO *** */
4053 struct cmd_showportall_result {
4054         cmdline_fixed_string_t show;
4055         cmdline_fixed_string_t port;
4056         cmdline_fixed_string_t what;
4057         cmdline_fixed_string_t all;
4058 };
4059
4060 static void cmd_showportall_parsed(void *parsed_result,
4061                                 __attribute__((unused)) struct cmdline *cl,
4062                                 __attribute__((unused)) void *data)
4063 {
4064         portid_t i;
4065
4066         struct cmd_showportall_result *res = parsed_result;
4067         if (!strcmp(res->show, "clear")) {
4068                 if (!strcmp(res->what, "stats"))
4069                         for (i = 0; i < nb_ports; i++)
4070                                 nic_stats_clear(i);
4071         } else if (!strcmp(res->what, "info"))
4072                 for (i = 0; i < nb_ports; i++)
4073                         port_infos_display(i);
4074         else if (!strcmp(res->what, "stats"))
4075                 for (i = 0; i < nb_ports; i++)
4076                         nic_stats_display(i);
4077         else if (!strcmp(res->what, "fdir"))
4078                 for (i = 0; i < nb_ports; i++)
4079                         fdir_get_infos(i);
4080         else if (!strcmp(res->what, "stat_qmap"))
4081                 for (i = 0; i < nb_ports; i++)
4082                         nic_stats_mapping_display(i);
4083 }
4084
4085 cmdline_parse_token_string_t cmd_showportall_show =
4086         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
4087                                  "show#clear");
4088 cmdline_parse_token_string_t cmd_showportall_port =
4089         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
4090 cmdline_parse_token_string_t cmd_showportall_what =
4091         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
4092                                  "info#stats#fdir#stat_qmap");
4093 cmdline_parse_token_string_t cmd_showportall_all =
4094         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
4095 cmdline_parse_inst_t cmd_showportall = {
4096         .f = cmd_showportall_parsed,
4097         .data = NULL,
4098         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
4099         .tokens = {
4100                 (void *)&cmd_showportall_show,
4101                 (void *)&cmd_showportall_port,
4102                 (void *)&cmd_showportall_what,
4103                 (void *)&cmd_showportall_all,
4104                 NULL,
4105         },
4106 };
4107
4108 /* *** SHOW PORT INFO *** */
4109 struct cmd_showport_result {
4110         cmdline_fixed_string_t show;
4111         cmdline_fixed_string_t port;
4112         cmdline_fixed_string_t what;
4113         uint8_t portnum;
4114 };
4115
4116 static void cmd_showport_parsed(void *parsed_result,
4117                                 __attribute__((unused)) struct cmdline *cl,
4118                                 __attribute__((unused)) void *data)
4119 {
4120         struct cmd_showport_result *res = parsed_result;
4121         if (!strcmp(res->show, "clear")) {
4122                 if (!strcmp(res->what, "stats"))
4123                         nic_stats_clear(res->portnum);
4124         } else if (!strcmp(res->what, "info"))
4125                 port_infos_display(res->portnum);
4126         else if (!strcmp(res->what, "stats"))
4127                 nic_stats_display(res->portnum);
4128         else if (!strcmp(res->what, "fdir"))
4129                  fdir_get_infos(res->portnum);
4130         else if (!strcmp(res->what, "stat_qmap"))
4131                 nic_stats_mapping_display(res->portnum);
4132 }
4133
4134 cmdline_parse_token_string_t cmd_showport_show =
4135         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
4136                                  "show#clear");
4137 cmdline_parse_token_string_t cmd_showport_port =
4138         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
4139 cmdline_parse_token_string_t cmd_showport_what =
4140         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
4141                                  "info#stats#fdir#stat_qmap");
4142 cmdline_parse_token_num_t cmd_showport_portnum =
4143         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
4144
4145 cmdline_parse_inst_t cmd_showport = {
4146         .f = cmd_showport_parsed,
4147         .data = NULL,
4148         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
4149         .tokens = {
4150                 (void *)&cmd_showport_show,
4151                 (void *)&cmd_showport_port,
4152                 (void *)&cmd_showport_what,
4153                 (void *)&cmd_showport_portnum,
4154                 NULL,
4155         },
4156 };
4157
4158 /* *** READ PORT REGISTER *** */
4159 struct cmd_read_reg_result {
4160         cmdline_fixed_string_t read;
4161         cmdline_fixed_string_t reg;
4162         uint8_t port_id;
4163         uint32_t reg_off;
4164 };
4165
4166 static void
4167 cmd_read_reg_parsed(void *parsed_result,
4168                     __attribute__((unused)) struct cmdline *cl,
4169                     __attribute__((unused)) void *data)
4170 {
4171         struct cmd_read_reg_result *res = parsed_result;
4172         port_reg_display(res->port_id, res->reg_off);
4173 }
4174
4175 cmdline_parse_token_string_t cmd_read_reg_read =
4176         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
4177 cmdline_parse_token_string_t cmd_read_reg_reg =
4178         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
4179 cmdline_parse_token_num_t cmd_read_reg_port_id =
4180         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
4181 cmdline_parse_token_num_t cmd_read_reg_reg_off =
4182         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
4183
4184 cmdline_parse_inst_t cmd_read_reg = {
4185         .f = cmd_read_reg_parsed,
4186         .data = NULL,
4187         .help_str = "read reg port_id reg_off",
4188         .tokens = {
4189                 (void *)&cmd_read_reg_read,
4190                 (void *)&cmd_read_reg_reg,
4191                 (void *)&cmd_read_reg_port_id,
4192                 (void *)&cmd_read_reg_reg_off,
4193                 NULL,
4194         },
4195 };
4196
4197 /* *** READ PORT REGISTER BIT FIELD *** */
4198 struct cmd_read_reg_bit_field_result {
4199         cmdline_fixed_string_t read;
4200         cmdline_fixed_string_t regfield;
4201         uint8_t port_id;
4202         uint32_t reg_off;
4203         uint8_t bit1_pos;
4204         uint8_t bit2_pos;
4205 };
4206
4207 static void
4208 cmd_read_reg_bit_field_parsed(void *parsed_result,
4209                               __attribute__((unused)) struct cmdline *cl,
4210                               __attribute__((unused)) void *data)
4211 {
4212         struct cmd_read_reg_bit_field_result *res = parsed_result;
4213         port_reg_bit_field_display(res->port_id, res->reg_off,
4214                                    res->bit1_pos, res->bit2_pos);
4215 }
4216
4217 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
4218         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
4219                                  "read");
4220 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
4221         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
4222                                  regfield, "regfield");
4223 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
4224         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
4225                               UINT8);
4226 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
4227         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
4228                               UINT32);
4229 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
4230         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
4231                               UINT8);
4232 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
4233         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
4234                               UINT8);
4235
4236 cmdline_parse_inst_t cmd_read_reg_bit_field = {
4237         .f = cmd_read_reg_bit_field_parsed,
4238         .data = NULL,
4239         .help_str = "read regfield port_id reg_off bit_x bit_y "
4240         "(read register bit field between bit_x and bit_y included)",
4241         .tokens = {
4242                 (void *)&cmd_read_reg_bit_field_read,
4243                 (void *)&cmd_read_reg_bit_field_regfield,
4244                 (void *)&cmd_read_reg_bit_field_port_id,
4245                 (void *)&cmd_read_reg_bit_field_reg_off,
4246                 (void *)&cmd_read_reg_bit_field_bit1_pos,
4247                 (void *)&cmd_read_reg_bit_field_bit2_pos,
4248                 NULL,
4249         },
4250 };
4251
4252 /* *** READ PORT REGISTER BIT *** */
4253 struct cmd_read_reg_bit_result {
4254         cmdline_fixed_string_t read;
4255         cmdline_fixed_string_t regbit;
4256         uint8_t port_id;
4257         uint32_t reg_off;
4258         uint8_t bit_pos;
4259 };
4260
4261 static void
4262 cmd_read_reg_bit_parsed(void *parsed_result,
4263                         __attribute__((unused)) struct cmdline *cl,
4264                         __attribute__((unused)) void *data)
4265 {
4266         struct cmd_read_reg_bit_result *res = parsed_result;
4267         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
4268 }
4269
4270 cmdline_parse_token_string_t cmd_read_reg_bit_read =
4271         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
4272 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
4273         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
4274                                  regbit, "regbit");
4275 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
4276         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
4277 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
4278         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
4279 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
4280         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
4281
4282 cmdline_parse_inst_t cmd_read_reg_bit = {
4283         .f = cmd_read_reg_bit_parsed,
4284         .data = NULL,
4285         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
4286         .tokens = {
4287                 (void *)&cmd_read_reg_bit_read,
4288                 (void *)&cmd_read_reg_bit_regbit,
4289                 (void *)&cmd_read_reg_bit_port_id,
4290                 (void *)&cmd_read_reg_bit_reg_off,
4291                 (void *)&cmd_read_reg_bit_bit_pos,
4292                 NULL,
4293         },
4294 };
4295
4296 /* *** WRITE PORT REGISTER *** */
4297 struct cmd_write_reg_result {
4298         cmdline_fixed_string_t write;
4299         cmdline_fixed_string_t reg;
4300         uint8_t port_id;
4301         uint32_t reg_off;
4302         uint32_t value;
4303 };
4304
4305 static void
4306 cmd_write_reg_parsed(void *parsed_result,
4307                      __attribute__((unused)) struct cmdline *cl,
4308                      __attribute__((unused)) void *data)
4309 {
4310         struct cmd_write_reg_result *res = parsed_result;
4311         port_reg_set(res->port_id, res->reg_off, res->value);
4312 }
4313
4314 cmdline_parse_token_string_t cmd_write_reg_write =
4315         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
4316 cmdline_parse_token_string_t cmd_write_reg_reg =
4317         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
4318 cmdline_parse_token_num_t cmd_write_reg_port_id =
4319         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
4320 cmdline_parse_token_num_t cmd_write_reg_reg_off =
4321         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
4322 cmdline_parse_token_num_t cmd_write_reg_value =
4323         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
4324
4325 cmdline_parse_inst_t cmd_write_reg = {
4326         .f = cmd_write_reg_parsed,
4327         .data = NULL,
4328         .help_str = "write reg port_id reg_off reg_value",
4329         .tokens = {
4330                 (void *)&cmd_write_reg_write,
4331                 (void *)&cmd_write_reg_reg,
4332                 (void *)&cmd_write_reg_port_id,
4333                 (void *)&cmd_write_reg_reg_off,
4334                 (void *)&cmd_write_reg_value,
4335                 NULL,
4336         },
4337 };
4338
4339 /* *** WRITE PORT REGISTER BIT FIELD *** */
4340 struct cmd_write_reg_bit_field_result {
4341         cmdline_fixed_string_t write;
4342         cmdline_fixed_string_t regfield;
4343         uint8_t port_id;
4344         uint32_t reg_off;
4345         uint8_t bit1_pos;
4346         uint8_t bit2_pos;
4347         uint32_t value;
4348 };
4349
4350 static void
4351 cmd_write_reg_bit_field_parsed(void *parsed_result,
4352                                __attribute__((unused)) struct cmdline *cl,
4353                                __attribute__((unused)) void *data)
4354 {
4355         struct cmd_write_reg_bit_field_result *res = parsed_result;
4356         port_reg_bit_field_set(res->port_id, res->reg_off,
4357                           res->bit1_pos, res->bit2_pos, res->value);
4358 }
4359
4360 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
4361         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
4362                                  "write");
4363 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
4364         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
4365                                  regfield, "regfield");
4366 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
4367         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
4368                               UINT8);
4369 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
4370         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
4371                               UINT32);
4372 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
4373         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
4374                               UINT8);
4375 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
4376         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
4377                               UINT8);
4378 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
4379         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
4380                               UINT32);
4381
4382 cmdline_parse_inst_t cmd_write_reg_bit_field = {
4383         .f = cmd_write_reg_bit_field_parsed,
4384         .data = NULL,
4385         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
4386         "(set register bit field between bit_x and bit_y included)",
4387         .tokens = {
4388                 (void *)&cmd_write_reg_bit_field_write,
4389                 (void *)&cmd_write_reg_bit_field_regfield,
4390                 (void *)&cmd_write_reg_bit_field_port_id,
4391                 (void *)&cmd_write_reg_bit_field_reg_off,
4392                 (void *)&cmd_write_reg_bit_field_bit1_pos,
4393                 (void *)&cmd_write_reg_bit_field_bit2_pos,
4394                 (void *)&cmd_write_reg_bit_field_value,
4395                 NULL,
4396         },
4397 };
4398
4399 /* *** WRITE PORT REGISTER BIT *** */
4400 struct cmd_write_reg_bit_result {
4401         cmdline_fixed_string_t write;
4402         cmdline_fixed_string_t regbit;
4403         uint8_t port_id;
4404         uint32_t reg_off;
4405         uint8_t bit_pos;
4406         uint8_t value;
4407 };
4408
4409 static void
4410 cmd_write_reg_bit_parsed(void *parsed_result,
4411                          __attribute__((unused)) struct cmdline *cl,
4412                          __attribute__((unused)) void *data)
4413 {
4414         struct cmd_write_reg_bit_result *res = parsed_result;
4415         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
4416 }
4417
4418 cmdline_parse_token_string_t cmd_write_reg_bit_write =
4419         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
4420                                  "write");
4421 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
4422         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
4423                                  regbit, "regbit");
4424 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
4425         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
4426 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
4427         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
4428 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
4429         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
4430 cmdline_parse_token_num_t cmd_write_reg_bit_value =
4431         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
4432
4433 cmdline_parse_inst_t cmd_write_reg_bit = {
4434         .f = cmd_write_reg_bit_parsed,
4435         .data = NULL,
4436         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
4437         .tokens = {
4438                 (void *)&cmd_write_reg_bit_write,
4439                 (void *)&cmd_write_reg_bit_regbit,
4440                 (void *)&cmd_write_reg_bit_port_id,
4441                 (void *)&cmd_write_reg_bit_reg_off,
4442                 (void *)&cmd_write_reg_bit_bit_pos,
4443                 (void *)&cmd_write_reg_bit_value,
4444                 NULL,
4445         },
4446 };
4447
4448 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
4449 struct cmd_read_rxd_txd_result {
4450         cmdline_fixed_string_t read;
4451         cmdline_fixed_string_t rxd_txd;
4452         uint8_t port_id;
4453         uint16_t queue_id;
4454         uint16_t desc_id;
4455 };
4456
4457 static void
4458 cmd_read_rxd_txd_parsed(void *parsed_result,
4459                         __attribute__((unused)) struct cmdline *cl,
4460                         __attribute__((unused)) void *data)
4461 {
4462         struct cmd_read_rxd_txd_result *res = parsed_result;
4463
4464         if (!strcmp(res->rxd_txd, "rxd"))
4465                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4466         else if (!strcmp(res->rxd_txd, "txd"))
4467                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
4468 }
4469
4470 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
4471         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
4472 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
4473         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
4474                                  "rxd#txd");
4475 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
4476         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
4477 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
4478         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
4479 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
4480         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
4481
4482 cmdline_parse_inst_t cmd_read_rxd_txd = {
4483         .f = cmd_read_rxd_txd_parsed,
4484         .data = NULL,
4485         .help_str = "read rxd|txd port_id queue_id rxd_id",
4486         .tokens = {
4487                 (void *)&cmd_read_rxd_txd_read,
4488                 (void *)&cmd_read_rxd_txd_rxd_txd,
4489                 (void *)&cmd_read_rxd_txd_port_id,
4490                 (void *)&cmd_read_rxd_txd_queue_id,
4491                 (void *)&cmd_read_rxd_txd_desc_id,
4492                 NULL,
4493         },
4494 };
4495
4496 /* *** QUIT *** */
4497 struct cmd_quit_result {
4498         cmdline_fixed_string_t quit;
4499 };
4500
4501 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
4502                             struct cmdline *cl,
4503                             __attribute__((unused)) void *data)
4504 {
4505         pmd_test_exit();
4506         cmdline_quit(cl);
4507 }
4508
4509 cmdline_parse_token_string_t cmd_quit_quit =
4510         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
4511
4512 cmdline_parse_inst_t cmd_quit = {
4513         .f = cmd_quit_parsed,
4514         .data = NULL,
4515         .help_str = "exit application",
4516         .tokens = {
4517                 (void *)&cmd_quit_quit,
4518                 NULL,
4519         },
4520 };
4521
4522 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
4523 struct cmd_mac_addr_result {
4524         cmdline_fixed_string_t mac_addr_cmd;
4525         cmdline_fixed_string_t what;
4526         uint8_t port_num;
4527         struct ether_addr address;
4528 };
4529
4530 static void cmd_mac_addr_parsed(void *parsed_result,
4531                 __attribute__((unused)) struct cmdline *cl,
4532                 __attribute__((unused)) void *data)
4533 {
4534         struct cmd_mac_addr_result *res = parsed_result;
4535         int ret;
4536
4537         if (strcmp(res->what, "add") == 0)
4538                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
4539         else
4540                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
4541
4542         /* check the return value and print it if is < 0 */
4543         if(ret < 0)
4544                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
4545
4546 }
4547
4548 cmdline_parse_token_string_t cmd_mac_addr_cmd =
4549         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
4550                                 "mac_addr");
4551 cmdline_parse_token_string_t cmd_mac_addr_what =
4552         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
4553                                 "add#remove");
4554 cmdline_parse_token_num_t cmd_mac_addr_portnum =
4555                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
4556 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
4557                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
4558
4559 cmdline_parse_inst_t cmd_mac_addr = {
4560         .f = cmd_mac_addr_parsed,
4561         .data = (void *)0,
4562         .help_str = "mac_addr add|remove X <address>: "
4563                         "add/remove MAC address on port X",
4564         .tokens = {
4565                 (void *)&cmd_mac_addr_cmd,
4566                 (void *)&cmd_mac_addr_what,
4567                 (void *)&cmd_mac_addr_portnum,
4568                 (void *)&cmd_mac_addr_addr,
4569                 NULL,
4570         },
4571 };
4572
4573
4574 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
4575 struct cmd_set_qmap_result {
4576         cmdline_fixed_string_t set;
4577         cmdline_fixed_string_t qmap;
4578         cmdline_fixed_string_t what;
4579         uint8_t port_id;
4580         uint16_t queue_id;
4581         uint8_t map_value;
4582 };
4583
4584 static void
4585 cmd_set_qmap_parsed(void *parsed_result,
4586                        __attribute__((unused)) struct cmdline *cl,
4587                        __attribute__((unused)) void *data)
4588 {
4589         struct cmd_set_qmap_result *res = parsed_result;
4590         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
4591
4592         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
4593 }
4594
4595 cmdline_parse_token_string_t cmd_setqmap_set =
4596         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4597                                  set, "set");
4598 cmdline_parse_token_string_t cmd_setqmap_qmap =
4599         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4600                                  qmap, "stat_qmap");
4601 cmdline_parse_token_string_t cmd_setqmap_what =
4602         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
4603                                  what, "tx#rx");
4604 cmdline_parse_token_num_t cmd_setqmap_portid =
4605         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4606                               port_id, UINT8);
4607 cmdline_parse_token_num_t cmd_setqmap_queueid =
4608         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4609                               queue_id, UINT16);
4610 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
4611         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
4612                               map_value, UINT8);
4613
4614 cmdline_parse_inst_t cmd_set_qmap = {
4615         .f = cmd_set_qmap_parsed,
4616         .data = NULL,
4617         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
4618         .tokens = {
4619                 (void *)&cmd_setqmap_set,
4620                 (void *)&cmd_setqmap_qmap,
4621                 (void *)&cmd_setqmap_what,
4622                 (void *)&cmd_setqmap_portid,
4623                 (void *)&cmd_setqmap_queueid,
4624                 (void *)&cmd_setqmap_mapvalue,
4625                 NULL,
4626         },
4627 };
4628
4629 /* *** CONFIGURE UNICAST HASH TABLE *** */
4630 struct cmd_set_uc_hash_table {
4631         cmdline_fixed_string_t set;
4632         cmdline_fixed_string_t port;
4633         uint8_t port_id;
4634         cmdline_fixed_string_t what;
4635         struct ether_addr address;
4636         cmdline_fixed_string_t mode;
4637 };
4638
4639 static void
4640 cmd_set_uc_hash_parsed(void *parsed_result,
4641                        __attribute__((unused)) struct cmdline *cl,
4642                        __attribute__((unused)) void *data)
4643 {
4644         int ret=0;
4645         struct cmd_set_uc_hash_table *res = parsed_result;
4646
4647         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4648
4649         if (strcmp(res->what, "uta") == 0)
4650                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
4651                                                 &res->address,(uint8_t)is_on);
4652         if (ret < 0)
4653                 printf("bad unicast hash table parameter, return code = %d \n", ret);
4654
4655 }
4656
4657 cmdline_parse_token_string_t cmd_set_uc_hash_set =
4658         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4659                                  set, "set");
4660 cmdline_parse_token_string_t cmd_set_uc_hash_port =
4661         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4662                                  port, "port");
4663 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
4664         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
4665                               port_id, UINT8);
4666 cmdline_parse_token_string_t cmd_set_uc_hash_what =
4667         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4668                                  what, "uta");
4669 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
4670         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
4671                                 address);
4672 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
4673         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
4674                                  mode, "on#off");
4675
4676 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
4677         .f = cmd_set_uc_hash_parsed,
4678         .data = NULL,
4679         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
4680         .tokens = {
4681                 (void *)&cmd_set_uc_hash_set,
4682                 (void *)&cmd_set_uc_hash_port,
4683                 (void *)&cmd_set_uc_hash_portid,
4684                 (void *)&cmd_set_uc_hash_what,
4685                 (void *)&cmd_set_uc_hash_mac,
4686                 (void *)&cmd_set_uc_hash_mode,
4687                 NULL,
4688         },
4689 };
4690
4691 struct cmd_set_uc_all_hash_table {
4692         cmdline_fixed_string_t set;
4693         cmdline_fixed_string_t port;
4694         uint8_t port_id;
4695         cmdline_fixed_string_t what;
4696         cmdline_fixed_string_t value;
4697         cmdline_fixed_string_t mode;
4698 };
4699
4700 static void
4701 cmd_set_uc_all_hash_parsed(void *parsed_result,
4702                        __attribute__((unused)) struct cmdline *cl,
4703                        __attribute__((unused)) void *data)
4704 {
4705         int ret=0;
4706         struct cmd_set_uc_all_hash_table *res = parsed_result;
4707
4708         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4709
4710         if ((strcmp(res->what, "uta") == 0) &&
4711                 (strcmp(res->value, "all") == 0))
4712                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
4713         if (ret < 0)
4714                 printf("bad unicast hash table parameter,"
4715                         "return code = %d \n", ret);
4716 }
4717
4718 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
4719         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4720                                  set, "set");
4721 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
4722         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4723                                  port, "port");
4724 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
4725         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
4726                               port_id, UINT8);
4727 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
4728         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4729                                  what, "uta");
4730 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
4731         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4732                                 value,"all");
4733 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
4734         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
4735                                  mode, "on#off");
4736
4737 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
4738         .f = cmd_set_uc_all_hash_parsed,
4739         .data = NULL,
4740         .help_str = "set port X uta all on|off (X = port number)",
4741         .tokens = {
4742                 (void *)&cmd_set_uc_all_hash_set,
4743                 (void *)&cmd_set_uc_all_hash_port,
4744                 (void *)&cmd_set_uc_all_hash_portid,
4745                 (void *)&cmd_set_uc_all_hash_what,
4746                 (void *)&cmd_set_uc_all_hash_value,
4747                 (void *)&cmd_set_uc_all_hash_mode,
4748                 NULL,
4749         },
4750 };
4751
4752 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
4753 struct cmd_set_vf_traffic {
4754         cmdline_fixed_string_t set;
4755         cmdline_fixed_string_t port;
4756         uint8_t port_id;
4757         cmdline_fixed_string_t vf;
4758         uint8_t vf_id;
4759         cmdline_fixed_string_t what;
4760         cmdline_fixed_string_t mode;
4761 };
4762
4763 static void
4764 cmd_set_vf_traffic_parsed(void *parsed_result,
4765                        __attribute__((unused)) struct cmdline *cl,
4766                        __attribute__((unused)) void *data)
4767 {
4768         struct cmd_set_vf_traffic *res = parsed_result;
4769         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
4770         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
4771
4772         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
4773 }
4774
4775 cmdline_parse_token_string_t cmd_setvf_traffic_set =
4776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4777                                  set, "set");
4778 cmdline_parse_token_string_t cmd_setvf_traffic_port =
4779         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4780                                  port, "port");
4781 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
4782         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4783                               port_id, UINT8);
4784 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
4785         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4786                                  vf, "vf");
4787 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
4788         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
4789                               vf_id, UINT8);
4790 cmdline_parse_token_string_t cmd_setvf_traffic_what =
4791         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4792                                  what, "tx#rx");
4793 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
4794         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
4795                                  mode, "on#off");
4796
4797 cmdline_parse_inst_t cmd_set_vf_traffic = {
4798         .f = cmd_set_vf_traffic_parsed,
4799         .data = NULL,
4800         .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)",
4801         .tokens = {
4802                 (void *)&cmd_setvf_traffic_set,
4803                 (void *)&cmd_setvf_traffic_port,
4804                 (void *)&cmd_setvf_traffic_portid,
4805                 (void *)&cmd_setvf_traffic_vf,
4806                 (void *)&cmd_setvf_traffic_vfid,
4807                 (void *)&cmd_setvf_traffic_what,
4808                 (void *)&cmd_setvf_traffic_mode,
4809                 NULL,
4810         },
4811 };
4812
4813 /* *** CONFIGURE VF RECEIVE MODE *** */
4814 struct cmd_set_vf_rxmode {
4815         cmdline_fixed_string_t set;
4816         cmdline_fixed_string_t port;
4817         uint8_t port_id;
4818         cmdline_fixed_string_t vf;
4819         uint8_t vf_id;
4820         cmdline_fixed_string_t what;
4821         cmdline_fixed_string_t mode;
4822         cmdline_fixed_string_t on;
4823 };
4824
4825 static void
4826 cmd_set_vf_rxmode_parsed(void *parsed_result,
4827                        __attribute__((unused)) struct cmdline *cl,
4828                        __attribute__((unused)) void *data)
4829 {
4830         int ret;
4831         uint16_t rx_mode = 0;
4832         struct cmd_set_vf_rxmode *res = parsed_result;
4833
4834         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
4835         if (!strcmp(res->what,"rxmode")) {
4836                 if (!strcmp(res->mode, "AUPE"))
4837                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
4838                 else if (!strcmp(res->mode, "ROPE"))
4839                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
4840                 else if (!strcmp(res->mode, "BAM"))
4841                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
4842                 else if (!strncmp(res->mode, "MPE",3))
4843                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
4844         }
4845
4846         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
4847         if (ret < 0)
4848                 printf("bad VF receive mode parameter, return code = %d \n",
4849                 ret);
4850 }
4851
4852 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
4853         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4854                                  set, "set");
4855 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
4856         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4857                                  port, "port");
4858 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
4859         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4860                               port_id, UINT8);
4861 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
4862         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4863                                  vf, "vf");
4864 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
4865         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
4866                               vf_id, UINT8);
4867 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
4868         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4869                                  what, "rxmode");
4870 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
4871         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4872                                  mode, "AUPE#ROPE#BAM#MPE");
4873 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
4874         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
4875                                  on, "on#off");
4876
4877 cmdline_parse_inst_t cmd_set_vf_rxmode = {
4878         .f = cmd_set_vf_rxmode_parsed,
4879         .data = NULL,
4880         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
4881         .tokens = {
4882                 (void *)&cmd_set_vf_rxmode_set,
4883                 (void *)&cmd_set_vf_rxmode_port,
4884                 (void *)&cmd_set_vf_rxmode_portid,
4885                 (void *)&cmd_set_vf_rxmode_vf,
4886                 (void *)&cmd_set_vf_rxmode_vfid,
4887                 (void *)&cmd_set_vf_rxmode_what,
4888                 (void *)&cmd_set_vf_rxmode_mode,
4889                 (void *)&cmd_set_vf_rxmode_on,
4890                 NULL,
4891         },
4892 };
4893
4894 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
4895 struct cmd_vf_mac_addr_result {
4896         cmdline_fixed_string_t mac_addr_cmd;
4897         cmdline_fixed_string_t what;
4898         cmdline_fixed_string_t port;
4899         uint8_t port_num;
4900         cmdline_fixed_string_t vf;
4901         uint8_t vf_num;
4902         struct ether_addr address;
4903 };
4904
4905 static void cmd_vf_mac_addr_parsed(void *parsed_result,
4906                 __attribute__((unused)) struct cmdline *cl,
4907                 __attribute__((unused)) void *data)
4908 {
4909         struct cmd_vf_mac_addr_result *res = parsed_result;
4910         int ret = 0;
4911
4912         if (strcmp(res->what, "add") == 0)
4913                 ret = rte_eth_dev_mac_addr_add(res->port_num,
4914                                         &res->address, res->vf_num);
4915         if(ret < 0)
4916                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
4917
4918 }
4919
4920 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
4921         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4922                                 mac_addr_cmd,"mac_addr");
4923 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
4924         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4925                                 what,"add");
4926 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
4927         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4928                                 port,"port");
4929 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
4930         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
4931                                 port_num, UINT8);
4932 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
4933         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
4934                                 vf,"vf");
4935 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
4936         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
4937                                 vf_num, UINT8);
4938 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
4939         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
4940                                 address);
4941
4942 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
4943         .f = cmd_vf_mac_addr_parsed,
4944         .data = (void *)0,
4945         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
4946         "Y = VF number)add MAC address filtering for a VF on port X",
4947         .tokens = {
4948                 (void *)&cmd_vf_mac_addr_cmd,
4949                 (void *)&cmd_vf_mac_addr_what,
4950                 (void *)&cmd_vf_mac_addr_port,
4951                 (void *)&cmd_vf_mac_addr_portnum,
4952                 (void *)&cmd_vf_mac_addr_vf,
4953                 (void *)&cmd_vf_mac_addr_vfnum,
4954                 (void *)&cmd_vf_mac_addr_addr,
4955                 NULL,
4956         },
4957 };
4958
4959 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4960 struct cmd_vf_rx_vlan_filter {
4961         cmdline_fixed_string_t rx_vlan;
4962         cmdline_fixed_string_t what;
4963         uint16_t vlan_id;
4964         cmdline_fixed_string_t port;
4965         uint8_t port_id;
4966         cmdline_fixed_string_t vf;
4967         uint64_t vf_mask;
4968 };
4969
4970 static void
4971 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
4972                           __attribute__((unused)) struct cmdline *cl,
4973                           __attribute__((unused)) void *data)
4974 {
4975         struct cmd_vf_rx_vlan_filter *res = parsed_result;
4976
4977         if (!strcmp(res->what, "add"))
4978                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
4979         else
4980                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
4981 }
4982
4983 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
4984         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4985                                  rx_vlan, "rx_vlan");
4986 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
4987         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4988                                  what, "add#rm");
4989 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
4990         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4991                               vlan_id, UINT16);
4992 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
4993         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4994                                  port, "port");
4995 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
4996         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
4997                               port_id, UINT8);
4998 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
4999         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5000                                  vf, "vf");
5001 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
5002         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5003                               vf_mask, UINT64);
5004
5005 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
5006         .f = cmd_vf_rx_vlan_filter_parsed,
5007         .data = NULL,
5008         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
5009                 "Y = port number,Z = hexadecimal VF mask)",
5010         .tokens = {
5011                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
5012                 (void *)&cmd_vf_rx_vlan_filter_what,
5013                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
5014                 (void *)&cmd_vf_rx_vlan_filter_port,
5015                 (void *)&cmd_vf_rx_vlan_filter_portid,
5016                 (void *)&cmd_vf_rx_vlan_filter_vf,
5017                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
5018                 NULL,
5019         },
5020 };
5021
5022 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
5023 struct cmd_set_mirror_mask_result {
5024         cmdline_fixed_string_t set;
5025         cmdline_fixed_string_t port;
5026         uint8_t port_id;
5027         cmdline_fixed_string_t mirror;
5028         uint8_t rule_id;
5029         cmdline_fixed_string_t what;
5030         cmdline_fixed_string_t value;
5031         cmdline_fixed_string_t dstpool;
5032         uint8_t dstpool_id;
5033         cmdline_fixed_string_t on;
5034 };
5035
5036 cmdline_parse_token_string_t cmd_mirror_mask_set =
5037         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5038                                 set, "set");
5039 cmdline_parse_token_string_t cmd_mirror_mask_port =
5040         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5041                                 port, "port");
5042 cmdline_parse_token_string_t cmd_mirror_mask_portid =
5043         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
5044                                 port_id, UINT8);
5045 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
5046         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5047                                 mirror, "mirror-rule");
5048 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
5049         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
5050                                 rule_id, UINT8);
5051 cmdline_parse_token_string_t cmd_mirror_mask_what =
5052         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5053                                 what, "pool-mirror#vlan-mirror");
5054 cmdline_parse_token_string_t cmd_mirror_mask_value =
5055         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5056                                 value, NULL);
5057 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
5058         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5059                                 dstpool, "dst-pool");
5060 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
5061         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
5062                                 dstpool_id, UINT8);
5063 cmdline_parse_token_string_t cmd_mirror_mask_on =
5064         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
5065                                 on, "on#off");
5066
5067 static void
5068 cmd_set_mirror_mask_parsed(void *parsed_result,
5069                        __attribute__((unused)) struct cmdline *cl,
5070                        __attribute__((unused)) void *data)
5071 {
5072         int ret,nb_item,i;
5073         struct cmd_set_mirror_mask_result *res = parsed_result;
5074         struct rte_eth_vmdq_mirror_conf mr_conf;
5075
5076         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
5077
5078         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
5079
5080         mr_conf.dst_pool = res->dstpool_id;
5081
5082         if (!strcmp(res->what, "pool-mirror")) {
5083                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
5084                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
5085         } else if(!strcmp(res->what, "vlan-mirror")) {
5086                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
5087                 nb_item = parse_item_list(res->value, "core",
5088                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
5089                 if (nb_item <= 0)
5090                         return;
5091
5092                 for(i=0; i < nb_item; i++) {
5093                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
5094                                 printf("Invalid vlan_id: must be < 4096\n");
5095                                 return;
5096                         }
5097
5098                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
5099                         mr_conf.vlan.vlan_mask |= 1ULL << i;
5100                 }
5101         }
5102
5103         if(!strcmp(res->on, "on"))
5104                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5105                                                 res->rule_id, 1);
5106         else
5107                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5108                                                 res->rule_id, 0);
5109         if(ret < 0)
5110                 printf("mirror rule add error: (%s)\n", strerror(-ret));
5111 }
5112
5113 cmdline_parse_inst_t cmd_set_mirror_mask = {
5114                 .f = cmd_set_mirror_mask_parsed,
5115                 .data = NULL,
5116                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror "
5117                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
5118                 .tokens = {
5119                         (void *)&cmd_mirror_mask_set,
5120                         (void *)&cmd_mirror_mask_port,
5121                         (void *)&cmd_mirror_mask_portid,
5122                         (void *)&cmd_mirror_mask_mirror,
5123                         (void *)&cmd_mirror_mask_ruleid,
5124                         (void *)&cmd_mirror_mask_what,
5125                         (void *)&cmd_mirror_mask_value,
5126                         (void *)&cmd_mirror_mask_dstpool,
5127                         (void *)&cmd_mirror_mask_poolid,
5128                         (void *)&cmd_mirror_mask_on,
5129                         NULL,
5130                 },
5131 };
5132
5133 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
5134 struct cmd_set_mirror_link_result {
5135         cmdline_fixed_string_t set;
5136         cmdline_fixed_string_t port;
5137         uint8_t port_id;
5138         cmdline_fixed_string_t mirror;
5139         uint8_t rule_id;
5140         cmdline_fixed_string_t what;
5141         cmdline_fixed_string_t dstpool;
5142         uint8_t dstpool_id;
5143         cmdline_fixed_string_t on;
5144 };
5145
5146 cmdline_parse_token_string_t cmd_mirror_link_set =
5147         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5148                                  set, "set");
5149 cmdline_parse_token_string_t cmd_mirror_link_port =
5150         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5151                                 port, "port");
5152 cmdline_parse_token_string_t cmd_mirror_link_portid =
5153         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5154                                 port_id, UINT8);
5155 cmdline_parse_token_string_t cmd_mirror_link_mirror =
5156         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5157                                 mirror, "mirror-rule");
5158 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
5159         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5160                             rule_id, UINT8);
5161 cmdline_parse_token_string_t cmd_mirror_link_what =
5162         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5163                                 what, "uplink-mirror#downlink-mirror");
5164 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
5165         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5166                                 dstpool, "dst-pool");
5167 cmdline_parse_token_num_t cmd_mirror_link_poolid =
5168         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
5169                                 dstpool_id, UINT8);
5170 cmdline_parse_token_string_t cmd_mirror_link_on =
5171         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
5172                                 on, "on#off");
5173
5174 static void
5175 cmd_set_mirror_link_parsed(void *parsed_result,
5176                        __attribute__((unused)) struct cmdline *cl,
5177                        __attribute__((unused)) void *data)
5178 {
5179         int ret;
5180         struct cmd_set_mirror_link_result *res = parsed_result;
5181         struct rte_eth_vmdq_mirror_conf mr_conf;
5182
5183         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
5184         if(!strcmp(res->what, "uplink-mirror")) {
5185                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
5186         }else if(!strcmp(res->what, "downlink-mirror"))
5187                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
5188
5189         mr_conf.dst_pool = res->dstpool_id;
5190
5191         if(!strcmp(res->on, "on"))
5192                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5193                                                 res->rule_id, 1);
5194         else
5195                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
5196                                                 res->rule_id, 0);
5197
5198         /* check the return value and print it if is < 0 */
5199         if(ret < 0)
5200                 printf("mirror rule add error: (%s)\n", strerror(-ret));
5201
5202 }
5203
5204 cmdline_parse_inst_t cmd_set_mirror_link = {
5205                 .f = cmd_set_mirror_link_parsed,
5206                 .data = NULL,
5207                 .help_str = "set port X mirror-rule Y uplink-mirror|"
5208                         "downlink-mirror dst-pool Z on|off",
5209                 .tokens = {
5210                         (void *)&cmd_mirror_link_set,
5211                         (void *)&cmd_mirror_link_port,
5212                         (void *)&cmd_mirror_link_portid,
5213                         (void *)&cmd_mirror_link_mirror,
5214                         (void *)&cmd_mirror_link_ruleid,
5215                         (void *)&cmd_mirror_link_what,
5216                         (void *)&cmd_mirror_link_dstpool,
5217                         (void *)&cmd_mirror_link_poolid,
5218                         (void *)&cmd_mirror_link_on,
5219                         NULL,
5220                 },
5221 };
5222
5223 /* *** RESET VM MIRROR RULE *** */
5224 struct cmd_rm_mirror_rule_result {
5225         cmdline_fixed_string_t reset;
5226         cmdline_fixed_string_t port;
5227         uint8_t port_id;
5228         cmdline_fixed_string_t mirror;
5229         uint8_t rule_id;
5230 };
5231
5232 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
5233         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5234                                  reset, "reset");
5235 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
5236         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5237                                 port, "port");
5238 cmdline_parse_token_string_t cmd_rm_mirror_rule_portid =
5239         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
5240                                 port_id, UINT8);
5241 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
5242         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
5243                                 mirror, "mirror-rule");
5244 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
5245         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
5246                                 rule_id, UINT8);
5247
5248 static void
5249 cmd_reset_mirror_rule_parsed(void *parsed_result,
5250                        __attribute__((unused)) struct cmdline *cl,
5251                        __attribute__((unused)) void *data)
5252 {
5253         int ret;
5254         struct cmd_set_mirror_link_result *res = parsed_result;
5255         /* check rule_id */
5256         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
5257         if(ret < 0)
5258                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
5259 }
5260
5261 cmdline_parse_inst_t cmd_reset_mirror_rule = {
5262                 .f = cmd_reset_mirror_rule_parsed,
5263                 .data = NULL,
5264                 .help_str = "reset port X mirror-rule Y",
5265                 .tokens = {
5266                         (void *)&cmd_rm_mirror_rule_reset,
5267                         (void *)&cmd_rm_mirror_rule_port,
5268                         (void *)&cmd_rm_mirror_rule_portid,
5269                         (void *)&cmd_rm_mirror_rule_mirror,
5270                         (void *)&cmd_rm_mirror_rule_ruleid,
5271                         NULL,
5272                 },
5273 };
5274
5275 /* ******************************************************************************** */
5276
5277 struct cmd_dump_result {
5278         cmdline_fixed_string_t dump;
5279 };
5280
5281 static void
5282 dump_struct_sizes(void)
5283 {
5284 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
5285         DUMP_SIZE(struct rte_mbuf);
5286         DUMP_SIZE(struct rte_pktmbuf);
5287         DUMP_SIZE(struct rte_ctrlmbuf);
5288         DUMP_SIZE(struct rte_mempool);
5289         DUMP_SIZE(struct rte_ring);
5290 #undef DUMP_SIZE
5291 }
5292
5293 static void cmd_dump_parsed(void *parsed_result,
5294                             __attribute__((unused)) struct cmdline *cl,
5295                             __attribute__((unused)) void *data)
5296 {
5297         struct cmd_dump_result *res = parsed_result;
5298
5299         if (!strcmp(res->dump, "dump_physmem"))
5300                 rte_dump_physmem_layout(stdout);
5301         else if (!strcmp(res->dump, "dump_memzone"))
5302                 rte_memzone_dump(stdout);
5303         else if (!strcmp(res->dump, "dump_log_history"))
5304                 rte_log_dump_history(stdout);
5305         else if (!strcmp(res->dump, "dump_struct_sizes"))
5306                 dump_struct_sizes();
5307         else if (!strcmp(res->dump, "dump_ring"))
5308                 rte_ring_list_dump(stdout);
5309         else if (!strcmp(res->dump, "dump_mempool"))
5310                 rte_mempool_list_dump(stdout);
5311         else if (!strcmp(res->dump, "dump_devargs"))
5312                 rte_eal_devargs_dump(stdout);
5313 }
5314
5315 cmdline_parse_token_string_t cmd_dump_dump =
5316         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
5317                 "dump_physmem#"
5318                 "dump_memzone#"
5319                 "dump_log_history#"
5320                 "dump_struct_sizes#"
5321                 "dump_ring#"
5322                 "dump_mempool#"
5323                 "dump_devargs");
5324
5325 cmdline_parse_inst_t cmd_dump = {
5326         .f = cmd_dump_parsed,  /* function to call */
5327         .data = NULL,      /* 2nd arg of func */
5328         .help_str = "dump status",
5329         .tokens = {        /* token list, NULL terminated */
5330                 (void *)&cmd_dump_dump,
5331                 NULL,
5332         },
5333 };
5334
5335 /* ******************************************************************************** */
5336
5337 struct cmd_dump_one_result {
5338         cmdline_fixed_string_t dump;
5339         cmdline_fixed_string_t name;
5340 };
5341
5342 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
5343                                 __attribute__((unused)) void *data)
5344 {
5345         struct cmd_dump_one_result *res = parsed_result;
5346
5347         if (!strcmp(res->dump, "dump_ring")) {
5348                 struct rte_ring *r;
5349                 r = rte_ring_lookup(res->name);
5350                 if (r == NULL) {
5351                         cmdline_printf(cl, "Cannot find ring\n");
5352                         return;
5353                 }
5354                 rte_ring_dump(stdout, r);
5355         } else if (!strcmp(res->dump, "dump_mempool")) {
5356                 struct rte_mempool *mp;
5357                 mp = rte_mempool_lookup(res->name);
5358                 if (mp == NULL) {
5359                         cmdline_printf(cl, "Cannot find mempool\n");
5360                         return;
5361                 }
5362                 rte_mempool_dump(stdout, mp);
5363         }
5364 }
5365
5366 cmdline_parse_token_string_t cmd_dump_one_dump =
5367         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
5368                                  "dump_ring#dump_mempool");
5369
5370 cmdline_parse_token_string_t cmd_dump_one_name =
5371         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
5372
5373 cmdline_parse_inst_t cmd_dump_one = {
5374         .f = cmd_dump_one_parsed,  /* function to call */
5375         .data = NULL,      /* 2nd arg of func */
5376         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
5377         .tokens = {        /* token list, NULL terminated */
5378                 (void *)&cmd_dump_one_dump,
5379                 (void *)&cmd_dump_one_name,
5380                 NULL,
5381         },
5382 };
5383
5384 /* ******************************************************************************** */
5385
5386 /* list of instructions */
5387 cmdline_parse_ctx_t main_ctx[] = {
5388         (cmdline_parse_inst_t *)&cmd_help_brief,
5389         (cmdline_parse_inst_t *)&cmd_help_long,
5390         (cmdline_parse_inst_t *)&cmd_quit,
5391         (cmdline_parse_inst_t *)&cmd_showport,
5392         (cmdline_parse_inst_t *)&cmd_showportall,
5393         (cmdline_parse_inst_t *)&cmd_showcfg,
5394         (cmdline_parse_inst_t *)&cmd_start,
5395         (cmdline_parse_inst_t *)&cmd_start_tx_first,
5396         (cmdline_parse_inst_t *)&cmd_set_link_up,
5397         (cmdline_parse_inst_t *)&cmd_set_link_down,
5398         (cmdline_parse_inst_t *)&cmd_reset,
5399         (cmdline_parse_inst_t *)&cmd_set_numbers,
5400         (cmdline_parse_inst_t *)&cmd_set_txpkts,
5401         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
5402         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
5403         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
5404         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
5405         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
5406         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
5407         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
5408         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
5409         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
5410         (cmdline_parse_inst_t *)&cmd_set_link_check,
5411 #ifdef RTE_NIC_BYPASS
5412         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
5413         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
5414         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
5415         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
5416 #endif
5417         (cmdline_parse_inst_t *)&cmd_vlan_offload,
5418         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
5419         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
5420         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
5421         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
5422         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
5423         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
5424         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
5425         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
5426         (cmdline_parse_inst_t *)&cmd_config_dcb,
5427         (cmdline_parse_inst_t *)&cmd_read_reg,
5428         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
5429         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
5430         (cmdline_parse_inst_t *)&cmd_write_reg,
5431         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
5432         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
5433         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
5434         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
5435         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
5436         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
5437         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
5438         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
5439         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
5440         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
5441         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
5442         (cmdline_parse_inst_t *)&cmd_stop,
5443         (cmdline_parse_inst_t *)&cmd_mac_addr,
5444         (cmdline_parse_inst_t *)&cmd_set_qmap,
5445         (cmdline_parse_inst_t *)&cmd_operate_port,
5446         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
5447         (cmdline_parse_inst_t *)&cmd_config_speed_all,
5448         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
5449         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
5450         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
5451         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
5452         (cmdline_parse_inst_t *)&cmd_config_rss,
5453         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
5454         (cmdline_parse_inst_t *)&cmd_showport_reta,
5455         (cmdline_parse_inst_t *)&cmd_config_burst,
5456         (cmdline_parse_inst_t *)&cmd_config_thresh,
5457         (cmdline_parse_inst_t *)&cmd_config_threshold,
5458         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
5459         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
5460         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
5461         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
5462         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
5463         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
5464         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
5465         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
5466         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
5467         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
5468         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
5469         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
5470         (cmdline_parse_inst_t *)&cmd_dump,
5471         (cmdline_parse_inst_t *)&cmd_dump_one,
5472         NULL,
5473 };
5474
5475 /* prompt function, called from main on MASTER lcore */
5476 void
5477 prompt(void)
5478 {
5479         struct cmdline *cl;
5480
5481         /* initialize non-constant commands */
5482         cmd_set_fwd_mode_init();
5483
5484         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
5485         if (cl == NULL) {
5486                 return;
5487         }
5488         cmdline_interact(cl);
5489         cmdline_stdin_exit(cl);
5490 }
5491
5492 static void
5493 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
5494 {
5495         if (id < nb_ports) {
5496                 /* check if need_reconfig has been set to 1 */
5497                 if (ports[id].need_reconfig == 0)
5498                         ports[id].need_reconfig = dev;
5499                 /* check if need_reconfig_queues has been set to 1 */
5500                 if (ports[id].need_reconfig_queues == 0)
5501                         ports[id].need_reconfig_queues = queue;
5502         } else {
5503                 portid_t pid;
5504
5505                 for (pid = 0; pid < nb_ports; pid++) {
5506                         /* check if need_reconfig has been set to 1 */
5507                         if (ports[pid].need_reconfig == 0)
5508                                 ports[pid].need_reconfig = dev;
5509                         /* check if need_reconfig_queues has been set to 1 */
5510                         if (ports[pid].need_reconfig_queues == 0)
5511                                 ports[pid].need_reconfig_queues = queue;
5512                 }
5513         }
5514 }
5515
5516 #ifdef RTE_NIC_BYPASS
5517 uint8_t
5518 bypass_is_supported(portid_t port_id)
5519 {
5520         struct rte_port   *port;
5521         struct rte_pci_id *pci_id;
5522
5523         if (port_id >= nb_ports) {
5524                 printf("\tPort id must be less than %d.\n", nb_ports);
5525                 return 0;
5526         }
5527
5528         /* Get the device id. */
5529         port    = &ports[port_id];
5530         pci_id = &port->dev_info.pci_dev->id;
5531
5532         /* Check if NIC supports bypass. */
5533         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
5534                 return 1;
5535         }
5536         else {
5537                 printf("\tBypass not supported for port_id = %d.\n", port_id);
5538                 return 0;
5539         }
5540 }
5541 #endif