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