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