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