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