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