app/testpmd: add port reset command
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 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 <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.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 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102
103 static struct cmdline *testpmd_cl;
104
105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
106
107 /* *** Help command with introduction. *** */
108 struct cmd_help_brief_result {
109         cmdline_fixed_string_t help;
110 };
111
112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
113                                   struct cmdline *cl,
114                                   __attribute__((unused)) void *data)
115 {
116         cmdline_printf(
117                 cl,
118                 "\n"
119                 "Help is available for the following sections:\n\n"
120                 "    help control    : Start and stop forwarding.\n"
121                 "    help display    : Displaying port, stats and config "
122                 "information.\n"
123                 "    help config     : Configuration information.\n"
124                 "    help ports      : Configuring ports.\n"
125                 "    help registers  : Reading and setting port registers.\n"
126                 "    help filters    : Filters configuration help.\n"
127                 "    help all        : All of the above sections.\n\n"
128         );
129
130 }
131
132 cmdline_parse_token_string_t cmd_help_brief_help =
133         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
134
135 cmdline_parse_inst_t cmd_help_brief = {
136         .f = cmd_help_brief_parsed,
137         .data = NULL,
138         .help_str = "help: Show help",
139         .tokens = {
140                 (void *)&cmd_help_brief_help,
141                 NULL,
142         },
143 };
144
145 /* *** Help command with help sections. *** */
146 struct cmd_help_long_result {
147         cmdline_fixed_string_t help;
148         cmdline_fixed_string_t section;
149 };
150
151 static void cmd_help_long_parsed(void *parsed_result,
152                                  struct cmdline *cl,
153                                  __attribute__((unused)) void *data)
154 {
155         int show_all = 0;
156         struct cmd_help_long_result *res = parsed_result;
157
158         if (!strcmp(res->section, "all"))
159                 show_all = 1;
160
161         if (show_all || !strcmp(res->section, "control")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Control forwarding:\n"
167                         "-------------------\n\n"
168
169                         "start\n"
170                         "    Start packet forwarding with current configuration.\n\n"
171
172                         "start tx_first\n"
173                         "    Start packet forwarding with current config"
174                         " after sending one burst of packets.\n\n"
175
176                         "stop\n"
177                         "    Stop packet forwarding, and display accumulated"
178                         " statistics.\n\n"
179
180                         "quit\n"
181                         "    Quit to prompt.\n\n"
182                 );
183         }
184
185         if (show_all || !strcmp(res->section, "display")) {
186
187                 cmdline_printf(
188                         cl,
189                         "\n"
190                         "Display:\n"
191                         "--------\n\n"
192
193                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
194                         "    Display information for port_id, or all.\n\n"
195
196                         "show port X rss reta (size) (mask0,mask1,...)\n"
197                         "    Display the rss redirection table entry indicated"
198                         " by masks on port X. size is used to indicate the"
199                         " hardware supported reta size\n\n"
200
201                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
202                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
203                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
204                         "    Display the RSS hash functions and RSS hash key"
205                         " of port X\n\n"
206
207                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
208                         "    Clear information for port_id, or all.\n\n"
209
210                         "show (rxq|txq) info (port_id) (queue_id)\n"
211                         "    Display information for configured RX/TX queue.\n\n"
212
213                         "show config (rxtx|cores|fwd|txpkts)\n"
214                         "    Display the given configuration.\n\n"
215
216                         "read rxd (port_id) (queue_id) (rxd_id)\n"
217                         "    Display an RX descriptor of a port RX queue.\n\n"
218
219                         "read txd (port_id) (queue_id) (txd_id)\n"
220                         "    Display a TX descriptor of a port TX queue.\n\n"
221
222                         "ddp get list (port_id)\n"
223                         "    Get ddp profile info list\n\n"
224
225                         "ddp get info (profile_path)\n"
226                         "    Get ddp profile information.\n\n"
227
228                         "show vf stats (port_id) (vf_id)\n"
229                         "    Display a VF's statistics.\n\n"
230
231                         "clear vf stats (port_id) (vf_id)\n"
232                         "    Reset a VF's statistics.\n\n"
233                 );
234         }
235
236         if (show_all || !strcmp(res->section, "config")) {
237                 cmdline_printf(
238                         cl,
239                         "\n"
240                         "Configuration:\n"
241                         "--------------\n"
242                         "Configuration changes only become active when"
243                         " forwarding is started/restarted.\n\n"
244
245                         "set default\n"
246                         "    Reset forwarding to the default configuration.\n\n"
247
248                         "set verbose (level)\n"
249                         "    Set the debug verbosity level X.\n\n"
250
251                         "set nbport (num)\n"
252                         "    Set number of ports.\n\n"
253
254                         "set nbcore (num)\n"
255                         "    Set number of cores.\n\n"
256
257                         "set coremask (mask)\n"
258                         "    Set the forwarding cores hexadecimal mask.\n\n"
259
260                         "set portmask (mask)\n"
261                         "    Set the forwarding ports hexadecimal mask.\n\n"
262
263                         "set burst (num)\n"
264                         "    Set number of packets per burst.\n\n"
265
266                         "set burst tx delay (microseconds) retry (num)\n"
267                         "    Set the transmit delay time and number of retries,"
268                         " effective when retry is enabled.\n\n"
269
270                         "set txpkts (x[,y]*)\n"
271                         "    Set the length of each segment of TXONLY"
272                         " and optionally CSUM packets.\n\n"
273
274                         "set txsplit (off|on|rand)\n"
275                         "    Set the split policy for the TX packets."
276                         " Right now only applicable for CSUM and TXONLY"
277                         " modes\n\n"
278
279                         "set corelist (x[,y]*)\n"
280                         "    Set the list of forwarding cores.\n\n"
281
282                         "set portlist (x[,y]*)\n"
283                         "    Set the list of forwarding ports.\n\n"
284
285                         "set tx loopback (port_id) (on|off)\n"
286                         "    Enable or disable tx loopback.\n\n"
287
288                         "set all queues drop (port_id) (on|off)\n"
289                         "    Set drop enable bit for all queues.\n\n"
290
291                         "set vf split drop (port_id) (vf_id) (on|off)\n"
292                         "    Set split drop enable bit for a VF from the PF.\n\n"
293
294                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
295                         "    Set MAC antispoof for a VF from the PF.\n\n"
296
297                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
298                         "    Enable MACsec offload.\n\n"
299
300                         "set macsec offload (port_id) off\n"
301                         "    Disable MACsec offload.\n\n"
302
303                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
304                         "    Configure MACsec secure connection (SC).\n\n"
305
306                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
307                         "    Configure MACsec secure association (SA).\n\n"
308
309                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
310                         "    Set VF broadcast for a VF from the PF.\n\n"
311
312                         "vlan set strip (on|off) (port_id)\n"
313                         "    Set the VLAN strip on a port.\n\n"
314
315                         "vlan set stripq (on|off) (port_id,queue_id)\n"
316                         "    Set the VLAN strip for a queue on a port.\n\n"
317
318                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
319                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
320
321                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
322                         "    Set VLAN insert for a VF from the PF.\n\n"
323
324                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
325                         "    Set VLAN antispoof for a VF from the PF.\n\n"
326
327                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
328                         "    Set VLAN tag for a VF from the PF.\n\n"
329
330                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
331                         "    Set a VF's max bandwidth(Mbps).\n\n"
332
333                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
334                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
335
336                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
337                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
338
339                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
340                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
341
342                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
343                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
344
345                         "vlan set filter (on|off) (port_id)\n"
346                         "    Set the VLAN filter on a port.\n\n"
347
348                         "vlan set qinq (on|off) (port_id)\n"
349                         "    Set the VLAN QinQ (extended queue in queue)"
350                         " on a port.\n\n"
351
352                         "vlan set (inner|outer) tpid (value) (port_id)\n"
353                         "    Set the VLAN TPID for Packet Filtering on"
354                         " a port\n\n"
355
356                         "rx_vlan add (vlan_id|all) (port_id)\n"
357                         "    Add a vlan_id, or all identifiers, to the set"
358                         " of VLAN identifiers filtered by port_id.\n\n"
359
360                         "rx_vlan rm (vlan_id|all) (port_id)\n"
361                         "    Remove a vlan_id, or all identifiers, from the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
365                         "    Add a vlan_id, to the set of VLAN identifiers"
366                         "filtered for VF(s) from port_id.\n\n"
367
368                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Remove a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
373                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
374                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
375                         "   add a tunnel filter of a port.\n\n"
376
377                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
378                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
379                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
380                         "   remove a tunnel filter of a port.\n\n"
381
382                         "rx_vxlan_port add (udp_port) (port_id)\n"
383                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
384
385                         "rx_vxlan_port rm (udp_port) (port_id)\n"
386                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
387
388                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
389                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
390                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
391
392                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
393                         "    Set port based TX VLAN insertion.\n\n"
394
395                         "tx_vlan reset (port_id)\n"
396                         "    Disable hardware insertion of a VLAN header in"
397                         " packets sent on a port.\n\n"
398
399                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
400                         "    Select hardware or software calculation of the"
401                         " checksum when transmitting a packet using the"
402                         " csum forward engine.\n"
403                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
404                         "    outer-ip concerns the outer IP layer in"
405                         " case the packet is recognized as a tunnel packet by"
406                         " the forward engine (vxlan, gre and ipip are supported)\n"
407                         "    Please check the NIC datasheet for HW limits.\n\n"
408
409                         "csum parse-tunnel (on|off) (tx_port_id)\n"
410                         "    If disabled, treat tunnel packets as non-tunneled"
411                         " packets (treat inner headers as payload). The port\n"
412                         "    argument is the port used for TX in csum forward"
413                         " engine.\n\n"
414
415                         "csum show (port_id)\n"
416                         "    Display tx checksum offload configuration\n\n"
417
418                         "tso set (segsize) (portid)\n"
419                         "    Enable TCP Segmentation Offload in csum forward"
420                         " engine.\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "tso show (portid)"
424                         "    Display the status of TCP Segmentation Offload.\n\n"
425
426                         "gro (on|off) (port_id)"
427                         "    Enable or disable Generic Receive Offload in"
428                         " csum forwarding engine.\n\n"
429
430                         "gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n"
431                         "    Set max flow number and max packet number per-flow"
432                         " for GRO.\n\n"
433
434                         "set fwd (%s)\n"
435                         "    Set packet forwarding mode.\n\n"
436
437                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
438                         "    Add a MAC address on port_id.\n\n"
439
440                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
441                         "    Remove a MAC address from port_id.\n\n"
442
443                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
444                         "    Set the default MAC address for port_id.\n\n"
445
446                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
447                         "    Add a MAC address for a VF on the port.\n\n"
448
449                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
450                         "    Set the MAC address for a VF from the PF.\n\n"
451
452                         "set port (port_id) uta (mac_address|all) (on|off)\n"
453                         "    Add/Remove a or all unicast hash filter(s)"
454                         "from port X.\n\n"
455
456                         "set promisc (port_id|all) (on|off)\n"
457                         "    Set the promiscuous mode on port_id, or all.\n\n"
458
459                         "set allmulti (port_id|all) (on|off)\n"
460                         "    Set the allmulti mode on port_id, or all.\n\n"
461
462                         "set vf promisc (port_id) (vf_id) (on|off)\n"
463                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
464
465                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
466                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
467
468                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
469                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
470                         " (on|off) autoneg (on|off) (port_id)\n"
471                         "set flow_ctrl rx (on|off) (portid)\n"
472                         "set flow_ctrl tx (on|off) (portid)\n"
473                         "set flow_ctrl high_water (high_water) (portid)\n"
474                         "set flow_ctrl low_water (low_water) (portid)\n"
475                         "set flow_ctrl pause_time (pause_time) (portid)\n"
476                         "set flow_ctrl send_xon (send_xon) (portid)\n"
477                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
478                         "set flow_ctrl autoneg (on|off) (port_id)\n"
479                         "    Set the link flow control parameter on a port.\n\n"
480
481                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
482                         " (low_water) (pause_time) (priority) (port_id)\n"
483                         "    Set the priority flow control parameter on a"
484                         " port.\n\n"
485
486                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
487                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
488                         " queue on port.\n"
489                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
490                         " on port 0 to mapping 5.\n\n"
491
492                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
493                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
494
495                         "set port (port_id) vf (vf_id) (mac_addr)"
496                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
497                         "   Add/Remove unicast or multicast MAC addr filter"
498                         " for a VF.\n\n"
499
500                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
501                         "|MPE) (on|off)\n"
502                         "    AUPE:accepts untagged VLAN;"
503                         "ROPE:accept unicast hash\n\n"
504                         "    BAM:accepts broadcast packets;"
505                         "MPE:accepts all multicast packets\n\n"
506                         "    Enable/Disable a VF receive mode of a port\n\n"
507
508                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
509                         "    Set rate limit for a queue of a port\n\n"
510
511                         "set port (port_id) vf (vf_id) rate (rate_num) "
512                         "queue_mask (queue_mask_value)\n"
513                         "    Set rate limit for queues in VF of a port\n\n"
514
515                         "set port (port_id) mirror-rule (rule_id)"
516                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
517                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
518                         "   Set pool or vlan type mirror rule on a port.\n"
519                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
520                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
521                         " to pool 0.\n\n"
522
523                         "set port (port_id) mirror-rule (rule_id)"
524                         " (uplink-mirror|downlink-mirror) dst-pool"
525                         " (pool_id) (on|off)\n"
526                         "   Set uplink or downlink type mirror rule on a port.\n"
527                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
528                         " 0 on' enable mirror income traffic to pool 0.\n\n"
529
530                         "reset port (port_id) mirror-rule (rule_id)\n"
531                         "   Reset a mirror rule.\n\n"
532
533                         "set flush_rx (on|off)\n"
534                         "   Flush (default) or don't flush RX streams before"
535                         " forwarding. Mainly used with PCAP drivers.\n\n"
536
537                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
538                         "   Set the bypass mode for the lowest port on bypass enabled"
539                         " NIC.\n\n"
540
541                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
542                         "mode (normal|bypass|isolate) (port_id)\n"
543                         "   Set the event required to initiate specified bypass mode for"
544                         " the lowest port on a bypass enabled NIC where:\n"
545                         "       timeout   = enable bypass after watchdog timeout.\n"
546                         "       os_on     = enable bypass when OS/board is powered on.\n"
547                         "       os_off    = enable bypass when OS/board is powered off.\n"
548                         "       power_on  = enable bypass when power supply is turned on.\n"
549                         "       power_off = enable bypass when power supply is turned off."
550                         "\n\n"
551
552                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
553                         "   Set the bypass watchdog timeout to 'n' seconds"
554                         " where 0 = instant.\n\n"
555
556                         "show bypass config (port_id)\n"
557                         "   Show the bypass configuration for a bypass enabled NIC"
558                         " using the lowest port on the NIC.\n\n"
559
560 #ifdef RTE_LIBRTE_PMD_BOND
561                         "create bonded device (mode) (socket)\n"
562                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
563
564                         "add bonding slave (slave_id) (port_id)\n"
565                         "       Add a slave device to a bonded device.\n\n"
566
567                         "remove bonding slave (slave_id) (port_id)\n"
568                         "       Remove a slave device from a bonded device.\n\n"
569
570                         "set bonding mode (value) (port_id)\n"
571                         "       Set the bonding mode on a bonded device.\n\n"
572
573                         "set bonding primary (slave_id) (port_id)\n"
574                         "       Set the primary slave for a bonded device.\n\n"
575
576                         "show bonding config (port_id)\n"
577                         "       Show the bonding config for port_id.\n\n"
578
579                         "set bonding mac_addr (port_id) (address)\n"
580                         "       Set the MAC address of a bonded device.\n\n"
581
582                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
583                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
584
585                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
586                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
587
588                         "set bonding mon_period (port_id) (value)\n"
589                         "       Set the bonding link status monitoring polling period in ms.\n\n"
590
591                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
592                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
593
594 #endif
595                         "set link-up port (port_id)\n"
596                         "       Set link up for a port.\n\n"
597
598                         "set link-down port (port_id)\n"
599                         "       Set link down for a port.\n\n"
600
601                         "E-tag set insertion on port-tag-id (value)"
602                         " port (port_id) vf (vf_id)\n"
603                         "    Enable E-tag insertion for a VF on a port\n\n"
604
605                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
606                         "    Disable E-tag insertion for a VF on a port\n\n"
607
608                         "E-tag set stripping (on|off) port (port_id)\n"
609                         "    Enable/disable E-tag stripping on a port\n\n"
610
611                         "E-tag set forwarding (on|off) port (port_id)\n"
612                         "    Enable/disable E-tag based forwarding"
613                         " on a port\n\n"
614
615                         "E-tag set filter add e-tag-id (value) dst-pool"
616                         " (pool_id) port (port_id)\n"
617                         "    Add an E-tag forwarding filter on a port\n\n"
618
619                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
620                         "    Delete an E-tag forwarding filter on a port\n\n"
621
622                         "ddp add (port_id) (profile_path[,output_path])\n"
623                         "    Load a profile package on a port\n\n"
624
625                         "ddp del (port_id) (profile_path)\n"
626                         "    Delete a profile package from a port\n\n"
627
628                         "ptype mapping get (port_id) (valid_only)\n"
629                         "    Get ptype mapping on a port\n\n"
630
631                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
632                         "    Replace target with the pkt_type in ptype mapping\n\n"
633
634                         "ptype mapping reset (port_id)\n"
635                         "    Reset ptype mapping on a port\n\n"
636
637                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
638                         "    Update a ptype mapping item on a port\n\n"
639
640                         , list_pkt_forwarding_modes()
641                 );
642         }
643
644         if (show_all || !strcmp(res->section, "ports")) {
645
646                 cmdline_printf(
647                         cl,
648                         "\n"
649                         "Port Operations:\n"
650                         "----------------\n\n"
651
652                         "port start (port_id|all)\n"
653                         "    Start all ports or port_id.\n\n"
654
655                         "port stop (port_id|all)\n"
656                         "    Stop all ports or port_id.\n\n"
657
658                         "port close (port_id|all)\n"
659                         "    Close all ports or port_id.\n\n"
660
661                         "port attach (ident)\n"
662                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
663
664                         "port detach (port_id)\n"
665                         "    Detach physical or virtual dev by port_id\n\n"
666
667                         "port config (port_id|all)"
668                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
669                         " duplex (half|full|auto)\n"
670                         "    Set speed and duplex for all ports or port_id\n\n"
671
672                         "port config all (rxq|txq|rxd|txd) (value)\n"
673                         "    Set number for rxq/txq/rxd/txd.\n\n"
674
675                         "port config all max-pkt-len (value)\n"
676                         "    Set the max packet length.\n\n"
677
678                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
679                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
680                         " (on|off)\n"
681                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
682                         " for ports.\n\n"
683
684                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n"
685                         "    Set the RSS mode.\n\n"
686
687                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
688                         "    Set the RSS redirection table.\n\n"
689
690                         "port config (port_id) dcb vt (on|off) (traffic_class)"
691                         " pfc (on|off)\n"
692                         "    Set the DCB mode.\n\n"
693
694                         "port config all burst (value)\n"
695                         "    Set the number of packets per burst.\n\n"
696
697                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
698                         " (value)\n"
699                         "    Set the ring prefetch/host/writeback threshold"
700                         " for tx/rx queue.\n\n"
701
702                         "port config all (txfreet|txrst|rxfreet) (value)\n"
703                         "    Set free threshold for rx/tx, or set"
704                         " tx rs bit threshold.\n\n"
705                         "port config mtu X value\n"
706                         "    Set the MTU of port X to a given value\n\n"
707
708                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
709                         "    Start/stop a rx/tx queue of port X. Only take effect"
710                         " when port X is started\n\n"
711
712                         "port config (port_id|all) l2-tunnel E-tag ether-type"
713                         " (value)\n"
714                         "    Set the value of E-tag ether-type.\n\n"
715
716                         "port config (port_id|all) l2-tunnel E-tag"
717                         " (enable|disable)\n"
718                         "    Enable/disable the E-tag support.\n\n"
719                 );
720         }
721
722         if (show_all || !strcmp(res->section, "registers")) {
723
724                 cmdline_printf(
725                         cl,
726                         "\n"
727                         "Registers:\n"
728                         "----------\n\n"
729
730                         "read reg (port_id) (address)\n"
731                         "    Display value of a port register.\n\n"
732
733                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
734                         "    Display a port register bit field.\n\n"
735
736                         "read regbit (port_id) (address) (bit_x)\n"
737                         "    Display a single port register bit.\n\n"
738
739                         "write reg (port_id) (address) (value)\n"
740                         "    Set value of a port register.\n\n"
741
742                         "write regfield (port_id) (address) (bit_x) (bit_y)"
743                         " (value)\n"
744                         "    Set bit field of a port register.\n\n"
745
746                         "write regbit (port_id) (address) (bit_x) (value)\n"
747                         "    Set single bit value of a port register.\n\n"
748                 );
749         }
750         if (show_all || !strcmp(res->section, "filters")) {
751
752                 cmdline_printf(
753                         cl,
754                         "\n"
755                         "filters:\n"
756                         "--------\n\n"
757
758                         "ethertype_filter (port_id) (add|del)"
759                         " (mac_addr|mac_ignr) (mac_address) ethertype"
760                         " (ether_type) (drop|fwd) queue (queue_id)\n"
761                         "    Add/Del an ethertype filter.\n\n"
762
763                         "2tuple_filter (port_id) (add|del)"
764                         " dst_port (dst_port_value) protocol (protocol_value)"
765                         " mask (mask_value) tcp_flags (tcp_flags_value)"
766                         " priority (prio_value) queue (queue_id)\n"
767                         "    Add/Del a 2tuple filter.\n\n"
768
769                         "5tuple_filter (port_id) (add|del)"
770                         " dst_ip (dst_address) src_ip (src_address)"
771                         " dst_port (dst_port_value) src_port (src_port_value)"
772                         " protocol (protocol_value)"
773                         " mask (mask_value) tcp_flags (tcp_flags_value)"
774                         " priority (prio_value) queue (queue_id)\n"
775                         "    Add/Del a 5tuple filter.\n\n"
776
777                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
778                         "    Add/Del syn filter.\n\n"
779
780                         "flex_filter (port_id) (add|del) len (len_value)"
781                         " bytes (bytes_value) mask (mask_value)"
782                         " priority (prio_value) queue (queue_id)\n"
783                         "    Add/Del a flex filter.\n\n"
784
785                         "flow_director_filter (port_id) mode IP (add|del|update)"
786                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
787                         " src (src_ip_address) dst (dst_ip_address)"
788                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
789                         " vlan (vlan_value) flexbytes (flexbytes_value)"
790                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
791                         " fd_id (fd_id_value)\n"
792                         "    Add/Del an IP type flow director filter.\n\n"
793
794                         "flow_director_filter (port_id) mode IP (add|del|update)"
795                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
796                         " src (src_ip_address) (src_port)"
797                         " dst (dst_ip_address) (dst_port)"
798                         " tos (tos_value) ttl (ttl_value)"
799                         " vlan (vlan_value) flexbytes (flexbytes_value)"
800                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
801                         " fd_id (fd_id_value)\n"
802                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
803
804                         "flow_director_filter (port_id) mode IP (add|del|update)"
805                         " flow (ipv4-sctp|ipv6-sctp)"
806                         " src (src_ip_address) (src_port)"
807                         " dst (dst_ip_address) (dst_port)"
808                         " tag (verification_tag) "
809                         " tos (tos_value) ttl (ttl_value)"
810                         " vlan (vlan_value)"
811                         " flexbytes (flexbytes_value) (drop|fwd)"
812                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
813                         "    Add/Del a SCTP type flow director filter.\n\n"
814
815                         "flow_director_filter (port_id) mode IP (add|del|update)"
816                         " flow l2_payload ether (ethertype)"
817                         " flexbytes (flexbytes_value) (drop|fwd)"
818                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
819                         "    Add/Del a l2 payload type flow director filter.\n\n"
820
821                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
822                         " mac (mac_address) vlan (vlan_value)"
823                         " flexbytes (flexbytes_value) (drop|fwd)"
824                         " queue (queue_id) fd_id (fd_id_value)\n"
825                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
826
827                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
828                         " mac (mac_address) vlan (vlan_value)"
829                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
830                         " flexbytes (flexbytes_value) (drop|fwd)"
831                         " queue (queue_id) fd_id (fd_id_value)\n"
832                         "    Add/Del a Tunnel flow director filter.\n\n"
833
834                         "flush_flow_director (port_id)\n"
835                         "    Flush all flow director entries of a device.\n\n"
836
837                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
838                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
839                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
840                         "    Set flow director IP mask.\n\n"
841
842                         "flow_director_mask (port_id) mode MAC-VLAN"
843                         " vlan (vlan_value)\n"
844                         "    Set flow director MAC-VLAN mask.\n\n"
845
846                         "flow_director_mask (port_id) mode Tunnel"
847                         " vlan (vlan_value) mac (mac_value)"
848                         " tunnel-type (tunnel_type_value)"
849                         " tunnel-id (tunnel_id_value)\n"
850                         "    Set flow director Tunnel mask.\n\n"
851
852                         "flow_director_flex_mask (port_id)"
853                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
854                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
855                         " (mask)\n"
856                         "    Configure mask of flex payload.\n\n"
857
858                         "flow_director_flex_payload (port_id)"
859                         " (raw|l2|l3|l4) (config)\n"
860                         "    Configure flex payload selection.\n\n"
861
862                         "get_sym_hash_ena_per_port (port_id)\n"
863                         "    get symmetric hash enable configuration per port.\n\n"
864
865                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
866                         "    set symmetric hash enable configuration per port"
867                         " to enable or disable.\n\n"
868
869                         "get_hash_global_config (port_id)\n"
870                         "    Get the global configurations of hash filters.\n\n"
871
872                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
873                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
874                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
875                         " (enable|disable)\n"
876                         "    Set the global configurations of hash filters.\n\n"
877
878                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
879                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
880                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
881                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
882                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
883                         "ipv6-next-header|udp-src-port|udp-dst-port|"
884                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
885                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
886                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
887                         "fld-8th|none) (select|add)\n"
888                         "    Set the input set for hash.\n\n"
889
890                         "set_fdir_input_set (port_id) "
891                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
892                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
893                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
894                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
895                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
896                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
897                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
898                         " (select|add)\n"
899                         "    Set the input set for FDir.\n\n"
900
901                         "flow validate {port_id}"
902                         " [group {group_id}] [priority {level}]"
903                         " [ingress] [egress]"
904                         " pattern {item} [/ {item} [...]] / end"
905                         " actions {action} [/ {action} [...]] / end\n"
906                         "    Check whether a flow rule can be created.\n\n"
907
908                         "flow create {port_id}"
909                         " [group {group_id}] [priority {level}]"
910                         " [ingress] [egress]"
911                         " pattern {item} [/ {item} [...]] / end"
912                         " actions {action} [/ {action} [...]] / end\n"
913                         "    Create a flow rule.\n\n"
914
915                         "flow destroy {port_id} rule {rule_id} [...]\n"
916                         "    Destroy specific flow rules.\n\n"
917
918                         "flow flush {port_id}\n"
919                         "    Destroy all flow rules.\n\n"
920
921                         "flow query {port_id} {rule_id} {action}\n"
922                         "    Query an existing flow rule.\n\n"
923
924                         "flow list {port_id} [group {group_id}] [...]\n"
925                         "    List existing flow rules sorted by priority,"
926                         " filtered by group identifiers.\n\n"
927
928                         "flow isolate {port_id} {boolean}\n"
929                         "    Restrict ingress traffic to the defined"
930                         " flow rules\n\n"
931                 );
932         }
933 }
934
935 cmdline_parse_token_string_t cmd_help_long_help =
936         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
937
938 cmdline_parse_token_string_t cmd_help_long_section =
939         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
940                         "all#control#display#config#"
941                         "ports#registers#filters");
942
943 cmdline_parse_inst_t cmd_help_long = {
944         .f = cmd_help_long_parsed,
945         .data = NULL,
946         .help_str = "help all|control|display|config|ports|register|filters: "
947                 "Show help",
948         .tokens = {
949                 (void *)&cmd_help_long_help,
950                 (void *)&cmd_help_long_section,
951                 NULL,
952         },
953 };
954
955
956 /* *** start/stop/close all ports *** */
957 struct cmd_operate_port_result {
958         cmdline_fixed_string_t keyword;
959         cmdline_fixed_string_t name;
960         cmdline_fixed_string_t value;
961 };
962
963 static void cmd_operate_port_parsed(void *parsed_result,
964                                 __attribute__((unused)) struct cmdline *cl,
965                                 __attribute__((unused)) void *data)
966 {
967         struct cmd_operate_port_result *res = parsed_result;
968
969         if (!strcmp(res->name, "start"))
970                 start_port(RTE_PORT_ALL);
971         else if (!strcmp(res->name, "stop"))
972                 stop_port(RTE_PORT_ALL);
973         else if (!strcmp(res->name, "close"))
974                 close_port(RTE_PORT_ALL);
975         else if (!strcmp(res->name, "reset"))
976                 reset_port(RTE_PORT_ALL);
977         else
978                 printf("Unknown parameter\n");
979 }
980
981 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
982         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
983                                                                 "port");
984 cmdline_parse_token_string_t cmd_operate_port_all_port =
985         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
986                                                 "start#stop#close#reset");
987 cmdline_parse_token_string_t cmd_operate_port_all_all =
988         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
989
990 cmdline_parse_inst_t cmd_operate_port = {
991         .f = cmd_operate_port_parsed,
992         .data = NULL,
993         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
994         .tokens = {
995                 (void *)&cmd_operate_port_all_cmd,
996                 (void *)&cmd_operate_port_all_port,
997                 (void *)&cmd_operate_port_all_all,
998                 NULL,
999         },
1000 };
1001
1002 /* *** start/stop/close specific port *** */
1003 struct cmd_operate_specific_port_result {
1004         cmdline_fixed_string_t keyword;
1005         cmdline_fixed_string_t name;
1006         uint8_t value;
1007 };
1008
1009 static void cmd_operate_specific_port_parsed(void *parsed_result,
1010                         __attribute__((unused)) struct cmdline *cl,
1011                                 __attribute__((unused)) void *data)
1012 {
1013         struct cmd_operate_specific_port_result *res = parsed_result;
1014
1015         if (!strcmp(res->name, "start"))
1016                 start_port(res->value);
1017         else if (!strcmp(res->name, "stop"))
1018                 stop_port(res->value);
1019         else if (!strcmp(res->name, "close"))
1020                 close_port(res->value);
1021         else if (!strcmp(res->name, "reset"))
1022                 reset_port(res->value);
1023         else
1024                 printf("Unknown parameter\n");
1025 }
1026
1027 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1028         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1029                                                         keyword, "port");
1030 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1031         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1032                                                 name, "start#stop#close#reset");
1033 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1034         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1035                                                         value, UINT8);
1036
1037 cmdline_parse_inst_t cmd_operate_specific_port = {
1038         .f = cmd_operate_specific_port_parsed,
1039         .data = NULL,
1040         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1041         .tokens = {
1042                 (void *)&cmd_operate_specific_port_cmd,
1043                 (void *)&cmd_operate_specific_port_port,
1044                 (void *)&cmd_operate_specific_port_id,
1045                 NULL,
1046         },
1047 };
1048
1049 /* *** attach a specified port *** */
1050 struct cmd_operate_attach_port_result {
1051         cmdline_fixed_string_t port;
1052         cmdline_fixed_string_t keyword;
1053         cmdline_fixed_string_t identifier;
1054 };
1055
1056 static void cmd_operate_attach_port_parsed(void *parsed_result,
1057                                 __attribute__((unused)) struct cmdline *cl,
1058                                 __attribute__((unused)) void *data)
1059 {
1060         struct cmd_operate_attach_port_result *res = parsed_result;
1061
1062         if (!strcmp(res->keyword, "attach"))
1063                 attach_port(res->identifier);
1064         else
1065                 printf("Unknown parameter\n");
1066 }
1067
1068 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1069         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1070                         port, "port");
1071 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1072         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1073                         keyword, "attach");
1074 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1075         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1076                         identifier, NULL);
1077
1078 cmdline_parse_inst_t cmd_operate_attach_port = {
1079         .f = cmd_operate_attach_port_parsed,
1080         .data = NULL,
1081         .help_str = "port attach <identifier>: "
1082                 "(identifier: pci address or virtual dev name)",
1083         .tokens = {
1084                 (void *)&cmd_operate_attach_port_port,
1085                 (void *)&cmd_operate_attach_port_keyword,
1086                 (void *)&cmd_operate_attach_port_identifier,
1087                 NULL,
1088         },
1089 };
1090
1091 /* *** detach a specified port *** */
1092 struct cmd_operate_detach_port_result {
1093         cmdline_fixed_string_t port;
1094         cmdline_fixed_string_t keyword;
1095         uint8_t port_id;
1096 };
1097
1098 static void cmd_operate_detach_port_parsed(void *parsed_result,
1099                                 __attribute__((unused)) struct cmdline *cl,
1100                                 __attribute__((unused)) void *data)
1101 {
1102         struct cmd_operate_detach_port_result *res = parsed_result;
1103
1104         if (!strcmp(res->keyword, "detach"))
1105                 detach_port(res->port_id);
1106         else
1107                 printf("Unknown parameter\n");
1108 }
1109
1110 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1111         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1112                         port, "port");
1113 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1114         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1115                         keyword, "detach");
1116 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1117         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1118                         port_id, UINT8);
1119
1120 cmdline_parse_inst_t cmd_operate_detach_port = {
1121         .f = cmd_operate_detach_port_parsed,
1122         .data = NULL,
1123         .help_str = "port detach <port_id>",
1124         .tokens = {
1125                 (void *)&cmd_operate_detach_port_port,
1126                 (void *)&cmd_operate_detach_port_keyword,
1127                 (void *)&cmd_operate_detach_port_port_id,
1128                 NULL,
1129         },
1130 };
1131
1132 /* *** configure speed for all ports *** */
1133 struct cmd_config_speed_all {
1134         cmdline_fixed_string_t port;
1135         cmdline_fixed_string_t keyword;
1136         cmdline_fixed_string_t all;
1137         cmdline_fixed_string_t item1;
1138         cmdline_fixed_string_t item2;
1139         cmdline_fixed_string_t value1;
1140         cmdline_fixed_string_t value2;
1141 };
1142
1143 static int
1144 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1145 {
1146
1147         int duplex;
1148
1149         if (!strcmp(duplexstr, "half")) {
1150                 duplex = ETH_LINK_HALF_DUPLEX;
1151         } else if (!strcmp(duplexstr, "full")) {
1152                 duplex = ETH_LINK_FULL_DUPLEX;
1153         } else if (!strcmp(duplexstr, "auto")) {
1154                 duplex = ETH_LINK_FULL_DUPLEX;
1155         } else {
1156                 printf("Unknown duplex parameter\n");
1157                 return -1;
1158         }
1159
1160         if (!strcmp(speedstr, "10")) {
1161                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1162                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1163         } else if (!strcmp(speedstr, "100")) {
1164                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1165                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1166         } else {
1167                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1168                         printf("Invalid speed/duplex parameters\n");
1169                         return -1;
1170                 }
1171                 if (!strcmp(speedstr, "1000")) {
1172                         *speed = ETH_LINK_SPEED_1G;
1173                 } else if (!strcmp(speedstr, "10000")) {
1174                         *speed = ETH_LINK_SPEED_10G;
1175                 } else if (!strcmp(speedstr, "25000")) {
1176                         *speed = ETH_LINK_SPEED_25G;
1177                 } else if (!strcmp(speedstr, "40000")) {
1178                         *speed = ETH_LINK_SPEED_40G;
1179                 } else if (!strcmp(speedstr, "50000")) {
1180                         *speed = ETH_LINK_SPEED_50G;
1181                 } else if (!strcmp(speedstr, "100000")) {
1182                         *speed = ETH_LINK_SPEED_100G;
1183                 } else if (!strcmp(speedstr, "auto")) {
1184                         *speed = ETH_LINK_SPEED_AUTONEG;
1185                 } else {
1186                         printf("Unknown speed parameter\n");
1187                         return -1;
1188                 }
1189         }
1190
1191         return 0;
1192 }
1193
1194 static void
1195 cmd_config_speed_all_parsed(void *parsed_result,
1196                         __attribute__((unused)) struct cmdline *cl,
1197                         __attribute__((unused)) void *data)
1198 {
1199         struct cmd_config_speed_all *res = parsed_result;
1200         uint32_t link_speed;
1201         portid_t pid;
1202
1203         if (!all_ports_stopped()) {
1204                 printf("Please stop all ports first\n");
1205                 return;
1206         }
1207
1208         if (parse_and_check_speed_duplex(res->value1, res->value2,
1209                         &link_speed) < 0)
1210                 return;
1211
1212         RTE_ETH_FOREACH_DEV(pid) {
1213                 ports[pid].dev_conf.link_speeds = link_speed;
1214         }
1215
1216         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1217 }
1218
1219 cmdline_parse_token_string_t cmd_config_speed_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1221 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1222         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1223                                                         "config");
1224 cmdline_parse_token_string_t cmd_config_speed_all_all =
1225         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1226 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1227         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1228 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1229         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1230                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1231 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1232         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1233 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1234         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1235                                                 "half#full#auto");
1236
1237 cmdline_parse_inst_t cmd_config_speed_all = {
1238         .f = cmd_config_speed_all_parsed,
1239         .data = NULL,
1240         .help_str = "port config all speed "
1241                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1242                                                         "half|full|auto",
1243         .tokens = {
1244                 (void *)&cmd_config_speed_all_port,
1245                 (void *)&cmd_config_speed_all_keyword,
1246                 (void *)&cmd_config_speed_all_all,
1247                 (void *)&cmd_config_speed_all_item1,
1248                 (void *)&cmd_config_speed_all_value1,
1249                 (void *)&cmd_config_speed_all_item2,
1250                 (void *)&cmd_config_speed_all_value2,
1251                 NULL,
1252         },
1253 };
1254
1255 /* *** configure speed for specific port *** */
1256 struct cmd_config_speed_specific {
1257         cmdline_fixed_string_t port;
1258         cmdline_fixed_string_t keyword;
1259         uint8_t id;
1260         cmdline_fixed_string_t item1;
1261         cmdline_fixed_string_t item2;
1262         cmdline_fixed_string_t value1;
1263         cmdline_fixed_string_t value2;
1264 };
1265
1266 static void
1267 cmd_config_speed_specific_parsed(void *parsed_result,
1268                                 __attribute__((unused)) struct cmdline *cl,
1269                                 __attribute__((unused)) void *data)
1270 {
1271         struct cmd_config_speed_specific *res = parsed_result;
1272         uint32_t link_speed;
1273
1274         if (!all_ports_stopped()) {
1275                 printf("Please stop all ports first\n");
1276                 return;
1277         }
1278
1279         if (port_id_is_invalid(res->id, ENABLED_WARN))
1280                 return;
1281
1282         if (parse_and_check_speed_duplex(res->value1, res->value2,
1283                         &link_speed) < 0)
1284                 return;
1285
1286         ports[res->id].dev_conf.link_speeds = link_speed;
1287
1288         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1289 }
1290
1291
1292 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1293         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1294                                                                 "port");
1295 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1296         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1297                                                                 "config");
1298 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1299         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1300 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1301         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1302                                                                 "speed");
1303 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1304         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1305                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1306 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1307         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1308                                                                 "duplex");
1309 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1310         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1311                                                         "half#full#auto");
1312
1313 cmdline_parse_inst_t cmd_config_speed_specific = {
1314         .f = cmd_config_speed_specific_parsed,
1315         .data = NULL,
1316         .help_str = "port config <port_id> speed "
1317                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1318                                                         "half|full|auto",
1319         .tokens = {
1320                 (void *)&cmd_config_speed_specific_port,
1321                 (void *)&cmd_config_speed_specific_keyword,
1322                 (void *)&cmd_config_speed_specific_id,
1323                 (void *)&cmd_config_speed_specific_item1,
1324                 (void *)&cmd_config_speed_specific_value1,
1325                 (void *)&cmd_config_speed_specific_item2,
1326                 (void *)&cmd_config_speed_specific_value2,
1327                 NULL,
1328         },
1329 };
1330
1331 /* *** configure txq/rxq, txd/rxd *** */
1332 struct cmd_config_rx_tx {
1333         cmdline_fixed_string_t port;
1334         cmdline_fixed_string_t keyword;
1335         cmdline_fixed_string_t all;
1336         cmdline_fixed_string_t name;
1337         uint16_t value;
1338 };
1339
1340 static void
1341 cmd_config_rx_tx_parsed(void *parsed_result,
1342                         __attribute__((unused)) struct cmdline *cl,
1343                         __attribute__((unused)) void *data)
1344 {
1345         struct cmd_config_rx_tx *res = parsed_result;
1346
1347         if (!all_ports_stopped()) {
1348                 printf("Please stop all ports first\n");
1349                 return;
1350         }
1351         if (!strcmp(res->name, "rxq")) {
1352                 if (!res->value && !nb_txq) {
1353                         printf("Warning: Either rx or tx queues should be non zero\n");
1354                         return;
1355                 }
1356                 nb_rxq = res->value;
1357         }
1358         else if (!strcmp(res->name, "txq")) {
1359                 if (!res->value && !nb_rxq) {
1360                         printf("Warning: Either rx or tx queues should be non zero\n");
1361                         return;
1362                 }
1363                 nb_txq = res->value;
1364         }
1365         else if (!strcmp(res->name, "rxd")) {
1366                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1367                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1368                                         res->value, RTE_TEST_RX_DESC_MAX);
1369                         return;
1370                 }
1371                 nb_rxd = res->value;
1372         } else if (!strcmp(res->name, "txd")) {
1373                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1374                         printf("txd %d invalid - must be > 0 && <= %d\n",
1375                                         res->value, RTE_TEST_TX_DESC_MAX);
1376                         return;
1377                 }
1378                 nb_txd = res->value;
1379         } else {
1380                 printf("Unknown parameter\n");
1381                 return;
1382         }
1383
1384         fwd_config_setup();
1385
1386         init_port_config();
1387
1388         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1389 }
1390
1391 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1393 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1395 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1397 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1399                                                 "rxq#txq#rxd#txd");
1400 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1401         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1402
1403 cmdline_parse_inst_t cmd_config_rx_tx = {
1404         .f = cmd_config_rx_tx_parsed,
1405         .data = NULL,
1406         .help_str = "port config all rxq|txq|rxd|txd <value>",
1407         .tokens = {
1408                 (void *)&cmd_config_rx_tx_port,
1409                 (void *)&cmd_config_rx_tx_keyword,
1410                 (void *)&cmd_config_rx_tx_all,
1411                 (void *)&cmd_config_rx_tx_name,
1412                 (void *)&cmd_config_rx_tx_value,
1413                 NULL,
1414         },
1415 };
1416
1417 /* *** config max packet length *** */
1418 struct cmd_config_max_pkt_len_result {
1419         cmdline_fixed_string_t port;
1420         cmdline_fixed_string_t keyword;
1421         cmdline_fixed_string_t all;
1422         cmdline_fixed_string_t name;
1423         uint32_t value;
1424 };
1425
1426 static void
1427 cmd_config_max_pkt_len_parsed(void *parsed_result,
1428                                 __attribute__((unused)) struct cmdline *cl,
1429                                 __attribute__((unused)) void *data)
1430 {
1431         struct cmd_config_max_pkt_len_result *res = parsed_result;
1432
1433         if (!all_ports_stopped()) {
1434                 printf("Please stop all ports first\n");
1435                 return;
1436         }
1437
1438         if (!strcmp(res->name, "max-pkt-len")) {
1439                 if (res->value < ETHER_MIN_LEN) {
1440                         printf("max-pkt-len can not be less than %d\n",
1441                                                         ETHER_MIN_LEN);
1442                         return;
1443                 }
1444                 if (res->value == rx_mode.max_rx_pkt_len)
1445                         return;
1446
1447                 rx_mode.max_rx_pkt_len = res->value;
1448                 if (res->value > ETHER_MAX_LEN)
1449                         rx_mode.jumbo_frame = 1;
1450                 else
1451                         rx_mode.jumbo_frame = 0;
1452         } else {
1453                 printf("Unknown parameter\n");
1454                 return;
1455         }
1456
1457         init_port_config();
1458
1459         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1460 }
1461
1462 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1464                                                                 "port");
1465 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1467                                                                 "config");
1468 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1470                                                                 "all");
1471 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1473                                                                 "max-pkt-len");
1474 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1475         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1476                                                                 UINT32);
1477
1478 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1479         .f = cmd_config_max_pkt_len_parsed,
1480         .data = NULL,
1481         .help_str = "port config all max-pkt-len <value>",
1482         .tokens = {
1483                 (void *)&cmd_config_max_pkt_len_port,
1484                 (void *)&cmd_config_max_pkt_len_keyword,
1485                 (void *)&cmd_config_max_pkt_len_all,
1486                 (void *)&cmd_config_max_pkt_len_name,
1487                 (void *)&cmd_config_max_pkt_len_value,
1488                 NULL,
1489         },
1490 };
1491
1492 /* *** configure port MTU *** */
1493 struct cmd_config_mtu_result {
1494         cmdline_fixed_string_t port;
1495         cmdline_fixed_string_t keyword;
1496         cmdline_fixed_string_t mtu;
1497         uint8_t port_id;
1498         uint16_t value;
1499 };
1500
1501 static void
1502 cmd_config_mtu_parsed(void *parsed_result,
1503                       __attribute__((unused)) struct cmdline *cl,
1504                       __attribute__((unused)) void *data)
1505 {
1506         struct cmd_config_mtu_result *res = parsed_result;
1507
1508         if (res->value < ETHER_MIN_LEN) {
1509                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1510                 return;
1511         }
1512         port_mtu_set(res->port_id, res->value);
1513 }
1514
1515 cmdline_parse_token_string_t cmd_config_mtu_port =
1516         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1517                                  "port");
1518 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1519         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1520                                  "config");
1521 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1522         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1523                                  "mtu");
1524 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1525         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1526 cmdline_parse_token_num_t cmd_config_mtu_value =
1527         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1528
1529 cmdline_parse_inst_t cmd_config_mtu = {
1530         .f = cmd_config_mtu_parsed,
1531         .data = NULL,
1532         .help_str = "port config mtu <port_id> <value>",
1533         .tokens = {
1534                 (void *)&cmd_config_mtu_port,
1535                 (void *)&cmd_config_mtu_keyword,
1536                 (void *)&cmd_config_mtu_mtu,
1537                 (void *)&cmd_config_mtu_port_id,
1538                 (void *)&cmd_config_mtu_value,
1539                 NULL,
1540         },
1541 };
1542
1543 /* *** configure rx mode *** */
1544 struct cmd_config_rx_mode_flag {
1545         cmdline_fixed_string_t port;
1546         cmdline_fixed_string_t keyword;
1547         cmdline_fixed_string_t all;
1548         cmdline_fixed_string_t name;
1549         cmdline_fixed_string_t value;
1550 };
1551
1552 static void
1553 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1554                                 __attribute__((unused)) struct cmdline *cl,
1555                                 __attribute__((unused)) void *data)
1556 {
1557         struct cmd_config_rx_mode_flag *res = parsed_result;
1558
1559         if (!all_ports_stopped()) {
1560                 printf("Please stop all ports first\n");
1561                 return;
1562         }
1563
1564         if (!strcmp(res->name, "crc-strip")) {
1565                 if (!strcmp(res->value, "on"))
1566                         rx_mode.hw_strip_crc = 1;
1567                 else if (!strcmp(res->value, "off"))
1568                         rx_mode.hw_strip_crc = 0;
1569                 else {
1570                         printf("Unknown parameter\n");
1571                         return;
1572                 }
1573         } else if (!strcmp(res->name, "scatter")) {
1574                 if (!strcmp(res->value, "on"))
1575                         rx_mode.enable_scatter = 1;
1576                 else if (!strcmp(res->value, "off"))
1577                         rx_mode.enable_scatter = 0;
1578                 else {
1579                         printf("Unknown parameter\n");
1580                         return;
1581                 }
1582         } else if (!strcmp(res->name, "rx-cksum")) {
1583                 if (!strcmp(res->value, "on"))
1584                         rx_mode.hw_ip_checksum = 1;
1585                 else if (!strcmp(res->value, "off"))
1586                         rx_mode.hw_ip_checksum = 0;
1587                 else {
1588                         printf("Unknown parameter\n");
1589                         return;
1590                 }
1591         } else if (!strcmp(res->name, "hw-vlan")) {
1592                 if (!strcmp(res->value, "on")) {
1593                         rx_mode.hw_vlan_filter = 1;
1594                         rx_mode.hw_vlan_strip  = 1;
1595                 }
1596                 else if (!strcmp(res->value, "off")) {
1597                         rx_mode.hw_vlan_filter = 0;
1598                         rx_mode.hw_vlan_strip  = 0;
1599                 }
1600                 else {
1601                         printf("Unknown parameter\n");
1602                         return;
1603                 }
1604         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1605                 if (!strcmp(res->value, "on"))
1606                         rx_mode.hw_vlan_filter = 1;
1607                 else if (!strcmp(res->value, "off"))
1608                         rx_mode.hw_vlan_filter = 0;
1609                 else {
1610                         printf("Unknown parameter\n");
1611                         return;
1612                 }
1613         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1614                 if (!strcmp(res->value, "on"))
1615                         rx_mode.hw_vlan_strip  = 1;
1616                 else if (!strcmp(res->value, "off"))
1617                         rx_mode.hw_vlan_strip  = 0;
1618                 else {
1619                         printf("Unknown parameter\n");
1620                         return;
1621                 }
1622         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1623                 if (!strcmp(res->value, "on"))
1624                         rx_mode.hw_vlan_extend = 1;
1625                 else if (!strcmp(res->value, "off"))
1626                         rx_mode.hw_vlan_extend = 0;
1627                 else {
1628                         printf("Unknown parameter\n");
1629                         return;
1630                 }
1631         } else if (!strcmp(res->name, "drop-en")) {
1632                 if (!strcmp(res->value, "on"))
1633                         rx_drop_en = 1;
1634                 else if (!strcmp(res->value, "off"))
1635                         rx_drop_en = 0;
1636                 else {
1637                         printf("Unknown parameter\n");
1638                         return;
1639                 }
1640         } else {
1641                 printf("Unknown parameter\n");
1642                 return;
1643         }
1644
1645         init_port_config();
1646
1647         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1648 }
1649
1650 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1652 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1654                                                                 "config");
1655 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1657 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1659                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1660                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1661 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1663                                                         "on#off");
1664
1665 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1666         .f = cmd_config_rx_mode_flag_parsed,
1667         .data = NULL,
1668         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1669                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1670         .tokens = {
1671                 (void *)&cmd_config_rx_mode_flag_port,
1672                 (void *)&cmd_config_rx_mode_flag_keyword,
1673                 (void *)&cmd_config_rx_mode_flag_all,
1674                 (void *)&cmd_config_rx_mode_flag_name,
1675                 (void *)&cmd_config_rx_mode_flag_value,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure rss *** */
1681 struct cmd_config_rss {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         cmdline_fixed_string_t all;
1685         cmdline_fixed_string_t name;
1686         cmdline_fixed_string_t value;
1687 };
1688
1689 static void
1690 cmd_config_rss_parsed(void *parsed_result,
1691                         __attribute__((unused)) struct cmdline *cl,
1692                         __attribute__((unused)) void *data)
1693 {
1694         struct cmd_config_rss *res = parsed_result;
1695         struct rte_eth_rss_conf rss_conf;
1696         int diag;
1697         uint8_t i;
1698
1699         if (!strcmp(res->value, "all"))
1700                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1701                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1702                                         ETH_RSS_L2_PAYLOAD;
1703         else if (!strcmp(res->value, "ip"))
1704                 rss_conf.rss_hf = ETH_RSS_IP;
1705         else if (!strcmp(res->value, "udp"))
1706                 rss_conf.rss_hf = ETH_RSS_UDP;
1707         else if (!strcmp(res->value, "tcp"))
1708                 rss_conf.rss_hf = ETH_RSS_TCP;
1709         else if (!strcmp(res->value, "sctp"))
1710                 rss_conf.rss_hf = ETH_RSS_SCTP;
1711         else if (!strcmp(res->value, "ether"))
1712                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1713         else if (!strcmp(res->value, "port"))
1714                 rss_conf.rss_hf = ETH_RSS_PORT;
1715         else if (!strcmp(res->value, "vxlan"))
1716                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1717         else if (!strcmp(res->value, "geneve"))
1718                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1719         else if (!strcmp(res->value, "nvgre"))
1720                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1721         else if (!strcmp(res->value, "none"))
1722                 rss_conf.rss_hf = 0;
1723         else {
1724                 printf("Unknown parameter\n");
1725                 return;
1726         }
1727         rss_conf.rss_key = NULL;
1728         for (i = 0; i < rte_eth_dev_count(); i++) {
1729                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1730                 if (diag < 0)
1731                         printf("Configuration of RSS hash at ethernet port %d "
1732                                 "failed with error (%d): %s.\n",
1733                                 i, -diag, strerror(-diag));
1734         }
1735 }
1736
1737 cmdline_parse_token_string_t cmd_config_rss_port =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1739 cmdline_parse_token_string_t cmd_config_rss_keyword =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1741 cmdline_parse_token_string_t cmd_config_rss_all =
1742         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1743 cmdline_parse_token_string_t cmd_config_rss_name =
1744         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1745 cmdline_parse_token_string_t cmd_config_rss_value =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1747                 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none");
1748
1749 cmdline_parse_inst_t cmd_config_rss = {
1750         .f = cmd_config_rss_parsed,
1751         .data = NULL,
1752         .help_str = "port config all rss "
1753                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none",
1754         .tokens = {
1755                 (void *)&cmd_config_rss_port,
1756                 (void *)&cmd_config_rss_keyword,
1757                 (void *)&cmd_config_rss_all,
1758                 (void *)&cmd_config_rss_name,
1759                 (void *)&cmd_config_rss_value,
1760                 NULL,
1761         },
1762 };
1763
1764 /* *** configure rss hash key *** */
1765 struct cmd_config_rss_hash_key {
1766         cmdline_fixed_string_t port;
1767         cmdline_fixed_string_t config;
1768         uint8_t port_id;
1769         cmdline_fixed_string_t rss_hash_key;
1770         cmdline_fixed_string_t rss_type;
1771         cmdline_fixed_string_t key;
1772 };
1773
1774 static uint8_t
1775 hexa_digit_to_value(char hexa_digit)
1776 {
1777         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1778                 return (uint8_t) (hexa_digit - '0');
1779         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1780                 return (uint8_t) ((hexa_digit - 'a') + 10);
1781         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1782                 return (uint8_t) ((hexa_digit - 'A') + 10);
1783         /* Invalid hexa digit */
1784         return 0xFF;
1785 }
1786
1787 static uint8_t
1788 parse_and_check_key_hexa_digit(char *key, int idx)
1789 {
1790         uint8_t hexa_v;
1791
1792         hexa_v = hexa_digit_to_value(key[idx]);
1793         if (hexa_v == 0xFF)
1794                 printf("invalid key: character %c at position %d is not a "
1795                        "valid hexa digit\n", key[idx], idx);
1796         return hexa_v;
1797 }
1798
1799 static void
1800 cmd_config_rss_hash_key_parsed(void *parsed_result,
1801                                __attribute__((unused)) struct cmdline *cl,
1802                                __attribute__((unused)) void *data)
1803 {
1804         struct cmd_config_rss_hash_key *res = parsed_result;
1805         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1806         uint8_t xdgt0;
1807         uint8_t xdgt1;
1808         int i;
1809         struct rte_eth_dev_info dev_info;
1810         uint8_t hash_key_size;
1811         uint32_t key_len;
1812
1813         memset(&dev_info, 0, sizeof(dev_info));
1814         rte_eth_dev_info_get(res->port_id, &dev_info);
1815         if (dev_info.hash_key_size > 0 &&
1816                         dev_info.hash_key_size <= sizeof(hash_key))
1817                 hash_key_size = dev_info.hash_key_size;
1818         else {
1819                 printf("dev_info did not provide a valid hash key size\n");
1820                 return;
1821         }
1822         /* Check the length of the RSS hash key */
1823         key_len = strlen(res->key);
1824         if (key_len != (hash_key_size * 2)) {
1825                 printf("key length: %d invalid - key must be a string of %d"
1826                            " hexa-decimal numbers\n",
1827                            (int) key_len, hash_key_size * 2);
1828                 return;
1829         }
1830         /* Translate RSS hash key into binary representation */
1831         for (i = 0; i < hash_key_size; i++) {
1832                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1833                 if (xdgt0 == 0xFF)
1834                         return;
1835                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1836                 if (xdgt1 == 0xFF)
1837                         return;
1838                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1839         }
1840         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1841                         hash_key_size);
1842 }
1843
1844 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1846 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1848                                  "config");
1849 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1850         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1851 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1853                                  rss_hash_key, "rss-hash-key");
1854 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1856                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1857                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1858                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1859                                  "ipv6-tcp-ex#ipv6-udp-ex");
1860 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1862
1863 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1864         .f = cmd_config_rss_hash_key_parsed,
1865         .data = NULL,
1866         .help_str = "port config <port_id> rss-hash-key "
1867                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1868                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1869                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1870                 "<string of hex digits (variable length, NIC dependent)>",
1871         .tokens = {
1872                 (void *)&cmd_config_rss_hash_key_port,
1873                 (void *)&cmd_config_rss_hash_key_config,
1874                 (void *)&cmd_config_rss_hash_key_port_id,
1875                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1876                 (void *)&cmd_config_rss_hash_key_rss_type,
1877                 (void *)&cmd_config_rss_hash_key_value,
1878                 NULL,
1879         },
1880 };
1881
1882 /* *** configure port rxq/txq start/stop *** */
1883 struct cmd_config_rxtx_queue {
1884         cmdline_fixed_string_t port;
1885         uint8_t portid;
1886         cmdline_fixed_string_t rxtxq;
1887         uint16_t qid;
1888         cmdline_fixed_string_t opname;
1889 };
1890
1891 static void
1892 cmd_config_rxtx_queue_parsed(void *parsed_result,
1893                         __attribute__((unused)) struct cmdline *cl,
1894                         __attribute__((unused)) void *data)
1895 {
1896         struct cmd_config_rxtx_queue *res = parsed_result;
1897         uint8_t isrx;
1898         uint8_t isstart;
1899         int ret = 0;
1900
1901         if (test_done == 0) {
1902                 printf("Please stop forwarding first\n");
1903                 return;
1904         }
1905
1906         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1907                 return;
1908
1909         if (port_is_started(res->portid) != 1) {
1910                 printf("Please start port %u first\n", res->portid);
1911                 return;
1912         }
1913
1914         if (!strcmp(res->rxtxq, "rxq"))
1915                 isrx = 1;
1916         else if (!strcmp(res->rxtxq, "txq"))
1917                 isrx = 0;
1918         else {
1919                 printf("Unknown parameter\n");
1920                 return;
1921         }
1922
1923         if (isrx && rx_queue_id_is_invalid(res->qid))
1924                 return;
1925         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1926                 return;
1927
1928         if (!strcmp(res->opname, "start"))
1929                 isstart = 1;
1930         else if (!strcmp(res->opname, "stop"))
1931                 isstart = 0;
1932         else {
1933                 printf("Unknown parameter\n");
1934                 return;
1935         }
1936
1937         if (isstart && isrx)
1938                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1939         else if (!isstart && isrx)
1940                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1941         else if (isstart && !isrx)
1942                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1943         else
1944                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1945
1946         if (ret == -ENOTSUP)
1947                 printf("Function not supported in PMD driver\n");
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1952 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1953         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1954 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1956 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1957         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1958 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1960                                                 "start#stop");
1961
1962 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1963         .f = cmd_config_rxtx_queue_parsed,
1964         .data = NULL,
1965         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1966         .tokens = {
1967                 (void *)&cmd_config_speed_all_port,
1968                 (void *)&cmd_config_rxtx_queue_portid,
1969                 (void *)&cmd_config_rxtx_queue_rxtxq,
1970                 (void *)&cmd_config_rxtx_queue_qid,
1971                 (void *)&cmd_config_rxtx_queue_opname,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** Configure RSS RETA *** */
1977 struct cmd_config_rss_reta {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t keyword;
1980         uint8_t port_id;
1981         cmdline_fixed_string_t name;
1982         cmdline_fixed_string_t list_name;
1983         cmdline_fixed_string_t list_of_items;
1984 };
1985
1986 static int
1987 parse_reta_config(const char *str,
1988                   struct rte_eth_rss_reta_entry64 *reta_conf,
1989                   uint16_t nb_entries)
1990 {
1991         int i;
1992         unsigned size;
1993         uint16_t hash_index, idx, shift;
1994         uint16_t nb_queue;
1995         char s[256];
1996         const char *p, *p0 = str;
1997         char *end;
1998         enum fieldnames {
1999                 FLD_HASH_INDEX = 0,
2000                 FLD_QUEUE,
2001                 _NUM_FLD
2002         };
2003         unsigned long int_fld[_NUM_FLD];
2004         char *str_fld[_NUM_FLD];
2005
2006         while ((p = strchr(p0,'(')) != NULL) {
2007                 ++p;
2008                 if((p0 = strchr(p,')')) == NULL)
2009                         return -1;
2010
2011                 size = p0 - p;
2012                 if(size >= sizeof(s))
2013                         return -1;
2014
2015                 snprintf(s, sizeof(s), "%.*s", size, p);
2016                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2017                         return -1;
2018                 for (i = 0; i < _NUM_FLD; i++) {
2019                         errno = 0;
2020                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2021                         if (errno != 0 || end == str_fld[i] ||
2022                                         int_fld[i] > 65535)
2023                                 return -1;
2024                 }
2025
2026                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2027                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2028
2029                 if (hash_index >= nb_entries) {
2030                         printf("Invalid RETA hash index=%d\n", hash_index);
2031                         return -1;
2032                 }
2033
2034                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2035                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2036                 reta_conf[idx].mask |= (1ULL << shift);
2037                 reta_conf[idx].reta[shift] = nb_queue;
2038         }
2039
2040         return 0;
2041 }
2042
2043 static void
2044 cmd_set_rss_reta_parsed(void *parsed_result,
2045                         __attribute__((unused)) struct cmdline *cl,
2046                         __attribute__((unused)) void *data)
2047 {
2048         int ret;
2049         struct rte_eth_dev_info dev_info;
2050         struct rte_eth_rss_reta_entry64 reta_conf[8];
2051         struct cmd_config_rss_reta *res = parsed_result;
2052
2053         memset(&dev_info, 0, sizeof(dev_info));
2054         rte_eth_dev_info_get(res->port_id, &dev_info);
2055         if (dev_info.reta_size == 0) {
2056                 printf("Redirection table size is 0 which is "
2057                                         "invalid for RSS\n");
2058                 return;
2059         } else
2060                 printf("The reta size of port %d is %u\n",
2061                         res->port_id, dev_info.reta_size);
2062         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2063                 printf("Currently do not support more than %u entries of "
2064                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2065                 return;
2066         }
2067
2068         memset(reta_conf, 0, sizeof(reta_conf));
2069         if (!strcmp(res->list_name, "reta")) {
2070                 if (parse_reta_config(res->list_of_items, reta_conf,
2071                                                 dev_info.reta_size)) {
2072                         printf("Invalid RSS Redirection Table "
2073                                         "config entered\n");
2074                         return;
2075                 }
2076                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2077                                 reta_conf, dev_info.reta_size);
2078                 if (ret != 0)
2079                         printf("Bad redirection table parameter, "
2080                                         "return code = %d \n", ret);
2081         }
2082 }
2083
2084 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2086 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2088 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2089         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2090 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2091         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2092 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2094 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2095         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2096                                  NULL);
2097 cmdline_parse_inst_t cmd_config_rss_reta = {
2098         .f = cmd_set_rss_reta_parsed,
2099         .data = NULL,
2100         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2101         .tokens = {
2102                 (void *)&cmd_config_rss_reta_port,
2103                 (void *)&cmd_config_rss_reta_keyword,
2104                 (void *)&cmd_config_rss_reta_port_id,
2105                 (void *)&cmd_config_rss_reta_name,
2106                 (void *)&cmd_config_rss_reta_list_name,
2107                 (void *)&cmd_config_rss_reta_list_of_items,
2108                 NULL,
2109         },
2110 };
2111
2112 /* *** SHOW PORT RETA INFO *** */
2113 struct cmd_showport_reta {
2114         cmdline_fixed_string_t show;
2115         cmdline_fixed_string_t port;
2116         uint8_t port_id;
2117         cmdline_fixed_string_t rss;
2118         cmdline_fixed_string_t reta;
2119         uint16_t size;
2120         cmdline_fixed_string_t list_of_items;
2121 };
2122
2123 static int
2124 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2125                            uint16_t nb_entries,
2126                            char *str)
2127 {
2128         uint32_t size;
2129         const char *p, *p0 = str;
2130         char s[256];
2131         char *end;
2132         char *str_fld[8];
2133         uint16_t i;
2134         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2135                         RTE_RETA_GROUP_SIZE;
2136         int ret;
2137
2138         p = strchr(p0, '(');
2139         if (p == NULL)
2140                 return -1;
2141         p++;
2142         p0 = strchr(p, ')');
2143         if (p0 == NULL)
2144                 return -1;
2145         size = p0 - p;
2146         if (size >= sizeof(s)) {
2147                 printf("The string size exceeds the internal buffer size\n");
2148                 return -1;
2149         }
2150         snprintf(s, sizeof(s), "%.*s", size, p);
2151         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2152         if (ret <= 0 || ret != num) {
2153                 printf("The bits of masks do not match the number of "
2154                                         "reta entries: %u\n", num);
2155                 return -1;
2156         }
2157         for (i = 0; i < ret; i++)
2158                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2159
2160         return 0;
2161 }
2162
2163 static void
2164 cmd_showport_reta_parsed(void *parsed_result,
2165                          __attribute__((unused)) struct cmdline *cl,
2166                          __attribute__((unused)) void *data)
2167 {
2168         struct cmd_showport_reta *res = parsed_result;
2169         struct rte_eth_rss_reta_entry64 reta_conf[8];
2170         struct rte_eth_dev_info dev_info;
2171
2172         memset(&dev_info, 0, sizeof(dev_info));
2173         rte_eth_dev_info_get(res->port_id, &dev_info);
2174         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2175                                 res->size > ETH_RSS_RETA_SIZE_512) {
2176                 printf("Invalid redirection table size: %u\n", res->size);
2177                 return;
2178         }
2179
2180         memset(reta_conf, 0, sizeof(reta_conf));
2181         if (showport_parse_reta_config(reta_conf, res->size,
2182                                 res->list_of_items) < 0) {
2183                 printf("Invalid string: %s for reta masks\n",
2184                                         res->list_of_items);
2185                 return;
2186         }
2187         port_rss_reta_info(res->port_id, reta_conf, res->size);
2188 }
2189
2190 cmdline_parse_token_string_t cmd_showport_reta_show =
2191         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2192 cmdline_parse_token_string_t cmd_showport_reta_port =
2193         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2194 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2195         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2196 cmdline_parse_token_string_t cmd_showport_reta_rss =
2197         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2198 cmdline_parse_token_string_t cmd_showport_reta_reta =
2199         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2200 cmdline_parse_token_num_t cmd_showport_reta_size =
2201         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2202 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2203         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2204                                         list_of_items, NULL);
2205
2206 cmdline_parse_inst_t cmd_showport_reta = {
2207         .f = cmd_showport_reta_parsed,
2208         .data = NULL,
2209         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2210         .tokens = {
2211                 (void *)&cmd_showport_reta_show,
2212                 (void *)&cmd_showport_reta_port,
2213                 (void *)&cmd_showport_reta_port_id,
2214                 (void *)&cmd_showport_reta_rss,
2215                 (void *)&cmd_showport_reta_reta,
2216                 (void *)&cmd_showport_reta_size,
2217                 (void *)&cmd_showport_reta_list_of_items,
2218                 NULL,
2219         },
2220 };
2221
2222 /* *** Show RSS hash configuration *** */
2223 struct cmd_showport_rss_hash {
2224         cmdline_fixed_string_t show;
2225         cmdline_fixed_string_t port;
2226         uint8_t port_id;
2227         cmdline_fixed_string_t rss_hash;
2228         cmdline_fixed_string_t rss_type;
2229         cmdline_fixed_string_t key; /* optional argument */
2230 };
2231
2232 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2233                                 __attribute__((unused)) struct cmdline *cl,
2234                                 void *show_rss_key)
2235 {
2236         struct cmd_showport_rss_hash *res = parsed_result;
2237
2238         port_rss_hash_conf_show(res->port_id, res->rss_type,
2239                                 show_rss_key != NULL);
2240 }
2241
2242 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2243         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2244 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2245         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2246 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2247         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2248 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2249         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2250                                  "rss-hash");
2251 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2252         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2253                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2254                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2255                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2256                                  "ipv6-tcp-ex#ipv6-udp-ex");
2257 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2258         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2259
2260 cmdline_parse_inst_t cmd_showport_rss_hash = {
2261         .f = cmd_showport_rss_hash_parsed,
2262         .data = NULL,
2263         .help_str = "show port <port_id> rss-hash "
2264                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2265                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2266                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2267         .tokens = {
2268                 (void *)&cmd_showport_rss_hash_show,
2269                 (void *)&cmd_showport_rss_hash_port,
2270                 (void *)&cmd_showport_rss_hash_port_id,
2271                 (void *)&cmd_showport_rss_hash_rss_hash,
2272                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2273                 NULL,
2274         },
2275 };
2276
2277 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2278         .f = cmd_showport_rss_hash_parsed,
2279         .data = (void *)1,
2280         .help_str = "show port <port_id> rss-hash "
2281                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2282                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2283                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2284         .tokens = {
2285                 (void *)&cmd_showport_rss_hash_show,
2286                 (void *)&cmd_showport_rss_hash_port,
2287                 (void *)&cmd_showport_rss_hash_port_id,
2288                 (void *)&cmd_showport_rss_hash_rss_hash,
2289                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2290                 (void *)&cmd_showport_rss_hash_rss_key,
2291                 NULL,
2292         },
2293 };
2294
2295 /* *** Configure DCB *** */
2296 struct cmd_config_dcb {
2297         cmdline_fixed_string_t port;
2298         cmdline_fixed_string_t config;
2299         uint8_t port_id;
2300         cmdline_fixed_string_t dcb;
2301         cmdline_fixed_string_t vt;
2302         cmdline_fixed_string_t vt_en;
2303         uint8_t num_tcs;
2304         cmdline_fixed_string_t pfc;
2305         cmdline_fixed_string_t pfc_en;
2306 };
2307
2308 static void
2309 cmd_config_dcb_parsed(void *parsed_result,
2310                         __attribute__((unused)) struct cmdline *cl,
2311                         __attribute__((unused)) void *data)
2312 {
2313         struct cmd_config_dcb *res = parsed_result;
2314         portid_t port_id = res->port_id;
2315         struct rte_port *port;
2316         uint8_t pfc_en;
2317         int ret;
2318
2319         port = &ports[port_id];
2320         /** Check if the port is not started **/
2321         if (port->port_status != RTE_PORT_STOPPED) {
2322                 printf("Please stop port %d first\n", port_id);
2323                 return;
2324         }
2325
2326         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2327                 printf("The invalid number of traffic class,"
2328                         " only 4 or 8 allowed.\n");
2329                 return;
2330         }
2331
2332         if (nb_fwd_lcores < res->num_tcs) {
2333                 printf("nb_cores shouldn't be less than number of TCs.\n");
2334                 return;
2335         }
2336         if (!strncmp(res->pfc_en, "on", 2))
2337                 pfc_en = 1;
2338         else
2339                 pfc_en = 0;
2340
2341         /* DCB in VT mode */
2342         if (!strncmp(res->vt_en, "on", 2))
2343                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2344                                 (enum rte_eth_nb_tcs)res->num_tcs,
2345                                 pfc_en);
2346         else
2347                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2348                                 (enum rte_eth_nb_tcs)res->num_tcs,
2349                                 pfc_en);
2350
2351
2352         if (ret != 0) {
2353                 printf("Cannot initialize network ports.\n");
2354                 return;
2355         }
2356
2357         cmd_reconfig_device_queue(port_id, 1, 1);
2358 }
2359
2360 cmdline_parse_token_string_t cmd_config_dcb_port =
2361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2362 cmdline_parse_token_string_t cmd_config_dcb_config =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2364 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2365         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2366 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2368 cmdline_parse_token_string_t cmd_config_dcb_vt =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2370 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2372 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2373         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2374 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2376 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2378
2379 cmdline_parse_inst_t cmd_config_dcb = {
2380         .f = cmd_config_dcb_parsed,
2381         .data = NULL,
2382         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2383         .tokens = {
2384                 (void *)&cmd_config_dcb_port,
2385                 (void *)&cmd_config_dcb_config,
2386                 (void *)&cmd_config_dcb_port_id,
2387                 (void *)&cmd_config_dcb_dcb,
2388                 (void *)&cmd_config_dcb_vt,
2389                 (void *)&cmd_config_dcb_vt_en,
2390                 (void *)&cmd_config_dcb_num_tcs,
2391                 (void *)&cmd_config_dcb_pfc,
2392                 (void *)&cmd_config_dcb_pfc_en,
2393                 NULL,
2394         },
2395 };
2396
2397 /* *** configure number of packets per burst *** */
2398 struct cmd_config_burst {
2399         cmdline_fixed_string_t port;
2400         cmdline_fixed_string_t keyword;
2401         cmdline_fixed_string_t all;
2402         cmdline_fixed_string_t name;
2403         uint16_t value;
2404 };
2405
2406 static void
2407 cmd_config_burst_parsed(void *parsed_result,
2408                         __attribute__((unused)) struct cmdline *cl,
2409                         __attribute__((unused)) void *data)
2410 {
2411         struct cmd_config_burst *res = parsed_result;
2412
2413         if (!all_ports_stopped()) {
2414                 printf("Please stop all ports first\n");
2415                 return;
2416         }
2417
2418         if (!strcmp(res->name, "burst")) {
2419                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2420                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2421                         return;
2422                 }
2423                 nb_pkt_per_burst = res->value;
2424         } else {
2425                 printf("Unknown parameter\n");
2426                 return;
2427         }
2428
2429         init_port_config();
2430
2431         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2432 }
2433
2434 cmdline_parse_token_string_t cmd_config_burst_port =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2436 cmdline_parse_token_string_t cmd_config_burst_keyword =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2438 cmdline_parse_token_string_t cmd_config_burst_all =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2440 cmdline_parse_token_string_t cmd_config_burst_name =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2442 cmdline_parse_token_num_t cmd_config_burst_value =
2443         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2444
2445 cmdline_parse_inst_t cmd_config_burst = {
2446         .f = cmd_config_burst_parsed,
2447         .data = NULL,
2448         .help_str = "port config all burst <value>",
2449         .tokens = {
2450                 (void *)&cmd_config_burst_port,
2451                 (void *)&cmd_config_burst_keyword,
2452                 (void *)&cmd_config_burst_all,
2453                 (void *)&cmd_config_burst_name,
2454                 (void *)&cmd_config_burst_value,
2455                 NULL,
2456         },
2457 };
2458
2459 /* *** configure rx/tx queues *** */
2460 struct cmd_config_thresh {
2461         cmdline_fixed_string_t port;
2462         cmdline_fixed_string_t keyword;
2463         cmdline_fixed_string_t all;
2464         cmdline_fixed_string_t name;
2465         uint8_t value;
2466 };
2467
2468 static void
2469 cmd_config_thresh_parsed(void *parsed_result,
2470                         __attribute__((unused)) struct cmdline *cl,
2471                         __attribute__((unused)) void *data)
2472 {
2473         struct cmd_config_thresh *res = parsed_result;
2474
2475         if (!all_ports_stopped()) {
2476                 printf("Please stop all ports first\n");
2477                 return;
2478         }
2479
2480         if (!strcmp(res->name, "txpt"))
2481                 tx_pthresh = res->value;
2482         else if(!strcmp(res->name, "txht"))
2483                 tx_hthresh = res->value;
2484         else if(!strcmp(res->name, "txwt"))
2485                 tx_wthresh = res->value;
2486         else if(!strcmp(res->name, "rxpt"))
2487                 rx_pthresh = res->value;
2488         else if(!strcmp(res->name, "rxht"))
2489                 rx_hthresh = res->value;
2490         else if(!strcmp(res->name, "rxwt"))
2491                 rx_wthresh = res->value;
2492         else {
2493                 printf("Unknown parameter\n");
2494                 return;
2495         }
2496
2497         init_port_config();
2498
2499         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2500 }
2501
2502 cmdline_parse_token_string_t cmd_config_thresh_port =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2504 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2505         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2506 cmdline_parse_token_string_t cmd_config_thresh_all =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2508 cmdline_parse_token_string_t cmd_config_thresh_name =
2509         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2510                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2511 cmdline_parse_token_num_t cmd_config_thresh_value =
2512         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2513
2514 cmdline_parse_inst_t cmd_config_thresh = {
2515         .f = cmd_config_thresh_parsed,
2516         .data = NULL,
2517         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2518         .tokens = {
2519                 (void *)&cmd_config_thresh_port,
2520                 (void *)&cmd_config_thresh_keyword,
2521                 (void *)&cmd_config_thresh_all,
2522                 (void *)&cmd_config_thresh_name,
2523                 (void *)&cmd_config_thresh_value,
2524                 NULL,
2525         },
2526 };
2527
2528 /* *** configure free/rs threshold *** */
2529 struct cmd_config_threshold {
2530         cmdline_fixed_string_t port;
2531         cmdline_fixed_string_t keyword;
2532         cmdline_fixed_string_t all;
2533         cmdline_fixed_string_t name;
2534         uint16_t value;
2535 };
2536
2537 static void
2538 cmd_config_threshold_parsed(void *parsed_result,
2539                         __attribute__((unused)) struct cmdline *cl,
2540                         __attribute__((unused)) void *data)
2541 {
2542         struct cmd_config_threshold *res = parsed_result;
2543
2544         if (!all_ports_stopped()) {
2545                 printf("Please stop all ports first\n");
2546                 return;
2547         }
2548
2549         if (!strcmp(res->name, "txfreet"))
2550                 tx_free_thresh = res->value;
2551         else if (!strcmp(res->name, "txrst"))
2552                 tx_rs_thresh = res->value;
2553         else if (!strcmp(res->name, "rxfreet"))
2554                 rx_free_thresh = res->value;
2555         else {
2556                 printf("Unknown parameter\n");
2557                 return;
2558         }
2559
2560         init_port_config();
2561
2562         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2563 }
2564
2565 cmdline_parse_token_string_t cmd_config_threshold_port =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2567 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2568         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2569                                                                 "config");
2570 cmdline_parse_token_string_t cmd_config_threshold_all =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2572 cmdline_parse_token_string_t cmd_config_threshold_name =
2573         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2574                                                 "txfreet#txrst#rxfreet");
2575 cmdline_parse_token_num_t cmd_config_threshold_value =
2576         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2577
2578 cmdline_parse_inst_t cmd_config_threshold = {
2579         .f = cmd_config_threshold_parsed,
2580         .data = NULL,
2581         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2582         .tokens = {
2583                 (void *)&cmd_config_threshold_port,
2584                 (void *)&cmd_config_threshold_keyword,
2585                 (void *)&cmd_config_threshold_all,
2586                 (void *)&cmd_config_threshold_name,
2587                 (void *)&cmd_config_threshold_value,
2588                 NULL,
2589         },
2590 };
2591
2592 /* *** stop *** */
2593 struct cmd_stop_result {
2594         cmdline_fixed_string_t stop;
2595 };
2596
2597 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2598                             __attribute__((unused)) struct cmdline *cl,
2599                             __attribute__((unused)) void *data)
2600 {
2601         stop_packet_forwarding();
2602 }
2603
2604 cmdline_parse_token_string_t cmd_stop_stop =
2605         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2606
2607 cmdline_parse_inst_t cmd_stop = {
2608         .f = cmd_stop_parsed,
2609         .data = NULL,
2610         .help_str = "stop: Stop packet forwarding",
2611         .tokens = {
2612                 (void *)&cmd_stop_stop,
2613                 NULL,
2614         },
2615 };
2616
2617 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2618
2619 unsigned int
2620 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2621                 unsigned int *parsed_items, int check_unique_values)
2622 {
2623         unsigned int nb_item;
2624         unsigned int value;
2625         unsigned int i;
2626         unsigned int j;
2627         int value_ok;
2628         char c;
2629
2630         /*
2631          * First parse all items in the list and store their value.
2632          */
2633         value = 0;
2634         nb_item = 0;
2635         value_ok = 0;
2636         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2637                 c = str[i];
2638                 if ((c >= '0') && (c <= '9')) {
2639                         value = (unsigned int) (value * 10 + (c - '0'));
2640                         value_ok = 1;
2641                         continue;
2642                 }
2643                 if (c != ',') {
2644                         printf("character %c is not a decimal digit\n", c);
2645                         return 0;
2646                 }
2647                 if (! value_ok) {
2648                         printf("No valid value before comma\n");
2649                         return 0;
2650                 }
2651                 if (nb_item < max_items) {
2652                         parsed_items[nb_item] = value;
2653                         value_ok = 0;
2654                         value = 0;
2655                 }
2656                 nb_item++;
2657         }
2658         if (nb_item >= max_items) {
2659                 printf("Number of %s = %u > %u (maximum items)\n",
2660                        item_name, nb_item + 1, max_items);
2661                 return 0;
2662         }
2663         parsed_items[nb_item++] = value;
2664         if (! check_unique_values)
2665                 return nb_item;
2666
2667         /*
2668          * Then, check that all values in the list are differents.
2669          * No optimization here...
2670          */
2671         for (i = 0; i < nb_item; i++) {
2672                 for (j = i + 1; j < nb_item; j++) {
2673                         if (parsed_items[j] == parsed_items[i]) {
2674                                 printf("duplicated %s %u at index %u and %u\n",
2675                                        item_name, parsed_items[i], i, j);
2676                                 return 0;
2677                         }
2678                 }
2679         }
2680         return nb_item;
2681 }
2682
2683 struct cmd_set_list_result {
2684         cmdline_fixed_string_t cmd_keyword;
2685         cmdline_fixed_string_t list_name;
2686         cmdline_fixed_string_t list_of_items;
2687 };
2688
2689 static void cmd_set_list_parsed(void *parsed_result,
2690                                 __attribute__((unused)) struct cmdline *cl,
2691                                 __attribute__((unused)) void *data)
2692 {
2693         struct cmd_set_list_result *res;
2694         union {
2695                 unsigned int lcorelist[RTE_MAX_LCORE];
2696                 unsigned int portlist[RTE_MAX_ETHPORTS];
2697         } parsed_items;
2698         unsigned int nb_item;
2699
2700         if (test_done == 0) {
2701                 printf("Please stop forwarding first\n");
2702                 return;
2703         }
2704
2705         res = parsed_result;
2706         if (!strcmp(res->list_name, "corelist")) {
2707                 nb_item = parse_item_list(res->list_of_items, "core",
2708                                           RTE_MAX_LCORE,
2709                                           parsed_items.lcorelist, 1);
2710                 if (nb_item > 0) {
2711                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2712                         fwd_config_setup();
2713                 }
2714                 return;
2715         }
2716         if (!strcmp(res->list_name, "portlist")) {
2717                 nb_item = parse_item_list(res->list_of_items, "port",
2718                                           RTE_MAX_ETHPORTS,
2719                                           parsed_items.portlist, 1);
2720                 if (nb_item > 0) {
2721                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2722                         fwd_config_setup();
2723                 }
2724         }
2725 }
2726
2727 cmdline_parse_token_string_t cmd_set_list_keyword =
2728         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2729                                  "set");
2730 cmdline_parse_token_string_t cmd_set_list_name =
2731         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2732                                  "corelist#portlist");
2733 cmdline_parse_token_string_t cmd_set_list_of_items =
2734         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2735                                  NULL);
2736
2737 cmdline_parse_inst_t cmd_set_fwd_list = {
2738         .f = cmd_set_list_parsed,
2739         .data = NULL,
2740         .help_str = "set corelist|portlist <list0[,list1]*>",
2741         .tokens = {
2742                 (void *)&cmd_set_list_keyword,
2743                 (void *)&cmd_set_list_name,
2744                 (void *)&cmd_set_list_of_items,
2745                 NULL,
2746         },
2747 };
2748
2749 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2750
2751 struct cmd_setmask_result {
2752         cmdline_fixed_string_t set;
2753         cmdline_fixed_string_t mask;
2754         uint64_t hexavalue;
2755 };
2756
2757 static void cmd_set_mask_parsed(void *parsed_result,
2758                                 __attribute__((unused)) struct cmdline *cl,
2759                                 __attribute__((unused)) void *data)
2760 {
2761         struct cmd_setmask_result *res = parsed_result;
2762
2763         if (test_done == 0) {
2764                 printf("Please stop forwarding first\n");
2765                 return;
2766         }
2767         if (!strcmp(res->mask, "coremask")) {
2768                 set_fwd_lcores_mask(res->hexavalue);
2769                 fwd_config_setup();
2770         } else if (!strcmp(res->mask, "portmask")) {
2771                 set_fwd_ports_mask(res->hexavalue);
2772                 fwd_config_setup();
2773         }
2774 }
2775
2776 cmdline_parse_token_string_t cmd_setmask_set =
2777         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2778 cmdline_parse_token_string_t cmd_setmask_mask =
2779         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2780                                  "coremask#portmask");
2781 cmdline_parse_token_num_t cmd_setmask_value =
2782         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2783
2784 cmdline_parse_inst_t cmd_set_fwd_mask = {
2785         .f = cmd_set_mask_parsed,
2786         .data = NULL,
2787         .help_str = "set coremask|portmask <hexadecimal value>",
2788         .tokens = {
2789                 (void *)&cmd_setmask_set,
2790                 (void *)&cmd_setmask_mask,
2791                 (void *)&cmd_setmask_value,
2792                 NULL,
2793         },
2794 };
2795
2796 /*
2797  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2798  */
2799 struct cmd_set_result {
2800         cmdline_fixed_string_t set;
2801         cmdline_fixed_string_t what;
2802         uint16_t value;
2803 };
2804
2805 static void cmd_set_parsed(void *parsed_result,
2806                            __attribute__((unused)) struct cmdline *cl,
2807                            __attribute__((unused)) void *data)
2808 {
2809         struct cmd_set_result *res = parsed_result;
2810         if (!strcmp(res->what, "nbport")) {
2811                 set_fwd_ports_number(res->value);
2812                 fwd_config_setup();
2813         } else if (!strcmp(res->what, "nbcore")) {
2814                 set_fwd_lcores_number(res->value);
2815                 fwd_config_setup();
2816         } else if (!strcmp(res->what, "burst"))
2817                 set_nb_pkt_per_burst(res->value);
2818         else if (!strcmp(res->what, "verbose"))
2819                 set_verbose_level(res->value);
2820 }
2821
2822 cmdline_parse_token_string_t cmd_set_set =
2823         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2824 cmdline_parse_token_string_t cmd_set_what =
2825         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2826                                  "nbport#nbcore#burst#verbose");
2827 cmdline_parse_token_num_t cmd_set_value =
2828         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2829
2830 cmdline_parse_inst_t cmd_set_numbers = {
2831         .f = cmd_set_parsed,
2832         .data = NULL,
2833         .help_str = "set nbport|nbcore|burst|verbose <value>",
2834         .tokens = {
2835                 (void *)&cmd_set_set,
2836                 (void *)&cmd_set_what,
2837                 (void *)&cmd_set_value,
2838                 NULL,
2839         },
2840 };
2841
2842 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2843
2844 struct cmd_set_txpkts_result {
2845         cmdline_fixed_string_t cmd_keyword;
2846         cmdline_fixed_string_t txpkts;
2847         cmdline_fixed_string_t seg_lengths;
2848 };
2849
2850 static void
2851 cmd_set_txpkts_parsed(void *parsed_result,
2852                       __attribute__((unused)) struct cmdline *cl,
2853                       __attribute__((unused)) void *data)
2854 {
2855         struct cmd_set_txpkts_result *res;
2856         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2857         unsigned int nb_segs;
2858
2859         res = parsed_result;
2860         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2861                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2862         if (nb_segs > 0)
2863                 set_tx_pkt_segments(seg_lengths, nb_segs);
2864 }
2865
2866 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2867         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2868                                  cmd_keyword, "set");
2869 cmdline_parse_token_string_t cmd_set_txpkts_name =
2870         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2871                                  txpkts, "txpkts");
2872 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2873         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2874                                  seg_lengths, NULL);
2875
2876 cmdline_parse_inst_t cmd_set_txpkts = {
2877         .f = cmd_set_txpkts_parsed,
2878         .data = NULL,
2879         .help_str = "set txpkts <len0[,len1]*>",
2880         .tokens = {
2881                 (void *)&cmd_set_txpkts_keyword,
2882                 (void *)&cmd_set_txpkts_name,
2883                 (void *)&cmd_set_txpkts_lengths,
2884                 NULL,
2885         },
2886 };
2887
2888 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2889
2890 struct cmd_set_txsplit_result {
2891         cmdline_fixed_string_t cmd_keyword;
2892         cmdline_fixed_string_t txsplit;
2893         cmdline_fixed_string_t mode;
2894 };
2895
2896 static void
2897 cmd_set_txsplit_parsed(void *parsed_result,
2898                       __attribute__((unused)) struct cmdline *cl,
2899                       __attribute__((unused)) void *data)
2900 {
2901         struct cmd_set_txsplit_result *res;
2902
2903         res = parsed_result;
2904         set_tx_pkt_split(res->mode);
2905 }
2906
2907 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2908         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2909                                  cmd_keyword, "set");
2910 cmdline_parse_token_string_t cmd_set_txsplit_name =
2911         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2912                                  txsplit, "txsplit");
2913 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2914         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2915                                  mode, NULL);
2916
2917 cmdline_parse_inst_t cmd_set_txsplit = {
2918         .f = cmd_set_txsplit_parsed,
2919         .data = NULL,
2920         .help_str = "set txsplit on|off|rand",
2921         .tokens = {
2922                 (void *)&cmd_set_txsplit_keyword,
2923                 (void *)&cmd_set_txsplit_name,
2924                 (void *)&cmd_set_txsplit_mode,
2925                 NULL,
2926         },
2927 };
2928
2929 /* *** CONFIG TX QUEUE FLAGS *** */
2930
2931 struct cmd_config_txqflags_result {
2932         cmdline_fixed_string_t port;
2933         cmdline_fixed_string_t config;
2934         cmdline_fixed_string_t all;
2935         cmdline_fixed_string_t what;
2936         int32_t hexvalue;
2937 };
2938
2939 static void cmd_config_txqflags_parsed(void *parsed_result,
2940                                 __attribute__((unused)) struct cmdline *cl,
2941                                 __attribute__((unused)) void *data)
2942 {
2943         struct cmd_config_txqflags_result *res = parsed_result;
2944
2945         if (!all_ports_stopped()) {
2946                 printf("Please stop all ports first\n");
2947                 return;
2948         }
2949
2950         if (strcmp(res->what, "txqflags")) {
2951                 printf("Unknown parameter\n");
2952                 return;
2953         }
2954
2955         if (res->hexvalue >= 0) {
2956                 txq_flags = res->hexvalue;
2957         } else {
2958                 printf("txqflags must be >= 0\n");
2959                 return;
2960         }
2961
2962         init_port_config();
2963
2964         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2965 }
2966
2967 cmdline_parse_token_string_t cmd_config_txqflags_port =
2968         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2969                                  "port");
2970 cmdline_parse_token_string_t cmd_config_txqflags_config =
2971         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2972                                  "config");
2973 cmdline_parse_token_string_t cmd_config_txqflags_all =
2974         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2975                                  "all");
2976 cmdline_parse_token_string_t cmd_config_txqflags_what =
2977         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2978                                  "txqflags");
2979 cmdline_parse_token_num_t cmd_config_txqflags_value =
2980         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2981                                 hexvalue, INT32);
2982
2983 cmdline_parse_inst_t cmd_config_txqflags = {
2984         .f = cmd_config_txqflags_parsed,
2985         .data = NULL,
2986         .help_str = "port config all txqflags <value>",
2987         .tokens = {
2988                 (void *)&cmd_config_txqflags_port,
2989                 (void *)&cmd_config_txqflags_config,
2990                 (void *)&cmd_config_txqflags_all,
2991                 (void *)&cmd_config_txqflags_what,
2992                 (void *)&cmd_config_txqflags_value,
2993                 NULL,
2994         },
2995 };
2996
2997 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2998 struct cmd_rx_vlan_filter_all_result {
2999         cmdline_fixed_string_t rx_vlan;
3000         cmdline_fixed_string_t what;
3001         cmdline_fixed_string_t all;
3002         uint8_t port_id;
3003 };
3004
3005 static void
3006 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3007                               __attribute__((unused)) struct cmdline *cl,
3008                               __attribute__((unused)) void *data)
3009 {
3010         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3011
3012         if (!strcmp(res->what, "add"))
3013                 rx_vlan_all_filter_set(res->port_id, 1);
3014         else
3015                 rx_vlan_all_filter_set(res->port_id, 0);
3016 }
3017
3018 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3019         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3020                                  rx_vlan, "rx_vlan");
3021 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3022         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3023                                  what, "add#rm");
3024 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3025         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3026                                  all, "all");
3027 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3028         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3029                               port_id, UINT8);
3030
3031 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3032         .f = cmd_rx_vlan_filter_all_parsed,
3033         .data = NULL,
3034         .help_str = "rx_vlan add|rm all <port_id>: "
3035                 "Add/Remove all identifiers to/from the set of VLAN "
3036                 "identifiers filtered by a port",
3037         .tokens = {
3038                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3039                 (void *)&cmd_rx_vlan_filter_all_what,
3040                 (void *)&cmd_rx_vlan_filter_all_all,
3041                 (void *)&cmd_rx_vlan_filter_all_portid,
3042                 NULL,
3043         },
3044 };
3045
3046 /* *** VLAN OFFLOAD SET ON A PORT *** */
3047 struct cmd_vlan_offload_result {
3048         cmdline_fixed_string_t vlan;
3049         cmdline_fixed_string_t set;
3050         cmdline_fixed_string_t vlan_type;
3051         cmdline_fixed_string_t what;
3052         cmdline_fixed_string_t on;
3053         cmdline_fixed_string_t port_id;
3054 };
3055
3056 static void
3057 cmd_vlan_offload_parsed(void *parsed_result,
3058                           __attribute__((unused)) struct cmdline *cl,
3059                           __attribute__((unused)) void *data)
3060 {
3061         int on;
3062         struct cmd_vlan_offload_result *res = parsed_result;
3063         char *str;
3064         int i, len = 0;
3065         portid_t port_id = 0;
3066         unsigned int tmp;
3067
3068         str = res->port_id;
3069         len = strnlen(str, STR_TOKEN_SIZE);
3070         i = 0;
3071         /* Get port_id first */
3072         while(i < len){
3073                 if(str[i] == ',')
3074                         break;
3075
3076                 i++;
3077         }
3078         str[i]='\0';
3079         tmp = strtoul(str, NULL, 0);
3080         /* If port_id greater that what portid_t can represent, return */
3081         if(tmp >= RTE_MAX_ETHPORTS)
3082                 return;
3083         port_id = (portid_t)tmp;
3084
3085         if (!strcmp(res->on, "on"))
3086                 on = 1;
3087         else
3088                 on = 0;
3089
3090         if (!strcmp(res->what, "strip"))
3091                 rx_vlan_strip_set(port_id,  on);
3092         else if(!strcmp(res->what, "stripq")){
3093                 uint16_t queue_id = 0;
3094
3095                 /* No queue_id, return */
3096                 if(i + 1 >= len) {
3097                         printf("must specify (port,queue_id)\n");
3098                         return;
3099                 }
3100                 tmp = strtoul(str + i + 1, NULL, 0);
3101                 /* If queue_id greater that what 16-bits can represent, return */
3102                 if(tmp > 0xffff)
3103                         return;
3104
3105                 queue_id = (uint16_t)tmp;
3106                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3107         }
3108         else if (!strcmp(res->what, "filter"))
3109                 rx_vlan_filter_set(port_id, on);
3110         else
3111                 vlan_extend_set(port_id, on);
3112
3113         return;
3114 }
3115
3116 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3117         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3118                                  vlan, "vlan");
3119 cmdline_parse_token_string_t cmd_vlan_offload_set =
3120         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3121                                  set, "set");
3122 cmdline_parse_token_string_t cmd_vlan_offload_what =
3123         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3124                                  what, "strip#filter#qinq#stripq");
3125 cmdline_parse_token_string_t cmd_vlan_offload_on =
3126         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3127                               on, "on#off");
3128 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3129         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3130                               port_id, NULL);
3131
3132 cmdline_parse_inst_t cmd_vlan_offload = {
3133         .f = cmd_vlan_offload_parsed,
3134         .data = NULL,
3135         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3136                 "<port_id[,queue_id]>: "
3137                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3138         .tokens = {
3139                 (void *)&cmd_vlan_offload_vlan,
3140                 (void *)&cmd_vlan_offload_set,
3141                 (void *)&cmd_vlan_offload_what,
3142                 (void *)&cmd_vlan_offload_on,
3143                 (void *)&cmd_vlan_offload_portid,
3144                 NULL,
3145         },
3146 };
3147
3148 /* *** VLAN TPID SET ON A PORT *** */
3149 struct cmd_vlan_tpid_result {
3150         cmdline_fixed_string_t vlan;
3151         cmdline_fixed_string_t set;
3152         cmdline_fixed_string_t vlan_type;
3153         cmdline_fixed_string_t what;
3154         uint16_t tp_id;
3155         uint8_t port_id;
3156 };
3157
3158 static void
3159 cmd_vlan_tpid_parsed(void *parsed_result,
3160                           __attribute__((unused)) struct cmdline *cl,
3161                           __attribute__((unused)) void *data)
3162 {
3163         struct cmd_vlan_tpid_result *res = parsed_result;
3164         enum rte_vlan_type vlan_type;
3165
3166         if (!strcmp(res->vlan_type, "inner"))
3167                 vlan_type = ETH_VLAN_TYPE_INNER;
3168         else if (!strcmp(res->vlan_type, "outer"))
3169                 vlan_type = ETH_VLAN_TYPE_OUTER;
3170         else {
3171                 printf("Unknown vlan type\n");
3172                 return;
3173         }
3174         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3175 }
3176
3177 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3178         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3179                                  vlan, "vlan");
3180 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3181         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3182                                  set, "set");
3183 cmdline_parse_token_string_t cmd_vlan_type =
3184         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3185                                  vlan_type, "inner#outer");
3186 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3187         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3188                                  what, "tpid");
3189 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3190         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3191                               tp_id, UINT16);
3192 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3193         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3194                               port_id, UINT8);
3195
3196 cmdline_parse_inst_t cmd_vlan_tpid = {
3197         .f = cmd_vlan_tpid_parsed,
3198         .data = NULL,
3199         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3200                 "Set the VLAN Ether type",
3201         .tokens = {
3202                 (void *)&cmd_vlan_tpid_vlan,
3203                 (void *)&cmd_vlan_tpid_set,
3204                 (void *)&cmd_vlan_type,
3205                 (void *)&cmd_vlan_tpid_what,
3206                 (void *)&cmd_vlan_tpid_tpid,
3207                 (void *)&cmd_vlan_tpid_portid,
3208                 NULL,
3209         },
3210 };
3211
3212 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3213 struct cmd_rx_vlan_filter_result {
3214         cmdline_fixed_string_t rx_vlan;
3215         cmdline_fixed_string_t what;
3216         uint16_t vlan_id;
3217         uint8_t port_id;
3218 };
3219
3220 static void
3221 cmd_rx_vlan_filter_parsed(void *parsed_result,
3222                           __attribute__((unused)) struct cmdline *cl,
3223                           __attribute__((unused)) void *data)
3224 {
3225         struct cmd_rx_vlan_filter_result *res = parsed_result;
3226
3227         if (!strcmp(res->what, "add"))
3228                 rx_vft_set(res->port_id, res->vlan_id, 1);
3229         else
3230                 rx_vft_set(res->port_id, res->vlan_id, 0);
3231 }
3232
3233 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3234         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3235                                  rx_vlan, "rx_vlan");
3236 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3237         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3238                                  what, "add#rm");
3239 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3240         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3241                               vlan_id, UINT16);
3242 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3243         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3244                               port_id, UINT8);
3245
3246 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3247         .f = cmd_rx_vlan_filter_parsed,
3248         .data = NULL,
3249         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3250                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3251                 "identifiers filtered by a port",
3252         .tokens = {
3253                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3254                 (void *)&cmd_rx_vlan_filter_what,
3255                 (void *)&cmd_rx_vlan_filter_vlanid,
3256                 (void *)&cmd_rx_vlan_filter_portid,
3257                 NULL,
3258         },
3259 };
3260
3261 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3262 struct cmd_tx_vlan_set_result {
3263         cmdline_fixed_string_t tx_vlan;
3264         cmdline_fixed_string_t set;
3265         uint8_t port_id;
3266         uint16_t vlan_id;
3267 };
3268
3269 static void
3270 cmd_tx_vlan_set_parsed(void *parsed_result,
3271                        __attribute__((unused)) struct cmdline *cl,
3272                        __attribute__((unused)) void *data)
3273 {
3274         struct cmd_tx_vlan_set_result *res = parsed_result;
3275
3276         tx_vlan_set(res->port_id, res->vlan_id);
3277 }
3278
3279 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3280         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3281                                  tx_vlan, "tx_vlan");
3282 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3283         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3284                                  set, "set");
3285 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3286         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3287                               port_id, UINT8);
3288 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3290                               vlan_id, UINT16);
3291
3292 cmdline_parse_inst_t cmd_tx_vlan_set = {
3293         .f = cmd_tx_vlan_set_parsed,
3294         .data = NULL,
3295         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3296                 "Enable hardware insertion of a single VLAN header "
3297                 "with a given TAG Identifier in packets sent on a port",
3298         .tokens = {
3299                 (void *)&cmd_tx_vlan_set_tx_vlan,
3300                 (void *)&cmd_tx_vlan_set_set,
3301                 (void *)&cmd_tx_vlan_set_portid,
3302                 (void *)&cmd_tx_vlan_set_vlanid,
3303                 NULL,
3304         },
3305 };
3306
3307 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3308 struct cmd_tx_vlan_set_qinq_result {
3309         cmdline_fixed_string_t tx_vlan;
3310         cmdline_fixed_string_t set;
3311         uint8_t port_id;
3312         uint16_t vlan_id;
3313         uint16_t vlan_id_outer;
3314 };
3315
3316 static void
3317 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3318                             __attribute__((unused)) struct cmdline *cl,
3319                             __attribute__((unused)) void *data)
3320 {
3321         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3322
3323         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3324 }
3325
3326 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3327         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3328                 tx_vlan, "tx_vlan");
3329 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3330         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3331                 set, "set");
3332 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3333         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3334                 port_id, UINT8);
3335 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3336         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3337                 vlan_id, UINT16);
3338 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3339         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3340                 vlan_id_outer, UINT16);
3341
3342 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3343         .f = cmd_tx_vlan_set_qinq_parsed,
3344         .data = NULL,
3345         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3346                 "Enable hardware insertion of double VLAN header "
3347                 "with given TAG Identifiers in packets sent on a port",
3348         .tokens = {
3349                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3350                 (void *)&cmd_tx_vlan_set_qinq_set,
3351                 (void *)&cmd_tx_vlan_set_qinq_portid,
3352                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3353                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3354                 NULL,
3355         },
3356 };
3357
3358 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3359 struct cmd_tx_vlan_set_pvid_result {
3360         cmdline_fixed_string_t tx_vlan;
3361         cmdline_fixed_string_t set;
3362         cmdline_fixed_string_t pvid;
3363         uint8_t port_id;
3364         uint16_t vlan_id;
3365         cmdline_fixed_string_t mode;
3366 };
3367
3368 static void
3369 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3370                             __attribute__((unused)) struct cmdline *cl,
3371                             __attribute__((unused)) void *data)
3372 {
3373         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3374
3375         if (strcmp(res->mode, "on") == 0)
3376                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3377         else
3378                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3379 }
3380
3381 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3382         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3383                                  tx_vlan, "tx_vlan");
3384 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3385         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3386                                  set, "set");
3387 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3388         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3389                                  pvid, "pvid");
3390 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3391         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3392                              port_id, UINT8);
3393 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3394         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3395                               vlan_id, UINT16);
3396 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3397         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3398                                  mode, "on#off");
3399
3400 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3401         .f = cmd_tx_vlan_set_pvid_parsed,
3402         .data = NULL,
3403         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3404         .tokens = {
3405                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3406                 (void *)&cmd_tx_vlan_set_pvid_set,
3407                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3408                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3409                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3410                 (void *)&cmd_tx_vlan_set_pvid_mode,
3411                 NULL,
3412         },
3413 };
3414
3415 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3416 struct cmd_tx_vlan_reset_result {
3417         cmdline_fixed_string_t tx_vlan;
3418         cmdline_fixed_string_t reset;
3419         uint8_t port_id;
3420 };
3421
3422 static void
3423 cmd_tx_vlan_reset_parsed(void *parsed_result,
3424                          __attribute__((unused)) struct cmdline *cl,
3425                          __attribute__((unused)) void *data)
3426 {
3427         struct cmd_tx_vlan_reset_result *res = parsed_result;
3428
3429         tx_vlan_reset(res->port_id);
3430 }
3431
3432 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3433         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3434                                  tx_vlan, "tx_vlan");
3435 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3436         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3437                                  reset, "reset");
3438 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3439         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3440                               port_id, UINT8);
3441
3442 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3443         .f = cmd_tx_vlan_reset_parsed,
3444         .data = NULL,
3445         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3446                 "VLAN header in packets sent on a port",
3447         .tokens = {
3448                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3449                 (void *)&cmd_tx_vlan_reset_reset,
3450                 (void *)&cmd_tx_vlan_reset_portid,
3451                 NULL,
3452         },
3453 };
3454
3455
3456 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3457 struct cmd_csum_result {
3458         cmdline_fixed_string_t csum;
3459         cmdline_fixed_string_t mode;
3460         cmdline_fixed_string_t proto;
3461         cmdline_fixed_string_t hwsw;
3462         uint8_t port_id;
3463 };
3464
3465 static void
3466 csum_show(int port_id)
3467 {
3468         struct rte_eth_dev_info dev_info;
3469         uint16_t ol_flags;
3470
3471         ol_flags = ports[port_id].tx_ol_flags;
3472         printf("Parse tunnel is %s\n",
3473                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3474         printf("IP checksum offload is %s\n",
3475                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3476         printf("UDP checksum offload is %s\n",
3477                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3478         printf("TCP checksum offload is %s\n",
3479                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3480         printf("SCTP checksum offload is %s\n",
3481                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3482         printf("Outer-Ip checksum offload is %s\n",
3483                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3484
3485         /* display warnings if configuration is not supported by the NIC */
3486         rte_eth_dev_info_get(port_id, &dev_info);
3487         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3488                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3489                 printf("Warning: hardware IP checksum enabled but not "
3490                         "supported by port %d\n", port_id);
3491         }
3492         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3493                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3494                 printf("Warning: hardware UDP checksum enabled but not "
3495                         "supported by port %d\n", port_id);
3496         }
3497         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3498                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3499                 printf("Warning: hardware TCP checksum enabled but not "
3500                         "supported by port %d\n", port_id);
3501         }
3502         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3503                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3504                 printf("Warning: hardware SCTP checksum enabled but not "
3505                         "supported by port %d\n", port_id);
3506         }
3507         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3508                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3509                 printf("Warning: hardware outer IP checksum enabled but not "
3510                         "supported by port %d\n", port_id);
3511         }
3512 }
3513
3514 static void
3515 cmd_csum_parsed(void *parsed_result,
3516                        __attribute__((unused)) struct cmdline *cl,
3517                        __attribute__((unused)) void *data)
3518 {
3519         struct cmd_csum_result *res = parsed_result;
3520         int hw = 0;
3521         uint16_t mask = 0;
3522
3523         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3524                 printf("invalid port %d\n", res->port_id);
3525                 return;
3526         }
3527
3528         if (!strcmp(res->mode, "set")) {
3529
3530                 if (!strcmp(res->hwsw, "hw"))
3531                         hw = 1;
3532
3533                 if (!strcmp(res->proto, "ip")) {
3534                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3535                 } else if (!strcmp(res->proto, "udp")) {
3536                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3537                 } else if (!strcmp(res->proto, "tcp")) {
3538                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3539                 } else if (!strcmp(res->proto, "sctp")) {
3540                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3541                 } else if (!strcmp(res->proto, "outer-ip")) {
3542                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3543                 }
3544
3545                 if (hw)
3546                         ports[res->port_id].tx_ol_flags |= mask;
3547                 else
3548                         ports[res->port_id].tx_ol_flags &= (~mask);
3549         }
3550         csum_show(res->port_id);
3551 }
3552
3553 cmdline_parse_token_string_t cmd_csum_csum =
3554         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3555                                 csum, "csum");
3556 cmdline_parse_token_string_t cmd_csum_mode =
3557         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3558                                 mode, "set");
3559 cmdline_parse_token_string_t cmd_csum_proto =
3560         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3561                                 proto, "ip#tcp#udp#sctp#outer-ip");
3562 cmdline_parse_token_string_t cmd_csum_hwsw =
3563         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3564                                 hwsw, "hw#sw");
3565 cmdline_parse_token_num_t cmd_csum_portid =
3566         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3567                                 port_id, UINT8);
3568
3569 cmdline_parse_inst_t cmd_csum_set = {
3570         .f = cmd_csum_parsed,
3571         .data = NULL,
3572         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3573                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3574                 "using csum forward engine",
3575         .tokens = {
3576                 (void *)&cmd_csum_csum,
3577                 (void *)&cmd_csum_mode,
3578                 (void *)&cmd_csum_proto,
3579                 (void *)&cmd_csum_hwsw,
3580                 (void *)&cmd_csum_portid,
3581                 NULL,
3582         },
3583 };
3584
3585 cmdline_parse_token_string_t cmd_csum_mode_show =
3586         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3587                                 mode, "show");
3588
3589 cmdline_parse_inst_t cmd_csum_show = {
3590         .f = cmd_csum_parsed,
3591         .data = NULL,
3592         .help_str = "csum show <port_id>: Show checksum offload configuration",
3593         .tokens = {
3594                 (void *)&cmd_csum_csum,
3595                 (void *)&cmd_csum_mode_show,
3596                 (void *)&cmd_csum_portid,
3597                 NULL,
3598         },
3599 };
3600
3601 /* Enable/disable tunnel parsing */
3602 struct cmd_csum_tunnel_result {
3603         cmdline_fixed_string_t csum;
3604         cmdline_fixed_string_t parse;
3605         cmdline_fixed_string_t onoff;
3606         uint8_t port_id;
3607 };
3608
3609 static void
3610 cmd_csum_tunnel_parsed(void *parsed_result,
3611                        __attribute__((unused)) struct cmdline *cl,
3612                        __attribute__((unused)) void *data)
3613 {
3614         struct cmd_csum_tunnel_result *res = parsed_result;
3615
3616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3617                 return;
3618
3619         if (!strcmp(res->onoff, "on"))
3620                 ports[res->port_id].tx_ol_flags |=
3621                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3622         else
3623                 ports[res->port_id].tx_ol_flags &=
3624                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3625
3626         csum_show(res->port_id);
3627 }
3628
3629 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3630         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3631                                 csum, "csum");
3632 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3633         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3634                                 parse, "parse_tunnel");
3635 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3636         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3637                                 onoff, "on#off");
3638 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3639         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3640                                 port_id, UINT8);
3641
3642 cmdline_parse_inst_t cmd_csum_tunnel = {
3643         .f = cmd_csum_tunnel_parsed,
3644         .data = NULL,
3645         .help_str = "csum parse_tunnel on|off <port_id>: "
3646                 "Enable/Disable parsing of tunnels for csum engine",
3647         .tokens = {
3648                 (void *)&cmd_csum_tunnel_csum,
3649                 (void *)&cmd_csum_tunnel_parse,
3650                 (void *)&cmd_csum_tunnel_onoff,
3651                 (void *)&cmd_csum_tunnel_portid,
3652                 NULL,
3653         },
3654 };
3655
3656 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3657 struct cmd_tso_set_result {
3658         cmdline_fixed_string_t tso;
3659         cmdline_fixed_string_t mode;
3660         uint16_t tso_segsz;
3661         uint8_t port_id;
3662 };
3663
3664 static void
3665 cmd_tso_set_parsed(void *parsed_result,
3666                        __attribute__((unused)) struct cmdline *cl,
3667                        __attribute__((unused)) void *data)
3668 {
3669         struct cmd_tso_set_result *res = parsed_result;
3670         struct rte_eth_dev_info dev_info;
3671
3672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3673                 return;
3674
3675         if (!strcmp(res->mode, "set"))
3676                 ports[res->port_id].tso_segsz = res->tso_segsz;
3677
3678         if (ports[res->port_id].tso_segsz == 0)
3679                 printf("TSO for non-tunneled packets is disabled\n");
3680         else
3681                 printf("TSO segment size for non-tunneled packets is %d\n",
3682                         ports[res->port_id].tso_segsz);
3683
3684         /* display warnings if configuration is not supported by the NIC */
3685         rte_eth_dev_info_get(res->port_id, &dev_info);
3686         if ((ports[res->port_id].tso_segsz != 0) &&
3687                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3688                 printf("Warning: TSO enabled but not "
3689                         "supported by port %d\n", res->port_id);
3690         }
3691 }
3692
3693 cmdline_parse_token_string_t cmd_tso_set_tso =
3694         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3695                                 tso, "tso");
3696 cmdline_parse_token_string_t cmd_tso_set_mode =
3697         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3698                                 mode, "set");
3699 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3700         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3701                                 tso_segsz, UINT16);
3702 cmdline_parse_token_num_t cmd_tso_set_portid =
3703         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3704                                 port_id, UINT8);
3705
3706 cmdline_parse_inst_t cmd_tso_set = {
3707         .f = cmd_tso_set_parsed,
3708         .data = NULL,
3709         .help_str = "tso set <tso_segsz> <port_id>: "
3710                 "Set TSO segment size of non-tunneled packets for csum engine "
3711                 "(0 to disable)",
3712         .tokens = {
3713                 (void *)&cmd_tso_set_tso,
3714                 (void *)&cmd_tso_set_mode,
3715                 (void *)&cmd_tso_set_tso_segsz,
3716                 (void *)&cmd_tso_set_portid,
3717                 NULL,
3718         },
3719 };
3720
3721 cmdline_parse_token_string_t cmd_tso_show_mode =
3722         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3723                                 mode, "show");
3724
3725
3726 cmdline_parse_inst_t cmd_tso_show = {
3727         .f = cmd_tso_set_parsed,
3728         .data = NULL,
3729         .help_str = "tso show <port_id>: "
3730                 "Show TSO segment size of non-tunneled packets for csum engine",
3731         .tokens = {
3732                 (void *)&cmd_tso_set_tso,
3733                 (void *)&cmd_tso_show_mode,
3734                 (void *)&cmd_tso_set_portid,
3735                 NULL,
3736         },
3737 };
3738
3739 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3740 struct cmd_tunnel_tso_set_result {
3741         cmdline_fixed_string_t tso;
3742         cmdline_fixed_string_t mode;
3743         uint16_t tso_segsz;
3744         uint8_t port_id;
3745 };
3746
3747 static void
3748 check_tunnel_tso_nic_support(uint8_t port_id)
3749 {
3750         struct rte_eth_dev_info dev_info;
3751
3752         rte_eth_dev_info_get(port_id, &dev_info);
3753         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3754                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3755                        "supported by port %d\n", port_id);
3756         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3757                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3758                         "supported by port %d\n", port_id);
3759         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3760                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3761                        "supported by port %d\n", port_id);
3762         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3763                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3764                        "supported by port %d\n", port_id);
3765 }
3766
3767 static void
3768 cmd_tunnel_tso_set_parsed(void *parsed_result,
3769                           __attribute__((unused)) struct cmdline *cl,
3770                           __attribute__((unused)) void *data)
3771 {
3772         struct cmd_tunnel_tso_set_result *res = parsed_result;
3773
3774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3775                 return;
3776
3777         if (!strcmp(res->mode, "set"))
3778                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3779
3780         if (ports[res->port_id].tunnel_tso_segsz == 0)
3781                 printf("TSO for tunneled packets is disabled\n");
3782         else {
3783                 printf("TSO segment size for tunneled packets is %d\n",
3784                         ports[res->port_id].tunnel_tso_segsz);
3785
3786                 /* Below conditions are needed to make it work:
3787                  * (1) tunnel TSO is supported by the NIC;
3788                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3789                  * are recognized;
3790                  * (3) for tunneled pkts with outer L3 of IPv4,
3791                  * "csum set outer-ip" must be set to hw, because after tso,
3792                  * total_len of outer IP header is changed, and the checksum
3793                  * of outer IP header calculated by sw should be wrong; that
3794                  * is not necessary for IPv6 tunneled pkts because there's no
3795                  * checksum in IP header anymore.
3796                  */
3797                 check_tunnel_tso_nic_support(res->port_id);
3798
3799                 if (!(ports[res->port_id].tx_ol_flags &
3800                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3801                         printf("Warning: csum parse_tunnel must be set "
3802                                 "so that tunneled packets are recognized\n");
3803                 if (!(ports[res->port_id].tx_ol_flags &
3804                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3805                         printf("Warning: csum set outer-ip must be set to hw "
3806                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3807         }
3808 }
3809
3810 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3811         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3812                                 tso, "tunnel_tso");
3813 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3814         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3815                                 mode, "set");
3816 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3817         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3818                                 tso_segsz, UINT16);
3819 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3820         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3821                                 port_id, UINT8);
3822
3823 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3824         .f = cmd_tunnel_tso_set_parsed,
3825         .data = NULL,
3826         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3827                 "Set TSO segment size of tunneled packets for csum engine "
3828                 "(0 to disable)",
3829         .tokens = {
3830                 (void *)&cmd_tunnel_tso_set_tso,
3831                 (void *)&cmd_tunnel_tso_set_mode,
3832                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3833                 (void *)&cmd_tunnel_tso_set_portid,
3834                 NULL,
3835         },
3836 };
3837
3838 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3839         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3840                                 mode, "show");
3841
3842
3843 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3844         .f = cmd_tunnel_tso_set_parsed,
3845         .data = NULL,
3846         .help_str = "tunnel_tso show <port_id> "
3847                 "Show TSO segment size of tunneled packets for csum engine",
3848         .tokens = {
3849                 (void *)&cmd_tunnel_tso_set_tso,
3850                 (void *)&cmd_tunnel_tso_show_mode,
3851                 (void *)&cmd_tunnel_tso_set_portid,
3852                 NULL,
3853         },
3854 };
3855
3856 /* *** SET GRO FOR A PORT *** */
3857 struct cmd_gro_result {
3858         cmdline_fixed_string_t cmd_keyword;
3859         cmdline_fixed_string_t mode;
3860         uint8_t port_id;
3861 };
3862
3863 static void
3864 cmd_enable_gro_parsed(void *parsed_result,
3865                 __attribute__((unused)) struct cmdline *cl,
3866                 __attribute__((unused)) void *data)
3867 {
3868         struct cmd_gro_result *res;
3869
3870         res = parsed_result;
3871         setup_gro(res->mode, res->port_id);
3872 }
3873
3874 cmdline_parse_token_string_t cmd_gro_keyword =
3875         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3876                         cmd_keyword, "gro");
3877 cmdline_parse_token_string_t cmd_gro_mode =
3878         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3879                         mode, "on#off");
3880 cmdline_parse_token_num_t cmd_gro_pid =
3881         TOKEN_NUM_INITIALIZER(struct cmd_gro_result,
3882                         port_id, UINT8);
3883
3884 cmdline_parse_inst_t cmd_enable_gro = {
3885         .f = cmd_enable_gro_parsed,
3886         .data = NULL,
3887         .help_str = "gro (on|off) (port_id)",
3888         .tokens = {
3889                 (void *)&cmd_gro_keyword,
3890                 (void *)&cmd_gro_mode,
3891                 (void *)&cmd_gro_pid,
3892                 NULL,
3893         },
3894 };
3895
3896 /* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */
3897 struct cmd_gro_set_result {
3898         cmdline_fixed_string_t gro;
3899         cmdline_fixed_string_t mode;
3900         uint16_t flow_num;
3901         uint16_t item_num_per_flow;
3902         uint8_t port_id;
3903 };
3904
3905 static void
3906 cmd_gro_set_parsed(void *parsed_result,
3907                        __attribute__((unused)) struct cmdline *cl,
3908                        __attribute__((unused)) void *data)
3909 {
3910         struct cmd_gro_set_result *res = parsed_result;
3911
3912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3913                 return;
3914         if (test_done == 0) {
3915                 printf("Before set GRO flow_num and item_num_per_flow,"
3916                                 " please stop forwarding first\n");
3917                 return;
3918         }
3919
3920         if (!strcmp(res->mode, "set")) {
3921                 if (res->flow_num == 0)
3922                         printf("Invalid flow number. Revert to default value:"
3923                                         " %u.\n", GRO_DEFAULT_FLOW_NUM);
3924                 else
3925                         gro_ports[res->port_id].param.max_flow_num =
3926                                 res->flow_num;
3927
3928                 if (res->item_num_per_flow == 0)
3929                         printf("Invalid item number per-flow. Revert"
3930                                         " to default value:%u.\n",
3931                                         GRO_DEFAULT_ITEM_NUM_PER_FLOW);
3932                 else
3933                         gro_ports[res->port_id].param.max_item_per_flow =
3934                                 res->item_num_per_flow;
3935         }
3936 }
3937
3938 cmdline_parse_token_string_t cmd_gro_set_gro =
3939         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3940                                 gro, "gro");
3941 cmdline_parse_token_string_t cmd_gro_set_mode =
3942         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3943                                 mode, "set");
3944 cmdline_parse_token_num_t cmd_gro_set_flow_num =
3945         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3946                                 flow_num, UINT16);
3947 cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow =
3948         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3949                                 item_num_per_flow, UINT16);
3950 cmdline_parse_token_num_t cmd_gro_set_portid =
3951         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3952                                 port_id, UINT8);
3953
3954 cmdline_parse_inst_t cmd_gro_set = {
3955         .f = cmd_gro_set_parsed,
3956         .data = NULL,
3957         .help_str = "gro set <max_flow_num> <max_item_num_per_flow> "
3958                 "<port_id>: set max flow number and max packet number per-flow "
3959                 "for GRO",
3960         .tokens = {
3961                 (void *)&cmd_gro_set_gro,
3962                 (void *)&cmd_gro_set_mode,
3963                 (void *)&cmd_gro_set_flow_num,
3964                 (void *)&cmd_gro_set_item_num_per_flow,
3965                 (void *)&cmd_gro_set_portid,
3966                 NULL,
3967         },
3968 };
3969
3970 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3971 struct cmd_set_flush_rx {
3972         cmdline_fixed_string_t set;
3973         cmdline_fixed_string_t flush_rx;
3974         cmdline_fixed_string_t mode;
3975 };
3976
3977 static void
3978 cmd_set_flush_rx_parsed(void *parsed_result,
3979                 __attribute__((unused)) struct cmdline *cl,
3980                 __attribute__((unused)) void *data)
3981 {
3982         struct cmd_set_flush_rx *res = parsed_result;
3983         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3984 }
3985
3986 cmdline_parse_token_string_t cmd_setflushrx_set =
3987         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3988                         set, "set");
3989 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3990         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3991                         flush_rx, "flush_rx");
3992 cmdline_parse_token_string_t cmd_setflushrx_mode =
3993         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3994                         mode, "on#off");
3995
3996
3997 cmdline_parse_inst_t cmd_set_flush_rx = {
3998         .f = cmd_set_flush_rx_parsed,
3999         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4000         .data = NULL,
4001         .tokens = {
4002                 (void *)&cmd_setflushrx_set,
4003                 (void *)&cmd_setflushrx_flush_rx,
4004                 (void *)&cmd_setflushrx_mode,
4005                 NULL,
4006         },
4007 };
4008
4009 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4010 struct cmd_set_link_check {
4011         cmdline_fixed_string_t set;
4012         cmdline_fixed_string_t link_check;
4013         cmdline_fixed_string_t mode;
4014 };
4015
4016 static void
4017 cmd_set_link_check_parsed(void *parsed_result,
4018                 __attribute__((unused)) struct cmdline *cl,
4019                 __attribute__((unused)) void *data)
4020 {
4021         struct cmd_set_link_check *res = parsed_result;
4022         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4023 }
4024
4025 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4026         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4027                         set, "set");
4028 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4029         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4030                         link_check, "link_check");
4031 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4032         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4033                         mode, "on#off");
4034
4035
4036 cmdline_parse_inst_t cmd_set_link_check = {
4037         .f = cmd_set_link_check_parsed,
4038         .help_str = "set link_check on|off: Enable/Disable link status check "
4039                     "when starting/stopping a port",
4040         .data = NULL,
4041         .tokens = {
4042                 (void *)&cmd_setlinkcheck_set,
4043                 (void *)&cmd_setlinkcheck_link_check,
4044                 (void *)&cmd_setlinkcheck_mode,
4045                 NULL,
4046         },
4047 };
4048
4049 /* *** SET NIC BYPASS MODE *** */
4050 struct cmd_set_bypass_mode_result {
4051         cmdline_fixed_string_t set;
4052         cmdline_fixed_string_t bypass;
4053         cmdline_fixed_string_t mode;
4054         cmdline_fixed_string_t value;
4055         uint8_t port_id;
4056 };
4057
4058 static void
4059 cmd_set_bypass_mode_parsed(void *parsed_result,
4060                 __attribute__((unused)) struct cmdline *cl,
4061                 __attribute__((unused)) void *data)
4062 {
4063         struct cmd_set_bypass_mode_result *res = parsed_result;
4064         portid_t port_id = res->port_id;
4065         int32_t rc = -EINVAL;
4066
4067 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4068         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4069
4070         if (!strcmp(res->value, "bypass"))
4071                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4072         else if (!strcmp(res->value, "isolate"))
4073                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4074         else
4075                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4076
4077         /* Set the bypass mode for the relevant port. */
4078         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4079 #endif
4080         if (rc != 0)
4081                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4082 }
4083
4084 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4086                         set, "set");
4087 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4089                         bypass, "bypass");
4090 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4091         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4092                         mode, "mode");
4093 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4094         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4095                         value, "normal#bypass#isolate");
4096 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4097         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4098                                 port_id, UINT8);
4099
4100 cmdline_parse_inst_t cmd_set_bypass_mode = {
4101         .f = cmd_set_bypass_mode_parsed,
4102         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4103                     "Set the NIC bypass mode for port_id",
4104         .data = NULL,
4105         .tokens = {
4106                 (void *)&cmd_setbypass_mode_set,
4107                 (void *)&cmd_setbypass_mode_bypass,
4108                 (void *)&cmd_setbypass_mode_mode,
4109                 (void *)&cmd_setbypass_mode_value,
4110                 (void *)&cmd_setbypass_mode_port,
4111                 NULL,
4112         },
4113 };
4114
4115 /* *** SET NIC BYPASS EVENT *** */
4116 struct cmd_set_bypass_event_result {
4117         cmdline_fixed_string_t set;
4118         cmdline_fixed_string_t bypass;
4119         cmdline_fixed_string_t event;
4120         cmdline_fixed_string_t event_value;
4121         cmdline_fixed_string_t mode;
4122         cmdline_fixed_string_t mode_value;
4123         uint8_t port_id;
4124 };
4125
4126 static void
4127 cmd_set_bypass_event_parsed(void *parsed_result,
4128                 __attribute__((unused)) struct cmdline *cl,
4129                 __attribute__((unused)) void *data)
4130 {
4131         int32_t rc = -EINVAL;
4132         struct cmd_set_bypass_event_result *res = parsed_result;
4133         portid_t port_id = res->port_id;
4134
4135 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4136         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4137         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4138
4139         if (!strcmp(res->event_value, "timeout"))
4140                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4141         else if (!strcmp(res->event_value, "os_on"))
4142                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4143         else if (!strcmp(res->event_value, "os_off"))
4144                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4145         else if (!strcmp(res->event_value, "power_on"))
4146                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4147         else if (!strcmp(res->event_value, "power_off"))
4148                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4149         else
4150                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4151
4152         if (!strcmp(res->mode_value, "bypass"))
4153                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4154         else if (!strcmp(res->mode_value, "isolate"))
4155                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4156         else
4157                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4158
4159         /* Set the watchdog timeout. */
4160         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4161
4162                 rc = -EINVAL;
4163                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4164                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4165                                                            bypass_timeout);
4166                 }
4167                 if (rc != 0) {
4168                         printf("Failed to set timeout value %u "
4169                         "for port %d, errto code: %d.\n",
4170                         bypass_timeout, port_id, rc);
4171                 }
4172         }
4173
4174         /* Set the bypass event to transition to bypass mode. */
4175         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4176                                               bypass_mode);
4177 #endif
4178
4179         if (rc != 0)
4180                 printf("\t Failed to set bypass event for port = %d.\n",
4181                        port_id);
4182 }
4183
4184 cmdline_parse_token_string_t cmd_setbypass_event_set =
4185         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4186                         set, "set");
4187 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4188         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4189                         bypass, "bypass");
4190 cmdline_parse_token_string_t cmd_setbypass_event_event =
4191         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4192                         event, "event");
4193 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4194         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4195                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4196 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4197         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4198                         mode, "mode");
4199 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4200         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4201                         mode_value, "normal#bypass#isolate");
4202 cmdline_parse_token_num_t cmd_setbypass_event_port =
4203         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4204                                 port_id, UINT8);
4205
4206 cmdline_parse_inst_t cmd_set_bypass_event = {
4207         .f = cmd_set_bypass_event_parsed,
4208         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4209                 "power_off mode normal|bypass|isolate <port_id>: "
4210                 "Set the NIC bypass event mode for port_id",
4211         .data = NULL,
4212         .tokens = {
4213                 (void *)&cmd_setbypass_event_set,
4214                 (void *)&cmd_setbypass_event_bypass,
4215                 (void *)&cmd_setbypass_event_event,
4216                 (void *)&cmd_setbypass_event_event_value,
4217                 (void *)&cmd_setbypass_event_mode,
4218                 (void *)&cmd_setbypass_event_mode_value,
4219                 (void *)&cmd_setbypass_event_port,
4220                 NULL,
4221         },
4222 };
4223
4224
4225 /* *** SET NIC BYPASS TIMEOUT *** */
4226 struct cmd_set_bypass_timeout_result {
4227         cmdline_fixed_string_t set;
4228         cmdline_fixed_string_t bypass;
4229         cmdline_fixed_string_t timeout;
4230         cmdline_fixed_string_t value;
4231 };
4232
4233 static void
4234 cmd_set_bypass_timeout_parsed(void *parsed_result,
4235                 __attribute__((unused)) struct cmdline *cl,
4236                 __attribute__((unused)) void *data)
4237 {
4238         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4239
4240 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4241         if (!strcmp(res->value, "1.5"))
4242                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4243         else if (!strcmp(res->value, "2"))
4244                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4245         else if (!strcmp(res->value, "3"))
4246                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4247         else if (!strcmp(res->value, "4"))
4248                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4249         else if (!strcmp(res->value, "8"))
4250                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4251         else if (!strcmp(res->value, "16"))
4252                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4253         else if (!strcmp(res->value, "32"))
4254                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4255         else
4256                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4257 #endif
4258 }
4259
4260 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4261         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4262                         set, "set");
4263 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4265                         bypass, "bypass");
4266 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4267         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4268                         timeout, "timeout");
4269 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4270         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4271                         value, "0#1.5#2#3#4#8#16#32");
4272
4273 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4274         .f = cmd_set_bypass_timeout_parsed,
4275         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4276                 "Set the NIC bypass watchdog timeout in seconds",
4277         .data = NULL,
4278         .tokens = {
4279                 (void *)&cmd_setbypass_timeout_set,
4280                 (void *)&cmd_setbypass_timeout_bypass,
4281                 (void *)&cmd_setbypass_timeout_timeout,
4282                 (void *)&cmd_setbypass_timeout_value,
4283                 NULL,
4284         },
4285 };
4286
4287 /* *** SHOW NIC BYPASS MODE *** */
4288 struct cmd_show_bypass_config_result {
4289         cmdline_fixed_string_t show;
4290         cmdline_fixed_string_t bypass;
4291         cmdline_fixed_string_t config;
4292         uint8_t port_id;
4293 };
4294
4295 static void
4296 cmd_show_bypass_config_parsed(void *parsed_result,
4297                 __attribute__((unused)) struct cmdline *cl,
4298                 __attribute__((unused)) void *data)
4299 {
4300         struct cmd_show_bypass_config_result *res = parsed_result;
4301         portid_t port_id = res->port_id;
4302         int rc = -EINVAL;
4303 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4304         uint32_t event_mode;
4305         uint32_t bypass_mode;
4306         uint32_t timeout = bypass_timeout;
4307         int i;
4308
4309         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4310                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4311         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4312                 {"UNKNOWN", "normal", "bypass", "isolate"};
4313         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4314                 "NONE",
4315                 "OS/board on",
4316                 "power supply on",
4317                 "OS/board off",
4318                 "power supply off",
4319                 "timeout"};
4320         int num_events = (sizeof events) / (sizeof events[0]);
4321
4322         /* Display the bypass mode.*/
4323         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4324                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4325                 return;
4326         }
4327         else {
4328                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4329                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4330
4331                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4332         }
4333
4334         /* Display the bypass timeout.*/
4335         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4336                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4337
4338         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4339
4340         /* Display the bypass events and associated modes. */
4341         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4342
4343                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4344                         printf("\tFailed to get bypass mode for event = %s\n",
4345                                 events[i]);
4346                 } else {
4347                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4348                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4349
4350                         printf("\tbypass event: %-16s = %s\n", events[i],
4351                                 modes[event_mode]);
4352                 }
4353         }
4354 #endif
4355         if (rc != 0)
4356                 printf("\tFailed to get bypass configuration for port = %d\n",
4357                        port_id);
4358 }
4359
4360 cmdline_parse_token_string_t cmd_showbypass_config_show =
4361         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4362                         show, "show");
4363 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4364         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4365                         bypass, "bypass");
4366 cmdline_parse_token_string_t cmd_showbypass_config_config =
4367         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4368                         config, "config");
4369 cmdline_parse_token_num_t cmd_showbypass_config_port =
4370         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4371                                 port_id, UINT8);
4372
4373 cmdline_parse_inst_t cmd_show_bypass_config = {
4374         .f = cmd_show_bypass_config_parsed,
4375         .help_str = "show bypass config <port_id>: "
4376                     "Show the NIC bypass config for port_id",
4377         .data = NULL,
4378         .tokens = {
4379                 (void *)&cmd_showbypass_config_show,
4380                 (void *)&cmd_showbypass_config_bypass,
4381                 (void *)&cmd_showbypass_config_config,
4382                 (void *)&cmd_showbypass_config_port,
4383                 NULL,
4384         },
4385 };
4386
4387 #ifdef RTE_LIBRTE_PMD_BOND
4388 /* *** SET BONDING MODE *** */
4389 struct cmd_set_bonding_mode_result {
4390         cmdline_fixed_string_t set;
4391         cmdline_fixed_string_t bonding;
4392         cmdline_fixed_string_t mode;
4393         uint8_t value;
4394         uint8_t port_id;
4395 };
4396
4397 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4398                 __attribute__((unused))  struct cmdline *cl,
4399                 __attribute__((unused)) void *data)
4400 {
4401         struct cmd_set_bonding_mode_result *res = parsed_result;
4402         portid_t port_id = res->port_id;
4403
4404         /* Set the bonding mode for the relevant port. */
4405         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4406                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4407 }
4408
4409 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4410 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4411                 set, "set");
4412 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4413 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4414                 bonding, "bonding");
4415 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4416 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4417                 mode, "mode");
4418 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4419 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4420                 value, UINT8);
4421 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4422 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4423                 port_id, UINT8);
4424
4425 cmdline_parse_inst_t cmd_set_bonding_mode = {
4426                 .f = cmd_set_bonding_mode_parsed,
4427                 .help_str = "set bonding mode <mode_value> <port_id>: "
4428                         "Set the bonding mode for port_id",
4429                 .data = NULL,
4430                 .tokens = {
4431                                 (void *) &cmd_setbonding_mode_set,
4432                                 (void *) &cmd_setbonding_mode_bonding,
4433                                 (void *) &cmd_setbonding_mode_mode,
4434                                 (void *) &cmd_setbonding_mode_value,
4435                                 (void *) &cmd_setbonding_mode_port,
4436                                 NULL
4437                 }
4438 };
4439
4440 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4441 struct cmd_set_bonding_lacp_dedicated_queues_result {
4442         cmdline_fixed_string_t set;
4443         cmdline_fixed_string_t bonding;
4444         cmdline_fixed_string_t lacp;
4445         cmdline_fixed_string_t dedicated_queues;
4446         uint8_t port_id;
4447         cmdline_fixed_string_t mode;
4448 };
4449
4450 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4451                 __attribute__((unused))  struct cmdline *cl,
4452                 __attribute__((unused)) void *data)
4453 {
4454         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4455         portid_t port_id = res->port_id;
4456         struct rte_port *port;
4457
4458         port = &ports[port_id];
4459
4460         /** Check if the port is not started **/
4461         if (port->port_status != RTE_PORT_STOPPED) {
4462                 printf("Please stop port %d first\n", port_id);
4463                 return;
4464         }
4465
4466         if (!strcmp(res->mode, "enable")) {
4467                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4468                         printf("Dedicate queues for LACP control packets"
4469                                         " enabled\n");
4470                 else
4471                         printf("Enabling dedicate queues for LACP control "
4472                                         "packets on port %d failed\n", port_id);
4473         } else if (!strcmp(res->mode, "disable")) {
4474                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4475                         printf("Dedicated queues for LACP control packets "
4476                                         "disabled\n");
4477                 else
4478                         printf("Disabling dedicated queues for LACP control "
4479                                         "traffic on port %d failed\n", port_id);
4480         }
4481 }
4482
4483 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4484 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4485                 set, "set");
4486 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4487 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4488                 bonding, "bonding");
4489 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4490 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4491                 lacp, "lacp");
4492 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4493 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4494                 dedicated_queues, "dedicated_queues");
4495 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4496 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4497                 port_id, UINT8);
4498 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4499 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4500                 mode, "enable#disable");
4501
4502 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4503                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4504                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4505                         "enable|disable: "
4506                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4507                 .data = NULL,
4508                 .tokens = {
4509                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4510                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4511                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4512                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4513                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4514                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4515                         NULL
4516                 }
4517 };
4518
4519 /* *** SET BALANCE XMIT POLICY *** */
4520 struct cmd_set_bonding_balance_xmit_policy_result {
4521         cmdline_fixed_string_t set;
4522         cmdline_fixed_string_t bonding;
4523         cmdline_fixed_string_t balance_xmit_policy;
4524         uint8_t port_id;
4525         cmdline_fixed_string_t policy;
4526 };
4527
4528 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4529                 __attribute__((unused))  struct cmdline *cl,
4530                 __attribute__((unused)) void *data)
4531 {
4532         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4533         portid_t port_id = res->port_id;
4534         uint8_t policy;
4535
4536         if (!strcmp(res->policy, "l2")) {
4537                 policy = BALANCE_XMIT_POLICY_LAYER2;
4538         } else if (!strcmp(res->policy, "l23")) {
4539                 policy = BALANCE_XMIT_POLICY_LAYER23;
4540         } else if (!strcmp(res->policy, "l34")) {
4541                 policy = BALANCE_XMIT_POLICY_LAYER34;
4542         } else {
4543                 printf("\t Invalid xmit policy selection");
4544                 return;
4545         }
4546
4547         /* Set the bonding mode for the relevant port. */
4548         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4549                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4550                                 port_id);
4551         }
4552 }
4553
4554 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4555 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4556                 set, "set");
4557 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4558 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4559                 bonding, "bonding");
4560 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4561 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4562                 balance_xmit_policy, "balance_xmit_policy");
4563 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4564 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4565                 port_id, UINT8);
4566 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4567 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4568                 policy, "l2#l23#l34");
4569
4570 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4571                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4572                 .help_str = "set bonding balance_xmit_policy <port_id> "
4573                         "l2|l23|l34: "
4574                         "Set the bonding balance_xmit_policy for port_id",
4575                 .data = NULL,
4576                 .tokens = {
4577                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4578                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4579                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4580                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4581                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4582                                 NULL
4583                 }
4584 };
4585
4586 /* *** SHOW NIC BONDING CONFIGURATION *** */
4587 struct cmd_show_bonding_config_result {
4588         cmdline_fixed_string_t show;
4589         cmdline_fixed_string_t bonding;
4590         cmdline_fixed_string_t config;
4591         uint8_t port_id;
4592 };
4593
4594 static void cmd_show_bonding_config_parsed(void *parsed_result,
4595                 __attribute__((unused))  struct cmdline *cl,
4596                 __attribute__((unused)) void *data)
4597 {
4598         struct cmd_show_bonding_config_result *res = parsed_result;
4599         int bonding_mode, agg_mode;
4600         uint8_t slaves[RTE_MAX_ETHPORTS];
4601         int num_slaves, num_active_slaves;
4602         int primary_id;
4603         int i;
4604         portid_t port_id = res->port_id;
4605
4606         /* Display the bonding mode.*/
4607         bonding_mode = rte_eth_bond_mode_get(port_id);
4608         if (bonding_mode < 0) {
4609                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4610                 return;
4611         } else
4612                 printf("\tBonding mode: %d\n", bonding_mode);
4613
4614         if (bonding_mode == BONDING_MODE_BALANCE) {
4615                 int balance_xmit_policy;
4616
4617                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4618                 if (balance_xmit_policy < 0) {
4619                         printf("\tFailed to get balance xmit policy for port = %d\n",
4620                                         port_id);
4621                         return;
4622                 } else {
4623                         printf("\tBalance Xmit Policy: ");
4624
4625                         switch (balance_xmit_policy) {
4626                         case BALANCE_XMIT_POLICY_LAYER2:
4627                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4628                                 break;
4629                         case BALANCE_XMIT_POLICY_LAYER23:
4630                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4631                                 break;
4632                         case BALANCE_XMIT_POLICY_LAYER34:
4633                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4634                                 break;
4635                         }
4636                         printf("\n");
4637                 }
4638         }
4639
4640         if (bonding_mode == BONDING_MODE_8023AD) {
4641                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4642                 printf("\tIEEE802.3AD Aggregator Mode: ");
4643                 switch (agg_mode) {
4644                 case AGG_BANDWIDTH:
4645                         printf("bandwidth");
4646                         break;
4647                 case AGG_STABLE:
4648                         printf("stable");
4649                         break;
4650                 case AGG_COUNT:
4651                         printf("count");
4652                         break;
4653                 }
4654                 printf("\n");
4655         }
4656
4657         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4658
4659         if (num_slaves < 0) {
4660                 printf("\tFailed to get slave list for port = %d\n", port_id);
4661                 return;
4662         }
4663         if (num_slaves > 0) {
4664                 printf("\tSlaves (%d): [", num_slaves);
4665                 for (i = 0; i < num_slaves - 1; i++)
4666                         printf("%d ", slaves[i]);
4667
4668                 printf("%d]\n", slaves[num_slaves - 1]);
4669         } else {
4670                 printf("\tSlaves: []\n");
4671
4672         }
4673
4674         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4675                         RTE_MAX_ETHPORTS);
4676
4677         if (num_active_slaves < 0) {
4678                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4679                 return;
4680         }
4681         if (num_active_slaves > 0) {
4682                 printf("\tActive Slaves (%d): [", num_active_slaves);
4683                 for (i = 0; i < num_active_slaves - 1; i++)
4684                         printf("%d ", slaves[i]);
4685
4686                 printf("%d]\n", slaves[num_active_slaves - 1]);
4687
4688         } else {
4689                 printf("\tActive Slaves: []\n");
4690
4691         }
4692
4693         primary_id = rte_eth_bond_primary_get(port_id);
4694         if (primary_id < 0) {
4695                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4696                 return;
4697         } else
4698                 printf("\tPrimary: [%d]\n", primary_id);
4699
4700 }
4701
4702 cmdline_parse_token_string_t cmd_showbonding_config_show =
4703 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4704                 show, "show");
4705 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4706 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4707                 bonding, "bonding");
4708 cmdline_parse_token_string_t cmd_showbonding_config_config =
4709 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4710                 config, "config");
4711 cmdline_parse_token_num_t cmd_showbonding_config_port =
4712 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4713                 port_id, UINT8);
4714
4715 cmdline_parse_inst_t cmd_show_bonding_config = {
4716                 .f = cmd_show_bonding_config_parsed,
4717                 .help_str = "show bonding config <port_id>: "
4718                         "Show the bonding config for port_id",
4719                 .data = NULL,
4720                 .tokens = {
4721                                 (void *)&cmd_showbonding_config_show,
4722                                 (void *)&cmd_showbonding_config_bonding,
4723                                 (void *)&cmd_showbonding_config_config,
4724                                 (void *)&cmd_showbonding_config_port,
4725                                 NULL
4726                 }
4727 };
4728
4729 /* *** SET BONDING PRIMARY *** */
4730 struct cmd_set_bonding_primary_result {
4731         cmdline_fixed_string_t set;
4732         cmdline_fixed_string_t bonding;
4733         cmdline_fixed_string_t primary;
4734         uint8_t slave_id;
4735         uint8_t port_id;
4736 };
4737
4738 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4739                 __attribute__((unused))  struct cmdline *cl,
4740                 __attribute__((unused)) void *data)
4741 {
4742         struct cmd_set_bonding_primary_result *res = parsed_result;
4743         portid_t master_port_id = res->port_id;
4744         portid_t slave_port_id = res->slave_id;
4745
4746         /* Set the primary slave for a bonded device. */
4747         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4748                 printf("\t Failed to set primary slave for port = %d.\n",
4749                                 master_port_id);
4750                 return;
4751         }
4752         init_port_config();
4753 }
4754
4755 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4756 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4757                 set, "set");
4758 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4759 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4760                 bonding, "bonding");
4761 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4762 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4763                 primary, "primary");
4764 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4765 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4766                 slave_id, UINT8);
4767 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4768 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4769                 port_id, UINT8);
4770
4771 cmdline_parse_inst_t cmd_set_bonding_primary = {
4772                 .f = cmd_set_bonding_primary_parsed,
4773                 .help_str = "set bonding primary <slave_id> <port_id>: "
4774                         "Set the primary slave for port_id",
4775                 .data = NULL,
4776                 .tokens = {
4777                                 (void *)&cmd_setbonding_primary_set,
4778                                 (void *)&cmd_setbonding_primary_bonding,
4779                                 (void *)&cmd_setbonding_primary_primary,
4780                                 (void *)&cmd_setbonding_primary_slave,
4781                                 (void *)&cmd_setbonding_primary_port,
4782                                 NULL
4783                 }
4784 };
4785
4786 /* *** ADD SLAVE *** */
4787 struct cmd_add_bonding_slave_result {
4788         cmdline_fixed_string_t add;
4789         cmdline_fixed_string_t bonding;
4790         cmdline_fixed_string_t slave;
4791         uint8_t slave_id;
4792         uint8_t port_id;
4793 };
4794
4795 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4796                 __attribute__((unused))  struct cmdline *cl,
4797                 __attribute__((unused)) void *data)
4798 {
4799         struct cmd_add_bonding_slave_result *res = parsed_result;
4800         portid_t master_port_id = res->port_id;
4801         portid_t slave_port_id = res->slave_id;
4802
4803         /* add the slave for a bonded device. */
4804         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4805                 printf("\t Failed to add slave %d to master port = %d.\n",
4806                                 slave_port_id, master_port_id);
4807                 return;
4808         }
4809         init_port_config();
4810         set_port_slave_flag(slave_port_id);
4811 }
4812
4813 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4814 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4815                 add, "add");
4816 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4817 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4818                 bonding, "bonding");
4819 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4820 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4821                 slave, "slave");
4822 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4823 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4824                 slave_id, UINT8);
4825 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4826 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4827                 port_id, UINT8);
4828
4829 cmdline_parse_inst_t cmd_add_bonding_slave = {
4830                 .f = cmd_add_bonding_slave_parsed,
4831                 .help_str = "add bonding slave <slave_id> <port_id>: "
4832                         "Add a slave device to a bonded device",
4833                 .data = NULL,
4834                 .tokens = {
4835                                 (void *)&cmd_addbonding_slave_add,
4836                                 (void *)&cmd_addbonding_slave_bonding,
4837                                 (void *)&cmd_addbonding_slave_slave,
4838                                 (void *)&cmd_addbonding_slave_slaveid,
4839                                 (void *)&cmd_addbonding_slave_port,
4840                                 NULL
4841                 }
4842 };
4843
4844 /* *** REMOVE SLAVE *** */
4845 struct cmd_remove_bonding_slave_result {
4846         cmdline_fixed_string_t remove;
4847         cmdline_fixed_string_t bonding;
4848         cmdline_fixed_string_t slave;
4849         uint8_t slave_id;
4850         uint8_t port_id;
4851 };
4852
4853 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4854                 __attribute__((unused))  struct cmdline *cl,
4855                 __attribute__((unused)) void *data)
4856 {
4857         struct cmd_remove_bonding_slave_result *res = parsed_result;
4858         portid_t master_port_id = res->port_id;
4859         portid_t slave_port_id = res->slave_id;
4860
4861         /* remove the slave from a bonded device. */
4862         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4863                 printf("\t Failed to remove slave %d from master port = %d.\n",
4864                                 slave_port_id, master_port_id);
4865                 return;
4866         }
4867         init_port_config();
4868         clear_port_slave_flag(slave_port_id);
4869 }
4870
4871 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4872                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4873                                 remove, "remove");
4874 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4875                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4876                                 bonding, "bonding");
4877 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4878                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4879                                 slave, "slave");
4880 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4881                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4882                                 slave_id, UINT8);
4883 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4884                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4885                                 port_id, UINT8);
4886
4887 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4888                 .f = cmd_remove_bonding_slave_parsed,
4889                 .help_str = "remove bonding slave <slave_id> <port_id>: "
4890                         "Remove a slave device from a bonded device",
4891                 .data = NULL,
4892                 .tokens = {
4893                                 (void *)&cmd_removebonding_slave_remove,
4894                                 (void *)&cmd_removebonding_slave_bonding,
4895                                 (void *)&cmd_removebonding_slave_slave,
4896                                 (void *)&cmd_removebonding_slave_slaveid,
4897                                 (void *)&cmd_removebonding_slave_port,
4898                                 NULL
4899                 }
4900 };
4901
4902 /* *** CREATE BONDED DEVICE *** */
4903 struct cmd_create_bonded_device_result {
4904         cmdline_fixed_string_t create;
4905         cmdline_fixed_string_t bonded;
4906         cmdline_fixed_string_t device;
4907         uint8_t mode;
4908         uint8_t socket;
4909 };
4910
4911 static int bond_dev_num = 0;
4912
4913 static void cmd_create_bonded_device_parsed(void *parsed_result,
4914                 __attribute__((unused))  struct cmdline *cl,
4915                 __attribute__((unused)) void *data)
4916 {
4917         struct cmd_create_bonded_device_result *res = parsed_result;
4918         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4919         int port_id;
4920
4921         if (test_done == 0) {
4922                 printf("Please stop forwarding first\n");
4923                 return;
4924         }
4925
4926         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
4927                         bond_dev_num++);
4928
4929         /* Create a new bonded device. */
4930         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4931         if (port_id < 0) {
4932                 printf("\t Failed to create bonded device.\n");
4933                 return;
4934         } else {
4935                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4936                                 port_id);
4937
4938                 /* Update number of ports */
4939                 nb_ports = rte_eth_dev_count();
4940                 reconfig(port_id, res->socket);
4941                 rte_eth_promiscuous_enable(port_id);
4942         }
4943
4944 }
4945
4946 cmdline_parse_token_string_t cmd_createbonded_device_create =
4947                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4948                                 create, "create");
4949 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4950                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4951                                 bonded, "bonded");
4952 cmdline_parse_token_string_t cmd_createbonded_device_device =
4953                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4954                                 device, "device");
4955 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4956                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4957                                 mode, UINT8);
4958 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4959                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4960                                 socket, UINT8);
4961
4962 cmdline_parse_inst_t cmd_create_bonded_device = {
4963                 .f = cmd_create_bonded_device_parsed,
4964                 .help_str = "create bonded device <mode> <socket>: "
4965                         "Create a new bonded device with specific bonding mode and socket",
4966                 .data = NULL,
4967                 .tokens = {
4968                                 (void *)&cmd_createbonded_device_create,
4969                                 (void *)&cmd_createbonded_device_bonded,
4970                                 (void *)&cmd_createbonded_device_device,
4971                                 (void *)&cmd_createbonded_device_mode,
4972                                 (void *)&cmd_createbonded_device_socket,
4973                                 NULL
4974                 }
4975 };
4976
4977 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4978 struct cmd_set_bond_mac_addr_result {
4979         cmdline_fixed_string_t set;
4980         cmdline_fixed_string_t bonding;
4981         cmdline_fixed_string_t mac_addr;
4982         uint8_t port_num;
4983         struct ether_addr address;
4984 };
4985
4986 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4987                 __attribute__((unused))  struct cmdline *cl,
4988                 __attribute__((unused)) void *data)
4989 {
4990         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4991         int ret;
4992
4993         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4994                 return;
4995
4996         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4997
4998         /* check the return value and print it if is < 0 */
4999         if (ret < 0)
5000                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5001 }
5002
5003 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5004                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5005 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5006                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5007                                 "bonding");
5008 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5009                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5010                                 "mac_addr");
5011 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5012                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5013 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5014                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5015
5016 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5017                 .f = cmd_set_bond_mac_addr_parsed,
5018                 .data = (void *) 0,
5019                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5020                 .tokens = {
5021                                 (void *)&cmd_set_bond_mac_addr_set,
5022                                 (void *)&cmd_set_bond_mac_addr_bonding,
5023                                 (void *)&cmd_set_bond_mac_addr_mac,
5024                                 (void *)&cmd_set_bond_mac_addr_portnum,
5025                                 (void *)&cmd_set_bond_mac_addr_addr,
5026                                 NULL
5027                 }
5028 };
5029
5030
5031 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5032 struct cmd_set_bond_mon_period_result {
5033         cmdline_fixed_string_t set;
5034         cmdline_fixed_string_t bonding;
5035         cmdline_fixed_string_t mon_period;
5036         uint8_t port_num;
5037         uint32_t period_ms;
5038 };
5039
5040 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5041                 __attribute__((unused))  struct cmdline *cl,
5042                 __attribute__((unused)) void *data)
5043 {
5044         struct cmd_set_bond_mon_period_result *res = parsed_result;
5045         int ret;
5046
5047         if (res->port_num >= nb_ports) {
5048                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5049                 return;
5050         }
5051
5052         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5053
5054         /* check the return value and print it if is < 0 */
5055         if (ret < 0)
5056                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5057 }
5058
5059 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5060                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5061                                 set, "set");
5062 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5063                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5064                                 bonding, "bonding");
5065 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5066                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5067                                 mon_period,     "mon_period");
5068 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5069                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5070                                 port_num, UINT8);
5071 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5072                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5073                                 period_ms, UINT32);
5074
5075 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5076                 .f = cmd_set_bond_mon_period_parsed,
5077                 .data = (void *) 0,
5078                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5079                 .tokens = {
5080                                 (void *)&cmd_set_bond_mon_period_set,
5081                                 (void *)&cmd_set_bond_mon_period_bonding,
5082                                 (void *)&cmd_set_bond_mon_period_mon_period,
5083                                 (void *)&cmd_set_bond_mon_period_portnum,
5084                                 (void *)&cmd_set_bond_mon_period_period_ms,
5085                                 NULL
5086                 }
5087 };
5088
5089
5090
5091 struct cmd_set_bonding_agg_mode_policy_result {
5092         cmdline_fixed_string_t set;
5093         cmdline_fixed_string_t bonding;
5094         cmdline_fixed_string_t agg_mode;
5095         uint8_t port_num;
5096         cmdline_fixed_string_t policy;
5097 };
5098
5099
5100 static void
5101 cmd_set_bonding_agg_mode(void *parsed_result,
5102                 __attribute__((unused)) struct cmdline *cl,
5103                 __attribute__((unused)) void *data)
5104 {
5105         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5106         uint8_t policy = AGG_BANDWIDTH;
5107
5108         if (res->port_num >= nb_ports) {
5109                 printf("Port id %d must be less than %d\n",
5110                                 res->port_num, nb_ports);
5111                 return;
5112         }
5113
5114         if (!strcmp(res->policy, "bandwidth"))
5115                 policy = AGG_BANDWIDTH;
5116         else if (!strcmp(res->policy, "stable"))
5117                 policy = AGG_STABLE;
5118         else if (!strcmp(res->policy, "count"))
5119                 policy = AGG_COUNT;
5120
5121         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5122 }
5123
5124
5125 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5126         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5127                                 set, "set");
5128 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5130                                 bonding, "bonding");
5131
5132 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5133         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5134                                 agg_mode, "agg_mode");
5135
5136 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5137         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5138                                 port_num, UINT8);
5139
5140 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5141         TOKEN_STRING_INITIALIZER(
5142                         struct cmd_set_bonding_balance_xmit_policy_result,
5143                 policy, "stable#bandwidth#count");
5144
5145 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5146         .f = cmd_set_bonding_agg_mode,
5147         .data = (void *) 0,
5148         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5149         .tokens = {
5150                         (void *)&cmd_set_bonding_agg_mode_set,
5151                         (void *)&cmd_set_bonding_agg_mode_bonding,
5152                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5153                         (void *)&cmd_set_bonding_agg_mode_portnum,
5154                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5155                         NULL
5156                 }
5157 };
5158
5159
5160 #endif /* RTE_LIBRTE_PMD_BOND */
5161
5162 /* *** SET FORWARDING MODE *** */
5163 struct cmd_set_fwd_mode_result {
5164         cmdline_fixed_string_t set;
5165         cmdline_fixed_string_t fwd;
5166         cmdline_fixed_string_t mode;
5167 };
5168
5169 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5170                                     __attribute__((unused)) struct cmdline *cl,
5171                                     __attribute__((unused)) void *data)
5172 {
5173         struct cmd_set_fwd_mode_result *res = parsed_result;
5174
5175         retry_enabled = 0;
5176         set_pkt_forwarding_mode(res->mode);
5177 }
5178
5179 cmdline_parse_token_string_t cmd_setfwd_set =
5180         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5181 cmdline_parse_token_string_t cmd_setfwd_fwd =
5182         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5183 cmdline_parse_token_string_t cmd_setfwd_mode =
5184         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5185                 "" /* defined at init */);
5186
5187 cmdline_parse_inst_t cmd_set_fwd_mode = {
5188         .f = cmd_set_fwd_mode_parsed,
5189         .data = NULL,
5190         .help_str = NULL, /* defined at init */
5191         .tokens = {
5192                 (void *)&cmd_setfwd_set,
5193                 (void *)&cmd_setfwd_fwd,
5194                 (void *)&cmd_setfwd_mode,
5195                 NULL,
5196         },
5197 };
5198
5199 static void cmd_set_fwd_mode_init(void)
5200 {
5201         char *modes, *c;
5202         static char token[128];
5203         static char help[256];
5204         cmdline_parse_token_string_t *token_struct;
5205
5206         modes = list_pkt_forwarding_modes();
5207         snprintf(help, sizeof(help), "set fwd %s: "
5208                 "Set packet forwarding mode", modes);
5209         cmd_set_fwd_mode.help_str = help;
5210
5211         /* string token separator is # */
5212         for (c = token; *modes != '\0'; modes++)
5213                 if (*modes == '|')
5214                         *c++ = '#';
5215                 else
5216                         *c++ = *modes;
5217         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5218         token_struct->string_data.str = token;
5219 }
5220
5221 /* *** SET RETRY FORWARDING MODE *** */
5222 struct cmd_set_fwd_retry_mode_result {
5223         cmdline_fixed_string_t set;
5224         cmdline_fixed_string_t fwd;
5225         cmdline_fixed_string_t mode;
5226         cmdline_fixed_string_t retry;
5227 };
5228
5229 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5230                             __attribute__((unused)) struct cmdline *cl,
5231                             __attribute__((unused)) void *data)
5232 {
5233         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5234
5235         retry_enabled = 1;
5236         set_pkt_forwarding_mode(res->mode);
5237 }
5238
5239 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5240         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5241                         set, "set");
5242 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5243         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5244                         fwd, "fwd");
5245 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5246         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5247                         mode,
5248                 "" /* defined at init */);
5249 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5251                         retry, "retry");
5252
5253 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5254         .f = cmd_set_fwd_retry_mode_parsed,
5255         .data = NULL,
5256         .help_str = NULL, /* defined at init */
5257         .tokens = {
5258                 (void *)&cmd_setfwd_retry_set,
5259                 (void *)&cmd_setfwd_retry_fwd,
5260                 (void *)&cmd_setfwd_retry_mode,
5261                 (void *)&cmd_setfwd_retry_retry,
5262                 NULL,
5263         },
5264 };
5265
5266 static void cmd_set_fwd_retry_mode_init(void)
5267 {
5268         char *modes, *c;
5269         static char token[128];
5270         static char help[256];
5271         cmdline_parse_token_string_t *token_struct;
5272
5273         modes = list_pkt_forwarding_retry_modes();
5274         snprintf(help, sizeof(help), "set fwd %s retry: "
5275                 "Set packet forwarding mode with retry", modes);
5276         cmd_set_fwd_retry_mode.help_str = help;
5277
5278         /* string token separator is # */
5279         for (c = token; *modes != '\0'; modes++)
5280                 if (*modes == '|')
5281                         *c++ = '#';
5282                 else
5283                         *c++ = *modes;
5284         token_struct = (cmdline_parse_token_string_t *)
5285                 cmd_set_fwd_retry_mode.tokens[2];
5286         token_struct->string_data.str = token;
5287 }
5288
5289 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5290 struct cmd_set_burst_tx_retry_result {
5291         cmdline_fixed_string_t set;
5292         cmdline_fixed_string_t burst;
5293         cmdline_fixed_string_t tx;
5294         cmdline_fixed_string_t delay;
5295         uint32_t time;
5296         cmdline_fixed_string_t retry;
5297         uint32_t retry_num;
5298 };
5299
5300 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5301                                         __attribute__((unused)) struct cmdline *cl,
5302                                         __attribute__((unused)) void *data)
5303 {
5304         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5305
5306         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5307                 && !strcmp(res->tx, "tx")) {
5308                 if (!strcmp(res->delay, "delay"))
5309                         burst_tx_delay_time = res->time;
5310                 if (!strcmp(res->retry, "retry"))
5311                         burst_tx_retry_num = res->retry_num;
5312         }
5313
5314 }
5315
5316 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5317         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5318 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5319         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5320                                  "burst");
5321 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5322         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5323 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5324         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5325 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5326         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5327 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5328         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5329 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5330         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5331
5332 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5333         .f = cmd_set_burst_tx_retry_parsed,
5334         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5335         .tokens = {
5336                 (void *)&cmd_set_burst_tx_retry_set,
5337                 (void *)&cmd_set_burst_tx_retry_burst,
5338                 (void *)&cmd_set_burst_tx_retry_tx,
5339                 (void *)&cmd_set_burst_tx_retry_delay,
5340                 (void *)&cmd_set_burst_tx_retry_time,
5341                 (void *)&cmd_set_burst_tx_retry_retry,
5342                 (void *)&cmd_set_burst_tx_retry_retry_num,
5343                 NULL,
5344         },
5345 };
5346
5347 /* *** SET PROMISC MODE *** */
5348 struct cmd_set_promisc_mode_result {
5349         cmdline_fixed_string_t set;
5350         cmdline_fixed_string_t promisc;
5351         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5352         uint8_t port_num;                /* valid if "allports" argument == 0 */
5353         cmdline_fixed_string_t mode;
5354 };
5355
5356 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5357                                         __attribute__((unused)) struct cmdline *cl,
5358                                         void *allports)
5359 {
5360         struct cmd_set_promisc_mode_result *res = parsed_result;
5361         int enable;
5362         portid_t i;
5363
5364         if (!strcmp(res->mode, "on"))
5365                 enable = 1;
5366         else
5367                 enable = 0;
5368
5369         /* all ports */
5370         if (allports) {
5371                 RTE_ETH_FOREACH_DEV(i) {
5372                         if (enable)
5373                                 rte_eth_promiscuous_enable(i);
5374                         else
5375                                 rte_eth_promiscuous_disable(i);
5376                 }
5377         }
5378         else {
5379                 if (enable)
5380                         rte_eth_promiscuous_enable(res->port_num);
5381                 else
5382                         rte_eth_promiscuous_disable(res->port_num);
5383         }
5384 }
5385
5386 cmdline_parse_token_string_t cmd_setpromisc_set =
5387         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5388 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5389         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5390                                  "promisc");
5391 cmdline_parse_token_string_t cmd_setpromisc_portall =
5392         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5393                                  "all");
5394 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5395         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5396                               UINT8);
5397 cmdline_parse_token_string_t cmd_setpromisc_mode =
5398         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5399                                  "on#off");
5400
5401 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5402         .f = cmd_set_promisc_mode_parsed,
5403         .data = (void *)1,
5404         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5405         .tokens = {
5406                 (void *)&cmd_setpromisc_set,
5407                 (void *)&cmd_setpromisc_promisc,
5408                 (void *)&cmd_setpromisc_portall,
5409                 (void *)&cmd_setpromisc_mode,
5410                 NULL,
5411         },
5412 };
5413
5414 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5415         .f = cmd_set_promisc_mode_parsed,
5416         .data = (void *)0,
5417         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5418         .tokens = {
5419                 (void *)&cmd_setpromisc_set,
5420                 (void *)&cmd_setpromisc_promisc,
5421                 (void *)&cmd_setpromisc_portnum,
5422                 (void *)&cmd_setpromisc_mode,
5423                 NULL,
5424         },
5425 };
5426
5427 /* *** SET ALLMULTI MODE *** */
5428 struct cmd_set_allmulti_mode_result {
5429         cmdline_fixed_string_t set;
5430         cmdline_fixed_string_t allmulti;
5431         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5432         uint8_t port_num;                /* valid if "allports" argument == 0 */
5433         cmdline_fixed_string_t mode;
5434 };
5435
5436 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5437                                         __attribute__((unused)) struct cmdline *cl,
5438                                         void *allports)
5439 {
5440         struct cmd_set_allmulti_mode_result *res = parsed_result;
5441         int enable;
5442         portid_t i;
5443
5444         if (!strcmp(res->mode, "on"))
5445                 enable = 1;
5446         else
5447                 enable = 0;
5448
5449         /* all ports */
5450         if (allports) {
5451                 RTE_ETH_FOREACH_DEV(i) {
5452                         if (enable)
5453                                 rte_eth_allmulticast_enable(i);
5454                         else
5455                                 rte_eth_allmulticast_disable(i);
5456                 }
5457         }
5458         else {
5459                 if (enable)
5460                         rte_eth_allmulticast_enable(res->port_num);
5461                 else
5462                         rte_eth_allmulticast_disable(res->port_num);
5463         }
5464 }
5465
5466 cmdline_parse_token_string_t cmd_setallmulti_set =
5467         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5468 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5469         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5470                                  "allmulti");
5471 cmdline_parse_token_string_t cmd_setallmulti_portall =
5472         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5473                                  "all");
5474 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5475         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5476                               UINT8);
5477 cmdline_parse_token_string_t cmd_setallmulti_mode =
5478         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5479                                  "on#off");
5480
5481 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5482         .f = cmd_set_allmulti_mode_parsed,
5483         .data = (void *)1,
5484         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5485         .tokens = {
5486                 (void *)&cmd_setallmulti_set,
5487                 (void *)&cmd_setallmulti_allmulti,
5488                 (void *)&cmd_setallmulti_portall,
5489                 (void *)&cmd_setallmulti_mode,
5490                 NULL,
5491         },
5492 };
5493
5494 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5495         .f = cmd_set_allmulti_mode_parsed,
5496         .data = (void *)0,
5497         .help_str = "set allmulti <port_id> on|off: "
5498                 "Set allmulti mode on port_id",
5499         .tokens = {
5500                 (void *)&cmd_setallmulti_set,
5501                 (void *)&cmd_setallmulti_allmulti,
5502                 (void *)&cmd_setallmulti_portnum,
5503                 (void *)&cmd_setallmulti_mode,
5504                 NULL,
5505         },
5506 };
5507
5508 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5509 struct cmd_link_flow_ctrl_set_result {
5510         cmdline_fixed_string_t set;
5511         cmdline_fixed_string_t flow_ctrl;
5512         cmdline_fixed_string_t rx;
5513         cmdline_fixed_string_t rx_lfc_mode;
5514         cmdline_fixed_string_t tx;
5515         cmdline_fixed_string_t tx_lfc_mode;
5516         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5517         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5518         cmdline_fixed_string_t autoneg_str;
5519         cmdline_fixed_string_t autoneg;
5520         cmdline_fixed_string_t hw_str;
5521         uint32_t high_water;
5522         cmdline_fixed_string_t lw_str;
5523         uint32_t low_water;
5524         cmdline_fixed_string_t pt_str;
5525         uint16_t pause_time;
5526         cmdline_fixed_string_t xon_str;
5527         uint16_t send_xon;
5528         uint8_t  port_id;
5529 };
5530
5531 cmdline_parse_token_string_t cmd_lfc_set_set =
5532         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5533                                 set, "set");
5534 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5535         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5536                                 flow_ctrl, "flow_ctrl");
5537 cmdline_parse_token_string_t cmd_lfc_set_rx =
5538         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5539                                 rx, "rx");
5540 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5541         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5542                                 rx_lfc_mode, "on#off");
5543 cmdline_parse_token_string_t cmd_lfc_set_tx =
5544         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5545                                 tx, "tx");
5546 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5547         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5548                                 tx_lfc_mode, "on#off");
5549 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5550         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5551                                 hw_str, "high_water");
5552 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5553         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5554                                 high_water, UINT32);
5555 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5556         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5557                                 lw_str, "low_water");
5558 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5559         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5560                                 low_water, UINT32);
5561 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5562         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5563                                 pt_str, "pause_time");
5564 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5565         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5566                                 pause_time, UINT16);
5567 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5568         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5569                                 xon_str, "send_xon");
5570 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5571         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5572                                 send_xon, UINT16);
5573 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5574         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5575                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5576 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5577         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5578                                 mac_ctrl_frame_fwd_mode, "on#off");
5579 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5580         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5581                                 autoneg_str, "autoneg");
5582 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5583         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5584                                 autoneg, "on#off");
5585 cmdline_parse_token_num_t cmd_lfc_set_portid =
5586         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5587                                 port_id, UINT8);
5588
5589 /* forward declaration */
5590 static void
5591 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5592                               void *data);
5593
5594 cmdline_parse_inst_t cmd_link_flow_control_set = {
5595         .f = cmd_link_flow_ctrl_set_parsed,
5596         .data = NULL,
5597         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5598                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5599                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5600         .tokens = {
5601                 (void *)&cmd_lfc_set_set,
5602                 (void *)&cmd_lfc_set_flow_ctrl,
5603                 (void *)&cmd_lfc_set_rx,
5604                 (void *)&cmd_lfc_set_rx_mode,
5605                 (void *)&cmd_lfc_set_tx,
5606                 (void *)&cmd_lfc_set_tx_mode,
5607                 (void *)&cmd_lfc_set_high_water,
5608                 (void *)&cmd_lfc_set_low_water,
5609                 (void *)&cmd_lfc_set_pause_time,
5610                 (void *)&cmd_lfc_set_send_xon,
5611                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5612                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5613                 (void *)&cmd_lfc_set_autoneg_str,
5614                 (void *)&cmd_lfc_set_autoneg,
5615                 (void *)&cmd_lfc_set_portid,
5616                 NULL,
5617         },
5618 };
5619
5620 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5621         .f = cmd_link_flow_ctrl_set_parsed,
5622         .data = (void *)&cmd_link_flow_control_set_rx,
5623         .help_str = "set flow_ctrl rx on|off <port_id>: "
5624                 "Change rx flow control parameter",
5625         .tokens = {
5626                 (void *)&cmd_lfc_set_set,
5627                 (void *)&cmd_lfc_set_flow_ctrl,
5628                 (void *)&cmd_lfc_set_rx,
5629                 (void *)&cmd_lfc_set_rx_mode,
5630                 (void *)&cmd_lfc_set_portid,
5631                 NULL,
5632         },
5633 };
5634
5635 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5636         .f = cmd_link_flow_ctrl_set_parsed,
5637         .data = (void *)&cmd_link_flow_control_set_tx,
5638         .help_str = "set flow_ctrl tx on|off <port_id>: "
5639                 "Change tx flow control parameter",
5640         .tokens = {
5641                 (void *)&cmd_lfc_set_set,
5642                 (void *)&cmd_lfc_set_flow_ctrl,
5643                 (void *)&cmd_lfc_set_tx,
5644                 (void *)&cmd_lfc_set_tx_mode,
5645                 (void *)&cmd_lfc_set_portid,
5646                 NULL,
5647         },
5648 };
5649
5650 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5651         .f = cmd_link_flow_ctrl_set_parsed,
5652         .data = (void *)&cmd_link_flow_control_set_hw,
5653         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5654                 "Change high water flow control parameter",
5655         .tokens = {
5656                 (void *)&cmd_lfc_set_set,
5657                 (void *)&cmd_lfc_set_flow_ctrl,
5658                 (void *)&cmd_lfc_set_high_water_str,
5659                 (void *)&cmd_lfc_set_high_water,
5660                 (void *)&cmd_lfc_set_portid,
5661                 NULL,
5662         },
5663 };
5664
5665 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5666         .f = cmd_link_flow_ctrl_set_parsed,
5667         .data = (void *)&cmd_link_flow_control_set_lw,
5668         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5669                 "Change low water flow control parameter",
5670         .tokens = {
5671                 (void *)&cmd_lfc_set_set,
5672                 (void *)&cmd_lfc_set_flow_ctrl,
5673                 (void *)&cmd_lfc_set_low_water_str,
5674                 (void *)&cmd_lfc_set_low_water,
5675                 (void *)&cmd_lfc_set_portid,
5676                 NULL,
5677         },
5678 };
5679
5680 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5681         .f = cmd_link_flow_ctrl_set_parsed,
5682         .data = (void *)&cmd_link_flow_control_set_pt,
5683         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5684                 "Change pause time flow control parameter",
5685         .tokens = {
5686                 (void *)&cmd_lfc_set_set,
5687                 (void *)&cmd_lfc_set_flow_ctrl,
5688                 (void *)&cmd_lfc_set_pause_time_str,
5689                 (void *)&cmd_lfc_set_pause_time,
5690                 (void *)&cmd_lfc_set_portid,
5691                 NULL,
5692         },
5693 };
5694
5695 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5696         .f = cmd_link_flow_ctrl_set_parsed,
5697         .data = (void *)&cmd_link_flow_control_set_xon,
5698         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5699                 "Change send_xon flow control parameter",
5700         .tokens = {
5701                 (void *)&cmd_lfc_set_set,
5702                 (void *)&cmd_lfc_set_flow_ctrl,
5703                 (void *)&cmd_lfc_set_send_xon_str,
5704                 (void *)&cmd_lfc_set_send_xon,
5705                 (void *)&cmd_lfc_set_portid,
5706                 NULL,
5707         },
5708 };
5709
5710 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5711         .f = cmd_link_flow_ctrl_set_parsed,
5712         .data = (void *)&cmd_link_flow_control_set_macfwd,
5713         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5714                 "Change mac ctrl fwd flow control parameter",
5715         .tokens = {
5716                 (void *)&cmd_lfc_set_set,
5717                 (void *)&cmd_lfc_set_flow_ctrl,
5718                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5719                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5720                 (void *)&cmd_lfc_set_portid,
5721                 NULL,
5722         },
5723 };
5724
5725 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5726         .f = cmd_link_flow_ctrl_set_parsed,
5727         .data = (void *)&cmd_link_flow_control_set_autoneg,
5728         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5729                 "Change autoneg flow control parameter",
5730         .tokens = {
5731                 (void *)&cmd_lfc_set_set,
5732                 (void *)&cmd_lfc_set_flow_ctrl,
5733                 (void *)&cmd_lfc_set_autoneg_str,
5734                 (void *)&cmd_lfc_set_autoneg,
5735                 (void *)&cmd_lfc_set_portid,
5736                 NULL,
5737         },
5738 };
5739
5740 static void
5741 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5742                               __attribute__((unused)) struct cmdline *cl,
5743                               void *data)
5744 {
5745         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5746         cmdline_parse_inst_t *cmd = data;
5747         struct rte_eth_fc_conf fc_conf;
5748         int rx_fc_en = 0;
5749         int tx_fc_en = 0;
5750         int ret;
5751
5752         /*
5753          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5754          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5755          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5756          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5757          */
5758         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5759                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5760         };
5761
5762         /* Partial command line, retrieve current configuration */
5763         if (cmd) {
5764                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5765                 if (ret != 0) {
5766                         printf("cannot get current flow ctrl parameters, return"
5767                                "code = %d\n", ret);
5768                         return;
5769                 }
5770
5771                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5772                     (fc_conf.mode == RTE_FC_FULL))
5773                         rx_fc_en = 1;
5774                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5775                     (fc_conf.mode == RTE_FC_FULL))
5776                         tx_fc_en = 1;
5777         }
5778
5779         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5780                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5781
5782         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5783                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5784
5785         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5786
5787         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5788                 fc_conf.high_water = res->high_water;
5789
5790         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5791                 fc_conf.low_water = res->low_water;
5792
5793         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5794                 fc_conf.pause_time = res->pause_time;
5795
5796         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5797                 fc_conf.send_xon = res->send_xon;
5798
5799         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5800                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5801                         fc_conf.mac_ctrl_frame_fwd = 1;
5802                 else
5803                         fc_conf.mac_ctrl_frame_fwd = 0;
5804         }
5805
5806         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5807                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5808
5809         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5810         if (ret != 0)
5811                 printf("bad flow contrl parameter, return code = %d \n", ret);
5812 }
5813
5814 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5815 struct cmd_priority_flow_ctrl_set_result {
5816         cmdline_fixed_string_t set;
5817         cmdline_fixed_string_t pfc_ctrl;
5818         cmdline_fixed_string_t rx;
5819         cmdline_fixed_string_t rx_pfc_mode;
5820         cmdline_fixed_string_t tx;
5821         cmdline_fixed_string_t tx_pfc_mode;
5822         uint32_t high_water;
5823         uint32_t low_water;
5824         uint16_t pause_time;
5825         uint8_t  priority;
5826         uint8_t  port_id;
5827 };
5828
5829 static void
5830 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5831                        __attribute__((unused)) struct cmdline *cl,
5832                        __attribute__((unused)) void *data)
5833 {
5834         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5835         struct rte_eth_pfc_conf pfc_conf;
5836         int rx_fc_enable, tx_fc_enable;
5837         int ret;
5838
5839         /*
5840          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5841          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5842          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5843          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5844          */
5845         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5846                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5847         };
5848
5849         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5850         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5851         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5852         pfc_conf.fc.high_water = res->high_water;
5853         pfc_conf.fc.low_water  = res->low_water;
5854         pfc_conf.fc.pause_time = res->pause_time;
5855         pfc_conf.priority      = res->priority;
5856
5857         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5858         if (ret != 0)
5859                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5860 }
5861
5862 cmdline_parse_token_string_t cmd_pfc_set_set =
5863         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5864                                 set, "set");
5865 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5866         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5867                                 pfc_ctrl, "pfc_ctrl");
5868 cmdline_parse_token_string_t cmd_pfc_set_rx =
5869         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5870                                 rx, "rx");
5871 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5872         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5873                                 rx_pfc_mode, "on#off");
5874 cmdline_parse_token_string_t cmd_pfc_set_tx =
5875         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5876                                 tx, "tx");
5877 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5878         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5879                                 tx_pfc_mode, "on#off");
5880 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5881         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5882                                 high_water, UINT32);
5883 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5884         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5885                                 low_water, UINT32);
5886 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5887         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5888                                 pause_time, UINT16);
5889 cmdline_parse_token_num_t cmd_pfc_set_priority =
5890         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5891                                 priority, UINT8);
5892 cmdline_parse_token_num_t cmd_pfc_set_portid =
5893         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5894                                 port_id, UINT8);
5895
5896 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5897         .f = cmd_priority_flow_ctrl_set_parsed,
5898         .data = NULL,
5899         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5900                 "<pause_time> <priority> <port_id>: "
5901                 "Configure the Ethernet priority flow control",
5902         .tokens = {
5903                 (void *)&cmd_pfc_set_set,
5904                 (void *)&cmd_pfc_set_flow_ctrl,
5905                 (void *)&cmd_pfc_set_rx,
5906                 (void *)&cmd_pfc_set_rx_mode,
5907                 (void *)&cmd_pfc_set_tx,
5908                 (void *)&cmd_pfc_set_tx_mode,
5909                 (void *)&cmd_pfc_set_high_water,
5910                 (void *)&cmd_pfc_set_low_water,
5911                 (void *)&cmd_pfc_set_pause_time,
5912                 (void *)&cmd_pfc_set_priority,
5913                 (void *)&cmd_pfc_set_portid,
5914                 NULL,
5915         },
5916 };
5917
5918 /* *** RESET CONFIGURATION *** */
5919 struct cmd_reset_result {
5920         cmdline_fixed_string_t reset;
5921         cmdline_fixed_string_t def;
5922 };
5923
5924 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5925                              struct cmdline *cl,
5926                              __attribute__((unused)) void *data)
5927 {
5928         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5929         set_def_fwd_config();
5930 }
5931
5932 cmdline_parse_token_string_t cmd_reset_set =
5933         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5934 cmdline_parse_token_string_t cmd_reset_def =
5935         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5936                                  "default");
5937
5938 cmdline_parse_inst_t cmd_reset = {
5939         .f = cmd_reset_parsed,
5940         .data = NULL,
5941         .help_str = "set default: Reset default forwarding configuration",
5942         .tokens = {
5943                 (void *)&cmd_reset_set,
5944                 (void *)&cmd_reset_def,
5945                 NULL,
5946         },
5947 };
5948
5949 /* *** START FORWARDING *** */
5950 struct cmd_start_result {
5951         cmdline_fixed_string_t start;
5952 };
5953
5954 cmdline_parse_token_string_t cmd_start_start =
5955         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5956
5957 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5958                              __attribute__((unused)) struct cmdline *cl,
5959                              __attribute__((unused)) void *data)
5960 {
5961         start_packet_forwarding(0);
5962 }
5963
5964 cmdline_parse_inst_t cmd_start = {
5965         .f = cmd_start_parsed,
5966         .data = NULL,
5967         .help_str = "start: Start packet forwarding",
5968         .tokens = {
5969                 (void *)&cmd_start_start,
5970                 NULL,
5971         },
5972 };
5973
5974 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5975 struct cmd_start_tx_first_result {
5976         cmdline_fixed_string_t start;
5977         cmdline_fixed_string_t tx_first;
5978 };
5979
5980 static void
5981 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5982                           __attribute__((unused)) struct cmdline *cl,
5983                           __attribute__((unused)) void *data)
5984 {
5985         start_packet_forwarding(1);
5986 }
5987
5988 cmdline_parse_token_string_t cmd_start_tx_first_start =
5989         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5990                                  "start");
5991 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5992         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5993                                  tx_first, "tx_first");
5994
5995 cmdline_parse_inst_t cmd_start_tx_first = {
5996         .f = cmd_start_tx_first_parsed,
5997         .data = NULL,
5998         .help_str = "start tx_first: Start packet forwarding, "
5999                 "after sending 1 burst of packets",
6000         .tokens = {
6001                 (void *)&cmd_start_tx_first_start,
6002                 (void *)&cmd_start_tx_first_tx_first,
6003                 NULL,
6004         },
6005 };
6006
6007 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6008 struct cmd_start_tx_first_n_result {
6009         cmdline_fixed_string_t start;
6010         cmdline_fixed_string_t tx_first;
6011         uint32_t tx_num;
6012 };
6013
6014 static void
6015 cmd_start_tx_first_n_parsed(void *parsed_result,
6016                           __attribute__((unused)) struct cmdline *cl,
6017                           __attribute__((unused)) void *data)
6018 {
6019         struct cmd_start_tx_first_n_result *res = parsed_result;
6020
6021         start_packet_forwarding(res->tx_num);
6022 }
6023
6024 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6025         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6026                         start, "start");
6027 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6028         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6029                         tx_first, "tx_first");
6030 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6031         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6032                         tx_num, UINT32);
6033
6034 cmdline_parse_inst_t cmd_start_tx_first_n = {
6035         .f = cmd_start_tx_first_n_parsed,
6036         .data = NULL,
6037         .help_str = "start tx_first <num>: "
6038                 "packet forwarding, after sending <num> bursts of packets",
6039         .tokens = {
6040                 (void *)&cmd_start_tx_first_n_start,
6041                 (void *)&cmd_start_tx_first_n_tx_first,
6042                 (void *)&cmd_start_tx_first_n_tx_num,
6043                 NULL,
6044         },
6045 };
6046
6047 /* *** SET LINK UP *** */
6048 struct cmd_set_link_up_result {
6049         cmdline_fixed_string_t set;
6050         cmdline_fixed_string_t link_up;
6051         cmdline_fixed_string_t port;
6052         uint8_t port_id;
6053 };
6054
6055 cmdline_parse_token_string_t cmd_set_link_up_set =
6056         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6057 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6058         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6059                                 "link-up");
6060 cmdline_parse_token_string_t cmd_set_link_up_port =
6061         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6062 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6063         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6064
6065 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6066                              __attribute__((unused)) struct cmdline *cl,
6067                              __attribute__((unused)) void *data)
6068 {
6069         struct cmd_set_link_up_result *res = parsed_result;
6070         dev_set_link_up(res->port_id);
6071 }
6072
6073 cmdline_parse_inst_t cmd_set_link_up = {
6074         .f = cmd_set_link_up_parsed,
6075         .data = NULL,
6076         .help_str = "set link-up port <port id>",
6077         .tokens = {
6078                 (void *)&cmd_set_link_up_set,
6079                 (void *)&cmd_set_link_up_link_up,
6080                 (void *)&cmd_set_link_up_port,
6081                 (void *)&cmd_set_link_up_port_id,
6082                 NULL,
6083         },
6084 };
6085
6086 /* *** SET LINK DOWN *** */
6087 struct cmd_set_link_down_result {
6088         cmdline_fixed_string_t set;
6089         cmdline_fixed_string_t link_down;
6090         cmdline_fixed_string_t port;
6091         uint8_t port_id;
6092 };
6093
6094 cmdline_parse_token_string_t cmd_set_link_down_set =
6095         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6096 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6097         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6098                                 "link-down");
6099 cmdline_parse_token_string_t cmd_set_link_down_port =
6100         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6101 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6102         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6103
6104 static void cmd_set_link_down_parsed(
6105                                 __attribute__((unused)) void *parsed_result,
6106                                 __attribute__((unused)) struct cmdline *cl,
6107                                 __attribute__((unused)) void *data)
6108 {
6109         struct cmd_set_link_down_result *res = parsed_result;
6110         dev_set_link_down(res->port_id);
6111 }
6112
6113 cmdline_parse_inst_t cmd_set_link_down = {
6114         .f = cmd_set_link_down_parsed,
6115         .data = NULL,
6116         .help_str = "set link-down port <port id>",
6117         .tokens = {
6118                 (void *)&cmd_set_link_down_set,
6119                 (void *)&cmd_set_link_down_link_down,
6120                 (void *)&cmd_set_link_down_port,
6121                 (void *)&cmd_set_link_down_port_id,
6122                 NULL,
6123         },
6124 };
6125
6126 /* *** SHOW CFG *** */
6127 struct cmd_showcfg_result {
6128         cmdline_fixed_string_t show;
6129         cmdline_fixed_string_t cfg;
6130         cmdline_fixed_string_t what;
6131 };
6132
6133 static void cmd_showcfg_parsed(void *parsed_result,
6134                                __attribute__((unused)) struct cmdline *cl,
6135                                __attribute__((unused)) void *data)
6136 {
6137         struct cmd_showcfg_result *res = parsed_result;
6138         if (!strcmp(res->what, "rxtx"))
6139                 rxtx_config_display();
6140         else if (!strcmp(res->what, "cores"))
6141                 fwd_lcores_config_display();
6142         else if (!strcmp(res->what, "fwd"))
6143                 pkt_fwd_config_display(&cur_fwd_config);
6144         else if (!strcmp(res->what, "txpkts"))
6145                 show_tx_pkt_segments();
6146 }
6147
6148 cmdline_parse_token_string_t cmd_showcfg_show =
6149         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6150 cmdline_parse_token_string_t cmd_showcfg_port =
6151         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6152 cmdline_parse_token_string_t cmd_showcfg_what =
6153         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6154                                  "rxtx#cores#fwd#txpkts");
6155
6156 cmdline_parse_inst_t cmd_showcfg = {
6157         .f = cmd_showcfg_parsed,
6158         .data = NULL,
6159         .help_str = "show config rxtx|cores|fwd|txpkts",
6160         .tokens = {
6161                 (void *)&cmd_showcfg_show,
6162                 (void *)&cmd_showcfg_port,
6163                 (void *)&cmd_showcfg_what,
6164                 NULL,
6165         },
6166 };
6167
6168 /* *** SHOW ALL PORT INFO *** */
6169 struct cmd_showportall_result {
6170         cmdline_fixed_string_t show;
6171         cmdline_fixed_string_t port;
6172         cmdline_fixed_string_t what;
6173         cmdline_fixed_string_t all;
6174 };
6175
6176 static void cmd_showportall_parsed(void *parsed_result,
6177                                 __attribute__((unused)) struct cmdline *cl,
6178                                 __attribute__((unused)) void *data)
6179 {
6180         portid_t i;
6181
6182         struct cmd_showportall_result *res = parsed_result;
6183         if (!strcmp(res->show, "clear")) {
6184                 if (!strcmp(res->what, "stats"))
6185                         RTE_ETH_FOREACH_DEV(i)
6186                                 nic_stats_clear(i);
6187                 else if (!strcmp(res->what, "xstats"))
6188                         RTE_ETH_FOREACH_DEV(i)
6189                                 nic_xstats_clear(i);
6190         } else if (!strcmp(res->what, "info"))
6191                 RTE_ETH_FOREACH_DEV(i)
6192                         port_infos_display(i);
6193         else if (!strcmp(res->what, "stats"))
6194                 RTE_ETH_FOREACH_DEV(i)
6195                         nic_stats_display(i);
6196         else if (!strcmp(res->what, "xstats"))
6197                 RTE_ETH_FOREACH_DEV(i)
6198                         nic_xstats_display(i);
6199         else if (!strcmp(res->what, "fdir"))
6200                 RTE_ETH_FOREACH_DEV(i)
6201                         fdir_get_infos(i);
6202         else if (!strcmp(res->what, "stat_qmap"))
6203                 RTE_ETH_FOREACH_DEV(i)
6204                         nic_stats_mapping_display(i);
6205         else if (!strcmp(res->what, "dcb_tc"))
6206                 RTE_ETH_FOREACH_DEV(i)
6207                         port_dcb_info_display(i);
6208         else if (!strcmp(res->what, "cap"))
6209                 RTE_ETH_FOREACH_DEV(i)
6210                         port_offload_cap_display(i);
6211 }
6212
6213 cmdline_parse_token_string_t cmd_showportall_show =
6214         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6215                                  "show#clear");
6216 cmdline_parse_token_string_t cmd_showportall_port =
6217         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6218 cmdline_parse_token_string_t cmd_showportall_what =
6219         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6220                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6221 cmdline_parse_token_string_t cmd_showportall_all =
6222         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6223 cmdline_parse_inst_t cmd_showportall = {
6224         .f = cmd_showportall_parsed,
6225         .data = NULL,
6226         .help_str = "show|clear port "
6227                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6228         .tokens = {
6229                 (void *)&cmd_showportall_show,
6230                 (void *)&cmd_showportall_port,
6231                 (void *)&cmd_showportall_what,
6232                 (void *)&cmd_showportall_all,
6233                 NULL,
6234         },
6235 };
6236
6237 /* *** SHOW PORT INFO *** */
6238 struct cmd_showport_result {
6239         cmdline_fixed_string_t show;
6240         cmdline_fixed_string_t port;
6241         cmdline_fixed_string_t what;
6242         uint8_t portnum;
6243 };
6244
6245 static void cmd_showport_parsed(void *parsed_result,
6246                                 __attribute__((unused)) struct cmdline *cl,
6247                                 __attribute__((unused)) void *data)
6248 {
6249         struct cmd_showport_result *res = parsed_result;
6250         if (!strcmp(res->show, "clear")) {
6251                 if (!strcmp(res->what, "stats"))
6252                         nic_stats_clear(res->portnum);
6253                 else if (!strcmp(res->what, "xstats"))
6254                         nic_xstats_clear(res->portnum);
6255         } else if (!strcmp(res->what, "info"))
6256                 port_infos_display(res->portnum);
6257         else if (!strcmp(res->what, "stats"))
6258                 nic_stats_display(res->portnum);
6259         else if (!strcmp(res->what, "xstats"))
6260                 nic_xstats_display(res->portnum);
6261         else if (!strcmp(res->what, "fdir"))
6262                  fdir_get_infos(res->portnum);
6263         else if (!strcmp(res->what, "stat_qmap"))
6264                 nic_stats_mapping_display(res->portnum);
6265         else if (!strcmp(res->what, "dcb_tc"))
6266                 port_dcb_info_display(res->portnum);
6267         else if (!strcmp(res->what, "cap"))
6268                 port_offload_cap_display(res->portnum);
6269 }
6270
6271 cmdline_parse_token_string_t cmd_showport_show =
6272         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6273                                  "show#clear");
6274 cmdline_parse_token_string_t cmd_showport_port =
6275         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6276 cmdline_parse_token_string_t cmd_showport_what =
6277         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6278                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6279 cmdline_parse_token_num_t cmd_showport_portnum =
6280         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6281
6282 cmdline_parse_inst_t cmd_showport = {
6283         .f = cmd_showport_parsed,
6284         .data = NULL,
6285         .help_str = "show|clear port "
6286                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6287                 "<port_id>",
6288         .tokens = {
6289                 (void *)&cmd_showport_show,
6290                 (void *)&cmd_showport_port,
6291                 (void *)&cmd_showport_what,
6292                 (void *)&cmd_showport_portnum,
6293                 NULL,
6294         },
6295 };
6296
6297 /* *** SHOW QUEUE INFO *** */
6298 struct cmd_showqueue_result {
6299         cmdline_fixed_string_t show;
6300         cmdline_fixed_string_t type;
6301         cmdline_fixed_string_t what;
6302         uint8_t portnum;
6303         uint16_t queuenum;
6304 };
6305
6306 static void
6307 cmd_showqueue_parsed(void *parsed_result,
6308         __attribute__((unused)) struct cmdline *cl,
6309         __attribute__((unused)) void *data)
6310 {
6311         struct cmd_showqueue_result *res = parsed_result;
6312
6313         if (!strcmp(res->type, "rxq"))
6314                 rx_queue_infos_display(res->portnum, res->queuenum);
6315         else if (!strcmp(res->type, "txq"))
6316                 tx_queue_infos_display(res->portnum, res->queuenum);
6317 }
6318
6319 cmdline_parse_token_string_t cmd_showqueue_show =
6320         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6321 cmdline_parse_token_string_t cmd_showqueue_type =
6322         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6323 cmdline_parse_token_string_t cmd_showqueue_what =
6324         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6325 cmdline_parse_token_num_t cmd_showqueue_portnum =
6326         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6327 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6328         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6329
6330 cmdline_parse_inst_t cmd_showqueue = {
6331         .f = cmd_showqueue_parsed,
6332         .data = NULL,
6333         .help_str = "show rxq|txq info <port_id> <queue_id>",
6334         .tokens = {
6335                 (void *)&cmd_showqueue_show,
6336                 (void *)&cmd_showqueue_type,
6337                 (void *)&cmd_showqueue_what,
6338                 (void *)&cmd_showqueue_portnum,
6339                 (void *)&cmd_showqueue_queuenum,
6340                 NULL,
6341         },
6342 };
6343
6344 /* *** READ PORT REGISTER *** */
6345 struct cmd_read_reg_result {
6346         cmdline_fixed_string_t read;
6347         cmdline_fixed_string_t reg;
6348         uint8_t port_id;
6349         uint32_t reg_off;
6350 };
6351
6352 static void
6353 cmd_read_reg_parsed(void *parsed_result,
6354                     __attribute__((unused)) struct cmdline *cl,
6355                     __attribute__((unused)) void *data)
6356 {
6357         struct cmd_read_reg_result *res = parsed_result;
6358         port_reg_display(res->port_id, res->reg_off);
6359 }
6360
6361 cmdline_parse_token_string_t cmd_read_reg_read =
6362         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6363 cmdline_parse_token_string_t cmd_read_reg_reg =
6364         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6365 cmdline_parse_token_num_t cmd_read_reg_port_id =
6366         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6367 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6368         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6369
6370 cmdline_parse_inst_t cmd_read_reg = {
6371         .f = cmd_read_reg_parsed,
6372         .data = NULL,
6373         .help_str = "read reg <port_id> <reg_off>",
6374         .tokens = {
6375                 (void *)&cmd_read_reg_read,
6376                 (void *)&cmd_read_reg_reg,
6377                 (void *)&cmd_read_reg_port_id,
6378                 (void *)&cmd_read_reg_reg_off,
6379                 NULL,
6380         },
6381 };
6382
6383 /* *** READ PORT REGISTER BIT FIELD *** */
6384 struct cmd_read_reg_bit_field_result {
6385         cmdline_fixed_string_t read;
6386         cmdline_fixed_string_t regfield;
6387         uint8_t port_id;
6388         uint32_t reg_off;
6389         uint8_t bit1_pos;
6390         uint8_t bit2_pos;
6391 };
6392
6393 static void
6394 cmd_read_reg_bit_field_parsed(void *parsed_result,
6395                               __attribute__((unused)) struct cmdline *cl,
6396                               __attribute__((unused)) void *data)
6397 {
6398         struct cmd_read_reg_bit_field_result *res = parsed_result;
6399         port_reg_bit_field_display(res->port_id, res->reg_off,
6400                                    res->bit1_pos, res->bit2_pos);
6401 }
6402
6403 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6404         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6405                                  "read");
6406 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6407         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6408                                  regfield, "regfield");
6409 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6410         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6411                               UINT8);
6412 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6413         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6414                               UINT32);
6415 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6416         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6417                               UINT8);
6418 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6419         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6420                               UINT8);
6421
6422 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6423         .f = cmd_read_reg_bit_field_parsed,
6424         .data = NULL,
6425         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6426         "Read register bit field between bit_x and bit_y included",
6427         .tokens = {
6428                 (void *)&cmd_read_reg_bit_field_read,
6429                 (void *)&cmd_read_reg_bit_field_regfield,
6430                 (void *)&cmd_read_reg_bit_field_port_id,
6431                 (void *)&cmd_read_reg_bit_field_reg_off,
6432                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6433                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6434                 NULL,
6435         },
6436 };
6437
6438 /* *** READ PORT REGISTER BIT *** */
6439 struct cmd_read_reg_bit_result {
6440         cmdline_fixed_string_t read;
6441         cmdline_fixed_string_t regbit;
6442         uint8_t port_id;
6443         uint32_t reg_off;
6444         uint8_t bit_pos;
6445 };
6446
6447 static void
6448 cmd_read_reg_bit_parsed(void *parsed_result,
6449                         __attribute__((unused)) struct cmdline *cl,
6450                         __attribute__((unused)) void *data)
6451 {
6452         struct cmd_read_reg_bit_result *res = parsed_result;
6453         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6454 }
6455
6456 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6457         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6458 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6459         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6460                                  regbit, "regbit");
6461 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6462         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6463 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6464         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6465 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6466         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6467
6468 cmdline_parse_inst_t cmd_read_reg_bit = {
6469         .f = cmd_read_reg_bit_parsed,
6470         .data = NULL,
6471         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6472         .tokens = {
6473                 (void *)&cmd_read_reg_bit_read,
6474                 (void *)&cmd_read_reg_bit_regbit,
6475                 (void *)&cmd_read_reg_bit_port_id,
6476                 (void *)&cmd_read_reg_bit_reg_off,
6477                 (void *)&cmd_read_reg_bit_bit_pos,
6478                 NULL,
6479         },
6480 };
6481
6482 /* *** WRITE PORT REGISTER *** */
6483 struct cmd_write_reg_result {
6484         cmdline_fixed_string_t write;
6485         cmdline_fixed_string_t reg;
6486         uint8_t port_id;
6487         uint32_t reg_off;
6488         uint32_t value;
6489 };
6490
6491 static void
6492 cmd_write_reg_parsed(void *parsed_result,
6493                      __attribute__((unused)) struct cmdline *cl,
6494                      __attribute__((unused)) void *data)
6495 {
6496         struct cmd_write_reg_result *res = parsed_result;
6497         port_reg_set(res->port_id, res->reg_off, res->value);
6498 }
6499
6500 cmdline_parse_token_string_t cmd_write_reg_write =
6501         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6502 cmdline_parse_token_string_t cmd_write_reg_reg =
6503         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6504 cmdline_parse_token_num_t cmd_write_reg_port_id =
6505         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6506 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6507         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6508 cmdline_parse_token_num_t cmd_write_reg_value =
6509         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6510
6511 cmdline_parse_inst_t cmd_write_reg = {
6512         .f = cmd_write_reg_parsed,
6513         .data = NULL,
6514         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6515         .tokens = {
6516                 (void *)&cmd_write_reg_write,
6517                 (void *)&cmd_write_reg_reg,
6518                 (void *)&cmd_write_reg_port_id,
6519                 (void *)&cmd_write_reg_reg_off,
6520                 (void *)&cmd_write_reg_value,
6521                 NULL,
6522         },
6523 };
6524
6525 /* *** WRITE PORT REGISTER BIT FIELD *** */
6526 struct cmd_write_reg_bit_field_result {
6527         cmdline_fixed_string_t write;
6528         cmdline_fixed_string_t regfield;
6529         uint8_t port_id;
6530         uint32_t reg_off;
6531         uint8_t bit1_pos;
6532         uint8_t bit2_pos;
6533         uint32_t value;
6534 };
6535
6536 static void
6537 cmd_write_reg_bit_field_parsed(void *parsed_result,
6538                                __attribute__((unused)) struct cmdline *cl,
6539                                __attribute__((unused)) void *data)
6540 {
6541         struct cmd_write_reg_bit_field_result *res = parsed_result;
6542         port_reg_bit_field_set(res->port_id, res->reg_off,
6543                           res->bit1_pos, res->bit2_pos, res->value);
6544 }
6545
6546 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6547         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6548                                  "write");
6549 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6550         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6551                                  regfield, "regfield");
6552 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6553         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6554                               UINT8);
6555 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6556         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6557                               UINT32);
6558 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6559         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6560                               UINT8);
6561 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6562         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6563                               UINT8);
6564 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6565         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6566                               UINT32);
6567
6568 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6569         .f = cmd_write_reg_bit_field_parsed,
6570         .data = NULL,
6571         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6572                 "<reg_value>: "
6573                 "Set register bit field between bit_x and bit_y included",
6574         .tokens = {
6575                 (void *)&cmd_write_reg_bit_field_write,
6576                 (void *)&cmd_write_reg_bit_field_regfield,
6577                 (void *)&cmd_write_reg_bit_field_port_id,
6578                 (void *)&cmd_write_reg_bit_field_reg_off,
6579                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6580                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6581                 (void *)&cmd_write_reg_bit_field_value,
6582                 NULL,
6583         },
6584 };
6585
6586 /* *** WRITE PORT REGISTER BIT *** */
6587 struct cmd_write_reg_bit_result {
6588         cmdline_fixed_string_t write;
6589         cmdline_fixed_string_t regbit;
6590         uint8_t port_id;
6591         uint32_t reg_off;
6592         uint8_t bit_pos;
6593         uint8_t value;
6594 };
6595
6596 static void
6597 cmd_write_reg_bit_parsed(void *parsed_result,
6598                          __attribute__((unused)) struct cmdline *cl,
6599                          __attribute__((unused)) void *data)
6600 {
6601         struct cmd_write_reg_bit_result *res = parsed_result;
6602         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6603 }
6604
6605 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6606         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6607                                  "write");
6608 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6609         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6610                                  regbit, "regbit");
6611 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6612         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6613 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6614         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6615 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6616         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6617 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6618         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6619
6620 cmdline_parse_inst_t cmd_write_reg_bit = {
6621         .f = cmd_write_reg_bit_parsed,
6622         .data = NULL,
6623         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6624                 "0 <= bit_x <= 31",
6625         .tokens = {
6626                 (void *)&cmd_write_reg_bit_write,
6627                 (void *)&cmd_write_reg_bit_regbit,
6628                 (void *)&cmd_write_reg_bit_port_id,
6629                 (void *)&cmd_write_reg_bit_reg_off,
6630                 (void *)&cmd_write_reg_bit_bit_pos,
6631                 (void *)&cmd_write_reg_bit_value,
6632                 NULL,
6633         },
6634 };
6635
6636 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6637 struct cmd_read_rxd_txd_result {
6638         cmdline_fixed_string_t read;
6639         cmdline_fixed_string_t rxd_txd;
6640         uint8_t port_id;
6641         uint16_t queue_id;
6642         uint16_t desc_id;
6643 };
6644
6645 static void
6646 cmd_read_rxd_txd_parsed(void *parsed_result,
6647                         __attribute__((unused)) struct cmdline *cl,
6648                         __attribute__((unused)) void *data)
6649 {
6650         struct cmd_read_rxd_txd_result *res = parsed_result;
6651
6652         if (!strcmp(res->rxd_txd, "rxd"))
6653                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6654         else if (!strcmp(res->rxd_txd, "txd"))
6655                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6656 }
6657
6658 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6659         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6660 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6661         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6662                                  "rxd#txd");
6663 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6664         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6665 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6666         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6667 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6668         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6669
6670 cmdline_parse_inst_t cmd_read_rxd_txd = {
6671         .f = cmd_read_rxd_txd_parsed,
6672         .data = NULL,
6673         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6674         .tokens = {
6675                 (void *)&cmd_read_rxd_txd_read,
6676                 (void *)&cmd_read_rxd_txd_rxd_txd,
6677                 (void *)&cmd_read_rxd_txd_port_id,
6678                 (void *)&cmd_read_rxd_txd_queue_id,
6679                 (void *)&cmd_read_rxd_txd_desc_id,
6680                 NULL,
6681         },
6682 };
6683
6684 /* *** QUIT *** */
6685 struct cmd_quit_result {
6686         cmdline_fixed_string_t quit;
6687 };
6688
6689 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6690                             struct cmdline *cl,
6691                             __attribute__((unused)) void *data)
6692 {
6693         pmd_test_exit();
6694         cmdline_quit(cl);
6695 }
6696
6697 cmdline_parse_token_string_t cmd_quit_quit =
6698         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6699
6700 cmdline_parse_inst_t cmd_quit = {
6701         .f = cmd_quit_parsed,
6702         .data = NULL,
6703         .help_str = "quit: Exit application",
6704         .tokens = {
6705                 (void *)&cmd_quit_quit,
6706                 NULL,
6707         },
6708 };
6709
6710 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6711 struct cmd_mac_addr_result {
6712         cmdline_fixed_string_t mac_addr_cmd;
6713         cmdline_fixed_string_t what;
6714         uint8_t port_num;
6715         struct ether_addr address;
6716 };
6717
6718 static void cmd_mac_addr_parsed(void *parsed_result,
6719                 __attribute__((unused)) struct cmdline *cl,
6720                 __attribute__((unused)) void *data)
6721 {
6722         struct cmd_mac_addr_result *res = parsed_result;
6723         int ret;
6724
6725         if (strcmp(res->what, "add") == 0)
6726                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6727         else if (strcmp(res->what, "set") == 0)
6728                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6729                                                        &res->address);
6730         else
6731                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6732
6733         /* check the return value and print it if is < 0 */
6734         if(ret < 0)
6735                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6736
6737 }
6738
6739 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6740         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6741                                 "mac_addr");
6742 cmdline_parse_token_string_t cmd_mac_addr_what =
6743         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6744                                 "add#remove#set");
6745 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6746                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6747 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6748                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6749
6750 cmdline_parse_inst_t cmd_mac_addr = {
6751         .f = cmd_mac_addr_parsed,
6752         .data = (void *)0,
6753         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6754                         "Add/Remove/Set MAC address on port_id",
6755         .tokens = {
6756                 (void *)&cmd_mac_addr_cmd,
6757                 (void *)&cmd_mac_addr_what,
6758                 (void *)&cmd_mac_addr_portnum,
6759                 (void *)&cmd_mac_addr_addr,
6760                 NULL,
6761         },
6762 };
6763
6764
6765 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6766 struct cmd_set_qmap_result {
6767         cmdline_fixed_string_t set;
6768         cmdline_fixed_string_t qmap;
6769         cmdline_fixed_string_t what;
6770         uint8_t port_id;
6771         uint16_t queue_id;
6772         uint8_t map_value;
6773 };
6774
6775 static void
6776 cmd_set_qmap_parsed(void *parsed_result,
6777                        __attribute__((unused)) struct cmdline *cl,
6778                        __attribute__((unused)) void *data)
6779 {
6780         struct cmd_set_qmap_result *res = parsed_result;
6781         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6782
6783         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6784 }
6785
6786 cmdline_parse_token_string_t cmd_setqmap_set =
6787         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6788                                  set, "set");
6789 cmdline_parse_token_string_t cmd_setqmap_qmap =
6790         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6791                                  qmap, "stat_qmap");
6792 cmdline_parse_token_string_t cmd_setqmap_what =
6793         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6794                                  what, "tx#rx");
6795 cmdline_parse_token_num_t cmd_setqmap_portid =
6796         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6797                               port_id, UINT8);
6798 cmdline_parse_token_num_t cmd_setqmap_queueid =
6799         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6800                               queue_id, UINT16);
6801 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6802         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6803                               map_value, UINT8);
6804
6805 cmdline_parse_inst_t cmd_set_qmap = {
6806         .f = cmd_set_qmap_parsed,
6807         .data = NULL,
6808         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6809                 "Set statistics mapping value on tx|rx queue_id of port_id",
6810         .tokens = {
6811                 (void *)&cmd_setqmap_set,
6812                 (void *)&cmd_setqmap_qmap,
6813                 (void *)&cmd_setqmap_what,
6814                 (void *)&cmd_setqmap_portid,
6815                 (void *)&cmd_setqmap_queueid,
6816                 (void *)&cmd_setqmap_mapvalue,
6817                 NULL,
6818         },
6819 };
6820
6821 /* *** CONFIGURE UNICAST HASH TABLE *** */
6822 struct cmd_set_uc_hash_table {
6823         cmdline_fixed_string_t set;
6824         cmdline_fixed_string_t port;
6825         uint8_t port_id;
6826         cmdline_fixed_string_t what;
6827         struct ether_addr address;
6828         cmdline_fixed_string_t mode;
6829 };
6830
6831 static void
6832 cmd_set_uc_hash_parsed(void *parsed_result,
6833                        __attribute__((unused)) struct cmdline *cl,
6834                        __attribute__((unused)) void *data)
6835 {
6836         int ret=0;
6837         struct cmd_set_uc_hash_table *res = parsed_result;
6838
6839         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6840
6841         if (strcmp(res->what, "uta") == 0)
6842                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6843                                                 &res->address,(uint8_t)is_on);
6844         if (ret < 0)
6845                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6846
6847 }
6848
6849 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6850         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6851                                  set, "set");
6852 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6853         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6854                                  port, "port");
6855 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6856         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6857                               port_id, UINT8);
6858 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6859         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6860                                  what, "uta");
6861 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6862         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6863                                 address);
6864 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6865         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6866                                  mode, "on#off");
6867
6868 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6869         .f = cmd_set_uc_hash_parsed,
6870         .data = NULL,
6871         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6872         .tokens = {
6873                 (void *)&cmd_set_uc_hash_set,
6874                 (void *)&cmd_set_uc_hash_port,
6875                 (void *)&cmd_set_uc_hash_portid,
6876                 (void *)&cmd_set_uc_hash_what,
6877                 (void *)&cmd_set_uc_hash_mac,
6878                 (void *)&cmd_set_uc_hash_mode,
6879                 NULL,
6880         },
6881 };
6882
6883 struct cmd_set_uc_all_hash_table {
6884         cmdline_fixed_string_t set;
6885         cmdline_fixed_string_t port;
6886         uint8_t port_id;
6887         cmdline_fixed_string_t what;
6888         cmdline_fixed_string_t value;
6889         cmdline_fixed_string_t mode;
6890 };
6891
6892 static void
6893 cmd_set_uc_all_hash_parsed(void *parsed_result,
6894                        __attribute__((unused)) struct cmdline *cl,
6895                        __attribute__((unused)) void *data)
6896 {
6897         int ret=0;
6898         struct cmd_set_uc_all_hash_table *res = parsed_result;
6899
6900         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6901
6902         if ((strcmp(res->what, "uta") == 0) &&
6903                 (strcmp(res->value, "all") == 0))
6904                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6905         if (ret < 0)
6906                 printf("bad unicast hash table parameter,"
6907                         "return code = %d \n", ret);
6908 }
6909
6910 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6911         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6912                                  set, "set");
6913 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6914         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6915                                  port, "port");
6916 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6917         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6918                               port_id, UINT8);
6919 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6920         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6921                                  what, "uta");
6922 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6923         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6924                                 value,"all");
6925 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6926         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6927                                  mode, "on#off");
6928
6929 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6930         .f = cmd_set_uc_all_hash_parsed,
6931         .data = NULL,
6932         .help_str = "set port <port_id> uta all on|off",
6933         .tokens = {
6934                 (void *)&cmd_set_uc_all_hash_set,
6935                 (void *)&cmd_set_uc_all_hash_port,
6936                 (void *)&cmd_set_uc_all_hash_portid,
6937                 (void *)&cmd_set_uc_all_hash_what,
6938                 (void *)&cmd_set_uc_all_hash_value,
6939                 (void *)&cmd_set_uc_all_hash_mode,
6940                 NULL,
6941         },
6942 };
6943
6944 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6945 struct cmd_set_vf_macvlan_filter {
6946         cmdline_fixed_string_t set;
6947         cmdline_fixed_string_t port;
6948         uint8_t port_id;
6949         cmdline_fixed_string_t vf;
6950         uint8_t vf_id;
6951         struct ether_addr address;
6952         cmdline_fixed_string_t filter_type;
6953         cmdline_fixed_string_t mode;
6954 };
6955
6956 static void
6957 cmd_set_vf_macvlan_parsed(void *parsed_result,
6958                        __attribute__((unused)) struct cmdline *cl,
6959                        __attribute__((unused)) void *data)
6960 {
6961         int is_on, ret = 0;
6962         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6963         struct rte_eth_mac_filter filter;
6964
6965         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6966
6967         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6968
6969         /* set VF MAC filter */
6970         filter.is_vf = 1;
6971
6972         /* set VF ID */
6973         filter.dst_id = res->vf_id;
6974
6975         if (!strcmp(res->filter_type, "exact-mac"))
6976                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6977         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6978                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6979         else if (!strcmp(res->filter_type, "hashmac"))
6980                 filter.filter_type = RTE_MAC_HASH_MATCH;
6981         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6982                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6983
6984         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6985
6986         if (is_on)
6987                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6988                                         RTE_ETH_FILTER_MACVLAN,
6989                                         RTE_ETH_FILTER_ADD,
6990                                          &filter);
6991         else
6992                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6993                                         RTE_ETH_FILTER_MACVLAN,
6994                                         RTE_ETH_FILTER_DELETE,
6995                                         &filter);
6996
6997         if (ret < 0)
6998                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6999
7000 }
7001
7002 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7003         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7004                                  set, "set");
7005 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7006         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7007                                  port, "port");
7008 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7009         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7010                               port_id, UINT8);
7011 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7012         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7013                                  vf, "vf");
7014 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7015         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7016                                 vf_id, UINT8);
7017 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7018         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7019                                 address);
7020 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7021         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7022                                 filter_type, "exact-mac#exact-mac-vlan"
7023                                 "#hashmac#hashmac-vlan");
7024 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7025         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7026                                  mode, "on#off");
7027
7028 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7029         .f = cmd_set_vf_macvlan_parsed,
7030         .data = NULL,
7031         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7032                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7033                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7034                 "hash match rule: hash match of MAC and exact match of VLAN",
7035         .tokens = {
7036                 (void *)&cmd_set_vf_macvlan_set,
7037                 (void *)&cmd_set_vf_macvlan_port,
7038                 (void *)&cmd_set_vf_macvlan_portid,
7039                 (void *)&cmd_set_vf_macvlan_vf,
7040                 (void *)&cmd_set_vf_macvlan_vf_id,
7041                 (void *)&cmd_set_vf_macvlan_mac,
7042                 (void *)&cmd_set_vf_macvlan_filter_type,
7043                 (void *)&cmd_set_vf_macvlan_mode,
7044                 NULL,
7045         },
7046 };
7047
7048 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7049 struct cmd_set_vf_traffic {
7050         cmdline_fixed_string_t set;
7051         cmdline_fixed_string_t port;
7052         uint8_t port_id;
7053         cmdline_fixed_string_t vf;
7054         uint8_t vf_id;
7055         cmdline_fixed_string_t what;
7056         cmdline_fixed_string_t mode;
7057 };
7058
7059 static void
7060 cmd_set_vf_traffic_parsed(void *parsed_result,
7061                        __attribute__((unused)) struct cmdline *cl,
7062                        __attribute__((unused)) void *data)
7063 {
7064         struct cmd_set_vf_traffic *res = parsed_result;
7065         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7066         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7067
7068         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7069 }
7070
7071 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7072         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7073                                  set, "set");
7074 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7075         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7076                                  port, "port");
7077 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7078         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7079                               port_id, UINT8);
7080 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7081         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7082                                  vf, "vf");
7083 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7084         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7085                               vf_id, UINT8);
7086 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7087         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7088                                  what, "tx#rx");
7089 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7090         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7091                                  mode, "on#off");
7092
7093 cmdline_parse_inst_t cmd_set_vf_traffic = {
7094         .f = cmd_set_vf_traffic_parsed,
7095         .data = NULL,
7096         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7097         .tokens = {
7098                 (void *)&cmd_setvf_traffic_set,
7099                 (void *)&cmd_setvf_traffic_port,
7100                 (void *)&cmd_setvf_traffic_portid,
7101                 (void *)&cmd_setvf_traffic_vf,
7102                 (void *)&cmd_setvf_traffic_vfid,
7103                 (void *)&cmd_setvf_traffic_what,
7104                 (void *)&cmd_setvf_traffic_mode,
7105                 NULL,
7106         },
7107 };
7108
7109 /* *** CONFIGURE VF RECEIVE MODE *** */
7110 struct cmd_set_vf_rxmode {
7111         cmdline_fixed_string_t set;
7112         cmdline_fixed_string_t port;
7113         uint8_t port_id;
7114         cmdline_fixed_string_t vf;
7115         uint8_t vf_id;
7116         cmdline_fixed_string_t what;
7117         cmdline_fixed_string_t mode;
7118         cmdline_fixed_string_t on;
7119 };
7120
7121 static void
7122 cmd_set_vf_rxmode_parsed(void *parsed_result,
7123                        __attribute__((unused)) struct cmdline *cl,
7124                        __attribute__((unused)) void *data)
7125 {
7126         int ret = -ENOTSUP;
7127         uint16_t rx_mode = 0;
7128         struct cmd_set_vf_rxmode *res = parsed_result;
7129
7130         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7131         if (!strcmp(res->what,"rxmode")) {
7132                 if (!strcmp(res->mode, "AUPE"))
7133                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7134                 else if (!strcmp(res->mode, "ROPE"))
7135                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7136                 else if (!strcmp(res->mode, "BAM"))
7137                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7138                 else if (!strncmp(res->mode, "MPE",3))
7139                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7140         }
7141
7142 #ifdef RTE_LIBRTE_IXGBE_PMD
7143         if (ret == -ENOTSUP)
7144                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7145                                                   rx_mode, (uint8_t)is_on);
7146 #endif
7147 #ifdef RTE_LIBRTE_BNXT_PMD
7148         if (ret == -ENOTSUP)
7149                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7150                                                  rx_mode, (uint8_t)is_on);
7151 #endif
7152         if (ret < 0)
7153                 printf("bad VF receive mode parameter, return code = %d \n",
7154                 ret);
7155 }
7156
7157 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7158         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7159                                  set, "set");
7160 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7161         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7162                                  port, "port");
7163 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7164         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7165                               port_id, UINT8);
7166 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7167         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7168                                  vf, "vf");
7169 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7170         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7171                               vf_id, UINT8);
7172 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7173         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7174                                  what, "rxmode");
7175 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7176         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7177                                  mode, "AUPE#ROPE#BAM#MPE");
7178 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7179         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7180                                  on, "on#off");
7181
7182 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7183         .f = cmd_set_vf_rxmode_parsed,
7184         .data = NULL,
7185         .help_str = "set port <port_id> vf <vf_id> rxmode "
7186                 "AUPE|ROPE|BAM|MPE on|off",
7187         .tokens = {
7188                 (void *)&cmd_set_vf_rxmode_set,
7189                 (void *)&cmd_set_vf_rxmode_port,
7190                 (void *)&cmd_set_vf_rxmode_portid,
7191                 (void *)&cmd_set_vf_rxmode_vf,
7192                 (void *)&cmd_set_vf_rxmode_vfid,
7193                 (void *)&cmd_set_vf_rxmode_what,
7194                 (void *)&cmd_set_vf_rxmode_mode,
7195                 (void *)&cmd_set_vf_rxmode_on,
7196                 NULL,
7197         },
7198 };
7199
7200 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7201 struct cmd_vf_mac_addr_result {
7202         cmdline_fixed_string_t mac_addr_cmd;
7203         cmdline_fixed_string_t what;
7204         cmdline_fixed_string_t port;
7205         uint8_t port_num;
7206         cmdline_fixed_string_t vf;
7207         uint8_t vf_num;
7208         struct ether_addr address;
7209 };
7210
7211 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7212                 __attribute__((unused)) struct cmdline *cl,
7213                 __attribute__((unused)) void *data)
7214 {
7215         struct cmd_vf_mac_addr_result *res = parsed_result;
7216         int ret = 0;
7217
7218         if (strcmp(res->what, "add") == 0)
7219                 ret = rte_eth_dev_mac_addr_add(res->port_num,
7220                                         &res->address, res->vf_num);
7221         if(ret < 0)
7222                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7223
7224 }
7225
7226 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7227         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7228                                 mac_addr_cmd,"mac_addr");
7229 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7230         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7231                                 what,"add");
7232 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7233         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7234                                 port,"port");
7235 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7236         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7237                                 port_num, UINT8);
7238 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7239         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7240                                 vf,"vf");
7241 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7242         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7243                                 vf_num, UINT8);
7244 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7245         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7246                                 address);
7247
7248 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7249         .f = cmd_vf_mac_addr_parsed,
7250         .data = (void *)0,
7251         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7252                 "Add MAC address filtering for a VF on port_id",
7253         .tokens = {
7254                 (void *)&cmd_vf_mac_addr_cmd,
7255                 (void *)&cmd_vf_mac_addr_what,
7256                 (void *)&cmd_vf_mac_addr_port,
7257                 (void *)&cmd_vf_mac_addr_portnum,
7258                 (void *)&cmd_vf_mac_addr_vf,
7259                 (void *)&cmd_vf_mac_addr_vfnum,
7260                 (void *)&cmd_vf_mac_addr_addr,
7261                 NULL,
7262         },
7263 };
7264
7265 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7266 struct cmd_vf_rx_vlan_filter {
7267         cmdline_fixed_string_t rx_vlan;
7268         cmdline_fixed_string_t what;
7269         uint16_t vlan_id;
7270         cmdline_fixed_string_t port;
7271         uint8_t port_id;
7272         cmdline_fixed_string_t vf;
7273         uint64_t vf_mask;
7274 };
7275
7276 static void
7277 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7278                           __attribute__((unused)) struct cmdline *cl,
7279                           __attribute__((unused)) void *data)
7280 {
7281         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7282         int ret = -ENOTSUP;
7283
7284         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7285
7286 #ifdef RTE_LIBRTE_IXGBE_PMD
7287         if (ret == -ENOTSUP)
7288                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7289                                 res->vlan_id, res->vf_mask, is_add);
7290 #endif
7291 #ifdef RTE_LIBRTE_I40E_PMD
7292         if (ret == -ENOTSUP)
7293                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7294                                 res->vlan_id, res->vf_mask, is_add);
7295 #endif
7296 #ifdef RTE_LIBRTE_BNXT_PMD
7297         if (ret == -ENOTSUP)
7298                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7299                                 res->vlan_id, res->vf_mask, is_add);
7300 #endif
7301
7302         switch (ret) {
7303         case 0:
7304                 break;
7305         case -EINVAL:
7306                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7307                                 res->vlan_id, res->vf_mask);
7308                 break;
7309         case -ENODEV:
7310                 printf("invalid port_id %d\n", res->port_id);
7311                 break;
7312         case -ENOTSUP:
7313                 printf("function not implemented or supported\n");
7314                 break;
7315         default:
7316                 printf("programming error: (%s)\n", strerror(-ret));
7317         }
7318 }
7319
7320 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7321         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7322                                  rx_vlan, "rx_vlan");
7323 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7324         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7325                                  what, "add#rm");
7326 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7327         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7328                               vlan_id, UINT16);
7329 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7330         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7331                                  port, "port");
7332 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7333         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7334                               port_id, UINT8);
7335 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7336         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7337                                  vf, "vf");
7338 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7339         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7340                               vf_mask, UINT64);
7341
7342 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7343         .f = cmd_vf_rx_vlan_filter_parsed,
7344         .data = NULL,
7345         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7346                 "(vf_mask = hexadecimal VF mask)",
7347         .tokens = {
7348                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7349                 (void *)&cmd_vf_rx_vlan_filter_what,
7350                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7351                 (void *)&cmd_vf_rx_vlan_filter_port,
7352                 (void *)&cmd_vf_rx_vlan_filter_portid,
7353                 (void *)&cmd_vf_rx_vlan_filter_vf,
7354                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7355                 NULL,
7356         },
7357 };
7358
7359 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7360 struct cmd_queue_rate_limit_result {
7361         cmdline_fixed_string_t set;
7362         cmdline_fixed_string_t port;
7363         uint8_t port_num;
7364         cmdline_fixed_string_t queue;
7365         uint8_t queue_num;
7366         cmdline_fixed_string_t rate;
7367         uint16_t rate_num;
7368 };
7369
7370 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7371                 __attribute__((unused)) struct cmdline *cl,
7372                 __attribute__((unused)) void *data)
7373 {
7374         struct cmd_queue_rate_limit_result *res = parsed_result;
7375         int ret = 0;
7376
7377         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7378                 && (strcmp(res->queue, "queue") == 0)
7379                 && (strcmp(res->rate, "rate") == 0))
7380                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7381                                         res->rate_num);
7382         if (ret < 0)
7383                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7384
7385 }
7386
7387 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7388         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7389                                 set, "set");
7390 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7391         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7392                                 port, "port");
7393 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7394         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7395                                 port_num, UINT8);
7396 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7397         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7398                                 queue, "queue");
7399 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7400         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7401                                 queue_num, UINT8);
7402 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7403         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7404                                 rate, "rate");
7405 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7406         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7407                                 rate_num, UINT16);
7408
7409 cmdline_parse_inst_t cmd_queue_rate_limit = {
7410         .f = cmd_queue_rate_limit_parsed,
7411         .data = (void *)0,
7412         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7413                 "Set rate limit for a queue on port_id",
7414         .tokens = {
7415                 (void *)&cmd_queue_rate_limit_set,
7416                 (void *)&cmd_queue_rate_limit_port,
7417                 (void *)&cmd_queue_rate_limit_portnum,
7418                 (void *)&cmd_queue_rate_limit_queue,
7419                 (void *)&cmd_queue_rate_limit_queuenum,
7420                 (void *)&cmd_queue_rate_limit_rate,
7421                 (void *)&cmd_queue_rate_limit_ratenum,
7422                 NULL,
7423         },
7424 };
7425
7426 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7427 struct cmd_vf_rate_limit_result {
7428         cmdline_fixed_string_t set;
7429         cmdline_fixed_string_t port;
7430         uint8_t port_num;
7431         cmdline_fixed_string_t vf;
7432         uint8_t vf_num;
7433         cmdline_fixed_string_t rate;
7434         uint16_t rate_num;
7435         cmdline_fixed_string_t q_msk;
7436         uint64_t q_msk_val;
7437 };
7438
7439 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7440                 __attribute__((unused)) struct cmdline *cl,
7441                 __attribute__((unused)) void *data)
7442 {
7443         struct cmd_vf_rate_limit_result *res = parsed_result;
7444         int ret = 0;
7445
7446         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7447                 && (strcmp(res->vf, "vf") == 0)
7448                 && (strcmp(res->rate, "rate") == 0)
7449                 && (strcmp(res->q_msk, "queue_mask") == 0))
7450                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7451                                         res->rate_num, res->q_msk_val);
7452         if (ret < 0)
7453                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7454
7455 }
7456
7457 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7458         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7459                                 set, "set");
7460 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7461         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7462                                 port, "port");
7463 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7464         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7465                                 port_num, UINT8);
7466 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7467         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7468                                 vf, "vf");
7469 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7470         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7471                                 vf_num, UINT8);
7472 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7473         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7474                                 rate, "rate");
7475 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7476         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7477                                 rate_num, UINT16);
7478 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7479         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7480                                 q_msk, "queue_mask");
7481 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7482         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7483                                 q_msk_val, UINT64);
7484
7485 cmdline_parse_inst_t cmd_vf_rate_limit = {
7486         .f = cmd_vf_rate_limit_parsed,
7487         .data = (void *)0,
7488         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7489                 "queue_mask <queue_mask_value>: "
7490                 "Set rate limit for queues of VF on port_id",
7491         .tokens = {
7492                 (void *)&cmd_vf_rate_limit_set,
7493                 (void *)&cmd_vf_rate_limit_port,
7494                 (void *)&cmd_vf_rate_limit_portnum,
7495                 (void *)&cmd_vf_rate_limit_vf,
7496                 (void *)&cmd_vf_rate_limit_vfnum,
7497                 (void *)&cmd_vf_rate_limit_rate,
7498                 (void *)&cmd_vf_rate_limit_ratenum,
7499                 (void *)&cmd_vf_rate_limit_q_msk,
7500                 (void *)&cmd_vf_rate_limit_q_msk_val,
7501                 NULL,
7502         },
7503 };
7504
7505 /* *** ADD TUNNEL FILTER OF A PORT *** */
7506 struct cmd_tunnel_filter_result {
7507         cmdline_fixed_string_t cmd;
7508         cmdline_fixed_string_t what;
7509         uint8_t port_id;
7510         struct ether_addr outer_mac;
7511         struct ether_addr inner_mac;
7512         cmdline_ipaddr_t ip_value;
7513         uint16_t inner_vlan;
7514         cmdline_fixed_string_t tunnel_type;
7515         cmdline_fixed_string_t filter_type;
7516         uint32_t tenant_id;
7517         uint16_t queue_num;
7518 };
7519
7520 static void
7521 cmd_tunnel_filter_parsed(void *parsed_result,
7522                           __attribute__((unused)) struct cmdline *cl,
7523                           __attribute__((unused)) void *data)
7524 {
7525         struct cmd_tunnel_filter_result *res = parsed_result;
7526         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7527         int ret = 0;
7528
7529         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7530
7531         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7532         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7533         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7534
7535         if (res->ip_value.family == AF_INET) {
7536                 tunnel_filter_conf.ip_addr.ipv4_addr =
7537                         res->ip_value.addr.ipv4.s_addr;
7538                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7539         } else {
7540                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7541                         &(res->ip_value.addr.ipv6),
7542                         sizeof(struct in6_addr));
7543                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7544         }
7545
7546         if (!strcmp(res->filter_type, "imac-ivlan"))
7547                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7548         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7549                 tunnel_filter_conf.filter_type =
7550                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7551         else if (!strcmp(res->filter_type, "imac-tenid"))
7552                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7553         else if (!strcmp(res->filter_type, "imac"))
7554                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7555         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7556                 tunnel_filter_conf.filter_type =
7557                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7558         else if (!strcmp(res->filter_type, "oip"))
7559                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7560         else if (!strcmp(res->filter_type, "iip"))
7561                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7562         else {
7563                 printf("The filter type is not supported");
7564                 return;
7565         }
7566
7567         if (!strcmp(res->tunnel_type, "vxlan"))
7568                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7569         else if (!strcmp(res->tunnel_type, "nvgre"))
7570                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7571         else if (!strcmp(res->tunnel_type, "ipingre"))
7572                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7573         else {
7574                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7575                 return;
7576         }
7577
7578         tunnel_filter_conf.tenant_id = res->tenant_id;
7579         tunnel_filter_conf.queue_id = res->queue_num;
7580         if (!strcmp(res->what, "add"))
7581                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7582                                         RTE_ETH_FILTER_TUNNEL,
7583                                         RTE_ETH_FILTER_ADD,
7584                                         &tunnel_filter_conf);
7585         else
7586                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7587                                         RTE_ETH_FILTER_TUNNEL,
7588                                         RTE_ETH_FILTER_DELETE,
7589                                         &tunnel_filter_conf);
7590         if (ret < 0)
7591                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7592                                 strerror(-ret));
7593
7594 }
7595 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7596         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7597         cmd, "tunnel_filter");
7598 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7599         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7600         what, "add#rm");
7601 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7602         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7603         port_id, UINT8);
7604 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7605         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7606         outer_mac);
7607 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7608         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7609         inner_mac);
7610 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7611         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7612         inner_vlan, UINT16);
7613 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7614         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7615         ip_value);
7616 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7617         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7618         tunnel_type, "vxlan#nvgre#ipingre");
7619
7620 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7621         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7622         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7623                 "imac#omac-imac-tenid");
7624 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7625         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7626         tenant_id, UINT32);
7627 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7628         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7629         queue_num, UINT16);
7630
7631 cmdline_parse_inst_t cmd_tunnel_filter = {
7632         .f = cmd_tunnel_filter_parsed,
7633         .data = (void *)0,
7634         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7635                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7636                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7637                 "<queue_id>: Add/Rm tunnel filter of a port",
7638         .tokens = {
7639                 (void *)&cmd_tunnel_filter_cmd,
7640                 (void *)&cmd_tunnel_filter_what,
7641                 (void *)&cmd_tunnel_filter_port_id,
7642                 (void *)&cmd_tunnel_filter_outer_mac,
7643                 (void *)&cmd_tunnel_filter_inner_mac,
7644                 (void *)&cmd_tunnel_filter_ip_value,
7645                 (void *)&cmd_tunnel_filter_innner_vlan,
7646                 (void *)&cmd_tunnel_filter_tunnel_type,
7647                 (void *)&cmd_tunnel_filter_filter_type,
7648                 (void *)&cmd_tunnel_filter_tenant_id,
7649                 (void *)&cmd_tunnel_filter_queue_num,
7650                 NULL,
7651         },
7652 };
7653
7654 /* *** CONFIGURE TUNNEL UDP PORT *** */
7655 struct cmd_tunnel_udp_config {
7656         cmdline_fixed_string_t cmd;
7657         cmdline_fixed_string_t what;
7658         uint16_t udp_port;
7659         uint8_t port_id;
7660 };
7661
7662 static void
7663 cmd_tunnel_udp_config_parsed(void *parsed_result,
7664                           __attribute__((unused)) struct cmdline *cl,
7665                           __attribute__((unused)) void *data)
7666 {
7667         struct cmd_tunnel_udp_config *res = parsed_result;
7668         struct rte_eth_udp_tunnel tunnel_udp;
7669         int ret;
7670
7671         tunnel_udp.udp_port = res->udp_port;
7672
7673         if (!strcmp(res->cmd, "rx_vxlan_port"))
7674                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7675
7676         if (!strcmp(res->what, "add"))
7677                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7678                                                       &tunnel_udp);
7679         else
7680                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7681                                                          &tunnel_udp);
7682
7683         if (ret < 0)
7684                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7685 }
7686
7687 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7688         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7689                                 cmd, "rx_vxlan_port");
7690 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7691         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7692                                 what, "add#rm");
7693 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7694         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7695                                 udp_port, UINT16);
7696 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7697         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7698                                 port_id, UINT8);
7699
7700 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7701         .f = cmd_tunnel_udp_config_parsed,
7702         .data = (void *)0,
7703         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7704                 "Add/Remove a tunneling UDP port filter",
7705         .tokens = {
7706                 (void *)&cmd_tunnel_udp_config_cmd,
7707                 (void *)&cmd_tunnel_udp_config_what,
7708                 (void *)&cmd_tunnel_udp_config_udp_port,
7709                 (void *)&cmd_tunnel_udp_config_port_id,
7710                 NULL,
7711         },
7712 };
7713
7714 /* *** GLOBAL CONFIG *** */
7715 struct cmd_global_config_result {
7716         cmdline_fixed_string_t cmd;
7717         uint8_t port_id;
7718         cmdline_fixed_string_t cfg_type;
7719         uint8_t len;
7720 };
7721
7722 static void
7723 cmd_global_config_parsed(void *parsed_result,
7724                          __attribute__((unused)) struct cmdline *cl,
7725                          __attribute__((unused)) void *data)
7726 {
7727         struct cmd_global_config_result *res = parsed_result;
7728         struct rte_eth_global_cfg conf;
7729         int ret;
7730
7731         memset(&conf, 0, sizeof(conf));
7732         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7733         conf.cfg.gre_key_len = res->len;
7734         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7735                                       RTE_ETH_FILTER_SET, &conf);
7736         if (ret != 0)
7737                 printf("Global config error\n");
7738 }
7739
7740 cmdline_parse_token_string_t cmd_global_config_cmd =
7741         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7742                 "global_config");
7743 cmdline_parse_token_num_t cmd_global_config_port_id =
7744         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7745 cmdline_parse_token_string_t cmd_global_config_type =
7746         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7747                 cfg_type, "gre-key-len");
7748 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7749         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7750                 len, UINT8);
7751
7752 cmdline_parse_inst_t cmd_global_config = {
7753         .f = cmd_global_config_parsed,
7754         .data = (void *)NULL,
7755         .help_str = "global_config <port_id> gre-key-len <key_len>",
7756         .tokens = {
7757                 (void *)&cmd_global_config_cmd,
7758                 (void *)&cmd_global_config_port_id,
7759                 (void *)&cmd_global_config_type,
7760                 (void *)&cmd_global_config_gre_key_len,
7761                 NULL,
7762         },
7763 };
7764
7765 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7766 struct cmd_set_mirror_mask_result {
7767         cmdline_fixed_string_t set;
7768         cmdline_fixed_string_t port;
7769         uint8_t port_id;
7770         cmdline_fixed_string_t mirror;
7771         uint8_t rule_id;
7772         cmdline_fixed_string_t what;
7773         cmdline_fixed_string_t value;
7774         cmdline_fixed_string_t dstpool;
7775         uint8_t dstpool_id;
7776         cmdline_fixed_string_t on;
7777 };
7778
7779 cmdline_parse_token_string_t cmd_mirror_mask_set =
7780         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7781                                 set, "set");
7782 cmdline_parse_token_string_t cmd_mirror_mask_port =
7783         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7784                                 port, "port");
7785 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7786         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7787                                 port_id, UINT8);
7788 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7789         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7790                                 mirror, "mirror-rule");
7791 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7792         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7793                                 rule_id, UINT8);
7794 cmdline_parse_token_string_t cmd_mirror_mask_what =
7795         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7796                                 what, "pool-mirror-up#pool-mirror-down"
7797                                       "#vlan-mirror");
7798 cmdline_parse_token_string_t cmd_mirror_mask_value =
7799         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7800                                 value, NULL);
7801 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7802         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7803                                 dstpool, "dst-pool");
7804 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7805         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7806                                 dstpool_id, UINT8);
7807 cmdline_parse_token_string_t cmd_mirror_mask_on =
7808         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7809                                 on, "on#off");
7810
7811 static void
7812 cmd_set_mirror_mask_parsed(void *parsed_result,
7813                        __attribute__((unused)) struct cmdline *cl,
7814                        __attribute__((unused)) void *data)
7815 {
7816         int ret,nb_item,i;
7817         struct cmd_set_mirror_mask_result *res = parsed_result;
7818         struct rte_eth_mirror_conf mr_conf;
7819
7820         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7821
7822         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7823
7824         mr_conf.dst_pool = res->dstpool_id;
7825
7826         if (!strcmp(res->what, "pool-mirror-up")) {
7827                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7828                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7829         } else if (!strcmp(res->what, "pool-mirror-down")) {
7830                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7831                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7832         } else if (!strcmp(res->what, "vlan-mirror")) {
7833                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7834                 nb_item = parse_item_list(res->value, "vlan",
7835                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7836                 if (nb_item <= 0)
7837                         return;
7838
7839                 for (i = 0; i < nb_item; i++) {
7840                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7841                                 printf("Invalid vlan_id: must be < 4096\n");
7842                                 return;
7843                         }
7844
7845                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7846                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7847                 }
7848         }
7849
7850         if (!strcmp(res->on, "on"))
7851                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7852                                                 res->rule_id, 1);
7853         else
7854                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7855                                                 res->rule_id, 0);
7856         if (ret < 0)
7857                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7858 }
7859
7860 cmdline_parse_inst_t cmd_set_mirror_mask = {
7861                 .f = cmd_set_mirror_mask_parsed,
7862                 .data = NULL,
7863                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7864                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7865                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7866                 .tokens = {
7867                         (void *)&cmd_mirror_mask_set,
7868                         (void *)&cmd_mirror_mask_port,
7869                         (void *)&cmd_mirror_mask_portid,
7870                         (void *)&cmd_mirror_mask_mirror,
7871                         (void *)&cmd_mirror_mask_ruleid,
7872                         (void *)&cmd_mirror_mask_what,
7873                         (void *)&cmd_mirror_mask_value,
7874                         (void *)&cmd_mirror_mask_dstpool,
7875                         (void *)&cmd_mirror_mask_poolid,
7876                         (void *)&cmd_mirror_mask_on,
7877                         NULL,
7878                 },
7879 };
7880
7881 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7882 struct cmd_set_mirror_link_result {
7883         cmdline_fixed_string_t set;
7884         cmdline_fixed_string_t port;
7885         uint8_t port_id;
7886         cmdline_fixed_string_t mirror;
7887         uint8_t rule_id;
7888         cmdline_fixed_string_t what;
7889         cmdline_fixed_string_t dstpool;
7890         uint8_t dstpool_id;
7891         cmdline_fixed_string_t on;
7892 };
7893
7894 cmdline_parse_token_string_t cmd_mirror_link_set =
7895         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7896                                  set, "set");
7897 cmdline_parse_token_string_t cmd_mirror_link_port =
7898         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7899                                 port, "port");
7900 cmdline_parse_token_num_t cmd_mirror_link_portid =
7901         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7902                                 port_id, UINT8);
7903 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7904         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7905                                 mirror, "mirror-rule");
7906 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7907         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7908                             rule_id, UINT8);
7909 cmdline_parse_token_string_t cmd_mirror_link_what =
7910         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7911                                 what, "uplink-mirror#downlink-mirror");
7912 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7913         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7914                                 dstpool, "dst-pool");
7915 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7916         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7917                                 dstpool_id, UINT8);
7918 cmdline_parse_token_string_t cmd_mirror_link_on =
7919         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7920                                 on, "on#off");
7921
7922 static void
7923 cmd_set_mirror_link_parsed(void *parsed_result,
7924                        __attribute__((unused)) struct cmdline *cl,
7925                        __attribute__((unused)) void *data)
7926 {
7927         int ret;
7928         struct cmd_set_mirror_link_result *res = parsed_result;
7929         struct rte_eth_mirror_conf mr_conf;
7930
7931         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7932         if (!strcmp(res->what, "uplink-mirror"))
7933                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7934         else
7935                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7936
7937         mr_conf.dst_pool = res->dstpool_id;
7938
7939         if (!strcmp(res->on, "on"))
7940                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7941                                                 res->rule_id, 1);
7942         else
7943                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7944                                                 res->rule_id, 0);
7945
7946         /* check the return value and print it if is < 0 */
7947         if (ret < 0)
7948                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7949
7950 }
7951
7952 cmdline_parse_inst_t cmd_set_mirror_link = {
7953                 .f = cmd_set_mirror_link_parsed,
7954                 .data = NULL,
7955                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7956                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7957                 .tokens = {
7958                         (void *)&cmd_mirror_link_set,
7959                         (void *)&cmd_mirror_link_port,
7960                         (void *)&cmd_mirror_link_portid,
7961                         (void *)&cmd_mirror_link_mirror,
7962                         (void *)&cmd_mirror_link_ruleid,
7963                         (void *)&cmd_mirror_link_what,
7964                         (void *)&cmd_mirror_link_dstpool,
7965                         (void *)&cmd_mirror_link_poolid,
7966                         (void *)&cmd_mirror_link_on,
7967                         NULL,
7968                 },
7969 };
7970
7971 /* *** RESET VM MIRROR RULE *** */
7972 struct cmd_rm_mirror_rule_result {
7973         cmdline_fixed_string_t reset;
7974         cmdline_fixed_string_t port;
7975         uint8_t port_id;
7976         cmdline_fixed_string_t mirror;
7977         uint8_t rule_id;
7978 };
7979
7980 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7981         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7982                                  reset, "reset");
7983 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7984         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7985                                 port, "port");
7986 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7987         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7988                                 port_id, UINT8);
7989 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7990         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7991                                 mirror, "mirror-rule");
7992 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7993         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7994                                 rule_id, UINT8);
7995
7996 static void
7997 cmd_reset_mirror_rule_parsed(void *parsed_result,
7998                        __attribute__((unused)) struct cmdline *cl,
7999                        __attribute__((unused)) void *data)
8000 {
8001         int ret;
8002         struct cmd_set_mirror_link_result *res = parsed_result;
8003         /* check rule_id */
8004         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8005         if(ret < 0)
8006                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8007 }
8008
8009 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8010                 .f = cmd_reset_mirror_rule_parsed,
8011                 .data = NULL,
8012                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8013                 .tokens = {
8014                         (void *)&cmd_rm_mirror_rule_reset,
8015                         (void *)&cmd_rm_mirror_rule_port,
8016                         (void *)&cmd_rm_mirror_rule_portid,
8017                         (void *)&cmd_rm_mirror_rule_mirror,
8018                         (void *)&cmd_rm_mirror_rule_ruleid,
8019                         NULL,
8020                 },
8021 };
8022
8023 /* ******************************************************************************** */
8024
8025 struct cmd_dump_result {
8026         cmdline_fixed_string_t dump;
8027 };
8028
8029 static void
8030 dump_struct_sizes(void)
8031 {
8032 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8033         DUMP_SIZE(struct rte_mbuf);
8034         DUMP_SIZE(struct rte_mempool);
8035         DUMP_SIZE(struct rte_ring);
8036 #undef DUMP_SIZE
8037 }
8038
8039 static void cmd_dump_parsed(void *parsed_result,
8040                             __attribute__((unused)) struct cmdline *cl,
8041                             __attribute__((unused)) void *data)
8042 {
8043         struct cmd_dump_result *res = parsed_result;
8044
8045         if (!strcmp(res->dump, "dump_physmem"))
8046                 rte_dump_physmem_layout(stdout);
8047         else if (!strcmp(res->dump, "dump_memzone"))
8048                 rte_memzone_dump(stdout);
8049         else if (!strcmp(res->dump, "dump_struct_sizes"))
8050                 dump_struct_sizes();
8051         else if (!strcmp(res->dump, "dump_ring"))
8052                 rte_ring_list_dump(stdout);
8053         else if (!strcmp(res->dump, "dump_mempool"))
8054                 rte_mempool_list_dump(stdout);
8055         else if (!strcmp(res->dump, "dump_devargs"))
8056                 rte_eal_devargs_dump(stdout);
8057         else if (!strcmp(res->dump, "dump_log_types"))
8058                 rte_log_dump(stdout);
8059 }
8060
8061 cmdline_parse_token_string_t cmd_dump_dump =
8062         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8063                 "dump_physmem#"
8064                 "dump_memzone#"
8065                 "dump_struct_sizes#"
8066                 "dump_ring#"
8067                 "dump_mempool#"
8068                 "dump_devargs#"
8069                 "dump_log_types");
8070
8071 cmdline_parse_inst_t cmd_dump = {
8072         .f = cmd_dump_parsed,  /* function to call */
8073         .data = NULL,      /* 2nd arg of func */
8074         .help_str = "Dump status",
8075         .tokens = {        /* token list, NULL terminated */
8076                 (void *)&cmd_dump_dump,
8077                 NULL,
8078         },
8079 };
8080
8081 /* ******************************************************************************** */
8082
8083 struct cmd_dump_one_result {
8084         cmdline_fixed_string_t dump;
8085         cmdline_fixed_string_t name;
8086 };
8087
8088 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8089                                 __attribute__((unused)) void *data)
8090 {
8091         struct cmd_dump_one_result *res = parsed_result;
8092
8093         if (!strcmp(res->dump, "dump_ring")) {
8094                 struct rte_ring *r;
8095                 r = rte_ring_lookup(res->name);
8096                 if (r == NULL) {
8097                         cmdline_printf(cl, "Cannot find ring\n");
8098                         return;
8099                 }
8100                 rte_ring_dump(stdout, r);
8101         } else if (!strcmp(res->dump, "dump_mempool")) {
8102                 struct rte_mempool *mp;
8103                 mp = rte_mempool_lookup(res->name);
8104                 if (mp == NULL) {
8105                         cmdline_printf(cl, "Cannot find mempool\n");
8106                         return;
8107                 }
8108                 rte_mempool_dump(stdout, mp);
8109         }
8110 }
8111
8112 cmdline_parse_token_string_t cmd_dump_one_dump =
8113         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8114                                  "dump_ring#dump_mempool");
8115
8116 cmdline_parse_token_string_t cmd_dump_one_name =
8117         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8118
8119 cmdline_parse_inst_t cmd_dump_one = {
8120         .f = cmd_dump_one_parsed,  /* function to call */
8121         .data = NULL,      /* 2nd arg of func */
8122         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8123         .tokens = {        /* token list, NULL terminated */
8124                 (void *)&cmd_dump_one_dump,
8125                 (void *)&cmd_dump_one_name,
8126                 NULL,
8127         },
8128 };
8129
8130 /* *** Add/Del syn filter *** */
8131 struct cmd_syn_filter_result {
8132         cmdline_fixed_string_t filter;
8133         uint8_t port_id;
8134         cmdline_fixed_string_t ops;
8135         cmdline_fixed_string_t priority;
8136         cmdline_fixed_string_t high;
8137         cmdline_fixed_string_t queue;
8138         uint16_t queue_id;
8139 };
8140
8141 static void
8142 cmd_syn_filter_parsed(void *parsed_result,
8143                         __attribute__((unused)) struct cmdline *cl,
8144                         __attribute__((unused)) void *data)
8145 {
8146         struct cmd_syn_filter_result *res = parsed_result;
8147         struct rte_eth_syn_filter syn_filter;
8148         int ret = 0;
8149
8150         ret = rte_eth_dev_filter_supported(res->port_id,
8151                                         RTE_ETH_FILTER_SYN);
8152         if (ret < 0) {
8153                 printf("syn filter is not supported on port %u.\n",
8154                                 res->port_id);
8155                 return;
8156         }
8157
8158         memset(&syn_filter, 0, sizeof(syn_filter));
8159
8160         if (!strcmp(res->ops, "add")) {
8161                 if (!strcmp(res->high, "high"))
8162                         syn_filter.hig_pri = 1;
8163                 else
8164                         syn_filter.hig_pri = 0;
8165
8166                 syn_filter.queue = res->queue_id;
8167                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8168                                                 RTE_ETH_FILTER_SYN,
8169                                                 RTE_ETH_FILTER_ADD,
8170                                                 &syn_filter);
8171         } else
8172                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8173                                                 RTE_ETH_FILTER_SYN,
8174                                                 RTE_ETH_FILTER_DELETE,
8175                                                 &syn_filter);
8176
8177         if (ret < 0)
8178                 printf("syn filter programming error: (%s)\n",
8179                                 strerror(-ret));
8180 }
8181
8182 cmdline_parse_token_string_t cmd_syn_filter_filter =
8183         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8184         filter, "syn_filter");
8185 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8186         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8187         port_id, UINT8);
8188 cmdline_parse_token_string_t cmd_syn_filter_ops =
8189         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8190         ops, "add#del");
8191 cmdline_parse_token_string_t cmd_syn_filter_priority =
8192         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8193                                 priority, "priority");
8194 cmdline_parse_token_string_t cmd_syn_filter_high =
8195         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8196                                 high, "high#low");
8197 cmdline_parse_token_string_t cmd_syn_filter_queue =
8198         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8199                                 queue, "queue");
8200 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8201         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8202                                 queue_id, UINT16);
8203
8204 cmdline_parse_inst_t cmd_syn_filter = {
8205         .f = cmd_syn_filter_parsed,
8206         .data = NULL,
8207         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8208                 "<queue_id>: Add/Delete syn filter",
8209         .tokens = {
8210                 (void *)&cmd_syn_filter_filter,
8211                 (void *)&cmd_syn_filter_port_id,
8212                 (void *)&cmd_syn_filter_ops,
8213                 (void *)&cmd_syn_filter_priority,
8214                 (void *)&cmd_syn_filter_high,
8215                 (void *)&cmd_syn_filter_queue,
8216                 (void *)&cmd_syn_filter_queue_id,
8217                 NULL,
8218         },
8219 };
8220
8221 /* *** ADD/REMOVE A 2tuple FILTER *** */
8222 struct cmd_2tuple_filter_result {
8223         cmdline_fixed_string_t filter;
8224         uint8_t  port_id;
8225         cmdline_fixed_string_t ops;
8226         cmdline_fixed_string_t dst_port;
8227         uint16_t dst_port_value;
8228         cmdline_fixed_string_t protocol;
8229         uint8_t protocol_value;
8230         cmdline_fixed_string_t mask;
8231         uint8_t  mask_value;
8232         cmdline_fixed_string_t tcp_flags;
8233         uint8_t tcp_flags_value;
8234         cmdline_fixed_string_t priority;
8235         uint8_t  priority_value;
8236         cmdline_fixed_string_t queue;
8237         uint16_t  queue_id;
8238 };
8239
8240 static void
8241 cmd_2tuple_filter_parsed(void *parsed_result,
8242                         __attribute__((unused)) struct cmdline *cl,
8243                         __attribute__((unused)) void *data)
8244 {
8245         struct rte_eth_ntuple_filter filter;
8246         struct cmd_2tuple_filter_result *res = parsed_result;
8247         int ret = 0;
8248
8249         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8250         if (ret < 0) {
8251                 printf("ntuple filter is not supported on port %u.\n",
8252                         res->port_id);
8253                 return;
8254         }
8255
8256         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8257
8258         filter.flags = RTE_2TUPLE_FLAGS;
8259         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8260         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8261         filter.proto = res->protocol_value;
8262         filter.priority = res->priority_value;
8263         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8264                 printf("nonzero tcp_flags is only meaningful"
8265                         " when protocol is TCP.\n");
8266                 return;
8267         }
8268         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8269                 printf("invalid TCP flags.\n");
8270                 return;
8271         }
8272
8273         if (res->tcp_flags_value != 0) {
8274                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8275                 filter.tcp_flags = res->tcp_flags_value;
8276         }
8277
8278         /* need convert to big endian. */
8279         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8280         filter.queue = res->queue_id;
8281
8282         if (!strcmp(res->ops, "add"))
8283                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8284                                 RTE_ETH_FILTER_NTUPLE,
8285                                 RTE_ETH_FILTER_ADD,
8286                                 &filter);
8287         else
8288                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8289                                 RTE_ETH_FILTER_NTUPLE,
8290                                 RTE_ETH_FILTER_DELETE,
8291                                 &filter);
8292         if (ret < 0)
8293                 printf("2tuple filter programming error: (%s)\n",
8294                         strerror(-ret));
8295
8296 }
8297
8298 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8299         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8300                                  filter, "2tuple_filter");
8301 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8302         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8303                                 port_id, UINT8);
8304 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8305         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8306                                  ops, "add#del");
8307 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8308         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8309                                 dst_port, "dst_port");
8310 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8311         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8312                                 dst_port_value, UINT16);
8313 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8314         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8315                                 protocol, "protocol");
8316 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8317         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8318                                 protocol_value, UINT8);
8319 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8320         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8321                                 mask, "mask");
8322 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8323         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8324                                 mask_value, INT8);
8325 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8326         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8327                                 tcp_flags, "tcp_flags");
8328 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8329         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8330                                 tcp_flags_value, UINT8);
8331 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8332         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8333                                 priority, "priority");
8334 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8335         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8336                                 priority_value, UINT8);
8337 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8338         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8339                                 queue, "queue");
8340 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8341         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8342                                 queue_id, UINT16);
8343
8344 cmdline_parse_inst_t cmd_2tuple_filter = {
8345         .f = cmd_2tuple_filter_parsed,
8346         .data = NULL,
8347         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8348                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8349                 "<queue_id>: Add a 2tuple filter",
8350         .tokens = {
8351                 (void *)&cmd_2tuple_filter_filter,
8352                 (void *)&cmd_2tuple_filter_port_id,
8353                 (void *)&cmd_2tuple_filter_ops,
8354                 (void *)&cmd_2tuple_filter_dst_port,
8355                 (void *)&cmd_2tuple_filter_dst_port_value,
8356                 (void *)&cmd_2tuple_filter_protocol,
8357                 (void *)&cmd_2tuple_filter_protocol_value,
8358                 (void *)&cmd_2tuple_filter_mask,
8359                 (void *)&cmd_2tuple_filter_mask_value,
8360                 (void *)&cmd_2tuple_filter_tcp_flags,
8361                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8362                 (void *)&cmd_2tuple_filter_priority,
8363                 (void *)&cmd_2tuple_filter_priority_value,
8364                 (void *)&cmd_2tuple_filter_queue,
8365                 (void *)&cmd_2tuple_filter_queue_id,
8366                 NULL,
8367         },
8368 };
8369
8370 /* *** ADD/REMOVE A 5tuple FILTER *** */
8371 struct cmd_5tuple_filter_result {
8372         cmdline_fixed_string_t filter;
8373         uint8_t  port_id;
8374         cmdline_fixed_string_t ops;
8375         cmdline_fixed_string_t dst_ip;
8376         cmdline_ipaddr_t dst_ip_value;
8377         cmdline_fixed_string_t src_ip;
8378         cmdline_ipaddr_t src_ip_value;
8379         cmdline_fixed_string_t dst_port;
8380         uint16_t dst_port_value;
8381         cmdline_fixed_string_t src_port;
8382         uint16_t src_port_value;
8383         cmdline_fixed_string_t protocol;
8384         uint8_t protocol_value;
8385         cmdline_fixed_string_t mask;
8386         uint8_t  mask_value;
8387         cmdline_fixed_string_t tcp_flags;
8388         uint8_t tcp_flags_value;
8389         cmdline_fixed_string_t priority;
8390         uint8_t  priority_value;
8391         cmdline_fixed_string_t queue;
8392         uint16_t  queue_id;
8393 };
8394
8395 static void
8396 cmd_5tuple_filter_parsed(void *parsed_result,
8397                         __attribute__((unused)) struct cmdline *cl,
8398                         __attribute__((unused)) void *data)
8399 {
8400         struct rte_eth_ntuple_filter filter;
8401         struct cmd_5tuple_filter_result *res = parsed_result;
8402         int ret = 0;
8403
8404         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8405         if (ret < 0) {
8406                 printf("ntuple filter is not supported on port %u.\n",
8407                         res->port_id);
8408                 return;
8409         }
8410
8411         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8412
8413         filter.flags = RTE_5TUPLE_FLAGS;
8414         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8415         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8416         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8417         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8418         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8419         filter.proto = res->protocol_value;
8420         filter.priority = res->priority_value;
8421         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8422                 printf("nonzero tcp_flags is only meaningful"
8423                         " when protocol is TCP.\n");
8424                 return;
8425         }
8426         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8427                 printf("invalid TCP flags.\n");
8428                 return;
8429         }
8430
8431         if (res->tcp_flags_value != 0) {
8432                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8433                 filter.tcp_flags = res->tcp_flags_value;
8434         }
8435
8436         if (res->dst_ip_value.family == AF_INET)
8437                 /* no need to convert, already big endian. */
8438                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8439         else {
8440                 if (filter.dst_ip_mask == 0) {
8441                         printf("can not support ipv6 involved compare.\n");
8442                         return;
8443                 }
8444                 filter.dst_ip = 0;
8445         }
8446
8447         if (res->src_ip_value.family == AF_INET)
8448                 /* no need to convert, already big endian. */
8449                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8450         else {
8451                 if (filter.src_ip_mask == 0) {
8452                         printf("can not support ipv6 involved compare.\n");
8453                         return;
8454                 }
8455                 filter.src_ip = 0;
8456         }
8457         /* need convert to big endian. */
8458         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8459         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8460         filter.queue = res->queue_id;
8461
8462         if (!strcmp(res->ops, "add"))
8463                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8464                                 RTE_ETH_FILTER_NTUPLE,
8465                                 RTE_ETH_FILTER_ADD,
8466                                 &filter);
8467         else
8468                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8469                                 RTE_ETH_FILTER_NTUPLE,
8470                                 RTE_ETH_FILTER_DELETE,
8471                                 &filter);
8472         if (ret < 0)
8473                 printf("5tuple filter programming error: (%s)\n",
8474                         strerror(-ret));
8475 }
8476
8477 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8478         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8479                                  filter, "5tuple_filter");
8480 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8481         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8482                                 port_id, UINT8);
8483 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8484         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8485                                  ops, "add#del");
8486 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8487         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8488                                 dst_ip, "dst_ip");
8489 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8490         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8491                                 dst_ip_value);
8492 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8493         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8494                                 src_ip, "src_ip");
8495 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8496         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8497                                 src_ip_value);
8498 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8499         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8500                                 dst_port, "dst_port");
8501 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8502         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8503                                 dst_port_value, UINT16);
8504 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8505         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8506                                 src_port, "src_port");
8507 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8508         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8509                                 src_port_value, UINT16);
8510 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8511         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8512                                 protocol, "protocol");
8513 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8514         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8515                                 protocol_value, UINT8);
8516 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8517         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8518                                 mask, "mask");
8519 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8520         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8521                                 mask_value, INT8);
8522 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8523         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8524                                 tcp_flags, "tcp_flags");
8525 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8526         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8527                                 tcp_flags_value, UINT8);
8528 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8529         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8530                                 priority, "priority");
8531 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8532         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8533                                 priority_value, UINT8);
8534 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8535         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8536                                 queue, "queue");
8537 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8538         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8539                                 queue_id, UINT16);
8540
8541 cmdline_parse_inst_t cmd_5tuple_filter = {
8542         .f = cmd_5tuple_filter_parsed,
8543         .data = NULL,
8544         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8545                 "src_ip <value> dst_port <value> src_port <value> "
8546                 "protocol <value>  mask <value> tcp_flags <value> "
8547                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8548         .tokens = {
8549                 (void *)&cmd_5tuple_filter_filter,
8550                 (void *)&cmd_5tuple_filter_port_id,
8551                 (void *)&cmd_5tuple_filter_ops,
8552                 (void *)&cmd_5tuple_filter_dst_ip,
8553                 (void *)&cmd_5tuple_filter_dst_ip_value,
8554                 (void *)&cmd_5tuple_filter_src_ip,
8555                 (void *)&cmd_5tuple_filter_src_ip_value,
8556                 (void *)&cmd_5tuple_filter_dst_port,
8557                 (void *)&cmd_5tuple_filter_dst_port_value,
8558                 (void *)&cmd_5tuple_filter_src_port,
8559                 (void *)&cmd_5tuple_filter_src_port_value,
8560                 (void *)&cmd_5tuple_filter_protocol,
8561                 (void *)&cmd_5tuple_filter_protocol_value,
8562                 (void *)&cmd_5tuple_filter_mask,
8563                 (void *)&cmd_5tuple_filter_mask_value,
8564                 (void *)&cmd_5tuple_filter_tcp_flags,
8565                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8566                 (void *)&cmd_5tuple_filter_priority,
8567                 (void *)&cmd_5tuple_filter_priority_value,
8568                 (void *)&cmd_5tuple_filter_queue,
8569                 (void *)&cmd_5tuple_filter_queue_id,
8570                 NULL,
8571         },
8572 };
8573
8574 /* *** ADD/REMOVE A flex FILTER *** */
8575 struct cmd_flex_filter_result {
8576         cmdline_fixed_string_t filter;
8577         cmdline_fixed_string_t ops;
8578         uint8_t port_id;
8579         cmdline_fixed_string_t len;
8580         uint8_t len_value;
8581         cmdline_fixed_string_t bytes;
8582         cmdline_fixed_string_t bytes_value;
8583         cmdline_fixed_string_t mask;
8584         cmdline_fixed_string_t mask_value;
8585         cmdline_fixed_string_t priority;
8586         uint8_t priority_value;
8587         cmdline_fixed_string_t queue;
8588         uint16_t queue_id;
8589 };
8590
8591 static int xdigit2val(unsigned char c)
8592 {
8593         int val;
8594         if (isdigit(c))
8595                 val = c - '0';
8596         else if (isupper(c))
8597                 val = c - 'A' + 10;
8598         else
8599                 val = c - 'a' + 10;
8600         return val;
8601 }
8602
8603 static void
8604 cmd_flex_filter_parsed(void *parsed_result,
8605                           __attribute__((unused)) struct cmdline *cl,
8606                           __attribute__((unused)) void *data)
8607 {
8608         int ret = 0;
8609         struct rte_eth_flex_filter filter;
8610         struct cmd_flex_filter_result *res = parsed_result;
8611         char *bytes_ptr, *mask_ptr;
8612         uint16_t len, i, j = 0;
8613         char c;
8614         int val;
8615         uint8_t byte = 0;
8616
8617         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8618                 printf("the len exceed the max length 128\n");
8619                 return;
8620         }
8621         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8622         filter.len = res->len_value;
8623         filter.priority = res->priority_value;
8624         filter.queue = res->queue_id;
8625         bytes_ptr = res->bytes_value;
8626         mask_ptr = res->mask_value;
8627
8628          /* translate bytes string to array. */
8629         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8630                 (bytes_ptr[1] == 'X')))
8631                 bytes_ptr += 2;
8632         len = strnlen(bytes_ptr, res->len_value * 2);
8633         if (len == 0 || (len % 8 != 0)) {
8634                 printf("please check len and bytes input\n");
8635                 return;
8636         }
8637         for (i = 0; i < len; i++) {
8638                 c = bytes_ptr[i];
8639                 if (isxdigit(c) == 0) {
8640                         /* invalid characters. */
8641                         printf("invalid input\n");
8642                         return;
8643                 }
8644                 val = xdigit2val(c);
8645                 if (i % 2) {
8646                         byte |= val;
8647                         filter.bytes[j] = byte;
8648                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8649                         j++;
8650                         byte = 0;
8651                 } else
8652                         byte |= val << 4;
8653         }
8654         printf("\n");
8655          /* translate mask string to uint8_t array. */
8656         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8657                 (mask_ptr[1] == 'X')))
8658                 mask_ptr += 2;
8659         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8660         if (len == 0) {
8661                 printf("invalid input\n");
8662                 return;
8663         }
8664         j = 0;
8665         byte = 0;
8666         for (i = 0; i < len; i++) {
8667                 c = mask_ptr[i];
8668                 if (isxdigit(c) == 0) {
8669                         /* invalid characters. */
8670                         printf("invalid input\n");
8671                         return;
8672                 }
8673                 val = xdigit2val(c);
8674                 if (i % 2) {
8675                         byte |= val;
8676                         filter.mask[j] = byte;
8677                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8678                         j++;
8679                         byte = 0;
8680                 } else
8681                         byte |= val << 4;
8682         }
8683         printf("\n");
8684
8685         if (!strcmp(res->ops, "add"))
8686                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8687                                 RTE_ETH_FILTER_FLEXIBLE,
8688                                 RTE_ETH_FILTER_ADD,
8689                                 &filter);
8690         else
8691                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8692                                 RTE_ETH_FILTER_FLEXIBLE,
8693                                 RTE_ETH_FILTER_DELETE,
8694                                 &filter);
8695
8696         if (ret < 0)
8697                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8698 }
8699
8700 cmdline_parse_token_string_t cmd_flex_filter_filter =
8701         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8702                                 filter, "flex_filter");
8703 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8704         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8705                                 port_id, UINT8);
8706 cmdline_parse_token_string_t cmd_flex_filter_ops =
8707         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8708                                 ops, "add#del");
8709 cmdline_parse_token_string_t cmd_flex_filter_len =
8710         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8711                                 len, "len");
8712 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8713         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8714                                 len_value, UINT8);
8715 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8716         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8717                                 bytes, "bytes");
8718 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8719         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8720                                 bytes_value, NULL);
8721 cmdline_parse_token_string_t cmd_flex_filter_mask =
8722         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8723                                 mask, "mask");
8724 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8725         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8726                                 mask_value, NULL);
8727 cmdline_parse_token_string_t cmd_flex_filter_priority =
8728         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8729                                 priority, "priority");
8730 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8731         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8732                                 priority_value, UINT8);
8733 cmdline_parse_token_string_t cmd_flex_filter_queue =
8734         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8735                                 queue, "queue");
8736 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8737         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8738                                 queue_id, UINT16);
8739 cmdline_parse_inst_t cmd_flex_filter = {
8740         .f = cmd_flex_filter_parsed,
8741         .data = NULL,
8742         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8743                 "<value> mask <value> priority <value> queue <queue_id>: "
8744                 "Add/Del a flex filter",
8745         .tokens = {
8746                 (void *)&cmd_flex_filter_filter,
8747                 (void *)&cmd_flex_filter_port_id,
8748                 (void *)&cmd_flex_filter_ops,
8749                 (void *)&cmd_flex_filter_len,
8750                 (void *)&cmd_flex_filter_len_value,
8751                 (void *)&cmd_flex_filter_bytes,
8752                 (void *)&cmd_flex_filter_bytes_value,
8753                 (void *)&cmd_flex_filter_mask,
8754                 (void *)&cmd_flex_filter_mask_value,
8755                 (void *)&cmd_flex_filter_priority,
8756                 (void *)&cmd_flex_filter_priority_value,
8757                 (void *)&cmd_flex_filter_queue,
8758                 (void *)&cmd_flex_filter_queue_id,
8759                 NULL,
8760         },
8761 };
8762
8763 /* *** Filters Control *** */
8764
8765 /* *** deal with ethertype filter *** */
8766 struct cmd_ethertype_filter_result {
8767         cmdline_fixed_string_t filter;
8768         uint8_t port_id;
8769         cmdline_fixed_string_t ops;
8770         cmdline_fixed_string_t mac;
8771         struct ether_addr mac_addr;
8772         cmdline_fixed_string_t ethertype;
8773         uint16_t ethertype_value;
8774         cmdline_fixed_string_t drop;
8775         cmdline_fixed_string_t queue;
8776         uint16_t  queue_id;
8777 };
8778
8779 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8780         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8781                                  filter, "ethertype_filter");
8782 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8783         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8784                               port_id, UINT8);
8785 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8786         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8787                                  ops, "add#del");
8788 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8789         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8790                                  mac, "mac_addr#mac_ignr");
8791 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8792         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8793                                      mac_addr);
8794 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8795         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8796                                  ethertype, "ethertype");
8797 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8798         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8799                               ethertype_value, UINT16);
8800 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8801         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8802                                  drop, "drop#fwd");
8803 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8804         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8805                                  queue, "queue");
8806 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8807         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8808                               queue_id, UINT16);
8809
8810 static void
8811 cmd_ethertype_filter_parsed(void *parsed_result,
8812                           __attribute__((unused)) struct cmdline *cl,
8813                           __attribute__((unused)) void *data)
8814 {
8815         struct cmd_ethertype_filter_result *res = parsed_result;
8816         struct rte_eth_ethertype_filter filter;
8817         int ret = 0;
8818
8819         ret = rte_eth_dev_filter_supported(res->port_id,
8820                         RTE_ETH_FILTER_ETHERTYPE);
8821         if (ret < 0) {
8822                 printf("ethertype filter is not supported on port %u.\n",
8823                         res->port_id);
8824                 return;
8825         }
8826
8827         memset(&filter, 0, sizeof(filter));
8828         if (!strcmp(res->mac, "mac_addr")) {
8829                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8830                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8831                         sizeof(struct ether_addr));
8832         }
8833         if (!strcmp(res->drop, "drop"))
8834                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8835         filter.ether_type = res->ethertype_value;
8836         filter.queue = res->queue_id;
8837
8838         if (!strcmp(res->ops, "add"))
8839                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8840                                 RTE_ETH_FILTER_ETHERTYPE,
8841                                 RTE_ETH_FILTER_ADD,
8842                                 &filter);
8843         else
8844                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8845                                 RTE_ETH_FILTER_ETHERTYPE,
8846                                 RTE_ETH_FILTER_DELETE,
8847                                 &filter);
8848         if (ret < 0)
8849                 printf("ethertype filter programming error: (%s)\n",
8850                         strerror(-ret));
8851 }
8852
8853 cmdline_parse_inst_t cmd_ethertype_filter = {
8854         .f = cmd_ethertype_filter_parsed,
8855         .data = NULL,
8856         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8857                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8858                 "Add or delete an ethertype filter entry",
8859         .tokens = {
8860                 (void *)&cmd_ethertype_filter_filter,
8861                 (void *)&cmd_ethertype_filter_port_id,
8862                 (void *)&cmd_ethertype_filter_ops,
8863                 (void *)&cmd_ethertype_filter_mac,
8864                 (void *)&cmd_ethertype_filter_mac_addr,
8865                 (void *)&cmd_ethertype_filter_ethertype,
8866                 (void *)&cmd_ethertype_filter_ethertype_value,
8867                 (void *)&cmd_ethertype_filter_drop,
8868                 (void *)&cmd_ethertype_filter_queue,
8869                 (void *)&cmd_ethertype_filter_queue_id,
8870                 NULL,
8871         },
8872 };
8873
8874 /* *** deal with flow director filter *** */
8875 struct cmd_flow_director_result {
8876         cmdline_fixed_string_t flow_director_filter;
8877         uint8_t port_id;
8878         cmdline_fixed_string_t mode;
8879         cmdline_fixed_string_t mode_value;
8880         cmdline_fixed_string_t ops;
8881         cmdline_fixed_string_t flow;
8882         cmdline_fixed_string_t flow_type;
8883         cmdline_fixed_string_t ether;
8884         uint16_t ether_type;
8885         cmdline_fixed_string_t src;
8886         cmdline_ipaddr_t ip_src;
8887         uint16_t port_src;
8888         cmdline_fixed_string_t dst;
8889         cmdline_ipaddr_t ip_dst;
8890         uint16_t port_dst;
8891         cmdline_fixed_string_t verify_tag;
8892         uint32_t verify_tag_value;
8893         cmdline_ipaddr_t tos;
8894         uint8_t tos_value;
8895         cmdline_ipaddr_t proto;
8896         uint8_t proto_value;
8897         cmdline_ipaddr_t ttl;
8898         uint8_t ttl_value;
8899         cmdline_fixed_string_t vlan;
8900         uint16_t vlan_value;
8901         cmdline_fixed_string_t flexbytes;
8902         cmdline_fixed_string_t flexbytes_value;
8903         cmdline_fixed_string_t pf_vf;
8904         cmdline_fixed_string_t drop;
8905         cmdline_fixed_string_t queue;
8906         uint16_t  queue_id;
8907         cmdline_fixed_string_t fd_id;
8908         uint32_t  fd_id_value;
8909         cmdline_fixed_string_t mac;
8910         struct ether_addr mac_addr;
8911         cmdline_fixed_string_t tunnel;
8912         cmdline_fixed_string_t tunnel_type;
8913         cmdline_fixed_string_t tunnel_id;
8914         uint32_t tunnel_id_value;
8915 };
8916
8917 static inline int
8918 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8919 {
8920         char s[256];
8921         const char *p, *p0 = q_arg;
8922         char *end;
8923         unsigned long int_fld;
8924         char *str_fld[max_num];
8925         int i;
8926         unsigned size;
8927         int ret = -1;
8928
8929         p = strchr(p0, '(');
8930         if (p == NULL)
8931                 return -1;
8932         ++p;
8933         p0 = strchr(p, ')');
8934         if (p0 == NULL)
8935                 return -1;
8936
8937         size = p0 - p;
8938         if (size >= sizeof(s))
8939                 return -1;
8940
8941         snprintf(s, sizeof(s), "%.*s", size, p);
8942         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8943         if (ret < 0 || ret > max_num)
8944                 return -1;
8945         for (i = 0; i < ret; i++) {
8946                 errno = 0;
8947                 int_fld = strtoul(str_fld[i], &end, 0);
8948                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8949                         return -1;
8950                 flexbytes[i] = (uint8_t)int_fld;
8951         }
8952         return ret;
8953 }
8954
8955 static uint16_t
8956 str2flowtype(char *string)
8957 {
8958         uint8_t i = 0;
8959         static const struct {
8960                 char str[32];
8961                 uint16_t type;
8962         } flowtype_str[] = {
8963                 {"raw", RTE_ETH_FLOW_RAW},
8964                 {"ipv4", RTE_ETH_FLOW_IPV4},
8965                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8966                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8967                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8968                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8969                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8970                 {"ipv6", RTE_ETH_FLOW_IPV6},
8971                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8972                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8973                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8974                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8975                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8976                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8977         };
8978
8979         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8980                 if (!strcmp(flowtype_str[i].str, string))
8981                         return flowtype_str[i].type;
8982         }
8983         return RTE_ETH_FLOW_UNKNOWN;
8984 }
8985
8986 static enum rte_eth_fdir_tunnel_type
8987 str2fdir_tunneltype(char *string)
8988 {
8989         uint8_t i = 0;
8990
8991         static const struct {
8992                 char str[32];
8993                 enum rte_eth_fdir_tunnel_type type;
8994         } tunneltype_str[] = {
8995                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8996                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8997         };
8998
8999         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9000                 if (!strcmp(tunneltype_str[i].str, string))
9001                         return tunneltype_str[i].type;
9002         }
9003         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9004 }
9005
9006 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9007 do { \
9008         if ((ip_addr).family == AF_INET) \
9009                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9010         else { \
9011                 printf("invalid parameter.\n"); \
9012                 return; \
9013         } \
9014 } while (0)
9015
9016 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9017 do { \
9018         if ((ip_addr).family == AF_INET6) \
9019                 (void)rte_memcpy(&(ip), \
9020                                  &((ip_addr).addr.ipv6), \
9021                                  sizeof(struct in6_addr)); \
9022         else { \
9023                 printf("invalid parameter.\n"); \
9024                 return; \
9025         } \
9026 } while (0)
9027
9028 static void
9029 cmd_flow_director_filter_parsed(void *parsed_result,
9030                           __attribute__((unused)) struct cmdline *cl,
9031                           __attribute__((unused)) void *data)
9032 {
9033         struct cmd_flow_director_result *res = parsed_result;
9034         struct rte_eth_fdir_filter entry;
9035         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9036         char *end;
9037         unsigned long vf_id;
9038         int ret = 0;
9039
9040         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9041         if (ret < 0) {
9042                 printf("flow director is not supported on port %u.\n",
9043                         res->port_id);
9044                 return;
9045         }
9046         memset(flexbytes, 0, sizeof(flexbytes));
9047         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9048
9049         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9050                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9051                         printf("Please set mode to MAC-VLAN.\n");
9052                         return;
9053                 }
9054         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9055                 if (strcmp(res->mode_value, "Tunnel")) {
9056                         printf("Please set mode to Tunnel.\n");
9057                         return;
9058                 }
9059         } else {
9060                 if (strcmp(res->mode_value, "IP")) {
9061                         printf("Please set mode to IP.\n");
9062                         return;
9063                 }
9064                 entry.input.flow_type = str2flowtype(res->flow_type);
9065         }
9066
9067         ret = parse_flexbytes(res->flexbytes_value,
9068                                         flexbytes,
9069                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9070         if (ret < 0) {
9071                 printf("error: Cannot parse flexbytes input.\n");
9072                 return;
9073         }
9074
9075         switch (entry.input.flow_type) {
9076         case RTE_ETH_FLOW_FRAG_IPV4:
9077         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9078                 entry.input.flow.ip4_flow.proto = res->proto_value;
9079                 /* fall-through */
9080         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9081         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9082                 IPV4_ADDR_TO_UINT(res->ip_dst,
9083                         entry.input.flow.ip4_flow.dst_ip);
9084                 IPV4_ADDR_TO_UINT(res->ip_src,
9085                         entry.input.flow.ip4_flow.src_ip);
9086                 entry.input.flow.ip4_flow.tos = res->tos_value;
9087                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9088                 /* need convert to big endian. */
9089                 entry.input.flow.udp4_flow.dst_port =
9090                                 rte_cpu_to_be_16(res->port_dst);
9091                 entry.input.flow.udp4_flow.src_port =
9092                                 rte_cpu_to_be_16(res->port_src);
9093                 break;
9094         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9095                 IPV4_ADDR_TO_UINT(res->ip_dst,
9096                         entry.input.flow.sctp4_flow.ip.dst_ip);
9097                 IPV4_ADDR_TO_UINT(res->ip_src,
9098                         entry.input.flow.sctp4_flow.ip.src_ip);
9099                 entry.input.flow.ip4_flow.tos = res->tos_value;
9100                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9101                 /* need convert to big endian. */
9102                 entry.input.flow.sctp4_flow.dst_port =
9103                                 rte_cpu_to_be_16(res->port_dst);
9104                 entry.input.flow.sctp4_flow.src_port =
9105                                 rte_cpu_to_be_16(res->port_src);
9106                 entry.input.flow.sctp4_flow.verify_tag =
9107                                 rte_cpu_to_be_32(res->verify_tag_value);
9108                 break;
9109         case RTE_ETH_FLOW_FRAG_IPV6:
9110         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9111                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9112                 /* fall-through */
9113         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9114         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9115                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9116                         entry.input.flow.ipv6_flow.dst_ip);
9117                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9118                         entry.input.flow.ipv6_flow.src_ip);
9119                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9120                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9121                 /* need convert to big endian. */
9122                 entry.input.flow.udp6_flow.dst_port =
9123                                 rte_cpu_to_be_16(res->port_dst);
9124                 entry.input.flow.udp6_flow.src_port =
9125                                 rte_cpu_to_be_16(res->port_src);
9126                 break;
9127         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9128                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9129                         entry.input.flow.sctp6_flow.ip.dst_ip);
9130                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9131                         entry.input.flow.sctp6_flow.ip.src_ip);
9132                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9133                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9134                 /* need convert to big endian. */
9135                 entry.input.flow.sctp6_flow.dst_port =
9136                                 rte_cpu_to_be_16(res->port_dst);
9137                 entry.input.flow.sctp6_flow.src_port =
9138                                 rte_cpu_to_be_16(res->port_src);
9139                 entry.input.flow.sctp6_flow.verify_tag =
9140                                 rte_cpu_to_be_32(res->verify_tag_value);
9141                 break;
9142         case RTE_ETH_FLOW_L2_PAYLOAD:
9143                 entry.input.flow.l2_flow.ether_type =
9144                         rte_cpu_to_be_16(res->ether_type);
9145                 break;
9146         default:
9147                 break;
9148         }
9149
9150         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9151                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9152                                  &res->mac_addr,
9153                                  sizeof(struct ether_addr));
9154
9155         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9156                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9157                                  &res->mac_addr,
9158                                  sizeof(struct ether_addr));
9159                 entry.input.flow.tunnel_flow.tunnel_type =
9160                         str2fdir_tunneltype(res->tunnel_type);
9161                 entry.input.flow.tunnel_flow.tunnel_id =
9162                         rte_cpu_to_be_32(res->tunnel_id_value);
9163         }
9164
9165         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
9166                    flexbytes,
9167                    RTE_ETH_FDIR_MAX_FLEXLEN);
9168
9169         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9170
9171         entry.action.flex_off = 0;  /*use 0 by default */
9172         if (!strcmp(res->drop, "drop"))
9173                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9174         else
9175                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9176
9177         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9178             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9179                 if (!strcmp(res->pf_vf, "pf"))
9180                         entry.input.flow_ext.is_vf = 0;
9181                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9182                         struct rte_eth_dev_info dev_info;
9183
9184                         memset(&dev_info, 0, sizeof(dev_info));
9185                         rte_eth_dev_info_get(res->port_id, &dev_info);
9186                         errno = 0;
9187                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9188                         if (errno != 0 || *end != '\0' ||
9189                             vf_id >= dev_info.max_vfs) {
9190                                 printf("invalid parameter %s.\n", res->pf_vf);
9191                                 return;
9192                         }
9193                         entry.input.flow_ext.is_vf = 1;
9194                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9195                 } else {
9196                         printf("invalid parameter %s.\n", res->pf_vf);
9197                         return;
9198                 }
9199         }
9200
9201         /* set to report FD ID by default */
9202         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9203         entry.action.rx_queue = res->queue_id;
9204         entry.soft_id = res->fd_id_value;
9205         if (!strcmp(res->ops, "add"))
9206                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9207                                              RTE_ETH_FILTER_ADD, &entry);
9208         else if (!strcmp(res->ops, "del"))
9209                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9210                                              RTE_ETH_FILTER_DELETE, &entry);
9211         else
9212                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9213                                              RTE_ETH_FILTER_UPDATE, &entry);
9214         if (ret < 0)
9215                 printf("flow director programming error: (%s)\n",
9216                         strerror(-ret));
9217 }
9218
9219 cmdline_parse_token_string_t cmd_flow_director_filter =
9220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9221                                  flow_director_filter, "flow_director_filter");
9222 cmdline_parse_token_num_t cmd_flow_director_port_id =
9223         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9224                               port_id, UINT8);
9225 cmdline_parse_token_string_t cmd_flow_director_ops =
9226         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9227                                  ops, "add#del#update");
9228 cmdline_parse_token_string_t cmd_flow_director_flow =
9229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9230                                  flow, "flow");
9231 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9233                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9234                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9235 cmdline_parse_token_string_t cmd_flow_director_ether =
9236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9237                                  ether, "ether");
9238 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9239         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9240                               ether_type, UINT16);
9241 cmdline_parse_token_string_t cmd_flow_director_src =
9242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9243                                  src, "src");
9244 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9245         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9246                                  ip_src);
9247 cmdline_parse_token_num_t cmd_flow_director_port_src =
9248         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9249                               port_src, UINT16);
9250 cmdline_parse_token_string_t cmd_flow_director_dst =
9251         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9252                                  dst, "dst");
9253 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9254         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9255                                  ip_dst);
9256 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9258                               port_dst, UINT16);
9259 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9261                                   verify_tag, "verify_tag");
9262 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9263         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9264                               verify_tag_value, UINT32);
9265 cmdline_parse_token_string_t cmd_flow_director_tos =
9266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9267                                  tos, "tos");
9268 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9269         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9270                               tos_value, UINT8);
9271 cmdline_parse_token_string_t cmd_flow_director_proto =
9272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9273                                  proto, "proto");
9274 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9275         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9276                               proto_value, UINT8);
9277 cmdline_parse_token_string_t cmd_flow_director_ttl =
9278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9279                                  ttl, "ttl");
9280 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9282                               ttl_value, UINT8);
9283 cmdline_parse_token_string_t cmd_flow_director_vlan =
9284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9285                                  vlan, "vlan");
9286 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9287         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9288                               vlan_value, UINT16);
9289 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9290         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9291                                  flexbytes, "flexbytes");
9292 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9294                               flexbytes_value, NULL);
9295 cmdline_parse_token_string_t cmd_flow_director_drop =
9296         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9297                                  drop, "drop#fwd");
9298 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9299         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9300                               pf_vf, NULL);
9301 cmdline_parse_token_string_t cmd_flow_director_queue =
9302         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9303                                  queue, "queue");
9304 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9305         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9306                               queue_id, UINT16);
9307 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9308         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9309                                  fd_id, "fd_id");
9310 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9311         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9312                               fd_id_value, UINT32);
9313
9314 cmdline_parse_token_string_t cmd_flow_director_mode =
9315         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9316                                  mode, "mode");
9317 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9319                                  mode_value, "IP");
9320 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9321         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9322                                  mode_value, "MAC-VLAN");
9323 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9324         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9325                                  mode_value, "Tunnel");
9326 cmdline_parse_token_string_t cmd_flow_director_mac =
9327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9328                                  mac, "mac");
9329 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9330         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9331                                     mac_addr);
9332 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9334                                  tunnel, "tunnel");
9335 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9337                                  tunnel_type, "NVGRE#VxLAN");
9338 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9340                                  tunnel_id, "tunnel-id");
9341 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9342         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9343                               tunnel_id_value, UINT32);
9344
9345 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9346         .f = cmd_flow_director_filter_parsed,
9347         .data = NULL,
9348         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9349                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9350                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9351                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9352                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9353                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9354                 "fd_id <fd_id_value>: "
9355                 "Add or delete an ip flow director entry on NIC",
9356         .tokens = {
9357                 (void *)&cmd_flow_director_filter,
9358                 (void *)&cmd_flow_director_port_id,
9359                 (void *)&cmd_flow_director_mode,
9360                 (void *)&cmd_flow_director_mode_ip,
9361                 (void *)&cmd_flow_director_ops,
9362                 (void *)&cmd_flow_director_flow,
9363                 (void *)&cmd_flow_director_flow_type,
9364                 (void *)&cmd_flow_director_src,
9365                 (void *)&cmd_flow_director_ip_src,
9366                 (void *)&cmd_flow_director_dst,
9367                 (void *)&cmd_flow_director_ip_dst,
9368                 (void *)&cmd_flow_director_tos,
9369                 (void *)&cmd_flow_director_tos_value,
9370                 (void *)&cmd_flow_director_proto,
9371                 (void *)&cmd_flow_director_proto_value,
9372                 (void *)&cmd_flow_director_ttl,
9373                 (void *)&cmd_flow_director_ttl_value,
9374                 (void *)&cmd_flow_director_vlan,
9375                 (void *)&cmd_flow_director_vlan_value,
9376                 (void *)&cmd_flow_director_flexbytes,
9377                 (void *)&cmd_flow_director_flexbytes_value,
9378                 (void *)&cmd_flow_director_drop,
9379                 (void *)&cmd_flow_director_pf_vf,
9380                 (void *)&cmd_flow_director_queue,
9381                 (void *)&cmd_flow_director_queue_id,
9382                 (void *)&cmd_flow_director_fd_id,
9383                 (void *)&cmd_flow_director_fd_id_value,
9384                 NULL,
9385         },
9386 };
9387
9388 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9389         .f = cmd_flow_director_filter_parsed,
9390         .data = NULL,
9391         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9392                 "director entry on NIC",
9393         .tokens = {
9394                 (void *)&cmd_flow_director_filter,
9395                 (void *)&cmd_flow_director_port_id,
9396                 (void *)&cmd_flow_director_mode,
9397                 (void *)&cmd_flow_director_mode_ip,
9398                 (void *)&cmd_flow_director_ops,
9399                 (void *)&cmd_flow_director_flow,
9400                 (void *)&cmd_flow_director_flow_type,
9401                 (void *)&cmd_flow_director_src,
9402                 (void *)&cmd_flow_director_ip_src,
9403                 (void *)&cmd_flow_director_port_src,
9404                 (void *)&cmd_flow_director_dst,
9405                 (void *)&cmd_flow_director_ip_dst,
9406                 (void *)&cmd_flow_director_port_dst,
9407                 (void *)&cmd_flow_director_tos,
9408                 (void *)&cmd_flow_director_tos_value,
9409                 (void *)&cmd_flow_director_ttl,
9410                 (void *)&cmd_flow_director_ttl_value,
9411                 (void *)&cmd_flow_director_vlan,
9412                 (void *)&cmd_flow_director_vlan_value,
9413                 (void *)&cmd_flow_director_flexbytes,
9414                 (void *)&cmd_flow_director_flexbytes_value,
9415                 (void *)&cmd_flow_director_drop,
9416                 (void *)&cmd_flow_director_pf_vf,
9417                 (void *)&cmd_flow_director_queue,
9418                 (void *)&cmd_flow_director_queue_id,
9419                 (void *)&cmd_flow_director_fd_id,
9420                 (void *)&cmd_flow_director_fd_id_value,
9421                 NULL,
9422         },
9423 };
9424
9425 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9426         .f = cmd_flow_director_filter_parsed,
9427         .data = NULL,
9428         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9429                 "director entry on NIC",
9430         .tokens = {
9431                 (void *)&cmd_flow_director_filter,
9432                 (void *)&cmd_flow_director_port_id,
9433                 (void *)&cmd_flow_director_mode,
9434                 (void *)&cmd_flow_director_mode_ip,
9435                 (void *)&cmd_flow_director_ops,
9436                 (void *)&cmd_flow_director_flow,
9437                 (void *)&cmd_flow_director_flow_type,
9438                 (void *)&cmd_flow_director_src,
9439                 (void *)&cmd_flow_director_ip_src,
9440                 (void *)&cmd_flow_director_port_dst,
9441                 (void *)&cmd_flow_director_dst,
9442                 (void *)&cmd_flow_director_ip_dst,
9443                 (void *)&cmd_flow_director_port_dst,
9444                 (void *)&cmd_flow_director_verify_tag,
9445                 (void *)&cmd_flow_director_verify_tag_value,
9446                 (void *)&cmd_flow_director_tos,
9447                 (void *)&cmd_flow_director_tos_value,
9448                 (void *)&cmd_flow_director_ttl,
9449                 (void *)&cmd_flow_director_ttl_value,
9450                 (void *)&cmd_flow_director_vlan,
9451                 (void *)&cmd_flow_director_vlan_value,
9452                 (void *)&cmd_flow_director_flexbytes,
9453                 (void *)&cmd_flow_director_flexbytes_value,
9454                 (void *)&cmd_flow_director_drop,
9455                 (void *)&cmd_flow_director_pf_vf,
9456                 (void *)&cmd_flow_director_queue,
9457                 (void *)&cmd_flow_director_queue_id,
9458                 (void *)&cmd_flow_director_fd_id,
9459                 (void *)&cmd_flow_director_fd_id_value,
9460                 NULL,
9461         },
9462 };
9463
9464 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9465         .f = cmd_flow_director_filter_parsed,
9466         .data = NULL,
9467         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9468                 "director entry on NIC",
9469         .tokens = {
9470                 (void *)&cmd_flow_director_filter,
9471                 (void *)&cmd_flow_director_port_id,
9472                 (void *)&cmd_flow_director_mode,
9473                 (void *)&cmd_flow_director_mode_ip,
9474                 (void *)&cmd_flow_director_ops,
9475                 (void *)&cmd_flow_director_flow,
9476                 (void *)&cmd_flow_director_flow_type,
9477                 (void *)&cmd_flow_director_ether,
9478                 (void *)&cmd_flow_director_ether_type,
9479                 (void *)&cmd_flow_director_flexbytes,
9480                 (void *)&cmd_flow_director_flexbytes_value,
9481                 (void *)&cmd_flow_director_drop,
9482                 (void *)&cmd_flow_director_pf_vf,
9483                 (void *)&cmd_flow_director_queue,
9484                 (void *)&cmd_flow_director_queue_id,
9485                 (void *)&cmd_flow_director_fd_id,
9486                 (void *)&cmd_flow_director_fd_id_value,
9487                 NULL,
9488         },
9489 };
9490
9491 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9492         .f = cmd_flow_director_filter_parsed,
9493         .data = NULL,
9494         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9495                 "director entry on NIC",
9496         .tokens = {
9497                 (void *)&cmd_flow_director_filter,
9498                 (void *)&cmd_flow_director_port_id,
9499                 (void *)&cmd_flow_director_mode,
9500                 (void *)&cmd_flow_director_mode_mac_vlan,
9501                 (void *)&cmd_flow_director_ops,
9502                 (void *)&cmd_flow_director_mac,
9503                 (void *)&cmd_flow_director_mac_addr,
9504                 (void *)&cmd_flow_director_vlan,
9505                 (void *)&cmd_flow_director_vlan_value,
9506                 (void *)&cmd_flow_director_flexbytes,
9507                 (void *)&cmd_flow_director_flexbytes_value,
9508                 (void *)&cmd_flow_director_drop,
9509                 (void *)&cmd_flow_director_queue,
9510                 (void *)&cmd_flow_director_queue_id,
9511                 (void *)&cmd_flow_director_fd_id,
9512                 (void *)&cmd_flow_director_fd_id_value,
9513                 NULL,
9514         },
9515 };
9516
9517 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9518         .f = cmd_flow_director_filter_parsed,
9519         .data = NULL,
9520         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9521                 "director entry on NIC",
9522         .tokens = {
9523                 (void *)&cmd_flow_director_filter,
9524                 (void *)&cmd_flow_director_port_id,
9525                 (void *)&cmd_flow_director_mode,
9526                 (void *)&cmd_flow_director_mode_tunnel,
9527                 (void *)&cmd_flow_director_ops,
9528                 (void *)&cmd_flow_director_mac,
9529                 (void *)&cmd_flow_director_mac_addr,
9530                 (void *)&cmd_flow_director_vlan,
9531                 (void *)&cmd_flow_director_vlan_value,
9532                 (void *)&cmd_flow_director_tunnel,
9533                 (void *)&cmd_flow_director_tunnel_type,
9534                 (void *)&cmd_flow_director_tunnel_id,
9535                 (void *)&cmd_flow_director_tunnel_id_value,
9536                 (void *)&cmd_flow_director_flexbytes,
9537                 (void *)&cmd_flow_director_flexbytes_value,
9538                 (void *)&cmd_flow_director_drop,
9539                 (void *)&cmd_flow_director_queue,
9540                 (void *)&cmd_flow_director_queue_id,
9541                 (void *)&cmd_flow_director_fd_id,
9542                 (void *)&cmd_flow_director_fd_id_value,
9543                 NULL,
9544         },
9545 };
9546
9547 struct cmd_flush_flow_director_result {
9548         cmdline_fixed_string_t flush_flow_director;
9549         uint8_t port_id;
9550 };
9551
9552 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9553         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9554                                  flush_flow_director, "flush_flow_director");
9555 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9556         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9557                               port_id, UINT8);
9558
9559 static void
9560 cmd_flush_flow_director_parsed(void *parsed_result,
9561                           __attribute__((unused)) struct cmdline *cl,
9562                           __attribute__((unused)) void *data)
9563 {
9564         struct cmd_flow_director_result *res = parsed_result;
9565         int ret = 0;
9566
9567         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9568         if (ret < 0) {
9569                 printf("flow director is not supported on port %u.\n",
9570                         res->port_id);
9571                 return;
9572         }
9573
9574         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9575                         RTE_ETH_FILTER_FLUSH, NULL);
9576         if (ret < 0)
9577                 printf("flow director table flushing error: (%s)\n",
9578                         strerror(-ret));
9579 }
9580
9581 cmdline_parse_inst_t cmd_flush_flow_director = {
9582         .f = cmd_flush_flow_director_parsed,
9583         .data = NULL,
9584         .help_str = "flush_flow_director <port_id>: "
9585                 "Flush all flow director entries of a device on NIC",
9586         .tokens = {
9587                 (void *)&cmd_flush_flow_director_flush,
9588                 (void *)&cmd_flush_flow_director_port_id,
9589                 NULL,
9590         },
9591 };
9592
9593 /* *** deal with flow director mask *** */
9594 struct cmd_flow_director_mask_result {
9595         cmdline_fixed_string_t flow_director_mask;
9596         uint8_t port_id;
9597         cmdline_fixed_string_t mode;
9598         cmdline_fixed_string_t mode_value;
9599         cmdline_fixed_string_t vlan;
9600         uint16_t vlan_mask;
9601         cmdline_fixed_string_t src_mask;
9602         cmdline_ipaddr_t ipv4_src;
9603         cmdline_ipaddr_t ipv6_src;
9604         uint16_t port_src;
9605         cmdline_fixed_string_t dst_mask;
9606         cmdline_ipaddr_t ipv4_dst;
9607         cmdline_ipaddr_t ipv6_dst;
9608         uint16_t port_dst;
9609         cmdline_fixed_string_t mac;
9610         uint8_t mac_addr_byte_mask;
9611         cmdline_fixed_string_t tunnel_id;
9612         uint32_t tunnel_id_mask;
9613         cmdline_fixed_string_t tunnel_type;
9614         uint8_t tunnel_type_mask;
9615 };
9616
9617 static void
9618 cmd_flow_director_mask_parsed(void *parsed_result,
9619                           __attribute__((unused)) struct cmdline *cl,
9620                           __attribute__((unused)) void *data)
9621 {
9622         struct cmd_flow_director_mask_result *res = parsed_result;
9623         struct rte_eth_fdir_masks *mask;
9624         struct rte_port *port;
9625
9626         if (res->port_id > nb_ports) {
9627                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9628                 return;
9629         }
9630
9631         port = &ports[res->port_id];
9632         /** Check if the port is not started **/
9633         if (port->port_status != RTE_PORT_STOPPED) {
9634                 printf("Please stop port %d first\n", res->port_id);
9635                 return;
9636         }
9637
9638         mask = &port->dev_conf.fdir_conf.mask;
9639
9640         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9641                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9642                         printf("Please set mode to MAC-VLAN.\n");
9643                         return;
9644                 }
9645
9646                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9647         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9648                 if (strcmp(res->mode_value, "Tunnel")) {
9649                         printf("Please set mode to Tunnel.\n");
9650                         return;
9651                 }
9652
9653                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9654                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9655                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9656                 mask->tunnel_type_mask = res->tunnel_type_mask;
9657         } else {
9658                 if (strcmp(res->mode_value, "IP")) {
9659                         printf("Please set mode to IP.\n");
9660                         return;
9661                 }
9662
9663                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9664                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9665                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9666                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9667                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9668                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9669                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9670         }
9671
9672         cmd_reconfig_device_queue(res->port_id, 1, 1);
9673 }
9674
9675 cmdline_parse_token_string_t cmd_flow_director_mask =
9676         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9677                                  flow_director_mask, "flow_director_mask");
9678 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9679         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9680                               port_id, UINT8);
9681 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9682         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9683                                  vlan, "vlan");
9684 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9685         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9686                               vlan_mask, UINT16);
9687 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9688         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9689                                  src_mask, "src_mask");
9690 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9691         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9692                                  ipv4_src);
9693 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9694         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9695                                  ipv6_src);
9696 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9697         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9698                               port_src, UINT16);
9699 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9701                                  dst_mask, "dst_mask");
9702 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9703         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9704                                  ipv4_dst);
9705 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9706         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9707                                  ipv6_dst);
9708 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9709         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9710                               port_dst, UINT16);
9711
9712 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9713         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9714                                  mode, "mode");
9715 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9716         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9717                                  mode_value, "IP");
9718 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9719         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9720                                  mode_value, "MAC-VLAN");
9721 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9722         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9723                                  mode_value, "Tunnel");
9724 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9725         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9726                                  mac, "mac");
9727 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9728         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9729                               mac_addr_byte_mask, UINT8);
9730 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9731         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9732                                  tunnel_type, "tunnel-type");
9733 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9734         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9735                               tunnel_type_mask, UINT8);
9736 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9737         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9738                                  tunnel_id, "tunnel-id");
9739 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9740         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9741                               tunnel_id_mask, UINT32);
9742
9743 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9744         .f = cmd_flow_director_mask_parsed,
9745         .data = NULL,
9746         .help_str = "flow_director_mask ... : "
9747                 "Set IP mode flow director's mask on NIC",
9748         .tokens = {
9749                 (void *)&cmd_flow_director_mask,
9750                 (void *)&cmd_flow_director_mask_port_id,
9751                 (void *)&cmd_flow_director_mask_mode,
9752                 (void *)&cmd_flow_director_mask_mode_ip,
9753                 (void *)&cmd_flow_director_mask_vlan,
9754                 (void *)&cmd_flow_director_mask_vlan_value,
9755                 (void *)&cmd_flow_director_mask_src,
9756                 (void *)&cmd_flow_director_mask_ipv4_src,
9757                 (void *)&cmd_flow_director_mask_ipv6_src,
9758                 (void *)&cmd_flow_director_mask_port_src,
9759                 (void *)&cmd_flow_director_mask_dst,
9760                 (void *)&cmd_flow_director_mask_ipv4_dst,
9761                 (void *)&cmd_flow_director_mask_ipv6_dst,
9762                 (void *)&cmd_flow_director_mask_port_dst,
9763                 NULL,
9764         },
9765 };
9766
9767 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9768         .f = cmd_flow_director_mask_parsed,
9769         .data = NULL,
9770         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9771                 "flow director's mask on NIC",
9772         .tokens = {
9773                 (void *)&cmd_flow_director_mask,
9774                 (void *)&cmd_flow_director_mask_port_id,
9775                 (void *)&cmd_flow_director_mask_mode,
9776                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9777                 (void *)&cmd_flow_director_mask_vlan,
9778                 (void *)&cmd_flow_director_mask_vlan_value,
9779                 NULL,
9780         },
9781 };
9782
9783 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9784         .f = cmd_flow_director_mask_parsed,
9785         .data = NULL,
9786         .help_str = "flow_director_mask ... : Set tunnel mode "
9787                 "flow director's mask on NIC",
9788         .tokens = {
9789                 (void *)&cmd_flow_director_mask,
9790                 (void *)&cmd_flow_director_mask_port_id,
9791                 (void *)&cmd_flow_director_mask_mode,
9792                 (void *)&cmd_flow_director_mask_mode_tunnel,
9793                 (void *)&cmd_flow_director_mask_vlan,
9794                 (void *)&cmd_flow_director_mask_vlan_value,
9795                 (void *)&cmd_flow_director_mask_mac,
9796                 (void *)&cmd_flow_director_mask_mac_value,
9797                 (void *)&cmd_flow_director_mask_tunnel_type,
9798                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9799                 (void *)&cmd_flow_director_mask_tunnel_id,
9800                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9801                 NULL,
9802         },
9803 };
9804
9805 /* *** deal with flow director mask on flexible payload *** */
9806 struct cmd_flow_director_flex_mask_result {
9807         cmdline_fixed_string_t flow_director_flexmask;
9808         uint8_t port_id;
9809         cmdline_fixed_string_t flow;
9810         cmdline_fixed_string_t flow_type;
9811         cmdline_fixed_string_t mask;
9812 };
9813
9814 static void
9815 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9816                           __attribute__((unused)) struct cmdline *cl,
9817                           __attribute__((unused)) void *data)
9818 {
9819         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9820         struct rte_eth_fdir_info fdir_info;
9821         struct rte_eth_fdir_flex_mask flex_mask;
9822         struct rte_port *port;
9823         uint32_t flow_type_mask;
9824         uint16_t i;
9825         int ret;
9826
9827         if (res->port_id > nb_ports) {
9828                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9829                 return;
9830         }
9831
9832         port = &ports[res->port_id];
9833         /** Check if the port is not started **/
9834         if (port->port_status != RTE_PORT_STOPPED) {
9835                 printf("Please stop port %d first\n", res->port_id);
9836                 return;
9837         }
9838
9839         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9840         ret = parse_flexbytes(res->mask,
9841                         flex_mask.mask,
9842                         RTE_ETH_FDIR_MAX_FLEXLEN);
9843         if (ret < 0) {
9844                 printf("error: Cannot parse mask input.\n");
9845                 return;
9846         }
9847
9848         memset(&fdir_info, 0, sizeof(fdir_info));
9849         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9850                                 RTE_ETH_FILTER_INFO, &fdir_info);
9851         if (ret < 0) {
9852                 printf("Cannot get FDir filter info\n");
9853                 return;
9854         }
9855
9856         if (!strcmp(res->flow_type, "none")) {
9857                 /* means don't specify the flow type */
9858                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9859                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9860                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9861                                0, sizeof(struct rte_eth_fdir_flex_mask));
9862                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9863                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9864                                  &flex_mask,
9865                                  sizeof(struct rte_eth_fdir_flex_mask));
9866                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9867                 return;
9868         }
9869         flow_type_mask = fdir_info.flow_types_mask[0];
9870         if (!strcmp(res->flow_type, "all")) {
9871                 if (!flow_type_mask) {
9872                         printf("No flow type supported\n");
9873                         return;
9874                 }
9875                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9876                         if (flow_type_mask & (1 << i)) {
9877                                 flex_mask.flow_type = i;
9878                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9879                         }
9880                 }
9881                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9882                 return;
9883         }
9884         flex_mask.flow_type = str2flowtype(res->flow_type);
9885         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9886                 printf("Flow type %s not supported on port %d\n",
9887                                 res->flow_type, res->port_id);
9888                 return;
9889         }
9890         fdir_set_flex_mask(res->port_id, &flex_mask);
9891         cmd_reconfig_device_queue(res->port_id, 1, 1);
9892 }
9893
9894 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9896                                  flow_director_flexmask,
9897                                  "flow_director_flex_mask");
9898 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9899         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9900                               port_id, UINT8);
9901 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9902         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9903                                  flow, "flow");
9904 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9906                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9907                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9908 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9909         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9910                                  mask, NULL);
9911
9912 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9913         .f = cmd_flow_director_flex_mask_parsed,
9914         .data = NULL,
9915         .help_str = "flow_director_flex_mask ... : "
9916                 "Set flow director's flex mask on NIC",
9917         .tokens = {
9918                 (void *)&cmd_flow_director_flexmask,
9919                 (void *)&cmd_flow_director_flexmask_port_id,
9920                 (void *)&cmd_flow_director_flexmask_flow,
9921                 (void *)&cmd_flow_director_flexmask_flow_type,
9922                 (void *)&cmd_flow_director_flexmask_mask,
9923                 NULL,
9924         },
9925 };
9926
9927 /* *** deal with flow director flexible payload configuration *** */
9928 struct cmd_flow_director_flexpayload_result {
9929         cmdline_fixed_string_t flow_director_flexpayload;
9930         uint8_t port_id;
9931         cmdline_fixed_string_t payload_layer;
9932         cmdline_fixed_string_t payload_cfg;
9933 };
9934
9935 static inline int
9936 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9937 {
9938         char s[256];
9939         const char *p, *p0 = q_arg;
9940         char *end;
9941         unsigned long int_fld;
9942         char *str_fld[max_num];
9943         int i;
9944         unsigned size;
9945         int ret = -1;
9946
9947         p = strchr(p0, '(');
9948         if (p == NULL)
9949                 return -1;
9950         ++p;
9951         p0 = strchr(p, ')');
9952         if (p0 == NULL)
9953                 return -1;
9954
9955         size = p0 - p;
9956         if (size >= sizeof(s))
9957                 return -1;
9958
9959         snprintf(s, sizeof(s), "%.*s", size, p);
9960         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9961         if (ret < 0 || ret > max_num)
9962                 return -1;
9963         for (i = 0; i < ret; i++) {
9964                 errno = 0;
9965                 int_fld = strtoul(str_fld[i], &end, 0);
9966                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9967                         return -1;
9968                 offsets[i] = (uint16_t)int_fld;
9969         }
9970         return ret;
9971 }
9972
9973 static void
9974 cmd_flow_director_flxpld_parsed(void *parsed_result,
9975                           __attribute__((unused)) struct cmdline *cl,
9976                           __attribute__((unused)) void *data)
9977 {
9978         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9979         struct rte_eth_flex_payload_cfg flex_cfg;
9980         struct rte_port *port;
9981         int ret = 0;
9982
9983         if (res->port_id > nb_ports) {
9984                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9985                 return;
9986         }
9987
9988         port = &ports[res->port_id];
9989         /** Check if the port is not started **/
9990         if (port->port_status != RTE_PORT_STOPPED) {
9991                 printf("Please stop port %d first\n", res->port_id);
9992                 return;
9993         }
9994
9995         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9996
9997         if (!strcmp(res->payload_layer, "raw"))
9998                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9999         else if (!strcmp(res->payload_layer, "l2"))
10000                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10001         else if (!strcmp(res->payload_layer, "l3"))
10002                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10003         else if (!strcmp(res->payload_layer, "l4"))
10004                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10005
10006         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10007                             RTE_ETH_FDIR_MAX_FLEXLEN);
10008         if (ret < 0) {
10009                 printf("error: Cannot parse flex payload input.\n");
10010                 return;
10011         }
10012
10013         fdir_set_flex_payload(res->port_id, &flex_cfg);
10014         cmd_reconfig_device_queue(res->port_id, 1, 1);
10015 }
10016
10017 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10018         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10019                                  flow_director_flexpayload,
10020                                  "flow_director_flex_payload");
10021 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10022         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10023                               port_id, UINT8);
10024 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10025         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10026                                  payload_layer, "raw#l2#l3#l4");
10027 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10028         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10029                                  payload_cfg, NULL);
10030
10031 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10032         .f = cmd_flow_director_flxpld_parsed,
10033         .data = NULL,
10034         .help_str = "flow_director_flexpayload ... : "
10035                 "Set flow director's flex payload on NIC",
10036         .tokens = {
10037                 (void *)&cmd_flow_director_flexpayload,
10038                 (void *)&cmd_flow_director_flexpayload_port_id,
10039                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10040                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10041                 NULL,
10042         },
10043 };
10044
10045 /* Generic flow interface command. */
10046 extern cmdline_parse_inst_t cmd_flow;
10047
10048 /* *** Classification Filters Control *** */
10049 /* *** Get symmetric hash enable per port *** */
10050 struct cmd_get_sym_hash_ena_per_port_result {
10051         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10052         uint8_t port_id;
10053 };
10054
10055 static void
10056 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10057                                  __rte_unused struct cmdline *cl,
10058                                  __rte_unused void *data)
10059 {
10060         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10061         struct rte_eth_hash_filter_info info;
10062         int ret;
10063
10064         if (rte_eth_dev_filter_supported(res->port_id,
10065                                 RTE_ETH_FILTER_HASH) < 0) {
10066                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10067                                                         res->port_id);
10068                 return;
10069         }
10070
10071         memset(&info, 0, sizeof(info));
10072         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10073         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10074                                                 RTE_ETH_FILTER_GET, &info);
10075
10076         if (ret < 0) {
10077                 printf("Cannot get symmetric hash enable per port "
10078                                         "on port %u\n", res->port_id);
10079                 return;
10080         }
10081
10082         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10083                                 "enabled" : "disabled", res->port_id);
10084 }
10085
10086 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10087         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10088                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10089 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10090         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10091                 port_id, UINT8);
10092
10093 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10094         .f = cmd_get_sym_hash_per_port_parsed,
10095         .data = NULL,
10096         .help_str = "get_sym_hash_ena_per_port <port_id>",
10097         .tokens = {
10098                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10099                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10100                 NULL,
10101         },
10102 };
10103
10104 /* *** Set symmetric hash enable per port *** */
10105 struct cmd_set_sym_hash_ena_per_port_result {
10106         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10107         cmdline_fixed_string_t enable;
10108         uint8_t port_id;
10109 };
10110
10111 static void
10112 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10113                                  __rte_unused struct cmdline *cl,
10114                                  __rte_unused void *data)
10115 {
10116         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10117         struct rte_eth_hash_filter_info info;
10118         int ret;
10119
10120         if (rte_eth_dev_filter_supported(res->port_id,
10121                                 RTE_ETH_FILTER_HASH) < 0) {
10122                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10123                                                         res->port_id);
10124                 return;
10125         }
10126
10127         memset(&info, 0, sizeof(info));
10128         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10129         if (!strcmp(res->enable, "enable"))
10130                 info.info.enable = 1;
10131         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10132                                         RTE_ETH_FILTER_SET, &info);
10133         if (ret < 0) {
10134                 printf("Cannot set symmetric hash enable per port on "
10135                                         "port %u\n", res->port_id);
10136                 return;
10137         }
10138         printf("Symmetric hash has been set to %s on port %u\n",
10139                                         res->enable, res->port_id);
10140 }
10141
10142 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10143         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10144                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10145 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10146         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10147                 port_id, UINT8);
10148 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10149         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10150                 enable, "enable#disable");
10151
10152 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10153         .f = cmd_set_sym_hash_per_port_parsed,
10154         .data = NULL,
10155         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10156         .tokens = {
10157                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10158                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10159                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10160                 NULL,
10161         },
10162 };
10163
10164 /* Get global config of hash function */
10165 struct cmd_get_hash_global_config_result {
10166         cmdline_fixed_string_t get_hash_global_config;
10167         uint8_t port_id;
10168 };
10169
10170 static char *
10171 flowtype_to_str(uint16_t ftype)
10172 {
10173         uint16_t i;
10174         static struct {
10175                 char str[16];
10176                 uint16_t ftype;
10177         } ftype_table[] = {
10178                 {"ipv4", RTE_ETH_FLOW_IPV4},
10179                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10180                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10181                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10182                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10183                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10184                 {"ipv6", RTE_ETH_FLOW_IPV6},
10185                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10186                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10187                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10188                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10189                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10190                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10191                 {"port", RTE_ETH_FLOW_PORT},
10192                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10193                 {"geneve", RTE_ETH_FLOW_GENEVE},
10194                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10195         };
10196
10197         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10198                 if (ftype_table[i].ftype == ftype)
10199                         return ftype_table[i].str;
10200         }
10201
10202         return NULL;
10203 }
10204
10205 static void
10206 cmd_get_hash_global_config_parsed(void *parsed_result,
10207                                   __rte_unused struct cmdline *cl,
10208                                   __rte_unused void *data)
10209 {
10210         struct cmd_get_hash_global_config_result *res = parsed_result;
10211         struct rte_eth_hash_filter_info info;
10212         uint32_t idx, offset;
10213         uint16_t i;
10214         char *str;
10215         int ret;
10216
10217         if (rte_eth_dev_filter_supported(res->port_id,
10218                         RTE_ETH_FILTER_HASH) < 0) {
10219                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10220                                                         res->port_id);
10221                 return;
10222         }
10223
10224         memset(&info, 0, sizeof(info));
10225         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10226         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10227                                         RTE_ETH_FILTER_GET, &info);
10228         if (ret < 0) {
10229                 printf("Cannot get hash global configurations by port %d\n",
10230                                                         res->port_id);
10231                 return;
10232         }
10233
10234         switch (info.info.global_conf.hash_func) {
10235         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10236                 printf("Hash function is Toeplitz\n");
10237                 break;
10238         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10239                 printf("Hash function is Simple XOR\n");
10240                 break;
10241         default:
10242                 printf("Unknown hash function\n");
10243                 break;
10244         }
10245
10246         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10247                 idx = i / UINT32_BIT;
10248                 offset = i % UINT32_BIT;
10249                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10250                                                 (1UL << offset)))
10251                         continue;
10252                 str = flowtype_to_str(i);
10253                 if (!str)
10254                         continue;
10255                 printf("Symmetric hash is %s globally for flow type %s "
10256                                                         "by port %d\n",
10257                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10258                         (1UL << offset)) ? "enabled" : "disabled"), str,
10259                                                         res->port_id);
10260         }
10261 }
10262
10263 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10264         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10265                 get_hash_global_config, "get_hash_global_config");
10266 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10267         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10268                 port_id, UINT8);
10269
10270 cmdline_parse_inst_t cmd_get_hash_global_config = {
10271         .f = cmd_get_hash_global_config_parsed,
10272         .data = NULL,
10273         .help_str = "get_hash_global_config <port_id>",
10274         .tokens = {
10275                 (void *)&cmd_get_hash_global_config_all,
10276                 (void *)&cmd_get_hash_global_config_port_id,
10277                 NULL,
10278         },
10279 };
10280
10281 /* Set global config of hash function */
10282 struct cmd_set_hash_global_config_result {
10283         cmdline_fixed_string_t set_hash_global_config;
10284         uint8_t port_id;
10285         cmdline_fixed_string_t hash_func;
10286         cmdline_fixed_string_t flow_type;
10287         cmdline_fixed_string_t enable;
10288 };
10289
10290 static void
10291 cmd_set_hash_global_config_parsed(void *parsed_result,
10292                                   __rte_unused struct cmdline *cl,
10293                                   __rte_unused void *data)
10294 {
10295         struct cmd_set_hash_global_config_result *res = parsed_result;
10296         struct rte_eth_hash_filter_info info;
10297         uint32_t ftype, idx, offset;
10298         int ret;
10299
10300         if (rte_eth_dev_filter_supported(res->port_id,
10301                                 RTE_ETH_FILTER_HASH) < 0) {
10302                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10303                                                         res->port_id);
10304                 return;
10305         }
10306         memset(&info, 0, sizeof(info));
10307         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10308         if (!strcmp(res->hash_func, "toeplitz"))
10309                 info.info.global_conf.hash_func =
10310                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10311         else if (!strcmp(res->hash_func, "simple_xor"))
10312                 info.info.global_conf.hash_func =
10313                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10314         else if (!strcmp(res->hash_func, "default"))
10315                 info.info.global_conf.hash_func =
10316                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10317
10318         ftype = str2flowtype(res->flow_type);
10319         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10320         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10321         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10322         if (!strcmp(res->enable, "enable"))
10323                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10324                                                 (1UL << offset);
10325         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10326                                         RTE_ETH_FILTER_SET, &info);
10327         if (ret < 0)
10328                 printf("Cannot set global hash configurations by port %d\n",
10329                                                         res->port_id);
10330         else
10331                 printf("Global hash configurations have been set "
10332                         "succcessfully by port %d\n", res->port_id);
10333 }
10334
10335 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10336         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10337                 set_hash_global_config, "set_hash_global_config");
10338 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10339         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10340                 port_id, UINT8);
10341 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10342         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10343                 hash_func, "toeplitz#simple_xor#default");
10344 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10345         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10346                 flow_type,
10347                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10348                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10349 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10350         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10351                 enable, "enable#disable");
10352
10353 cmdline_parse_inst_t cmd_set_hash_global_config = {
10354         .f = cmd_set_hash_global_config_parsed,
10355         .data = NULL,
10356         .help_str = "set_hash_global_config <port_id> "
10357                 "toeplitz|simple_xor|default "
10358                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10359                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10360                 "l2_payload enable|disable",
10361         .tokens = {
10362                 (void *)&cmd_set_hash_global_config_all,
10363                 (void *)&cmd_set_hash_global_config_port_id,
10364                 (void *)&cmd_set_hash_global_config_hash_func,
10365                 (void *)&cmd_set_hash_global_config_flow_type,
10366                 (void *)&cmd_set_hash_global_config_enable,
10367                 NULL,
10368         },
10369 };
10370
10371 /* Set hash input set */
10372 struct cmd_set_hash_input_set_result {
10373         cmdline_fixed_string_t set_hash_input_set;
10374         uint8_t port_id;
10375         cmdline_fixed_string_t flow_type;
10376         cmdline_fixed_string_t inset_field;
10377         cmdline_fixed_string_t select;
10378 };
10379
10380 static enum rte_eth_input_set_field
10381 str2inset(char *string)
10382 {
10383         uint16_t i;
10384
10385         static const struct {
10386                 char str[32];
10387                 enum rte_eth_input_set_field inset;
10388         } inset_table[] = {
10389                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10390                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10391                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10392                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10393                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10394                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10395                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10396                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10397                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10398                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10399                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10400                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10401                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10402                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10403                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10404                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10405                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10406                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10407                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10408                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10409                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10410                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10411                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10412                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10413                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10414                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10415                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10416                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10417                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10418                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10419                 {"none", RTE_ETH_INPUT_SET_NONE},
10420         };
10421
10422         for (i = 0; i < RTE_DIM(inset_table); i++) {
10423                 if (!strcmp(string, inset_table[i].str))
10424                         return inset_table[i].inset;
10425         }
10426
10427         return RTE_ETH_INPUT_SET_UNKNOWN;
10428 }
10429
10430 static void
10431 cmd_set_hash_input_set_parsed(void *parsed_result,
10432                               __rte_unused struct cmdline *cl,
10433                               __rte_unused void *data)
10434 {
10435         struct cmd_set_hash_input_set_result *res = parsed_result;
10436         struct rte_eth_hash_filter_info info;
10437
10438         memset(&info, 0, sizeof(info));
10439         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10440         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10441         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10442         info.info.input_set_conf.inset_size = 1;
10443         if (!strcmp(res->select, "select"))
10444                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10445         else if (!strcmp(res->select, "add"))
10446                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10447         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10448                                 RTE_ETH_FILTER_SET, &info);
10449 }
10450
10451 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10452         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10453                 set_hash_input_set, "set_hash_input_set");
10454 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10455         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10456                 port_id, UINT8);
10457 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10458         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10459                 flow_type,
10460                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10461                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10462 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10463         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10464                 inset_field,
10465                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10466                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10467                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10468                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10469                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10470                 "fld-8th#none");
10471 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10472         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10473                 select, "select#add");
10474
10475 cmdline_parse_inst_t cmd_set_hash_input_set = {
10476         .f = cmd_set_hash_input_set_parsed,
10477         .data = NULL,
10478         .help_str = "set_hash_input_set <port_id> "
10479         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10480         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10481         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10482         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10483         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10484         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10485         "fld-7th|fld-8th|none select|add",
10486         .tokens = {
10487                 (void *)&cmd_set_hash_input_set_cmd,
10488                 (void *)&cmd_set_hash_input_set_port_id,
10489                 (void *)&cmd_set_hash_input_set_flow_type,
10490                 (void *)&cmd_set_hash_input_set_field,
10491                 (void *)&cmd_set_hash_input_set_select,
10492                 NULL,
10493         },
10494 };
10495
10496 /* Set flow director input set */
10497 struct cmd_set_fdir_input_set_result {
10498         cmdline_fixed_string_t set_fdir_input_set;
10499         uint8_t port_id;
10500         cmdline_fixed_string_t flow_type;
10501         cmdline_fixed_string_t inset_field;
10502         cmdline_fixed_string_t select;
10503 };
10504
10505 static void
10506 cmd_set_fdir_input_set_parsed(void *parsed_result,
10507         __rte_unused struct cmdline *cl,
10508         __rte_unused void *data)
10509 {
10510         struct cmd_set_fdir_input_set_result *res = parsed_result;
10511         struct rte_eth_fdir_filter_info info;
10512
10513         memset(&info, 0, sizeof(info));
10514         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10515         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10516         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10517         info.info.input_set_conf.inset_size = 1;
10518         if (!strcmp(res->select, "select"))
10519                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10520         else if (!strcmp(res->select, "add"))
10521                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10522         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10523                 RTE_ETH_FILTER_SET, &info);
10524 }
10525
10526 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10527         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10528         set_fdir_input_set, "set_fdir_input_set");
10529 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10530         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10531         port_id, UINT8);
10532 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10533         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10534         flow_type,
10535         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10536         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10537 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10538         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10539         inset_field,
10540         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10541         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10542         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10543         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10544         "sctp-veri-tag#none");
10545 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10546         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10547         select, "select#add");
10548
10549 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10550         .f = cmd_set_fdir_input_set_parsed,
10551         .data = NULL,
10552         .help_str = "set_fdir_input_set <port_id> "
10553         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10554         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10555         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10556         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10557         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10558         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10559         "sctp-veri-tag|none select|add",
10560         .tokens = {
10561                 (void *)&cmd_set_fdir_input_set_cmd,
10562                 (void *)&cmd_set_fdir_input_set_port_id,
10563                 (void *)&cmd_set_fdir_input_set_flow_type,
10564                 (void *)&cmd_set_fdir_input_set_field,
10565                 (void *)&cmd_set_fdir_input_set_select,
10566                 NULL,
10567         },
10568 };
10569
10570 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10571 struct cmd_mcast_addr_result {
10572         cmdline_fixed_string_t mcast_addr_cmd;
10573         cmdline_fixed_string_t what;
10574         uint8_t port_num;
10575         struct ether_addr mc_addr;
10576 };
10577
10578 static void cmd_mcast_addr_parsed(void *parsed_result,
10579                 __attribute__((unused)) struct cmdline *cl,
10580                 __attribute__((unused)) void *data)
10581 {
10582         struct cmd_mcast_addr_result *res = parsed_result;
10583
10584         if (!is_multicast_ether_addr(&res->mc_addr)) {
10585                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10586                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10587                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10588                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10589                 return;
10590         }
10591         if (strcmp(res->what, "add") == 0)
10592                 mcast_addr_add(res->port_num, &res->mc_addr);
10593         else
10594                 mcast_addr_remove(res->port_num, &res->mc_addr);
10595 }
10596
10597 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10598         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10599                                  mcast_addr_cmd, "mcast_addr");
10600 cmdline_parse_token_string_t cmd_mcast_addr_what =
10601         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10602                                  "add#remove");
10603 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10604         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10605 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10606         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10607
10608 cmdline_parse_inst_t cmd_mcast_addr = {
10609         .f = cmd_mcast_addr_parsed,
10610         .data = (void *)0,
10611         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10612                 "Add/Remove multicast MAC address on port_id",
10613         .tokens = {
10614                 (void *)&cmd_mcast_addr_cmd,
10615                 (void *)&cmd_mcast_addr_what,
10616                 (void *)&cmd_mcast_addr_portnum,
10617                 (void *)&cmd_mcast_addr_addr,
10618                 NULL,
10619         },
10620 };
10621
10622 /* l2 tunnel config
10623  * only support E-tag now.
10624  */
10625
10626 /* Ether type config */
10627 struct cmd_config_l2_tunnel_eth_type_result {
10628         cmdline_fixed_string_t port;
10629         cmdline_fixed_string_t config;
10630         cmdline_fixed_string_t all;
10631         uint8_t id;
10632         cmdline_fixed_string_t l2_tunnel;
10633         cmdline_fixed_string_t l2_tunnel_type;
10634         cmdline_fixed_string_t eth_type;
10635         uint16_t eth_type_val;
10636 };
10637
10638 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10639         TOKEN_STRING_INITIALIZER
10640                 (struct cmd_config_l2_tunnel_eth_type_result,
10641                  port, "port");
10642 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10643         TOKEN_STRING_INITIALIZER
10644                 (struct cmd_config_l2_tunnel_eth_type_result,
10645                  config, "config");
10646 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10647         TOKEN_STRING_INITIALIZER
10648                 (struct cmd_config_l2_tunnel_eth_type_result,
10649                  all, "all");
10650 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10651         TOKEN_NUM_INITIALIZER
10652                 (struct cmd_config_l2_tunnel_eth_type_result,
10653                  id, UINT8);
10654 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10655         TOKEN_STRING_INITIALIZER
10656                 (struct cmd_config_l2_tunnel_eth_type_result,
10657                  l2_tunnel, "l2-tunnel");
10658 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10659         TOKEN_STRING_INITIALIZER
10660                 (struct cmd_config_l2_tunnel_eth_type_result,
10661                  l2_tunnel_type, "E-tag");
10662 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10663         TOKEN_STRING_INITIALIZER
10664                 (struct cmd_config_l2_tunnel_eth_type_result,
10665                  eth_type, "ether-type");
10666 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10667         TOKEN_NUM_INITIALIZER
10668                 (struct cmd_config_l2_tunnel_eth_type_result,
10669                  eth_type_val, UINT16);
10670
10671 static enum rte_eth_tunnel_type
10672 str2fdir_l2_tunnel_type(char *string)
10673 {
10674         uint32_t i = 0;
10675
10676         static const struct {
10677                 char str[32];
10678                 enum rte_eth_tunnel_type type;
10679         } l2_tunnel_type_str[] = {
10680                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10681         };
10682
10683         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10684                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10685                         return l2_tunnel_type_str[i].type;
10686         }
10687         return RTE_TUNNEL_TYPE_NONE;
10688 }
10689
10690 /* ether type config for all ports */
10691 static void
10692 cmd_config_l2_tunnel_eth_type_all_parsed
10693         (void *parsed_result,
10694          __attribute__((unused)) struct cmdline *cl,
10695          __attribute__((unused)) void *data)
10696 {
10697         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10698         struct rte_eth_l2_tunnel_conf entry;
10699         portid_t pid;
10700
10701         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10702         entry.ether_type = res->eth_type_val;
10703
10704         RTE_ETH_FOREACH_DEV(pid) {
10705                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10706         }
10707 }
10708
10709 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10710         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10711         .data = NULL,
10712         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10713         .tokens = {
10714                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10715                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10716                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10717                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10718                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10719                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10720                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10721                 NULL,
10722         },
10723 };
10724
10725 /* ether type config for a specific port */
10726 static void
10727 cmd_config_l2_tunnel_eth_type_specific_parsed(
10728         void *parsed_result,
10729         __attribute__((unused)) struct cmdline *cl,
10730         __attribute__((unused)) void *data)
10731 {
10732         struct cmd_config_l2_tunnel_eth_type_result *res =
10733                  parsed_result;
10734         struct rte_eth_l2_tunnel_conf entry;
10735
10736         if (port_id_is_invalid(res->id, ENABLED_WARN))
10737                 return;
10738
10739         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10740         entry.ether_type = res->eth_type_val;
10741
10742         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10743 }
10744
10745 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10746         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10747         .data = NULL,
10748         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10749         .tokens = {
10750                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10751                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10752                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10753                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10754                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10755                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10756                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10757                 NULL,
10758         },
10759 };
10760
10761 /* Enable/disable l2 tunnel */
10762 struct cmd_config_l2_tunnel_en_dis_result {
10763         cmdline_fixed_string_t port;
10764         cmdline_fixed_string_t config;
10765         cmdline_fixed_string_t all;
10766         uint8_t id;
10767         cmdline_fixed_string_t l2_tunnel;
10768         cmdline_fixed_string_t l2_tunnel_type;
10769         cmdline_fixed_string_t en_dis;
10770 };
10771
10772 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10773         TOKEN_STRING_INITIALIZER
10774                 (struct cmd_config_l2_tunnel_en_dis_result,
10775                  port, "port");
10776 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10777         TOKEN_STRING_INITIALIZER
10778                 (struct cmd_config_l2_tunnel_en_dis_result,
10779                  config, "config");
10780 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10781         TOKEN_STRING_INITIALIZER
10782                 (struct cmd_config_l2_tunnel_en_dis_result,
10783                  all, "all");
10784 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10785         TOKEN_NUM_INITIALIZER
10786                 (struct cmd_config_l2_tunnel_en_dis_result,
10787                  id, UINT8);
10788 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10789         TOKEN_STRING_INITIALIZER
10790                 (struct cmd_config_l2_tunnel_en_dis_result,
10791                  l2_tunnel, "l2-tunnel");
10792 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10793         TOKEN_STRING_INITIALIZER
10794                 (struct cmd_config_l2_tunnel_en_dis_result,
10795                  l2_tunnel_type, "E-tag");
10796 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10797         TOKEN_STRING_INITIALIZER
10798                 (struct cmd_config_l2_tunnel_en_dis_result,
10799                  en_dis, "enable#disable");
10800
10801 /* enable/disable l2 tunnel for all ports */
10802 static void
10803 cmd_config_l2_tunnel_en_dis_all_parsed(
10804         void *parsed_result,
10805         __attribute__((unused)) struct cmdline *cl,
10806         __attribute__((unused)) void *data)
10807 {
10808         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10809         struct rte_eth_l2_tunnel_conf entry;
10810         portid_t pid;
10811         uint8_t en;
10812
10813         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10814
10815         if (!strcmp("enable", res->en_dis))
10816                 en = 1;
10817         else
10818                 en = 0;
10819
10820         RTE_ETH_FOREACH_DEV(pid) {
10821                 rte_eth_dev_l2_tunnel_offload_set(pid,
10822                                                   &entry,
10823                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10824                                                   en);
10825         }
10826 }
10827
10828 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10829         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10830         .data = NULL,
10831         .help_str = "port config all l2-tunnel E-tag enable|disable",
10832         .tokens = {
10833                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10834                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10835                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10836                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10837                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10838                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10839                 NULL,
10840         },
10841 };
10842
10843 /* enable/disable l2 tunnel for a port */
10844 static void
10845 cmd_config_l2_tunnel_en_dis_specific_parsed(
10846         void *parsed_result,
10847         __attribute__((unused)) struct cmdline *cl,
10848         __attribute__((unused)) void *data)
10849 {
10850         struct cmd_config_l2_tunnel_en_dis_result *res =
10851                 parsed_result;
10852         struct rte_eth_l2_tunnel_conf entry;
10853
10854         if (port_id_is_invalid(res->id, ENABLED_WARN))
10855                 return;
10856
10857         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10858
10859         if (!strcmp("enable", res->en_dis))
10860                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10861                                                   &entry,
10862                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10863                                                   1);
10864         else
10865                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10866                                                   &entry,
10867                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10868                                                   0);
10869 }
10870
10871 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10872         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10873         .data = NULL,
10874         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10875         .tokens = {
10876                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10877                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10878                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10879                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10880                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10881                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10882                 NULL,
10883         },
10884 };
10885
10886 /* E-tag configuration */
10887
10888 /* Common result structure for all E-tag configuration */
10889 struct cmd_config_e_tag_result {
10890         cmdline_fixed_string_t e_tag;
10891         cmdline_fixed_string_t set;
10892         cmdline_fixed_string_t insertion;
10893         cmdline_fixed_string_t stripping;
10894         cmdline_fixed_string_t forwarding;
10895         cmdline_fixed_string_t filter;
10896         cmdline_fixed_string_t add;
10897         cmdline_fixed_string_t del;
10898         cmdline_fixed_string_t on;
10899         cmdline_fixed_string_t off;
10900         cmdline_fixed_string_t on_off;
10901         cmdline_fixed_string_t port_tag_id;
10902         uint32_t port_tag_id_val;
10903         cmdline_fixed_string_t e_tag_id;
10904         uint16_t e_tag_id_val;
10905         cmdline_fixed_string_t dst_pool;
10906         uint8_t dst_pool_val;
10907         cmdline_fixed_string_t port;
10908         uint8_t port_id;
10909         cmdline_fixed_string_t vf;
10910         uint8_t vf_id;
10911 };
10912
10913 /* Common CLI fields for all E-tag configuration */
10914 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10915         TOKEN_STRING_INITIALIZER
10916                 (struct cmd_config_e_tag_result,
10917                  e_tag, "E-tag");
10918 cmdline_parse_token_string_t cmd_config_e_tag_set =
10919         TOKEN_STRING_INITIALIZER
10920                 (struct cmd_config_e_tag_result,
10921                  set, "set");
10922 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10923         TOKEN_STRING_INITIALIZER
10924                 (struct cmd_config_e_tag_result,
10925                  insertion, "insertion");
10926 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10927         TOKEN_STRING_INITIALIZER
10928                 (struct cmd_config_e_tag_result,
10929                  stripping, "stripping");
10930 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10931         TOKEN_STRING_INITIALIZER
10932                 (struct cmd_config_e_tag_result,
10933                  forwarding, "forwarding");
10934 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10935         TOKEN_STRING_INITIALIZER
10936                 (struct cmd_config_e_tag_result,
10937                  filter, "filter");
10938 cmdline_parse_token_string_t cmd_config_e_tag_add =
10939         TOKEN_STRING_INITIALIZER
10940                 (struct cmd_config_e_tag_result,
10941                  add, "add");
10942 cmdline_parse_token_string_t cmd_config_e_tag_del =
10943         TOKEN_STRING_INITIALIZER
10944                 (struct cmd_config_e_tag_result,
10945                  del, "del");
10946 cmdline_parse_token_string_t cmd_config_e_tag_on =
10947         TOKEN_STRING_INITIALIZER
10948                 (struct cmd_config_e_tag_result,
10949                  on, "on");
10950 cmdline_parse_token_string_t cmd_config_e_tag_off =
10951         TOKEN_STRING_INITIALIZER
10952                 (struct cmd_config_e_tag_result,
10953                  off, "off");
10954 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10955         TOKEN_STRING_INITIALIZER
10956                 (struct cmd_config_e_tag_result,
10957                  on_off, "on#off");
10958 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10959         TOKEN_STRING_INITIALIZER
10960                 (struct cmd_config_e_tag_result,
10961                  port_tag_id, "port-tag-id");
10962 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10963         TOKEN_NUM_INITIALIZER
10964                 (struct cmd_config_e_tag_result,
10965                  port_tag_id_val, UINT32);
10966 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10967         TOKEN_STRING_INITIALIZER
10968                 (struct cmd_config_e_tag_result,
10969                  e_tag_id, "e-tag-id");
10970 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10971         TOKEN_NUM_INITIALIZER
10972                 (struct cmd_config_e_tag_result,
10973                  e_tag_id_val, UINT16);
10974 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10975         TOKEN_STRING_INITIALIZER
10976                 (struct cmd_config_e_tag_result,
10977                  dst_pool, "dst-pool");
10978 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10979         TOKEN_NUM_INITIALIZER
10980                 (struct cmd_config_e_tag_result,
10981                  dst_pool_val, UINT8);
10982 cmdline_parse_token_string_t cmd_config_e_tag_port =
10983         TOKEN_STRING_INITIALIZER
10984                 (struct cmd_config_e_tag_result,
10985                  port, "port");
10986 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10987         TOKEN_NUM_INITIALIZER
10988                 (struct cmd_config_e_tag_result,
10989                  port_id, UINT8);
10990 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10991         TOKEN_STRING_INITIALIZER
10992                 (struct cmd_config_e_tag_result,
10993                  vf, "vf");
10994 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10995         TOKEN_NUM_INITIALIZER
10996                 (struct cmd_config_e_tag_result,
10997                  vf_id, UINT8);
10998
10999 /* E-tag insertion configuration */
11000 static void
11001 cmd_config_e_tag_insertion_en_parsed(
11002         void *parsed_result,
11003         __attribute__((unused)) struct cmdline *cl,
11004         __attribute__((unused)) void *data)
11005 {
11006         struct cmd_config_e_tag_result *res =
11007                 parsed_result;
11008         struct rte_eth_l2_tunnel_conf entry;
11009
11010         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11011                 return;
11012
11013         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11014         entry.tunnel_id = res->port_tag_id_val;
11015         entry.vf_id = res->vf_id;
11016         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11017                                           &entry,
11018                                           ETH_L2_TUNNEL_INSERTION_MASK,
11019                                           1);
11020 }
11021
11022 static void
11023 cmd_config_e_tag_insertion_dis_parsed(
11024         void *parsed_result,
11025         __attribute__((unused)) struct cmdline *cl,
11026         __attribute__((unused)) void *data)
11027 {
11028         struct cmd_config_e_tag_result *res =
11029                 parsed_result;
11030         struct rte_eth_l2_tunnel_conf entry;
11031
11032         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11033                 return;
11034
11035         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11036         entry.vf_id = res->vf_id;
11037
11038         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11039                                           &entry,
11040                                           ETH_L2_TUNNEL_INSERTION_MASK,
11041                                           0);
11042 }
11043
11044 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11045         .f = cmd_config_e_tag_insertion_en_parsed,
11046         .data = NULL,
11047         .help_str = "E-tag ... : E-tag insertion enable",
11048         .tokens = {
11049                 (void *)&cmd_config_e_tag_e_tag,
11050                 (void *)&cmd_config_e_tag_set,
11051                 (void *)&cmd_config_e_tag_insertion,
11052                 (void *)&cmd_config_e_tag_on,
11053                 (void *)&cmd_config_e_tag_port_tag_id,
11054                 (void *)&cmd_config_e_tag_port_tag_id_val,
11055                 (void *)&cmd_config_e_tag_port,
11056                 (void *)&cmd_config_e_tag_port_id,
11057                 (void *)&cmd_config_e_tag_vf,
11058                 (void *)&cmd_config_e_tag_vf_id,
11059                 NULL,
11060         },
11061 };
11062
11063 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11064         .f = cmd_config_e_tag_insertion_dis_parsed,
11065         .data = NULL,
11066         .help_str = "E-tag ... : E-tag insertion disable",
11067         .tokens = {
11068                 (void *)&cmd_config_e_tag_e_tag,
11069                 (void *)&cmd_config_e_tag_set,
11070                 (void *)&cmd_config_e_tag_insertion,
11071                 (void *)&cmd_config_e_tag_off,
11072                 (void *)&cmd_config_e_tag_port,
11073                 (void *)&cmd_config_e_tag_port_id,
11074                 (void *)&cmd_config_e_tag_vf,
11075                 (void *)&cmd_config_e_tag_vf_id,
11076                 NULL,
11077         },
11078 };
11079
11080 /* E-tag stripping configuration */
11081 static void
11082 cmd_config_e_tag_stripping_parsed(
11083         void *parsed_result,
11084         __attribute__((unused)) struct cmdline *cl,
11085         __attribute__((unused)) void *data)
11086 {
11087         struct cmd_config_e_tag_result *res =
11088                 parsed_result;
11089         struct rte_eth_l2_tunnel_conf entry;
11090
11091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11092                 return;
11093
11094         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11095
11096         if (!strcmp(res->on_off, "on"))
11097                 rte_eth_dev_l2_tunnel_offload_set
11098                         (res->port_id,
11099                          &entry,
11100                          ETH_L2_TUNNEL_STRIPPING_MASK,
11101                          1);
11102         else
11103                 rte_eth_dev_l2_tunnel_offload_set
11104                         (res->port_id,
11105                          &entry,
11106                          ETH_L2_TUNNEL_STRIPPING_MASK,
11107                          0);
11108 }
11109
11110 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11111         .f = cmd_config_e_tag_stripping_parsed,
11112         .data = NULL,
11113         .help_str = "E-tag ... : E-tag stripping enable/disable",
11114         .tokens = {
11115                 (void *)&cmd_config_e_tag_e_tag,
11116                 (void *)&cmd_config_e_tag_set,
11117                 (void *)&cmd_config_e_tag_stripping,
11118                 (void *)&cmd_config_e_tag_on_off,
11119                 (void *)&cmd_config_e_tag_port,
11120                 (void *)&cmd_config_e_tag_port_id,
11121                 NULL,
11122         },
11123 };
11124
11125 /* E-tag forwarding configuration */
11126 static void
11127 cmd_config_e_tag_forwarding_parsed(
11128         void *parsed_result,
11129         __attribute__((unused)) struct cmdline *cl,
11130         __attribute__((unused)) void *data)
11131 {
11132         struct cmd_config_e_tag_result *res = parsed_result;
11133         struct rte_eth_l2_tunnel_conf entry;
11134
11135         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11136                 return;
11137
11138         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11139
11140         if (!strcmp(res->on_off, "on"))
11141                 rte_eth_dev_l2_tunnel_offload_set
11142                         (res->port_id,
11143                          &entry,
11144                          ETH_L2_TUNNEL_FORWARDING_MASK,
11145                          1);
11146         else
11147                 rte_eth_dev_l2_tunnel_offload_set
11148                         (res->port_id,
11149                          &entry,
11150                          ETH_L2_TUNNEL_FORWARDING_MASK,
11151                          0);
11152 }
11153
11154 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11155         .f = cmd_config_e_tag_forwarding_parsed,
11156         .data = NULL,
11157         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11158         .tokens = {
11159                 (void *)&cmd_config_e_tag_e_tag,
11160                 (void *)&cmd_config_e_tag_set,
11161                 (void *)&cmd_config_e_tag_forwarding,
11162                 (void *)&cmd_config_e_tag_on_off,
11163                 (void *)&cmd_config_e_tag_port,
11164                 (void *)&cmd_config_e_tag_port_id,
11165                 NULL,
11166         },
11167 };
11168
11169 /* E-tag filter configuration */
11170 static void
11171 cmd_config_e_tag_filter_add_parsed(
11172         void *parsed_result,
11173         __attribute__((unused)) struct cmdline *cl,
11174         __attribute__((unused)) void *data)
11175 {
11176         struct cmd_config_e_tag_result *res = parsed_result;
11177         struct rte_eth_l2_tunnel_conf entry;
11178         int ret = 0;
11179
11180         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11181                 return;
11182
11183         if (res->e_tag_id_val > 0x3fff) {
11184                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11185                 return;
11186         }
11187
11188         ret = rte_eth_dev_filter_supported(res->port_id,
11189                                            RTE_ETH_FILTER_L2_TUNNEL);
11190         if (ret < 0) {
11191                 printf("E-tag filter is not supported on port %u.\n",
11192                        res->port_id);
11193                 return;
11194         }
11195
11196         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11197         entry.tunnel_id = res->e_tag_id_val;
11198         entry.pool = res->dst_pool_val;
11199
11200         ret = rte_eth_dev_filter_ctrl(res->port_id,
11201                                       RTE_ETH_FILTER_L2_TUNNEL,
11202                                       RTE_ETH_FILTER_ADD,
11203                                       &entry);
11204         if (ret < 0)
11205                 printf("E-tag filter programming error: (%s)\n",
11206                        strerror(-ret));
11207 }
11208
11209 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11210         .f = cmd_config_e_tag_filter_add_parsed,
11211         .data = NULL,
11212         .help_str = "E-tag ... : E-tag filter add",
11213         .tokens = {
11214                 (void *)&cmd_config_e_tag_e_tag,
11215                 (void *)&cmd_config_e_tag_set,
11216                 (void *)&cmd_config_e_tag_filter,
11217                 (void *)&cmd_config_e_tag_add,
11218                 (void *)&cmd_config_e_tag_e_tag_id,
11219                 (void *)&cmd_config_e_tag_e_tag_id_val,
11220                 (void *)&cmd_config_e_tag_dst_pool,
11221                 (void *)&cmd_config_e_tag_dst_pool_val,
11222                 (void *)&cmd_config_e_tag_port,
11223                 (void *)&cmd_config_e_tag_port_id,
11224                 NULL,
11225         },
11226 };
11227
11228 static void
11229 cmd_config_e_tag_filter_del_parsed(
11230         void *parsed_result,
11231         __attribute__((unused)) struct cmdline *cl,
11232         __attribute__((unused)) void *data)
11233 {
11234         struct cmd_config_e_tag_result *res = parsed_result;
11235         struct rte_eth_l2_tunnel_conf entry;
11236         int ret = 0;
11237
11238         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11239                 return;
11240
11241         if (res->e_tag_id_val > 0x3fff) {
11242                 printf("e-tag-id must be less than 0x3fff.\n");
11243                 return;
11244         }
11245
11246         ret = rte_eth_dev_filter_supported(res->port_id,
11247                                            RTE_ETH_FILTER_L2_TUNNEL);
11248         if (ret < 0) {
11249                 printf("E-tag filter is not supported on port %u.\n",
11250                        res->port_id);
11251                 return;
11252         }
11253
11254         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11255         entry.tunnel_id = res->e_tag_id_val;
11256
11257         ret = rte_eth_dev_filter_ctrl(res->port_id,
11258                                       RTE_ETH_FILTER_L2_TUNNEL,
11259                                       RTE_ETH_FILTER_DELETE,
11260                                       &entry);
11261         if (ret < 0)
11262                 printf("E-tag filter programming error: (%s)\n",
11263                        strerror(-ret));
11264 }
11265
11266 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11267         .f = cmd_config_e_tag_filter_del_parsed,
11268         .data = NULL,
11269         .help_str = "E-tag ... : E-tag filter delete",
11270         .tokens = {
11271                 (void *)&cmd_config_e_tag_e_tag,
11272                 (void *)&cmd_config_e_tag_set,
11273                 (void *)&cmd_config_e_tag_filter,
11274                 (void *)&cmd_config_e_tag_del,
11275                 (void *)&cmd_config_e_tag_e_tag_id,
11276                 (void *)&cmd_config_e_tag_e_tag_id_val,
11277                 (void *)&cmd_config_e_tag_port,
11278                 (void *)&cmd_config_e_tag_port_id,
11279                 NULL,
11280         },
11281 };
11282
11283 /* vf vlan anti spoof configuration */
11284
11285 /* Common result structure for vf vlan anti spoof */
11286 struct cmd_vf_vlan_anti_spoof_result {
11287         cmdline_fixed_string_t set;
11288         cmdline_fixed_string_t vf;
11289         cmdline_fixed_string_t vlan;
11290         cmdline_fixed_string_t antispoof;
11291         uint8_t port_id;
11292         uint32_t vf_id;
11293         cmdline_fixed_string_t on_off;
11294 };
11295
11296 /* Common CLI fields for vf vlan anti spoof enable disable */
11297 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11298         TOKEN_STRING_INITIALIZER
11299                 (struct cmd_vf_vlan_anti_spoof_result,
11300                  set, "set");
11301 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11302         TOKEN_STRING_INITIALIZER
11303                 (struct cmd_vf_vlan_anti_spoof_result,
11304                  vf, "vf");
11305 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11306         TOKEN_STRING_INITIALIZER
11307                 (struct cmd_vf_vlan_anti_spoof_result,
11308                  vlan, "vlan");
11309 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11310         TOKEN_STRING_INITIALIZER
11311                 (struct cmd_vf_vlan_anti_spoof_result,
11312                  antispoof, "antispoof");
11313 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11314         TOKEN_NUM_INITIALIZER
11315                 (struct cmd_vf_vlan_anti_spoof_result,
11316                  port_id, UINT8);
11317 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11318         TOKEN_NUM_INITIALIZER
11319                 (struct cmd_vf_vlan_anti_spoof_result,
11320                  vf_id, UINT32);
11321 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11322         TOKEN_STRING_INITIALIZER
11323                 (struct cmd_vf_vlan_anti_spoof_result,
11324                  on_off, "on#off");
11325
11326 static void
11327 cmd_set_vf_vlan_anti_spoof_parsed(
11328         void *parsed_result,
11329         __attribute__((unused)) struct cmdline *cl,
11330         __attribute__((unused)) void *data)
11331 {
11332         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11333         int ret = -ENOTSUP;
11334
11335         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11336
11337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11338                 return;
11339
11340 #ifdef RTE_LIBRTE_IXGBE_PMD
11341         if (ret == -ENOTSUP)
11342                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11343                                 res->vf_id, is_on);
11344 #endif
11345 #ifdef RTE_LIBRTE_I40E_PMD
11346         if (ret == -ENOTSUP)
11347                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11348                                 res->vf_id, is_on);
11349 #endif
11350 #ifdef RTE_LIBRTE_BNXT_PMD
11351         if (ret == -ENOTSUP)
11352                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11353                                 res->vf_id, is_on);
11354 #endif
11355
11356         switch (ret) {
11357         case 0:
11358                 break;
11359         case -EINVAL:
11360                 printf("invalid vf_id %d\n", res->vf_id);
11361                 break;
11362         case -ENODEV:
11363                 printf("invalid port_id %d\n", res->port_id);
11364                 break;
11365         case -ENOTSUP:
11366                 printf("function not implemented\n");
11367                 break;
11368         default:
11369                 printf("programming error: (%s)\n", strerror(-ret));
11370         }
11371 }
11372
11373 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11374         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11375         .data = NULL,
11376         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11377         .tokens = {
11378                 (void *)&cmd_vf_vlan_anti_spoof_set,
11379                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11380                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11381                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11382                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11383                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11384                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11385                 NULL,
11386         },
11387 };
11388
11389 /* vf mac anti spoof configuration */
11390
11391 /* Common result structure for vf mac anti spoof */
11392 struct cmd_vf_mac_anti_spoof_result {
11393         cmdline_fixed_string_t set;
11394         cmdline_fixed_string_t vf;
11395         cmdline_fixed_string_t mac;
11396         cmdline_fixed_string_t antispoof;
11397         uint8_t port_id;
11398         uint32_t vf_id;
11399         cmdline_fixed_string_t on_off;
11400 };
11401
11402 /* Common CLI fields for vf mac anti spoof enable disable */
11403 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11404         TOKEN_STRING_INITIALIZER
11405                 (struct cmd_vf_mac_anti_spoof_result,
11406                  set, "set");
11407 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11408         TOKEN_STRING_INITIALIZER
11409                 (struct cmd_vf_mac_anti_spoof_result,
11410                  vf, "vf");
11411 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11412         TOKEN_STRING_INITIALIZER
11413                 (struct cmd_vf_mac_anti_spoof_result,
11414                  mac, "mac");
11415 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11416         TOKEN_STRING_INITIALIZER
11417                 (struct cmd_vf_mac_anti_spoof_result,
11418                  antispoof, "antispoof");
11419 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11420         TOKEN_NUM_INITIALIZER
11421                 (struct cmd_vf_mac_anti_spoof_result,
11422                  port_id, UINT8);
11423 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11424         TOKEN_NUM_INITIALIZER
11425                 (struct cmd_vf_mac_anti_spoof_result,
11426                  vf_id, UINT32);
11427 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11428         TOKEN_STRING_INITIALIZER
11429                 (struct cmd_vf_mac_anti_spoof_result,
11430                  on_off, "on#off");
11431
11432 static void
11433 cmd_set_vf_mac_anti_spoof_parsed(
11434         void *parsed_result,
11435         __attribute__((unused)) struct cmdline *cl,
11436         __attribute__((unused)) void *data)
11437 {
11438         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11439         int ret = -ENOTSUP;
11440
11441         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11442
11443         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11444                 return;
11445
11446 #ifdef RTE_LIBRTE_IXGBE_PMD
11447         if (ret == -ENOTSUP)
11448                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11449                         res->vf_id, is_on);
11450 #endif
11451 #ifdef RTE_LIBRTE_I40E_PMD
11452         if (ret == -ENOTSUP)
11453                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11454                         res->vf_id, is_on);
11455 #endif
11456 #ifdef RTE_LIBRTE_BNXT_PMD
11457         if (ret == -ENOTSUP)
11458                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11459                         res->vf_id, is_on);
11460 #endif
11461
11462         switch (ret) {
11463         case 0:
11464                 break;
11465         case -EINVAL:
11466                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11467                 break;
11468         case -ENODEV:
11469                 printf("invalid port_id %d\n", res->port_id);
11470                 break;
11471         case -ENOTSUP:
11472                 printf("function not implemented\n");
11473                 break;
11474         default:
11475                 printf("programming error: (%s)\n", strerror(-ret));
11476         }
11477 }
11478
11479 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11480         .f = cmd_set_vf_mac_anti_spoof_parsed,
11481         .data = NULL,
11482         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11483         .tokens = {
11484                 (void *)&cmd_vf_mac_anti_spoof_set,
11485                 (void *)&cmd_vf_mac_anti_spoof_vf,
11486                 (void *)&cmd_vf_mac_anti_spoof_mac,
11487                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11488                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11489                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11490                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11491                 NULL,
11492         },
11493 };
11494
11495 /* vf vlan strip queue configuration */
11496
11497 /* Common result structure for vf mac anti spoof */
11498 struct cmd_vf_vlan_stripq_result {
11499         cmdline_fixed_string_t set;
11500         cmdline_fixed_string_t vf;
11501         cmdline_fixed_string_t vlan;
11502         cmdline_fixed_string_t stripq;
11503         uint8_t port_id;
11504         uint16_t vf_id;
11505         cmdline_fixed_string_t on_off;
11506 };
11507
11508 /* Common CLI fields for vf vlan strip enable disable */
11509 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_vf_vlan_stripq_result,
11512                  set, "set");
11513 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11514         TOKEN_STRING_INITIALIZER
11515                 (struct cmd_vf_vlan_stripq_result,
11516                  vf, "vf");
11517 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_vf_vlan_stripq_result,
11520                  vlan, "vlan");
11521 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_vf_vlan_stripq_result,
11524                  stripq, "stripq");
11525 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11526         TOKEN_NUM_INITIALIZER
11527                 (struct cmd_vf_vlan_stripq_result,
11528                  port_id, UINT8);
11529 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11530         TOKEN_NUM_INITIALIZER
11531                 (struct cmd_vf_vlan_stripq_result,
11532                  vf_id, UINT16);
11533 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11534         TOKEN_STRING_INITIALIZER
11535                 (struct cmd_vf_vlan_stripq_result,
11536                  on_off, "on#off");
11537
11538 static void
11539 cmd_set_vf_vlan_stripq_parsed(
11540         void *parsed_result,
11541         __attribute__((unused)) struct cmdline *cl,
11542         __attribute__((unused)) void *data)
11543 {
11544         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11545         int ret = -ENOTSUP;
11546
11547         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11548
11549         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11550                 return;
11551
11552 #ifdef RTE_LIBRTE_IXGBE_PMD
11553         if (ret == -ENOTSUP)
11554                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11555                         res->vf_id, is_on);
11556 #endif
11557 #ifdef RTE_LIBRTE_I40E_PMD
11558         if (ret == -ENOTSUP)
11559                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11560                         res->vf_id, is_on);
11561 #endif
11562 #ifdef RTE_LIBRTE_BNXT_PMD
11563         if (ret == -ENOTSUP)
11564                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11565                         res->vf_id, is_on);
11566 #endif
11567
11568         switch (ret) {
11569         case 0:
11570                 break;
11571         case -EINVAL:
11572                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11573                 break;
11574         case -ENODEV:
11575                 printf("invalid port_id %d\n", res->port_id);
11576                 break;
11577         case -ENOTSUP:
11578                 printf("function not implemented\n");
11579                 break;
11580         default:
11581                 printf("programming error: (%s)\n", strerror(-ret));
11582         }
11583 }
11584
11585 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11586         .f = cmd_set_vf_vlan_stripq_parsed,
11587         .data = NULL,
11588         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11589         .tokens = {
11590                 (void *)&cmd_vf_vlan_stripq_set,
11591                 (void *)&cmd_vf_vlan_stripq_vf,
11592                 (void *)&cmd_vf_vlan_stripq_vlan,
11593                 (void *)&cmd_vf_vlan_stripq_stripq,
11594                 (void *)&cmd_vf_vlan_stripq_port_id,
11595                 (void *)&cmd_vf_vlan_stripq_vf_id,
11596                 (void *)&cmd_vf_vlan_stripq_on_off,
11597                 NULL,
11598         },
11599 };
11600
11601 /* vf vlan insert configuration */
11602
11603 /* Common result structure for vf vlan insert */
11604 struct cmd_vf_vlan_insert_result {
11605         cmdline_fixed_string_t set;
11606         cmdline_fixed_string_t vf;
11607         cmdline_fixed_string_t vlan;
11608         cmdline_fixed_string_t insert;
11609         uint8_t port_id;
11610         uint16_t vf_id;
11611         uint16_t vlan_id;
11612 };
11613
11614 /* Common CLI fields for vf vlan insert enable disable */
11615 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11616         TOKEN_STRING_INITIALIZER
11617                 (struct cmd_vf_vlan_insert_result,
11618                  set, "set");
11619 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11620         TOKEN_STRING_INITIALIZER
11621                 (struct cmd_vf_vlan_insert_result,
11622                  vf, "vf");
11623 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11624         TOKEN_STRING_INITIALIZER
11625                 (struct cmd_vf_vlan_insert_result,
11626                  vlan, "vlan");
11627 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11628         TOKEN_STRING_INITIALIZER
11629                 (struct cmd_vf_vlan_insert_result,
11630                  insert, "insert");
11631 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11632         TOKEN_NUM_INITIALIZER
11633                 (struct cmd_vf_vlan_insert_result,
11634                  port_id, UINT8);
11635 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11636         TOKEN_NUM_INITIALIZER
11637                 (struct cmd_vf_vlan_insert_result,
11638                  vf_id, UINT16);
11639 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11640         TOKEN_NUM_INITIALIZER
11641                 (struct cmd_vf_vlan_insert_result,
11642                  vlan_id, UINT16);
11643
11644 static void
11645 cmd_set_vf_vlan_insert_parsed(
11646         void *parsed_result,
11647         __attribute__((unused)) struct cmdline *cl,
11648         __attribute__((unused)) void *data)
11649 {
11650         struct cmd_vf_vlan_insert_result *res = parsed_result;
11651         int ret = -ENOTSUP;
11652
11653         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11654                 return;
11655
11656 #ifdef RTE_LIBRTE_IXGBE_PMD
11657         if (ret == -ENOTSUP)
11658                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11659                         res->vlan_id);
11660 #endif
11661 #ifdef RTE_LIBRTE_I40E_PMD
11662         if (ret == -ENOTSUP)
11663                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11664                         res->vlan_id);
11665 #endif
11666 #ifdef RTE_LIBRTE_BNXT_PMD
11667         if (ret == -ENOTSUP)
11668                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11669                         res->vlan_id);
11670 #endif
11671
11672         switch (ret) {
11673         case 0:
11674                 break;
11675         case -EINVAL:
11676                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11677                 break;
11678         case -ENODEV:
11679                 printf("invalid port_id %d\n", res->port_id);
11680                 break;
11681         case -ENOTSUP:
11682                 printf("function not implemented\n");
11683                 break;
11684         default:
11685                 printf("programming error: (%s)\n", strerror(-ret));
11686         }
11687 }
11688
11689 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11690         .f = cmd_set_vf_vlan_insert_parsed,
11691         .data = NULL,
11692         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11693         .tokens = {
11694                 (void *)&cmd_vf_vlan_insert_set,
11695                 (void *)&cmd_vf_vlan_insert_vf,
11696                 (void *)&cmd_vf_vlan_insert_vlan,
11697                 (void *)&cmd_vf_vlan_insert_insert,
11698                 (void *)&cmd_vf_vlan_insert_port_id,
11699                 (void *)&cmd_vf_vlan_insert_vf_id,
11700                 (void *)&cmd_vf_vlan_insert_vlan_id,
11701                 NULL,
11702         },
11703 };
11704
11705 /* tx loopback configuration */
11706
11707 /* Common result structure for tx loopback */
11708 struct cmd_tx_loopback_result {
11709         cmdline_fixed_string_t set;
11710         cmdline_fixed_string_t tx;
11711         cmdline_fixed_string_t loopback;
11712         uint8_t port_id;
11713         cmdline_fixed_string_t on_off;
11714 };
11715
11716 /* Common CLI fields for tx loopback enable disable */
11717 cmdline_parse_token_string_t cmd_tx_loopback_set =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_tx_loopback_result,
11720                  set, "set");
11721 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11722         TOKEN_STRING_INITIALIZER
11723                 (struct cmd_tx_loopback_result,
11724                  tx, "tx");
11725 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11726         TOKEN_STRING_INITIALIZER
11727                 (struct cmd_tx_loopback_result,
11728                  loopback, "loopback");
11729 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11730         TOKEN_NUM_INITIALIZER
11731                 (struct cmd_tx_loopback_result,
11732                  port_id, UINT8);
11733 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11734         TOKEN_STRING_INITIALIZER
11735                 (struct cmd_tx_loopback_result,
11736                  on_off, "on#off");
11737
11738 static void
11739 cmd_set_tx_loopback_parsed(
11740         void *parsed_result,
11741         __attribute__((unused)) struct cmdline *cl,
11742         __attribute__((unused)) void *data)
11743 {
11744         struct cmd_tx_loopback_result *res = parsed_result;
11745         int ret = -ENOTSUP;
11746
11747         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11748
11749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11750                 return;
11751
11752 #ifdef RTE_LIBRTE_IXGBE_PMD
11753         if (ret == -ENOTSUP)
11754                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11755 #endif
11756 #ifdef RTE_LIBRTE_I40E_PMD
11757         if (ret == -ENOTSUP)
11758                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11759 #endif
11760 #ifdef RTE_LIBRTE_BNXT_PMD
11761         if (ret == -ENOTSUP)
11762                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11763 #endif
11764
11765         switch (ret) {
11766         case 0:
11767                 break;
11768         case -EINVAL:
11769                 printf("invalid is_on %d\n", is_on);
11770                 break;
11771         case -ENODEV:
11772                 printf("invalid port_id %d\n", res->port_id);
11773                 break;
11774         case -ENOTSUP:
11775                 printf("function not implemented\n");
11776                 break;
11777         default:
11778                 printf("programming error: (%s)\n", strerror(-ret));
11779         }
11780 }
11781
11782 cmdline_parse_inst_t cmd_set_tx_loopback = {
11783         .f = cmd_set_tx_loopback_parsed,
11784         .data = NULL,
11785         .help_str = "set tx loopback <port_id> on|off",
11786         .tokens = {
11787                 (void *)&cmd_tx_loopback_set,
11788                 (void *)&cmd_tx_loopback_tx,
11789                 (void *)&cmd_tx_loopback_loopback,
11790                 (void *)&cmd_tx_loopback_port_id,
11791                 (void *)&cmd_tx_loopback_on_off,
11792                 NULL,
11793         },
11794 };
11795
11796 /* all queues drop enable configuration */
11797
11798 /* Common result structure for all queues drop enable */
11799 struct cmd_all_queues_drop_en_result {
11800         cmdline_fixed_string_t set;
11801         cmdline_fixed_string_t all;
11802         cmdline_fixed_string_t queues;
11803         cmdline_fixed_string_t drop;
11804         uint8_t port_id;
11805         cmdline_fixed_string_t on_off;
11806 };
11807
11808 /* Common CLI fields for tx loopback enable disable */
11809 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_all_queues_drop_en_result,
11812                  set, "set");
11813 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_all_queues_drop_en_result,
11816                  all, "all");
11817 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11818         TOKEN_STRING_INITIALIZER
11819                 (struct cmd_all_queues_drop_en_result,
11820                  queues, "queues");
11821 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_all_queues_drop_en_result,
11824                  drop, "drop");
11825 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11826         TOKEN_NUM_INITIALIZER
11827                 (struct cmd_all_queues_drop_en_result,
11828                  port_id, UINT8);
11829 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_all_queues_drop_en_result,
11832                  on_off, "on#off");
11833
11834 static void
11835 cmd_set_all_queues_drop_en_parsed(
11836         void *parsed_result,
11837         __attribute__((unused)) struct cmdline *cl,
11838         __attribute__((unused)) void *data)
11839 {
11840         struct cmd_all_queues_drop_en_result *res = parsed_result;
11841         int ret = -ENOTSUP;
11842         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11843
11844         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11845                 return;
11846
11847 #ifdef RTE_LIBRTE_IXGBE_PMD
11848         if (ret == -ENOTSUP)
11849                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11850 #endif
11851 #ifdef RTE_LIBRTE_BNXT_PMD
11852         if (ret == -ENOTSUP)
11853                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11854 #endif
11855         switch (ret) {
11856         case 0:
11857                 break;
11858         case -EINVAL:
11859                 printf("invalid is_on %d\n", is_on);
11860                 break;
11861         case -ENODEV:
11862                 printf("invalid port_id %d\n", res->port_id);
11863                 break;
11864         case -ENOTSUP:
11865                 printf("function not implemented\n");
11866                 break;
11867         default:
11868                 printf("programming error: (%s)\n", strerror(-ret));
11869         }
11870 }
11871
11872 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11873         .f = cmd_set_all_queues_drop_en_parsed,
11874         .data = NULL,
11875         .help_str = "set all queues drop <port_id> on|off",
11876         .tokens = {
11877                 (void *)&cmd_all_queues_drop_en_set,
11878                 (void *)&cmd_all_queues_drop_en_all,
11879                 (void *)&cmd_all_queues_drop_en_queues,
11880                 (void *)&cmd_all_queues_drop_en_drop,
11881                 (void *)&cmd_all_queues_drop_en_port_id,
11882                 (void *)&cmd_all_queues_drop_en_on_off,
11883                 NULL,
11884         },
11885 };
11886
11887 /* vf split drop enable configuration */
11888
11889 /* Common result structure for vf split drop enable */
11890 struct cmd_vf_split_drop_en_result {
11891         cmdline_fixed_string_t set;
11892         cmdline_fixed_string_t vf;
11893         cmdline_fixed_string_t split;
11894         cmdline_fixed_string_t drop;
11895         uint8_t port_id;
11896         uint16_t vf_id;
11897         cmdline_fixed_string_t on_off;
11898 };
11899
11900 /* Common CLI fields for vf split drop enable disable */
11901 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11902         TOKEN_STRING_INITIALIZER
11903                 (struct cmd_vf_split_drop_en_result,
11904                  set, "set");
11905 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11906         TOKEN_STRING_INITIALIZER
11907                 (struct cmd_vf_split_drop_en_result,
11908                  vf, "vf");
11909 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11910         TOKEN_STRING_INITIALIZER
11911                 (struct cmd_vf_split_drop_en_result,
11912                  split, "split");
11913 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11914         TOKEN_STRING_INITIALIZER
11915                 (struct cmd_vf_split_drop_en_result,
11916                  drop, "drop");
11917 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11918         TOKEN_NUM_INITIALIZER
11919                 (struct cmd_vf_split_drop_en_result,
11920                  port_id, UINT8);
11921 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11922         TOKEN_NUM_INITIALIZER
11923                 (struct cmd_vf_split_drop_en_result,
11924                  vf_id, UINT16);
11925 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11926         TOKEN_STRING_INITIALIZER
11927                 (struct cmd_vf_split_drop_en_result,
11928                  on_off, "on#off");
11929
11930 static void
11931 cmd_set_vf_split_drop_en_parsed(
11932         void *parsed_result,
11933         __attribute__((unused)) struct cmdline *cl,
11934         __attribute__((unused)) void *data)
11935 {
11936         struct cmd_vf_split_drop_en_result *res = parsed_result;
11937         int ret = -ENOTSUP;
11938         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11939
11940         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11941                 return;
11942
11943 #ifdef RTE_LIBRTE_IXGBE_PMD
11944         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11945                         is_on);
11946 #endif
11947         switch (ret) {
11948         case 0:
11949                 break;
11950         case -EINVAL:
11951                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11952                 break;
11953         case -ENODEV:
11954                 printf("invalid port_id %d\n", res->port_id);
11955                 break;
11956         case -ENOTSUP:
11957                 printf("not supported on port %d\n", res->port_id);
11958                 break;
11959         default:
11960                 printf("programming error: (%s)\n", strerror(-ret));
11961         }
11962 }
11963
11964 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11965         .f = cmd_set_vf_split_drop_en_parsed,
11966         .data = NULL,
11967         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11968         .tokens = {
11969                 (void *)&cmd_vf_split_drop_en_set,
11970                 (void *)&cmd_vf_split_drop_en_vf,
11971                 (void *)&cmd_vf_split_drop_en_split,
11972                 (void *)&cmd_vf_split_drop_en_drop,
11973                 (void *)&cmd_vf_split_drop_en_port_id,
11974                 (void *)&cmd_vf_split_drop_en_vf_id,
11975                 (void *)&cmd_vf_split_drop_en_on_off,
11976                 NULL,
11977         },
11978 };
11979
11980 /* vf mac address configuration */
11981
11982 /* Common result structure for vf mac address */
11983 struct cmd_set_vf_mac_addr_result {
11984         cmdline_fixed_string_t set;
11985         cmdline_fixed_string_t vf;
11986         cmdline_fixed_string_t mac;
11987         cmdline_fixed_string_t addr;
11988         uint8_t port_id;
11989         uint16_t vf_id;
11990         struct ether_addr mac_addr;
11991
11992 };
11993
11994 /* Common CLI fields for vf split drop enable disable */
11995 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11996         TOKEN_STRING_INITIALIZER
11997                 (struct cmd_set_vf_mac_addr_result,
11998                  set, "set");
11999 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_set_vf_mac_addr_result,
12002                  vf, "vf");
12003 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12004         TOKEN_STRING_INITIALIZER
12005                 (struct cmd_set_vf_mac_addr_result,
12006                  mac, "mac");
12007 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_set_vf_mac_addr_result,
12010                  addr, "addr");
12011 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12012         TOKEN_NUM_INITIALIZER
12013                 (struct cmd_set_vf_mac_addr_result,
12014                  port_id, UINT8);
12015 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12016         TOKEN_NUM_INITIALIZER
12017                 (struct cmd_set_vf_mac_addr_result,
12018                  vf_id, UINT16);
12019 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12020         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12021                  mac_addr);
12022
12023 static void
12024 cmd_set_vf_mac_addr_parsed(
12025         void *parsed_result,
12026         __attribute__((unused)) struct cmdline *cl,
12027         __attribute__((unused)) void *data)
12028 {
12029         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12030         int ret = -ENOTSUP;
12031
12032         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12033                 return;
12034
12035 #ifdef RTE_LIBRTE_IXGBE_PMD
12036         if (ret == -ENOTSUP)
12037                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12038                                 &res->mac_addr);
12039 #endif
12040 #ifdef RTE_LIBRTE_I40E_PMD
12041         if (ret == -ENOTSUP)
12042                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12043                                 &res->mac_addr);
12044 #endif
12045 #ifdef RTE_LIBRTE_BNXT_PMD
12046         if (ret == -ENOTSUP)
12047                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12048                                 &res->mac_addr);
12049 #endif
12050
12051         switch (ret) {
12052         case 0:
12053                 break;
12054         case -EINVAL:
12055                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12056                 break;
12057         case -ENODEV:
12058                 printf("invalid port_id %d\n", res->port_id);
12059                 break;
12060         case -ENOTSUP:
12061                 printf("function not implemented\n");
12062                 break;
12063         default:
12064                 printf("programming error: (%s)\n", strerror(-ret));
12065         }
12066 }
12067
12068 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12069         .f = cmd_set_vf_mac_addr_parsed,
12070         .data = NULL,
12071         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12072         .tokens = {
12073                 (void *)&cmd_set_vf_mac_addr_set,
12074                 (void *)&cmd_set_vf_mac_addr_vf,
12075                 (void *)&cmd_set_vf_mac_addr_mac,
12076                 (void *)&cmd_set_vf_mac_addr_addr,
12077                 (void *)&cmd_set_vf_mac_addr_port_id,
12078                 (void *)&cmd_set_vf_mac_addr_vf_id,
12079                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12080                 NULL,
12081         },
12082 };
12083
12084 /* MACsec configuration */
12085
12086 /* Common result structure for MACsec offload enable */
12087 struct cmd_macsec_offload_on_result {
12088         cmdline_fixed_string_t set;
12089         cmdline_fixed_string_t macsec;
12090         cmdline_fixed_string_t offload;
12091         uint8_t port_id;
12092         cmdline_fixed_string_t on;
12093         cmdline_fixed_string_t encrypt;
12094         cmdline_fixed_string_t en_on_off;
12095         cmdline_fixed_string_t replay_protect;
12096         cmdline_fixed_string_t rp_on_off;
12097 };
12098
12099 /* Common CLI fields for MACsec offload disable */
12100 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12101         TOKEN_STRING_INITIALIZER
12102                 (struct cmd_macsec_offload_on_result,
12103                  set, "set");
12104 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12105         TOKEN_STRING_INITIALIZER
12106                 (struct cmd_macsec_offload_on_result,
12107                  macsec, "macsec");
12108 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12109         TOKEN_STRING_INITIALIZER
12110                 (struct cmd_macsec_offload_on_result,
12111                  offload, "offload");
12112 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12113         TOKEN_NUM_INITIALIZER
12114                 (struct cmd_macsec_offload_on_result,
12115                  port_id, UINT8);
12116 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12117         TOKEN_STRING_INITIALIZER
12118                 (struct cmd_macsec_offload_on_result,
12119                  on, "on");
12120 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12121         TOKEN_STRING_INITIALIZER
12122                 (struct cmd_macsec_offload_on_result,
12123                  encrypt, "encrypt");
12124 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12125         TOKEN_STRING_INITIALIZER
12126                 (struct cmd_macsec_offload_on_result,
12127                  en_on_off, "on#off");
12128 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12129         TOKEN_STRING_INITIALIZER
12130                 (struct cmd_macsec_offload_on_result,
12131                  replay_protect, "replay-protect");
12132 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12133         TOKEN_STRING_INITIALIZER
12134                 (struct cmd_macsec_offload_on_result,
12135                  rp_on_off, "on#off");
12136
12137 static void
12138 cmd_set_macsec_offload_on_parsed(
12139         void *parsed_result,
12140         __attribute__((unused)) struct cmdline *cl,
12141         __attribute__((unused)) void *data)
12142 {
12143         struct cmd_macsec_offload_on_result *res = parsed_result;
12144         int ret = -ENOTSUP;
12145         portid_t port_id = res->port_id;
12146         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12147         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12148
12149         if (port_id_is_invalid(port_id, ENABLED_WARN))
12150                 return;
12151
12152         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12153 #ifdef RTE_LIBRTE_IXGBE_PMD
12154         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12155 #endif
12156         RTE_SET_USED(en);
12157         RTE_SET_USED(rp);
12158
12159         switch (ret) {
12160         case 0:
12161                 break;
12162         case -ENODEV:
12163                 printf("invalid port_id %d\n", port_id);
12164                 break;
12165         case -ENOTSUP:
12166                 printf("not supported on port %d\n", port_id);
12167                 break;
12168         default:
12169                 printf("programming error: (%s)\n", strerror(-ret));
12170         }
12171 }
12172
12173 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12174         .f = cmd_set_macsec_offload_on_parsed,
12175         .data = NULL,
12176         .help_str = "set macsec offload <port_id> on "
12177                 "encrypt on|off replay-protect on|off",
12178         .tokens = {
12179                 (void *)&cmd_macsec_offload_on_set,
12180                 (void *)&cmd_macsec_offload_on_macsec,
12181                 (void *)&cmd_macsec_offload_on_offload,
12182                 (void *)&cmd_macsec_offload_on_port_id,
12183                 (void *)&cmd_macsec_offload_on_on,
12184                 (void *)&cmd_macsec_offload_on_encrypt,
12185                 (void *)&cmd_macsec_offload_on_en_on_off,
12186                 (void *)&cmd_macsec_offload_on_replay_protect,
12187                 (void *)&cmd_macsec_offload_on_rp_on_off,
12188                 NULL,
12189         },
12190 };
12191
12192 /* Common result structure for MACsec offload disable */
12193 struct cmd_macsec_offload_off_result {
12194         cmdline_fixed_string_t set;
12195         cmdline_fixed_string_t macsec;
12196         cmdline_fixed_string_t offload;
12197         uint8_t port_id;
12198         cmdline_fixed_string_t off;
12199 };
12200
12201 /* Common CLI fields for MACsec offload disable */
12202 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_macsec_offload_off_result,
12205                  set, "set");
12206 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12207         TOKEN_STRING_INITIALIZER
12208                 (struct cmd_macsec_offload_off_result,
12209                  macsec, "macsec");
12210 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12211         TOKEN_STRING_INITIALIZER
12212                 (struct cmd_macsec_offload_off_result,
12213                  offload, "offload");
12214 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12215         TOKEN_NUM_INITIALIZER
12216                 (struct cmd_macsec_offload_off_result,
12217                  port_id, UINT8);
12218 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_macsec_offload_off_result,
12221                  off, "off");
12222
12223 static void
12224 cmd_set_macsec_offload_off_parsed(
12225         void *parsed_result,
12226         __attribute__((unused)) struct cmdline *cl,
12227         __attribute__((unused)) void *data)
12228 {
12229         struct cmd_macsec_offload_off_result *res = parsed_result;
12230         int ret = -ENOTSUP;
12231         portid_t port_id = res->port_id;
12232
12233         if (port_id_is_invalid(port_id, ENABLED_WARN))
12234                 return;
12235
12236         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12237 #ifdef RTE_LIBRTE_IXGBE_PMD
12238         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12239 #endif
12240
12241         switch (ret) {
12242         case 0:
12243                 break;
12244         case -ENODEV:
12245                 printf("invalid port_id %d\n", port_id);
12246                 break;
12247         case -ENOTSUP:
12248                 printf("not supported on port %d\n", port_id);
12249                 break;
12250         default:
12251                 printf("programming error: (%s)\n", strerror(-ret));
12252         }
12253 }
12254
12255 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12256         .f = cmd_set_macsec_offload_off_parsed,
12257         .data = NULL,
12258         .help_str = "set macsec offload <port_id> off",
12259         .tokens = {
12260                 (void *)&cmd_macsec_offload_off_set,
12261                 (void *)&cmd_macsec_offload_off_macsec,
12262                 (void *)&cmd_macsec_offload_off_offload,
12263                 (void *)&cmd_macsec_offload_off_port_id,
12264                 (void *)&cmd_macsec_offload_off_off,
12265                 NULL,
12266         },
12267 };
12268
12269 /* Common result structure for MACsec secure connection configure */
12270 struct cmd_macsec_sc_result {
12271         cmdline_fixed_string_t set;
12272         cmdline_fixed_string_t macsec;
12273         cmdline_fixed_string_t sc;
12274         cmdline_fixed_string_t tx_rx;
12275         uint8_t port_id;
12276         struct ether_addr mac;
12277         uint16_t pi;
12278 };
12279
12280 /* Common CLI fields for MACsec secure connection configure */
12281 cmdline_parse_token_string_t cmd_macsec_sc_set =
12282         TOKEN_STRING_INITIALIZER
12283                 (struct cmd_macsec_sc_result,
12284                  set, "set");
12285 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12286         TOKEN_STRING_INITIALIZER
12287                 (struct cmd_macsec_sc_result,
12288                  macsec, "macsec");
12289 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12290         TOKEN_STRING_INITIALIZER
12291                 (struct cmd_macsec_sc_result,
12292                  sc, "sc");
12293 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12294         TOKEN_STRING_INITIALIZER
12295                 (struct cmd_macsec_sc_result,
12296                  tx_rx, "tx#rx");
12297 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12298         TOKEN_NUM_INITIALIZER
12299                 (struct cmd_macsec_sc_result,
12300                  port_id, UINT8);
12301 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12302         TOKEN_ETHERADDR_INITIALIZER
12303                 (struct cmd_macsec_sc_result,
12304                  mac);
12305 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12306         TOKEN_NUM_INITIALIZER
12307                 (struct cmd_macsec_sc_result,
12308                  pi, UINT16);
12309
12310 static void
12311 cmd_set_macsec_sc_parsed(
12312         void *parsed_result,
12313         __attribute__((unused)) struct cmdline *cl,
12314         __attribute__((unused)) void *data)
12315 {
12316         struct cmd_macsec_sc_result *res = parsed_result;
12317         int ret = -ENOTSUP;
12318         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12319
12320 #ifdef RTE_LIBRTE_IXGBE_PMD
12321         ret = is_tx ?
12322                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12323                                 res->mac.addr_bytes) :
12324                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12325                                 res->mac.addr_bytes, res->pi);
12326 #endif
12327         RTE_SET_USED(is_tx);
12328
12329         switch (ret) {
12330         case 0:
12331                 break;
12332         case -ENODEV:
12333                 printf("invalid port_id %d\n", res->port_id);
12334                 break;
12335         case -ENOTSUP:
12336                 printf("not supported on port %d\n", res->port_id);
12337                 break;
12338         default:
12339                 printf("programming error: (%s)\n", strerror(-ret));
12340         }
12341 }
12342
12343 cmdline_parse_inst_t cmd_set_macsec_sc = {
12344         .f = cmd_set_macsec_sc_parsed,
12345         .data = NULL,
12346         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12347         .tokens = {
12348                 (void *)&cmd_macsec_sc_set,
12349                 (void *)&cmd_macsec_sc_macsec,
12350                 (void *)&cmd_macsec_sc_sc,
12351                 (void *)&cmd_macsec_sc_tx_rx,
12352                 (void *)&cmd_macsec_sc_port_id,
12353                 (void *)&cmd_macsec_sc_mac,
12354                 (void *)&cmd_macsec_sc_pi,
12355                 NULL,
12356         },
12357 };
12358
12359 /* Common result structure for MACsec secure connection configure */
12360 struct cmd_macsec_sa_result {
12361         cmdline_fixed_string_t set;
12362         cmdline_fixed_string_t macsec;
12363         cmdline_fixed_string_t sa;
12364         cmdline_fixed_string_t tx_rx;
12365         uint8_t port_id;
12366         uint8_t idx;
12367         uint8_t an;
12368         uint32_t pn;
12369         cmdline_fixed_string_t key;
12370 };
12371
12372 /* Common CLI fields for MACsec secure connection configure */
12373 cmdline_parse_token_string_t cmd_macsec_sa_set =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_macsec_sa_result,
12376                  set, "set");
12377 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12378         TOKEN_STRING_INITIALIZER
12379                 (struct cmd_macsec_sa_result,
12380                  macsec, "macsec");
12381 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12382         TOKEN_STRING_INITIALIZER
12383                 (struct cmd_macsec_sa_result,
12384                  sa, "sa");
12385 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12386         TOKEN_STRING_INITIALIZER
12387                 (struct cmd_macsec_sa_result,
12388                  tx_rx, "tx#rx");
12389 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12390         TOKEN_NUM_INITIALIZER
12391                 (struct cmd_macsec_sa_result,
12392                  port_id, UINT8);
12393 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12394         TOKEN_NUM_INITIALIZER
12395                 (struct cmd_macsec_sa_result,
12396                  idx, UINT8);
12397 cmdline_parse_token_num_t cmd_macsec_sa_an =
12398         TOKEN_NUM_INITIALIZER
12399                 (struct cmd_macsec_sa_result,
12400                  an, UINT8);
12401 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12402         TOKEN_NUM_INITIALIZER
12403                 (struct cmd_macsec_sa_result,
12404                  pn, UINT32);
12405 cmdline_parse_token_string_t cmd_macsec_sa_key =
12406         TOKEN_STRING_INITIALIZER
12407                 (struct cmd_macsec_sa_result,
12408                  key, NULL);
12409
12410 static void
12411 cmd_set_macsec_sa_parsed(
12412         void *parsed_result,
12413         __attribute__((unused)) struct cmdline *cl,
12414         __attribute__((unused)) void *data)
12415 {
12416         struct cmd_macsec_sa_result *res = parsed_result;
12417         int ret = -ENOTSUP;
12418         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12419         uint8_t key[16] = { 0 };
12420         uint8_t xdgt0;
12421         uint8_t xdgt1;
12422         int key_len;
12423         int i;
12424
12425         key_len = strlen(res->key) / 2;
12426         if (key_len > 16)
12427                 key_len = 16;
12428
12429         for (i = 0; i < key_len; i++) {
12430                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12431                 if (xdgt0 == 0xFF)
12432                         return;
12433                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12434                 if (xdgt1 == 0xFF)
12435                         return;
12436                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12437         }
12438
12439 #ifdef RTE_LIBRTE_IXGBE_PMD
12440         ret = is_tx ?
12441                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12442                         res->idx, res->an, res->pn, key) :
12443                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12444                         res->idx, res->an, res->pn, key);
12445 #endif
12446         RTE_SET_USED(is_tx);
12447         RTE_SET_USED(key);
12448
12449         switch (ret) {
12450         case 0:
12451                 break;
12452         case -EINVAL:
12453                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12454                 break;
12455         case -ENODEV:
12456                 printf("invalid port_id %d\n", res->port_id);
12457                 break;
12458         case -ENOTSUP:
12459                 printf("not supported on port %d\n", res->port_id);
12460                 break;
12461         default:
12462                 printf("programming error: (%s)\n", strerror(-ret));
12463         }
12464 }
12465
12466 cmdline_parse_inst_t cmd_set_macsec_sa = {
12467         .f = cmd_set_macsec_sa_parsed,
12468         .data = NULL,
12469         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12470         .tokens = {
12471                 (void *)&cmd_macsec_sa_set,
12472                 (void *)&cmd_macsec_sa_macsec,
12473                 (void *)&cmd_macsec_sa_sa,
12474                 (void *)&cmd_macsec_sa_tx_rx,
12475                 (void *)&cmd_macsec_sa_port_id,
12476                 (void *)&cmd_macsec_sa_idx,
12477                 (void *)&cmd_macsec_sa_an,
12478                 (void *)&cmd_macsec_sa_pn,
12479                 (void *)&cmd_macsec_sa_key,
12480                 NULL,
12481         },
12482 };
12483
12484 /* VF unicast promiscuous mode configuration */
12485
12486 /* Common result structure for VF unicast promiscuous mode */
12487 struct cmd_vf_promisc_result {
12488         cmdline_fixed_string_t set;
12489         cmdline_fixed_string_t vf;
12490         cmdline_fixed_string_t promisc;
12491         uint8_t port_id;
12492         uint32_t vf_id;
12493         cmdline_fixed_string_t on_off;
12494 };
12495
12496 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12497 cmdline_parse_token_string_t cmd_vf_promisc_set =
12498         TOKEN_STRING_INITIALIZER
12499                 (struct cmd_vf_promisc_result,
12500                  set, "set");
12501 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12502         TOKEN_STRING_INITIALIZER
12503                 (struct cmd_vf_promisc_result,
12504                  vf, "vf");
12505 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12506         TOKEN_STRING_INITIALIZER
12507                 (struct cmd_vf_promisc_result,
12508                  promisc, "promisc");
12509 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12510         TOKEN_NUM_INITIALIZER
12511                 (struct cmd_vf_promisc_result,
12512                  port_id, UINT8);
12513 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12514         TOKEN_NUM_INITIALIZER
12515                 (struct cmd_vf_promisc_result,
12516                  vf_id, UINT32);
12517 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12518         TOKEN_STRING_INITIALIZER
12519                 (struct cmd_vf_promisc_result,
12520                  on_off, "on#off");
12521
12522 static void
12523 cmd_set_vf_promisc_parsed(
12524         void *parsed_result,
12525         __attribute__((unused)) struct cmdline *cl,
12526         __attribute__((unused)) void *data)
12527 {
12528         struct cmd_vf_promisc_result *res = parsed_result;
12529         int ret = -ENOTSUP;
12530
12531         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12532
12533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12534                 return;
12535
12536 #ifdef RTE_LIBRTE_I40E_PMD
12537         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12538                                                   res->vf_id, is_on);
12539 #endif
12540
12541         switch (ret) {
12542         case 0:
12543                 break;
12544         case -EINVAL:
12545                 printf("invalid vf_id %d\n", res->vf_id);
12546                 break;
12547         case -ENODEV:
12548                 printf("invalid port_id %d\n", res->port_id);
12549                 break;
12550         case -ENOTSUP:
12551                 printf("function not implemented\n");
12552                 break;
12553         default:
12554                 printf("programming error: (%s)\n", strerror(-ret));
12555         }
12556 }
12557
12558 cmdline_parse_inst_t cmd_set_vf_promisc = {
12559         .f = cmd_set_vf_promisc_parsed,
12560         .data = NULL,
12561         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12562                 "Set unicast promiscuous mode for a VF from the PF",
12563         .tokens = {
12564                 (void *)&cmd_vf_promisc_set,
12565                 (void *)&cmd_vf_promisc_vf,
12566                 (void *)&cmd_vf_promisc_promisc,
12567                 (void *)&cmd_vf_promisc_port_id,
12568                 (void *)&cmd_vf_promisc_vf_id,
12569                 (void *)&cmd_vf_promisc_on_off,
12570                 NULL,
12571         },
12572 };
12573
12574 /* VF multicast promiscuous mode configuration */
12575
12576 /* Common result structure for VF multicast promiscuous mode */
12577 struct cmd_vf_allmulti_result {
12578         cmdline_fixed_string_t set;
12579         cmdline_fixed_string_t vf;
12580         cmdline_fixed_string_t allmulti;
12581         uint8_t port_id;
12582         uint32_t vf_id;
12583         cmdline_fixed_string_t on_off;
12584 };
12585
12586 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12587 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12588         TOKEN_STRING_INITIALIZER
12589                 (struct cmd_vf_allmulti_result,
12590                  set, "set");
12591 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12592         TOKEN_STRING_INITIALIZER
12593                 (struct cmd_vf_allmulti_result,
12594                  vf, "vf");
12595 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12596         TOKEN_STRING_INITIALIZER
12597                 (struct cmd_vf_allmulti_result,
12598                  allmulti, "allmulti");
12599 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12600         TOKEN_NUM_INITIALIZER
12601                 (struct cmd_vf_allmulti_result,
12602                  port_id, UINT8);
12603 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12604         TOKEN_NUM_INITIALIZER
12605                 (struct cmd_vf_allmulti_result,
12606                  vf_id, UINT32);
12607 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12608         TOKEN_STRING_INITIALIZER
12609                 (struct cmd_vf_allmulti_result,
12610                  on_off, "on#off");
12611
12612 static void
12613 cmd_set_vf_allmulti_parsed(
12614         void *parsed_result,
12615         __attribute__((unused)) struct cmdline *cl,
12616         __attribute__((unused)) void *data)
12617 {
12618         struct cmd_vf_allmulti_result *res = parsed_result;
12619         int ret = -ENOTSUP;
12620
12621         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12622
12623         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12624                 return;
12625
12626 #ifdef RTE_LIBRTE_I40E_PMD
12627         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12628                                                     res->vf_id, is_on);
12629 #endif
12630
12631         switch (ret) {
12632         case 0:
12633                 break;
12634         case -EINVAL:
12635                 printf("invalid vf_id %d\n", res->vf_id);
12636                 break;
12637         case -ENODEV:
12638                 printf("invalid port_id %d\n", res->port_id);
12639                 break;
12640         case -ENOTSUP:
12641                 printf("function not implemented\n");
12642                 break;
12643         default:
12644                 printf("programming error: (%s)\n", strerror(-ret));
12645         }
12646 }
12647
12648 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12649         .f = cmd_set_vf_allmulti_parsed,
12650         .data = NULL,
12651         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12652                 "Set multicast promiscuous mode for a VF from the PF",
12653         .tokens = {
12654                 (void *)&cmd_vf_allmulti_set,
12655                 (void *)&cmd_vf_allmulti_vf,
12656                 (void *)&cmd_vf_allmulti_allmulti,
12657                 (void *)&cmd_vf_allmulti_port_id,
12658                 (void *)&cmd_vf_allmulti_vf_id,
12659                 (void *)&cmd_vf_allmulti_on_off,
12660                 NULL,
12661         },
12662 };
12663
12664 /* vf broadcast mode configuration */
12665
12666 /* Common result structure for vf broadcast */
12667 struct cmd_set_vf_broadcast_result {
12668         cmdline_fixed_string_t set;
12669         cmdline_fixed_string_t vf;
12670         cmdline_fixed_string_t broadcast;
12671         uint8_t port_id;
12672         uint16_t vf_id;
12673         cmdline_fixed_string_t on_off;
12674 };
12675
12676 /* Common CLI fields for vf broadcast enable disable */
12677 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_set_vf_broadcast_result,
12680                  set, "set");
12681 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_set_vf_broadcast_result,
12684                  vf, "vf");
12685 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_set_vf_broadcast_result,
12688                  broadcast, "broadcast");
12689 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12690         TOKEN_NUM_INITIALIZER
12691                 (struct cmd_set_vf_broadcast_result,
12692                  port_id, UINT8);
12693 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12694         TOKEN_NUM_INITIALIZER
12695                 (struct cmd_set_vf_broadcast_result,
12696                  vf_id, UINT16);
12697 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_set_vf_broadcast_result,
12700                  on_off, "on#off");
12701
12702 static void
12703 cmd_set_vf_broadcast_parsed(
12704         void *parsed_result,
12705         __attribute__((unused)) struct cmdline *cl,
12706         __attribute__((unused)) void *data)
12707 {
12708         struct cmd_set_vf_broadcast_result *res = parsed_result;
12709         int ret = -ENOTSUP;
12710
12711         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12712
12713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12714                 return;
12715
12716 #ifdef RTE_LIBRTE_I40E_PMD
12717         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12718                                             res->vf_id, is_on);
12719 #endif
12720
12721         switch (ret) {
12722         case 0:
12723                 break;
12724         case -EINVAL:
12725                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12726                 break;
12727         case -ENODEV:
12728                 printf("invalid port_id %d\n", res->port_id);
12729                 break;
12730         case -ENOTSUP:
12731                 printf("function not implemented\n");
12732                 break;
12733         default:
12734                 printf("programming error: (%s)\n", strerror(-ret));
12735         }
12736 }
12737
12738 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12739         .f = cmd_set_vf_broadcast_parsed,
12740         .data = NULL,
12741         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12742         .tokens = {
12743                 (void *)&cmd_set_vf_broadcast_set,
12744                 (void *)&cmd_set_vf_broadcast_vf,
12745                 (void *)&cmd_set_vf_broadcast_broadcast,
12746                 (void *)&cmd_set_vf_broadcast_port_id,
12747                 (void *)&cmd_set_vf_broadcast_vf_id,
12748                 (void *)&cmd_set_vf_broadcast_on_off,
12749                 NULL,
12750         },
12751 };
12752
12753 /* vf vlan tag configuration */
12754
12755 /* Common result structure for vf vlan tag */
12756 struct cmd_set_vf_vlan_tag_result {
12757         cmdline_fixed_string_t set;
12758         cmdline_fixed_string_t vf;
12759         cmdline_fixed_string_t vlan;
12760         cmdline_fixed_string_t tag;
12761         uint8_t port_id;
12762         uint16_t vf_id;
12763         cmdline_fixed_string_t on_off;
12764 };
12765
12766 /* Common CLI fields for vf vlan tag enable disable */
12767 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12768         TOKEN_STRING_INITIALIZER
12769                 (struct cmd_set_vf_vlan_tag_result,
12770                  set, "set");
12771 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12772         TOKEN_STRING_INITIALIZER
12773                 (struct cmd_set_vf_vlan_tag_result,
12774                  vf, "vf");
12775 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_set_vf_vlan_tag_result,
12778                  vlan, "vlan");
12779 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12780         TOKEN_STRING_INITIALIZER
12781                 (struct cmd_set_vf_vlan_tag_result,
12782                  tag, "tag");
12783 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12784         TOKEN_NUM_INITIALIZER
12785                 (struct cmd_set_vf_vlan_tag_result,
12786                  port_id, UINT8);
12787 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12788         TOKEN_NUM_INITIALIZER
12789                 (struct cmd_set_vf_vlan_tag_result,
12790                  vf_id, UINT16);
12791 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12792         TOKEN_STRING_INITIALIZER
12793                 (struct cmd_set_vf_vlan_tag_result,
12794                  on_off, "on#off");
12795
12796 static void
12797 cmd_set_vf_vlan_tag_parsed(
12798         void *parsed_result,
12799         __attribute__((unused)) struct cmdline *cl,
12800         __attribute__((unused)) void *data)
12801 {
12802         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12803         int ret = -ENOTSUP;
12804
12805         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12806
12807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12808                 return;
12809
12810 #ifdef RTE_LIBRTE_I40E_PMD
12811         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12812                                            res->vf_id, is_on);
12813 #endif
12814
12815         switch (ret) {
12816         case 0:
12817                 break;
12818         case -EINVAL:
12819                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12820                 break;
12821         case -ENODEV:
12822                 printf("invalid port_id %d\n", res->port_id);
12823                 break;
12824         case -ENOTSUP:
12825                 printf("function not implemented\n");
12826                 break;
12827         default:
12828                 printf("programming error: (%s)\n", strerror(-ret));
12829         }
12830 }
12831
12832 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12833         .f = cmd_set_vf_vlan_tag_parsed,
12834         .data = NULL,
12835         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12836         .tokens = {
12837                 (void *)&cmd_set_vf_vlan_tag_set,
12838                 (void *)&cmd_set_vf_vlan_tag_vf,
12839                 (void *)&cmd_set_vf_vlan_tag_vlan,
12840                 (void *)&cmd_set_vf_vlan_tag_tag,
12841                 (void *)&cmd_set_vf_vlan_tag_port_id,
12842                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12843                 (void *)&cmd_set_vf_vlan_tag_on_off,
12844                 NULL,
12845         },
12846 };
12847
12848 /* Common definition of VF and TC TX bandwidth configuration */
12849 struct cmd_vf_tc_bw_result {
12850         cmdline_fixed_string_t set;
12851         cmdline_fixed_string_t vf;
12852         cmdline_fixed_string_t tc;
12853         cmdline_fixed_string_t tx;
12854         cmdline_fixed_string_t min_bw;
12855         cmdline_fixed_string_t max_bw;
12856         cmdline_fixed_string_t strict_link_prio;
12857         uint8_t port_id;
12858         uint16_t vf_id;
12859         uint8_t tc_no;
12860         uint32_t bw;
12861         cmdline_fixed_string_t bw_list;
12862         uint8_t tc_map;
12863 };
12864
12865 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_vf_tc_bw_result,
12868                  set, "set");
12869 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12870         TOKEN_STRING_INITIALIZER
12871                 (struct cmd_vf_tc_bw_result,
12872                  vf, "vf");
12873 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12874         TOKEN_STRING_INITIALIZER
12875                 (struct cmd_vf_tc_bw_result,
12876                  tc, "tc");
12877 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_vf_tc_bw_result,
12880                  tx, "tx");
12881 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_vf_tc_bw_result,
12884                  strict_link_prio, "strict-link-priority");
12885 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_vf_tc_bw_result,
12888                  min_bw, "min-bandwidth");
12889 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12890         TOKEN_STRING_INITIALIZER
12891                 (struct cmd_vf_tc_bw_result,
12892                  max_bw, "max-bandwidth");
12893 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12894         TOKEN_NUM_INITIALIZER
12895                 (struct cmd_vf_tc_bw_result,
12896                  port_id, UINT8);
12897 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12898         TOKEN_NUM_INITIALIZER
12899                 (struct cmd_vf_tc_bw_result,
12900                  vf_id, UINT16);
12901 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12902         TOKEN_NUM_INITIALIZER
12903                 (struct cmd_vf_tc_bw_result,
12904                  tc_no, UINT8);
12905 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12906         TOKEN_NUM_INITIALIZER
12907                 (struct cmd_vf_tc_bw_result,
12908                  bw, UINT32);
12909 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_vf_tc_bw_result,
12912                  bw_list, NULL);
12913 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12914         TOKEN_NUM_INITIALIZER
12915                 (struct cmd_vf_tc_bw_result,
12916                  tc_map, UINT8);
12917
12918 /* VF max bandwidth setting */
12919 static void
12920 cmd_vf_max_bw_parsed(
12921         void *parsed_result,
12922         __attribute__((unused)) struct cmdline *cl,
12923         __attribute__((unused)) void *data)
12924 {
12925         struct cmd_vf_tc_bw_result *res = parsed_result;
12926         int ret = -ENOTSUP;
12927
12928         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12929                 return;
12930
12931 #ifdef RTE_LIBRTE_I40E_PMD
12932         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12933                                          res->vf_id, res->bw);
12934 #endif
12935
12936         switch (ret) {
12937         case 0:
12938                 break;
12939         case -EINVAL:
12940                 printf("invalid vf_id %d or bandwidth %d\n",
12941                        res->vf_id, res->bw);
12942                 break;
12943         case -ENODEV:
12944                 printf("invalid port_id %d\n", res->port_id);
12945                 break;
12946         case -ENOTSUP:
12947                 printf("function not implemented\n");
12948                 break;
12949         default:
12950                 printf("programming error: (%s)\n", strerror(-ret));
12951         }
12952 }
12953
12954 cmdline_parse_inst_t cmd_vf_max_bw = {
12955         .f = cmd_vf_max_bw_parsed,
12956         .data = NULL,
12957         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12958         .tokens = {
12959                 (void *)&cmd_vf_tc_bw_set,
12960                 (void *)&cmd_vf_tc_bw_vf,
12961                 (void *)&cmd_vf_tc_bw_tx,
12962                 (void *)&cmd_vf_tc_bw_max_bw,
12963                 (void *)&cmd_vf_tc_bw_port_id,
12964                 (void *)&cmd_vf_tc_bw_vf_id,
12965                 (void *)&cmd_vf_tc_bw_bw,
12966                 NULL,
12967         },
12968 };
12969
12970 static int
12971 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12972                            uint8_t *tc_num,
12973                            char *str)
12974 {
12975         uint32_t size;
12976         const char *p, *p0 = str;
12977         char s[256];
12978         char *end;
12979         char *str_fld[16];
12980         uint16_t i;
12981         int ret;
12982
12983         p = strchr(p0, '(');
12984         if (p == NULL) {
12985                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12986                 return -1;
12987         }
12988         p++;
12989         p0 = strchr(p, ')');
12990         if (p0 == NULL) {
12991                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12992                 return -1;
12993         }
12994         size = p0 - p;
12995         if (size >= sizeof(s)) {
12996                 printf("The string size exceeds the internal buffer size\n");
12997                 return -1;
12998         }
12999         snprintf(s, sizeof(s), "%.*s", size, p);
13000         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13001         if (ret <= 0) {
13002                 printf("Failed to get the bandwidth list. ");
13003                 return -1;
13004         }
13005         *tc_num = ret;
13006         for (i = 0; i < ret; i++)
13007                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13008
13009         return 0;
13010 }
13011
13012 /* TC min bandwidth setting */
13013 static void
13014 cmd_vf_tc_min_bw_parsed(
13015         void *parsed_result,
13016         __attribute__((unused)) struct cmdline *cl,
13017         __attribute__((unused)) void *data)
13018 {
13019         struct cmd_vf_tc_bw_result *res = parsed_result;
13020         uint8_t tc_num;
13021         uint8_t bw[16];
13022         int ret = -ENOTSUP;
13023
13024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13025                 return;
13026
13027         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13028         if (ret)
13029                 return;
13030
13031 #ifdef RTE_LIBRTE_I40E_PMD
13032         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13033                                               tc_num, bw);
13034 #endif
13035
13036         switch (ret) {
13037         case 0:
13038                 break;
13039         case -EINVAL:
13040                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13041                 break;
13042         case -ENODEV:
13043                 printf("invalid port_id %d\n", res->port_id);
13044                 break;
13045         case -ENOTSUP:
13046                 printf("function not implemented\n");
13047                 break;
13048         default:
13049                 printf("programming error: (%s)\n", strerror(-ret));
13050         }
13051 }
13052
13053 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13054         .f = cmd_vf_tc_min_bw_parsed,
13055         .data = NULL,
13056         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13057                     " <bw1, bw2, ...>",
13058         .tokens = {
13059                 (void *)&cmd_vf_tc_bw_set,
13060                 (void *)&cmd_vf_tc_bw_vf,
13061                 (void *)&cmd_vf_tc_bw_tc,
13062                 (void *)&cmd_vf_tc_bw_tx,
13063                 (void *)&cmd_vf_tc_bw_min_bw,
13064                 (void *)&cmd_vf_tc_bw_port_id,
13065                 (void *)&cmd_vf_tc_bw_vf_id,
13066                 (void *)&cmd_vf_tc_bw_bw_list,
13067                 NULL,
13068         },
13069 };
13070
13071 static void
13072 cmd_tc_min_bw_parsed(
13073         void *parsed_result,
13074         __attribute__((unused)) struct cmdline *cl,
13075         __attribute__((unused)) void *data)
13076 {
13077         struct cmd_vf_tc_bw_result *res = parsed_result;
13078         struct rte_port *port;
13079         uint8_t tc_num;
13080         uint8_t bw[16];
13081         int ret = -ENOTSUP;
13082
13083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13084                 return;
13085
13086         port = &ports[res->port_id];
13087         /** Check if the port is not started **/
13088         if (port->port_status != RTE_PORT_STOPPED) {
13089                 printf("Please stop port %d first\n", res->port_id);
13090                 return;
13091         }
13092
13093         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13094         if (ret)
13095                 return;
13096
13097 #ifdef RTE_LIBRTE_IXGBE_PMD
13098         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13099 #endif
13100
13101         switch (ret) {
13102         case 0:
13103                 break;
13104         case -EINVAL:
13105                 printf("invalid bandwidth\n");
13106                 break;
13107         case -ENODEV:
13108                 printf("invalid port_id %d\n", res->port_id);
13109                 break;
13110         case -ENOTSUP:
13111                 printf("function not implemented\n");
13112                 break;
13113         default:
13114                 printf("programming error: (%s)\n", strerror(-ret));
13115         }
13116 }
13117
13118 cmdline_parse_inst_t cmd_tc_min_bw = {
13119         .f = cmd_tc_min_bw_parsed,
13120         .data = NULL,
13121         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13122         .tokens = {
13123                 (void *)&cmd_vf_tc_bw_set,
13124                 (void *)&cmd_vf_tc_bw_tc,
13125                 (void *)&cmd_vf_tc_bw_tx,
13126                 (void *)&cmd_vf_tc_bw_min_bw,
13127                 (void *)&cmd_vf_tc_bw_port_id,
13128                 (void *)&cmd_vf_tc_bw_bw_list,
13129                 NULL,
13130         },
13131 };
13132
13133 /* TC max bandwidth setting */
13134 static void
13135 cmd_vf_tc_max_bw_parsed(
13136         void *parsed_result,
13137         __attribute__((unused)) struct cmdline *cl,
13138         __attribute__((unused)) void *data)
13139 {
13140         struct cmd_vf_tc_bw_result *res = parsed_result;
13141         int ret = -ENOTSUP;
13142
13143         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13144                 return;
13145
13146 #ifdef RTE_LIBRTE_I40E_PMD
13147         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13148                                             res->tc_no, res->bw);
13149 #endif
13150
13151         switch (ret) {
13152         case 0:
13153                 break;
13154         case -EINVAL:
13155                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13156                        res->vf_id, res->tc_no, res->bw);
13157                 break;
13158         case -ENODEV:
13159                 printf("invalid port_id %d\n", res->port_id);
13160                 break;
13161         case -ENOTSUP:
13162                 printf("function not implemented\n");
13163                 break;
13164         default:
13165                 printf("programming error: (%s)\n", strerror(-ret));
13166         }
13167 }
13168
13169 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13170         .f = cmd_vf_tc_max_bw_parsed,
13171         .data = NULL,
13172         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13173                     " <bandwidth>",
13174         .tokens = {
13175                 (void *)&cmd_vf_tc_bw_set,
13176                 (void *)&cmd_vf_tc_bw_vf,
13177                 (void *)&cmd_vf_tc_bw_tc,
13178                 (void *)&cmd_vf_tc_bw_tx,
13179                 (void *)&cmd_vf_tc_bw_max_bw,
13180                 (void *)&cmd_vf_tc_bw_port_id,
13181                 (void *)&cmd_vf_tc_bw_vf_id,
13182                 (void *)&cmd_vf_tc_bw_tc_no,
13183                 (void *)&cmd_vf_tc_bw_bw,
13184                 NULL,
13185         },
13186 };
13187
13188 /* Strict link priority scheduling mode setting */
13189 static void
13190 cmd_strict_link_prio_parsed(
13191         void *parsed_result,
13192         __attribute__((unused)) struct cmdline *cl,
13193         __attribute__((unused)) void *data)
13194 {
13195         struct cmd_vf_tc_bw_result *res = parsed_result;
13196         int ret = -ENOTSUP;
13197
13198         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13199                 return;
13200
13201 #ifdef RTE_LIBRTE_I40E_PMD
13202         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13203 #endif
13204
13205         switch (ret) {
13206         case 0:
13207                 break;
13208         case -EINVAL:
13209                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13210                 break;
13211         case -ENODEV:
13212                 printf("invalid port_id %d\n", res->port_id);
13213                 break;
13214         case -ENOTSUP:
13215                 printf("function not implemented\n");
13216                 break;
13217         default:
13218                 printf("programming error: (%s)\n", strerror(-ret));
13219         }
13220 }
13221
13222 cmdline_parse_inst_t cmd_strict_link_prio = {
13223         .f = cmd_strict_link_prio_parsed,
13224         .data = NULL,
13225         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13226         .tokens = {
13227                 (void *)&cmd_vf_tc_bw_set,
13228                 (void *)&cmd_vf_tc_bw_tx,
13229                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13230                 (void *)&cmd_vf_tc_bw_port_id,
13231                 (void *)&cmd_vf_tc_bw_tc_map,
13232                 NULL,
13233         },
13234 };
13235
13236 /* Load dynamic device personalization*/
13237 struct cmd_ddp_add_result {
13238         cmdline_fixed_string_t ddp;
13239         cmdline_fixed_string_t add;
13240         uint8_t port_id;
13241         char filepath[];
13242 };
13243
13244 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13245         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13246 cmdline_parse_token_string_t cmd_ddp_add_add =
13247         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13248 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13249         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13250 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13251         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13252
13253 static void
13254 cmd_ddp_add_parsed(
13255         void *parsed_result,
13256         __attribute__((unused)) struct cmdline *cl,
13257         __attribute__((unused)) void *data)
13258 {
13259         struct cmd_ddp_add_result *res = parsed_result;
13260         uint8_t *buff;
13261         uint32_t size;
13262         char *filepath;
13263         char *file_fld[2];
13264         int file_num;
13265         int ret = -ENOTSUP;
13266
13267         if (res->port_id > nb_ports) {
13268                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13269                 return;
13270         }
13271
13272         if (!all_ports_stopped()) {
13273                 printf("Please stop all ports first\n");
13274                 return;
13275         }
13276
13277         filepath = strdup(res->filepath);
13278         if (filepath == NULL) {
13279                 printf("Failed to allocate memory\n");
13280                 return;
13281         }
13282         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13283
13284         buff = open_ddp_package_file(file_fld[0], &size);
13285         if (!buff) {
13286                 free((void *)filepath);
13287                 return;
13288         }
13289
13290 #ifdef RTE_LIBRTE_I40E_PMD
13291         if (ret == -ENOTSUP)
13292                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13293                                                buff, size,
13294                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13295 #endif
13296
13297         if (ret == -EEXIST)
13298                 printf("Profile has already existed.\n");
13299         else if (ret < 0)
13300                 printf("Failed to load profile.\n");
13301         else if (file_num == 2)
13302                 save_ddp_package_file(file_fld[1], buff, size);
13303
13304         close_ddp_package_file(buff);
13305         free((void *)filepath);
13306 }
13307
13308 cmdline_parse_inst_t cmd_ddp_add = {
13309         .f = cmd_ddp_add_parsed,
13310         .data = NULL,
13311         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13312         .tokens = {
13313                 (void *)&cmd_ddp_add_ddp,
13314                 (void *)&cmd_ddp_add_add,
13315                 (void *)&cmd_ddp_add_port_id,
13316                 (void *)&cmd_ddp_add_filepath,
13317                 NULL,
13318         },
13319 };
13320
13321 /* Delete dynamic device personalization*/
13322 struct cmd_ddp_del_result {
13323         cmdline_fixed_string_t ddp;
13324         cmdline_fixed_string_t del;
13325         uint8_t port_id;
13326         char filepath[];
13327 };
13328
13329 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13330         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13331 cmdline_parse_token_string_t cmd_ddp_del_del =
13332         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13333 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13334         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13335 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13336         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13337
13338 static void
13339 cmd_ddp_del_parsed(
13340         void *parsed_result,
13341         __attribute__((unused)) struct cmdline *cl,
13342         __attribute__((unused)) void *data)
13343 {
13344         struct cmd_ddp_del_result *res = parsed_result;
13345         uint8_t *buff;
13346         uint32_t size;
13347         int ret = -ENOTSUP;
13348
13349         if (res->port_id > nb_ports) {
13350                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13351                 return;
13352         }
13353
13354         if (!all_ports_stopped()) {
13355                 printf("Please stop all ports first\n");
13356                 return;
13357         }
13358
13359         buff = open_ddp_package_file(res->filepath, &size);
13360         if (!buff)
13361                 return;
13362
13363 #ifdef RTE_LIBRTE_I40E_PMD
13364         if (ret == -ENOTSUP)
13365                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13366                                                buff, size,
13367                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13368 #endif
13369
13370         if (ret == -EACCES)
13371                 printf("Profile does not exist.\n");
13372         else if (ret < 0)
13373                 printf("Failed to delete profile.\n");
13374
13375         close_ddp_package_file(buff);
13376 }
13377
13378 cmdline_parse_inst_t cmd_ddp_del = {
13379         .f = cmd_ddp_del_parsed,
13380         .data = NULL,
13381         .help_str = "ddp del <port_id> <profile_path>",
13382         .tokens = {
13383                 (void *)&cmd_ddp_del_ddp,
13384                 (void *)&cmd_ddp_del_del,
13385                 (void *)&cmd_ddp_del_port_id,
13386                 (void *)&cmd_ddp_del_filepath,
13387                 NULL,
13388         },
13389 };
13390
13391 /* Get dynamic device personalization profile info */
13392 struct cmd_ddp_info_result {
13393         cmdline_fixed_string_t ddp;
13394         cmdline_fixed_string_t get;
13395         cmdline_fixed_string_t info;
13396         char filepath[];
13397 };
13398
13399 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13400         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13401 cmdline_parse_token_string_t cmd_ddp_info_get =
13402         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13403 cmdline_parse_token_string_t cmd_ddp_info_info =
13404         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13405 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13406         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13407
13408 static void
13409 cmd_ddp_info_parsed(
13410         void *parsed_result,
13411         __attribute__((unused)) struct cmdline *cl,
13412         __attribute__((unused)) void *data)
13413 {
13414         struct cmd_ddp_info_result *res = parsed_result;
13415         uint8_t *pkg;
13416         uint32_t pkg_size;
13417         int ret = -ENOTSUP;
13418 #ifdef RTE_LIBRTE_I40E_PMD
13419         uint32_t i;
13420         uint8_t *buff;
13421         uint32_t buff_size;
13422         struct rte_pmd_i40e_profile_info info;
13423         uint32_t dev_num;
13424         struct rte_pmd_i40e_ddp_device_id *devs;
13425 #endif
13426
13427         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13428         if (!pkg)
13429                 return;
13430
13431 #ifdef RTE_LIBRTE_I40E_PMD
13432         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13433                                 (uint8_t *)&info, sizeof(info),
13434                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13435         if (!ret) {
13436                 printf("Global Track id:       0x%x\n", info.track_id);
13437                 printf("Global Version:        %d.%d.%d.%d\n",
13438                         info.version.major,
13439                         info.version.minor,
13440                         info.version.update,
13441                         info.version.draft);
13442                 printf("Global Package name:   %s\n\n", info.name);
13443         }
13444
13445         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13446                                 (uint8_t *)&info, sizeof(info),
13447                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13448         if (!ret) {
13449                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13450                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13451                         info.version.major,
13452                         info.version.minor,
13453                         info.version.update,
13454                         info.version.draft);
13455                 printf("i40e Profile name:     %s\n\n", info.name);
13456         }
13457
13458         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13459                                 (uint8_t *)&buff_size, sizeof(buff_size),
13460                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13461         if (!ret && buff_size) {
13462                 buff = (uint8_t *)malloc(buff_size);
13463                 if (buff) {
13464                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13465                                                 buff, buff_size,
13466                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13467                         if (!ret)
13468                                 printf("Package Notes:\n%s\n\n", buff);
13469                         free(buff);
13470                 }
13471         }
13472
13473         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13474                                 (uint8_t *)&dev_num, sizeof(dev_num),
13475                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13476         if (!ret && dev_num) {
13477                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(dev_num *
13478                         sizeof(struct rte_pmd_i40e_ddp_device_id));
13479                 if (devs) {
13480                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13481                                                 (uint8_t *)devs, dev_num *
13482                                                 sizeof(struct rte_pmd_i40e_ddp_device_id),
13483                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13484                         if (!ret) {
13485                                 printf("List of supported devices:\n");
13486                                 for (i = 0; i < dev_num; i++) {
13487                                         printf("  %04X:%04X %04X:%04X\n",
13488                                                 devs[i].vendor_dev_id >> 16,
13489                                                 devs[i].vendor_dev_id & 0xFFFF,
13490                                                 devs[i].sub_vendor_dev_id >> 16,
13491                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13492                                 }
13493                                 printf("\n");
13494                         }
13495                         free(devs);
13496                 }
13497         }
13498         ret = 0;
13499 #endif
13500         if (ret == -ENOTSUP)
13501                 printf("Function not supported in PMD driver\n");
13502         close_ddp_package_file(pkg);
13503 }
13504
13505 cmdline_parse_inst_t cmd_ddp_get_info = {
13506         .f = cmd_ddp_info_parsed,
13507         .data = NULL,
13508         .help_str = "ddp get info <profile_path>",
13509         .tokens = {
13510                 (void *)&cmd_ddp_info_ddp,
13511                 (void *)&cmd_ddp_info_get,
13512                 (void *)&cmd_ddp_info_info,
13513                 (void *)&cmd_ddp_info_filepath,
13514                 NULL,
13515         },
13516 };
13517
13518 /* Get dynamic device personalization profile info list*/
13519 #define PROFILE_INFO_SIZE 48
13520 #define MAX_PROFILE_NUM 16
13521
13522 struct cmd_ddp_get_list_result {
13523         cmdline_fixed_string_t ddp;
13524         cmdline_fixed_string_t get;
13525         cmdline_fixed_string_t list;
13526         uint8_t port_id;
13527 };
13528
13529 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13530         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13531 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13532         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13533 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13534         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13535 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13536         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13537
13538 static void
13539 cmd_ddp_get_list_parsed(
13540         void *parsed_result,
13541         __attribute__((unused)) struct cmdline *cl,
13542         __attribute__((unused)) void *data)
13543 {
13544         struct cmd_ddp_get_list_result *res = parsed_result;
13545 #ifdef RTE_LIBRTE_I40E_PMD
13546         struct rte_pmd_i40e_profile_list *p_list;
13547         struct rte_pmd_i40e_profile_info *p_info;
13548         uint32_t p_num;
13549         uint32_t size;
13550         uint32_t i;
13551 #endif
13552         int ret = -ENOTSUP;
13553
13554         if (res->port_id > nb_ports) {
13555                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13556                 return;
13557         }
13558
13559 #ifdef RTE_LIBRTE_I40E_PMD
13560         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13561         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13562         if (!p_list)
13563                 printf("%s: Failed to malloc buffer\n", __func__);
13564
13565         if (ret == -ENOTSUP)
13566                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13567                                                 (uint8_t *)p_list, size);
13568
13569         if (!ret) {
13570                 p_num = p_list->p_count;
13571                 printf("Profile number is: %d\n\n", p_num);
13572
13573                 for (i = 0; i < p_num; i++) {
13574                         p_info = &p_list->p_info[i];
13575                         printf("Profile %d:\n", i);
13576                         printf("Track id:     0x%x\n", p_info->track_id);
13577                         printf("Version:      %d.%d.%d.%d\n",
13578                                p_info->version.major,
13579                                p_info->version.minor,
13580                                p_info->version.update,
13581                                p_info->version.draft);
13582                         printf("Profile name: %s\n\n", p_info->name);
13583                 }
13584         }
13585
13586         free(p_list);
13587 #endif
13588
13589         if (ret < 0)
13590                 printf("Failed to get ddp list\n");
13591 }
13592
13593 cmdline_parse_inst_t cmd_ddp_get_list = {
13594         .f = cmd_ddp_get_list_parsed,
13595         .data = NULL,
13596         .help_str = "ddp get list <port_id>",
13597         .tokens = {
13598                 (void *)&cmd_ddp_get_list_ddp,
13599                 (void *)&cmd_ddp_get_list_get,
13600                 (void *)&cmd_ddp_get_list_list,
13601                 (void *)&cmd_ddp_get_list_port_id,
13602                 NULL,
13603         },
13604 };
13605
13606 /* show vf stats */
13607
13608 /* Common result structure for show vf stats */
13609 struct cmd_show_vf_stats_result {
13610         cmdline_fixed_string_t show;
13611         cmdline_fixed_string_t vf;
13612         cmdline_fixed_string_t stats;
13613         uint8_t port_id;
13614         uint16_t vf_id;
13615 };
13616
13617 /* Common CLI fields show vf stats*/
13618 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13619         TOKEN_STRING_INITIALIZER
13620                 (struct cmd_show_vf_stats_result,
13621                  show, "show");
13622 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13623         TOKEN_STRING_INITIALIZER
13624                 (struct cmd_show_vf_stats_result,
13625                  vf, "vf");
13626 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13627         TOKEN_STRING_INITIALIZER
13628                 (struct cmd_show_vf_stats_result,
13629                  stats, "stats");
13630 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13631         TOKEN_NUM_INITIALIZER
13632                 (struct cmd_show_vf_stats_result,
13633                  port_id, UINT8);
13634 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13635         TOKEN_NUM_INITIALIZER
13636                 (struct cmd_show_vf_stats_result,
13637                  vf_id, UINT16);
13638
13639 static void
13640 cmd_show_vf_stats_parsed(
13641         void *parsed_result,
13642         __attribute__((unused)) struct cmdline *cl,
13643         __attribute__((unused)) void *data)
13644 {
13645         struct cmd_show_vf_stats_result *res = parsed_result;
13646         struct rte_eth_stats stats;
13647         int ret = -ENOTSUP;
13648         static const char *nic_stats_border = "########################";
13649
13650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13651                 return;
13652
13653         memset(&stats, 0, sizeof(stats));
13654
13655 #ifdef RTE_LIBRTE_I40E_PMD
13656         if (ret == -ENOTSUP)
13657                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13658                                                 res->vf_id,
13659                                                 &stats);
13660 #endif
13661 #ifdef RTE_LIBRTE_BNXT_PMD
13662         if (ret == -ENOTSUP)
13663                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
13664                                                 res->vf_id,
13665                                                 &stats);
13666 #endif
13667
13668         switch (ret) {
13669         case 0:
13670                 break;
13671         case -EINVAL:
13672                 printf("invalid vf_id %d\n", res->vf_id);
13673                 break;
13674         case -ENODEV:
13675                 printf("invalid port_id %d\n", res->port_id);
13676                 break;
13677         case -ENOTSUP:
13678                 printf("function not implemented\n");
13679                 break;
13680         default:
13681                 printf("programming error: (%s)\n", strerror(-ret));
13682         }
13683
13684         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13685                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13686
13687         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13688                "%-"PRIu64"\n",
13689                stats.ipackets, stats.imissed, stats.ibytes);
13690         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13691         printf("  RX-nombuf:  %-10"PRIu64"\n",
13692                stats.rx_nombuf);
13693         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13694                "%-"PRIu64"\n",
13695                stats.opackets, stats.oerrors, stats.obytes);
13696
13697         printf("  %s############################%s\n",
13698                                nic_stats_border, nic_stats_border);
13699 }
13700
13701 cmdline_parse_inst_t cmd_show_vf_stats = {
13702         .f = cmd_show_vf_stats_parsed,
13703         .data = NULL,
13704         .help_str = "show vf stats <port_id> <vf_id>",
13705         .tokens = {
13706                 (void *)&cmd_show_vf_stats_show,
13707                 (void *)&cmd_show_vf_stats_vf,
13708                 (void *)&cmd_show_vf_stats_stats,
13709                 (void *)&cmd_show_vf_stats_port_id,
13710                 (void *)&cmd_show_vf_stats_vf_id,
13711                 NULL,
13712         },
13713 };
13714
13715 /* clear vf stats */
13716
13717 /* Common result structure for clear vf stats */
13718 struct cmd_clear_vf_stats_result {
13719         cmdline_fixed_string_t clear;
13720         cmdline_fixed_string_t vf;
13721         cmdline_fixed_string_t stats;
13722         uint8_t port_id;
13723         uint16_t vf_id;
13724 };
13725
13726 /* Common CLI fields clear vf stats*/
13727 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13728         TOKEN_STRING_INITIALIZER
13729                 (struct cmd_clear_vf_stats_result,
13730                  clear, "clear");
13731 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13732         TOKEN_STRING_INITIALIZER
13733                 (struct cmd_clear_vf_stats_result,
13734                  vf, "vf");
13735 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13736         TOKEN_STRING_INITIALIZER
13737                 (struct cmd_clear_vf_stats_result,
13738                  stats, "stats");
13739 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13740         TOKEN_NUM_INITIALIZER
13741                 (struct cmd_clear_vf_stats_result,
13742                  port_id, UINT8);
13743 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13744         TOKEN_NUM_INITIALIZER
13745                 (struct cmd_clear_vf_stats_result,
13746                  vf_id, UINT16);
13747
13748 static void
13749 cmd_clear_vf_stats_parsed(
13750         void *parsed_result,
13751         __attribute__((unused)) struct cmdline *cl,
13752         __attribute__((unused)) void *data)
13753 {
13754         struct cmd_clear_vf_stats_result *res = parsed_result;
13755         int ret = -ENOTSUP;
13756
13757         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13758                 return;
13759
13760 #ifdef RTE_LIBRTE_I40E_PMD
13761         if (ret == -ENOTSUP)
13762                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13763                                                   res->vf_id);
13764 #endif
13765 #ifdef RTE_LIBRTE_BNXT_PMD
13766         if (ret == -ENOTSUP)
13767                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
13768                                                   res->vf_id);
13769 #endif
13770
13771         switch (ret) {
13772         case 0:
13773                 break;
13774         case -EINVAL:
13775                 printf("invalid vf_id %d\n", res->vf_id);
13776                 break;
13777         case -ENODEV:
13778                 printf("invalid port_id %d\n", res->port_id);
13779                 break;
13780         case -ENOTSUP:
13781                 printf("function not implemented\n");
13782                 break;
13783         default:
13784                 printf("programming error: (%s)\n", strerror(-ret));
13785         }
13786 }
13787
13788 cmdline_parse_inst_t cmd_clear_vf_stats = {
13789         .f = cmd_clear_vf_stats_parsed,
13790         .data = NULL,
13791         .help_str = "clear vf stats <port_id> <vf_id>",
13792         .tokens = {
13793                 (void *)&cmd_clear_vf_stats_clear,
13794                 (void *)&cmd_clear_vf_stats_vf,
13795                 (void *)&cmd_clear_vf_stats_stats,
13796                 (void *)&cmd_clear_vf_stats_port_id,
13797                 (void *)&cmd_clear_vf_stats_vf_id,
13798                 NULL,
13799         },
13800 };
13801
13802 /* ptype mapping get */
13803
13804 /* Common result structure for ptype mapping get */
13805 struct cmd_ptype_mapping_get_result {
13806         cmdline_fixed_string_t ptype;
13807         cmdline_fixed_string_t mapping;
13808         cmdline_fixed_string_t get;
13809         uint8_t port_id;
13810         uint8_t valid_only;
13811 };
13812
13813 /* Common CLI fields for ptype mapping get */
13814 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
13815         TOKEN_STRING_INITIALIZER
13816                 (struct cmd_ptype_mapping_get_result,
13817                  ptype, "ptype");
13818 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
13819         TOKEN_STRING_INITIALIZER
13820                 (struct cmd_ptype_mapping_get_result,
13821                  mapping, "mapping");
13822 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
13823         TOKEN_STRING_INITIALIZER
13824                 (struct cmd_ptype_mapping_get_result,
13825                  get, "get");
13826 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
13827         TOKEN_NUM_INITIALIZER
13828                 (struct cmd_ptype_mapping_get_result,
13829                  port_id, UINT8);
13830 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
13831         TOKEN_NUM_INITIALIZER
13832                 (struct cmd_ptype_mapping_get_result,
13833                  valid_only, UINT8);
13834
13835 static void
13836 cmd_ptype_mapping_get_parsed(
13837         void *parsed_result,
13838         __attribute__((unused)) struct cmdline *cl,
13839         __attribute__((unused)) void *data)
13840 {
13841         struct cmd_ptype_mapping_get_result *res = parsed_result;
13842         int ret = -ENOTSUP;
13843 #ifdef RTE_LIBRTE_I40E_PMD
13844         int max_ptype_num = 256;
13845         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
13846         uint16_t count;
13847         int i;
13848 #endif
13849
13850         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13851                 return;
13852
13853 #ifdef RTE_LIBRTE_I40E_PMD
13854         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
13855                                         mapping,
13856                                         max_ptype_num,
13857                                         &count,
13858                                         res->valid_only);
13859 #endif
13860
13861         switch (ret) {
13862         case 0:
13863                 break;
13864         case -ENODEV:
13865                 printf("invalid port_id %d\n", res->port_id);
13866                 break;
13867         case -ENOTSUP:
13868                 printf("function not implemented\n");
13869                 break;
13870         default:
13871                 printf("programming error: (%s)\n", strerror(-ret));
13872         }
13873
13874 #ifdef RTE_LIBRTE_I40E_PMD
13875         if (!ret) {
13876                 for (i = 0; i < count; i++)
13877                         printf("%3d\t0x%08x\n",
13878                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
13879         }
13880 #endif
13881 }
13882
13883 cmdline_parse_inst_t cmd_ptype_mapping_get = {
13884         .f = cmd_ptype_mapping_get_parsed,
13885         .data = NULL,
13886         .help_str = "ptype mapping get <port_id> <valid_only>",
13887         .tokens = {
13888                 (void *)&cmd_ptype_mapping_get_ptype,
13889                 (void *)&cmd_ptype_mapping_get_mapping,
13890                 (void *)&cmd_ptype_mapping_get_get,
13891                 (void *)&cmd_ptype_mapping_get_port_id,
13892                 (void *)&cmd_ptype_mapping_get_valid_only,
13893                 NULL,
13894         },
13895 };
13896
13897 /* ptype mapping replace */
13898
13899 /* Common result structure for ptype mapping replace */
13900 struct cmd_ptype_mapping_replace_result {
13901         cmdline_fixed_string_t ptype;
13902         cmdline_fixed_string_t mapping;
13903         cmdline_fixed_string_t replace;
13904         uint8_t port_id;
13905         uint32_t target;
13906         uint8_t mask;
13907         uint32_t pkt_type;
13908 };
13909
13910 /* Common CLI fields for ptype mapping replace */
13911 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
13912         TOKEN_STRING_INITIALIZER
13913                 (struct cmd_ptype_mapping_replace_result,
13914                  ptype, "ptype");
13915 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
13916         TOKEN_STRING_INITIALIZER
13917                 (struct cmd_ptype_mapping_replace_result,
13918                  mapping, "mapping");
13919 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_ptype_mapping_replace_result,
13922                  replace, "replace");
13923 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
13924         TOKEN_NUM_INITIALIZER
13925                 (struct cmd_ptype_mapping_replace_result,
13926                  port_id, UINT8);
13927 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
13928         TOKEN_NUM_INITIALIZER
13929                 (struct cmd_ptype_mapping_replace_result,
13930                  target, UINT32);
13931 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
13932         TOKEN_NUM_INITIALIZER
13933                 (struct cmd_ptype_mapping_replace_result,
13934                  mask, UINT8);
13935 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
13936         TOKEN_NUM_INITIALIZER
13937                 (struct cmd_ptype_mapping_replace_result,
13938                  pkt_type, UINT32);
13939
13940 static void
13941 cmd_ptype_mapping_replace_parsed(
13942         void *parsed_result,
13943         __attribute__((unused)) struct cmdline *cl,
13944         __attribute__((unused)) void *data)
13945 {
13946         struct cmd_ptype_mapping_replace_result *res = parsed_result;
13947         int ret = -ENOTSUP;
13948
13949         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13950                 return;
13951
13952 #ifdef RTE_LIBRTE_I40E_PMD
13953         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
13954                                         res->target,
13955                                         res->mask,
13956                                         res->pkt_type);
13957 #endif
13958
13959         switch (ret) {
13960         case 0:
13961                 break;
13962         case -EINVAL:
13963                 printf("invalid ptype 0x%8x or 0x%8x\n",
13964                                 res->target, res->pkt_type);
13965                 break;
13966         case -ENODEV:
13967                 printf("invalid port_id %d\n", res->port_id);
13968                 break;
13969         case -ENOTSUP:
13970                 printf("function not implemented\n");
13971                 break;
13972         default:
13973                 printf("programming error: (%s)\n", strerror(-ret));
13974         }
13975 }
13976
13977 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
13978         .f = cmd_ptype_mapping_replace_parsed,
13979         .data = NULL,
13980         .help_str =
13981                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
13982         .tokens = {
13983                 (void *)&cmd_ptype_mapping_replace_ptype,
13984                 (void *)&cmd_ptype_mapping_replace_mapping,
13985                 (void *)&cmd_ptype_mapping_replace_replace,
13986                 (void *)&cmd_ptype_mapping_replace_port_id,
13987                 (void *)&cmd_ptype_mapping_replace_target,
13988                 (void *)&cmd_ptype_mapping_replace_mask,
13989                 (void *)&cmd_ptype_mapping_replace_pkt_type,
13990                 NULL,
13991         },
13992 };
13993
13994 /* ptype mapping reset */
13995
13996 /* Common result structure for ptype mapping reset */
13997 struct cmd_ptype_mapping_reset_result {
13998         cmdline_fixed_string_t ptype;
13999         cmdline_fixed_string_t mapping;
14000         cmdline_fixed_string_t reset;
14001         uint8_t port_id;
14002 };
14003
14004 /* Common CLI fields for ptype mapping reset*/
14005 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14006         TOKEN_STRING_INITIALIZER
14007                 (struct cmd_ptype_mapping_reset_result,
14008                  ptype, "ptype");
14009 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14010         TOKEN_STRING_INITIALIZER
14011                 (struct cmd_ptype_mapping_reset_result,
14012                  mapping, "mapping");
14013 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14014         TOKEN_STRING_INITIALIZER
14015                 (struct cmd_ptype_mapping_reset_result,
14016                  reset, "reset");
14017 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14018         TOKEN_NUM_INITIALIZER
14019                 (struct cmd_ptype_mapping_reset_result,
14020                  port_id, UINT8);
14021
14022 static void
14023 cmd_ptype_mapping_reset_parsed(
14024         void *parsed_result,
14025         __attribute__((unused)) struct cmdline *cl,
14026         __attribute__((unused)) void *data)
14027 {
14028         struct cmd_ptype_mapping_reset_result *res = parsed_result;
14029         int ret = -ENOTSUP;
14030
14031         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14032                 return;
14033
14034 #ifdef RTE_LIBRTE_I40E_PMD
14035         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14036 #endif
14037
14038         switch (ret) {
14039         case 0:
14040                 break;
14041         case -ENODEV:
14042                 printf("invalid port_id %d\n", res->port_id);
14043                 break;
14044         case -ENOTSUP:
14045                 printf("function not implemented\n");
14046                 break;
14047         default:
14048                 printf("programming error: (%s)\n", strerror(-ret));
14049         }
14050 }
14051
14052 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14053         .f = cmd_ptype_mapping_reset_parsed,
14054         .data = NULL,
14055         .help_str = "ptype mapping reset <port_id>",
14056         .tokens = {
14057                 (void *)&cmd_ptype_mapping_reset_ptype,
14058                 (void *)&cmd_ptype_mapping_reset_mapping,
14059                 (void *)&cmd_ptype_mapping_reset_reset,
14060                 (void *)&cmd_ptype_mapping_reset_port_id,
14061                 NULL,
14062         },
14063 };
14064
14065 /* ptype mapping update */
14066
14067 /* Common result structure for ptype mapping update */
14068 struct cmd_ptype_mapping_update_result {
14069         cmdline_fixed_string_t ptype;
14070         cmdline_fixed_string_t mapping;
14071         cmdline_fixed_string_t reset;
14072         uint8_t port_id;
14073         uint8_t hw_ptype;
14074         uint32_t sw_ptype;
14075 };
14076
14077 /* Common CLI fields for ptype mapping update*/
14078 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14079         TOKEN_STRING_INITIALIZER
14080                 (struct cmd_ptype_mapping_update_result,
14081                  ptype, "ptype");
14082 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14083         TOKEN_STRING_INITIALIZER
14084                 (struct cmd_ptype_mapping_update_result,
14085                  mapping, "mapping");
14086 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14087         TOKEN_STRING_INITIALIZER
14088                 (struct cmd_ptype_mapping_update_result,
14089                  reset, "update");
14090 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14091         TOKEN_NUM_INITIALIZER
14092                 (struct cmd_ptype_mapping_update_result,
14093                  port_id, UINT8);
14094 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14095         TOKEN_NUM_INITIALIZER
14096                 (struct cmd_ptype_mapping_update_result,
14097                  hw_ptype, UINT8);
14098 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14099         TOKEN_NUM_INITIALIZER
14100                 (struct cmd_ptype_mapping_update_result,
14101                  sw_ptype, UINT32);
14102
14103 static void
14104 cmd_ptype_mapping_update_parsed(
14105         void *parsed_result,
14106         __attribute__((unused)) struct cmdline *cl,
14107         __attribute__((unused)) void *data)
14108 {
14109         struct cmd_ptype_mapping_update_result *res = parsed_result;
14110         int ret = -ENOTSUP;
14111 #ifdef RTE_LIBRTE_I40E_PMD
14112         struct rte_pmd_i40e_ptype_mapping mapping;
14113 #endif
14114         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14115                 return;
14116
14117 #ifdef RTE_LIBRTE_I40E_PMD
14118         mapping.hw_ptype = res->hw_ptype;
14119         mapping.sw_ptype = res->sw_ptype;
14120         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14121                                                 &mapping,
14122                                                 1,
14123                                                 0);
14124 #endif
14125
14126         switch (ret) {
14127         case 0:
14128                 break;
14129         case -EINVAL:
14130                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
14131                 break;
14132         case -ENODEV:
14133                 printf("invalid port_id %d\n", res->port_id);
14134                 break;
14135         case -ENOTSUP:
14136                 printf("function not implemented\n");
14137                 break;
14138         default:
14139                 printf("programming error: (%s)\n", strerror(-ret));
14140         }
14141 }
14142
14143 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14144         .f = cmd_ptype_mapping_update_parsed,
14145         .data = NULL,
14146         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14147         .tokens = {
14148                 (void *)&cmd_ptype_mapping_update_ptype,
14149                 (void *)&cmd_ptype_mapping_update_mapping,
14150                 (void *)&cmd_ptype_mapping_update_update,
14151                 (void *)&cmd_ptype_mapping_update_port_id,
14152                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14153                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14154                 NULL,
14155         },
14156 };
14157
14158 /* Common result structure for file commands */
14159 struct cmd_cmdfile_result {
14160         cmdline_fixed_string_t load;
14161         cmdline_fixed_string_t filename;
14162 };
14163
14164 /* Common CLI fields for file commands */
14165 cmdline_parse_token_string_t cmd_load_cmdfile =
14166         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14167 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14168         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14169
14170 static void
14171 cmd_load_from_file_parsed(
14172         void *parsed_result,
14173         __attribute__((unused)) struct cmdline *cl,
14174         __attribute__((unused)) void *data)
14175 {
14176         struct cmd_cmdfile_result *res = parsed_result;
14177
14178         cmdline_read_from_file(res->filename);
14179 }
14180
14181 cmdline_parse_inst_t cmd_load_from_file = {
14182         .f = cmd_load_from_file_parsed,
14183         .data = NULL,
14184         .help_str = "load <filename>",
14185         .tokens = {
14186                 (void *)&cmd_load_cmdfile,
14187                 (void *)&cmd_load_cmdfile_filename,
14188                 NULL,
14189         },
14190 };
14191
14192 /* ******************************************************************************** */
14193
14194 /* list of instructions */
14195 cmdline_parse_ctx_t main_ctx[] = {
14196         (cmdline_parse_inst_t *)&cmd_help_brief,
14197         (cmdline_parse_inst_t *)&cmd_help_long,
14198         (cmdline_parse_inst_t *)&cmd_quit,
14199         (cmdline_parse_inst_t *)&cmd_load_from_file,
14200         (cmdline_parse_inst_t *)&cmd_showport,
14201         (cmdline_parse_inst_t *)&cmd_showqueue,
14202         (cmdline_parse_inst_t *)&cmd_showportall,
14203         (cmdline_parse_inst_t *)&cmd_showcfg,
14204         (cmdline_parse_inst_t *)&cmd_start,
14205         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14206         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14207         (cmdline_parse_inst_t *)&cmd_set_link_up,
14208         (cmdline_parse_inst_t *)&cmd_set_link_down,
14209         (cmdline_parse_inst_t *)&cmd_reset,
14210         (cmdline_parse_inst_t *)&cmd_set_numbers,
14211         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14212         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14213         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14214         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14215         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14216         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14217         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14218         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14219         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14220         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14221         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14222         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14223         (cmdline_parse_inst_t *)&cmd_set_link_check,
14224         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14225         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14226         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14227         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14228 #ifdef RTE_LIBRTE_PMD_BOND
14229         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14230         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14231         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14232         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14233         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14234         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14235         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14236         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14237         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14238         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14239         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14240 #endif
14241         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14242         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14243         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14244         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14245         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14246         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14247         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14248         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14249         (cmdline_parse_inst_t *)&cmd_csum_set,
14250         (cmdline_parse_inst_t *)&cmd_csum_show,
14251         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14252         (cmdline_parse_inst_t *)&cmd_tso_set,
14253         (cmdline_parse_inst_t *)&cmd_tso_show,
14254         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14255         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14256         (cmdline_parse_inst_t *)&cmd_enable_gro,
14257         (cmdline_parse_inst_t *)&cmd_gro_set,
14258         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14259         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14260         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14261         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14262         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14263         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14264         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14265         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14266         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14267         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14268         (cmdline_parse_inst_t *)&cmd_config_dcb,
14269         (cmdline_parse_inst_t *)&cmd_read_reg,
14270         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14271         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
14272         (cmdline_parse_inst_t *)&cmd_write_reg,
14273         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14274         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
14275         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14276         (cmdline_parse_inst_t *)&cmd_stop,
14277         (cmdline_parse_inst_t *)&cmd_mac_addr,
14278         (cmdline_parse_inst_t *)&cmd_set_qmap,
14279         (cmdline_parse_inst_t *)&cmd_operate_port,
14280         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
14281         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
14282         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
14283         (cmdline_parse_inst_t *)&cmd_config_speed_all,
14284         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
14285         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
14286         (cmdline_parse_inst_t *)&cmd_config_mtu,
14287         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14288         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14289         (cmdline_parse_inst_t *)&cmd_config_rss,
14290         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14291         (cmdline_parse_inst_t *)&cmd_config_txqflags,
14292         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
14293         (cmdline_parse_inst_t *)&cmd_showport_reta,
14294         (cmdline_parse_inst_t *)&cmd_config_burst,
14295         (cmdline_parse_inst_t *)&cmd_config_thresh,
14296         (cmdline_parse_inst_t *)&cmd_config_threshold,
14297         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14298         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14299         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14300         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14301         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14302         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
14303         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14304         (cmdline_parse_inst_t *)&cmd_global_config,
14305         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14306         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
14307         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14308         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14309         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14310         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14311         (cmdline_parse_inst_t *)&cmd_dump,
14312         (cmdline_parse_inst_t *)&cmd_dump_one,
14313         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
14314         (cmdline_parse_inst_t *)&cmd_syn_filter,
14315         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
14316         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
14317         (cmdline_parse_inst_t *)&cmd_flex_filter,
14318         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14319         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14320         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14321         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14322         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14323         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14324         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
14325         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14326         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14327         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14328         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14329         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14330         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14331         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14332         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14333         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14334         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14335         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14336         (cmdline_parse_inst_t *)&cmd_flow,
14337         (cmdline_parse_inst_t *)&cmd_mcast_addr,
14338         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14339         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14340         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14341         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14342         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14343         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14344         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14345         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14346         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14347         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14348         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14349         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14350         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14351         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
14352         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
14353         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
14354         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
14355         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
14356         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
14357         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
14358         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
14359         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
14360         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
14361         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
14362         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
14363         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
14364         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
14365         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
14366         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
14367         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
14368         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
14369         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
14370         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
14371         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
14372         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
14373         (cmdline_parse_inst_t *)&cmd_ddp_add,
14374         (cmdline_parse_inst_t *)&cmd_ddp_del,
14375         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
14376         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
14377         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
14378         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
14379         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
14380         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
14381         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
14382         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
14383         NULL,
14384 };
14385
14386 /* read cmdline commands from file */
14387 void
14388 cmdline_read_from_file(const char *filename)
14389 {
14390         struct cmdline *cl;
14391
14392         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
14393         if (cl == NULL) {
14394                 printf("Failed to create file based cmdline context: %s\n",
14395                        filename);
14396                 return;
14397         }
14398
14399         cmdline_interact(cl);
14400         cmdline_quit(cl);
14401
14402         cmdline_free(cl);
14403
14404         printf("Read CLI commands from %s\n", filename);
14405 }
14406
14407 /* prompt function, called from main on MASTER lcore */
14408 void
14409 prompt(void)
14410 {
14411         /* initialize non-constant commands */
14412         cmd_set_fwd_mode_init();
14413         cmd_set_fwd_retry_mode_init();
14414
14415         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
14416         if (testpmd_cl == NULL)
14417                 return;
14418         cmdline_interact(testpmd_cl);
14419         cmdline_stdin_exit(testpmd_cl);
14420 }
14421
14422 void
14423 prompt_exit(void)
14424 {
14425         if (testpmd_cl != NULL)
14426                 cmdline_quit(testpmd_cl);
14427 }
14428
14429 static void
14430 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
14431 {
14432         if (id == (portid_t)RTE_PORT_ALL) {
14433                 portid_t pid;
14434
14435                 RTE_ETH_FOREACH_DEV(pid) {
14436                         /* check if need_reconfig has been set to 1 */
14437                         if (ports[pid].need_reconfig == 0)
14438                                 ports[pid].need_reconfig = dev;
14439                         /* check if need_reconfig_queues has been set to 1 */
14440                         if (ports[pid].need_reconfig_queues == 0)
14441                                 ports[pid].need_reconfig_queues = queue;
14442                 }
14443         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
14444                 /* check if need_reconfig has been set to 1 */
14445                 if (ports[id].need_reconfig == 0)
14446                         ports[id].need_reconfig = dev;
14447                 /* check if need_reconfig_queues has been set to 1 */
14448                 if (ports[id].need_reconfig_queues == 0)
14449                         ports[id].need_reconfig_queues = queue;
14450         }
14451 }