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