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