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