app/testpmd: fix port parsing in show port info command
[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                         "tx_cksum 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                         "tx_checksum 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_thresh.pthresh = res->value;
2101         else if(!strcmp(res->name, "txht"))
2102                 tx_thresh.hthresh = res->value;
2103         else if(!strcmp(res->name, "txwt"))
2104                 tx_thresh.wthresh = res->value;
2105         else if(!strcmp(res->name, "rxpt"))
2106                 rx_thresh.pthresh = res->value;
2107         else if(!strcmp(res->name, "rxht"))
2108                 rx_thresh.hthresh = res->value;
2109         else if(!strcmp(res->name, "rxwt"))
2110                 rx_thresh.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         res = parsed_result;
2320         if (!strcmp(res->list_name, "corelist")) {
2321                 nb_item = parse_item_list(res->list_of_items, "core",
2322                                           RTE_MAX_LCORE,
2323                                           parsed_items.lcorelist, 1);
2324                 if (nb_item > 0)
2325                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2326                 return;
2327         }
2328         if (!strcmp(res->list_name, "portlist")) {
2329                 nb_item = parse_item_list(res->list_of_items, "port",
2330                                           RTE_MAX_ETHPORTS,
2331                                           parsed_items.portlist, 1);
2332                 if (nb_item > 0)
2333                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2334         }
2335 }
2336
2337 cmdline_parse_token_string_t cmd_set_list_keyword =
2338         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2339                                  "set");
2340 cmdline_parse_token_string_t cmd_set_list_name =
2341         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2342                                  "corelist#portlist");
2343 cmdline_parse_token_string_t cmd_set_list_of_items =
2344         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2345                                  NULL);
2346
2347 cmdline_parse_inst_t cmd_set_fwd_list = {
2348         .f = cmd_set_list_parsed,
2349         .data = NULL,
2350         .help_str = "set corelist|portlist x[,y]*",
2351         .tokens = {
2352                 (void *)&cmd_set_list_keyword,
2353                 (void *)&cmd_set_list_name,
2354                 (void *)&cmd_set_list_of_items,
2355                 NULL,
2356         },
2357 };
2358
2359 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2360
2361 struct cmd_setmask_result {
2362         cmdline_fixed_string_t set;
2363         cmdline_fixed_string_t mask;
2364         uint64_t hexavalue;
2365 };
2366
2367 static void cmd_set_mask_parsed(void *parsed_result,
2368                                 __attribute__((unused)) struct cmdline *cl,
2369                                 __attribute__((unused)) void *data)
2370 {
2371         struct cmd_setmask_result *res = parsed_result;
2372
2373         if (!strcmp(res->mask, "coremask"))
2374                 set_fwd_lcores_mask(res->hexavalue);
2375         else if (!strcmp(res->mask, "portmask"))
2376                 set_fwd_ports_mask(res->hexavalue);
2377 }
2378
2379 cmdline_parse_token_string_t cmd_setmask_set =
2380         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2381 cmdline_parse_token_string_t cmd_setmask_mask =
2382         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2383                                  "coremask#portmask");
2384 cmdline_parse_token_num_t cmd_setmask_value =
2385         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2386
2387 cmdline_parse_inst_t cmd_set_fwd_mask = {
2388         .f = cmd_set_mask_parsed,
2389         .data = NULL,
2390         .help_str = "set coremask|portmask hexadecimal value",
2391         .tokens = {
2392                 (void *)&cmd_setmask_set,
2393                 (void *)&cmd_setmask_mask,
2394                 (void *)&cmd_setmask_value,
2395                 NULL,
2396         },
2397 };
2398
2399 /*
2400  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2401  */
2402 struct cmd_set_result {
2403         cmdline_fixed_string_t set;
2404         cmdline_fixed_string_t what;
2405         uint16_t value;
2406 };
2407
2408 static void cmd_set_parsed(void *parsed_result,
2409                            __attribute__((unused)) struct cmdline *cl,
2410                            __attribute__((unused)) void *data)
2411 {
2412         struct cmd_set_result *res = parsed_result;
2413         if (!strcmp(res->what, "nbport"))
2414                 set_fwd_ports_number(res->value);
2415         else if (!strcmp(res->what, "nbcore"))
2416                 set_fwd_lcores_number(res->value);
2417         else if (!strcmp(res->what, "burst"))
2418                 set_nb_pkt_per_burst(res->value);
2419         else if (!strcmp(res->what, "verbose"))
2420                 set_verbose_level(res->value);
2421 }
2422
2423 cmdline_parse_token_string_t cmd_set_set =
2424         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2425 cmdline_parse_token_string_t cmd_set_what =
2426         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2427                                  "nbport#nbcore#burst#verbose");
2428 cmdline_parse_token_num_t cmd_set_value =
2429         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2430
2431 cmdline_parse_inst_t cmd_set_numbers = {
2432         .f = cmd_set_parsed,
2433         .data = NULL,
2434         .help_str = "set nbport|nbcore|burst|verbose value",
2435         .tokens = {
2436                 (void *)&cmd_set_set,
2437                 (void *)&cmd_set_what,
2438                 (void *)&cmd_set_value,
2439                 NULL,
2440         },
2441 };
2442
2443 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2444
2445 struct cmd_set_txpkts_result {
2446         cmdline_fixed_string_t cmd_keyword;
2447         cmdline_fixed_string_t txpkts;
2448         cmdline_fixed_string_t seg_lengths;
2449 };
2450
2451 static void
2452 cmd_set_txpkts_parsed(void *parsed_result,
2453                       __attribute__((unused)) struct cmdline *cl,
2454                       __attribute__((unused)) void *data)
2455 {
2456         struct cmd_set_txpkts_result *res;
2457         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2458         unsigned int nb_segs;
2459
2460         res = parsed_result;
2461         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2462                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2463         if (nb_segs > 0)
2464                 set_tx_pkt_segments(seg_lengths, nb_segs);
2465 }
2466
2467 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2468         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2469                                  cmd_keyword, "set");
2470 cmdline_parse_token_string_t cmd_set_txpkts_name =
2471         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2472                                  txpkts, "txpkts");
2473 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2474         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2475                                  seg_lengths, NULL);
2476
2477 cmdline_parse_inst_t cmd_set_txpkts = {
2478         .f = cmd_set_txpkts_parsed,
2479         .data = NULL,
2480         .help_str = "set txpkts x[,y]*",
2481         .tokens = {
2482                 (void *)&cmd_set_txpkts_keyword,
2483                 (void *)&cmd_set_txpkts_name,
2484                 (void *)&cmd_set_txpkts_lengths,
2485                 NULL,
2486         },
2487 };
2488
2489 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2490 struct cmd_rx_vlan_filter_all_result {
2491         cmdline_fixed_string_t rx_vlan;
2492         cmdline_fixed_string_t what;
2493         cmdline_fixed_string_t all;
2494         uint8_t port_id;
2495 };
2496
2497 static void
2498 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2499                               __attribute__((unused)) struct cmdline *cl,
2500                               __attribute__((unused)) void *data)
2501 {
2502         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2503
2504         if (!strcmp(res->what, "add"))
2505                 rx_vlan_all_filter_set(res->port_id, 1);
2506         else
2507                 rx_vlan_all_filter_set(res->port_id, 0);
2508 }
2509
2510 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2511         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2512                                  rx_vlan, "rx_vlan");
2513 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2514         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2515                                  what, "add#rm");
2516 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2517         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2518                                  all, "all");
2519 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2520         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2521                               port_id, UINT8);
2522
2523 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2524         .f = cmd_rx_vlan_filter_all_parsed,
2525         .data = NULL,
2526         .help_str = "add/remove all identifiers to/from the set of VLAN "
2527         "Identifiers filtered by a port",
2528         .tokens = {
2529                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2530                 (void *)&cmd_rx_vlan_filter_all_what,
2531                 (void *)&cmd_rx_vlan_filter_all_all,
2532                 (void *)&cmd_rx_vlan_filter_all_portid,
2533                 NULL,
2534         },
2535 };
2536
2537 /* *** VLAN OFFLOAD SET ON A PORT *** */
2538 struct cmd_vlan_offload_result {
2539         cmdline_fixed_string_t vlan;
2540         cmdline_fixed_string_t set;
2541         cmdline_fixed_string_t what;
2542         cmdline_fixed_string_t on;
2543         cmdline_fixed_string_t port_id;
2544 };
2545
2546 static void
2547 cmd_vlan_offload_parsed(void *parsed_result,
2548                           __attribute__((unused)) struct cmdline *cl,
2549                           __attribute__((unused)) void *data)
2550 {
2551         int on;
2552         struct cmd_vlan_offload_result *res = parsed_result;
2553         char *str;
2554         int i, len = 0;
2555         portid_t port_id = 0;
2556         unsigned int tmp;
2557
2558         str = res->port_id;
2559         len = strnlen(str, STR_TOKEN_SIZE);
2560         i = 0;
2561         /* Get port_id first */
2562         while(i < len){
2563                 if(str[i] == ',')
2564                         break;
2565
2566                 i++;
2567         }
2568         str[i]='\0';
2569         tmp = strtoul(str, NULL, 0);
2570         /* If port_id greater that what portid_t can represent, return */
2571         if(tmp >= RTE_MAX_ETHPORTS)
2572                 return;
2573         port_id = (portid_t)tmp;
2574
2575         if (!strcmp(res->on, "on"))
2576                 on = 1;
2577         else
2578                 on = 0;
2579
2580         if (!strcmp(res->what, "strip"))
2581                 rx_vlan_strip_set(port_id,  on);
2582         else if(!strcmp(res->what, "stripq")){
2583                 uint16_t queue_id = 0;
2584
2585                 /* No queue_id, return */
2586                 if(i + 1 >= len) {
2587                         printf("must specify (port,queue_id)\n");
2588                         return;
2589                 }
2590                 tmp = strtoul(str + i + 1, NULL, 0);
2591                 /* If queue_id greater that what 16-bits can represent, return */
2592                 if(tmp > 0xffff)
2593                         return;
2594
2595                 queue_id = (uint16_t)tmp;
2596                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2597         }
2598         else if (!strcmp(res->what, "filter"))
2599                 rx_vlan_filter_set(port_id, on);
2600         else
2601                 vlan_extend_set(port_id, on);
2602
2603         return;
2604 }
2605
2606 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2607         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2608                                  vlan, "vlan");
2609 cmdline_parse_token_string_t cmd_vlan_offload_set =
2610         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2611                                  set, "set");
2612 cmdline_parse_token_string_t cmd_vlan_offload_what =
2613         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2614                                  what, "strip#filter#qinq#stripq");
2615 cmdline_parse_token_string_t cmd_vlan_offload_on =
2616         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2617                               on, "on#off");
2618 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2619         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2620                               port_id, NULL);
2621
2622 cmdline_parse_inst_t cmd_vlan_offload = {
2623         .f = cmd_vlan_offload_parsed,
2624         .data = NULL,
2625         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2626         " qinq(extended) for both rx/tx sides ",
2627         .tokens = {
2628                 (void *)&cmd_vlan_offload_vlan,
2629                 (void *)&cmd_vlan_offload_set,
2630                 (void *)&cmd_vlan_offload_what,
2631                 (void *)&cmd_vlan_offload_on,
2632                 (void *)&cmd_vlan_offload_portid,
2633                 NULL,
2634         },
2635 };
2636
2637 /* *** VLAN TPID SET ON A PORT *** */
2638 struct cmd_vlan_tpid_result {
2639         cmdline_fixed_string_t vlan;
2640         cmdline_fixed_string_t set;
2641         cmdline_fixed_string_t what;
2642         uint16_t tp_id;
2643         uint8_t port_id;
2644 };
2645
2646 static void
2647 cmd_vlan_tpid_parsed(void *parsed_result,
2648                           __attribute__((unused)) struct cmdline *cl,
2649                           __attribute__((unused)) void *data)
2650 {
2651         struct cmd_vlan_tpid_result *res = parsed_result;
2652         vlan_tpid_set(res->port_id, res->tp_id);
2653         return;
2654 }
2655
2656 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2657         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2658                                  vlan, "vlan");
2659 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2660         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2661                                  set, "set");
2662 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2663         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2664                                  what, "tpid");
2665 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2666         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2667                               tp_id, UINT16);
2668 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2669         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2670                               port_id, UINT8);
2671
2672 cmdline_parse_inst_t cmd_vlan_tpid = {
2673         .f = cmd_vlan_tpid_parsed,
2674         .data = NULL,
2675         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2676         .tokens = {
2677                 (void *)&cmd_vlan_tpid_vlan,
2678                 (void *)&cmd_vlan_tpid_set,
2679                 (void *)&cmd_vlan_tpid_what,
2680                 (void *)&cmd_vlan_tpid_tpid,
2681                 (void *)&cmd_vlan_tpid_portid,
2682                 NULL,
2683         },
2684 };
2685
2686 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2687 struct cmd_rx_vlan_filter_result {
2688         cmdline_fixed_string_t rx_vlan;
2689         cmdline_fixed_string_t what;
2690         uint16_t vlan_id;
2691         uint8_t port_id;
2692 };
2693
2694 static void
2695 cmd_rx_vlan_filter_parsed(void *parsed_result,
2696                           __attribute__((unused)) struct cmdline *cl,
2697                           __attribute__((unused)) void *data)
2698 {
2699         struct cmd_rx_vlan_filter_result *res = parsed_result;
2700
2701         if (!strcmp(res->what, "add"))
2702                 rx_vft_set(res->port_id, res->vlan_id, 1);
2703         else
2704                 rx_vft_set(res->port_id, res->vlan_id, 0);
2705 }
2706
2707 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2708         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2709                                  rx_vlan, "rx_vlan");
2710 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2711         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2712                                  what, "add#rm");
2713 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2714         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2715                               vlan_id, UINT16);
2716 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2717         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2718                               port_id, UINT8);
2719
2720 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2721         .f = cmd_rx_vlan_filter_parsed,
2722         .data = NULL,
2723         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2724         "Identifiers filtered by a port",
2725         .tokens = {
2726                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2727                 (void *)&cmd_rx_vlan_filter_what,
2728                 (void *)&cmd_rx_vlan_filter_vlanid,
2729                 (void *)&cmd_rx_vlan_filter_portid,
2730                 NULL,
2731         },
2732 };
2733
2734 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2735 struct cmd_tx_vlan_set_result {
2736         cmdline_fixed_string_t tx_vlan;
2737         cmdline_fixed_string_t set;
2738         uint16_t vlan_id;
2739         uint8_t port_id;
2740 };
2741
2742 static void
2743 cmd_tx_vlan_set_parsed(void *parsed_result,
2744                        __attribute__((unused)) struct cmdline *cl,
2745                        __attribute__((unused)) void *data)
2746 {
2747         struct cmd_tx_vlan_set_result *res = parsed_result;
2748         tx_vlan_set(res->port_id, res->vlan_id);
2749 }
2750
2751 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2752         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2753                                  tx_vlan, "tx_vlan");
2754 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2755         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2756                                  set, "set");
2757 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2758         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2759                               vlan_id, UINT16);
2760 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2761         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2762                               port_id, UINT8);
2763
2764 cmdline_parse_inst_t cmd_tx_vlan_set = {
2765         .f = cmd_tx_vlan_set_parsed,
2766         .data = NULL,
2767         .help_str = "enable hardware insertion of a VLAN header with a given "
2768         "TAG Identifier in packets sent on a port",
2769         .tokens = {
2770                 (void *)&cmd_tx_vlan_set_tx_vlan,
2771                 (void *)&cmd_tx_vlan_set_set,
2772                 (void *)&cmd_tx_vlan_set_vlanid,
2773                 (void *)&cmd_tx_vlan_set_portid,
2774                 NULL,
2775         },
2776 };
2777
2778 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
2779 struct cmd_tx_vlan_set_pvid_result {
2780         cmdline_fixed_string_t tx_vlan;
2781         cmdline_fixed_string_t set;
2782         cmdline_fixed_string_t pvid;
2783         uint8_t port_id;
2784         uint16_t vlan_id;
2785         cmdline_fixed_string_t mode;
2786 };
2787
2788 static void
2789 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
2790                             __attribute__((unused)) struct cmdline *cl,
2791                             __attribute__((unused)) void *data)
2792 {
2793         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
2794
2795         if (strcmp(res->mode, "on") == 0)
2796                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
2797         else
2798                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
2799 }
2800
2801 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
2802         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2803                                  tx_vlan, "tx_vlan");
2804 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
2805         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2806                                  set, "set");
2807 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
2808         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2809                                  pvid, "pvid");
2810 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
2811         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2812                              port_id, UINT8);
2813 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
2814         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2815                               vlan_id, UINT16);
2816 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
2817         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2818                                  mode, "on#off");
2819
2820 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
2821         .f = cmd_tx_vlan_set_pvid_parsed,
2822         .data = NULL,
2823         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
2824         .tokens = {
2825                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
2826                 (void *)&cmd_tx_vlan_set_pvid_set,
2827                 (void *)&cmd_tx_vlan_set_pvid_pvid,
2828                 (void *)&cmd_tx_vlan_set_pvid_port_id,
2829                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
2830                 (void *)&cmd_tx_vlan_set_pvid_mode,
2831                 NULL,
2832         },
2833 };
2834
2835 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2836 struct cmd_tx_vlan_reset_result {
2837         cmdline_fixed_string_t tx_vlan;
2838         cmdline_fixed_string_t reset;
2839         uint8_t port_id;
2840 };
2841
2842 static void
2843 cmd_tx_vlan_reset_parsed(void *parsed_result,
2844                          __attribute__((unused)) struct cmdline *cl,
2845                          __attribute__((unused)) void *data)
2846 {
2847         struct cmd_tx_vlan_reset_result *res = parsed_result;
2848
2849         tx_vlan_reset(res->port_id);
2850 }
2851
2852 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2853         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2854                                  tx_vlan, "tx_vlan");
2855 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2856         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2857                                  reset, "reset");
2858 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2859         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2860                               port_id, UINT8);
2861
2862 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2863         .f = cmd_tx_vlan_reset_parsed,
2864         .data = NULL,
2865         .help_str = "disable hardware insertion of a VLAN header in packets "
2866         "sent on a port",
2867         .tokens = {
2868                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2869                 (void *)&cmd_tx_vlan_reset_reset,
2870                 (void *)&cmd_tx_vlan_reset_portid,
2871                 NULL,
2872         },
2873 };
2874
2875
2876 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2877 struct cmd_tx_cksum_result {
2878         cmdline_fixed_string_t tx_cksum;
2879         cmdline_fixed_string_t mode;
2880         cmdline_fixed_string_t proto;
2881         cmdline_fixed_string_t hwsw;
2882         uint8_t port_id;
2883 };
2884
2885 static void
2886 cmd_tx_cksum_parsed(void *parsed_result,
2887                        __attribute__((unused)) struct cmdline *cl,
2888                        __attribute__((unused)) void *data)
2889 {
2890         struct cmd_tx_cksum_result *res = parsed_result;
2891         int hw = 0;
2892         uint16_t ol_flags, mask = 0;
2893         struct rte_eth_dev_info dev_info;
2894
2895         if (port_id_is_invalid(res->port_id)) {
2896                 printf("invalid port %d\n", res->port_id);
2897                 return;
2898         }
2899
2900         if (!strcmp(res->mode, "set")) {
2901
2902                 if (!strcmp(res->hwsw, "hw"))
2903                         hw = 1;
2904
2905                 if (!strcmp(res->proto, "ip")) {
2906                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
2907                 } else if (!strcmp(res->proto, "udp")) {
2908                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
2909                 } else if (!strcmp(res->proto, "tcp")) {
2910                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
2911                 } else if (!strcmp(res->proto, "sctp")) {
2912                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
2913                 } else if (!strcmp(res->proto, "vxlan")) {
2914                         mask = TESTPMD_TX_OFFLOAD_VXLAN_CKSUM;
2915                 }
2916
2917                 if (hw)
2918                         ports[res->port_id].tx_ol_flags |= mask;
2919                 else
2920                         ports[res->port_id].tx_ol_flags &= (~mask);
2921         }
2922
2923         ol_flags = ports[res->port_id].tx_ol_flags;
2924         printf("IP checksum offload is %s\n",
2925                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
2926         printf("UDP checksum offload is %s\n",
2927                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
2928         printf("TCP checksum offload is %s\n",
2929                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
2930         printf("SCTP checksum offload is %s\n",
2931                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
2932         printf("VxLAN checksum offload is %s\n",
2933                 (ol_flags & TESTPMD_TX_OFFLOAD_VXLAN_CKSUM) ? "hw" : "sw");
2934
2935         /* display warnings if configuration is not supported by the NIC */
2936         rte_eth_dev_info_get(res->port_id, &dev_info);
2937         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
2938                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
2939                 printf("Warning: hardware IP checksum enabled but not "
2940                         "supported by port %d\n", res->port_id);
2941         }
2942         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
2943                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
2944                 printf("Warning: hardware UDP checksum enabled but not "
2945                         "supported by port %d\n", res->port_id);
2946         }
2947         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
2948                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
2949                 printf("Warning: hardware TCP checksum enabled but not "
2950                         "supported by port %d\n", res->port_id);
2951         }
2952         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
2953                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
2954                 printf("Warning: hardware SCTP checksum enabled but not "
2955                         "supported by port %d\n", res->port_id);
2956         }
2957 }
2958
2959 cmdline_parse_token_string_t cmd_tx_cksum_tx_cksum =
2960         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_result,
2961                                 tx_cksum, "tx_checksum");
2962 cmdline_parse_token_string_t cmd_tx_cksum_mode =
2963         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_result,
2964                                 mode, "set");
2965 cmdline_parse_token_string_t cmd_tx_cksum_proto =
2966         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_result,
2967                                 proto, "ip#tcp#udp#sctp#vxlan");
2968 cmdline_parse_token_string_t cmd_tx_cksum_hwsw =
2969         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_result,
2970                                 hwsw, "hw#sw");
2971 cmdline_parse_token_num_t cmd_tx_cksum_portid =
2972         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_result,
2973                                 port_id, UINT8);
2974
2975 cmdline_parse_inst_t cmd_tx_cksum_set = {
2976         .f = cmd_tx_cksum_parsed,
2977         .data = NULL,
2978         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
2979                 "using csum forward engine: tx_cksum set ip|tcp|udp|sctp|vxlan hw|sw <port>",
2980         .tokens = {
2981                 (void *)&cmd_tx_cksum_tx_cksum,
2982                 (void *)&cmd_tx_cksum_mode,
2983                 (void *)&cmd_tx_cksum_proto,
2984                 (void *)&cmd_tx_cksum_hwsw,
2985                 (void *)&cmd_tx_cksum_portid,
2986                 NULL,
2987         },
2988 };
2989
2990 cmdline_parse_token_string_t cmd_tx_cksum_mode_show =
2991         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_result,
2992                                 mode, "show");
2993
2994 cmdline_parse_inst_t cmd_tx_cksum_show = {
2995         .f = cmd_tx_cksum_parsed,
2996         .data = NULL,
2997         .help_str = "show checksum offload configuration: tx_cksum show <port>",
2998         .tokens = {
2999                 (void *)&cmd_tx_cksum_tx_cksum,
3000                 (void *)&cmd_tx_cksum_mode_show,
3001                 (void *)&cmd_tx_cksum_portid,
3002                 NULL,
3003         },
3004 };
3005
3006 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3007 struct cmd_tso_set_result {
3008         cmdline_fixed_string_t tso;
3009         cmdline_fixed_string_t mode;
3010         uint16_t tso_segsz;
3011         uint8_t port_id;
3012 };
3013
3014 static void
3015 cmd_tso_set_parsed(void *parsed_result,
3016                        __attribute__((unused)) struct cmdline *cl,
3017                        __attribute__((unused)) void *data)
3018 {
3019         struct cmd_tso_set_result *res = parsed_result;
3020         struct rte_eth_dev_info dev_info;
3021
3022         if (port_id_is_invalid(res->port_id))
3023                 return;
3024
3025         if (!strcmp(res->mode, "set"))
3026                 ports[res->port_id].tso_segsz = res->tso_segsz;
3027
3028         if (ports[res->port_id].tso_segsz == 0)
3029                 printf("TSO is disabled\n");
3030         else
3031                 printf("TSO segment size is %d\n",
3032                         ports[res->port_id].tso_segsz);
3033
3034         /* display warnings if configuration is not supported by the NIC */
3035         rte_eth_dev_info_get(res->port_id, &dev_info);
3036         if ((ports[res->port_id].tso_segsz != 0) &&
3037                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3038                 printf("Warning: TSO enabled but not "
3039                         "supported by port %d\n", res->port_id);
3040         }
3041 }
3042
3043 cmdline_parse_token_string_t cmd_tso_set_tso =
3044         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3045                                 tso, "tso");
3046 cmdline_parse_token_string_t cmd_tso_set_mode =
3047         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3048                                 mode, "set");
3049 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3050         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3051                                 tso_segsz, UINT16);
3052 cmdline_parse_token_num_t cmd_tso_set_portid =
3053         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3054                                 port_id, UINT8);
3055
3056 cmdline_parse_inst_t cmd_tso_set = {
3057         .f = cmd_tso_set_parsed,
3058         .data = NULL,
3059         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3060         "tso set <tso_segsz> <port>",
3061         .tokens = {
3062                 (void *)&cmd_tso_set_tso,
3063                 (void *)&cmd_tso_set_mode,
3064                 (void *)&cmd_tso_set_tso_segsz,
3065                 (void *)&cmd_tso_set_portid,
3066                 NULL,
3067         },
3068 };
3069
3070 cmdline_parse_token_string_t cmd_tso_show_mode =
3071         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3072                                 mode, "show");
3073
3074
3075 cmdline_parse_inst_t cmd_tso_show = {
3076         .f = cmd_tso_set_parsed,
3077         .data = NULL,
3078         .help_str = "Show TSO segment size for csum engine: "
3079         "tso show <port>",
3080         .tokens = {
3081                 (void *)&cmd_tso_set_tso,
3082                 (void *)&cmd_tso_show_mode,
3083                 (void *)&cmd_tso_set_portid,
3084                 NULL,
3085         },
3086 };
3087
3088 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3089 struct cmd_set_flush_rx {
3090         cmdline_fixed_string_t set;
3091         cmdline_fixed_string_t flush_rx;
3092         cmdline_fixed_string_t mode;
3093 };
3094
3095 static void
3096 cmd_set_flush_rx_parsed(void *parsed_result,
3097                 __attribute__((unused)) struct cmdline *cl,
3098                 __attribute__((unused)) void *data)
3099 {
3100         struct cmd_set_flush_rx *res = parsed_result;
3101         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3102 }
3103
3104 cmdline_parse_token_string_t cmd_setflushrx_set =
3105         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3106                         set, "set");
3107 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3108         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3109                         flush_rx, "flush_rx");
3110 cmdline_parse_token_string_t cmd_setflushrx_mode =
3111         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3112                         mode, "on#off");
3113
3114
3115 cmdline_parse_inst_t cmd_set_flush_rx = {
3116         .f = cmd_set_flush_rx_parsed,
3117         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3118         .data = NULL,
3119         .tokens = {
3120                 (void *)&cmd_setflushrx_set,
3121                 (void *)&cmd_setflushrx_flush_rx,
3122                 (void *)&cmd_setflushrx_mode,
3123                 NULL,
3124         },
3125 };
3126
3127 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3128 struct cmd_set_link_check {
3129         cmdline_fixed_string_t set;
3130         cmdline_fixed_string_t link_check;
3131         cmdline_fixed_string_t mode;
3132 };
3133
3134 static void
3135 cmd_set_link_check_parsed(void *parsed_result,
3136                 __attribute__((unused)) struct cmdline *cl,
3137                 __attribute__((unused)) void *data)
3138 {
3139         struct cmd_set_link_check *res = parsed_result;
3140         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3141 }
3142
3143 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3144         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3145                         set, "set");
3146 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3147         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3148                         link_check, "link_check");
3149 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3150         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3151                         mode, "on#off");
3152
3153
3154 cmdline_parse_inst_t cmd_set_link_check = {
3155         .f = cmd_set_link_check_parsed,
3156         .help_str = "set link_check on|off: enable/disable link status check "
3157                     "when starting/stopping a port",
3158         .data = NULL,
3159         .tokens = {
3160                 (void *)&cmd_setlinkcheck_set,
3161                 (void *)&cmd_setlinkcheck_link_check,
3162                 (void *)&cmd_setlinkcheck_mode,
3163                 NULL,
3164         },
3165 };
3166
3167 #ifdef RTE_NIC_BYPASS
3168 /* *** SET NIC BYPASS MODE *** */
3169 struct cmd_set_bypass_mode_result {
3170         cmdline_fixed_string_t set;
3171         cmdline_fixed_string_t bypass;
3172         cmdline_fixed_string_t mode;
3173         cmdline_fixed_string_t value;
3174         uint8_t port_id;
3175 };
3176
3177 static void
3178 cmd_set_bypass_mode_parsed(void *parsed_result,
3179                 __attribute__((unused)) struct cmdline *cl,
3180                 __attribute__((unused)) void *data)
3181 {
3182         struct cmd_set_bypass_mode_result *res = parsed_result;
3183         portid_t port_id = res->port_id;
3184         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3185
3186         if (!bypass_is_supported(port_id))
3187                 return;
3188
3189         if (!strcmp(res->value, "bypass"))
3190                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3191         else if (!strcmp(res->value, "isolate"))
3192                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3193         else
3194                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3195
3196         /* Set the bypass mode for the relevant port. */
3197         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3198                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3199         }
3200 }
3201
3202 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3203         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3204                         set, "set");
3205 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3206         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3207                         bypass, "bypass");
3208 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3209         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3210                         mode, "mode");
3211 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3212         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3213                         value, "normal#bypass#isolate");
3214 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3215         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3216                                 port_id, UINT8);
3217
3218 cmdline_parse_inst_t cmd_set_bypass_mode = {
3219         .f = cmd_set_bypass_mode_parsed,
3220         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3221                     "Set the NIC bypass mode for port_id",
3222         .data = NULL,
3223         .tokens = {
3224                 (void *)&cmd_setbypass_mode_set,
3225                 (void *)&cmd_setbypass_mode_bypass,
3226                 (void *)&cmd_setbypass_mode_mode,
3227                 (void *)&cmd_setbypass_mode_value,
3228                 (void *)&cmd_setbypass_mode_port,
3229                 NULL,
3230         },
3231 };
3232
3233 /* *** SET NIC BYPASS EVENT *** */
3234 struct cmd_set_bypass_event_result {
3235         cmdline_fixed_string_t set;
3236         cmdline_fixed_string_t bypass;
3237         cmdline_fixed_string_t event;
3238         cmdline_fixed_string_t event_value;
3239         cmdline_fixed_string_t mode;
3240         cmdline_fixed_string_t mode_value;
3241         uint8_t port_id;
3242 };
3243
3244 static void
3245 cmd_set_bypass_event_parsed(void *parsed_result,
3246                 __attribute__((unused)) struct cmdline *cl,
3247                 __attribute__((unused)) void *data)
3248 {
3249         int32_t rc;
3250         struct cmd_set_bypass_event_result *res = parsed_result;
3251         portid_t port_id = res->port_id;
3252         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3253         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3254
3255         if (!bypass_is_supported(port_id))
3256                 return;
3257
3258         if (!strcmp(res->event_value, "timeout"))
3259                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3260         else if (!strcmp(res->event_value, "os_on"))
3261                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3262         else if (!strcmp(res->event_value, "os_off"))
3263                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3264         else if (!strcmp(res->event_value, "power_on"))
3265                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3266         else if (!strcmp(res->event_value, "power_off"))
3267                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3268         else
3269                 bypass_event = RTE_BYPASS_EVENT_NONE;
3270
3271         if (!strcmp(res->mode_value, "bypass"))
3272                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3273         else if (!strcmp(res->mode_value, "isolate"))
3274                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3275         else
3276                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3277
3278         /* Set the watchdog timeout. */
3279         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3280
3281                 rc = -EINVAL;
3282                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3283                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3284                                 bypass_timeout)) != 0) {
3285                         printf("Failed to set timeout value %u "
3286                                 "for port %d, errto code: %d.\n",
3287                                 bypass_timeout, port_id, rc);
3288                 }
3289         }
3290
3291         /* Set the bypass event to transition to bypass mode. */
3292         if (0 != rte_eth_dev_bypass_event_store(port_id,
3293                         bypass_event, bypass_mode)) {
3294                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3295         }
3296
3297 }
3298
3299 cmdline_parse_token_string_t cmd_setbypass_event_set =
3300         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3301                         set, "set");
3302 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3303         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3304                         bypass, "bypass");
3305 cmdline_parse_token_string_t cmd_setbypass_event_event =
3306         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3307                         event, "event");
3308 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3309         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3310                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3311 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3312         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3313                         mode, "mode");
3314 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3315         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3316                         mode_value, "normal#bypass#isolate");
3317 cmdline_parse_token_num_t cmd_setbypass_event_port =
3318         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3319                                 port_id, UINT8);
3320
3321 cmdline_parse_inst_t cmd_set_bypass_event = {
3322         .f = cmd_set_bypass_event_parsed,
3323         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3324                     "mode (normal|bypass|isolate) (port_id): "
3325                     "Set the NIC bypass event mode for port_id",
3326         .data = NULL,
3327         .tokens = {
3328                 (void *)&cmd_setbypass_event_set,
3329                 (void *)&cmd_setbypass_event_bypass,
3330                 (void *)&cmd_setbypass_event_event,
3331                 (void *)&cmd_setbypass_event_event_value,
3332                 (void *)&cmd_setbypass_event_mode,
3333                 (void *)&cmd_setbypass_event_mode_value,
3334                 (void *)&cmd_setbypass_event_port,
3335                 NULL,
3336         },
3337 };
3338
3339
3340 /* *** SET NIC BYPASS TIMEOUT *** */
3341 struct cmd_set_bypass_timeout_result {
3342         cmdline_fixed_string_t set;
3343         cmdline_fixed_string_t bypass;
3344         cmdline_fixed_string_t timeout;
3345         cmdline_fixed_string_t value;
3346 };
3347
3348 static void
3349 cmd_set_bypass_timeout_parsed(void *parsed_result,
3350                 __attribute__((unused)) struct cmdline *cl,
3351                 __attribute__((unused)) void *data)
3352 {
3353         struct cmd_set_bypass_timeout_result *res = parsed_result;
3354
3355         if (!strcmp(res->value, "1.5"))
3356                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3357         else if (!strcmp(res->value, "2"))
3358                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3359         else if (!strcmp(res->value, "3"))
3360                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3361         else if (!strcmp(res->value, "4"))
3362                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3363         else if (!strcmp(res->value, "8"))
3364                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3365         else if (!strcmp(res->value, "16"))
3366                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3367         else if (!strcmp(res->value, "32"))
3368                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3369         else
3370                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3371 }
3372
3373 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3374         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3375                         set, "set");
3376 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3377         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3378                         bypass, "bypass");
3379 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3380         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3381                         timeout, "timeout");
3382 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3383         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3384                         value, "0#1.5#2#3#4#8#16#32");
3385
3386 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3387         .f = cmd_set_bypass_timeout_parsed,
3388         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3389                     "Set the NIC bypass watchdog timeout",
3390         .data = NULL,
3391         .tokens = {
3392                 (void *)&cmd_setbypass_timeout_set,
3393                 (void *)&cmd_setbypass_timeout_bypass,
3394                 (void *)&cmd_setbypass_timeout_timeout,
3395                 (void *)&cmd_setbypass_timeout_value,
3396                 NULL,
3397         },
3398 };
3399
3400 /* *** SHOW NIC BYPASS MODE *** */
3401 struct cmd_show_bypass_config_result {
3402         cmdline_fixed_string_t show;
3403         cmdline_fixed_string_t bypass;
3404         cmdline_fixed_string_t config;
3405         uint8_t port_id;
3406 };
3407
3408 static void
3409 cmd_show_bypass_config_parsed(void *parsed_result,
3410                 __attribute__((unused)) struct cmdline *cl,
3411                 __attribute__((unused)) void *data)
3412 {
3413         struct cmd_show_bypass_config_result *res = parsed_result;
3414         uint32_t event_mode;
3415         uint32_t bypass_mode;
3416         portid_t port_id = res->port_id;
3417         uint32_t timeout = bypass_timeout;
3418         int i;
3419
3420         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3421                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3422         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3423                 {"UNKNOWN", "normal", "bypass", "isolate"};
3424         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3425                 "NONE",
3426                 "OS/board on",
3427                 "power supply on",
3428                 "OS/board off",
3429                 "power supply off",
3430                 "timeout"};
3431         int num_events = (sizeof events) / (sizeof events[0]);
3432
3433         if (!bypass_is_supported(port_id))
3434                 return;
3435
3436         /* Display the bypass mode.*/
3437         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3438                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3439                 return;
3440         }
3441         else {
3442                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3443                         bypass_mode = RTE_BYPASS_MODE_NONE;
3444
3445                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3446         }
3447
3448         /* Display the bypass timeout.*/
3449         if (!RTE_BYPASS_TMT_VALID(timeout))
3450                 timeout = RTE_BYPASS_TMT_OFF;
3451
3452         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3453
3454         /* Display the bypass events and associated modes. */
3455         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3456
3457                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3458                         printf("\tFailed to get bypass mode for event = %s\n",
3459                                 events[i]);
3460                 } else {
3461                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3462                                 event_mode = RTE_BYPASS_MODE_NONE;
3463
3464                         printf("\tbypass event: %-16s = %s\n", events[i],
3465                                 modes[event_mode]);
3466                 }
3467         }
3468 }
3469
3470 cmdline_parse_token_string_t cmd_showbypass_config_show =
3471         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3472                         show, "show");
3473 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3474         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3475                         bypass, "bypass");
3476 cmdline_parse_token_string_t cmd_showbypass_config_config =
3477         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3478                         config, "config");
3479 cmdline_parse_token_num_t cmd_showbypass_config_port =
3480         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3481                                 port_id, UINT8);
3482
3483 cmdline_parse_inst_t cmd_show_bypass_config = {
3484         .f = cmd_show_bypass_config_parsed,
3485         .help_str = "show bypass config (port_id): "
3486                     "Show the NIC bypass config for port_id",
3487         .data = NULL,
3488         .tokens = {
3489                 (void *)&cmd_showbypass_config_show,
3490                 (void *)&cmd_showbypass_config_bypass,
3491                 (void *)&cmd_showbypass_config_config,
3492                 (void *)&cmd_showbypass_config_port,
3493                 NULL,
3494         },
3495 };
3496 #endif
3497
3498 #ifdef RTE_LIBRTE_PMD_BOND
3499 /* *** SET BONDING MODE *** */
3500 struct cmd_set_bonding_mode_result {
3501         cmdline_fixed_string_t set;
3502         cmdline_fixed_string_t bonding;
3503         cmdline_fixed_string_t mode;
3504         uint8_t value;
3505         uint8_t port_id;
3506 };
3507
3508 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3509                 __attribute__((unused))  struct cmdline *cl,
3510                 __attribute__((unused)) void *data)
3511 {
3512         struct cmd_set_bonding_mode_result *res = parsed_result;
3513         portid_t port_id = res->port_id;
3514
3515         /* Set the bonding mode for the relevant port. */
3516         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3517                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3518 }
3519
3520 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3521 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3522                 set, "set");
3523 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3524 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3525                 bonding, "bonding");
3526 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3527 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3528                 mode, "mode");
3529 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3530 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3531                 value, UINT8);
3532 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3533 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3534                 port_id, UINT8);
3535
3536 cmdline_parse_inst_t cmd_set_bonding_mode = {
3537                 .f = cmd_set_bonding_mode_parsed,
3538                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3539                 .data = NULL,
3540                 .tokens = {
3541                                 (void *) &cmd_setbonding_mode_set,
3542                                 (void *) &cmd_setbonding_mode_bonding,
3543                                 (void *) &cmd_setbonding_mode_mode,
3544                                 (void *) &cmd_setbonding_mode_value,
3545                                 (void *) &cmd_setbonding_mode_port,
3546                                 NULL
3547                 }
3548 };
3549
3550 /* *** SET BALANCE XMIT POLICY *** */
3551 struct cmd_set_bonding_balance_xmit_policy_result {
3552         cmdline_fixed_string_t set;
3553         cmdline_fixed_string_t bonding;
3554         cmdline_fixed_string_t balance_xmit_policy;
3555         uint8_t port_id;
3556         cmdline_fixed_string_t policy;
3557 };
3558
3559 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3560                 __attribute__((unused))  struct cmdline *cl,
3561                 __attribute__((unused)) void *data)
3562 {
3563         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3564         portid_t port_id = res->port_id;
3565         uint8_t policy;
3566
3567         if (!strcmp(res->policy, "l2")) {
3568                 policy = BALANCE_XMIT_POLICY_LAYER2;
3569         } else if (!strcmp(res->policy, "l23")) {
3570                 policy = BALANCE_XMIT_POLICY_LAYER23;
3571         } else if (!strcmp(res->policy, "l34")) {
3572                 policy = BALANCE_XMIT_POLICY_LAYER34;
3573         } else {
3574                 printf("\t Invalid xmit policy selection");
3575                 return;
3576         }
3577
3578         /* Set the bonding mode for the relevant port. */
3579         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3580                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3581                                 port_id);
3582         }
3583 }
3584
3585 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3586 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3587                 set, "set");
3588 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3589 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3590                 bonding, "bonding");
3591 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3592 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3593                 balance_xmit_policy, "balance_xmit_policy");
3594 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3595 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3596                 port_id, UINT8);
3597 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3598 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3599                 policy, "l2#l23#l34");
3600
3601 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3602                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3603                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3604                 .data = NULL,
3605                 .tokens = {
3606                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3607                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3608                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3609                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3610                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3611                                 NULL
3612                 }
3613 };
3614
3615 /* *** SHOW NIC BONDING CONFIGURATION *** */
3616 struct cmd_show_bonding_config_result {
3617         cmdline_fixed_string_t show;
3618         cmdline_fixed_string_t bonding;
3619         cmdline_fixed_string_t config;
3620         uint8_t port_id;
3621 };
3622
3623 static void cmd_show_bonding_config_parsed(void *parsed_result,
3624                 __attribute__((unused))  struct cmdline *cl,
3625                 __attribute__((unused)) void *data)
3626 {
3627         struct cmd_show_bonding_config_result *res = parsed_result;
3628         int bonding_mode;
3629         uint8_t slaves[RTE_MAX_ETHPORTS];
3630         int num_slaves, num_active_slaves;
3631         int primary_id;
3632         int i;
3633         portid_t port_id = res->port_id;
3634
3635         /* Display the bonding mode.*/
3636         bonding_mode = rte_eth_bond_mode_get(port_id);
3637         if (bonding_mode < 0) {
3638                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3639                 return;
3640         } else
3641                 printf("\tBonding mode: %d\n", bonding_mode);
3642
3643         if (bonding_mode == BONDING_MODE_BALANCE) {
3644                 int balance_xmit_policy;
3645
3646                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3647                 if (balance_xmit_policy < 0) {
3648                         printf("\tFailed to get balance xmit policy for port = %d\n",
3649                                         port_id);
3650                         return;
3651                 } else {
3652                         printf("\tBalance Xmit Policy: ");
3653
3654                         switch (balance_xmit_policy) {
3655                         case BALANCE_XMIT_POLICY_LAYER2:
3656                                 printf("BALANCE_XMIT_POLICY_LAYER2");
3657                                 break;
3658                         case BALANCE_XMIT_POLICY_LAYER23:
3659                                 printf("BALANCE_XMIT_POLICY_LAYER23");
3660                                 break;
3661                         case BALANCE_XMIT_POLICY_LAYER34:
3662                                 printf("BALANCE_XMIT_POLICY_LAYER34");
3663                                 break;
3664                         }
3665                         printf("\n");
3666                 }
3667         }
3668
3669         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
3670
3671         if (num_slaves < 0) {
3672                 printf("\tFailed to get slave list for port = %d\n", port_id);
3673                 return;
3674         }
3675         if (num_slaves > 0) {
3676                 printf("\tSlaves (%d): [", num_slaves);
3677                 for (i = 0; i < num_slaves - 1; i++)
3678                         printf("%d ", slaves[i]);
3679
3680                 printf("%d]\n", slaves[num_slaves - 1]);
3681         } else {
3682                 printf("\tSlaves: []\n");
3683
3684         }
3685
3686         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
3687                         RTE_MAX_ETHPORTS);
3688
3689         if (num_active_slaves < 0) {
3690                 printf("\tFailed to get active slave list for port = %d\n", port_id);
3691                 return;
3692         }
3693         if (num_active_slaves > 0) {
3694                 printf("\tActive Slaves (%d): [", num_active_slaves);
3695                 for (i = 0; i < num_active_slaves - 1; i++)
3696                         printf("%d ", slaves[i]);
3697
3698                 printf("%d]\n", slaves[num_active_slaves - 1]);
3699
3700         } else {
3701                 printf("\tActive Slaves: []\n");
3702
3703         }
3704
3705         primary_id = rte_eth_bond_primary_get(port_id);
3706         if (primary_id < 0) {
3707                 printf("\tFailed to get primary slave for port = %d\n", port_id);
3708                 return;
3709         } else
3710                 printf("\tPrimary: [%d]\n", primary_id);
3711
3712 }
3713
3714 cmdline_parse_token_string_t cmd_showbonding_config_show =
3715 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3716                 show, "show");
3717 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
3718 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3719                 bonding, "bonding");
3720 cmdline_parse_token_string_t cmd_showbonding_config_config =
3721 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3722                 config, "config");
3723 cmdline_parse_token_num_t cmd_showbonding_config_port =
3724 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
3725                 port_id, UINT8);
3726
3727 cmdline_parse_inst_t cmd_show_bonding_config = {
3728                 .f = cmd_show_bonding_config_parsed,
3729                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
3730                 .data = NULL,
3731                 .tokens = {
3732                                 (void *)&cmd_showbonding_config_show,
3733                                 (void *)&cmd_showbonding_config_bonding,
3734                                 (void *)&cmd_showbonding_config_config,
3735                                 (void *)&cmd_showbonding_config_port,
3736                                 NULL
3737                 }
3738 };
3739
3740 /* *** SET BONDING PRIMARY *** */
3741 struct cmd_set_bonding_primary_result {
3742         cmdline_fixed_string_t set;
3743         cmdline_fixed_string_t bonding;
3744         cmdline_fixed_string_t primary;
3745         uint8_t slave_id;
3746         uint8_t port_id;
3747 };
3748
3749 static void cmd_set_bonding_primary_parsed(void *parsed_result,
3750                 __attribute__((unused))  struct cmdline *cl,
3751                 __attribute__((unused)) void *data)
3752 {
3753         struct cmd_set_bonding_primary_result *res = parsed_result;
3754         portid_t master_port_id = res->port_id;
3755         portid_t slave_port_id = res->slave_id;
3756
3757         /* Set the primary slave for a bonded device. */
3758         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
3759                 printf("\t Failed to set primary slave for port = %d.\n",
3760                                 master_port_id);
3761                 return;
3762         }
3763         init_port_config();
3764 }
3765
3766 cmdline_parse_token_string_t cmd_setbonding_primary_set =
3767 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3768                 set, "set");
3769 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
3770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3771                 bonding, "bonding");
3772 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
3773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3774                 primary, "primary");
3775 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
3776 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3777                 slave_id, UINT8);
3778 cmdline_parse_token_num_t cmd_setbonding_primary_port =
3779 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3780                 port_id, UINT8);
3781
3782 cmdline_parse_inst_t cmd_set_bonding_primary = {
3783                 .f = cmd_set_bonding_primary_parsed,
3784                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
3785                 .data = NULL,
3786                 .tokens = {
3787                                 (void *)&cmd_setbonding_primary_set,
3788                                 (void *)&cmd_setbonding_primary_bonding,
3789                                 (void *)&cmd_setbonding_primary_primary,
3790                                 (void *)&cmd_setbonding_primary_slave,
3791                                 (void *)&cmd_setbonding_primary_port,
3792                                 NULL
3793                 }
3794 };
3795
3796 /* *** ADD SLAVE *** */
3797 struct cmd_add_bonding_slave_result {
3798         cmdline_fixed_string_t add;
3799         cmdline_fixed_string_t bonding;
3800         cmdline_fixed_string_t slave;
3801         uint8_t slave_id;
3802         uint8_t port_id;
3803 };
3804
3805 static void cmd_add_bonding_slave_parsed(void *parsed_result,
3806                 __attribute__((unused))  struct cmdline *cl,
3807                 __attribute__((unused)) void *data)
3808 {
3809         struct cmd_add_bonding_slave_result *res = parsed_result;
3810         portid_t master_port_id = res->port_id;
3811         portid_t slave_port_id = res->slave_id;
3812
3813         /* Set the primary slave for a bonded device. */
3814         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
3815                 printf("\t Failed to add slave %d to master port = %d.\n",
3816                                 slave_port_id, master_port_id);
3817                 return;
3818         }
3819         init_port_config();
3820 }
3821
3822 cmdline_parse_token_string_t cmd_addbonding_slave_add =
3823 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3824                 add, "add");
3825 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
3826 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3827                 bonding, "bonding");
3828 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
3829 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3830                 slave, "slave");
3831 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
3832 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
3833                 slave_id, UINT8);
3834 cmdline_parse_token_num_t cmd_addbonding_slave_port =
3835 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
3836                 port_id, UINT8);
3837
3838 cmdline_parse_inst_t cmd_add_bonding_slave = {
3839                 .f = cmd_add_bonding_slave_parsed,
3840                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
3841                 .data = NULL,
3842                 .tokens = {
3843                                 (void *)&cmd_addbonding_slave_add,
3844                                 (void *)&cmd_addbonding_slave_bonding,
3845                                 (void *)&cmd_addbonding_slave_slave,
3846                                 (void *)&cmd_addbonding_slave_slaveid,
3847                                 (void *)&cmd_addbonding_slave_port,
3848                                 NULL
3849                 }
3850 };
3851
3852 /* *** REMOVE SLAVE *** */
3853 struct cmd_remove_bonding_slave_result {
3854         cmdline_fixed_string_t remove;
3855         cmdline_fixed_string_t bonding;
3856         cmdline_fixed_string_t slave;
3857         uint8_t slave_id;
3858         uint8_t port_id;
3859 };
3860
3861 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
3862                 __attribute__((unused))  struct cmdline *cl,
3863                 __attribute__((unused)) void *data)
3864 {
3865         struct cmd_remove_bonding_slave_result *res = parsed_result;
3866         portid_t master_port_id = res->port_id;
3867         portid_t slave_port_id = res->slave_id;
3868
3869         /* Set the primary slave for a bonded device. */
3870         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
3871                 printf("\t Failed to remove slave %d from master port = %d.\n",
3872                                 slave_port_id, master_port_id);
3873                 return;
3874         }
3875         init_port_config();
3876 }
3877
3878 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
3879                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3880                                 remove, "remove");
3881 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
3882                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3883                                 bonding, "bonding");
3884 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
3885                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3886                                 slave, "slave");
3887 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
3888                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
3889                                 slave_id, UINT8);
3890 cmdline_parse_token_num_t cmd_removebonding_slave_port =
3891                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
3892                                 port_id, UINT8);
3893
3894 cmdline_parse_inst_t cmd_remove_bonding_slave = {
3895                 .f = cmd_remove_bonding_slave_parsed,
3896                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
3897                 .data = NULL,
3898                 .tokens = {
3899                                 (void *)&cmd_removebonding_slave_remove,
3900                                 (void *)&cmd_removebonding_slave_bonding,
3901                                 (void *)&cmd_removebonding_slave_slave,
3902                                 (void *)&cmd_removebonding_slave_slaveid,
3903                                 (void *)&cmd_removebonding_slave_port,
3904                                 NULL
3905                 }
3906 };
3907
3908 /* *** CREATE BONDED DEVICE *** */
3909 struct cmd_create_bonded_device_result {
3910         cmdline_fixed_string_t create;
3911         cmdline_fixed_string_t bonded;
3912         cmdline_fixed_string_t device;
3913         uint8_t mode;
3914         uint8_t socket;
3915 };
3916
3917 static int bond_dev_num = 0;
3918
3919 static void cmd_create_bonded_device_parsed(void *parsed_result,
3920                 __attribute__((unused))  struct cmdline *cl,
3921                 __attribute__((unused)) void *data)
3922 {
3923         struct cmd_create_bonded_device_result *res = parsed_result;
3924         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
3925         int port_id;
3926
3927         if (test_done == 0) {
3928                 printf("Please stop forwarding first\n");
3929                 return;
3930         }
3931
3932         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
3933                         bond_dev_num++);
3934
3935         /* Create a new bonded device. */
3936         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
3937         if (port_id < 0) {
3938                 printf("\t Failed to create bonded device.\n");
3939                 return;
3940         } else {
3941                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
3942                                 port_id);
3943
3944                 /* Update number of ports */
3945                 nb_ports = rte_eth_dev_count();
3946                 reconfig(port_id, res->socket);
3947                 rte_eth_promiscuous_enable(port_id);
3948         }
3949
3950 }
3951
3952 cmdline_parse_token_string_t cmd_createbonded_device_create =
3953                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3954                                 create, "create");
3955 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
3956                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3957                                 bonded, "bonded");
3958 cmdline_parse_token_string_t cmd_createbonded_device_device =
3959                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3960                                 device, "device");
3961 cmdline_parse_token_num_t cmd_createbonded_device_mode =
3962                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
3963                                 mode, UINT8);
3964 cmdline_parse_token_num_t cmd_createbonded_device_socket =
3965                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
3966                                 socket, UINT8);
3967
3968 cmdline_parse_inst_t cmd_create_bonded_device = {
3969                 .f = cmd_create_bonded_device_parsed,
3970                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
3971                 .data = NULL,
3972                 .tokens = {
3973                                 (void *)&cmd_createbonded_device_create,
3974                                 (void *)&cmd_createbonded_device_bonded,
3975                                 (void *)&cmd_createbonded_device_device,
3976                                 (void *)&cmd_createbonded_device_mode,
3977                                 (void *)&cmd_createbonded_device_socket,
3978                                 NULL
3979                 }
3980 };
3981
3982 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
3983 struct cmd_set_bond_mac_addr_result {
3984         cmdline_fixed_string_t set;
3985         cmdline_fixed_string_t bonding;
3986         cmdline_fixed_string_t mac_addr;
3987         uint8_t port_num;
3988         struct ether_addr address;
3989 };
3990
3991 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
3992                 __attribute__((unused))  struct cmdline *cl,
3993                 __attribute__((unused)) void *data)
3994 {
3995         struct cmd_set_bond_mac_addr_result *res = parsed_result;
3996         int ret;
3997
3998         if (res->port_num >= nb_ports) {
3999                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4000                 return;
4001         }
4002
4003         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4004
4005         /* check the return value and print it if is < 0 */
4006         if (ret < 0)
4007                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4008 }
4009
4010 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4011                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4012 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4013                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4014                                 "bonding");
4015 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4016                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4017                                 "mac_addr");
4018 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4019                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4020 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4021                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4022
4023 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4024                 .f = cmd_set_bond_mac_addr_parsed,
4025                 .data = (void *) 0,
4026                 .help_str = "set bonding mac_addr (port_id) (address): ",
4027                 .tokens = {
4028                                 (void *)&cmd_set_bond_mac_addr_set,
4029                                 (void *)&cmd_set_bond_mac_addr_bonding,
4030                                 (void *)&cmd_set_bond_mac_addr_mac,
4031                                 (void *)&cmd_set_bond_mac_addr_portnum,
4032                                 (void *)&cmd_set_bond_mac_addr_addr,
4033                                 NULL
4034                 }
4035 };
4036
4037
4038 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4039 struct cmd_set_bond_mon_period_result {
4040         cmdline_fixed_string_t set;
4041         cmdline_fixed_string_t bonding;
4042         cmdline_fixed_string_t mon_period;
4043         uint8_t port_num;
4044         uint32_t period_ms;
4045 };
4046
4047 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4048                 __attribute__((unused))  struct cmdline *cl,
4049                 __attribute__((unused)) void *data)
4050 {
4051         struct cmd_set_bond_mon_period_result *res = parsed_result;
4052         int ret;
4053
4054         if (res->port_num >= nb_ports) {
4055                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4056                 return;
4057         }
4058
4059         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4060
4061         /* check the return value and print it if is < 0 */
4062         if (ret < 0)
4063                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4064 }
4065
4066 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4067                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4068                                 set, "set");
4069 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4070                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4071                                 bonding, "bonding");
4072 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4073                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4074                                 mon_period,     "mon_period");
4075 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4076                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4077                                 port_num, UINT8);
4078 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4079                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4080                                 period_ms, UINT32);
4081
4082 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4083                 .f = cmd_set_bond_mon_period_parsed,
4084                 .data = (void *) 0,
4085                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4086                 .tokens = {
4087                                 (void *)&cmd_set_bond_mon_period_set,
4088                                 (void *)&cmd_set_bond_mon_period_bonding,
4089                                 (void *)&cmd_set_bond_mon_period_mon_period,
4090                                 (void *)&cmd_set_bond_mon_period_portnum,
4091                                 (void *)&cmd_set_bond_mon_period_period_ms,
4092                                 NULL
4093                 }
4094 };
4095
4096 #endif /* RTE_LIBRTE_PMD_BOND */
4097
4098 /* *** SET FORWARDING MODE *** */
4099 struct cmd_set_fwd_mode_result {
4100         cmdline_fixed_string_t set;
4101         cmdline_fixed_string_t fwd;
4102         cmdline_fixed_string_t mode;
4103 };
4104
4105 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4106                                     __attribute__((unused)) struct cmdline *cl,
4107                                     __attribute__((unused)) void *data)
4108 {
4109         struct cmd_set_fwd_mode_result *res = parsed_result;
4110
4111         set_pkt_forwarding_mode(res->mode);
4112 }
4113
4114 cmdline_parse_token_string_t cmd_setfwd_set =
4115         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4116 cmdline_parse_token_string_t cmd_setfwd_fwd =
4117         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4118 cmdline_parse_token_string_t cmd_setfwd_mode =
4119         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4120                 "" /* defined at init */);
4121
4122 cmdline_parse_inst_t cmd_set_fwd_mode = {
4123         .f = cmd_set_fwd_mode_parsed,
4124         .data = NULL,
4125         .help_str = NULL, /* defined at init */
4126         .tokens = {
4127                 (void *)&cmd_setfwd_set,
4128                 (void *)&cmd_setfwd_fwd,
4129                 (void *)&cmd_setfwd_mode,
4130                 NULL,
4131         },
4132 };
4133
4134 static void cmd_set_fwd_mode_init(void)
4135 {
4136         char *modes, *c;
4137         static char token[128];
4138         static char help[256];
4139         cmdline_parse_token_string_t *token_struct;
4140
4141         modes = list_pkt_forwarding_modes();
4142         snprintf(help, sizeof help, "set fwd %s - "
4143                 "set packet forwarding mode", modes);
4144         cmd_set_fwd_mode.help_str = help;
4145
4146         /* string token separator is # */
4147         for (c = token; *modes != '\0'; modes++)
4148                 if (*modes == '|')
4149                         *c++ = '#';
4150                 else
4151                         *c++ = *modes;
4152         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4153         token_struct->string_data.str = token;
4154 }
4155
4156 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4157 struct cmd_set_burst_tx_retry_result {
4158         cmdline_fixed_string_t set;
4159         cmdline_fixed_string_t burst;
4160         cmdline_fixed_string_t tx;
4161         cmdline_fixed_string_t delay;
4162         uint32_t time;
4163         cmdline_fixed_string_t retry;
4164         uint32_t retry_num;
4165 };
4166
4167 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4168                                         __attribute__((unused)) struct cmdline *cl,
4169                                         __attribute__((unused)) void *data)
4170 {
4171         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4172
4173         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4174                 && !strcmp(res->tx, "tx")) {
4175                 if (!strcmp(res->delay, "delay"))
4176                         burst_tx_delay_time = res->time;
4177                 if (!strcmp(res->retry, "retry"))
4178                         burst_tx_retry_num = res->retry_num;
4179         }
4180
4181 }
4182
4183 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4184         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4185 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4186         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4187                                  "burst");
4188 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4189         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4190 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4191         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4192 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4193         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4194 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4195         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4196 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4197         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4198
4199 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4200         .f = cmd_set_burst_tx_retry_parsed,
4201         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4202         .tokens = {
4203                 (void *)&cmd_set_burst_tx_retry_set,
4204                 (void *)&cmd_set_burst_tx_retry_burst,
4205                 (void *)&cmd_set_burst_tx_retry_tx,
4206                 (void *)&cmd_set_burst_tx_retry_delay,
4207                 (void *)&cmd_set_burst_tx_retry_time,
4208                 (void *)&cmd_set_burst_tx_retry_retry,
4209                 (void *)&cmd_set_burst_tx_retry_retry_num,
4210                 NULL,
4211         },
4212 };
4213
4214 /* *** SET PROMISC MODE *** */
4215 struct cmd_set_promisc_mode_result {
4216         cmdline_fixed_string_t set;
4217         cmdline_fixed_string_t promisc;
4218         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4219         uint8_t port_num;                /* valid if "allports" argument == 0 */
4220         cmdline_fixed_string_t mode;
4221 };
4222
4223 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4224                                         __attribute__((unused)) struct cmdline *cl,
4225                                         void *allports)
4226 {
4227         struct cmd_set_promisc_mode_result *res = parsed_result;
4228         int enable;
4229         portid_t i;
4230
4231         if (!strcmp(res->mode, "on"))
4232                 enable = 1;
4233         else
4234                 enable = 0;
4235
4236         /* all ports */
4237         if (allports) {
4238                 for (i = 0; i < nb_ports; i++) {
4239                         if (enable)
4240                                 rte_eth_promiscuous_enable(i);
4241                         else
4242                                 rte_eth_promiscuous_disable(i);
4243                 }
4244         }
4245         else {
4246                 if (enable)
4247                         rte_eth_promiscuous_enable(res->port_num);
4248                 else
4249                         rte_eth_promiscuous_disable(res->port_num);
4250         }
4251 }
4252
4253 cmdline_parse_token_string_t cmd_setpromisc_set =
4254         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4255 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4256         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4257                                  "promisc");
4258 cmdline_parse_token_string_t cmd_setpromisc_portall =
4259         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4260                                  "all");
4261 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4262         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4263                               UINT8);
4264 cmdline_parse_token_string_t cmd_setpromisc_mode =
4265         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4266                                  "on#off");
4267
4268 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4269         .f = cmd_set_promisc_mode_parsed,
4270         .data = (void *)1,
4271         .help_str = "set promisc all on|off: set promisc mode for all ports",
4272         .tokens = {
4273                 (void *)&cmd_setpromisc_set,
4274                 (void *)&cmd_setpromisc_promisc,
4275                 (void *)&cmd_setpromisc_portall,
4276                 (void *)&cmd_setpromisc_mode,
4277                 NULL,
4278         },
4279 };
4280
4281 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4282         .f = cmd_set_promisc_mode_parsed,
4283         .data = (void *)0,
4284         .help_str = "set promisc X on|off: set promisc mode on port X",
4285         .tokens = {
4286                 (void *)&cmd_setpromisc_set,
4287                 (void *)&cmd_setpromisc_promisc,
4288                 (void *)&cmd_setpromisc_portnum,
4289                 (void *)&cmd_setpromisc_mode,
4290                 NULL,
4291         },
4292 };
4293
4294 /* *** SET ALLMULTI MODE *** */
4295 struct cmd_set_allmulti_mode_result {
4296         cmdline_fixed_string_t set;
4297         cmdline_fixed_string_t allmulti;
4298         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4299         uint8_t port_num;                /* valid if "allports" argument == 0 */
4300         cmdline_fixed_string_t mode;
4301 };
4302
4303 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4304                                         __attribute__((unused)) struct cmdline *cl,
4305                                         void *allports)
4306 {
4307         struct cmd_set_allmulti_mode_result *res = parsed_result;
4308         int enable;
4309         portid_t i;
4310
4311         if (!strcmp(res->mode, "on"))
4312                 enable = 1;
4313         else
4314                 enable = 0;
4315
4316         /* all ports */
4317         if (allports) {
4318                 for (i = 0; i < nb_ports; i++) {
4319                         if (enable)
4320                                 rte_eth_allmulticast_enable(i);
4321                         else
4322                                 rte_eth_allmulticast_disable(i);
4323                 }
4324         }
4325         else {
4326                 if (enable)
4327                         rte_eth_allmulticast_enable(res->port_num);
4328                 else
4329                         rte_eth_allmulticast_disable(res->port_num);
4330         }
4331 }
4332
4333 cmdline_parse_token_string_t cmd_setallmulti_set =
4334         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4335 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4336         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4337                                  "allmulti");
4338 cmdline_parse_token_string_t cmd_setallmulti_portall =
4339         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4340                                  "all");
4341 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4342         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4343                               UINT8);
4344 cmdline_parse_token_string_t cmd_setallmulti_mode =
4345         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4346                                  "on#off");
4347
4348 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4349         .f = cmd_set_allmulti_mode_parsed,
4350         .data = (void *)1,
4351         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4352         .tokens = {
4353                 (void *)&cmd_setallmulti_set,
4354                 (void *)&cmd_setallmulti_allmulti,
4355                 (void *)&cmd_setallmulti_portall,
4356                 (void *)&cmd_setallmulti_mode,
4357                 NULL,
4358         },
4359 };
4360
4361 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4362         .f = cmd_set_allmulti_mode_parsed,
4363         .data = (void *)0,
4364         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4365         .tokens = {
4366                 (void *)&cmd_setallmulti_set,
4367                 (void *)&cmd_setallmulti_allmulti,
4368                 (void *)&cmd_setallmulti_portnum,
4369                 (void *)&cmd_setallmulti_mode,
4370                 NULL,
4371         },
4372 };
4373
4374 /* *** ADD/REMOVE A PKT FILTER *** */
4375 struct cmd_pkt_filter_result {
4376         cmdline_fixed_string_t pkt_filter;
4377         uint8_t  port_id;
4378         cmdline_fixed_string_t protocol;
4379         cmdline_fixed_string_t src;
4380         cmdline_ipaddr_t ip_src;
4381         uint16_t port_src;
4382         cmdline_fixed_string_t dst;
4383         cmdline_ipaddr_t ip_dst;
4384         uint16_t port_dst;
4385         cmdline_fixed_string_t flexbytes;
4386         uint16_t flexbytes_value;
4387         cmdline_fixed_string_t vlan;
4388         uint16_t  vlan_id;
4389         cmdline_fixed_string_t queue;
4390         int8_t  queue_id;
4391         cmdline_fixed_string_t soft;
4392         uint8_t  soft_id;
4393 };
4394
4395 static void
4396 cmd_pkt_filter_parsed(void *parsed_result,
4397                           __attribute__((unused)) struct cmdline *cl,
4398                           __attribute__((unused)) void *data)
4399 {
4400         struct rte_fdir_filter fdir_filter;
4401         struct cmd_pkt_filter_result *res = parsed_result;
4402
4403         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
4404
4405         if (res->ip_src.family == AF_INET)
4406                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
4407         else
4408                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
4409                        &(res->ip_src.addr.ipv6),
4410                        sizeof(struct in6_addr));
4411
4412         if (res->ip_dst.family == AF_INET)
4413                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
4414         else
4415                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
4416                        &(res->ip_dst.addr.ipv6),
4417                        sizeof(struct in6_addr));
4418
4419         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
4420         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
4421
4422         if (!strcmp(res->protocol, "udp"))
4423                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
4424         else if (!strcmp(res->protocol, "tcp"))
4425                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
4426         else if (!strcmp(res->protocol, "sctp"))
4427                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
4428         else /* default only IP */
4429                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
4430
4431         if (res->ip_dst.family == AF_INET6)
4432                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
4433         else
4434                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
4435
4436         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
4437         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
4438
4439         if (!strcmp(res->pkt_filter, "add_signature_filter"))
4440                 fdir_add_signature_filter(res->port_id, res->queue_id,
4441                                           &fdir_filter);
4442         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
4443                 fdir_update_signature_filter(res->port_id, res->queue_id,
4444                                              &fdir_filter);
4445         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
4446                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
4447         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
4448                 fdir_add_perfect_filter(res->port_id, res->soft_id,
4449                                         res->queue_id,
4450                                         (uint8_t) (res->queue_id < 0),
4451                                         &fdir_filter);
4452         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
4453                 fdir_update_perfect_filter(res->port_id, res->soft_id,
4454                                            res->queue_id,
4455                                            (uint8_t) (res->queue_id < 0),
4456                                            &fdir_filter);
4457         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
4458                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
4459                                            &fdir_filter);
4460
4461 }
4462
4463
4464 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
4465         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4466                               port_id, UINT8);
4467 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
4468         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4469                                  protocol, "ip#tcp#udp#sctp");
4470 cmdline_parse_token_string_t cmd_pkt_filter_src =
4471         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4472                                  src, "src");
4473 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
4474         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
4475                                  ip_src);
4476 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
4477         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4478                               port_src, UINT16);
4479 cmdline_parse_token_string_t cmd_pkt_filter_dst =
4480         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4481                                  dst, "dst");
4482 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
4483         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
4484                                  ip_dst);
4485 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
4486         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4487                               port_dst, UINT16);
4488 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
4489         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4490                                  flexbytes, "flexbytes");
4491 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
4492         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4493                               flexbytes_value, UINT16);
4494 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
4495         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4496                                  vlan, "vlan");
4497 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
4498         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4499                               vlan_id, UINT16);
4500 cmdline_parse_token_string_t cmd_pkt_filter_queue =
4501         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4502                                  queue, "queue");
4503 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
4504         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4505                               queue_id, INT8);
4506 cmdline_parse_token_string_t cmd_pkt_filter_soft =
4507         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4508                                  soft, "soft");
4509 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
4510         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4511                               soft_id, UINT16);
4512
4513
4514 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
4515         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4516                                  pkt_filter, "add_signature_filter");
4517 cmdline_parse_inst_t cmd_add_signature_filter = {
4518         .f = cmd_pkt_filter_parsed,
4519         .data = NULL,
4520         .help_str = "add a signature filter",
4521         .tokens = {
4522                 (void *)&cmd_pkt_filter_add_signature_filter,
4523                 (void *)&cmd_pkt_filter_port_id,
4524                 (void *)&cmd_pkt_filter_protocol,
4525                 (void *)&cmd_pkt_filter_src,
4526                 (void *)&cmd_pkt_filter_ip_src,
4527                 (void *)&cmd_pkt_filter_port_src,
4528                 (void *)&cmd_pkt_filter_dst,
4529                 (void *)&cmd_pkt_filter_ip_dst,
4530                 (void *)&cmd_pkt_filter_port_dst,
4531                 (void *)&cmd_pkt_filter_flexbytes,
4532                 (void *)&cmd_pkt_filter_flexbytes_value,
4533                 (void *)&cmd_pkt_filter_vlan,
4534                 (void *)&cmd_pkt_filter_vlan_id,
4535                 (void *)&cmd_pkt_filter_queue,
4536                 (void *)&cmd_pkt_filter_queue_id,
4537                 NULL,
4538         },
4539 };
4540
4541
4542 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
4543         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4544                                  pkt_filter, "upd_signature_filter");
4545 cmdline_parse_inst_t cmd_upd_signature_filter = {
4546         .f = cmd_pkt_filter_parsed,
4547         .data = NULL,
4548         .help_str = "update a signature filter",
4549         .tokens = {
4550                 (void *)&cmd_pkt_filter_upd_signature_filter,
4551                 (void *)&cmd_pkt_filter_port_id,
4552                 (void *)&cmd_pkt_filter_protocol,
4553                 (void *)&cmd_pkt_filter_src,
4554                 (void *)&cmd_pkt_filter_ip_src,
4555                 (void *)&cmd_pkt_filter_port_src,
4556                 (void *)&cmd_pkt_filter_dst,
4557                 (void *)&cmd_pkt_filter_ip_dst,
4558                 (void *)&cmd_pkt_filter_port_dst,
4559                 (void *)&cmd_pkt_filter_flexbytes,
4560                 (void *)&cmd_pkt_filter_flexbytes_value,
4561                 (void *)&cmd_pkt_filter_vlan,
4562                 (void *)&cmd_pkt_filter_vlan_id,
4563                 (void *)&cmd_pkt_filter_queue,
4564                 (void *)&cmd_pkt_filter_queue_id,
4565                 NULL,
4566         },
4567 };
4568
4569
4570 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
4571         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4572                                  pkt_filter, "rm_signature_filter");
4573 cmdline_parse_inst_t cmd_rm_signature_filter = {
4574         .f = cmd_pkt_filter_parsed,
4575         .data = NULL,
4576         .help_str = "remove a signature filter",
4577         .tokens = {
4578                 (void *)&cmd_pkt_filter_rm_signature_filter,
4579                 (void *)&cmd_pkt_filter_port_id,
4580                 (void *)&cmd_pkt_filter_protocol,
4581                 (void *)&cmd_pkt_filter_src,
4582                 (void *)&cmd_pkt_filter_ip_src,
4583                 (void *)&cmd_pkt_filter_port_src,
4584                 (void *)&cmd_pkt_filter_dst,
4585                 (void *)&cmd_pkt_filter_ip_dst,
4586                 (void *)&cmd_pkt_filter_port_dst,
4587                 (void *)&cmd_pkt_filter_flexbytes,
4588                 (void *)&cmd_pkt_filter_flexbytes_value,
4589                 (void *)&cmd_pkt_filter_vlan,
4590                 (void *)&cmd_pkt_filter_vlan_id,
4591                 NULL
4592                 },
4593 };
4594
4595
4596 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
4597         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4598                                  pkt_filter, "add_perfect_filter");
4599 cmdline_parse_inst_t cmd_add_perfect_filter = {
4600         .f = cmd_pkt_filter_parsed,
4601         .data = NULL,
4602         .help_str = "add a perfect filter",
4603         .tokens = {
4604                 (void *)&cmd_pkt_filter_add_perfect_filter,
4605                 (void *)&cmd_pkt_filter_port_id,
4606                 (void *)&cmd_pkt_filter_protocol,
4607                 (void *)&cmd_pkt_filter_src,
4608                 (void *)&cmd_pkt_filter_ip_src,
4609                 (void *)&cmd_pkt_filter_port_src,
4610                 (void *)&cmd_pkt_filter_dst,
4611                 (void *)&cmd_pkt_filter_ip_dst,
4612                 (void *)&cmd_pkt_filter_port_dst,
4613                 (void *)&cmd_pkt_filter_flexbytes,
4614                 (void *)&cmd_pkt_filter_flexbytes_value,
4615                 (void *)&cmd_pkt_filter_vlan,
4616                 (void *)&cmd_pkt_filter_vlan_id,
4617                 (void *)&cmd_pkt_filter_queue,
4618                 (void *)&cmd_pkt_filter_queue_id,
4619                 (void *)&cmd_pkt_filter_soft,
4620                 (void *)&cmd_pkt_filter_soft_id,
4621                 NULL,
4622         },
4623 };
4624
4625
4626 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
4627         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4628                                  pkt_filter, "upd_perfect_filter");
4629 cmdline_parse_inst_t cmd_upd_perfect_filter = {
4630         .f = cmd_pkt_filter_parsed,
4631         .data = NULL,
4632         .help_str = "update a perfect filter",
4633         .tokens = {
4634                 (void *)&cmd_pkt_filter_upd_perfect_filter,
4635                 (void *)&cmd_pkt_filter_port_id,
4636                 (void *)&cmd_pkt_filter_protocol,
4637                 (void *)&cmd_pkt_filter_src,
4638                 (void *)&cmd_pkt_filter_ip_src,
4639                 (void *)&cmd_pkt_filter_port_src,
4640                 (void *)&cmd_pkt_filter_dst,
4641                 (void *)&cmd_pkt_filter_ip_dst,
4642                 (void *)&cmd_pkt_filter_port_dst,
4643                 (void *)&cmd_pkt_filter_flexbytes,
4644                 (void *)&cmd_pkt_filter_flexbytes_value,
4645                 (void *)&cmd_pkt_filter_vlan,
4646                 (void *)&cmd_pkt_filter_vlan_id,
4647                 (void *)&cmd_pkt_filter_queue,
4648                 (void *)&cmd_pkt_filter_queue_id,
4649                 (void *)&cmd_pkt_filter_soft,
4650                 (void *)&cmd_pkt_filter_soft_id,
4651                 NULL,
4652         },
4653 };
4654
4655
4656 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
4657         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4658                                  pkt_filter, "rm_perfect_filter");
4659 cmdline_parse_inst_t cmd_rm_perfect_filter = {
4660         .f = cmd_pkt_filter_parsed,
4661         .data = NULL,
4662         .help_str = "remove a perfect filter",
4663         .tokens = {
4664                 (void *)&cmd_pkt_filter_rm_perfect_filter,
4665                 (void *)&cmd_pkt_filter_port_id,
4666                 (void *)&cmd_pkt_filter_protocol,
4667                 (void *)&cmd_pkt_filter_src,
4668                 (void *)&cmd_pkt_filter_ip_src,
4669                 (void *)&cmd_pkt_filter_port_src,
4670                 (void *)&cmd_pkt_filter_dst,
4671                 (void *)&cmd_pkt_filter_ip_dst,
4672                 (void *)&cmd_pkt_filter_port_dst,
4673                 (void *)&cmd_pkt_filter_flexbytes,
4674                 (void *)&cmd_pkt_filter_flexbytes_value,
4675                 (void *)&cmd_pkt_filter_vlan,
4676                 (void *)&cmd_pkt_filter_vlan_id,
4677                 (void *)&cmd_pkt_filter_soft,
4678                 (void *)&cmd_pkt_filter_soft_id,
4679                 NULL,
4680         },
4681 };
4682
4683 /* *** SETUP MASKS FILTER *** */
4684 struct cmd_pkt_filter_masks_result {
4685         cmdline_fixed_string_t filter_mask;
4686         uint8_t  port_id;
4687         cmdline_fixed_string_t src_mask;
4688         uint32_t ip_src_mask;
4689         uint16_t ipv6_src_mask;
4690         uint16_t port_src_mask;
4691         cmdline_fixed_string_t dst_mask;
4692         uint32_t ip_dst_mask;
4693         uint16_t ipv6_dst_mask;
4694         uint16_t port_dst_mask;
4695         cmdline_fixed_string_t flexbytes;
4696         uint8_t flexbytes_value;
4697         cmdline_fixed_string_t vlan_id;
4698         uint8_t  vlan_id_value;
4699         cmdline_fixed_string_t vlan_prio;
4700         uint8_t  vlan_prio_value;
4701         cmdline_fixed_string_t only_ip_flow;
4702         uint8_t  only_ip_flow_value;
4703         cmdline_fixed_string_t comp_ipv6_dst;
4704         uint8_t  comp_ipv6_dst_value;
4705 };
4706
4707 static void
4708 cmd_pkt_filter_masks_parsed(void *parsed_result,
4709                           __attribute__((unused)) struct cmdline *cl,
4710                           __attribute__((unused)) void *data)
4711 {
4712         struct rte_fdir_masks fdir_masks;
4713         struct cmd_pkt_filter_masks_result *res = parsed_result;
4714
4715         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
4716
4717         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
4718         fdir_masks.vlan_id       = res->vlan_id_value;
4719         fdir_masks.vlan_prio     = res->vlan_prio_value;
4720         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
4721         fdir_masks.src_ipv4_mask = res->ip_src_mask;
4722         fdir_masks.src_port_mask = res->port_src_mask;
4723         fdir_masks.dst_port_mask = res->port_dst_mask;
4724         fdir_masks.flexbytes     = res->flexbytes_value;
4725
4726         fdir_set_masks(res->port_id, &fdir_masks);
4727 }
4728
4729 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
4730         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4731                                  filter_mask, "set_masks_filter");
4732 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
4733         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4734                               port_id, UINT8);
4735 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
4736         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4737                                  only_ip_flow, "only_ip_flow");
4738 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
4739         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4740                               only_ip_flow_value, UINT8);
4741 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
4742         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4743                                  src_mask, "src_mask");
4744 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
4745         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4746                               ip_src_mask, UINT32);
4747 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
4748         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4749                               port_src_mask, UINT16);
4750 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
4751         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4752                                  dst_mask, "dst_mask");
4753 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
4754         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4755                               ip_dst_mask, UINT32);
4756 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
4757         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4758                               port_dst_mask, UINT16);
4759 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
4760         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4761                                  flexbytes, "flexbytes");
4762 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
4763         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4764                               flexbytes_value, UINT8);
4765 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
4766         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4767                                  vlan_id, "vlan_id");
4768 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
4769         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4770                               vlan_id_value, UINT8);
4771 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
4772         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4773                                  vlan_prio, "vlan_prio");
4774 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
4775         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4776                               vlan_prio_value, UINT8);
4777
4778 cmdline_parse_inst_t cmd_set_masks_filter = {
4779         .f = cmd_pkt_filter_masks_parsed,
4780         .data = NULL,
4781         .help_str = "setup masks filter",
4782         .tokens = {
4783                 (void *)&cmd_pkt_filter_masks_filter_mask,
4784                 (void *)&cmd_pkt_filter_masks_port_id,
4785                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
4786                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
4787                 (void *)&cmd_pkt_filter_masks_src_mask,
4788                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
4789                 (void *)&cmd_pkt_filter_masks_port_src_mask,
4790                 (void *)&cmd_pkt_filter_masks_dst_mask,
4791                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
4792                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
4793                 (void *)&cmd_pkt_filter_masks_flexbytes,
4794                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
4795                 (void *)&cmd_pkt_filter_masks_vlan_id,
4796                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
4797                 (void *)&cmd_pkt_filter_masks_vlan_prio,
4798                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
4799                 NULL,
4800         },
4801 };
4802
4803 static void
4804 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
4805                           __attribute__((unused)) struct cmdline *cl,
4806                           __attribute__((unused)) void *data)
4807 {
4808         struct rte_fdir_masks fdir_masks;
4809         struct cmd_pkt_filter_masks_result *res = parsed_result;
4810
4811         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
4812
4813         fdir_masks.set_ipv6_mask = 1;
4814         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
4815         fdir_masks.vlan_id       = res->vlan_id_value;
4816         fdir_masks.vlan_prio     = res->vlan_prio_value;
4817         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
4818         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
4819         fdir_masks.src_port_mask = res->port_src_mask;
4820         fdir_masks.dst_port_mask = res->port_dst_mask;
4821         fdir_masks.flexbytes     = res->flexbytes_value;
4822         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
4823
4824         fdir_set_masks(res->port_id, &fdir_masks);
4825 }
4826
4827 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
4828         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4829                                  filter_mask, "set_ipv6_masks_filter");
4830 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
4831         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4832                               ipv6_src_mask, UINT16);
4833 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
4834         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4835                               ipv6_dst_mask, UINT16);
4836
4837 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
4838         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4839                                  comp_ipv6_dst, "compare_dst");
4840 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
4841         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4842                               comp_ipv6_dst_value, UINT8);
4843
4844 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
4845         .f = cmd_pkt_filter_masks_ipv6_parsed,
4846         .data = NULL,
4847         .help_str = "setup ipv6 masks filter",
4848         .tokens = {
4849                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
4850                 (void *)&cmd_pkt_filter_masks_port_id,
4851                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
4852                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
4853                 (void *)&cmd_pkt_filter_masks_src_mask,
4854                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
4855                 (void *)&cmd_pkt_filter_masks_port_src_mask,
4856                 (void *)&cmd_pkt_filter_masks_dst_mask,
4857                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
4858                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
4859                 (void *)&cmd_pkt_filter_masks_flexbytes,
4860                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
4861                 (void *)&cmd_pkt_filter_masks_vlan_id,
4862                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
4863                 (void *)&cmd_pkt_filter_masks_vlan_prio,
4864                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
4865                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
4866                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
4867                 NULL,
4868         },
4869 };
4870
4871 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4872 struct cmd_link_flow_ctrl_set_result {
4873         cmdline_fixed_string_t set;
4874         cmdline_fixed_string_t flow_ctrl;
4875         cmdline_fixed_string_t rx;
4876         cmdline_fixed_string_t rx_lfc_mode;
4877         cmdline_fixed_string_t tx;
4878         cmdline_fixed_string_t tx_lfc_mode;
4879         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4880         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4881         cmdline_fixed_string_t autoneg_str;
4882         cmdline_fixed_string_t autoneg;
4883         cmdline_fixed_string_t hw_str;
4884         uint32_t high_water;
4885         cmdline_fixed_string_t lw_str;
4886         uint32_t low_water;
4887         cmdline_fixed_string_t pt_str;
4888         uint16_t pause_time;
4889         cmdline_fixed_string_t xon_str;
4890         uint16_t send_xon;
4891         uint8_t  port_id;
4892 };
4893
4894 cmdline_parse_token_string_t cmd_lfc_set_set =
4895         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4896                                 set, "set");
4897 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4898         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4899                                 flow_ctrl, "flow_ctrl");
4900 cmdline_parse_token_string_t cmd_lfc_set_rx =
4901         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4902                                 rx, "rx");
4903 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4904         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4905                                 rx_lfc_mode, "on#off");
4906 cmdline_parse_token_string_t cmd_lfc_set_tx =
4907         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4908                                 tx, "tx");
4909 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4911                                 tx_lfc_mode, "on#off");
4912 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4913         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4914                                 hw_str, "high_water");
4915 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4916         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4917                                 high_water, UINT32);
4918 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4919         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4920                                 lw_str, "low_water");
4921 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4922         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4923                                 low_water, UINT32);
4924 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4925         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4926                                 pt_str, "pause_time");
4927 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4928         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4929                                 pause_time, UINT16);
4930 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4931         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4932                                 xon_str, "send_xon");
4933 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4934         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4935                                 send_xon, UINT16);
4936 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4937         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4938                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4939 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4940         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4941                                 mac_ctrl_frame_fwd_mode, "on#off");
4942 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4944                                 autoneg_str, "autoneg");
4945 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4946         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4947                                 autoneg, "on#off");
4948 cmdline_parse_token_num_t cmd_lfc_set_portid =
4949         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4950                                 port_id, UINT8);
4951
4952 /* forward declaration */
4953 static void
4954 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4955                               void *data);
4956
4957 cmdline_parse_inst_t cmd_link_flow_control_set = {
4958         .f = cmd_link_flow_ctrl_set_parsed,
4959         .data = NULL,
4960         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4961 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4962 autoneg on|off port_id",
4963         .tokens = {
4964                 (void *)&cmd_lfc_set_set,
4965                 (void *)&cmd_lfc_set_flow_ctrl,
4966                 (void *)&cmd_lfc_set_rx,
4967                 (void *)&cmd_lfc_set_rx_mode,
4968                 (void *)&cmd_lfc_set_tx,
4969                 (void *)&cmd_lfc_set_tx_mode,
4970                 (void *)&cmd_lfc_set_high_water,
4971                 (void *)&cmd_lfc_set_low_water,
4972                 (void *)&cmd_lfc_set_pause_time,
4973                 (void *)&cmd_lfc_set_send_xon,
4974                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4975                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4976                 (void *)&cmd_lfc_set_autoneg_str,
4977                 (void *)&cmd_lfc_set_autoneg,
4978                 (void *)&cmd_lfc_set_portid,
4979                 NULL,
4980         },
4981 };
4982
4983 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4984         .f = cmd_link_flow_ctrl_set_parsed,
4985         .data = (void *)&cmd_link_flow_control_set_rx,
4986         .help_str = "Change rx flow control parameter: set flow_ctrl "
4987                     "rx on|off port_id",
4988         .tokens = {
4989                 (void *)&cmd_lfc_set_set,
4990                 (void *)&cmd_lfc_set_flow_ctrl,
4991                 (void *)&cmd_lfc_set_rx,
4992                 (void *)&cmd_lfc_set_rx_mode,
4993                 (void *)&cmd_lfc_set_portid,
4994                 NULL,
4995         },
4996 };
4997
4998 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4999         .f = cmd_link_flow_ctrl_set_parsed,
5000         .data = (void *)&cmd_link_flow_control_set_tx,
5001         .help_str = "Change tx flow control parameter: set flow_ctrl "
5002                     "tx on|off port_id",
5003         .tokens = {
5004                 (void *)&cmd_lfc_set_set,
5005                 (void *)&cmd_lfc_set_flow_ctrl,
5006                 (void *)&cmd_lfc_set_tx,
5007                 (void *)&cmd_lfc_set_tx_mode,
5008                 (void *)&cmd_lfc_set_portid,
5009                 NULL,
5010         },
5011 };
5012
5013 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5014         .f = cmd_link_flow_ctrl_set_parsed,
5015         .data = (void *)&cmd_link_flow_control_set_hw,
5016         .help_str = "Change high water flow control parameter: set flow_ctrl "
5017                     "high_water value port_id",
5018         .tokens = {
5019                 (void *)&cmd_lfc_set_set,
5020                 (void *)&cmd_lfc_set_flow_ctrl,
5021                 (void *)&cmd_lfc_set_high_water_str,
5022                 (void *)&cmd_lfc_set_high_water,
5023                 (void *)&cmd_lfc_set_portid,
5024                 NULL,
5025         },
5026 };
5027
5028 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5029         .f = cmd_link_flow_ctrl_set_parsed,
5030         .data = (void *)&cmd_link_flow_control_set_lw,
5031         .help_str = "Change low water flow control parameter: set flow_ctrl "
5032                     "low_water value port_id",
5033         .tokens = {
5034                 (void *)&cmd_lfc_set_set,
5035                 (void *)&cmd_lfc_set_flow_ctrl,
5036                 (void *)&cmd_lfc_set_low_water_str,
5037                 (void *)&cmd_lfc_set_low_water,
5038                 (void *)&cmd_lfc_set_portid,
5039                 NULL,
5040         },
5041 };
5042
5043 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5044         .f = cmd_link_flow_ctrl_set_parsed,
5045         .data = (void *)&cmd_link_flow_control_set_pt,
5046         .help_str = "Change pause time flow control parameter: set flow_ctrl "
5047                     "pause_time value port_id",
5048         .tokens = {
5049                 (void *)&cmd_lfc_set_set,
5050                 (void *)&cmd_lfc_set_flow_ctrl,
5051                 (void *)&cmd_lfc_set_pause_time_str,
5052                 (void *)&cmd_lfc_set_pause_time,
5053                 (void *)&cmd_lfc_set_portid,
5054                 NULL,
5055         },
5056 };
5057
5058 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5059         .f = cmd_link_flow_ctrl_set_parsed,
5060         .data = (void *)&cmd_link_flow_control_set_xon,
5061         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
5062                     "send_xon value port_id",
5063         .tokens = {
5064                 (void *)&cmd_lfc_set_set,
5065                 (void *)&cmd_lfc_set_flow_ctrl,
5066                 (void *)&cmd_lfc_set_send_xon_str,
5067                 (void *)&cmd_lfc_set_send_xon,
5068                 (void *)&cmd_lfc_set_portid,
5069                 NULL,
5070         },
5071 };
5072
5073 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5074         .f = cmd_link_flow_ctrl_set_parsed,
5075         .data = (void *)&cmd_link_flow_control_set_macfwd,
5076         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
5077                     "mac_ctrl_frame_fwd on|off port_id",
5078         .tokens = {
5079                 (void *)&cmd_lfc_set_set,
5080                 (void *)&cmd_lfc_set_flow_ctrl,
5081                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5082                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5083                 (void *)&cmd_lfc_set_portid,
5084                 NULL,
5085         },
5086 };
5087
5088 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5089         .f = cmd_link_flow_ctrl_set_parsed,
5090         .data = (void *)&cmd_link_flow_control_set_autoneg,
5091         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
5092                     "autoneg on|off port_id",
5093         .tokens = {
5094                 (void *)&cmd_lfc_set_set,
5095                 (void *)&cmd_lfc_set_flow_ctrl,
5096                 (void *)&cmd_lfc_set_autoneg_str,
5097                 (void *)&cmd_lfc_set_autoneg,
5098                 (void *)&cmd_lfc_set_portid,
5099                 NULL,
5100         },
5101 };
5102
5103 static void
5104 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5105                               __attribute__((unused)) struct cmdline *cl,
5106                               void *data)
5107 {
5108         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5109         cmdline_parse_inst_t *cmd = data;
5110         struct rte_eth_fc_conf fc_conf;
5111         int rx_fc_en, tx_fc_en;
5112         int ret;
5113
5114         /*
5115          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5116          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5117          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5118          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5119          */
5120         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5121                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5122         };
5123
5124         /* Partial command line, retrieve current configuration */
5125         if (cmd) {
5126                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5127                 if (ret != 0) {
5128                         printf("cannot get current flow ctrl parameters, return"
5129                                "code = %d\n", ret);
5130                         return;
5131                 }
5132
5133                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5134                     (fc_conf.mode == RTE_FC_FULL))
5135                         rx_fc_en = 1;
5136                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5137                     (fc_conf.mode == RTE_FC_FULL))
5138                         tx_fc_en = 1;
5139         }
5140
5141         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5142                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5143
5144         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5145                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5146
5147         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5148
5149         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5150                 fc_conf.high_water = res->high_water;
5151
5152         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5153                 fc_conf.low_water = res->low_water;
5154
5155         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5156                 fc_conf.pause_time = res->pause_time;
5157
5158         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5159                 fc_conf.send_xon = res->send_xon;
5160
5161         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5162                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5163                         fc_conf.mac_ctrl_frame_fwd = 1;
5164                 else
5165                         fc_conf.mac_ctrl_frame_fwd = 0;
5166         }
5167
5168         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5169                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5170
5171         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5172         if (ret != 0)
5173                 printf("bad flow contrl parameter, return code = %d \n", ret);
5174 }
5175
5176 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5177 struct cmd_priority_flow_ctrl_set_result {
5178         cmdline_fixed_string_t set;
5179         cmdline_fixed_string_t pfc_ctrl;
5180         cmdline_fixed_string_t rx;
5181         cmdline_fixed_string_t rx_pfc_mode;
5182         cmdline_fixed_string_t tx;
5183         cmdline_fixed_string_t tx_pfc_mode;
5184         uint32_t high_water;
5185         uint32_t low_water;
5186         uint16_t pause_time;
5187         uint8_t  priority;
5188         uint8_t  port_id;
5189 };
5190
5191 static void
5192 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5193                        __attribute__((unused)) struct cmdline *cl,
5194                        __attribute__((unused)) void *data)
5195 {
5196         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5197         struct rte_eth_pfc_conf pfc_conf;
5198         int rx_fc_enable, tx_fc_enable;
5199         int ret;
5200
5201         /*
5202          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5203          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5204          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5205          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5206          */
5207         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5208                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5209         };
5210
5211         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5212         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5213         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5214         pfc_conf.fc.high_water = res->high_water;
5215         pfc_conf.fc.low_water  = res->low_water;
5216         pfc_conf.fc.pause_time = res->pause_time;
5217         pfc_conf.priority      = res->priority;
5218
5219         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5220         if (ret != 0)
5221                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5222 }
5223
5224 cmdline_parse_token_string_t cmd_pfc_set_set =
5225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5226                                 set, "set");
5227 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5229                                 pfc_ctrl, "pfc_ctrl");
5230 cmdline_parse_token_string_t cmd_pfc_set_rx =
5231         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5232                                 rx, "rx");
5233 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5234         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5235                                 rx_pfc_mode, "on#off");
5236 cmdline_parse_token_string_t cmd_pfc_set_tx =
5237         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5238                                 tx, "tx");
5239 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5240         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5241                                 tx_pfc_mode, "on#off");
5242 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5244                                 high_water, UINT32);
5245 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5246         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5247                                 low_water, UINT32);
5248 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5249         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5250                                 pause_time, UINT16);
5251 cmdline_parse_token_num_t cmd_pfc_set_priority =
5252         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5253                                 priority, UINT8);
5254 cmdline_parse_token_num_t cmd_pfc_set_portid =
5255         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5256                                 port_id, UINT8);
5257
5258 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5259         .f = cmd_priority_flow_ctrl_set_parsed,
5260         .data = NULL,
5261         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5262                         tx on|off high_water low_water pause_time priority port_id",
5263         .tokens = {
5264                 (void *)&cmd_pfc_set_set,
5265                 (void *)&cmd_pfc_set_flow_ctrl,
5266                 (void *)&cmd_pfc_set_rx,
5267                 (void *)&cmd_pfc_set_rx_mode,
5268                 (void *)&cmd_pfc_set_tx,
5269                 (void *)&cmd_pfc_set_tx_mode,
5270                 (void *)&cmd_pfc_set_high_water,
5271                 (void *)&cmd_pfc_set_low_water,
5272                 (void *)&cmd_pfc_set_pause_time,
5273                 (void *)&cmd_pfc_set_priority,
5274                 (void *)&cmd_pfc_set_portid,
5275                 NULL,
5276         },
5277 };
5278
5279 /* *** RESET CONFIGURATION *** */
5280 struct cmd_reset_result {
5281         cmdline_fixed_string_t reset;
5282         cmdline_fixed_string_t def;
5283 };
5284
5285 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5286                              struct cmdline *cl,
5287                              __attribute__((unused)) void *data)
5288 {
5289         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5290         set_def_fwd_config();
5291 }
5292
5293 cmdline_parse_token_string_t cmd_reset_set =
5294         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5295 cmdline_parse_token_string_t cmd_reset_def =
5296         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5297                                  "default");
5298
5299 cmdline_parse_inst_t cmd_reset = {
5300         .f = cmd_reset_parsed,
5301         .data = NULL,
5302         .help_str = "set default: reset default forwarding configuration",
5303         .tokens = {
5304                 (void *)&cmd_reset_set,
5305                 (void *)&cmd_reset_def,
5306                 NULL,
5307         },
5308 };
5309
5310 /* *** START FORWARDING *** */
5311 struct cmd_start_result {
5312         cmdline_fixed_string_t start;
5313 };
5314
5315 cmdline_parse_token_string_t cmd_start_start =
5316         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5317
5318 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5319                              __attribute__((unused)) struct cmdline *cl,
5320                              __attribute__((unused)) void *data)
5321 {
5322         start_packet_forwarding(0);
5323 }
5324
5325 cmdline_parse_inst_t cmd_start = {
5326         .f = cmd_start_parsed,
5327         .data = NULL,
5328         .help_str = "start packet forwarding",
5329         .tokens = {
5330                 (void *)&cmd_start_start,
5331                 NULL,
5332         },
5333 };
5334
5335 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5336 struct cmd_start_tx_first_result {
5337         cmdline_fixed_string_t start;
5338         cmdline_fixed_string_t tx_first;
5339 };
5340
5341 static void
5342 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5343                           __attribute__((unused)) struct cmdline *cl,
5344                           __attribute__((unused)) void *data)
5345 {
5346         start_packet_forwarding(1);
5347 }
5348
5349 cmdline_parse_token_string_t cmd_start_tx_first_start =
5350         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5351                                  "start");
5352 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5353         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5354                                  tx_first, "tx_first");
5355
5356 cmdline_parse_inst_t cmd_start_tx_first = {
5357         .f = cmd_start_tx_first_parsed,
5358         .data = NULL,
5359         .help_str = "start packet forwarding, after sending 1 burst of packets",
5360         .tokens = {
5361                 (void *)&cmd_start_tx_first_start,
5362                 (void *)&cmd_start_tx_first_tx_first,
5363                 NULL,
5364         },
5365 };
5366
5367 /* *** SET LINK UP *** */
5368 struct cmd_set_link_up_result {
5369         cmdline_fixed_string_t set;
5370         cmdline_fixed_string_t link_up;
5371         cmdline_fixed_string_t port;
5372         uint8_t port_id;
5373 };
5374
5375 cmdline_parse_token_string_t cmd_set_link_up_set =
5376         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5377 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5378         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5379                                 "link-up");
5380 cmdline_parse_token_string_t cmd_set_link_up_port =
5381         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5382 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5383         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5384
5385 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5386                              __attribute__((unused)) struct cmdline *cl,
5387                              __attribute__((unused)) void *data)
5388 {
5389         struct cmd_set_link_up_result *res = parsed_result;
5390         dev_set_link_up(res->port_id);
5391 }
5392
5393 cmdline_parse_inst_t cmd_set_link_up = {
5394         .f = cmd_set_link_up_parsed,
5395         .data = NULL,
5396         .help_str = "set link-up port (port id)",
5397         .tokens = {
5398                 (void *)&cmd_set_link_up_set,
5399                 (void *)&cmd_set_link_up_link_up,
5400                 (void *)&cmd_set_link_up_port,
5401                 (void *)&cmd_set_link_up_port_id,
5402                 NULL,
5403         },
5404 };
5405
5406 /* *** SET LINK DOWN *** */
5407 struct cmd_set_link_down_result {
5408         cmdline_fixed_string_t set;
5409         cmdline_fixed_string_t link_down;
5410         cmdline_fixed_string_t port;
5411         uint8_t port_id;
5412 };
5413
5414 cmdline_parse_token_string_t cmd_set_link_down_set =
5415         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5416 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5417         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5418                                 "link-down");
5419 cmdline_parse_token_string_t cmd_set_link_down_port =
5420         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5421 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5422         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5423
5424 static void cmd_set_link_down_parsed(
5425                                 __attribute__((unused)) void *parsed_result,
5426                                 __attribute__((unused)) struct cmdline *cl,
5427                                 __attribute__((unused)) void *data)
5428 {
5429         struct cmd_set_link_down_result *res = parsed_result;
5430         dev_set_link_down(res->port_id);
5431 }
5432
5433 cmdline_parse_inst_t cmd_set_link_down = {
5434         .f = cmd_set_link_down_parsed,
5435         .data = NULL,
5436         .help_str = "set link-down port (port id)",
5437         .tokens = {
5438                 (void *)&cmd_set_link_down_set,
5439                 (void *)&cmd_set_link_down_link_down,
5440                 (void *)&cmd_set_link_down_port,
5441                 (void *)&cmd_set_link_down_port_id,
5442                 NULL,
5443         },
5444 };
5445
5446 /* *** SHOW CFG *** */
5447 struct cmd_showcfg_result {
5448         cmdline_fixed_string_t show;
5449         cmdline_fixed_string_t cfg;
5450         cmdline_fixed_string_t what;
5451 };
5452
5453 static void cmd_showcfg_parsed(void *parsed_result,
5454                                __attribute__((unused)) struct cmdline *cl,
5455                                __attribute__((unused)) void *data)
5456 {
5457         struct cmd_showcfg_result *res = parsed_result;
5458         if (!strcmp(res->what, "rxtx"))
5459                 rxtx_config_display();
5460         else if (!strcmp(res->what, "cores"))
5461                 fwd_lcores_config_display();
5462         else if (!strcmp(res->what, "fwd"))
5463                 fwd_config_display();
5464 }
5465
5466 cmdline_parse_token_string_t cmd_showcfg_show =
5467         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5468 cmdline_parse_token_string_t cmd_showcfg_port =
5469         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5470 cmdline_parse_token_string_t cmd_showcfg_what =
5471         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5472                                  "rxtx#cores#fwd");
5473
5474 cmdline_parse_inst_t cmd_showcfg = {
5475         .f = cmd_showcfg_parsed,
5476         .data = NULL,
5477         .help_str = "show config rxtx|cores|fwd",
5478         .tokens = {
5479                 (void *)&cmd_showcfg_show,
5480                 (void *)&cmd_showcfg_port,
5481                 (void *)&cmd_showcfg_what,
5482                 NULL,
5483         },
5484 };
5485
5486 /* *** SHOW ALL PORT INFO *** */
5487 struct cmd_showportall_result {
5488         cmdline_fixed_string_t show;
5489         cmdline_fixed_string_t port;
5490         cmdline_fixed_string_t what;
5491         cmdline_fixed_string_t all;
5492 };
5493
5494 static void cmd_showportall_parsed(void *parsed_result,
5495                                 __attribute__((unused)) struct cmdline *cl,
5496                                 __attribute__((unused)) void *data)
5497 {
5498         portid_t i;
5499
5500         struct cmd_showportall_result *res = parsed_result;
5501         if (!strcmp(res->show, "clear")) {
5502                 if (!strcmp(res->what, "stats"))
5503                         for (i = 0; i < nb_ports; i++)
5504                                 nic_stats_clear(i);
5505                 else if (!strcmp(res->what, "xstats"))
5506                         for (i = 0; i < nb_ports; i++)
5507                                 nic_xstats_clear(i);
5508         } else if (!strcmp(res->what, "info"))
5509                 for (i = 0; i < nb_ports; i++)
5510                         port_infos_display(i);
5511         else if (!strcmp(res->what, "stats"))
5512                 for (i = 0; i < nb_ports; i++)
5513                         nic_stats_display(i);
5514         else if (!strcmp(res->what, "xstats"))
5515                 for (i = 0; i < nb_ports; i++)
5516                         nic_xstats_display(i);
5517         else if (!strcmp(res->what, "fdir"))
5518                 for (i = 0; i < nb_ports; i++)
5519                         fdir_get_infos(i);
5520         else if (!strcmp(res->what, "stat_qmap"))
5521                 for (i = 0; i < nb_ports; i++)
5522                         nic_stats_mapping_display(i);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_showportall_show =
5526         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5527                                  "show#clear");
5528 cmdline_parse_token_string_t cmd_showportall_port =
5529         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5530 cmdline_parse_token_string_t cmd_showportall_what =
5531         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5532                                  "info#stats#xstats#fdir#stat_qmap");
5533 cmdline_parse_token_string_t cmd_showportall_all =
5534         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5535 cmdline_parse_inst_t cmd_showportall = {
5536         .f = cmd_showportall_parsed,
5537         .data = NULL,
5538         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap all",
5539         .tokens = {
5540                 (void *)&cmd_showportall_show,
5541                 (void *)&cmd_showportall_port,
5542                 (void *)&cmd_showportall_what,
5543                 (void *)&cmd_showportall_all,
5544                 NULL,
5545         },
5546 };
5547
5548 /* *** SHOW PORT INFO *** */
5549 struct cmd_showport_result {
5550         cmdline_fixed_string_t show;
5551         cmdline_fixed_string_t port;
5552         cmdline_fixed_string_t what;
5553         uint8_t portnum;
5554 };
5555
5556 static void cmd_showport_parsed(void *parsed_result,
5557                                 __attribute__((unused)) struct cmdline *cl,
5558                                 __attribute__((unused)) void *data)
5559 {
5560         struct cmd_showport_result *res = parsed_result;
5561         if (!strcmp(res->show, "clear")) {
5562                 if (!strcmp(res->what, "stats"))
5563                         nic_stats_clear(res->portnum);
5564                 else if (!strcmp(res->what, "xstats"))
5565                         nic_xstats_clear(res->portnum);
5566         } else if (!strcmp(res->what, "info"))
5567                 port_infos_display(res->portnum);
5568         else if (!strcmp(res->what, "stats"))
5569                 nic_stats_display(res->portnum);
5570         else if (!strcmp(res->what, "xstats"))
5571                 nic_xstats_display(res->portnum);
5572         else if (!strcmp(res->what, "fdir"))
5573                  fdir_get_infos(res->portnum);
5574         else if (!strcmp(res->what, "stat_qmap"))
5575                 nic_stats_mapping_display(res->portnum);
5576 }
5577
5578 cmdline_parse_token_string_t cmd_showport_show =
5579         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5580                                  "show#clear");
5581 cmdline_parse_token_string_t cmd_showport_port =
5582         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5583 cmdline_parse_token_string_t cmd_showport_what =
5584         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5585                                  "info#stats#xstats#fdir#stat_qmap");
5586 cmdline_parse_token_num_t cmd_showport_portnum =
5587         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5588
5589 cmdline_parse_inst_t cmd_showport = {
5590         .f = cmd_showport_parsed,
5591         .data = NULL,
5592         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap X (X = port number)",
5593         .tokens = {
5594                 (void *)&cmd_showport_show,
5595                 (void *)&cmd_showport_port,
5596                 (void *)&cmd_showport_what,
5597                 (void *)&cmd_showport_portnum,
5598                 NULL,
5599         },
5600 };
5601
5602 /* *** READ PORT REGISTER *** */
5603 struct cmd_read_reg_result {
5604         cmdline_fixed_string_t read;
5605         cmdline_fixed_string_t reg;
5606         uint8_t port_id;
5607         uint32_t reg_off;
5608 };
5609
5610 static void
5611 cmd_read_reg_parsed(void *parsed_result,
5612                     __attribute__((unused)) struct cmdline *cl,
5613                     __attribute__((unused)) void *data)
5614 {
5615         struct cmd_read_reg_result *res = parsed_result;
5616         port_reg_display(res->port_id, res->reg_off);
5617 }
5618
5619 cmdline_parse_token_string_t cmd_read_reg_read =
5620         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5621 cmdline_parse_token_string_t cmd_read_reg_reg =
5622         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5623 cmdline_parse_token_num_t cmd_read_reg_port_id =
5624         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5625 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5626         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5627
5628 cmdline_parse_inst_t cmd_read_reg = {
5629         .f = cmd_read_reg_parsed,
5630         .data = NULL,
5631         .help_str = "read reg port_id reg_off",
5632         .tokens = {
5633                 (void *)&cmd_read_reg_read,
5634                 (void *)&cmd_read_reg_reg,
5635                 (void *)&cmd_read_reg_port_id,
5636                 (void *)&cmd_read_reg_reg_off,
5637                 NULL,
5638         },
5639 };
5640
5641 /* *** READ PORT REGISTER BIT FIELD *** */
5642 struct cmd_read_reg_bit_field_result {
5643         cmdline_fixed_string_t read;
5644         cmdline_fixed_string_t regfield;
5645         uint8_t port_id;
5646         uint32_t reg_off;
5647         uint8_t bit1_pos;
5648         uint8_t bit2_pos;
5649 };
5650
5651 static void
5652 cmd_read_reg_bit_field_parsed(void *parsed_result,
5653                               __attribute__((unused)) struct cmdline *cl,
5654                               __attribute__((unused)) void *data)
5655 {
5656         struct cmd_read_reg_bit_field_result *res = parsed_result;
5657         port_reg_bit_field_display(res->port_id, res->reg_off,
5658                                    res->bit1_pos, res->bit2_pos);
5659 }
5660
5661 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5662         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5663                                  "read");
5664 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5665         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5666                                  regfield, "regfield");
5667 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5668         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5669                               UINT8);
5670 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5671         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5672                               UINT32);
5673 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5674         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5675                               UINT8);
5676 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5677         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5678                               UINT8);
5679
5680 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5681         .f = cmd_read_reg_bit_field_parsed,
5682         .data = NULL,
5683         .help_str = "read regfield port_id reg_off bit_x bit_y "
5684         "(read register bit field between bit_x and bit_y included)",
5685         .tokens = {
5686                 (void *)&cmd_read_reg_bit_field_read,
5687                 (void *)&cmd_read_reg_bit_field_regfield,
5688                 (void *)&cmd_read_reg_bit_field_port_id,
5689                 (void *)&cmd_read_reg_bit_field_reg_off,
5690                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5691                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5692                 NULL,
5693         },
5694 };
5695
5696 /* *** READ PORT REGISTER BIT *** */
5697 struct cmd_read_reg_bit_result {
5698         cmdline_fixed_string_t read;
5699         cmdline_fixed_string_t regbit;
5700         uint8_t port_id;
5701         uint32_t reg_off;
5702         uint8_t bit_pos;
5703 };
5704
5705 static void
5706 cmd_read_reg_bit_parsed(void *parsed_result,
5707                         __attribute__((unused)) struct cmdline *cl,
5708                         __attribute__((unused)) void *data)
5709 {
5710         struct cmd_read_reg_bit_result *res = parsed_result;
5711         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5712 }
5713
5714 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5715         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5716 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5717         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5718                                  regbit, "regbit");
5719 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5720         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5721 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5722         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5723 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5724         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5725
5726 cmdline_parse_inst_t cmd_read_reg_bit = {
5727         .f = cmd_read_reg_bit_parsed,
5728         .data = NULL,
5729         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5730         .tokens = {
5731                 (void *)&cmd_read_reg_bit_read,
5732                 (void *)&cmd_read_reg_bit_regbit,
5733                 (void *)&cmd_read_reg_bit_port_id,
5734                 (void *)&cmd_read_reg_bit_reg_off,
5735                 (void *)&cmd_read_reg_bit_bit_pos,
5736                 NULL,
5737         },
5738 };
5739
5740 /* *** WRITE PORT REGISTER *** */
5741 struct cmd_write_reg_result {
5742         cmdline_fixed_string_t write;
5743         cmdline_fixed_string_t reg;
5744         uint8_t port_id;
5745         uint32_t reg_off;
5746         uint32_t value;
5747 };
5748
5749 static void
5750 cmd_write_reg_parsed(void *parsed_result,
5751                      __attribute__((unused)) struct cmdline *cl,
5752                      __attribute__((unused)) void *data)
5753 {
5754         struct cmd_write_reg_result *res = parsed_result;
5755         port_reg_set(res->port_id, res->reg_off, res->value);
5756 }
5757
5758 cmdline_parse_token_string_t cmd_write_reg_write =
5759         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5760 cmdline_parse_token_string_t cmd_write_reg_reg =
5761         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5762 cmdline_parse_token_num_t cmd_write_reg_port_id =
5763         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5764 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5765         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5766 cmdline_parse_token_num_t cmd_write_reg_value =
5767         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5768
5769 cmdline_parse_inst_t cmd_write_reg = {
5770         .f = cmd_write_reg_parsed,
5771         .data = NULL,
5772         .help_str = "write reg port_id reg_off reg_value",
5773         .tokens = {
5774                 (void *)&cmd_write_reg_write,
5775                 (void *)&cmd_write_reg_reg,
5776                 (void *)&cmd_write_reg_port_id,
5777                 (void *)&cmd_write_reg_reg_off,
5778                 (void *)&cmd_write_reg_value,
5779                 NULL,
5780         },
5781 };
5782
5783 /* *** WRITE PORT REGISTER BIT FIELD *** */
5784 struct cmd_write_reg_bit_field_result {
5785         cmdline_fixed_string_t write;
5786         cmdline_fixed_string_t regfield;
5787         uint8_t port_id;
5788         uint32_t reg_off;
5789         uint8_t bit1_pos;
5790         uint8_t bit2_pos;
5791         uint32_t value;
5792 };
5793
5794 static void
5795 cmd_write_reg_bit_field_parsed(void *parsed_result,
5796                                __attribute__((unused)) struct cmdline *cl,
5797                                __attribute__((unused)) void *data)
5798 {
5799         struct cmd_write_reg_bit_field_result *res = parsed_result;
5800         port_reg_bit_field_set(res->port_id, res->reg_off,
5801                           res->bit1_pos, res->bit2_pos, res->value);
5802 }
5803
5804 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5805         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5806                                  "write");
5807 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5808         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5809                                  regfield, "regfield");
5810 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5811         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5812                               UINT8);
5813 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5814         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5815                               UINT32);
5816 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5817         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5818                               UINT8);
5819 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5820         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5821                               UINT8);
5822 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5823         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5824                               UINT32);
5825
5826 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5827         .f = cmd_write_reg_bit_field_parsed,
5828         .data = NULL,
5829         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5830         "(set register bit field between bit_x and bit_y included)",
5831         .tokens = {
5832                 (void *)&cmd_write_reg_bit_field_write,
5833                 (void *)&cmd_write_reg_bit_field_regfield,
5834                 (void *)&cmd_write_reg_bit_field_port_id,
5835                 (void *)&cmd_write_reg_bit_field_reg_off,
5836                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5837                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5838                 (void *)&cmd_write_reg_bit_field_value,
5839                 NULL,
5840         },
5841 };
5842
5843 /* *** WRITE PORT REGISTER BIT *** */
5844 struct cmd_write_reg_bit_result {
5845         cmdline_fixed_string_t write;
5846         cmdline_fixed_string_t regbit;
5847         uint8_t port_id;
5848         uint32_t reg_off;
5849         uint8_t bit_pos;
5850         uint8_t value;
5851 };
5852
5853 static void
5854 cmd_write_reg_bit_parsed(void *parsed_result,
5855                          __attribute__((unused)) struct cmdline *cl,
5856                          __attribute__((unused)) void *data)
5857 {
5858         struct cmd_write_reg_bit_result *res = parsed_result;
5859         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5860 }
5861
5862 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5863         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5864                                  "write");
5865 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5866         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5867                                  regbit, "regbit");
5868 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5869         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5870 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5872 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5873         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5874 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5876
5877 cmdline_parse_inst_t cmd_write_reg_bit = {
5878         .f = cmd_write_reg_bit_parsed,
5879         .data = NULL,
5880         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5881         .tokens = {
5882                 (void *)&cmd_write_reg_bit_write,
5883                 (void *)&cmd_write_reg_bit_regbit,
5884                 (void *)&cmd_write_reg_bit_port_id,
5885                 (void *)&cmd_write_reg_bit_reg_off,
5886                 (void *)&cmd_write_reg_bit_bit_pos,
5887                 (void *)&cmd_write_reg_bit_value,
5888                 NULL,
5889         },
5890 };
5891
5892 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5893 struct cmd_read_rxd_txd_result {
5894         cmdline_fixed_string_t read;
5895         cmdline_fixed_string_t rxd_txd;
5896         uint8_t port_id;
5897         uint16_t queue_id;
5898         uint16_t desc_id;
5899 };
5900
5901 static void
5902 cmd_read_rxd_txd_parsed(void *parsed_result,
5903                         __attribute__((unused)) struct cmdline *cl,
5904                         __attribute__((unused)) void *data)
5905 {
5906         struct cmd_read_rxd_txd_result *res = parsed_result;
5907
5908         if (!strcmp(res->rxd_txd, "rxd"))
5909                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5910         else if (!strcmp(res->rxd_txd, "txd"))
5911                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5912 }
5913
5914 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5915         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5916 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5917         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5918                                  "rxd#txd");
5919 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5920         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5921 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5922         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5923 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5924         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5925
5926 cmdline_parse_inst_t cmd_read_rxd_txd = {
5927         .f = cmd_read_rxd_txd_parsed,
5928         .data = NULL,
5929         .help_str = "read rxd|txd port_id queue_id rxd_id",
5930         .tokens = {
5931                 (void *)&cmd_read_rxd_txd_read,
5932                 (void *)&cmd_read_rxd_txd_rxd_txd,
5933                 (void *)&cmd_read_rxd_txd_port_id,
5934                 (void *)&cmd_read_rxd_txd_queue_id,
5935                 (void *)&cmd_read_rxd_txd_desc_id,
5936                 NULL,
5937         },
5938 };
5939
5940 /* *** QUIT *** */
5941 struct cmd_quit_result {
5942         cmdline_fixed_string_t quit;
5943 };
5944
5945 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5946                             struct cmdline *cl,
5947                             __attribute__((unused)) void *data)
5948 {
5949         pmd_test_exit();
5950         cmdline_quit(cl);
5951 }
5952
5953 cmdline_parse_token_string_t cmd_quit_quit =
5954         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5955
5956 cmdline_parse_inst_t cmd_quit = {
5957         .f = cmd_quit_parsed,
5958         .data = NULL,
5959         .help_str = "exit application",
5960         .tokens = {
5961                 (void *)&cmd_quit_quit,
5962                 NULL,
5963         },
5964 };
5965
5966 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5967 struct cmd_mac_addr_result {
5968         cmdline_fixed_string_t mac_addr_cmd;
5969         cmdline_fixed_string_t what;
5970         uint8_t port_num;
5971         struct ether_addr address;
5972 };
5973
5974 static void cmd_mac_addr_parsed(void *parsed_result,
5975                 __attribute__((unused)) struct cmdline *cl,
5976                 __attribute__((unused)) void *data)
5977 {
5978         struct cmd_mac_addr_result *res = parsed_result;
5979         int ret;
5980
5981         if (strcmp(res->what, "add") == 0)
5982                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5983         else
5984                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5985
5986         /* check the return value and print it if is < 0 */
5987         if(ret < 0)
5988                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5989
5990 }
5991
5992 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5993         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5994                                 "mac_addr");
5995 cmdline_parse_token_string_t cmd_mac_addr_what =
5996         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5997                                 "add#remove");
5998 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5999                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6000 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6001                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6002
6003 cmdline_parse_inst_t cmd_mac_addr = {
6004         .f = cmd_mac_addr_parsed,
6005         .data = (void *)0,
6006         .help_str = "mac_addr add|remove X <address>: "
6007                         "add/remove MAC address on port X",
6008         .tokens = {
6009                 (void *)&cmd_mac_addr_cmd,
6010                 (void *)&cmd_mac_addr_what,
6011                 (void *)&cmd_mac_addr_portnum,
6012                 (void *)&cmd_mac_addr_addr,
6013                 NULL,
6014         },
6015 };
6016
6017
6018 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6019 struct cmd_set_qmap_result {
6020         cmdline_fixed_string_t set;
6021         cmdline_fixed_string_t qmap;
6022         cmdline_fixed_string_t what;
6023         uint8_t port_id;
6024         uint16_t queue_id;
6025         uint8_t map_value;
6026 };
6027
6028 static void
6029 cmd_set_qmap_parsed(void *parsed_result,
6030                        __attribute__((unused)) struct cmdline *cl,
6031                        __attribute__((unused)) void *data)
6032 {
6033         struct cmd_set_qmap_result *res = parsed_result;
6034         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6035
6036         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6037 }
6038
6039 cmdline_parse_token_string_t cmd_setqmap_set =
6040         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6041                                  set, "set");
6042 cmdline_parse_token_string_t cmd_setqmap_qmap =
6043         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6044                                  qmap, "stat_qmap");
6045 cmdline_parse_token_string_t cmd_setqmap_what =
6046         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6047                                  what, "tx#rx");
6048 cmdline_parse_token_num_t cmd_setqmap_portid =
6049         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6050                               port_id, UINT8);
6051 cmdline_parse_token_num_t cmd_setqmap_queueid =
6052         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6053                               queue_id, UINT16);
6054 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6055         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6056                               map_value, UINT8);
6057
6058 cmdline_parse_inst_t cmd_set_qmap = {
6059         .f = cmd_set_qmap_parsed,
6060         .data = NULL,
6061         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
6062         .tokens = {
6063                 (void *)&cmd_setqmap_set,
6064                 (void *)&cmd_setqmap_qmap,
6065                 (void *)&cmd_setqmap_what,
6066                 (void *)&cmd_setqmap_portid,
6067                 (void *)&cmd_setqmap_queueid,
6068                 (void *)&cmd_setqmap_mapvalue,
6069                 NULL,
6070         },
6071 };
6072
6073 /* *** CONFIGURE UNICAST HASH TABLE *** */
6074 struct cmd_set_uc_hash_table {
6075         cmdline_fixed_string_t set;
6076         cmdline_fixed_string_t port;
6077         uint8_t port_id;
6078         cmdline_fixed_string_t what;
6079         struct ether_addr address;
6080         cmdline_fixed_string_t mode;
6081 };
6082
6083 static void
6084 cmd_set_uc_hash_parsed(void *parsed_result,
6085                        __attribute__((unused)) struct cmdline *cl,
6086                        __attribute__((unused)) void *data)
6087 {
6088         int ret=0;
6089         struct cmd_set_uc_hash_table *res = parsed_result;
6090
6091         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6092
6093         if (strcmp(res->what, "uta") == 0)
6094                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6095                                                 &res->address,(uint8_t)is_on);
6096         if (ret < 0)
6097                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6098
6099 }
6100
6101 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6102         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6103                                  set, "set");
6104 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6105         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6106                                  port, "port");
6107 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6108         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6109                               port_id, UINT8);
6110 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6111         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6112                                  what, "uta");
6113 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6114         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6115                                 address);
6116 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6117         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6118                                  mode, "on#off");
6119
6120 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6121         .f = cmd_set_uc_hash_parsed,
6122         .data = NULL,
6123         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6124         .tokens = {
6125                 (void *)&cmd_set_uc_hash_set,
6126                 (void *)&cmd_set_uc_hash_port,
6127                 (void *)&cmd_set_uc_hash_portid,
6128                 (void *)&cmd_set_uc_hash_what,
6129                 (void *)&cmd_set_uc_hash_mac,
6130                 (void *)&cmd_set_uc_hash_mode,
6131                 NULL,
6132         },
6133 };
6134
6135 struct cmd_set_uc_all_hash_table {
6136         cmdline_fixed_string_t set;
6137         cmdline_fixed_string_t port;
6138         uint8_t port_id;
6139         cmdline_fixed_string_t what;
6140         cmdline_fixed_string_t value;
6141         cmdline_fixed_string_t mode;
6142 };
6143
6144 static void
6145 cmd_set_uc_all_hash_parsed(void *parsed_result,
6146                        __attribute__((unused)) struct cmdline *cl,
6147                        __attribute__((unused)) void *data)
6148 {
6149         int ret=0;
6150         struct cmd_set_uc_all_hash_table *res = parsed_result;
6151
6152         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6153
6154         if ((strcmp(res->what, "uta") == 0) &&
6155                 (strcmp(res->value, "all") == 0))
6156                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6157         if (ret < 0)
6158                 printf("bad unicast hash table parameter,"
6159                         "return code = %d \n", ret);
6160 }
6161
6162 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6163         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6164                                  set, "set");
6165 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6166         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6167                                  port, "port");
6168 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6169         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6170                               port_id, UINT8);
6171 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6172         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6173                                  what, "uta");
6174 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6175         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6176                                 value,"all");
6177 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6178         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6179                                  mode, "on#off");
6180
6181 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6182         .f = cmd_set_uc_all_hash_parsed,
6183         .data = NULL,
6184         .help_str = "set port X uta all on|off (X = port number)",
6185         .tokens = {
6186                 (void *)&cmd_set_uc_all_hash_set,
6187                 (void *)&cmd_set_uc_all_hash_port,
6188                 (void *)&cmd_set_uc_all_hash_portid,
6189                 (void *)&cmd_set_uc_all_hash_what,
6190                 (void *)&cmd_set_uc_all_hash_value,
6191                 (void *)&cmd_set_uc_all_hash_mode,
6192                 NULL,
6193         },
6194 };
6195
6196 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6197 struct cmd_set_vf_macvlan_filter {
6198         cmdline_fixed_string_t set;
6199         cmdline_fixed_string_t port;
6200         uint8_t port_id;
6201         cmdline_fixed_string_t vf;
6202         uint8_t vf_id;
6203         struct ether_addr address;
6204         cmdline_fixed_string_t filter_type;
6205         cmdline_fixed_string_t mode;
6206 };
6207
6208 static void
6209 cmd_set_vf_macvlan_parsed(void *parsed_result,
6210                        __attribute__((unused)) struct cmdline *cl,
6211                        __attribute__((unused)) void *data)
6212 {
6213         int is_on, ret = 0;
6214         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6215         struct rte_eth_mac_filter filter;
6216
6217         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6218
6219         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6220
6221         /* set VF MAC filter */
6222         filter.is_vf = 1;
6223
6224         /* set VF ID */
6225         filter.dst_id = res->vf_id;
6226
6227         if (!strcmp(res->filter_type, "exact-mac"))
6228                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6229         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6230                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6231         else if (!strcmp(res->filter_type, "hashmac"))
6232                 filter.filter_type = RTE_MAC_HASH_MATCH;
6233         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6234                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6235
6236         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6237
6238         if (is_on)
6239                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6240                                         RTE_ETH_FILTER_MACVLAN,
6241                                         RTE_ETH_FILTER_ADD,
6242                                          &filter);
6243         else
6244                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6245                                         RTE_ETH_FILTER_MACVLAN,
6246                                         RTE_ETH_FILTER_DELETE,
6247                                         &filter);
6248
6249         if (ret < 0)
6250                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6251
6252 }
6253
6254 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6255         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6256                                  set, "set");
6257 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6258         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6259                                  port, "port");
6260 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6261         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6262                               port_id, UINT8);
6263 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6264         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6265                                  vf, "vf");
6266 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6267         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6268                                 vf_id, UINT8);
6269 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6270         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6271                                 address);
6272 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6273         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6274                                 filter_type, "exact-mac#exact-mac-vlan"
6275                                 "#hashmac#hashmac-vlan");
6276 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6277         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6278                                  mode, "on#off");
6279
6280 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6281         .f = cmd_set_vf_macvlan_parsed,
6282         .data = NULL,
6283         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6284                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6285                         "on|off\n"
6286                         "exact match rule:exact match of MAC or MAC and VLAN; "
6287                         "hash match rule: hash match of MAC and exact match "
6288                         "of VLAN",
6289         .tokens = {
6290                 (void *)&cmd_set_vf_macvlan_set,
6291                 (void *)&cmd_set_vf_macvlan_port,
6292                 (void *)&cmd_set_vf_macvlan_portid,
6293                 (void *)&cmd_set_vf_macvlan_vf,
6294                 (void *)&cmd_set_vf_macvlan_vf_id,
6295                 (void *)&cmd_set_vf_macvlan_mac,
6296                 (void *)&cmd_set_vf_macvlan_filter_type,
6297                 (void *)&cmd_set_vf_macvlan_mode,
6298                 NULL,
6299         },
6300 };
6301
6302 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6303 struct cmd_set_vf_traffic {
6304         cmdline_fixed_string_t set;
6305         cmdline_fixed_string_t port;
6306         uint8_t port_id;
6307         cmdline_fixed_string_t vf;
6308         uint8_t vf_id;
6309         cmdline_fixed_string_t what;
6310         cmdline_fixed_string_t mode;
6311 };
6312
6313 static void
6314 cmd_set_vf_traffic_parsed(void *parsed_result,
6315                        __attribute__((unused)) struct cmdline *cl,
6316                        __attribute__((unused)) void *data)
6317 {
6318         struct cmd_set_vf_traffic *res = parsed_result;
6319         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6320         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6321
6322         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6323 }
6324
6325 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6326         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6327                                  set, "set");
6328 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6329         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6330                                  port, "port");
6331 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6332         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6333                               port_id, UINT8);
6334 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6335         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6336                                  vf, "vf");
6337 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6338         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6339                               vf_id, UINT8);
6340 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6341         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6342                                  what, "tx#rx");
6343 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6345                                  mode, "on#off");
6346
6347 cmdline_parse_inst_t cmd_set_vf_traffic = {
6348         .f = cmd_set_vf_traffic_parsed,
6349         .data = NULL,
6350         .help_str = "set port X vf Y rx|tx on|off"
6351                         "(X = port number,Y = vf id)",
6352         .tokens = {
6353                 (void *)&cmd_setvf_traffic_set,
6354                 (void *)&cmd_setvf_traffic_port,
6355                 (void *)&cmd_setvf_traffic_portid,
6356                 (void *)&cmd_setvf_traffic_vf,
6357                 (void *)&cmd_setvf_traffic_vfid,
6358                 (void *)&cmd_setvf_traffic_what,
6359                 (void *)&cmd_setvf_traffic_mode,
6360                 NULL,
6361         },
6362 };
6363
6364 /* *** CONFIGURE VF RECEIVE MODE *** */
6365 struct cmd_set_vf_rxmode {
6366         cmdline_fixed_string_t set;
6367         cmdline_fixed_string_t port;
6368         uint8_t port_id;
6369         cmdline_fixed_string_t vf;
6370         uint8_t vf_id;
6371         cmdline_fixed_string_t what;
6372         cmdline_fixed_string_t mode;
6373         cmdline_fixed_string_t on;
6374 };
6375
6376 static void
6377 cmd_set_vf_rxmode_parsed(void *parsed_result,
6378                        __attribute__((unused)) struct cmdline *cl,
6379                        __attribute__((unused)) void *data)
6380 {
6381         int ret;
6382         uint16_t rx_mode = 0;
6383         struct cmd_set_vf_rxmode *res = parsed_result;
6384
6385         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6386         if (!strcmp(res->what,"rxmode")) {
6387                 if (!strcmp(res->mode, "AUPE"))
6388                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6389                 else if (!strcmp(res->mode, "ROPE"))
6390                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6391                 else if (!strcmp(res->mode, "BAM"))
6392                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6393                 else if (!strncmp(res->mode, "MPE",3))
6394                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6395         }
6396
6397         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6398         if (ret < 0)
6399                 printf("bad VF receive mode parameter, return code = %d \n",
6400                 ret);
6401 }
6402
6403 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6404         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6405                                  set, "set");
6406 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6407         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6408                                  port, "port");
6409 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6410         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6411                               port_id, UINT8);
6412 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6413         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6414                                  vf, "vf");
6415 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6416         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6417                               vf_id, UINT8);
6418 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6420                                  what, "rxmode");
6421 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6422         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6423                                  mode, "AUPE#ROPE#BAM#MPE");
6424 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6425         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6426                                  on, "on#off");
6427
6428 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6429         .f = cmd_set_vf_rxmode_parsed,
6430         .data = NULL,
6431         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6432         .tokens = {
6433                 (void *)&cmd_set_vf_rxmode_set,
6434                 (void *)&cmd_set_vf_rxmode_port,
6435                 (void *)&cmd_set_vf_rxmode_portid,
6436                 (void *)&cmd_set_vf_rxmode_vf,
6437                 (void *)&cmd_set_vf_rxmode_vfid,
6438                 (void *)&cmd_set_vf_rxmode_what,
6439                 (void *)&cmd_set_vf_rxmode_mode,
6440                 (void *)&cmd_set_vf_rxmode_on,
6441                 NULL,
6442         },
6443 };
6444
6445 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6446 struct cmd_vf_mac_addr_result {
6447         cmdline_fixed_string_t mac_addr_cmd;
6448         cmdline_fixed_string_t what;
6449         cmdline_fixed_string_t port;
6450         uint8_t port_num;
6451         cmdline_fixed_string_t vf;
6452         uint8_t vf_num;
6453         struct ether_addr address;
6454 };
6455
6456 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6457                 __attribute__((unused)) struct cmdline *cl,
6458                 __attribute__((unused)) void *data)
6459 {
6460         struct cmd_vf_mac_addr_result *res = parsed_result;
6461         int ret = 0;
6462
6463         if (strcmp(res->what, "add") == 0)
6464                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6465                                         &res->address, res->vf_num);
6466         if(ret < 0)
6467                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6468
6469 }
6470
6471 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6472         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6473                                 mac_addr_cmd,"mac_addr");
6474 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6475         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6476                                 what,"add");
6477 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6478         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6479                                 port,"port");
6480 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6481         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6482                                 port_num, UINT8);
6483 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6484         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6485                                 vf,"vf");
6486 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6487         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6488                                 vf_num, UINT8);
6489 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6490         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6491                                 address);
6492
6493 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6494         .f = cmd_vf_mac_addr_parsed,
6495         .data = (void *)0,
6496         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6497         "Y = VF number)add MAC address filtering for a VF on port X",
6498         .tokens = {
6499                 (void *)&cmd_vf_mac_addr_cmd,
6500                 (void *)&cmd_vf_mac_addr_what,
6501                 (void *)&cmd_vf_mac_addr_port,
6502                 (void *)&cmd_vf_mac_addr_portnum,
6503                 (void *)&cmd_vf_mac_addr_vf,
6504                 (void *)&cmd_vf_mac_addr_vfnum,
6505                 (void *)&cmd_vf_mac_addr_addr,
6506                 NULL,
6507         },
6508 };
6509
6510 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6511 struct cmd_vf_rx_vlan_filter {
6512         cmdline_fixed_string_t rx_vlan;
6513         cmdline_fixed_string_t what;
6514         uint16_t vlan_id;
6515         cmdline_fixed_string_t port;
6516         uint8_t port_id;
6517         cmdline_fixed_string_t vf;
6518         uint64_t vf_mask;
6519 };
6520
6521 static void
6522 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6523                           __attribute__((unused)) struct cmdline *cl,
6524                           __attribute__((unused)) void *data)
6525 {
6526         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6527
6528         if (!strcmp(res->what, "add"))
6529                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6530         else
6531                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6532 }
6533
6534 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6535         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6536                                  rx_vlan, "rx_vlan");
6537 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6538         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6539                                  what, "add#rm");
6540 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6541         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6542                               vlan_id, UINT16);
6543 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6544         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6545                                  port, "port");
6546 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6547         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6548                               port_id, UINT8);
6549 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6550         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6551                                  vf, "vf");
6552 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6553         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6554                               vf_mask, UINT64);
6555
6556 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6557         .f = cmd_vf_rx_vlan_filter_parsed,
6558         .data = NULL,
6559         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6560                 "Y = port number,Z = hexadecimal VF mask)",
6561         .tokens = {
6562                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6563                 (void *)&cmd_vf_rx_vlan_filter_what,
6564                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6565                 (void *)&cmd_vf_rx_vlan_filter_port,
6566                 (void *)&cmd_vf_rx_vlan_filter_portid,
6567                 (void *)&cmd_vf_rx_vlan_filter_vf,
6568                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6569                 NULL,
6570         },
6571 };
6572
6573 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6574 struct cmd_queue_rate_limit_result {
6575         cmdline_fixed_string_t set;
6576         cmdline_fixed_string_t port;
6577         uint8_t port_num;
6578         cmdline_fixed_string_t queue;
6579         uint8_t queue_num;
6580         cmdline_fixed_string_t rate;
6581         uint16_t rate_num;
6582 };
6583
6584 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6585                 __attribute__((unused)) struct cmdline *cl,
6586                 __attribute__((unused)) void *data)
6587 {
6588         struct cmd_queue_rate_limit_result *res = parsed_result;
6589         int ret = 0;
6590
6591         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6592                 && (strcmp(res->queue, "queue") == 0)
6593                 && (strcmp(res->rate, "rate") == 0))
6594                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6595                                         res->rate_num);
6596         if (ret < 0)
6597                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6598
6599 }
6600
6601 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6602         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6603                                 set, "set");
6604 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6605         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6606                                 port, "port");
6607 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6608         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6609                                 port_num, UINT8);
6610 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6611         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6612                                 queue, "queue");
6613 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6614         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6615                                 queue_num, UINT8);
6616 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6617         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6618                                 rate, "rate");
6619 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6620         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6621                                 rate_num, UINT16);
6622
6623 cmdline_parse_inst_t cmd_queue_rate_limit = {
6624         .f = cmd_queue_rate_limit_parsed,
6625         .data = (void *)0,
6626         .help_str = "set port X queue Y rate Z:(X = port number,"
6627         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6628         .tokens = {
6629                 (void *)&cmd_queue_rate_limit_set,
6630                 (void *)&cmd_queue_rate_limit_port,
6631                 (void *)&cmd_queue_rate_limit_portnum,
6632                 (void *)&cmd_queue_rate_limit_queue,
6633                 (void *)&cmd_queue_rate_limit_queuenum,
6634                 (void *)&cmd_queue_rate_limit_rate,
6635                 (void *)&cmd_queue_rate_limit_ratenum,
6636                 NULL,
6637         },
6638 };
6639
6640 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6641 struct cmd_vf_rate_limit_result {
6642         cmdline_fixed_string_t set;
6643         cmdline_fixed_string_t port;
6644         uint8_t port_num;
6645         cmdline_fixed_string_t vf;
6646         uint8_t vf_num;
6647         cmdline_fixed_string_t rate;
6648         uint16_t rate_num;
6649         cmdline_fixed_string_t q_msk;
6650         uint64_t q_msk_val;
6651 };
6652
6653 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6654                 __attribute__((unused)) struct cmdline *cl,
6655                 __attribute__((unused)) void *data)
6656 {
6657         struct cmd_vf_rate_limit_result *res = parsed_result;
6658         int ret = 0;
6659
6660         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6661                 && (strcmp(res->vf, "vf") == 0)
6662                 && (strcmp(res->rate, "rate") == 0)
6663                 && (strcmp(res->q_msk, "queue_mask") == 0))
6664                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6665                                         res->rate_num, res->q_msk_val);
6666         if (ret < 0)
6667                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6668
6669 }
6670
6671 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6672         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6673                                 set, "set");
6674 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6675         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6676                                 port, "port");
6677 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6678         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6679                                 port_num, UINT8);
6680 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6681         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6682                                 vf, "vf");
6683 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6684         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6685                                 vf_num, UINT8);
6686 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6687         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6688                                 rate, "rate");
6689 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6690         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6691                                 rate_num, UINT16);
6692 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6693         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6694                                 q_msk, "queue_mask");
6695 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6696         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6697                                 q_msk_val, UINT64);
6698
6699 cmdline_parse_inst_t cmd_vf_rate_limit = {
6700         .f = cmd_vf_rate_limit_parsed,
6701         .data = (void *)0,
6702         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6703         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6704         "for queues of VF on port X",
6705         .tokens = {
6706                 (void *)&cmd_vf_rate_limit_set,
6707                 (void *)&cmd_vf_rate_limit_port,
6708                 (void *)&cmd_vf_rate_limit_portnum,
6709                 (void *)&cmd_vf_rate_limit_vf,
6710                 (void *)&cmd_vf_rate_limit_vfnum,
6711                 (void *)&cmd_vf_rate_limit_rate,
6712                 (void *)&cmd_vf_rate_limit_ratenum,
6713                 (void *)&cmd_vf_rate_limit_q_msk,
6714                 (void *)&cmd_vf_rate_limit_q_msk_val,
6715                 NULL,
6716         },
6717 };
6718
6719 /* *** ADD TUNNEL FILTER OF A PORT *** */
6720 struct cmd_tunnel_filter_result {
6721         cmdline_fixed_string_t cmd;
6722         cmdline_fixed_string_t what;
6723         uint8_t port_id;
6724         struct ether_addr outer_mac;
6725         struct ether_addr inner_mac;
6726         cmdline_ipaddr_t ip_value;
6727         uint16_t inner_vlan;
6728         cmdline_fixed_string_t tunnel_type;
6729         cmdline_fixed_string_t filter_type;
6730         uint32_t tenant_id;
6731         uint16_t queue_num;
6732 };
6733
6734 static void
6735 cmd_tunnel_filter_parsed(void *parsed_result,
6736                           __attribute__((unused)) struct cmdline *cl,
6737                           __attribute__((unused)) void *data)
6738 {
6739         struct cmd_tunnel_filter_result *res = parsed_result;
6740         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6741         int ret = 0;
6742
6743         tunnel_filter_conf.outer_mac = &res->outer_mac;
6744         tunnel_filter_conf.inner_mac = &res->inner_mac;
6745         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6746
6747         if (res->ip_value.family == AF_INET) {
6748                 tunnel_filter_conf.ip_addr.ipv4_addr =
6749                         res->ip_value.addr.ipv4.s_addr;
6750                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6751         } else {
6752                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6753                         &(res->ip_value.addr.ipv6),
6754                         sizeof(struct in6_addr));
6755                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6756         }
6757
6758         if (!strcmp(res->filter_type, "imac-ivlan"))
6759                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6760         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6761                 tunnel_filter_conf.filter_type =
6762                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6763         else if (!strcmp(res->filter_type, "imac-tenid"))
6764                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6765         else if (!strcmp(res->filter_type, "imac"))
6766                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6767         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6768                 tunnel_filter_conf.filter_type =
6769                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6770         else {
6771                 printf("The filter type is not supported");
6772                 return;
6773         }
6774
6775         if (!strcmp(res->tunnel_type, "vxlan"))
6776                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6777         else {
6778                 printf("Only VXLAN is supported now.\n");
6779                 return;
6780         }
6781
6782         tunnel_filter_conf.tenant_id = res->tenant_id;
6783         tunnel_filter_conf.queue_id = res->queue_num;
6784         if (!strcmp(res->what, "add"))
6785                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6786                                         RTE_ETH_FILTER_TUNNEL,
6787                                         RTE_ETH_FILTER_ADD,
6788                                         &tunnel_filter_conf);
6789         else
6790                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6791                                         RTE_ETH_FILTER_TUNNEL,
6792                                         RTE_ETH_FILTER_DELETE,
6793                                         &tunnel_filter_conf);
6794         if (ret < 0)
6795                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6796                                 strerror(-ret));
6797
6798 }
6799 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6800         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6801         cmd, "tunnel_filter");
6802 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6803         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6804         what, "add#rm");
6805 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6806         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6807         port_id, UINT8);
6808 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6809         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6810         outer_mac);
6811 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6812         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6813         inner_mac);
6814 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6815         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6816         inner_vlan, UINT16);
6817 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6818         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6819         ip_value);
6820 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6821         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6822         tunnel_type, "vxlan");
6823
6824 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6825         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6826         filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6827                 "imac#omac-imac-tenid");
6828 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6829         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6830         tenant_id, UINT32);
6831 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6832         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6833         queue_num, UINT16);
6834
6835 cmdline_parse_inst_t cmd_tunnel_filter = {
6836         .f = cmd_tunnel_filter_parsed,
6837         .data = (void *)0,
6838         .help_str = "add/rm tunnel filter of a port: "
6839                         "tunnel_filter add port_id outer_mac inner_mac ip "
6840                         "inner_vlan tunnel_type(vxlan) filter_type "
6841                         "(imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6842                         "imac|omac-imac-tenid) "
6843                         "tenant_id queue_num",
6844         .tokens = {
6845                 (void *)&cmd_tunnel_filter_cmd,
6846                 (void *)&cmd_tunnel_filter_what,
6847                 (void *)&cmd_tunnel_filter_port_id,
6848                 (void *)&cmd_tunnel_filter_outer_mac,
6849                 (void *)&cmd_tunnel_filter_inner_mac,
6850                 (void *)&cmd_tunnel_filter_ip_value,
6851                 (void *)&cmd_tunnel_filter_innner_vlan,
6852                 (void *)&cmd_tunnel_filter_tunnel_type,
6853                 (void *)&cmd_tunnel_filter_filter_type,
6854                 (void *)&cmd_tunnel_filter_tenant_id,
6855                 (void *)&cmd_tunnel_filter_queue_num,
6856                 NULL,
6857         },
6858 };
6859
6860 /* *** CONFIGURE TUNNEL UDP PORT *** */
6861 struct cmd_tunnel_udp_config {
6862         cmdline_fixed_string_t cmd;
6863         cmdline_fixed_string_t what;
6864         uint16_t udp_port;
6865         uint8_t port_id;
6866 };
6867
6868 static void
6869 cmd_tunnel_udp_config_parsed(void *parsed_result,
6870                           __attribute__((unused)) struct cmdline *cl,
6871                           __attribute__((unused)) void *data)
6872 {
6873         struct cmd_tunnel_udp_config *res = parsed_result;
6874         struct rte_eth_udp_tunnel tunnel_udp;
6875         int ret;
6876
6877         tunnel_udp.udp_port = res->udp_port;
6878
6879         if (!strcmp(res->cmd, "rx_vxlan_port"))
6880                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6881
6882         if (!strcmp(res->what, "add"))
6883                 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp);
6884         else
6885                 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp);
6886
6887         if (ret < 0)
6888                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6889 }
6890
6891 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6892         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6893                                 cmd, "rx_vxlan_port");
6894 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6895         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6896                                 what, "add#rm");
6897 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6898         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6899                                 udp_port, UINT16);
6900 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6901         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6902                                 port_id, UINT8);
6903
6904 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6905         .f = cmd_tunnel_udp_config_parsed,
6906         .data = (void *)0,
6907         .help_str = "add/rm an tunneling UDP port filter: "
6908                         "rx_vxlan_port add udp_port port_id",
6909         .tokens = {
6910                 (void *)&cmd_tunnel_udp_config_cmd,
6911                 (void *)&cmd_tunnel_udp_config_what,
6912                 (void *)&cmd_tunnel_udp_config_udp_port,
6913                 (void *)&cmd_tunnel_udp_config_port_id,
6914                 NULL,
6915         },
6916 };
6917
6918 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6919 struct cmd_set_mirror_mask_result {
6920         cmdline_fixed_string_t set;
6921         cmdline_fixed_string_t port;
6922         uint8_t port_id;
6923         cmdline_fixed_string_t mirror;
6924         uint8_t rule_id;
6925         cmdline_fixed_string_t what;
6926         cmdline_fixed_string_t value;
6927         cmdline_fixed_string_t dstpool;
6928         uint8_t dstpool_id;
6929         cmdline_fixed_string_t on;
6930 };
6931
6932 cmdline_parse_token_string_t cmd_mirror_mask_set =
6933         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6934                                 set, "set");
6935 cmdline_parse_token_string_t cmd_mirror_mask_port =
6936         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6937                                 port, "port");
6938 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6939         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6940                                 port_id, UINT8);
6941 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6942         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6943                                 mirror, "mirror-rule");
6944 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6945         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6946                                 rule_id, UINT8);
6947 cmdline_parse_token_string_t cmd_mirror_mask_what =
6948         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6949                                 what, "pool-mirror#vlan-mirror");
6950 cmdline_parse_token_string_t cmd_mirror_mask_value =
6951         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6952                                 value, NULL);
6953 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6954         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6955                                 dstpool, "dst-pool");
6956 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6957         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6958                                 dstpool_id, UINT8);
6959 cmdline_parse_token_string_t cmd_mirror_mask_on =
6960         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6961                                 on, "on#off");
6962
6963 static void
6964 cmd_set_mirror_mask_parsed(void *parsed_result,
6965                        __attribute__((unused)) struct cmdline *cl,
6966                        __attribute__((unused)) void *data)
6967 {
6968         int ret,nb_item,i;
6969         struct cmd_set_mirror_mask_result *res = parsed_result;
6970         struct rte_eth_vmdq_mirror_conf mr_conf;
6971
6972         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
6973
6974         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
6975
6976         mr_conf.dst_pool = res->dstpool_id;
6977
6978         if (!strcmp(res->what, "pool-mirror")) {
6979                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
6980                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
6981         } else if(!strcmp(res->what, "vlan-mirror")) {
6982                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
6983                 nb_item = parse_item_list(res->value, "core",
6984                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
6985                 if (nb_item <= 0)
6986                         return;
6987
6988                 for(i=0; i < nb_item; i++) {
6989                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6990                                 printf("Invalid vlan_id: must be < 4096\n");
6991                                 return;
6992                         }
6993
6994                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6995                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6996                 }
6997         }
6998
6999         if(!strcmp(res->on, "on"))
7000                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
7001                                                 res->rule_id, 1);
7002         else
7003                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
7004                                                 res->rule_id, 0);
7005         if(ret < 0)
7006                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7007 }
7008
7009 cmdline_parse_inst_t cmd_set_mirror_mask = {
7010                 .f = cmd_set_mirror_mask_parsed,
7011                 .data = NULL,
7012                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror "
7013                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
7014                 .tokens = {
7015                         (void *)&cmd_mirror_mask_set,
7016                         (void *)&cmd_mirror_mask_port,
7017                         (void *)&cmd_mirror_mask_portid,
7018                         (void *)&cmd_mirror_mask_mirror,
7019                         (void *)&cmd_mirror_mask_ruleid,
7020                         (void *)&cmd_mirror_mask_what,
7021                         (void *)&cmd_mirror_mask_value,
7022                         (void *)&cmd_mirror_mask_dstpool,
7023                         (void *)&cmd_mirror_mask_poolid,
7024                         (void *)&cmd_mirror_mask_on,
7025                         NULL,
7026                 },
7027 };
7028
7029 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
7030 struct cmd_set_mirror_link_result {
7031         cmdline_fixed_string_t set;
7032         cmdline_fixed_string_t port;
7033         uint8_t port_id;
7034         cmdline_fixed_string_t mirror;
7035         uint8_t rule_id;
7036         cmdline_fixed_string_t what;
7037         cmdline_fixed_string_t dstpool;
7038         uint8_t dstpool_id;
7039         cmdline_fixed_string_t on;
7040 };
7041
7042 cmdline_parse_token_string_t cmd_mirror_link_set =
7043         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7044                                  set, "set");
7045 cmdline_parse_token_string_t cmd_mirror_link_port =
7046         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7047                                 port, "port");
7048 cmdline_parse_token_num_t cmd_mirror_link_portid =
7049         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7050                                 port_id, UINT8);
7051 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7052         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7053                                 mirror, "mirror-rule");
7054 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7055         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7056                             rule_id, UINT8);
7057 cmdline_parse_token_string_t cmd_mirror_link_what =
7058         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7059                                 what, "uplink-mirror#downlink-mirror");
7060 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7061         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7062                                 dstpool, "dst-pool");
7063 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7064         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7065                                 dstpool_id, UINT8);
7066 cmdline_parse_token_string_t cmd_mirror_link_on =
7067         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7068                                 on, "on#off");
7069
7070 static void
7071 cmd_set_mirror_link_parsed(void *parsed_result,
7072                        __attribute__((unused)) struct cmdline *cl,
7073                        __attribute__((unused)) void *data)
7074 {
7075         int ret;
7076         struct cmd_set_mirror_link_result *res = parsed_result;
7077         struct rte_eth_vmdq_mirror_conf mr_conf;
7078
7079         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
7080         if(!strcmp(res->what, "uplink-mirror")) {
7081                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
7082         }else if(!strcmp(res->what, "downlink-mirror"))
7083                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
7084
7085         mr_conf.dst_pool = res->dstpool_id;
7086
7087         if(!strcmp(res->on, "on"))
7088                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
7089                                                 res->rule_id, 1);
7090         else
7091                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
7092                                                 res->rule_id, 0);
7093
7094         /* check the return value and print it if is < 0 */
7095         if(ret < 0)
7096                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7097
7098 }
7099
7100 cmdline_parse_inst_t cmd_set_mirror_link = {
7101                 .f = cmd_set_mirror_link_parsed,
7102                 .data = NULL,
7103                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7104                         "downlink-mirror dst-pool Z on|off",
7105                 .tokens = {
7106                         (void *)&cmd_mirror_link_set,
7107                         (void *)&cmd_mirror_link_port,
7108                         (void *)&cmd_mirror_link_portid,
7109                         (void *)&cmd_mirror_link_mirror,
7110                         (void *)&cmd_mirror_link_ruleid,
7111                         (void *)&cmd_mirror_link_what,
7112                         (void *)&cmd_mirror_link_dstpool,
7113                         (void *)&cmd_mirror_link_poolid,
7114                         (void *)&cmd_mirror_link_on,
7115                         NULL,
7116                 },
7117 };
7118
7119 /* *** RESET VM MIRROR RULE *** */
7120 struct cmd_rm_mirror_rule_result {
7121         cmdline_fixed_string_t reset;
7122         cmdline_fixed_string_t port;
7123         uint8_t port_id;
7124         cmdline_fixed_string_t mirror;
7125         uint8_t rule_id;
7126 };
7127
7128 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7129         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7130                                  reset, "reset");
7131 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7132         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7133                                 port, "port");
7134 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7135         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7136                                 port_id, UINT8);
7137 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7138         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7139                                 mirror, "mirror-rule");
7140 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7141         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7142                                 rule_id, UINT8);
7143
7144 static void
7145 cmd_reset_mirror_rule_parsed(void *parsed_result,
7146                        __attribute__((unused)) struct cmdline *cl,
7147                        __attribute__((unused)) void *data)
7148 {
7149         int ret;
7150         struct cmd_set_mirror_link_result *res = parsed_result;
7151         /* check rule_id */
7152         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7153         if(ret < 0)
7154                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7155 }
7156
7157 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7158                 .f = cmd_reset_mirror_rule_parsed,
7159                 .data = NULL,
7160                 .help_str = "reset port X mirror-rule Y",
7161                 .tokens = {
7162                         (void *)&cmd_rm_mirror_rule_reset,
7163                         (void *)&cmd_rm_mirror_rule_port,
7164                         (void *)&cmd_rm_mirror_rule_portid,
7165                         (void *)&cmd_rm_mirror_rule_mirror,
7166                         (void *)&cmd_rm_mirror_rule_ruleid,
7167                         NULL,
7168                 },
7169 };
7170
7171 /* ******************************************************************************** */
7172
7173 struct cmd_dump_result {
7174         cmdline_fixed_string_t dump;
7175 };
7176
7177 static void
7178 dump_struct_sizes(void)
7179 {
7180 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7181         DUMP_SIZE(struct rte_mbuf);
7182         DUMP_SIZE(struct rte_mempool);
7183         DUMP_SIZE(struct rte_ring);
7184 #undef DUMP_SIZE
7185 }
7186
7187 static void cmd_dump_parsed(void *parsed_result,
7188                             __attribute__((unused)) struct cmdline *cl,
7189                             __attribute__((unused)) void *data)
7190 {
7191         struct cmd_dump_result *res = parsed_result;
7192
7193         if (!strcmp(res->dump, "dump_physmem"))
7194                 rte_dump_physmem_layout(stdout);
7195         else if (!strcmp(res->dump, "dump_memzone"))
7196                 rte_memzone_dump(stdout);
7197         else if (!strcmp(res->dump, "dump_log_history"))
7198                 rte_log_dump_history(stdout);
7199         else if (!strcmp(res->dump, "dump_struct_sizes"))
7200                 dump_struct_sizes();
7201         else if (!strcmp(res->dump, "dump_ring"))
7202                 rte_ring_list_dump(stdout);
7203         else if (!strcmp(res->dump, "dump_mempool"))
7204                 rte_mempool_list_dump(stdout);
7205         else if (!strcmp(res->dump, "dump_devargs"))
7206                 rte_eal_devargs_dump(stdout);
7207 }
7208
7209 cmdline_parse_token_string_t cmd_dump_dump =
7210         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7211                 "dump_physmem#"
7212                 "dump_memzone#"
7213                 "dump_log_history#"
7214                 "dump_struct_sizes#"
7215                 "dump_ring#"
7216                 "dump_mempool#"
7217                 "dump_devargs");
7218
7219 cmdline_parse_inst_t cmd_dump = {
7220         .f = cmd_dump_parsed,  /* function to call */
7221         .data = NULL,      /* 2nd arg of func */
7222         .help_str = "dump status",
7223         .tokens = {        /* token list, NULL terminated */
7224                 (void *)&cmd_dump_dump,
7225                 NULL,
7226         },
7227 };
7228
7229 /* ******************************************************************************** */
7230
7231 struct cmd_dump_one_result {
7232         cmdline_fixed_string_t dump;
7233         cmdline_fixed_string_t name;
7234 };
7235
7236 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7237                                 __attribute__((unused)) void *data)
7238 {
7239         struct cmd_dump_one_result *res = parsed_result;
7240
7241         if (!strcmp(res->dump, "dump_ring")) {
7242                 struct rte_ring *r;
7243                 r = rte_ring_lookup(res->name);
7244                 if (r == NULL) {
7245                         cmdline_printf(cl, "Cannot find ring\n");
7246                         return;
7247                 }
7248                 rte_ring_dump(stdout, r);
7249         } else if (!strcmp(res->dump, "dump_mempool")) {
7250                 struct rte_mempool *mp;
7251                 mp = rte_mempool_lookup(res->name);
7252                 if (mp == NULL) {
7253                         cmdline_printf(cl, "Cannot find mempool\n");
7254                         return;
7255                 }
7256                 rte_mempool_dump(stdout, mp);
7257         }
7258 }
7259
7260 cmdline_parse_token_string_t cmd_dump_one_dump =
7261         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7262                                  "dump_ring#dump_mempool");
7263
7264 cmdline_parse_token_string_t cmd_dump_one_name =
7265         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7266
7267 cmdline_parse_inst_t cmd_dump_one = {
7268         .f = cmd_dump_one_parsed,  /* function to call */
7269         .data = NULL,      /* 2nd arg of func */
7270         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7271         .tokens = {        /* token list, NULL terminated */
7272                 (void *)&cmd_dump_one_dump,
7273                 (void *)&cmd_dump_one_name,
7274                 NULL,
7275         },
7276 };
7277
7278 /* *** set SYN filter *** */
7279 struct cmd_set_syn_filter_result {
7280         cmdline_fixed_string_t filter;
7281         uint8_t port_id;
7282         cmdline_fixed_string_t priority;
7283         cmdline_fixed_string_t high;
7284         cmdline_fixed_string_t queue;
7285         uint16_t  queue_id;
7286 };
7287
7288 static void
7289 cmd_set_syn_filter_parsed(void *parsed_result,
7290                         __attribute__((unused)) struct cmdline *cl,
7291                         __attribute__((unused)) void *data)
7292 {
7293         int ret = 0;
7294         struct cmd_set_syn_filter_result *res = parsed_result;
7295         struct rte_syn_filter filter;
7296
7297         if (!strcmp(res->filter, "add_syn_filter")) {
7298                 if (!strcmp(res->high, "high"))
7299                         filter.hig_pri = 1;
7300                 else
7301                         filter.hig_pri = 0;
7302                 ret = rte_eth_dev_add_syn_filter(res->port_id,
7303                                 &filter, res->queue_id);
7304         } else if (!strcmp(res->filter, "remove_syn_filter"))
7305                 ret = rte_eth_dev_remove_syn_filter(res->port_id);
7306         else if (!strcmp(res->filter, "get_syn_filter"))
7307                 get_syn_filter(res->port_id);
7308         if (ret < 0)
7309                 printf("syn filter setting error: (%s)\n", strerror(-ret));
7310
7311 }
7312 cmdline_parse_token_num_t cmd_syn_filter_portid =
7313         TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
7314                                 port_id, UINT8);
7315 cmdline_parse_token_string_t cmd_syn_filter_priority =
7316         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7317                                 priority, "priority");
7318 cmdline_parse_token_string_t cmd_syn_filter_high =
7319         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7320                                 high, "high#low");
7321 cmdline_parse_token_string_t cmd_syn_filter_queue =
7322         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7323                                 queue, "queue");
7324 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7325         TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
7326                                 queue_id, UINT16);
7327 cmdline_parse_token_string_t cmd_syn_filter_add_filter =
7328         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7329                                 filter, "add_syn_filter");
7330 cmdline_parse_token_string_t cmd_syn_filter_remove_filter =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7332                                 filter, "remove_syn_filter");
7333 cmdline_parse_inst_t cmd_add_syn_filter = {
7334                 .f = cmd_set_syn_filter_parsed,
7335                 .data = NULL,
7336                 .help_str = "add syn filter",
7337                 .tokens = {
7338                         (void *)&cmd_syn_filter_add_filter,
7339                         (void *)&cmd_syn_filter_portid,
7340                         (void *)&cmd_syn_filter_priority,
7341                         (void *)&cmd_syn_filter_high,
7342                         (void *)&cmd_syn_filter_queue,
7343                         (void *)&cmd_syn_filter_queue_id,
7344                         NULL,
7345                 },
7346 };
7347 cmdline_parse_inst_t cmd_remove_syn_filter = {
7348                 .f = cmd_set_syn_filter_parsed,
7349                 .data = NULL,
7350                 .help_str = "remove syn filter",
7351                 .tokens = {
7352                         (void *)&cmd_syn_filter_remove_filter,
7353                         (void *)&cmd_syn_filter_portid,
7354                         NULL,
7355                 },
7356 };
7357
7358 cmdline_parse_token_string_t cmd_syn_filter_get_filter =
7359         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
7360                                 filter, "get_syn_filter");
7361
7362 cmdline_parse_inst_t cmd_get_syn_filter = {
7363                 .f = cmd_set_syn_filter_parsed,
7364                 .data = NULL,
7365                 .help_str = "get syn filter",
7366                 .tokens = {
7367                         (void *)&cmd_syn_filter_get_filter,
7368                         (void *)&cmd_syn_filter_portid,
7369                         NULL,
7370                 },
7371 };
7372
7373 /* *** ADD/REMOVE A 2tuple FILTER *** */
7374 struct cmd_2tuple_filter_result {
7375         cmdline_fixed_string_t filter;
7376         uint8_t port_id;
7377         cmdline_fixed_string_t protocol;
7378         uint8_t protocol_value;
7379         uint8_t protocol_mask;
7380         cmdline_fixed_string_t dst_port;
7381         uint16_t dst_port_value;
7382         uint16_t dst_port_mask;
7383         cmdline_fixed_string_t flags;
7384         uint8_t flags_value;
7385         cmdline_fixed_string_t priority;
7386         uint8_t priority_value;
7387         cmdline_fixed_string_t queue;
7388         uint16_t queue_id;
7389         cmdline_fixed_string_t index;
7390         uint16_t index_value;
7391 };
7392
7393 static void
7394 cmd_2tuple_filter_parsed(void *parsed_result,
7395                         __attribute__((unused)) struct cmdline *cl,
7396                         __attribute__((unused)) void *data)
7397 {
7398         int ret = 0;
7399         struct rte_2tuple_filter filter;
7400         struct cmd_2tuple_filter_result *res = parsed_result;
7401
7402         memset(&filter, 0, sizeof(struct rte_2tuple_filter));
7403
7404         if (!strcmp(res->filter, "add_2tuple_filter")) {
7405                 /* need convert to big endian. */
7406                 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7407                 filter.protocol = res->protocol_value;
7408                 filter.dst_port_mask = (res->dst_port_mask) ? 0 : 1;
7409                 filter.protocol_mask = (res->protocol_mask) ? 0 : 1;
7410                 filter.priority = res->priority_value;
7411                 filter.tcp_flags = res->flags_value;
7412                 ret = rte_eth_dev_add_2tuple_filter(res->port_id,
7413                         res->index_value, &filter, res->queue_id);
7414         } else if (!strcmp(res->filter, "remove_2tuple_filter"))
7415                 ret = rte_eth_dev_remove_2tuple_filter(res->port_id,
7416                         res->index_value);
7417         else if (!strcmp(res->filter, "get_2tuple_filter"))
7418                 get_2tuple_filter(res->port_id, res->index_value);
7419
7420         if (ret < 0)
7421                 printf("2tuple filter setting error: (%s)\n", strerror(-ret));
7422 }
7423
7424 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7425         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7426                                 port_id, UINT8);
7427 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7428         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7429                                  protocol, "protocol");
7430 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7431         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7432                                  protocol_value, UINT8);
7433 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_mask =
7434         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7435                                 protocol_mask, UINT8);
7436 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7437         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7438                                 dst_port, "dst_port");
7439 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7440         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7441                                 dst_port_value, UINT16);
7442 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_mask =
7443         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7444                                 dst_port_mask, UINT16);
7445 cmdline_parse_token_string_t cmd_2tuple_filter_flags =
7446         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7447                                 flags, "flags");
7448 cmdline_parse_token_num_t cmd_2tuple_filter_flags_value =
7449         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7450                                 flags_value, UINT8);
7451 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7452         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7453                                 priority, "priority");
7454 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7455         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7456                                 priority_value, UINT8);
7457 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7458         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7459                                 queue, "queue");
7460 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7461         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7462                                 queue_id, UINT16);
7463 cmdline_parse_token_string_t cmd_2tuple_filter_index =
7464         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7465                                 index, "index");
7466 cmdline_parse_token_num_t cmd_2tuple_filter_index_value =
7467         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7468                                 index_value, UINT16);
7469 cmdline_parse_token_string_t cmd_2tuple_filter_add_filter =
7470         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7471                                 filter, "add_2tuple_filter");
7472 cmdline_parse_inst_t cmd_add_2tuple_filter = {
7473         .f = cmd_2tuple_filter_parsed,
7474         .data = NULL,
7475         .help_str = "add a 2tuple filter",
7476         .tokens = {
7477                 (void *)&cmd_2tuple_filter_add_filter,
7478                 (void *)&cmd_2tuple_filter_port_id,
7479                 (void *)&cmd_2tuple_filter_protocol,
7480                 (void *)&cmd_2tuple_filter_protocol_value,
7481                 (void *)&cmd_2tuple_filter_protocol_mask,
7482                 (void *)&cmd_2tuple_filter_dst_port,
7483                 (void *)&cmd_2tuple_filter_dst_port_value,
7484                 (void *)&cmd_2tuple_filter_dst_port_mask,
7485                 (void *)&cmd_2tuple_filter_flags,
7486                 (void *)&cmd_2tuple_filter_flags_value,
7487                 (void *)&cmd_2tuple_filter_priority,
7488                 (void *)&cmd_2tuple_filter_priority_value,
7489                 (void *)&cmd_2tuple_filter_queue,
7490                 (void *)&cmd_2tuple_filter_queue_id,
7491                 (void *)&cmd_2tuple_filter_index,
7492                 (void *)&cmd_2tuple_filter_index_value,
7493                 NULL,
7494         },
7495 };
7496
7497 cmdline_parse_token_string_t cmd_2tuple_filter_remove_filter =
7498         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7499                                 filter, "remove_2tuple_filter");
7500 cmdline_parse_inst_t cmd_remove_2tuple_filter = {
7501         .f = cmd_2tuple_filter_parsed,
7502         .data = NULL,
7503         .help_str = "remove a 2tuple filter",
7504         .tokens = {
7505                 (void *)&cmd_2tuple_filter_remove_filter,
7506                 (void *)&cmd_2tuple_filter_port_id,
7507                 (void *)&cmd_2tuple_filter_index,
7508                 (void *)&cmd_2tuple_filter_index_value,
7509                 NULL,
7510         },
7511 };
7512 cmdline_parse_token_string_t cmd_2tuple_filter_get_filter =
7513         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7514                                 filter, "get_2tuple_filter");
7515 cmdline_parse_inst_t cmd_get_2tuple_filter = {
7516         .f = cmd_2tuple_filter_parsed,
7517         .data = NULL,
7518         .help_str = "get a 2tuple filter",
7519         .tokens = {
7520                 (void *)&cmd_2tuple_filter_get_filter,
7521                 (void *)&cmd_2tuple_filter_port_id,
7522                 (void *)&cmd_2tuple_filter_index,
7523                 (void *)&cmd_2tuple_filter_index_value,
7524                 NULL,
7525         },
7526 };
7527
7528 /* *** ADD/REMOVE A 5tuple FILTER *** */
7529 struct cmd_5tuple_filter_result {
7530         cmdline_fixed_string_t filter;
7531         uint8_t  port_id;
7532         cmdline_fixed_string_t dst_ip;
7533         cmdline_ipaddr_t dst_ip_value;
7534         cmdline_fixed_string_t src_ip;
7535         cmdline_ipaddr_t src_ip_value;
7536         cmdline_fixed_string_t dst_port;
7537         uint16_t dst_port_value;
7538         cmdline_fixed_string_t src_port;
7539         uint16_t src_port_value;
7540         cmdline_fixed_string_t protocol;
7541         uint8_t protocol_value;
7542         cmdline_fixed_string_t mask;
7543         uint8_t  mask_value;
7544         cmdline_fixed_string_t flags;
7545         uint8_t flags_value;
7546         cmdline_fixed_string_t priority;
7547         uint8_t  priority_value;
7548         cmdline_fixed_string_t queue;
7549         uint16_t  queue_id;
7550         cmdline_fixed_string_t index;
7551         uint16_t  index_value;
7552 };
7553
7554 static void
7555 cmd_5tuple_filter_parsed(void *parsed_result,
7556                         __attribute__((unused)) struct cmdline *cl,
7557                         __attribute__((unused)) void *data)
7558 {
7559         int ret = 0;
7560         struct rte_5tuple_filter filter;
7561         struct cmd_5tuple_filter_result *res = parsed_result;
7562
7563         memset(&filter, 0, sizeof(struct rte_5tuple_filter));
7564
7565         if (!strcmp(res->filter, "add_5tuple_filter")) {
7566                 filter.dst_ip_mask = (res->mask_value & 0x10) ? 0 : 1;
7567                 filter.src_ip_mask = (res->mask_value & 0x08) ? 0 : 1;
7568                 filter.dst_port_mask = (res->mask_value & 0x04) ? 0 : 1;
7569                 filter.src_port_mask = (res->mask_value & 0x02) ? 0 : 1;
7570                 filter.protocol = res->protocol_value;
7571                 filter.protocol_mask = (res->mask_value & 0x01) ? 0 : 1;
7572                 filter.priority = res->priority_value;
7573                 filter.tcp_flags = res->flags_value;
7574
7575                 if (res->dst_ip_value.family == AF_INET)
7576                         /* no need to convert, already big endian. */
7577                         filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7578                 else {
7579                         if (filter.dst_ip_mask == 0) {
7580                                 printf("can not support ipv6 involved compare.\n");
7581                                 return;
7582                         }
7583                         filter.dst_ip = 0;
7584                 }
7585
7586                 if (res->src_ip_value.family == AF_INET)
7587                         /* no need to convert, already big endian. */
7588                         filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7589                 else {
7590                         if (filter.src_ip_mask == 0) {
7591                                 printf("can not support ipv6 involved compare.\n");
7592                                 return;
7593                         }
7594                         filter.src_ip = 0;
7595                 }
7596                 /* need convert to big endian. */
7597                 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7598                 filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7599
7600                 ret = rte_eth_dev_add_5tuple_filter(res->port_id,
7601                         res->index_value, &filter, res->queue_id);
7602         } else if (!strcmp(res->filter, "remove_5tuple_filter"))
7603                 ret = rte_eth_dev_remove_5tuple_filter(res->port_id,
7604                         res->index_value);
7605         else if (!strcmp(res->filter, "get_5tuple_filter"))
7606                 get_5tuple_filter(res->port_id, res->index_value);
7607         if (ret < 0)
7608                 printf("5tuple filter setting error: (%s)\n", strerror(-ret));
7609 }
7610
7611
7612 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7613         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7614                                 port_id, UINT8);
7615 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7616         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7617                                 dst_ip, "dst_ip");
7618 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7619         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7620                                 dst_ip_value);
7621 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7622         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7623                                 src_ip, "src_ip");
7624 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7625         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7626                                 src_ip_value);
7627 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7628         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7629                                 dst_port, "dst_port");
7630 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7631         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7632                                 dst_port_value, UINT16);
7633 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7634         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7635                                 src_port, "src_port");
7636 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7637         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7638                                 src_port_value, UINT16);
7639 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7640         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7641                                 protocol, "protocol");
7642 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7643         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7644                                 protocol_value, UINT8);
7645 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7646         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7647                                 mask, "mask");
7648 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7649         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7650                                 mask_value, INT8);
7651 cmdline_parse_token_string_t cmd_5tuple_filter_flags =
7652         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7653                                 flags, "flags");
7654 cmdline_parse_token_num_t cmd_5tuple_filter_flags_value =
7655         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7656                                 flags_value, UINT8);
7657 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7658         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7659                                 priority, "priority");
7660 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7661         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7662                                 priority_value, UINT8);
7663 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7664         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7665                                 queue, "queue");
7666 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7667         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7668                                 queue_id, UINT16);
7669 cmdline_parse_token_string_t cmd_5tuple_filter_index =
7670         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7671                                 index, "index");
7672 cmdline_parse_token_num_t cmd_5tuple_filter_index_value =
7673         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7674                                 index_value, UINT16);
7675
7676 cmdline_parse_token_string_t cmd_5tuple_filter_add_filter =
7677         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7678                                  filter, "add_5tuple_filter");
7679 cmdline_parse_inst_t cmd_add_5tuple_filter = {
7680         .f = cmd_5tuple_filter_parsed,
7681         .data = NULL,
7682         .help_str = "add a 5tuple filter",
7683         .tokens = {
7684                 (void *)&cmd_5tuple_filter_add_filter,
7685                 (void *)&cmd_5tuple_filter_port_id,
7686                 (void *)&cmd_5tuple_filter_dst_ip,
7687                 (void *)&cmd_5tuple_filter_dst_ip_value,
7688                 (void *)&cmd_5tuple_filter_src_ip,
7689                 (void *)&cmd_5tuple_filter_src_ip_value,
7690                 (void *)&cmd_5tuple_filter_dst_port,
7691                 (void *)&cmd_5tuple_filter_dst_port_value,
7692                 (void *)&cmd_5tuple_filter_src_port,
7693                 (void *)&cmd_5tuple_filter_src_port_value,
7694                 (void *)&cmd_5tuple_filter_protocol,
7695                 (void *)&cmd_5tuple_filter_protocol_value,
7696                 (void *)&cmd_5tuple_filter_mask,
7697                 (void *)&cmd_5tuple_filter_mask_value,
7698                 (void *)&cmd_5tuple_filter_flags,
7699                 (void *)&cmd_5tuple_filter_flags_value,
7700                 (void *)&cmd_5tuple_filter_priority,
7701                 (void *)&cmd_5tuple_filter_priority_value,
7702                 (void *)&cmd_5tuple_filter_queue,
7703                 (void *)&cmd_5tuple_filter_queue_id,
7704                 (void *)&cmd_5tuple_filter_index,
7705                 (void *)&cmd_5tuple_filter_index_value,
7706                 NULL,
7707         },
7708 };
7709
7710 cmdline_parse_token_string_t cmd_5tuple_filter_remove_filter =
7711         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7712                                 filter, "remove_5tuple_filter");
7713 cmdline_parse_inst_t cmd_remove_5tuple_filter = {
7714         .f = cmd_5tuple_filter_parsed,
7715         .data = NULL,
7716         .help_str = "remove a 5tuple filter",
7717         .tokens = {
7718                 (void *)&cmd_5tuple_filter_remove_filter,
7719                 (void *)&cmd_5tuple_filter_port_id,
7720                 (void *)&cmd_5tuple_filter_index,
7721                 (void *)&cmd_5tuple_filter_index_value,
7722                 NULL,
7723         },
7724 };
7725
7726 cmdline_parse_token_string_t cmd_5tuple_filter_get_filter =
7727         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7728                                 filter, "get_5tuple_filter");
7729 cmdline_parse_inst_t cmd_get_5tuple_filter = {
7730         .f = cmd_5tuple_filter_parsed,
7731         .data = NULL,
7732         .help_str = "get a 5tuple filter",
7733         .tokens = {
7734                 (void *)&cmd_5tuple_filter_get_filter,
7735                 (void *)&cmd_5tuple_filter_port_id,
7736                 (void *)&cmd_5tuple_filter_index,
7737                 (void *)&cmd_5tuple_filter_index_value,
7738                 NULL,
7739         },
7740 };
7741
7742 /* *** ADD/REMOVE A flex FILTER *** */
7743 struct cmd_flex_filter_result {
7744         cmdline_fixed_string_t filter;
7745         uint8_t port_id;
7746         cmdline_fixed_string_t len;
7747         uint8_t len_value;
7748         cmdline_fixed_string_t bytes;
7749         cmdline_fixed_string_t bytes_value;
7750         cmdline_fixed_string_t mask;
7751         cmdline_fixed_string_t mask_value;
7752         cmdline_fixed_string_t priority;
7753         uint8_t priority_value;
7754         cmdline_fixed_string_t queue;
7755         uint16_t queue_id;
7756         cmdline_fixed_string_t index;
7757         uint16_t index_value;
7758 };
7759
7760 static int xdigit2val(unsigned char c)
7761 {
7762         int val;
7763         if (isdigit(c))
7764                 val = c - '0';
7765         else if (isupper(c))
7766                 val = c - 'A' + 10;
7767         else
7768                 val = c - 'a' + 10;
7769         return val;
7770 }
7771
7772 static void
7773 cmd_flex_filter_parsed(void *parsed_result,
7774                           __attribute__((unused)) struct cmdline *cl,
7775                           __attribute__((unused)) void *data)
7776 {
7777         int ret = 0;
7778         struct rte_flex_filter filter;
7779         struct cmd_flex_filter_result *res = parsed_result;
7780         char *bytes_ptr, *mask_ptr;
7781         uint16_t len, i, j;
7782         char c;
7783         int val, mod = 0;
7784         uint32_t dword = 0;
7785         uint8_t byte = 0;
7786         uint8_t hex = 0;
7787
7788         if (!strcmp(res->filter, "add_flex_filter")) {
7789                 if (res->len_value > 128) {
7790                         printf("the len exceed the max length 128\n");
7791                         return;
7792                 }
7793                 memset(&filter, 0, sizeof(struct rte_flex_filter));
7794                 filter.len = res->len_value;
7795                 filter.priority = res->priority_value;
7796                 bytes_ptr = res->bytes_value;
7797                 mask_ptr = res->mask_value;
7798
7799                 j = 0;
7800                  /* translate bytes string to uint_32 array. */
7801                 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7802                         (bytes_ptr[1] == 'X')))
7803                         bytes_ptr += 2;
7804                 len = strnlen(bytes_ptr, res->len_value * 2);
7805                 if (len == 0 || (len % 8 != 0)) {
7806                         printf("please check len and bytes input\n");
7807                         return;
7808                 }
7809                 for (i = 0; i < len; i++) {
7810                         c = bytes_ptr[i];
7811                         if (isxdigit(c) == 0) {
7812                                 /* invalid characters. */
7813                                 printf("invalid input\n");
7814                                 return;
7815                         }
7816                         val = xdigit2val(c);
7817                         mod = i % 8;
7818                         if (i % 2) {
7819                                 byte |= val;
7820                                 dword |= byte << (4 * mod - 4);
7821                                 byte = 0;
7822                         } else
7823                                 byte |= val << 4;
7824                         if (mod == 7) {
7825                                 filter.dwords[j] = dword;
7826                                 printf("dwords[%d]:%08x ", j, filter.dwords[j]);
7827                                 j++;
7828                                 dword = 0;
7829                         }
7830                 }
7831                 printf("\n");
7832                  /* translate mask string to uint8_t array. */
7833                 j = 0;
7834                 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7835                         (mask_ptr[1] == 'X')))
7836                         mask_ptr += 2;
7837                 len = strnlen(mask_ptr, (res->len_value+3)/4);
7838                 if (len == 0) {
7839                         printf("invalid input\n");
7840                         return;
7841                 }
7842                 for (i = 0; i < len; i++) {
7843                         c = mask_ptr[i];
7844                         if (isxdigit(c) == 0) {
7845                                 /* invalid characters. */
7846                                 printf("invalid input\n");
7847                                 return;
7848                         }
7849                         val = xdigit2val(c);
7850                         hex |= (uint8_t)(val & 0x8) >> 3;
7851                         hex |= (uint8_t)(val & 0x4) >> 1;
7852                         hex |= (uint8_t)(val & 0x2) << 1;
7853                         hex |= (uint8_t)(val & 0x1) << 3;
7854                         if (i % 2) {
7855                                 byte |= hex << 4;
7856                                 filter.mask[j] = byte;
7857                                 printf("mask[%d]:%02x ", j, filter.mask[j]);
7858                                 j++;
7859                                 byte = 0;
7860                         } else
7861                                 byte |= hex;
7862                         hex = 0;
7863                 }
7864                 printf("\n");
7865                 printf("call function rte_eth_dev_add_flex_filter: "
7866                         "index = %d, queue-id = %d, len = %d, priority = %d\n",
7867                         res->index_value, res->queue_id,
7868                         filter.len, filter.priority);
7869                 ret = rte_eth_dev_add_flex_filter(res->port_id, res->index_value,
7870                                 &filter, res->queue_id);
7871
7872         } else if (!strcmp(res->filter, "remove_flex_filter"))
7873                 ret = rte_eth_dev_remove_flex_filter(res->port_id,
7874                         res->index_value);
7875         else if (!strcmp(res->filter, "get_flex_filter"))
7876                 get_flex_filter(res->port_id, res->index_value);
7877
7878         if (ret < 0)
7879                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7880 }
7881
7882 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7883         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7884                                 port_id, UINT8);
7885 cmdline_parse_token_string_t cmd_flex_filter_len =
7886         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7887                                 len, "len");
7888 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7889         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7890                                 len_value, UINT8);
7891 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7892         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7893                                 bytes, "bytes");
7894 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7895         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7896                                 bytes_value, NULL);
7897 cmdline_parse_token_string_t cmd_flex_filter_mask =
7898         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7899                                 mask, "mask");
7900 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7901         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7902                                 mask_value, NULL);
7903 cmdline_parse_token_string_t cmd_flex_filter_priority =
7904         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7905                                 priority, "priority");
7906 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7907         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7908                                 priority_value, UINT8);
7909 cmdline_parse_token_string_t cmd_flex_filter_queue =
7910         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7911                                 queue, "queue");
7912 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7913         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7914                                 queue_id, UINT16);
7915 cmdline_parse_token_string_t cmd_flex_filter_index =
7916         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7917                                 index, "index");
7918 cmdline_parse_token_num_t cmd_flex_filter_index_value =
7919         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7920                                 index_value, UINT16);
7921 cmdline_parse_token_string_t cmd_flex_filter_add_filter =
7922         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7923                                 filter, "add_flex_filter");
7924 cmdline_parse_inst_t cmd_add_flex_filter = {
7925         .f = cmd_flex_filter_parsed,
7926         .data = NULL,
7927         .help_str = "add a flex filter",
7928         .tokens = {
7929                 (void *)&cmd_flex_filter_add_filter,
7930                 (void *)&cmd_flex_filter_port_id,
7931                 (void *)&cmd_flex_filter_len,
7932                 (void *)&cmd_flex_filter_len_value,
7933                 (void *)&cmd_flex_filter_bytes,
7934                 (void *)&cmd_flex_filter_bytes_value,
7935                 (void *)&cmd_flex_filter_mask,
7936                 (void *)&cmd_flex_filter_mask_value,
7937                 (void *)&cmd_flex_filter_priority,
7938                 (void *)&cmd_flex_filter_priority_value,
7939                 (void *)&cmd_flex_filter_queue,
7940                 (void *)&cmd_flex_filter_queue_id,
7941                 (void *)&cmd_flex_filter_index,
7942                 (void *)&cmd_flex_filter_index_value,
7943                 NULL,
7944         },
7945 };
7946
7947 cmdline_parse_token_string_t cmd_flex_filter_remove_filter =
7948         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7949                                 filter, "remove_flex_filter");
7950 cmdline_parse_inst_t cmd_remove_flex_filter = {
7951         .f = cmd_flex_filter_parsed,
7952         .data = NULL,
7953         .help_str = "remove a flex filter",
7954         .tokens = {
7955                 (void *)&cmd_flex_filter_remove_filter,
7956                 (void *)&cmd_flex_filter_port_id,
7957                 (void *)&cmd_flex_filter_index,
7958                 (void *)&cmd_flex_filter_index_value,
7959                 NULL,
7960         },
7961 };
7962
7963 cmdline_parse_token_string_t cmd_flex_filter_get_filter =
7964         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7965                                 filter, "get_flex_filter");
7966 cmdline_parse_inst_t cmd_get_flex_filter = {
7967         .f = cmd_flex_filter_parsed,
7968         .data = NULL,
7969         .help_str = "get a flex filter",
7970         .tokens = {
7971                 (void *)&cmd_flex_filter_get_filter,
7972                 (void *)&cmd_flex_filter_port_id,
7973                 (void *)&cmd_flex_filter_index,
7974                 (void *)&cmd_flex_filter_index_value,
7975                 NULL,
7976         },
7977 };
7978
7979 /* *** Filters Control *** */
7980
7981 /* *** deal with ethertype filter *** */
7982 struct cmd_ethertype_filter_result {
7983         cmdline_fixed_string_t filter;
7984         uint8_t port_id;
7985         cmdline_fixed_string_t ops;
7986         cmdline_fixed_string_t mac;
7987         struct ether_addr mac_addr;
7988         cmdline_fixed_string_t ethertype;
7989         uint16_t ethertype_value;
7990         cmdline_fixed_string_t drop;
7991         cmdline_fixed_string_t queue;
7992         uint16_t  queue_id;
7993 };
7994
7995 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7996         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7997                                  filter, "ethertype_filter");
7998 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7999         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8000                               port_id, UINT8);
8001 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8002         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8003                                  ops, "add#del");
8004 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8005         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8006                                  mac, "mac_addr#mac_ignr");
8007 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8008         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8009                                      mac_addr);
8010 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8011         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8012                                  ethertype, "ethertype");
8013 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8014         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8015                               ethertype_value, UINT16);
8016 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8017         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8018                                  drop, "drop#fwd");
8019 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8020         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8021                                  queue, "queue");
8022 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8023         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8024                               queue_id, UINT16);
8025
8026 static void
8027 cmd_ethertype_filter_parsed(void *parsed_result,
8028                           __attribute__((unused)) struct cmdline *cl,
8029                           __attribute__((unused)) void *data)
8030 {
8031         struct cmd_ethertype_filter_result *res = parsed_result;
8032         struct rte_eth_ethertype_filter filter;
8033         int ret = 0;
8034
8035         ret = rte_eth_dev_filter_supported(res->port_id,
8036                         RTE_ETH_FILTER_ETHERTYPE);
8037         if (ret < 0) {
8038                 printf("ethertype filter is not supported on port %u.\n",
8039                         res->port_id);
8040                 return;
8041         }
8042
8043         memset(&filter, 0, sizeof(filter));
8044         if (!strcmp(res->mac, "mac_addr")) {
8045                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8046                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8047                         sizeof(struct ether_addr));
8048         }
8049         if (!strcmp(res->drop, "drop"))
8050                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8051         filter.ether_type = res->ethertype_value;
8052         filter.queue = res->queue_id;
8053
8054         if (!strcmp(res->ops, "add"))
8055                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8056                                 RTE_ETH_FILTER_ETHERTYPE,
8057                                 RTE_ETH_FILTER_ADD,
8058                                 &filter);
8059         else
8060                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8061                                 RTE_ETH_FILTER_ETHERTYPE,
8062                                 RTE_ETH_FILTER_DELETE,
8063                                 &filter);
8064         if (ret < 0)
8065                 printf("ethertype filter programming error: (%s)\n",
8066                         strerror(-ret));
8067 }
8068
8069 cmdline_parse_inst_t cmd_ethertype_filter = {
8070         .f = cmd_ethertype_filter_parsed,
8071         .data = NULL,
8072         .help_str = "add or delete an ethertype filter entry",
8073         .tokens = {
8074                 (void *)&cmd_ethertype_filter_filter,
8075                 (void *)&cmd_ethertype_filter_port_id,
8076                 (void *)&cmd_ethertype_filter_ops,
8077                 (void *)&cmd_ethertype_filter_mac,
8078                 (void *)&cmd_ethertype_filter_mac_addr,
8079                 (void *)&cmd_ethertype_filter_ethertype,
8080                 (void *)&cmd_ethertype_filter_ethertype_value,
8081                 (void *)&cmd_ethertype_filter_drop,
8082                 (void *)&cmd_ethertype_filter_queue,
8083                 (void *)&cmd_ethertype_filter_queue_id,
8084                 NULL,
8085         },
8086 };
8087
8088 /* *** deal with flow director filter *** */
8089 struct cmd_flow_director_result {
8090         cmdline_fixed_string_t flow_director_filter;
8091         uint8_t port_id;
8092         cmdline_fixed_string_t ops;
8093         cmdline_fixed_string_t flow;
8094         cmdline_fixed_string_t flow_type;
8095         cmdline_fixed_string_t src;
8096         cmdline_ipaddr_t ip_src;
8097         uint16_t port_src;
8098         cmdline_fixed_string_t dst;
8099         cmdline_ipaddr_t ip_dst;
8100         uint16_t port_dst;
8101         cmdline_fixed_string_t verify_tag;
8102         uint32_t verify_tag_value;
8103         cmdline_fixed_string_t flexbytes;
8104         cmdline_fixed_string_t flexbytes_value;
8105         cmdline_fixed_string_t drop;
8106         cmdline_fixed_string_t queue;
8107         uint16_t  queue_id;
8108         cmdline_fixed_string_t fd_id;
8109         uint32_t  fd_id_value;
8110 };
8111
8112 static inline int
8113 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8114 {
8115         char s[256];
8116         const char *p, *p0 = q_arg;
8117         char *end;
8118         unsigned long int_fld;
8119         char *str_fld[max_num];
8120         int i;
8121         unsigned size;
8122         int ret = -1;
8123
8124         p = strchr(p0, '(');
8125         if (p == NULL)
8126                 return -1;
8127         ++p;
8128         p0 = strchr(p, ')');
8129         if (p0 == NULL)
8130                 return -1;
8131
8132         size = p0 - p;
8133         if (size >= sizeof(s))
8134                 return -1;
8135
8136         snprintf(s, sizeof(s), "%.*s", size, p);
8137         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8138         if (ret < 0 || ret > max_num)
8139                 return -1;
8140         for (i = 0; i < ret; i++) {
8141                 errno = 0;
8142                 int_fld = strtoul(str_fld[i], &end, 0);
8143                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8144                         return -1;
8145                 flexbytes[i] = (uint8_t)int_fld;
8146         }
8147         return ret;
8148 }
8149
8150 static enum rte_eth_flow_type
8151 str2flowtype(char *string)
8152 {
8153         uint8_t i = 0;
8154         static const struct {
8155                 char str[32];
8156                 enum rte_eth_flow_type type;
8157         } flowtype_str[] = {
8158                 {"ip4", RTE_ETH_FLOW_TYPE_IPV4_OTHER},
8159                 {"ip4-frag", RTE_ETH_FLOW_TYPE_FRAG_IPV4},
8160                 {"udp4", RTE_ETH_FLOW_TYPE_UDPV4},
8161                 {"tcp4", RTE_ETH_FLOW_TYPE_TCPV4},
8162                 {"sctp4", RTE_ETH_FLOW_TYPE_SCTPV4},
8163                 {"ip6", RTE_ETH_FLOW_TYPE_IPV6_OTHER},
8164                 {"ip6-frag", RTE_ETH_FLOW_TYPE_FRAG_IPV6},
8165                 {"udp6", RTE_ETH_FLOW_TYPE_UDPV6},
8166                 {"tcp6", RTE_ETH_FLOW_TYPE_TCPV6},
8167                 {"sctp6", RTE_ETH_FLOW_TYPE_TCPV6},
8168         };
8169
8170         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8171                 if (!strcmp(flowtype_str[i].str, string))
8172                         return flowtype_str[i].type;
8173         }
8174         return RTE_ETH_FLOW_TYPE_NONE;
8175 }
8176
8177 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8178 do { \
8179         if ((ip_addr).family == AF_INET) \
8180                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8181         else { \
8182                 printf("invalid parameter.\n"); \
8183                 return; \
8184         } \
8185 } while (0)
8186
8187 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8188 do { \
8189         if ((ip_addr).family == AF_INET6) \
8190                 (void)rte_memcpy(&(ip), \
8191                                  &((ip_addr).addr.ipv6), \
8192                                  sizeof(struct in6_addr)); \
8193         else { \
8194                 printf("invalid parameter.\n"); \
8195                 return; \
8196         } \
8197 } while (0)
8198
8199 static void
8200 cmd_flow_director_filter_parsed(void *parsed_result,
8201                           __attribute__((unused)) struct cmdline *cl,
8202                           __attribute__((unused)) void *data)
8203 {
8204         struct cmd_flow_director_result *res = parsed_result;
8205         struct rte_eth_fdir_filter entry;
8206         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8207         int ret = 0;
8208
8209         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8210         if (ret < 0) {
8211                 printf("flow director is not supported on port %u.\n",
8212                         res->port_id);
8213                 return;
8214         }
8215         memset(flexbytes, 0, sizeof(flexbytes));
8216         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8217         ret = parse_flexbytes(res->flexbytes_value,
8218                                         flexbytes,
8219                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8220         if (ret < 0) {
8221                 printf("error: Cannot parse flexbytes input.\n");
8222                 return;
8223         }
8224
8225         entry.input.flow_type = str2flowtype(res->flow_type);
8226         switch (entry.input.flow_type) {
8227         case RTE_ETH_FLOW_TYPE_IPV4_OTHER:
8228         case RTE_ETH_FLOW_TYPE_UDPV4:
8229         case RTE_ETH_FLOW_TYPE_TCPV4:
8230                 IPV4_ADDR_TO_UINT(res->ip_dst,
8231                         entry.input.flow.ip4_flow.dst_ip);
8232                 IPV4_ADDR_TO_UINT(res->ip_src,
8233                         entry.input.flow.ip4_flow.src_ip);
8234                 /* need convert to big endian. */
8235                 entry.input.flow.udp4_flow.dst_port =
8236                                 rte_cpu_to_be_16(res->port_dst);
8237                 entry.input.flow.udp4_flow.src_port =
8238                                 rte_cpu_to_be_16(res->port_src);
8239                 break;
8240         case RTE_ETH_FLOW_TYPE_SCTPV4:
8241                 IPV4_ADDR_TO_UINT(res->ip_dst,
8242                         entry.input.flow.sctp4_flow.ip.dst_ip);
8243                 IPV4_ADDR_TO_UINT(res->ip_src,
8244                         entry.input.flow.sctp4_flow.ip.src_ip);
8245                 /* need convert to big endian. */
8246                 entry.input.flow.sctp4_flow.verify_tag =
8247                                 rte_cpu_to_be_32(res->verify_tag_value);
8248                 break;
8249         case RTE_ETH_FLOW_TYPE_IPV6_OTHER:
8250         case RTE_ETH_FLOW_TYPE_UDPV6:
8251         case RTE_ETH_FLOW_TYPE_TCPV6:
8252                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8253                         entry.input.flow.ipv6_flow.dst_ip);
8254                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8255                         entry.input.flow.ipv6_flow.src_ip);
8256                 /* need convert to big endian. */
8257                 entry.input.flow.udp6_flow.dst_port =
8258                                 rte_cpu_to_be_16(res->port_dst);
8259                 entry.input.flow.udp6_flow.src_port =
8260                                 rte_cpu_to_be_16(res->port_src);
8261                 break;
8262         case RTE_ETH_FLOW_TYPE_SCTPV6:
8263                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8264                         entry.input.flow.sctp6_flow.ip.dst_ip);
8265                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8266                         entry.input.flow.sctp6_flow.ip.src_ip);
8267                 /* need convert to big endian. */
8268                 entry.input.flow.sctp6_flow.verify_tag =
8269                                 rte_cpu_to_be_32(res->verify_tag_value);
8270                 break;
8271         default:
8272                 printf("invalid parameter.\n");
8273                 return;
8274         }
8275         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8276                    flexbytes,
8277                    RTE_ETH_FDIR_MAX_FLEXLEN);
8278
8279         entry.action.flex_off = 0;  /*use 0 by default */
8280         if (!strcmp(res->drop, "drop"))
8281                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8282         else
8283                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8284         /* set to report FD ID by default */
8285         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8286         entry.action.rx_queue = res->queue_id;
8287         entry.soft_id = res->fd_id_value;
8288         if (!strcmp(res->ops, "add"))
8289                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8290                                              RTE_ETH_FILTER_ADD, &entry);
8291         else
8292                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8293                                              RTE_ETH_FILTER_DELETE, &entry);
8294         if (ret < 0)
8295                 printf("flow director programming error: (%s)\n",
8296                         strerror(-ret));
8297 }
8298
8299 cmdline_parse_token_string_t cmd_flow_director_filter =
8300         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8301                                  flow_director_filter, "flow_director_filter");
8302 cmdline_parse_token_num_t cmd_flow_director_port_id =
8303         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8304                               port_id, UINT8);
8305 cmdline_parse_token_string_t cmd_flow_director_ops =
8306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8307                                  ops, "add#del");
8308 cmdline_parse_token_string_t cmd_flow_director_flow =
8309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8310                                  flow, "flow");
8311 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8313                                  flow_type,
8314                                  "ip4#ip4-frag#tcp4#udp4#sctp4#"
8315                                  "ip6#ip6-frag#tcp6#udp6#sctp6");
8316 cmdline_parse_token_string_t cmd_flow_director_src =
8317         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8318                                  src, "src");
8319 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8320         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8321                                  ip_src);
8322 cmdline_parse_token_num_t cmd_flow_director_port_src =
8323         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8324                               port_src, UINT16);
8325 cmdline_parse_token_string_t cmd_flow_director_dst =
8326         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8327                                  dst, "dst");
8328 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8329         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8330                                  ip_dst);
8331 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8332         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8333                               port_dst, UINT16);
8334 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8335         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8336                                   verify_tag, "verify_tag");
8337 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8338         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8339                               verify_tag_value, UINT32);
8340 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8342                                  flexbytes, "flexbytes");
8343 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8345                               flexbytes_value, NULL);
8346 cmdline_parse_token_string_t cmd_flow_director_drop =
8347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8348                                  drop, "drop#fwd");
8349 cmdline_parse_token_string_t cmd_flow_director_queue =
8350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8351                                  queue, "queue");
8352 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8353         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8354                               queue_id, UINT16);
8355 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8357                                  fd_id, "fd_id");
8358 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8359         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8360                               fd_id_value, UINT32);
8361
8362 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8363         .f = cmd_flow_director_filter_parsed,
8364         .data = NULL,
8365         .help_str = "add or delete an ip flow director entry on NIC",
8366         .tokens = {
8367                 (void *)&cmd_flow_director_filter,
8368                 (void *)&cmd_flow_director_port_id,
8369                 (void *)&cmd_flow_director_ops,
8370                 (void *)&cmd_flow_director_flow,
8371                 (void *)&cmd_flow_director_flow_type,
8372                 (void *)&cmd_flow_director_src,
8373                 (void *)&cmd_flow_director_ip_src,
8374                 (void *)&cmd_flow_director_dst,
8375                 (void *)&cmd_flow_director_ip_dst,
8376                 (void *)&cmd_flow_director_flexbytes,
8377                 (void *)&cmd_flow_director_flexbytes_value,
8378                 (void *)&cmd_flow_director_drop,
8379                 (void *)&cmd_flow_director_queue,
8380                 (void *)&cmd_flow_director_queue_id,
8381                 (void *)&cmd_flow_director_fd_id,
8382                 (void *)&cmd_flow_director_fd_id_value,
8383                 NULL,
8384         },
8385 };
8386
8387 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8388         .f = cmd_flow_director_filter_parsed,
8389         .data = NULL,
8390         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8391         .tokens = {
8392                 (void *)&cmd_flow_director_filter,
8393                 (void *)&cmd_flow_director_port_id,
8394                 (void *)&cmd_flow_director_ops,
8395                 (void *)&cmd_flow_director_flow,
8396                 (void *)&cmd_flow_director_flow_type,
8397                 (void *)&cmd_flow_director_src,
8398                 (void *)&cmd_flow_director_ip_src,
8399                 (void *)&cmd_flow_director_port_src,
8400                 (void *)&cmd_flow_director_dst,
8401                 (void *)&cmd_flow_director_ip_dst,
8402                 (void *)&cmd_flow_director_port_dst,
8403                 (void *)&cmd_flow_director_flexbytes,
8404                 (void *)&cmd_flow_director_flexbytes_value,
8405                 (void *)&cmd_flow_director_drop,
8406                 (void *)&cmd_flow_director_queue,
8407                 (void *)&cmd_flow_director_queue_id,
8408                 (void *)&cmd_flow_director_fd_id,
8409                 (void *)&cmd_flow_director_fd_id_value,
8410                 NULL,
8411         },
8412 };
8413
8414 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8415         .f = cmd_flow_director_filter_parsed,
8416         .data = NULL,
8417         .help_str = "add or delete a sctp flow director entry on NIC",
8418         .tokens = {
8419                 (void *)&cmd_flow_director_filter,
8420                 (void *)&cmd_flow_director_port_id,
8421                 (void *)&cmd_flow_director_ops,
8422                 (void *)&cmd_flow_director_flow,
8423                 (void *)&cmd_flow_director_flow_type,
8424                 (void *)&cmd_flow_director_src,
8425                 (void *)&cmd_flow_director_ip_src,
8426                 (void *)&cmd_flow_director_dst,
8427                 (void *)&cmd_flow_director_ip_dst,
8428                 (void *)&cmd_flow_director_verify_tag,
8429                 (void *)&cmd_flow_director_verify_tag_value,
8430                 (void *)&cmd_flow_director_flexbytes,
8431                 (void *)&cmd_flow_director_flexbytes_value,
8432                 (void *)&cmd_flow_director_drop,
8433                 (void *)&cmd_flow_director_queue,
8434                 (void *)&cmd_flow_director_queue_id,
8435                 (void *)&cmd_flow_director_fd_id,
8436                 (void *)&cmd_flow_director_fd_id_value,
8437                 NULL,
8438         },
8439 };
8440
8441 struct cmd_flush_flow_director_result {
8442         cmdline_fixed_string_t flush_flow_director;
8443         uint8_t port_id;
8444 };
8445
8446 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8447         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8448                                  flush_flow_director, "flush_flow_director");
8449 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8450         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8451                               port_id, UINT8);
8452
8453 static void
8454 cmd_flush_flow_director_parsed(void *parsed_result,
8455                           __attribute__((unused)) struct cmdline *cl,
8456                           __attribute__((unused)) void *data)
8457 {
8458         struct cmd_flow_director_result *res = parsed_result;
8459         int ret = 0;
8460
8461         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8462         if (ret < 0) {
8463                 printf("flow director is not supported on port %u.\n",
8464                         res->port_id);
8465                 return;
8466         }
8467
8468         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8469                         RTE_ETH_FILTER_FLUSH, NULL);
8470         if (ret < 0)
8471                 printf("flow director table flushing error: (%s)\n",
8472                         strerror(-ret));
8473 }
8474
8475 cmdline_parse_inst_t cmd_flush_flow_director = {
8476         .f = cmd_flush_flow_director_parsed,
8477         .data = NULL,
8478         .help_str = "flush all flow director entries of a device on NIC",
8479         .tokens = {
8480                 (void *)&cmd_flush_flow_director_flush,
8481                 (void *)&cmd_flush_flow_director_port_id,
8482                 NULL,
8483         },
8484 };
8485
8486 /* *** deal with flow director mask on flexible payload *** */
8487 struct cmd_flow_director_flex_mask_result {
8488         cmdline_fixed_string_t flow_director_flexmask;
8489         uint8_t port_id;
8490         cmdline_fixed_string_t flow;
8491         cmdline_fixed_string_t flow_type;
8492         cmdline_fixed_string_t mask;
8493 };
8494
8495 static void
8496 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8497                           __attribute__((unused)) struct cmdline *cl,
8498                           __attribute__((unused)) void *data)
8499 {
8500         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8501         struct rte_eth_fdir_flex_mask flex_mask;
8502         struct rte_port *port;
8503         enum rte_eth_flow_type i;
8504         int ret;
8505
8506         if (res->port_id > nb_ports) {
8507                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8508                 return;
8509         }
8510
8511         port = &ports[res->port_id];
8512         /** Check if the port is not started **/
8513         if (port->port_status != RTE_PORT_STOPPED) {
8514                 printf("Please stop port %d first\n", res->port_id);
8515                 return;
8516         }
8517
8518         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8519         ret = parse_flexbytes(res->mask,
8520                         flex_mask.mask,
8521                         RTE_ETH_FDIR_MAX_FLEXLEN);
8522         if (ret < 0) {
8523                 printf("error: Cannot parse mask input.\n");
8524                 return;
8525         }
8526         if (!strcmp(res->flow_type, "all")) {
8527                 for (i = RTE_ETH_FLOW_TYPE_UDPV4;
8528                      i <= RTE_ETH_FLOW_TYPE_FRAG_IPV6;
8529                      i++) {
8530                         flex_mask.flow_type = i;
8531                         fdir_set_flex_mask(res->port_id, &flex_mask);
8532                 }
8533                 cmd_reconfig_device_queue(res->port_id, 1, 0);
8534                 return;
8535         }
8536         flex_mask.flow_type = str2flowtype(res->flow_type);
8537         fdir_set_flex_mask(res->port_id, &flex_mask);
8538         cmd_reconfig_device_queue(res->port_id, 1, 1);
8539 }
8540
8541 cmdline_parse_token_string_t cmd_flow_director_flexmask =
8542         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8543                                  flow_director_flexmask,
8544                                  "flow_director_flex_mask");
8545 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
8546         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8547                               port_id, UINT8);
8548 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
8549         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8550                                  flow, "flow");
8551 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
8552         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8553                                  flow_type,
8554                                 "ip4#ip4-frag#tcp4#udp4#sctp4#"
8555                                 "ip6#ip6-frag#tcp6#udp6#sctp6#all");
8556 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
8557         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8558                                  mask, NULL);
8559
8560 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
8561         .f = cmd_flow_director_flex_mask_parsed,
8562         .data = NULL,
8563         .help_str = "set flow director's flex mask on NIC",
8564         .tokens = {
8565                 (void *)&cmd_flow_director_flexmask,
8566                 (void *)&cmd_flow_director_flexmask_port_id,
8567                 (void *)&cmd_flow_director_flexmask_flow,
8568                 (void *)&cmd_flow_director_flexmask_flow_type,
8569                 (void *)&cmd_flow_director_flexmask_mask,
8570                 NULL,
8571         },
8572 };
8573
8574 /* *** deal with flow director flexible payload configuration *** */
8575 struct cmd_flow_director_flexpayload_result {
8576         cmdline_fixed_string_t flow_director_flexpayload;
8577         uint8_t port_id;
8578         cmdline_fixed_string_t payload_layer;
8579         cmdline_fixed_string_t payload_cfg;
8580 };
8581
8582 static inline int
8583 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
8584 {
8585         char s[256];
8586         const char *p, *p0 = q_arg;
8587         char *end;
8588         unsigned long int_fld;
8589         char *str_fld[max_num];
8590         int i;
8591         unsigned size;
8592         int ret = -1;
8593
8594         p = strchr(p0, '(');
8595         if (p == NULL)
8596                 return -1;
8597         ++p;
8598         p0 = strchr(p, ')');
8599         if (p0 == NULL)
8600                 return -1;
8601
8602         size = p0 - p;
8603         if (size >= sizeof(s))
8604                 return -1;
8605
8606         snprintf(s, sizeof(s), "%.*s", size, p);
8607         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8608         if (ret < 0 || ret > max_num)
8609                 return -1;
8610         for (i = 0; i < ret; i++) {
8611                 errno = 0;
8612                 int_fld = strtoul(str_fld[i], &end, 0);
8613                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
8614                         return -1;
8615                 offsets[i] = (uint16_t)int_fld;
8616         }
8617         return ret;
8618 }
8619
8620 static void
8621 cmd_flow_director_flxpld_parsed(void *parsed_result,
8622                           __attribute__((unused)) struct cmdline *cl,
8623                           __attribute__((unused)) void *data)
8624 {
8625         struct cmd_flow_director_flexpayload_result *res = parsed_result;
8626         struct rte_eth_flex_payload_cfg flex_cfg;
8627         struct rte_port *port;
8628         int ret = 0;
8629
8630         if (res->port_id > nb_ports) {
8631                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8632                 return;
8633         }
8634
8635         port = &ports[res->port_id];
8636         /** Check if the port is not started **/
8637         if (port->port_status != RTE_PORT_STOPPED) {
8638                 printf("Please stop port %d first\n", res->port_id);
8639                 return;
8640         }
8641
8642         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
8643
8644         if (!strcmp(res->payload_layer, "l2"))
8645                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
8646         else if (!strcmp(res->payload_layer, "l3"))
8647                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
8648         else if (!strcmp(res->payload_layer, "l4"))
8649                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
8650
8651         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
8652                             RTE_ETH_FDIR_MAX_FLEXLEN);
8653         if (ret < 0) {
8654                 printf("error: Cannot parse flex payload input.\n");
8655                 return;
8656         }
8657
8658         fdir_set_flex_payload(res->port_id, &flex_cfg);
8659         cmd_reconfig_device_queue(res->port_id, 1, 1);
8660 }
8661
8662 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
8663         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8664                                  flow_director_flexpayload,
8665                                  "flow_director_flex_payload");
8666 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
8667         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8668                               port_id, UINT8);
8669 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
8670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8671                                  payload_layer, "l2#l3#l4");
8672 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
8673         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8674                                  payload_cfg, NULL);
8675
8676 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
8677         .f = cmd_flow_director_flxpld_parsed,
8678         .data = NULL,
8679         .help_str = "set flow director's flex payload on NIC",
8680         .tokens = {
8681                 (void *)&cmd_flow_director_flexpayload,
8682                 (void *)&cmd_flow_director_flexpayload_port_id,
8683                 (void *)&cmd_flow_director_flexpayload_payload_layer,
8684                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
8685                 NULL,
8686         },
8687 };
8688
8689 /* *** Classification Filters Control *** */
8690 /* *** Get symmetric hash enable per port *** */
8691 struct cmd_get_sym_hash_ena_per_port_result {
8692         cmdline_fixed_string_t get_sym_hash_ena_per_port;
8693         uint8_t port_id;
8694 };
8695
8696 static void
8697 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
8698                                  __rte_unused struct cmdline *cl,
8699                                  __rte_unused void *data)
8700 {
8701         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
8702         struct rte_eth_hash_filter_info info;
8703         int ret;
8704
8705         if (rte_eth_dev_filter_supported(res->port_id,
8706                                 RTE_ETH_FILTER_HASH) < 0) {
8707                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
8708                                                         res->port_id);
8709                 return;
8710         }
8711
8712         memset(&info, 0, sizeof(info));
8713         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
8714         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8715                                                 RTE_ETH_FILTER_GET, &info);
8716
8717         if (ret < 0) {
8718                 printf("Cannot get symmetric hash enable per port "
8719                                         "on port %u\n", res->port_id);
8720                 return;
8721         }
8722
8723         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
8724                                 "enabled" : "disabled", res->port_id);
8725 }
8726
8727 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
8728         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
8729                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
8730 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
8731         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
8732                 port_id, UINT8);
8733
8734 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
8735         .f = cmd_get_sym_hash_per_port_parsed,
8736         .data = NULL,
8737         .help_str = "get_sym_hash_ena_per_port port_id",
8738         .tokens = {
8739                 (void *)&cmd_get_sym_hash_ena_per_port_all,
8740                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** Set symmetric hash enable per port *** */
8746 struct cmd_set_sym_hash_ena_per_port_result {
8747         cmdline_fixed_string_t set_sym_hash_ena_per_port;
8748         cmdline_fixed_string_t enable;
8749         uint8_t port_id;
8750 };
8751
8752 static void
8753 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
8754                                  __rte_unused struct cmdline *cl,
8755                                  __rte_unused void *data)
8756 {
8757         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
8758         struct rte_eth_hash_filter_info info;
8759         int ret;
8760
8761         if (rte_eth_dev_filter_supported(res->port_id,
8762                                 RTE_ETH_FILTER_HASH) < 0) {
8763                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
8764                                                         res->port_id);
8765                 return;
8766         }
8767
8768         memset(&info, 0, sizeof(info));
8769         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
8770         if (!strcmp(res->enable, "enable"))
8771                 info.info.enable = 1;
8772         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8773                                         RTE_ETH_FILTER_SET, &info);
8774         if (ret < 0) {
8775                 printf("Cannot set symmetric hash enable per port on "
8776                                         "port %u\n", res->port_id);
8777                 return;
8778         }
8779         printf("Symmetric hash has been set to %s on port %u\n",
8780                                         res->enable, res->port_id);
8781 }
8782
8783 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
8784         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8785                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
8786 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
8787         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8788                 port_id, UINT8);
8789 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
8790         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8791                 enable, "enable#disable");
8792
8793 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
8794         .f = cmd_set_sym_hash_per_port_parsed,
8795         .data = NULL,
8796         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
8797         .tokens = {
8798                 (void *)&cmd_set_sym_hash_ena_per_port_all,
8799                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
8800                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
8801                 NULL,
8802         },
8803 };
8804
8805 /* Get global config of hash function */
8806 struct cmd_get_hash_global_config_result {
8807         cmdline_fixed_string_t get_hash_global_config;
8808         uint8_t port_id;
8809 };
8810
8811 static char *
8812 flowtype_to_str(enum rte_eth_flow_type ftype)
8813 {
8814         uint16_t i;
8815         static struct {
8816                 char str[16];
8817                 enum rte_eth_flow_type ftype;
8818         } ftype_table[] = {
8819                 {"ip4", RTE_ETH_FLOW_TYPE_IPV4_OTHER},
8820                 {"ip4-frag", RTE_ETH_FLOW_TYPE_FRAG_IPV4},
8821                 {"udp4", RTE_ETH_FLOW_TYPE_UDPV4},
8822                 {"tcp4", RTE_ETH_FLOW_TYPE_TCPV4},
8823                 {"sctp4", RTE_ETH_FLOW_TYPE_SCTPV4},
8824                 {"ip6", RTE_ETH_FLOW_TYPE_IPV6_OTHER},
8825                 {"ip6-frag", RTE_ETH_FLOW_TYPE_FRAG_IPV6},
8826                 {"udp6", RTE_ETH_FLOW_TYPE_UDPV6},
8827                 {"tcp6", RTE_ETH_FLOW_TYPE_TCPV6},
8828                 {"sctp6", RTE_ETH_FLOW_TYPE_TCPV6},
8829         };
8830
8831         for (i = 0; i < RTE_DIM(ftype_table); i++) {
8832                 if (ftype_table[i].ftype == ftype)
8833                         return ftype_table[i].str;
8834         }
8835
8836         return NULL;
8837 }
8838
8839 static void
8840 cmd_get_hash_global_config_parsed(void *parsed_result,
8841                                   __rte_unused struct cmdline *cl,
8842                                   __rte_unused void *data)
8843 {
8844         struct cmd_get_hash_global_config_result *res = parsed_result;
8845         struct rte_eth_hash_filter_info info;
8846         uint32_t idx, offset, i;
8847         char *str;
8848         int ret;
8849
8850         if (rte_eth_dev_filter_supported(res->port_id,
8851                         RTE_ETH_FILTER_HASH) < 0) {
8852                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
8853                                                         res->port_id);
8854                 return;
8855         }
8856
8857         memset(&info, 0, sizeof(info));
8858         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
8859         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8860                                         RTE_ETH_FILTER_GET, &info);
8861         if (ret < 0) {
8862                 printf("Cannot get hash global configurations by port %d\n",
8863                                                         res->port_id);
8864                 return;
8865         }
8866
8867         switch (info.info.global_conf.hash_func) {
8868         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
8869                 printf("Hash function is Toeplitz\n");
8870                 break;
8871         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
8872                 printf("Hash function is Simple XOR\n");
8873                 break;
8874         default:
8875                 printf("Unknown hash function\n");
8876                 break;
8877         }
8878
8879         for (i = 0; i < RTE_ETH_FLOW_TYPE_MAX; i++) {
8880                 idx = i / UINT32_BIT;
8881                 offset = i % UINT32_BIT;
8882                 if (!(info.info.global_conf.valid_bit_mask[idx] &
8883                                                 (1UL << offset)))
8884                         continue;
8885                 str = flowtype_to_str((enum rte_eth_flow_type)i);
8886                 if (!str)
8887                         continue;
8888                 printf("Symmetric hash is %s globally for flow type %s "
8889                                                         "by port %d\n",
8890                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
8891                         (1UL << offset)) ? "enabled" : "disabled"), str,
8892                                                         res->port_id);
8893         }
8894 }
8895
8896 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
8897         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
8898                 get_hash_global_config, "get_hash_global_config");
8899 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
8900         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
8901                 port_id, UINT8);
8902
8903 cmdline_parse_inst_t cmd_get_hash_global_config = {
8904         .f = cmd_get_hash_global_config_parsed,
8905         .data = NULL,
8906         .help_str = "get_hash_global_config port_id",
8907         .tokens = {
8908                 (void *)&cmd_get_hash_global_config_all,
8909                 (void *)&cmd_get_hash_global_config_port_id,
8910                 NULL,
8911         },
8912 };
8913
8914 /* Set global config of hash function */
8915 struct cmd_set_hash_global_config_result {
8916         cmdline_fixed_string_t set_hash_global_config;
8917         uint8_t port_id;
8918         cmdline_fixed_string_t hash_func;
8919         cmdline_fixed_string_t flow_type;
8920         cmdline_fixed_string_t enable;
8921 };
8922
8923 static void
8924 cmd_set_hash_global_config_parsed(void *parsed_result,
8925                                   __rte_unused struct cmdline *cl,
8926                                   __rte_unused void *data)
8927 {
8928         struct cmd_set_hash_global_config_result *res = parsed_result;
8929         struct rte_eth_hash_filter_info info;
8930         uint32_t ftype, idx, offset;
8931         int ret;
8932
8933         if (rte_eth_dev_filter_supported(res->port_id,
8934                                 RTE_ETH_FILTER_HASH) < 0) {
8935                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
8936                                                         res->port_id);
8937                 return;
8938         }
8939         memset(&info, 0, sizeof(info));
8940         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
8941         if (!strcmp(res->hash_func, "toeplitz"))
8942                 info.info.global_conf.hash_func =
8943                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
8944         else if (!strcmp(res->hash_func, "simple_xor"))
8945                 info.info.global_conf.hash_func =
8946                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
8947         else if (!strcmp(res->hash_func, "default"))
8948                 info.info.global_conf.hash_func =
8949                         RTE_ETH_HASH_FUNCTION_DEFAULT;
8950
8951         ftype = str2flowtype(res->flow_type);
8952         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
8953         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
8954         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
8955         if (!strcmp(res->enable, "enable"))
8956                 info.info.global_conf.sym_hash_enable_mask[idx] |=
8957                                                 (1UL << offset);
8958         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8959                                         RTE_ETH_FILTER_SET, &info);
8960         if (ret < 0)
8961                 printf("Cannot set global hash configurations by port %d\n",
8962                                                         res->port_id);
8963         else
8964                 printf("Global hash configurations have been set "
8965                         "succcessfully by port %d\n", res->port_id);
8966 }
8967
8968 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
8969         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8970                 set_hash_global_config, "set_hash_global_config");
8971 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
8972         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
8973                 port_id, UINT8);
8974 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
8975         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8976                 hash_func, "toeplitz#simple_xor#default");
8977 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
8978         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8979                 flow_type,
8980                 "ip4#ip4-frag#tcp4#udp4#sctp4#ip6#ip6-frag#tcp6#udp6#sctp6");
8981 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
8982         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8983                 enable, "enable#disable");
8984
8985 cmdline_parse_inst_t cmd_set_hash_global_config = {
8986         .f = cmd_set_hash_global_config_parsed,
8987         .data = NULL,
8988         .help_str = "set_hash_global_config port_id "
8989                 "toeplitz|simple_xor|default "
8990                 "ip4|ip4-frag|tcp4|udp4|#sctp4|ip6|ip6-frag|tcp6|udp6|sctp6 "
8991                 "enable|disable",
8992         .tokens = {
8993                 (void *)&cmd_set_hash_global_config_all,
8994                 (void *)&cmd_set_hash_global_config_port_id,
8995                 (void *)&cmd_set_hash_global_config_hash_func,
8996                 (void *)&cmd_set_hash_global_config_flow_type,
8997                 (void *)&cmd_set_hash_global_config_enable,
8998                 NULL,
8999         },
9000 };
9001
9002 /* ******************************************************************************** */
9003
9004 /* list of instructions */
9005 cmdline_parse_ctx_t main_ctx[] = {
9006         (cmdline_parse_inst_t *)&cmd_help_brief,
9007         (cmdline_parse_inst_t *)&cmd_help_long,
9008         (cmdline_parse_inst_t *)&cmd_quit,
9009         (cmdline_parse_inst_t *)&cmd_showport,
9010         (cmdline_parse_inst_t *)&cmd_showportall,
9011         (cmdline_parse_inst_t *)&cmd_showcfg,
9012         (cmdline_parse_inst_t *)&cmd_start,
9013         (cmdline_parse_inst_t *)&cmd_start_tx_first,
9014         (cmdline_parse_inst_t *)&cmd_set_link_up,
9015         (cmdline_parse_inst_t *)&cmd_set_link_down,
9016         (cmdline_parse_inst_t *)&cmd_reset,
9017         (cmdline_parse_inst_t *)&cmd_set_numbers,
9018         (cmdline_parse_inst_t *)&cmd_set_txpkts,
9019         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
9020         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
9021         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
9022         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
9023         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
9024         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
9025         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
9026         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
9027         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
9028         (cmdline_parse_inst_t *)&cmd_set_link_check,
9029 #ifdef RTE_NIC_BYPASS
9030         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
9031         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
9032         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
9033         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
9034 #endif
9035 #ifdef RTE_LIBRTE_PMD_BOND
9036         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
9037         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
9038         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
9039         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
9040         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
9041         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
9042         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
9043         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
9044         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
9045 #endif
9046         (cmdline_parse_inst_t *)&cmd_vlan_offload,
9047         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
9048         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
9049         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
9050         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
9051         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
9052         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
9053         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
9054         (cmdline_parse_inst_t *)&cmd_tx_cksum_show,
9055         (cmdline_parse_inst_t *)&cmd_tso_set,
9056         (cmdline_parse_inst_t *)&cmd_tso_show,
9057         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
9058         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
9059         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
9060         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
9061         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
9062         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
9063         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
9064         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
9065         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
9066         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
9067         (cmdline_parse_inst_t *)&cmd_config_dcb,
9068         (cmdline_parse_inst_t *)&cmd_read_reg,
9069         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
9070         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
9071         (cmdline_parse_inst_t *)&cmd_write_reg,
9072         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
9073         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
9074         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
9075         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
9076         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
9077         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
9078         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
9079         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
9080         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
9081         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
9082         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
9083         (cmdline_parse_inst_t *)&cmd_stop,
9084         (cmdline_parse_inst_t *)&cmd_mac_addr,
9085         (cmdline_parse_inst_t *)&cmd_set_qmap,
9086         (cmdline_parse_inst_t *)&cmd_operate_port,
9087         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
9088         (cmdline_parse_inst_t *)&cmd_config_speed_all,
9089         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
9090         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
9091         (cmdline_parse_inst_t *)&cmd_config_mtu,
9092         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
9093         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
9094         (cmdline_parse_inst_t *)&cmd_config_rss,
9095         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
9096         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
9097         (cmdline_parse_inst_t *)&cmd_showport_reta,
9098         (cmdline_parse_inst_t *)&cmd_config_burst,
9099         (cmdline_parse_inst_t *)&cmd_config_thresh,
9100         (cmdline_parse_inst_t *)&cmd_config_threshold,
9101         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
9102         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
9103         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
9104         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
9105         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
9106         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
9107         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
9108         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
9109         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
9110         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
9111         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
9112         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
9113         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
9114         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
9115         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
9116         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
9117         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
9118         (cmdline_parse_inst_t *)&cmd_dump,
9119         (cmdline_parse_inst_t *)&cmd_dump_one,
9120         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
9121         (cmdline_parse_inst_t *)&cmd_add_syn_filter,
9122         (cmdline_parse_inst_t *)&cmd_remove_syn_filter,
9123         (cmdline_parse_inst_t *)&cmd_get_syn_filter,
9124         (cmdline_parse_inst_t *)&cmd_add_2tuple_filter,
9125         (cmdline_parse_inst_t *)&cmd_remove_2tuple_filter,
9126         (cmdline_parse_inst_t *)&cmd_get_2tuple_filter,
9127         (cmdline_parse_inst_t *)&cmd_add_5tuple_filter,
9128         (cmdline_parse_inst_t *)&cmd_remove_5tuple_filter,
9129         (cmdline_parse_inst_t *)&cmd_get_5tuple_filter,
9130         (cmdline_parse_inst_t *)&cmd_add_flex_filter,
9131         (cmdline_parse_inst_t *)&cmd_remove_flex_filter,
9132         (cmdline_parse_inst_t *)&cmd_get_flex_filter,
9133         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
9134         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
9135         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
9136         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
9137         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
9138         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
9139         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
9140         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
9141         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
9142         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
9143         NULL,
9144 };
9145
9146 /* prompt function, called from main on MASTER lcore */
9147 void
9148 prompt(void)
9149 {
9150         struct cmdline *cl;
9151
9152         /* initialize non-constant commands */
9153         cmd_set_fwd_mode_init();
9154
9155         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
9156         if (cl == NULL) {
9157                 return;
9158         }
9159         cmdline_interact(cl);
9160         cmdline_stdin_exit(cl);
9161 }
9162
9163 static void
9164 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
9165 {
9166         if (id < nb_ports) {
9167                 /* check if need_reconfig has been set to 1 */
9168                 if (ports[id].need_reconfig == 0)
9169                         ports[id].need_reconfig = dev;
9170                 /* check if need_reconfig_queues has been set to 1 */
9171                 if (ports[id].need_reconfig_queues == 0)
9172                         ports[id].need_reconfig_queues = queue;
9173         } else {
9174                 portid_t pid;
9175
9176                 for (pid = 0; pid < nb_ports; pid++) {
9177                         /* check if need_reconfig has been set to 1 */
9178                         if (ports[pid].need_reconfig == 0)
9179                                 ports[pid].need_reconfig = dev;
9180                         /* check if need_reconfig_queues has been set to 1 */
9181                         if (ports[pid].need_reconfig_queues == 0)
9182                                 ports[pid].need_reconfig_queues = queue;
9183                 }
9184         }
9185 }
9186
9187 #ifdef RTE_NIC_BYPASS
9188 uint8_t
9189 bypass_is_supported(portid_t port_id)
9190 {
9191         struct rte_port   *port;
9192         struct rte_pci_id *pci_id;
9193
9194         if (port_id >= nb_ports) {
9195                 printf("\tPort id must be less than %d.\n", nb_ports);
9196                 return 0;
9197         }
9198
9199         /* Get the device id. */
9200         port    = &ports[port_id];
9201         pci_id = &port->dev_info.pci_dev->id;
9202
9203         /* Check if NIC supports bypass. */
9204         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
9205                 return 1;
9206         }
9207         else {
9208                 printf("\tBypass not supported for port_id = %d.\n", port_id);
9209                 return 0;
9210         }
9211 }
9212 #endif