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