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