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