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