app/testpmd: enable the heavyweight mode TCP/IPv4 GRO
[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                         "show port (port_id) pctype mapping\n"
235                         "    Get flow ptype to pctype mapping on a port\n\n"
236
237                 );
238         }
239
240         if (show_all || !strcmp(res->section, "config")) {
241                 cmdline_printf(
242                         cl,
243                         "\n"
244                         "Configuration:\n"
245                         "--------------\n"
246                         "Configuration changes only become active when"
247                         " forwarding is started/restarted.\n\n"
248
249                         "set default\n"
250                         "    Reset forwarding to the default configuration.\n\n"
251
252                         "set verbose (level)\n"
253                         "    Set the debug verbosity level X.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set fwd (%s)\n"
442                         "    Set packet forwarding mode.\n\n"
443
444                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
445                         "    Add a MAC address on port_id.\n\n"
446
447                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
448                         "    Remove a MAC address from port_id.\n\n"
449
450                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
451                         "    Set the default MAC address for port_id.\n\n"
452
453                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
454                         "    Add a MAC address for a VF on the port.\n\n"
455
456                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
457                         "    Set the MAC address for a VF from the PF.\n\n"
458
459                         "set port (port_id) uta (mac_address|all) (on|off)\n"
460                         "    Add/Remove a or all unicast hash filter(s)"
461                         "from port X.\n\n"
462
463                         "set promisc (port_id|all) (on|off)\n"
464                         "    Set the promiscuous mode on port_id, or all.\n\n"
465
466                         "set allmulti (port_id|all) (on|off)\n"
467                         "    Set the allmulti mode on port_id, or all.\n\n"
468
469                         "set vf promisc (port_id) (vf_id) (on|off)\n"
470                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
471
472                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
473                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
474
475                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
476                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
477                         " (on|off) autoneg (on|off) (port_id)\n"
478                         "set flow_ctrl rx (on|off) (portid)\n"
479                         "set flow_ctrl tx (on|off) (portid)\n"
480                         "set flow_ctrl high_water (high_water) (portid)\n"
481                         "set flow_ctrl low_water (low_water) (portid)\n"
482                         "set flow_ctrl pause_time (pause_time) (portid)\n"
483                         "set flow_ctrl send_xon (send_xon) (portid)\n"
484                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
485                         "set flow_ctrl autoneg (on|off) (port_id)\n"
486                         "    Set the link flow control parameter on a port.\n\n"
487
488                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
489                         " (low_water) (pause_time) (priority) (port_id)\n"
490                         "    Set the priority flow control parameter on a"
491                         " port.\n\n"
492
493                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
494                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
495                         " queue on port.\n"
496                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
497                         " on port 0 to mapping 5.\n\n"
498
499                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
500                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
501
502                         "set port (port_id) vf (vf_id) (mac_addr)"
503                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
504                         "   Add/Remove unicast or multicast MAC addr filter"
505                         " for a VF.\n\n"
506
507                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
508                         "|MPE) (on|off)\n"
509                         "    AUPE:accepts untagged VLAN;"
510                         "ROPE:accept unicast hash\n\n"
511                         "    BAM:accepts broadcast packets;"
512                         "MPE:accepts all multicast packets\n\n"
513                         "    Enable/Disable a VF receive mode of a port\n\n"
514
515                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
516                         "    Set rate limit for a queue of a port\n\n"
517
518                         "set port (port_id) vf (vf_id) rate (rate_num) "
519                         "queue_mask (queue_mask_value)\n"
520                         "    Set rate limit for queues in VF of a port\n\n"
521
522                         "set port (port_id) mirror-rule (rule_id)"
523                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
524                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
525                         "   Set pool or vlan type mirror rule on a port.\n"
526                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
527                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
528                         " to pool 0.\n\n"
529
530                         "set port (port_id) mirror-rule (rule_id)"
531                         " (uplink-mirror|downlink-mirror) dst-pool"
532                         " (pool_id) (on|off)\n"
533                         "   Set uplink or downlink type mirror rule on a port.\n"
534                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
535                         " 0 on' enable mirror income traffic to pool 0.\n\n"
536
537                         "reset port (port_id) mirror-rule (rule_id)\n"
538                         "   Reset a mirror rule.\n\n"
539
540                         "set flush_rx (on|off)\n"
541                         "   Flush (default) or don't flush RX streams before"
542                         " forwarding. Mainly used with PCAP drivers.\n\n"
543
544                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
545                         "   Set the bypass mode for the lowest port on bypass enabled"
546                         " NIC.\n\n"
547
548                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
549                         "mode (normal|bypass|isolate) (port_id)\n"
550                         "   Set the event required to initiate specified bypass mode for"
551                         " the lowest port on a bypass enabled NIC where:\n"
552                         "       timeout   = enable bypass after watchdog timeout.\n"
553                         "       os_on     = enable bypass when OS/board is powered on.\n"
554                         "       os_off    = enable bypass when OS/board is powered off.\n"
555                         "       power_on  = enable bypass when power supply is turned on.\n"
556                         "       power_off = enable bypass when power supply is turned off."
557                         "\n\n"
558
559                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
560                         "   Set the bypass watchdog timeout to 'n' seconds"
561                         " where 0 = instant.\n\n"
562
563                         "show bypass config (port_id)\n"
564                         "   Show the bypass configuration for a bypass enabled NIC"
565                         " using the lowest port on the NIC.\n\n"
566
567 #ifdef RTE_LIBRTE_PMD_BOND
568                         "create bonded device (mode) (socket)\n"
569                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
570
571                         "add bonding slave (slave_id) (port_id)\n"
572                         "       Add a slave device to a bonded device.\n\n"
573
574                         "remove bonding slave (slave_id) (port_id)\n"
575                         "       Remove a slave device from a bonded device.\n\n"
576
577                         "set bonding mode (value) (port_id)\n"
578                         "       Set the bonding mode on a bonded device.\n\n"
579
580                         "set bonding primary (slave_id) (port_id)\n"
581                         "       Set the primary slave for a bonded device.\n\n"
582
583                         "show bonding config (port_id)\n"
584                         "       Show the bonding config for port_id.\n\n"
585
586                         "set bonding mac_addr (port_id) (address)\n"
587                         "       Set the MAC address of a bonded device.\n\n"
588
589                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
590                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
591
592                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
593                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
594
595                         "set bonding mon_period (port_id) (value)\n"
596                         "       Set the bonding link status monitoring polling period in ms.\n\n"
597
598                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
599                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
600
601 #endif
602                         "set link-up port (port_id)\n"
603                         "       Set link up for a port.\n\n"
604
605                         "set link-down port (port_id)\n"
606                         "       Set link down for a port.\n\n"
607
608                         "E-tag set insertion on port-tag-id (value)"
609                         " port (port_id) vf (vf_id)\n"
610                         "    Enable E-tag insertion for a VF on a port\n\n"
611
612                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
613                         "    Disable E-tag insertion for a VF on a port\n\n"
614
615                         "E-tag set stripping (on|off) port (port_id)\n"
616                         "    Enable/disable E-tag stripping on a port\n\n"
617
618                         "E-tag set forwarding (on|off) port (port_id)\n"
619                         "    Enable/disable E-tag based forwarding"
620                         " on a port\n\n"
621
622                         "E-tag set filter add e-tag-id (value) dst-pool"
623                         " (pool_id) port (port_id)\n"
624                         "    Add an E-tag forwarding filter on a port\n\n"
625
626                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
627                         "    Delete an E-tag forwarding filter on a port\n\n"
628
629                         "ddp add (port_id) (profile_path[,output_path])\n"
630                         "    Load a profile package on a port\n\n"
631
632                         "ddp del (port_id) (profile_path)\n"
633                         "    Delete a profile package from a port\n\n"
634
635                         "ptype mapping get (port_id) (valid_only)\n"
636                         "    Get ptype mapping on a port\n\n"
637
638                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
639                         "    Replace target with the pkt_type in ptype mapping\n\n"
640
641                         "ptype mapping reset (port_id)\n"
642                         "    Reset ptype mapping on a port\n\n"
643
644                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
645                         "    Update a ptype mapping item on a port\n\n"
646
647                         , list_pkt_forwarding_modes()
648                 );
649         }
650
651         if (show_all || !strcmp(res->section, "ports")) {
652
653                 cmdline_printf(
654                         cl,
655                         "\n"
656                         "Port Operations:\n"
657                         "----------------\n\n"
658
659                         "port start (port_id|all)\n"
660                         "    Start all ports or port_id.\n\n"
661
662                         "port stop (port_id|all)\n"
663                         "    Stop all ports or port_id.\n\n"
664
665                         "port close (port_id|all)\n"
666                         "    Close all ports or port_id.\n\n"
667
668                         "port attach (ident)\n"
669                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
670
671                         "port detach (port_id)\n"
672                         "    Detach physical or virtual dev by port_id\n\n"
673
674                         "port config (port_id|all)"
675                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
676                         " duplex (half|full|auto)\n"
677                         "    Set speed and duplex for all ports or port_id\n\n"
678
679                         "port config all (rxq|txq|rxd|txd) (value)\n"
680                         "    Set number for rxq/txq/rxd/txd.\n\n"
681
682                         "port config all max-pkt-len (value)\n"
683                         "    Set the max packet length.\n\n"
684
685                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
686                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
687                         " (on|off)\n"
688                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
689                         " for ports.\n\n"
690
691                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
692                         "geneve|nvgre|none|<flowtype_id>)\n"
693                         "    Set the RSS mode.\n\n"
694
695                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
696                         "    Set the RSS redirection table.\n\n"
697
698                         "port config (port_id) dcb vt (on|off) (traffic_class)"
699                         " pfc (on|off)\n"
700                         "    Set the DCB mode.\n\n"
701
702                         "port config all burst (value)\n"
703                         "    Set the number of packets per burst.\n\n"
704
705                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
706                         " (value)\n"
707                         "    Set the ring prefetch/host/writeback threshold"
708                         " for tx/rx queue.\n\n"
709
710                         "port config all (txfreet|txrst|rxfreet) (value)\n"
711                         "    Set free threshold for rx/tx, or set"
712                         " tx rs bit threshold.\n\n"
713                         "port config mtu X value\n"
714                         "    Set the MTU of port X to a given value\n\n"
715
716                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
717                         "    Start/stop a rx/tx queue of port X. Only take effect"
718                         " when port X is started\n\n"
719
720                         "port config (port_id|all) l2-tunnel E-tag ether-type"
721                         " (value)\n"
722                         "    Set the value of E-tag ether-type.\n\n"
723
724                         "port config (port_id|all) l2-tunnel E-tag"
725                         " (enable|disable)\n"
726                         "    Enable/disable the E-tag support.\n\n"
727
728                         "port config (port_id) pctype mapping reset\n"
729                         "    Reset flow type to pctype mapping on a port\n\n"
730
731                         "port config (port_id) pctype mapping update"
732                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
733                         "    Update a flow type to pctype mapping item on a port\n\n"
734                 );
735         }
736
737         if (show_all || !strcmp(res->section, "registers")) {
738
739                 cmdline_printf(
740                         cl,
741                         "\n"
742                         "Registers:\n"
743                         "----------\n\n"
744
745                         "read reg (port_id) (address)\n"
746                         "    Display value of a port register.\n\n"
747
748                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
749                         "    Display a port register bit field.\n\n"
750
751                         "read regbit (port_id) (address) (bit_x)\n"
752                         "    Display a single port register bit.\n\n"
753
754                         "write reg (port_id) (address) (value)\n"
755                         "    Set value of a port register.\n\n"
756
757                         "write regfield (port_id) (address) (bit_x) (bit_y)"
758                         " (value)\n"
759                         "    Set bit field of a port register.\n\n"
760
761                         "write regbit (port_id) (address) (bit_x) (value)\n"
762                         "    Set single bit value of a port register.\n\n"
763                 );
764         }
765         if (show_all || !strcmp(res->section, "filters")) {
766
767                 cmdline_printf(
768                         cl,
769                         "\n"
770                         "filters:\n"
771                         "--------\n\n"
772
773                         "ethertype_filter (port_id) (add|del)"
774                         " (mac_addr|mac_ignr) (mac_address) ethertype"
775                         " (ether_type) (drop|fwd) queue (queue_id)\n"
776                         "    Add/Del an ethertype filter.\n\n"
777
778                         "2tuple_filter (port_id) (add|del)"
779                         " dst_port (dst_port_value) protocol (protocol_value)"
780                         " mask (mask_value) tcp_flags (tcp_flags_value)"
781                         " priority (prio_value) queue (queue_id)\n"
782                         "    Add/Del a 2tuple filter.\n\n"
783
784                         "5tuple_filter (port_id) (add|del)"
785                         " dst_ip (dst_address) src_ip (src_address)"
786                         " dst_port (dst_port_value) src_port (src_port_value)"
787                         " protocol (protocol_value)"
788                         " mask (mask_value) tcp_flags (tcp_flags_value)"
789                         " priority (prio_value) queue (queue_id)\n"
790                         "    Add/Del a 5tuple filter.\n\n"
791
792                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
793                         "    Add/Del syn filter.\n\n"
794
795                         "flex_filter (port_id) (add|del) len (len_value)"
796                         " bytes (bytes_value) mask (mask_value)"
797                         " priority (prio_value) queue (queue_id)\n"
798                         "    Add/Del a flex filter.\n\n"
799
800                         "flow_director_filter (port_id) mode IP (add|del|update)"
801                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
802                         " src (src_ip_address) dst (dst_ip_address)"
803                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
804                         " vlan (vlan_value) flexbytes (flexbytes_value)"
805                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
806                         " fd_id (fd_id_value)\n"
807                         "    Add/Del an IP type flow director filter.\n\n"
808
809                         "flow_director_filter (port_id) mode IP (add|del|update)"
810                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
811                         " src (src_ip_address) (src_port)"
812                         " dst (dst_ip_address) (dst_port)"
813                         " tos (tos_value) ttl (ttl_value)"
814                         " vlan (vlan_value) flexbytes (flexbytes_value)"
815                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
816                         " fd_id (fd_id_value)\n"
817                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
818
819                         "flow_director_filter (port_id) mode IP (add|del|update)"
820                         " flow (ipv4-sctp|ipv6-sctp)"
821                         " src (src_ip_address) (src_port)"
822                         " dst (dst_ip_address) (dst_port)"
823                         " tag (verification_tag) "
824                         " tos (tos_value) ttl (ttl_value)"
825                         " vlan (vlan_value)"
826                         " flexbytes (flexbytes_value) (drop|fwd)"
827                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
828                         "    Add/Del a SCTP type flow director filter.\n\n"
829
830                         "flow_director_filter (port_id) mode IP (add|del|update)"
831                         " flow l2_payload ether (ethertype)"
832                         " flexbytes (flexbytes_value) (drop|fwd)"
833                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
834                         "    Add/Del a l2 payload type flow director filter.\n\n"
835
836                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
837                         " mac (mac_address) vlan (vlan_value)"
838                         " flexbytes (flexbytes_value) (drop|fwd)"
839                         " queue (queue_id) fd_id (fd_id_value)\n"
840                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
841
842                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
843                         " mac (mac_address) vlan (vlan_value)"
844                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
845                         " flexbytes (flexbytes_value) (drop|fwd)"
846                         " queue (queue_id) fd_id (fd_id_value)\n"
847                         "    Add/Del a Tunnel flow director filter.\n\n"
848
849                         "flush_flow_director (port_id)\n"
850                         "    Flush all flow director entries of a device.\n\n"
851
852                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
853                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
854                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
855                         "    Set flow director IP mask.\n\n"
856
857                         "flow_director_mask (port_id) mode MAC-VLAN"
858                         " vlan (vlan_value)\n"
859                         "    Set flow director MAC-VLAN mask.\n\n"
860
861                         "flow_director_mask (port_id) mode Tunnel"
862                         " vlan (vlan_value) mac (mac_value)"
863                         " tunnel-type (tunnel_type_value)"
864                         " tunnel-id (tunnel_id_value)\n"
865                         "    Set flow director Tunnel mask.\n\n"
866
867                         "flow_director_flex_mask (port_id)"
868                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
869                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
870                         " (mask)\n"
871                         "    Configure mask of flex payload.\n\n"
872
873                         "flow_director_flex_payload (port_id)"
874                         " (raw|l2|l3|l4) (config)\n"
875                         "    Configure flex payload selection.\n\n"
876
877                         "get_sym_hash_ena_per_port (port_id)\n"
878                         "    get symmetric hash enable configuration per port.\n\n"
879
880                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
881                         "    set symmetric hash enable configuration per port"
882                         " to enable or disable.\n\n"
883
884                         "get_hash_global_config (port_id)\n"
885                         "    Get the global configurations of hash filters.\n\n"
886
887                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
888                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
889                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
890                         " (enable|disable)\n"
891                         "    Set the global configurations of hash filters.\n\n"
892
893                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
894                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
895                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
896                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
897                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
898                         "ipv6-next-header|udp-src-port|udp-dst-port|"
899                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
900                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
901                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
902                         "fld-8th|none) (select|add)\n"
903                         "    Set the input set for hash.\n\n"
904
905                         "set_fdir_input_set (port_id) "
906                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
907                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
908                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
909                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
910                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
911                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
912                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
913                         " (select|add)\n"
914                         "    Set the input set for FDir.\n\n"
915
916                         "flow validate {port_id}"
917                         " [group {group_id}] [priority {level}]"
918                         " [ingress] [egress]"
919                         " pattern {item} [/ {item} [...]] / end"
920                         " actions {action} [/ {action} [...]] / end\n"
921                         "    Check whether a flow rule can be created.\n\n"
922
923                         "flow create {port_id}"
924                         " [group {group_id}] [priority {level}]"
925                         " [ingress] [egress]"
926                         " pattern {item} [/ {item} [...]] / end"
927                         " actions {action} [/ {action} [...]] / end\n"
928                         "    Create a flow rule.\n\n"
929
930                         "flow destroy {port_id} rule {rule_id} [...]\n"
931                         "    Destroy specific flow rules.\n\n"
932
933                         "flow flush {port_id}\n"
934                         "    Destroy all flow rules.\n\n"
935
936                         "flow query {port_id} {rule_id} {action}\n"
937                         "    Query an existing flow rule.\n\n"
938
939                         "flow list {port_id} [group {group_id}] [...]\n"
940                         "    List existing flow rules sorted by priority,"
941                         " filtered by group identifiers.\n\n"
942
943                         "flow isolate {port_id} {boolean}\n"
944                         "    Restrict ingress traffic to the defined"
945                         " flow rules\n\n"
946                 );
947         }
948 }
949
950 cmdline_parse_token_string_t cmd_help_long_help =
951         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
952
953 cmdline_parse_token_string_t cmd_help_long_section =
954         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
955                         "all#control#display#config#"
956                         "ports#registers#filters");
957
958 cmdline_parse_inst_t cmd_help_long = {
959         .f = cmd_help_long_parsed,
960         .data = NULL,
961         .help_str = "help all|control|display|config|ports|register|filters: "
962                 "Show help",
963         .tokens = {
964                 (void *)&cmd_help_long_help,
965                 (void *)&cmd_help_long_section,
966                 NULL,
967         },
968 };
969
970
971 /* *** start/stop/close all ports *** */
972 struct cmd_operate_port_result {
973         cmdline_fixed_string_t keyword;
974         cmdline_fixed_string_t name;
975         cmdline_fixed_string_t value;
976 };
977
978 static void cmd_operate_port_parsed(void *parsed_result,
979                                 __attribute__((unused)) struct cmdline *cl,
980                                 __attribute__((unused)) void *data)
981 {
982         struct cmd_operate_port_result *res = parsed_result;
983
984         if (!strcmp(res->name, "start"))
985                 start_port(RTE_PORT_ALL);
986         else if (!strcmp(res->name, "stop"))
987                 stop_port(RTE_PORT_ALL);
988         else if (!strcmp(res->name, "close"))
989                 close_port(RTE_PORT_ALL);
990         else if (!strcmp(res->name, "reset"))
991                 reset_port(RTE_PORT_ALL);
992         else
993                 printf("Unknown parameter\n");
994 }
995
996 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
997         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
998                                                                 "port");
999 cmdline_parse_token_string_t cmd_operate_port_all_port =
1000         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1001                                                 "start#stop#close#reset");
1002 cmdline_parse_token_string_t cmd_operate_port_all_all =
1003         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1004
1005 cmdline_parse_inst_t cmd_operate_port = {
1006         .f = cmd_operate_port_parsed,
1007         .data = NULL,
1008         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1009         .tokens = {
1010                 (void *)&cmd_operate_port_all_cmd,
1011                 (void *)&cmd_operate_port_all_port,
1012                 (void *)&cmd_operate_port_all_all,
1013                 NULL,
1014         },
1015 };
1016
1017 /* *** start/stop/close specific port *** */
1018 struct cmd_operate_specific_port_result {
1019         cmdline_fixed_string_t keyword;
1020         cmdline_fixed_string_t name;
1021         uint8_t value;
1022 };
1023
1024 static void cmd_operate_specific_port_parsed(void *parsed_result,
1025                         __attribute__((unused)) struct cmdline *cl,
1026                                 __attribute__((unused)) void *data)
1027 {
1028         struct cmd_operate_specific_port_result *res = parsed_result;
1029
1030         if (!strcmp(res->name, "start"))
1031                 start_port(res->value);
1032         else if (!strcmp(res->name, "stop"))
1033                 stop_port(res->value);
1034         else if (!strcmp(res->name, "close"))
1035                 close_port(res->value);
1036         else if (!strcmp(res->name, "reset"))
1037                 reset_port(res->value);
1038         else
1039                 printf("Unknown parameter\n");
1040 }
1041
1042 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1043         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1044                                                         keyword, "port");
1045 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1046         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1047                                                 name, "start#stop#close#reset");
1048 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1049         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1050                                                         value, UINT8);
1051
1052 cmdline_parse_inst_t cmd_operate_specific_port = {
1053         .f = cmd_operate_specific_port_parsed,
1054         .data = NULL,
1055         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1056         .tokens = {
1057                 (void *)&cmd_operate_specific_port_cmd,
1058                 (void *)&cmd_operate_specific_port_port,
1059                 (void *)&cmd_operate_specific_port_id,
1060                 NULL,
1061         },
1062 };
1063
1064 /* *** attach a specified port *** */
1065 struct cmd_operate_attach_port_result {
1066         cmdline_fixed_string_t port;
1067         cmdline_fixed_string_t keyword;
1068         cmdline_fixed_string_t identifier;
1069 };
1070
1071 static void cmd_operate_attach_port_parsed(void *parsed_result,
1072                                 __attribute__((unused)) struct cmdline *cl,
1073                                 __attribute__((unused)) void *data)
1074 {
1075         struct cmd_operate_attach_port_result *res = parsed_result;
1076
1077         if (!strcmp(res->keyword, "attach"))
1078                 attach_port(res->identifier);
1079         else
1080                 printf("Unknown parameter\n");
1081 }
1082
1083 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1084         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1085                         port, "port");
1086 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1087         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1088                         keyword, "attach");
1089 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1090         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1091                         identifier, NULL);
1092
1093 cmdline_parse_inst_t cmd_operate_attach_port = {
1094         .f = cmd_operate_attach_port_parsed,
1095         .data = NULL,
1096         .help_str = "port attach <identifier>: "
1097                 "(identifier: pci address or virtual dev name)",
1098         .tokens = {
1099                 (void *)&cmd_operate_attach_port_port,
1100                 (void *)&cmd_operate_attach_port_keyword,
1101                 (void *)&cmd_operate_attach_port_identifier,
1102                 NULL,
1103         },
1104 };
1105
1106 /* *** detach a specified port *** */
1107 struct cmd_operate_detach_port_result {
1108         cmdline_fixed_string_t port;
1109         cmdline_fixed_string_t keyword;
1110         uint8_t port_id;
1111 };
1112
1113 static void cmd_operate_detach_port_parsed(void *parsed_result,
1114                                 __attribute__((unused)) struct cmdline *cl,
1115                                 __attribute__((unused)) void *data)
1116 {
1117         struct cmd_operate_detach_port_result *res = parsed_result;
1118
1119         if (!strcmp(res->keyword, "detach"))
1120                 detach_port(res->port_id);
1121         else
1122                 printf("Unknown parameter\n");
1123 }
1124
1125 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1126         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1127                         port, "port");
1128 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1129         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1130                         keyword, "detach");
1131 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1132         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1133                         port_id, UINT8);
1134
1135 cmdline_parse_inst_t cmd_operate_detach_port = {
1136         .f = cmd_operate_detach_port_parsed,
1137         .data = NULL,
1138         .help_str = "port detach <port_id>",
1139         .tokens = {
1140                 (void *)&cmd_operate_detach_port_port,
1141                 (void *)&cmd_operate_detach_port_keyword,
1142                 (void *)&cmd_operate_detach_port_port_id,
1143                 NULL,
1144         },
1145 };
1146
1147 /* *** configure speed for all ports *** */
1148 struct cmd_config_speed_all {
1149         cmdline_fixed_string_t port;
1150         cmdline_fixed_string_t keyword;
1151         cmdline_fixed_string_t all;
1152         cmdline_fixed_string_t item1;
1153         cmdline_fixed_string_t item2;
1154         cmdline_fixed_string_t value1;
1155         cmdline_fixed_string_t value2;
1156 };
1157
1158 static int
1159 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1160 {
1161
1162         int duplex;
1163
1164         if (!strcmp(duplexstr, "half")) {
1165                 duplex = ETH_LINK_HALF_DUPLEX;
1166         } else if (!strcmp(duplexstr, "full")) {
1167                 duplex = ETH_LINK_FULL_DUPLEX;
1168         } else if (!strcmp(duplexstr, "auto")) {
1169                 duplex = ETH_LINK_FULL_DUPLEX;
1170         } else {
1171                 printf("Unknown duplex parameter\n");
1172                 return -1;
1173         }
1174
1175         if (!strcmp(speedstr, "10")) {
1176                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1177                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1178         } else if (!strcmp(speedstr, "100")) {
1179                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1180                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1181         } else {
1182                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1183                         printf("Invalid speed/duplex parameters\n");
1184                         return -1;
1185                 }
1186                 if (!strcmp(speedstr, "1000")) {
1187                         *speed = ETH_LINK_SPEED_1G;
1188                 } else if (!strcmp(speedstr, "10000")) {
1189                         *speed = ETH_LINK_SPEED_10G;
1190                 } else if (!strcmp(speedstr, "25000")) {
1191                         *speed = ETH_LINK_SPEED_25G;
1192                 } else if (!strcmp(speedstr, "40000")) {
1193                         *speed = ETH_LINK_SPEED_40G;
1194                 } else if (!strcmp(speedstr, "50000")) {
1195                         *speed = ETH_LINK_SPEED_50G;
1196                 } else if (!strcmp(speedstr, "100000")) {
1197                         *speed = ETH_LINK_SPEED_100G;
1198                 } else if (!strcmp(speedstr, "auto")) {
1199                         *speed = ETH_LINK_SPEED_AUTONEG;
1200                 } else {
1201                         printf("Unknown speed parameter\n");
1202                         return -1;
1203                 }
1204         }
1205
1206         return 0;
1207 }
1208
1209 static void
1210 cmd_config_speed_all_parsed(void *parsed_result,
1211                         __attribute__((unused)) struct cmdline *cl,
1212                         __attribute__((unused)) void *data)
1213 {
1214         struct cmd_config_speed_all *res = parsed_result;
1215         uint32_t link_speed;
1216         portid_t pid;
1217
1218         if (!all_ports_stopped()) {
1219                 printf("Please stop all ports first\n");
1220                 return;
1221         }
1222
1223         if (parse_and_check_speed_duplex(res->value1, res->value2,
1224                         &link_speed) < 0)
1225                 return;
1226
1227         RTE_ETH_FOREACH_DEV(pid) {
1228                 ports[pid].dev_conf.link_speeds = link_speed;
1229         }
1230
1231         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1232 }
1233
1234 cmdline_parse_token_string_t cmd_config_speed_all_port =
1235         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1236 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1238                                                         "config");
1239 cmdline_parse_token_string_t cmd_config_speed_all_all =
1240         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1241 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1242         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1243 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1244         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1245                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1246 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1247         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1248 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1249         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1250                                                 "half#full#auto");
1251
1252 cmdline_parse_inst_t cmd_config_speed_all = {
1253         .f = cmd_config_speed_all_parsed,
1254         .data = NULL,
1255         .help_str = "port config all speed "
1256                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1257                                                         "half|full|auto",
1258         .tokens = {
1259                 (void *)&cmd_config_speed_all_port,
1260                 (void *)&cmd_config_speed_all_keyword,
1261                 (void *)&cmd_config_speed_all_all,
1262                 (void *)&cmd_config_speed_all_item1,
1263                 (void *)&cmd_config_speed_all_value1,
1264                 (void *)&cmd_config_speed_all_item2,
1265                 (void *)&cmd_config_speed_all_value2,
1266                 NULL,
1267         },
1268 };
1269
1270 /* *** configure speed for specific port *** */
1271 struct cmd_config_speed_specific {
1272         cmdline_fixed_string_t port;
1273         cmdline_fixed_string_t keyword;
1274         uint8_t id;
1275         cmdline_fixed_string_t item1;
1276         cmdline_fixed_string_t item2;
1277         cmdline_fixed_string_t value1;
1278         cmdline_fixed_string_t value2;
1279 };
1280
1281 static void
1282 cmd_config_speed_specific_parsed(void *parsed_result,
1283                                 __attribute__((unused)) struct cmdline *cl,
1284                                 __attribute__((unused)) void *data)
1285 {
1286         struct cmd_config_speed_specific *res = parsed_result;
1287         uint32_t link_speed;
1288
1289         if (!all_ports_stopped()) {
1290                 printf("Please stop all ports first\n");
1291                 return;
1292         }
1293
1294         if (port_id_is_invalid(res->id, ENABLED_WARN))
1295                 return;
1296
1297         if (parse_and_check_speed_duplex(res->value1, res->value2,
1298                         &link_speed) < 0)
1299                 return;
1300
1301         ports[res->id].dev_conf.link_speeds = link_speed;
1302
1303         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1304 }
1305
1306
1307 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1308         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1309                                                                 "port");
1310 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1311         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1312                                                                 "config");
1313 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1314         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1315 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1316         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1317                                                                 "speed");
1318 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1319         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1320                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1321 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1322         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1323                                                                 "duplex");
1324 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1325         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1326                                                         "half#full#auto");
1327
1328 cmdline_parse_inst_t cmd_config_speed_specific = {
1329         .f = cmd_config_speed_specific_parsed,
1330         .data = NULL,
1331         .help_str = "port config <port_id> speed "
1332                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1333                                                         "half|full|auto",
1334         .tokens = {
1335                 (void *)&cmd_config_speed_specific_port,
1336                 (void *)&cmd_config_speed_specific_keyword,
1337                 (void *)&cmd_config_speed_specific_id,
1338                 (void *)&cmd_config_speed_specific_item1,
1339                 (void *)&cmd_config_speed_specific_value1,
1340                 (void *)&cmd_config_speed_specific_item2,
1341                 (void *)&cmd_config_speed_specific_value2,
1342                 NULL,
1343         },
1344 };
1345
1346 /* *** configure txq/rxq, txd/rxd *** */
1347 struct cmd_config_rx_tx {
1348         cmdline_fixed_string_t port;
1349         cmdline_fixed_string_t keyword;
1350         cmdline_fixed_string_t all;
1351         cmdline_fixed_string_t name;
1352         uint16_t value;
1353 };
1354
1355 static void
1356 cmd_config_rx_tx_parsed(void *parsed_result,
1357                         __attribute__((unused)) struct cmdline *cl,
1358                         __attribute__((unused)) void *data)
1359 {
1360         struct cmd_config_rx_tx *res = parsed_result;
1361
1362         if (!all_ports_stopped()) {
1363                 printf("Please stop all ports first\n");
1364                 return;
1365         }
1366         if (!strcmp(res->name, "rxq")) {
1367                 if (!res->value && !nb_txq) {
1368                         printf("Warning: Either rx or tx queues should be non zero\n");
1369                         return;
1370                 }
1371                 nb_rxq = res->value;
1372         }
1373         else if (!strcmp(res->name, "txq")) {
1374                 if (!res->value && !nb_rxq) {
1375                         printf("Warning: Either rx or tx queues should be non zero\n");
1376                         return;
1377                 }
1378                 nb_txq = res->value;
1379         }
1380         else if (!strcmp(res->name, "rxd")) {
1381                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1382                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1383                                         res->value, RTE_TEST_RX_DESC_MAX);
1384                         return;
1385                 }
1386                 nb_rxd = res->value;
1387         } else if (!strcmp(res->name, "txd")) {
1388                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1389                         printf("txd %d invalid - must be > 0 && <= %d\n",
1390                                         res->value, RTE_TEST_TX_DESC_MAX);
1391                         return;
1392                 }
1393                 nb_txd = res->value;
1394         } else {
1395                 printf("Unknown parameter\n");
1396                 return;
1397         }
1398
1399         fwd_config_setup();
1400
1401         init_port_config();
1402
1403         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1404 }
1405
1406 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1408 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1409         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1410 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1411         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1412 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1413         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1414                                                 "rxq#txq#rxd#txd");
1415 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1416         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1417
1418 cmdline_parse_inst_t cmd_config_rx_tx = {
1419         .f = cmd_config_rx_tx_parsed,
1420         .data = NULL,
1421         .help_str = "port config all rxq|txq|rxd|txd <value>",
1422         .tokens = {
1423                 (void *)&cmd_config_rx_tx_port,
1424                 (void *)&cmd_config_rx_tx_keyword,
1425                 (void *)&cmd_config_rx_tx_all,
1426                 (void *)&cmd_config_rx_tx_name,
1427                 (void *)&cmd_config_rx_tx_value,
1428                 NULL,
1429         },
1430 };
1431
1432 /* *** config max packet length *** */
1433 struct cmd_config_max_pkt_len_result {
1434         cmdline_fixed_string_t port;
1435         cmdline_fixed_string_t keyword;
1436         cmdline_fixed_string_t all;
1437         cmdline_fixed_string_t name;
1438         uint32_t value;
1439 };
1440
1441 static void
1442 cmd_config_max_pkt_len_parsed(void *parsed_result,
1443                                 __attribute__((unused)) struct cmdline *cl,
1444                                 __attribute__((unused)) void *data)
1445 {
1446         struct cmd_config_max_pkt_len_result *res = parsed_result;
1447
1448         if (!all_ports_stopped()) {
1449                 printf("Please stop all ports first\n");
1450                 return;
1451         }
1452
1453         if (!strcmp(res->name, "max-pkt-len")) {
1454                 if (res->value < ETHER_MIN_LEN) {
1455                         printf("max-pkt-len can not be less than %d\n",
1456                                                         ETHER_MIN_LEN);
1457                         return;
1458                 }
1459                 if (res->value == rx_mode.max_rx_pkt_len)
1460                         return;
1461
1462                 rx_mode.max_rx_pkt_len = res->value;
1463                 if (res->value > ETHER_MAX_LEN)
1464                         rx_mode.jumbo_frame = 1;
1465                 else
1466                         rx_mode.jumbo_frame = 0;
1467         } else {
1468                 printf("Unknown parameter\n");
1469                 return;
1470         }
1471
1472         init_port_config();
1473
1474         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1475 }
1476
1477 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1478         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1479                                                                 "port");
1480 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1482                                                                 "config");
1483 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1485                                                                 "all");
1486 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1488                                                                 "max-pkt-len");
1489 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1490         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1491                                                                 UINT32);
1492
1493 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1494         .f = cmd_config_max_pkt_len_parsed,
1495         .data = NULL,
1496         .help_str = "port config all max-pkt-len <value>",
1497         .tokens = {
1498                 (void *)&cmd_config_max_pkt_len_port,
1499                 (void *)&cmd_config_max_pkt_len_keyword,
1500                 (void *)&cmd_config_max_pkt_len_all,
1501                 (void *)&cmd_config_max_pkt_len_name,
1502                 (void *)&cmd_config_max_pkt_len_value,
1503                 NULL,
1504         },
1505 };
1506
1507 /* *** configure port MTU *** */
1508 struct cmd_config_mtu_result {
1509         cmdline_fixed_string_t port;
1510         cmdline_fixed_string_t keyword;
1511         cmdline_fixed_string_t mtu;
1512         uint8_t port_id;
1513         uint16_t value;
1514 };
1515
1516 static void
1517 cmd_config_mtu_parsed(void *parsed_result,
1518                       __attribute__((unused)) struct cmdline *cl,
1519                       __attribute__((unused)) void *data)
1520 {
1521         struct cmd_config_mtu_result *res = parsed_result;
1522
1523         if (res->value < ETHER_MIN_LEN) {
1524                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1525                 return;
1526         }
1527         port_mtu_set(res->port_id, res->value);
1528 }
1529
1530 cmdline_parse_token_string_t cmd_config_mtu_port =
1531         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1532                                  "port");
1533 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1534         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1535                                  "config");
1536 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1537         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1538                                  "mtu");
1539 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1540         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1541 cmdline_parse_token_num_t cmd_config_mtu_value =
1542         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1543
1544 cmdline_parse_inst_t cmd_config_mtu = {
1545         .f = cmd_config_mtu_parsed,
1546         .data = NULL,
1547         .help_str = "port config mtu <port_id> <value>",
1548         .tokens = {
1549                 (void *)&cmd_config_mtu_port,
1550                 (void *)&cmd_config_mtu_keyword,
1551                 (void *)&cmd_config_mtu_mtu,
1552                 (void *)&cmd_config_mtu_port_id,
1553                 (void *)&cmd_config_mtu_value,
1554                 NULL,
1555         },
1556 };
1557
1558 /* *** configure rx mode *** */
1559 struct cmd_config_rx_mode_flag {
1560         cmdline_fixed_string_t port;
1561         cmdline_fixed_string_t keyword;
1562         cmdline_fixed_string_t all;
1563         cmdline_fixed_string_t name;
1564         cmdline_fixed_string_t value;
1565 };
1566
1567 static void
1568 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1569                                 __attribute__((unused)) struct cmdline *cl,
1570                                 __attribute__((unused)) void *data)
1571 {
1572         struct cmd_config_rx_mode_flag *res = parsed_result;
1573
1574         if (!all_ports_stopped()) {
1575                 printf("Please stop all ports first\n");
1576                 return;
1577         }
1578
1579         if (!strcmp(res->name, "crc-strip")) {
1580                 if (!strcmp(res->value, "on"))
1581                         rx_mode.hw_strip_crc = 1;
1582                 else if (!strcmp(res->value, "off"))
1583                         rx_mode.hw_strip_crc = 0;
1584                 else {
1585                         printf("Unknown parameter\n");
1586                         return;
1587                 }
1588         } else if (!strcmp(res->name, "scatter")) {
1589                 if (!strcmp(res->value, "on"))
1590                         rx_mode.enable_scatter = 1;
1591                 else if (!strcmp(res->value, "off"))
1592                         rx_mode.enable_scatter = 0;
1593                 else {
1594                         printf("Unknown parameter\n");
1595                         return;
1596                 }
1597         } else if (!strcmp(res->name, "rx-cksum")) {
1598                 if (!strcmp(res->value, "on"))
1599                         rx_mode.hw_ip_checksum = 1;
1600                 else if (!strcmp(res->value, "off"))
1601                         rx_mode.hw_ip_checksum = 0;
1602                 else {
1603                         printf("Unknown parameter\n");
1604                         return;
1605                 }
1606         } else if (!strcmp(res->name, "hw-vlan")) {
1607                 if (!strcmp(res->value, "on")) {
1608                         rx_mode.hw_vlan_filter = 1;
1609                         rx_mode.hw_vlan_strip  = 1;
1610                 }
1611                 else if (!strcmp(res->value, "off")) {
1612                         rx_mode.hw_vlan_filter = 0;
1613                         rx_mode.hw_vlan_strip  = 0;
1614                 }
1615                 else {
1616                         printf("Unknown parameter\n");
1617                         return;
1618                 }
1619         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1620                 if (!strcmp(res->value, "on"))
1621                         rx_mode.hw_vlan_filter = 1;
1622                 else if (!strcmp(res->value, "off"))
1623                         rx_mode.hw_vlan_filter = 0;
1624                 else {
1625                         printf("Unknown parameter\n");
1626                         return;
1627                 }
1628         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1629                 if (!strcmp(res->value, "on"))
1630                         rx_mode.hw_vlan_strip  = 1;
1631                 else if (!strcmp(res->value, "off"))
1632                         rx_mode.hw_vlan_strip  = 0;
1633                 else {
1634                         printf("Unknown parameter\n");
1635                         return;
1636                 }
1637         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1638                 if (!strcmp(res->value, "on"))
1639                         rx_mode.hw_vlan_extend = 1;
1640                 else if (!strcmp(res->value, "off"))
1641                         rx_mode.hw_vlan_extend = 0;
1642                 else {
1643                         printf("Unknown parameter\n");
1644                         return;
1645                 }
1646         } else if (!strcmp(res->name, "drop-en")) {
1647                 if (!strcmp(res->value, "on"))
1648                         rx_drop_en = 1;
1649                 else if (!strcmp(res->value, "off"))
1650                         rx_drop_en = 0;
1651                 else {
1652                         printf("Unknown parameter\n");
1653                         return;
1654                 }
1655         } else {
1656                 printf("Unknown parameter\n");
1657                 return;
1658         }
1659
1660         init_port_config();
1661
1662         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1663 }
1664
1665 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1667 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1669                                                                 "config");
1670 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1672 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1673         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1674                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1675                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1676 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1678                                                         "on#off");
1679
1680 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1681         .f = cmd_config_rx_mode_flag_parsed,
1682         .data = NULL,
1683         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1684                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1685         .tokens = {
1686                 (void *)&cmd_config_rx_mode_flag_port,
1687                 (void *)&cmd_config_rx_mode_flag_keyword,
1688                 (void *)&cmd_config_rx_mode_flag_all,
1689                 (void *)&cmd_config_rx_mode_flag_name,
1690                 (void *)&cmd_config_rx_mode_flag_value,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure rss *** */
1696 struct cmd_config_rss {
1697         cmdline_fixed_string_t port;
1698         cmdline_fixed_string_t keyword;
1699         cmdline_fixed_string_t all;
1700         cmdline_fixed_string_t name;
1701         cmdline_fixed_string_t value;
1702 };
1703
1704 static void
1705 cmd_config_rss_parsed(void *parsed_result,
1706                         __attribute__((unused)) struct cmdline *cl,
1707                         __attribute__((unused)) void *data)
1708 {
1709         struct cmd_config_rss *res = parsed_result;
1710         struct rte_eth_rss_conf rss_conf;
1711         int diag;
1712         uint8_t i;
1713
1714         if (!strcmp(res->value, "all"))
1715                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1716                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1717                                         ETH_RSS_L2_PAYLOAD;
1718         else if (!strcmp(res->value, "ip"))
1719                 rss_conf.rss_hf = ETH_RSS_IP;
1720         else if (!strcmp(res->value, "udp"))
1721                 rss_conf.rss_hf = ETH_RSS_UDP;
1722         else if (!strcmp(res->value, "tcp"))
1723                 rss_conf.rss_hf = ETH_RSS_TCP;
1724         else if (!strcmp(res->value, "sctp"))
1725                 rss_conf.rss_hf = ETH_RSS_SCTP;
1726         else if (!strcmp(res->value, "ether"))
1727                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1728         else if (!strcmp(res->value, "port"))
1729                 rss_conf.rss_hf = ETH_RSS_PORT;
1730         else if (!strcmp(res->value, "vxlan"))
1731                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1732         else if (!strcmp(res->value, "geneve"))
1733                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1734         else if (!strcmp(res->value, "nvgre"))
1735                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1736         else if (!strcmp(res->value, "none"))
1737                 rss_conf.rss_hf = 0;
1738         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1739                                                 atoi(res->value) < 64)
1740                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1741         else {
1742                 printf("Unknown parameter\n");
1743                 return;
1744         }
1745         rss_conf.rss_key = NULL;
1746         for (i = 0; i < rte_eth_dev_count(); i++) {
1747                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1748                 if (diag < 0)
1749                         printf("Configuration of RSS hash at ethernet port %d "
1750                                 "failed with error (%d): %s.\n",
1751                                 i, -diag, strerror(-diag));
1752         }
1753 }
1754
1755 cmdline_parse_token_string_t cmd_config_rss_port =
1756         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1757 cmdline_parse_token_string_t cmd_config_rss_keyword =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1759 cmdline_parse_token_string_t cmd_config_rss_all =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1761 cmdline_parse_token_string_t cmd_config_rss_name =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1763 cmdline_parse_token_string_t cmd_config_rss_value =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1765
1766 cmdline_parse_inst_t cmd_config_rss = {
1767         .f = cmd_config_rss_parsed,
1768         .data = NULL,
1769         .help_str = "port config all rss "
1770                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1771         .tokens = {
1772                 (void *)&cmd_config_rss_port,
1773                 (void *)&cmd_config_rss_keyword,
1774                 (void *)&cmd_config_rss_all,
1775                 (void *)&cmd_config_rss_name,
1776                 (void *)&cmd_config_rss_value,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** configure rss hash key *** */
1782 struct cmd_config_rss_hash_key {
1783         cmdline_fixed_string_t port;
1784         cmdline_fixed_string_t config;
1785         uint8_t port_id;
1786         cmdline_fixed_string_t rss_hash_key;
1787         cmdline_fixed_string_t rss_type;
1788         cmdline_fixed_string_t key;
1789 };
1790
1791 static uint8_t
1792 hexa_digit_to_value(char hexa_digit)
1793 {
1794         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1795                 return (uint8_t) (hexa_digit - '0');
1796         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1797                 return (uint8_t) ((hexa_digit - 'a') + 10);
1798         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1799                 return (uint8_t) ((hexa_digit - 'A') + 10);
1800         /* Invalid hexa digit */
1801         return 0xFF;
1802 }
1803
1804 static uint8_t
1805 parse_and_check_key_hexa_digit(char *key, int idx)
1806 {
1807         uint8_t hexa_v;
1808
1809         hexa_v = hexa_digit_to_value(key[idx]);
1810         if (hexa_v == 0xFF)
1811                 printf("invalid key: character %c at position %d is not a "
1812                        "valid hexa digit\n", key[idx], idx);
1813         return hexa_v;
1814 }
1815
1816 static void
1817 cmd_config_rss_hash_key_parsed(void *parsed_result,
1818                                __attribute__((unused)) struct cmdline *cl,
1819                                __attribute__((unused)) void *data)
1820 {
1821         struct cmd_config_rss_hash_key *res = parsed_result;
1822         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1823         uint8_t xdgt0;
1824         uint8_t xdgt1;
1825         int i;
1826         struct rte_eth_dev_info dev_info;
1827         uint8_t hash_key_size;
1828         uint32_t key_len;
1829
1830         memset(&dev_info, 0, sizeof(dev_info));
1831         rte_eth_dev_info_get(res->port_id, &dev_info);
1832         if (dev_info.hash_key_size > 0 &&
1833                         dev_info.hash_key_size <= sizeof(hash_key))
1834                 hash_key_size = dev_info.hash_key_size;
1835         else {
1836                 printf("dev_info did not provide a valid hash key size\n");
1837                 return;
1838         }
1839         /* Check the length of the RSS hash key */
1840         key_len = strlen(res->key);
1841         if (key_len != (hash_key_size * 2)) {
1842                 printf("key length: %d invalid - key must be a string of %d"
1843                            " hexa-decimal numbers\n",
1844                            (int) key_len, hash_key_size * 2);
1845                 return;
1846         }
1847         /* Translate RSS hash key into binary representation */
1848         for (i = 0; i < hash_key_size; i++) {
1849                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1850                 if (xdgt0 == 0xFF)
1851                         return;
1852                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1853                 if (xdgt1 == 0xFF)
1854                         return;
1855                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1856         }
1857         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1858                         hash_key_size);
1859 }
1860
1861 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1863 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1864         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1865                                  "config");
1866 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1867         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1868 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1869         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1870                                  rss_hash_key, "rss-hash-key");
1871 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1873                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1874                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1875                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1876                                  "ipv6-tcp-ex#ipv6-udp-ex");
1877 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1879
1880 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1881         .f = cmd_config_rss_hash_key_parsed,
1882         .data = NULL,
1883         .help_str = "port config <port_id> rss-hash-key "
1884                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1885                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1886                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1887                 "<string of hex digits (variable length, NIC dependent)>",
1888         .tokens = {
1889                 (void *)&cmd_config_rss_hash_key_port,
1890                 (void *)&cmd_config_rss_hash_key_config,
1891                 (void *)&cmd_config_rss_hash_key_port_id,
1892                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1893                 (void *)&cmd_config_rss_hash_key_rss_type,
1894                 (void *)&cmd_config_rss_hash_key_value,
1895                 NULL,
1896         },
1897 };
1898
1899 /* *** configure port rxq/txq start/stop *** */
1900 struct cmd_config_rxtx_queue {
1901         cmdline_fixed_string_t port;
1902         uint8_t portid;
1903         cmdline_fixed_string_t rxtxq;
1904         uint16_t qid;
1905         cmdline_fixed_string_t opname;
1906 };
1907
1908 static void
1909 cmd_config_rxtx_queue_parsed(void *parsed_result,
1910                         __attribute__((unused)) struct cmdline *cl,
1911                         __attribute__((unused)) void *data)
1912 {
1913         struct cmd_config_rxtx_queue *res = parsed_result;
1914         uint8_t isrx;
1915         uint8_t isstart;
1916         int ret = 0;
1917
1918         if (test_done == 0) {
1919                 printf("Please stop forwarding first\n");
1920                 return;
1921         }
1922
1923         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1924                 return;
1925
1926         if (port_is_started(res->portid) != 1) {
1927                 printf("Please start port %u first\n", res->portid);
1928                 return;
1929         }
1930
1931         if (!strcmp(res->rxtxq, "rxq"))
1932                 isrx = 1;
1933         else if (!strcmp(res->rxtxq, "txq"))
1934                 isrx = 0;
1935         else {
1936                 printf("Unknown parameter\n");
1937                 return;
1938         }
1939
1940         if (isrx && rx_queue_id_is_invalid(res->qid))
1941                 return;
1942         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1943                 return;
1944
1945         if (!strcmp(res->opname, "start"))
1946                 isstart = 1;
1947         else if (!strcmp(res->opname, "stop"))
1948                 isstart = 0;
1949         else {
1950                 printf("Unknown parameter\n");
1951                 return;
1952         }
1953
1954         if (isstart && isrx)
1955                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1956         else if (!isstart && isrx)
1957                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1958         else if (isstart && !isrx)
1959                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1960         else
1961                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1962
1963         if (ret == -ENOTSUP)
1964                 printf("Function not supported in PMD driver\n");
1965 }
1966
1967 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1968         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1969 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1970         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1971 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1972         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1973 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1974         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1975 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1976         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1977                                                 "start#stop");
1978
1979 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1980         .f = cmd_config_rxtx_queue_parsed,
1981         .data = NULL,
1982         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1983         .tokens = {
1984                 (void *)&cmd_config_speed_all_port,
1985                 (void *)&cmd_config_rxtx_queue_portid,
1986                 (void *)&cmd_config_rxtx_queue_rxtxq,
1987                 (void *)&cmd_config_rxtx_queue_qid,
1988                 (void *)&cmd_config_rxtx_queue_opname,
1989                 NULL,
1990         },
1991 };
1992
1993 /* *** Configure RSS RETA *** */
1994 struct cmd_config_rss_reta {
1995         cmdline_fixed_string_t port;
1996         cmdline_fixed_string_t keyword;
1997         uint8_t port_id;
1998         cmdline_fixed_string_t name;
1999         cmdline_fixed_string_t list_name;
2000         cmdline_fixed_string_t list_of_items;
2001 };
2002
2003 static int
2004 parse_reta_config(const char *str,
2005                   struct rte_eth_rss_reta_entry64 *reta_conf,
2006                   uint16_t nb_entries)
2007 {
2008         int i;
2009         unsigned size;
2010         uint16_t hash_index, idx, shift;
2011         uint16_t nb_queue;
2012         char s[256];
2013         const char *p, *p0 = str;
2014         char *end;
2015         enum fieldnames {
2016                 FLD_HASH_INDEX = 0,
2017                 FLD_QUEUE,
2018                 _NUM_FLD
2019         };
2020         unsigned long int_fld[_NUM_FLD];
2021         char *str_fld[_NUM_FLD];
2022
2023         while ((p = strchr(p0,'(')) != NULL) {
2024                 ++p;
2025                 if((p0 = strchr(p,')')) == NULL)
2026                         return -1;
2027
2028                 size = p0 - p;
2029                 if(size >= sizeof(s))
2030                         return -1;
2031
2032                 snprintf(s, sizeof(s), "%.*s", size, p);
2033                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2034                         return -1;
2035                 for (i = 0; i < _NUM_FLD; i++) {
2036                         errno = 0;
2037                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2038                         if (errno != 0 || end == str_fld[i] ||
2039                                         int_fld[i] > 65535)
2040                                 return -1;
2041                 }
2042
2043                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2044                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2045
2046                 if (hash_index >= nb_entries) {
2047                         printf("Invalid RETA hash index=%d\n", hash_index);
2048                         return -1;
2049                 }
2050
2051                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2052                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2053                 reta_conf[idx].mask |= (1ULL << shift);
2054                 reta_conf[idx].reta[shift] = nb_queue;
2055         }
2056
2057         return 0;
2058 }
2059
2060 static void
2061 cmd_set_rss_reta_parsed(void *parsed_result,
2062                         __attribute__((unused)) struct cmdline *cl,
2063                         __attribute__((unused)) void *data)
2064 {
2065         int ret;
2066         struct rte_eth_dev_info dev_info;
2067         struct rte_eth_rss_reta_entry64 reta_conf[8];
2068         struct cmd_config_rss_reta *res = parsed_result;
2069
2070         memset(&dev_info, 0, sizeof(dev_info));
2071         rte_eth_dev_info_get(res->port_id, &dev_info);
2072         if (dev_info.reta_size == 0) {
2073                 printf("Redirection table size is 0 which is "
2074                                         "invalid for RSS\n");
2075                 return;
2076         } else
2077                 printf("The reta size of port %d is %u\n",
2078                         res->port_id, dev_info.reta_size);
2079         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2080                 printf("Currently do not support more than %u entries of "
2081                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2082                 return;
2083         }
2084
2085         memset(reta_conf, 0, sizeof(reta_conf));
2086         if (!strcmp(res->list_name, "reta")) {
2087                 if (parse_reta_config(res->list_of_items, reta_conf,
2088                                                 dev_info.reta_size)) {
2089                         printf("Invalid RSS Redirection Table "
2090                                         "config entered\n");
2091                         return;
2092                 }
2093                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2094                                 reta_conf, dev_info.reta_size);
2095                 if (ret != 0)
2096                         printf("Bad redirection table parameter, "
2097                                         "return code = %d \n", ret);
2098         }
2099 }
2100
2101 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2103 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2104         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2105 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2106         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2107 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2108         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2109 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2111 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2112         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2113                                  NULL);
2114 cmdline_parse_inst_t cmd_config_rss_reta = {
2115         .f = cmd_set_rss_reta_parsed,
2116         .data = NULL,
2117         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2118         .tokens = {
2119                 (void *)&cmd_config_rss_reta_port,
2120                 (void *)&cmd_config_rss_reta_keyword,
2121                 (void *)&cmd_config_rss_reta_port_id,
2122                 (void *)&cmd_config_rss_reta_name,
2123                 (void *)&cmd_config_rss_reta_list_name,
2124                 (void *)&cmd_config_rss_reta_list_of_items,
2125                 NULL,
2126         },
2127 };
2128
2129 /* *** SHOW PORT RETA INFO *** */
2130 struct cmd_showport_reta {
2131         cmdline_fixed_string_t show;
2132         cmdline_fixed_string_t port;
2133         uint8_t port_id;
2134         cmdline_fixed_string_t rss;
2135         cmdline_fixed_string_t reta;
2136         uint16_t size;
2137         cmdline_fixed_string_t list_of_items;
2138 };
2139
2140 static int
2141 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2142                            uint16_t nb_entries,
2143                            char *str)
2144 {
2145         uint32_t size;
2146         const char *p, *p0 = str;
2147         char s[256];
2148         char *end;
2149         char *str_fld[8];
2150         uint16_t i;
2151         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2152                         RTE_RETA_GROUP_SIZE;
2153         int ret;
2154
2155         p = strchr(p0, '(');
2156         if (p == NULL)
2157                 return -1;
2158         p++;
2159         p0 = strchr(p, ')');
2160         if (p0 == NULL)
2161                 return -1;
2162         size = p0 - p;
2163         if (size >= sizeof(s)) {
2164                 printf("The string size exceeds the internal buffer size\n");
2165                 return -1;
2166         }
2167         snprintf(s, sizeof(s), "%.*s", size, p);
2168         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2169         if (ret <= 0 || ret != num) {
2170                 printf("The bits of masks do not match the number of "
2171                                         "reta entries: %u\n", num);
2172                 return -1;
2173         }
2174         for (i = 0; i < ret; i++)
2175                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2176
2177         return 0;
2178 }
2179
2180 static void
2181 cmd_showport_reta_parsed(void *parsed_result,
2182                          __attribute__((unused)) struct cmdline *cl,
2183                          __attribute__((unused)) void *data)
2184 {
2185         struct cmd_showport_reta *res = parsed_result;
2186         struct rte_eth_rss_reta_entry64 reta_conf[8];
2187         struct rte_eth_dev_info dev_info;
2188
2189         memset(&dev_info, 0, sizeof(dev_info));
2190         rte_eth_dev_info_get(res->port_id, &dev_info);
2191         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2192                                 res->size > ETH_RSS_RETA_SIZE_512) {
2193                 printf("Invalid redirection table size: %u\n", res->size);
2194                 return;
2195         }
2196
2197         memset(reta_conf, 0, sizeof(reta_conf));
2198         if (showport_parse_reta_config(reta_conf, res->size,
2199                                 res->list_of_items) < 0) {
2200                 printf("Invalid string: %s for reta masks\n",
2201                                         res->list_of_items);
2202                 return;
2203         }
2204         port_rss_reta_info(res->port_id, reta_conf, res->size);
2205 }
2206
2207 cmdline_parse_token_string_t cmd_showport_reta_show =
2208         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2209 cmdline_parse_token_string_t cmd_showport_reta_port =
2210         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2211 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2212         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2213 cmdline_parse_token_string_t cmd_showport_reta_rss =
2214         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2215 cmdline_parse_token_string_t cmd_showport_reta_reta =
2216         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2217 cmdline_parse_token_num_t cmd_showport_reta_size =
2218         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2219 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2220         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2221                                         list_of_items, NULL);
2222
2223 cmdline_parse_inst_t cmd_showport_reta = {
2224         .f = cmd_showport_reta_parsed,
2225         .data = NULL,
2226         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2227         .tokens = {
2228                 (void *)&cmd_showport_reta_show,
2229                 (void *)&cmd_showport_reta_port,
2230                 (void *)&cmd_showport_reta_port_id,
2231                 (void *)&cmd_showport_reta_rss,
2232                 (void *)&cmd_showport_reta_reta,
2233                 (void *)&cmd_showport_reta_size,
2234                 (void *)&cmd_showport_reta_list_of_items,
2235                 NULL,
2236         },
2237 };
2238
2239 /* *** Show RSS hash configuration *** */
2240 struct cmd_showport_rss_hash {
2241         cmdline_fixed_string_t show;
2242         cmdline_fixed_string_t port;
2243         uint8_t port_id;
2244         cmdline_fixed_string_t rss_hash;
2245         cmdline_fixed_string_t rss_type;
2246         cmdline_fixed_string_t key; /* optional argument */
2247 };
2248
2249 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2250                                 __attribute__((unused)) struct cmdline *cl,
2251                                 void *show_rss_key)
2252 {
2253         struct cmd_showport_rss_hash *res = parsed_result;
2254
2255         port_rss_hash_conf_show(res->port_id, res->rss_type,
2256                                 show_rss_key != NULL);
2257 }
2258
2259 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2260         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2261 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2262         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2263 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2264         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2265 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2266         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2267                                  "rss-hash");
2268 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2269         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2270                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2271                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2272                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2273                                  "ipv6-tcp-ex#ipv6-udp-ex");
2274 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2275         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2276
2277 cmdline_parse_inst_t cmd_showport_rss_hash = {
2278         .f = cmd_showport_rss_hash_parsed,
2279         .data = NULL,
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",
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                 NULL,
2291         },
2292 };
2293
2294 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2295         .f = cmd_showport_rss_hash_parsed,
2296         .data = (void *)1,
2297         .help_str = "show port <port_id> rss-hash "
2298                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2299                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2300                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2301         .tokens = {
2302                 (void *)&cmd_showport_rss_hash_show,
2303                 (void *)&cmd_showport_rss_hash_port,
2304                 (void *)&cmd_showport_rss_hash_port_id,
2305                 (void *)&cmd_showport_rss_hash_rss_hash,
2306                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2307                 (void *)&cmd_showport_rss_hash_rss_key,
2308                 NULL,
2309         },
2310 };
2311
2312 /* *** Configure DCB *** */
2313 struct cmd_config_dcb {
2314         cmdline_fixed_string_t port;
2315         cmdline_fixed_string_t config;
2316         uint8_t port_id;
2317         cmdline_fixed_string_t dcb;
2318         cmdline_fixed_string_t vt;
2319         cmdline_fixed_string_t vt_en;
2320         uint8_t num_tcs;
2321         cmdline_fixed_string_t pfc;
2322         cmdline_fixed_string_t pfc_en;
2323 };
2324
2325 static void
2326 cmd_config_dcb_parsed(void *parsed_result,
2327                         __attribute__((unused)) struct cmdline *cl,
2328                         __attribute__((unused)) void *data)
2329 {
2330         struct cmd_config_dcb *res = parsed_result;
2331         portid_t port_id = res->port_id;
2332         struct rte_port *port;
2333         uint8_t pfc_en;
2334         int ret;
2335
2336         port = &ports[port_id];
2337         /** Check if the port is not started **/
2338         if (port->port_status != RTE_PORT_STOPPED) {
2339                 printf("Please stop port %d first\n", port_id);
2340                 return;
2341         }
2342
2343         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2344                 printf("The invalid number of traffic class,"
2345                         " only 4 or 8 allowed.\n");
2346                 return;
2347         }
2348
2349         if (nb_fwd_lcores < res->num_tcs) {
2350                 printf("nb_cores shouldn't be less than number of TCs.\n");
2351                 return;
2352         }
2353         if (!strncmp(res->pfc_en, "on", 2))
2354                 pfc_en = 1;
2355         else
2356                 pfc_en = 0;
2357
2358         /* DCB in VT mode */
2359         if (!strncmp(res->vt_en, "on", 2))
2360                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2361                                 (enum rte_eth_nb_tcs)res->num_tcs,
2362                                 pfc_en);
2363         else
2364                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2365                                 (enum rte_eth_nb_tcs)res->num_tcs,
2366                                 pfc_en);
2367
2368
2369         if (ret != 0) {
2370                 printf("Cannot initialize network ports.\n");
2371                 return;
2372         }
2373
2374         cmd_reconfig_device_queue(port_id, 1, 1);
2375 }
2376
2377 cmdline_parse_token_string_t cmd_config_dcb_port =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2379 cmdline_parse_token_string_t cmd_config_dcb_config =
2380         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2381 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2382         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2383 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2385 cmdline_parse_token_string_t cmd_config_dcb_vt =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2387 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2388         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2389 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2390         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2391 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2392         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2393 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2395
2396 cmdline_parse_inst_t cmd_config_dcb = {
2397         .f = cmd_config_dcb_parsed,
2398         .data = NULL,
2399         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2400         .tokens = {
2401                 (void *)&cmd_config_dcb_port,
2402                 (void *)&cmd_config_dcb_config,
2403                 (void *)&cmd_config_dcb_port_id,
2404                 (void *)&cmd_config_dcb_dcb,
2405                 (void *)&cmd_config_dcb_vt,
2406                 (void *)&cmd_config_dcb_vt_en,
2407                 (void *)&cmd_config_dcb_num_tcs,
2408                 (void *)&cmd_config_dcb_pfc,
2409                 (void *)&cmd_config_dcb_pfc_en,
2410                 NULL,
2411         },
2412 };
2413
2414 /* *** configure number of packets per burst *** */
2415 struct cmd_config_burst {
2416         cmdline_fixed_string_t port;
2417         cmdline_fixed_string_t keyword;
2418         cmdline_fixed_string_t all;
2419         cmdline_fixed_string_t name;
2420         uint16_t value;
2421 };
2422
2423 static void
2424 cmd_config_burst_parsed(void *parsed_result,
2425                         __attribute__((unused)) struct cmdline *cl,
2426                         __attribute__((unused)) void *data)
2427 {
2428         struct cmd_config_burst *res = parsed_result;
2429
2430         if (!all_ports_stopped()) {
2431                 printf("Please stop all ports first\n");
2432                 return;
2433         }
2434
2435         if (!strcmp(res->name, "burst")) {
2436                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2437                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2438                         return;
2439                 }
2440                 nb_pkt_per_burst = res->value;
2441         } else {
2442                 printf("Unknown parameter\n");
2443                 return;
2444         }
2445
2446         init_port_config();
2447
2448         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2449 }
2450
2451 cmdline_parse_token_string_t cmd_config_burst_port =
2452         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2453 cmdline_parse_token_string_t cmd_config_burst_keyword =
2454         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2455 cmdline_parse_token_string_t cmd_config_burst_all =
2456         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2457 cmdline_parse_token_string_t cmd_config_burst_name =
2458         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2459 cmdline_parse_token_num_t cmd_config_burst_value =
2460         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2461
2462 cmdline_parse_inst_t cmd_config_burst = {
2463         .f = cmd_config_burst_parsed,
2464         .data = NULL,
2465         .help_str = "port config all burst <value>",
2466         .tokens = {
2467                 (void *)&cmd_config_burst_port,
2468                 (void *)&cmd_config_burst_keyword,
2469                 (void *)&cmd_config_burst_all,
2470                 (void *)&cmd_config_burst_name,
2471                 (void *)&cmd_config_burst_value,
2472                 NULL,
2473         },
2474 };
2475
2476 /* *** configure rx/tx queues *** */
2477 struct cmd_config_thresh {
2478         cmdline_fixed_string_t port;
2479         cmdline_fixed_string_t keyword;
2480         cmdline_fixed_string_t all;
2481         cmdline_fixed_string_t name;
2482         uint8_t value;
2483 };
2484
2485 static void
2486 cmd_config_thresh_parsed(void *parsed_result,
2487                         __attribute__((unused)) struct cmdline *cl,
2488                         __attribute__((unused)) void *data)
2489 {
2490         struct cmd_config_thresh *res = parsed_result;
2491
2492         if (!all_ports_stopped()) {
2493                 printf("Please stop all ports first\n");
2494                 return;
2495         }
2496
2497         if (!strcmp(res->name, "txpt"))
2498                 tx_pthresh = res->value;
2499         else if(!strcmp(res->name, "txht"))
2500                 tx_hthresh = res->value;
2501         else if(!strcmp(res->name, "txwt"))
2502                 tx_wthresh = res->value;
2503         else if(!strcmp(res->name, "rxpt"))
2504                 rx_pthresh = res->value;
2505         else if(!strcmp(res->name, "rxht"))
2506                 rx_hthresh = res->value;
2507         else if(!strcmp(res->name, "rxwt"))
2508                 rx_wthresh = res->value;
2509         else {
2510                 printf("Unknown parameter\n");
2511                 return;
2512         }
2513
2514         init_port_config();
2515
2516         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2517 }
2518
2519 cmdline_parse_token_string_t cmd_config_thresh_port =
2520         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2521 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2522         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2523 cmdline_parse_token_string_t cmd_config_thresh_all =
2524         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2525 cmdline_parse_token_string_t cmd_config_thresh_name =
2526         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2527                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2528 cmdline_parse_token_num_t cmd_config_thresh_value =
2529         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2530
2531 cmdline_parse_inst_t cmd_config_thresh = {
2532         .f = cmd_config_thresh_parsed,
2533         .data = NULL,
2534         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2535         .tokens = {
2536                 (void *)&cmd_config_thresh_port,
2537                 (void *)&cmd_config_thresh_keyword,
2538                 (void *)&cmd_config_thresh_all,
2539                 (void *)&cmd_config_thresh_name,
2540                 (void *)&cmd_config_thresh_value,
2541                 NULL,
2542         },
2543 };
2544
2545 /* *** configure free/rs threshold *** */
2546 struct cmd_config_threshold {
2547         cmdline_fixed_string_t port;
2548         cmdline_fixed_string_t keyword;
2549         cmdline_fixed_string_t all;
2550         cmdline_fixed_string_t name;
2551         uint16_t value;
2552 };
2553
2554 static void
2555 cmd_config_threshold_parsed(void *parsed_result,
2556                         __attribute__((unused)) struct cmdline *cl,
2557                         __attribute__((unused)) void *data)
2558 {
2559         struct cmd_config_threshold *res = parsed_result;
2560
2561         if (!all_ports_stopped()) {
2562                 printf("Please stop all ports first\n");
2563                 return;
2564         }
2565
2566         if (!strcmp(res->name, "txfreet"))
2567                 tx_free_thresh = res->value;
2568         else if (!strcmp(res->name, "txrst"))
2569                 tx_rs_thresh = res->value;
2570         else if (!strcmp(res->name, "rxfreet"))
2571                 rx_free_thresh = res->value;
2572         else {
2573                 printf("Unknown parameter\n");
2574                 return;
2575         }
2576
2577         init_port_config();
2578
2579         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2580 }
2581
2582 cmdline_parse_token_string_t cmd_config_threshold_port =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2584 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2585         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2586                                                                 "config");
2587 cmdline_parse_token_string_t cmd_config_threshold_all =
2588         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2589 cmdline_parse_token_string_t cmd_config_threshold_name =
2590         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2591                                                 "txfreet#txrst#rxfreet");
2592 cmdline_parse_token_num_t cmd_config_threshold_value =
2593         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2594
2595 cmdline_parse_inst_t cmd_config_threshold = {
2596         .f = cmd_config_threshold_parsed,
2597         .data = NULL,
2598         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2599         .tokens = {
2600                 (void *)&cmd_config_threshold_port,
2601                 (void *)&cmd_config_threshold_keyword,
2602                 (void *)&cmd_config_threshold_all,
2603                 (void *)&cmd_config_threshold_name,
2604                 (void *)&cmd_config_threshold_value,
2605                 NULL,
2606         },
2607 };
2608
2609 /* *** stop *** */
2610 struct cmd_stop_result {
2611         cmdline_fixed_string_t stop;
2612 };
2613
2614 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2615                             __attribute__((unused)) struct cmdline *cl,
2616                             __attribute__((unused)) void *data)
2617 {
2618         stop_packet_forwarding();
2619 }
2620
2621 cmdline_parse_token_string_t cmd_stop_stop =
2622         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2623
2624 cmdline_parse_inst_t cmd_stop = {
2625         .f = cmd_stop_parsed,
2626         .data = NULL,
2627         .help_str = "stop: Stop packet forwarding",
2628         .tokens = {
2629                 (void *)&cmd_stop_stop,
2630                 NULL,
2631         },
2632 };
2633
2634 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2635
2636 unsigned int
2637 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2638                 unsigned int *parsed_items, int check_unique_values)
2639 {
2640         unsigned int nb_item;
2641         unsigned int value;
2642         unsigned int i;
2643         unsigned int j;
2644         int value_ok;
2645         char c;
2646
2647         /*
2648          * First parse all items in the list and store their value.
2649          */
2650         value = 0;
2651         nb_item = 0;
2652         value_ok = 0;
2653         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2654                 c = str[i];
2655                 if ((c >= '0') && (c <= '9')) {
2656                         value = (unsigned int) (value * 10 + (c - '0'));
2657                         value_ok = 1;
2658                         continue;
2659                 }
2660                 if (c != ',') {
2661                         printf("character %c is not a decimal digit\n", c);
2662                         return 0;
2663                 }
2664                 if (! value_ok) {
2665                         printf("No valid value before comma\n");
2666                         return 0;
2667                 }
2668                 if (nb_item < max_items) {
2669                         parsed_items[nb_item] = value;
2670                         value_ok = 0;
2671                         value = 0;
2672                 }
2673                 nb_item++;
2674         }
2675         if (nb_item >= max_items) {
2676                 printf("Number of %s = %u > %u (maximum items)\n",
2677                        item_name, nb_item + 1, max_items);
2678                 return 0;
2679         }
2680         parsed_items[nb_item++] = value;
2681         if (! check_unique_values)
2682                 return nb_item;
2683
2684         /*
2685          * Then, check that all values in the list are differents.
2686          * No optimization here...
2687          */
2688         for (i = 0; i < nb_item; i++) {
2689                 for (j = i + 1; j < nb_item; j++) {
2690                         if (parsed_items[j] == parsed_items[i]) {
2691                                 printf("duplicated %s %u at index %u and %u\n",
2692                                        item_name, parsed_items[i], i, j);
2693                                 return 0;
2694                         }
2695                 }
2696         }
2697         return nb_item;
2698 }
2699
2700 struct cmd_set_list_result {
2701         cmdline_fixed_string_t cmd_keyword;
2702         cmdline_fixed_string_t list_name;
2703         cmdline_fixed_string_t list_of_items;
2704 };
2705
2706 static void cmd_set_list_parsed(void *parsed_result,
2707                                 __attribute__((unused)) struct cmdline *cl,
2708                                 __attribute__((unused)) void *data)
2709 {
2710         struct cmd_set_list_result *res;
2711         union {
2712                 unsigned int lcorelist[RTE_MAX_LCORE];
2713                 unsigned int portlist[RTE_MAX_ETHPORTS];
2714         } parsed_items;
2715         unsigned int nb_item;
2716
2717         if (test_done == 0) {
2718                 printf("Please stop forwarding first\n");
2719                 return;
2720         }
2721
2722         res = parsed_result;
2723         if (!strcmp(res->list_name, "corelist")) {
2724                 nb_item = parse_item_list(res->list_of_items, "core",
2725                                           RTE_MAX_LCORE,
2726                                           parsed_items.lcorelist, 1);
2727                 if (nb_item > 0) {
2728                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2729                         fwd_config_setup();
2730                 }
2731                 return;
2732         }
2733         if (!strcmp(res->list_name, "portlist")) {
2734                 nb_item = parse_item_list(res->list_of_items, "port",
2735                                           RTE_MAX_ETHPORTS,
2736                                           parsed_items.portlist, 1);
2737                 if (nb_item > 0) {
2738                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2739                         fwd_config_setup();
2740                 }
2741         }
2742 }
2743
2744 cmdline_parse_token_string_t cmd_set_list_keyword =
2745         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2746                                  "set");
2747 cmdline_parse_token_string_t cmd_set_list_name =
2748         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2749                                  "corelist#portlist");
2750 cmdline_parse_token_string_t cmd_set_list_of_items =
2751         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2752                                  NULL);
2753
2754 cmdline_parse_inst_t cmd_set_fwd_list = {
2755         .f = cmd_set_list_parsed,
2756         .data = NULL,
2757         .help_str = "set corelist|portlist <list0[,list1]*>",
2758         .tokens = {
2759                 (void *)&cmd_set_list_keyword,
2760                 (void *)&cmd_set_list_name,
2761                 (void *)&cmd_set_list_of_items,
2762                 NULL,
2763         },
2764 };
2765
2766 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2767
2768 struct cmd_setmask_result {
2769         cmdline_fixed_string_t set;
2770         cmdline_fixed_string_t mask;
2771         uint64_t hexavalue;
2772 };
2773
2774 static void cmd_set_mask_parsed(void *parsed_result,
2775                                 __attribute__((unused)) struct cmdline *cl,
2776                                 __attribute__((unused)) void *data)
2777 {
2778         struct cmd_setmask_result *res = parsed_result;
2779
2780         if (test_done == 0) {
2781                 printf("Please stop forwarding first\n");
2782                 return;
2783         }
2784         if (!strcmp(res->mask, "coremask")) {
2785                 set_fwd_lcores_mask(res->hexavalue);
2786                 fwd_config_setup();
2787         } else if (!strcmp(res->mask, "portmask")) {
2788                 set_fwd_ports_mask(res->hexavalue);
2789                 fwd_config_setup();
2790         }
2791 }
2792
2793 cmdline_parse_token_string_t cmd_setmask_set =
2794         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2795 cmdline_parse_token_string_t cmd_setmask_mask =
2796         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2797                                  "coremask#portmask");
2798 cmdline_parse_token_num_t cmd_setmask_value =
2799         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2800
2801 cmdline_parse_inst_t cmd_set_fwd_mask = {
2802         .f = cmd_set_mask_parsed,
2803         .data = NULL,
2804         .help_str = "set coremask|portmask <hexadecimal value>",
2805         .tokens = {
2806                 (void *)&cmd_setmask_set,
2807                 (void *)&cmd_setmask_mask,
2808                 (void *)&cmd_setmask_value,
2809                 NULL,
2810         },
2811 };
2812
2813 /*
2814  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2815  */
2816 struct cmd_set_result {
2817         cmdline_fixed_string_t set;
2818         cmdline_fixed_string_t what;
2819         uint16_t value;
2820 };
2821
2822 static void cmd_set_parsed(void *parsed_result,
2823                            __attribute__((unused)) struct cmdline *cl,
2824                            __attribute__((unused)) void *data)
2825 {
2826         struct cmd_set_result *res = parsed_result;
2827         if (!strcmp(res->what, "nbport")) {
2828                 set_fwd_ports_number(res->value);
2829                 fwd_config_setup();
2830         } else if (!strcmp(res->what, "nbcore")) {
2831                 set_fwd_lcores_number(res->value);
2832                 fwd_config_setup();
2833         } else if (!strcmp(res->what, "burst"))
2834                 set_nb_pkt_per_burst(res->value);
2835         else if (!strcmp(res->what, "verbose"))
2836                 set_verbose_level(res->value);
2837 }
2838
2839 cmdline_parse_token_string_t cmd_set_set =
2840         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2841 cmdline_parse_token_string_t cmd_set_what =
2842         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2843                                  "nbport#nbcore#burst#verbose");
2844 cmdline_parse_token_num_t cmd_set_value =
2845         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2846
2847 cmdline_parse_inst_t cmd_set_numbers = {
2848         .f = cmd_set_parsed,
2849         .data = NULL,
2850         .help_str = "set nbport|nbcore|burst|verbose <value>",
2851         .tokens = {
2852                 (void *)&cmd_set_set,
2853                 (void *)&cmd_set_what,
2854                 (void *)&cmd_set_value,
2855                 NULL,
2856         },
2857 };
2858
2859 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2860
2861 struct cmd_set_txpkts_result {
2862         cmdline_fixed_string_t cmd_keyword;
2863         cmdline_fixed_string_t txpkts;
2864         cmdline_fixed_string_t seg_lengths;
2865 };
2866
2867 static void
2868 cmd_set_txpkts_parsed(void *parsed_result,
2869                       __attribute__((unused)) struct cmdline *cl,
2870                       __attribute__((unused)) void *data)
2871 {
2872         struct cmd_set_txpkts_result *res;
2873         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2874         unsigned int nb_segs;
2875
2876         res = parsed_result;
2877         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2878                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2879         if (nb_segs > 0)
2880                 set_tx_pkt_segments(seg_lengths, nb_segs);
2881 }
2882
2883 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2884         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2885                                  cmd_keyword, "set");
2886 cmdline_parse_token_string_t cmd_set_txpkts_name =
2887         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2888                                  txpkts, "txpkts");
2889 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2890         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2891                                  seg_lengths, NULL);
2892
2893 cmdline_parse_inst_t cmd_set_txpkts = {
2894         .f = cmd_set_txpkts_parsed,
2895         .data = NULL,
2896         .help_str = "set txpkts <len0[,len1]*>",
2897         .tokens = {
2898                 (void *)&cmd_set_txpkts_keyword,
2899                 (void *)&cmd_set_txpkts_name,
2900                 (void *)&cmd_set_txpkts_lengths,
2901                 NULL,
2902         },
2903 };
2904
2905 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2906
2907 struct cmd_set_txsplit_result {
2908         cmdline_fixed_string_t cmd_keyword;
2909         cmdline_fixed_string_t txsplit;
2910         cmdline_fixed_string_t mode;
2911 };
2912
2913 static void
2914 cmd_set_txsplit_parsed(void *parsed_result,
2915                       __attribute__((unused)) struct cmdline *cl,
2916                       __attribute__((unused)) void *data)
2917 {
2918         struct cmd_set_txsplit_result *res;
2919
2920         res = parsed_result;
2921         set_tx_pkt_split(res->mode);
2922 }
2923
2924 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2925         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2926                                  cmd_keyword, "set");
2927 cmdline_parse_token_string_t cmd_set_txsplit_name =
2928         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2929                                  txsplit, "txsplit");
2930 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2931         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2932                                  mode, NULL);
2933
2934 cmdline_parse_inst_t cmd_set_txsplit = {
2935         .f = cmd_set_txsplit_parsed,
2936         .data = NULL,
2937         .help_str = "set txsplit on|off|rand",
2938         .tokens = {
2939                 (void *)&cmd_set_txsplit_keyword,
2940                 (void *)&cmd_set_txsplit_name,
2941                 (void *)&cmd_set_txsplit_mode,
2942                 NULL,
2943         },
2944 };
2945
2946 /* *** CONFIG TX QUEUE FLAGS *** */
2947
2948 struct cmd_config_txqflags_result {
2949         cmdline_fixed_string_t port;
2950         cmdline_fixed_string_t config;
2951         cmdline_fixed_string_t all;
2952         cmdline_fixed_string_t what;
2953         int32_t hexvalue;
2954 };
2955
2956 static void cmd_config_txqflags_parsed(void *parsed_result,
2957                                 __attribute__((unused)) struct cmdline *cl,
2958                                 __attribute__((unused)) void *data)
2959 {
2960         struct cmd_config_txqflags_result *res = parsed_result;
2961
2962         if (!all_ports_stopped()) {
2963                 printf("Please stop all ports first\n");
2964                 return;
2965         }
2966
2967         if (strcmp(res->what, "txqflags")) {
2968                 printf("Unknown parameter\n");
2969                 return;
2970         }
2971
2972         if (res->hexvalue >= 0) {
2973                 txq_flags = res->hexvalue;
2974         } else {
2975                 printf("txqflags must be >= 0\n");
2976                 return;
2977         }
2978
2979         init_port_config();
2980
2981         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2982 }
2983
2984 cmdline_parse_token_string_t cmd_config_txqflags_port =
2985         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2986                                  "port");
2987 cmdline_parse_token_string_t cmd_config_txqflags_config =
2988         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2989                                  "config");
2990 cmdline_parse_token_string_t cmd_config_txqflags_all =
2991         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2992                                  "all");
2993 cmdline_parse_token_string_t cmd_config_txqflags_what =
2994         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2995                                  "txqflags");
2996 cmdline_parse_token_num_t cmd_config_txqflags_value =
2997         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2998                                 hexvalue, INT32);
2999
3000 cmdline_parse_inst_t cmd_config_txqflags = {
3001         .f = cmd_config_txqflags_parsed,
3002         .data = NULL,
3003         .help_str = "port config all txqflags <value>",
3004         .tokens = {
3005                 (void *)&cmd_config_txqflags_port,
3006                 (void *)&cmd_config_txqflags_config,
3007                 (void *)&cmd_config_txqflags_all,
3008                 (void *)&cmd_config_txqflags_what,
3009                 (void *)&cmd_config_txqflags_value,
3010                 NULL,
3011         },
3012 };
3013
3014 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3015 struct cmd_rx_vlan_filter_all_result {
3016         cmdline_fixed_string_t rx_vlan;
3017         cmdline_fixed_string_t what;
3018         cmdline_fixed_string_t all;
3019         uint8_t port_id;
3020 };
3021
3022 static void
3023 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3024                               __attribute__((unused)) struct cmdline *cl,
3025                               __attribute__((unused)) void *data)
3026 {
3027         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3028
3029         if (!strcmp(res->what, "add"))
3030                 rx_vlan_all_filter_set(res->port_id, 1);
3031         else
3032                 rx_vlan_all_filter_set(res->port_id, 0);
3033 }
3034
3035 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3036         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3037                                  rx_vlan, "rx_vlan");
3038 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3039         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3040                                  what, "add#rm");
3041 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3042         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3043                                  all, "all");
3044 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3045         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3046                               port_id, UINT8);
3047
3048 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3049         .f = cmd_rx_vlan_filter_all_parsed,
3050         .data = NULL,
3051         .help_str = "rx_vlan add|rm all <port_id>: "
3052                 "Add/Remove all identifiers to/from the set of VLAN "
3053                 "identifiers filtered by a port",
3054         .tokens = {
3055                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3056                 (void *)&cmd_rx_vlan_filter_all_what,
3057                 (void *)&cmd_rx_vlan_filter_all_all,
3058                 (void *)&cmd_rx_vlan_filter_all_portid,
3059                 NULL,
3060         },
3061 };
3062
3063 /* *** VLAN OFFLOAD SET ON A PORT *** */
3064 struct cmd_vlan_offload_result {
3065         cmdline_fixed_string_t vlan;
3066         cmdline_fixed_string_t set;
3067         cmdline_fixed_string_t vlan_type;
3068         cmdline_fixed_string_t what;
3069         cmdline_fixed_string_t on;
3070         cmdline_fixed_string_t port_id;
3071 };
3072
3073 static void
3074 cmd_vlan_offload_parsed(void *parsed_result,
3075                           __attribute__((unused)) struct cmdline *cl,
3076                           __attribute__((unused)) void *data)
3077 {
3078         int on;
3079         struct cmd_vlan_offload_result *res = parsed_result;
3080         char *str;
3081         int i, len = 0;
3082         portid_t port_id = 0;
3083         unsigned int tmp;
3084
3085         str = res->port_id;
3086         len = strnlen(str, STR_TOKEN_SIZE);
3087         i = 0;
3088         /* Get port_id first */
3089         while(i < len){
3090                 if(str[i] == ',')
3091                         break;
3092
3093                 i++;
3094         }
3095         str[i]='\0';
3096         tmp = strtoul(str, NULL, 0);
3097         /* If port_id greater that what portid_t can represent, return */
3098         if(tmp >= RTE_MAX_ETHPORTS)
3099                 return;
3100         port_id = (portid_t)tmp;
3101
3102         if (!strcmp(res->on, "on"))
3103                 on = 1;
3104         else
3105                 on = 0;
3106
3107         if (!strcmp(res->what, "strip"))
3108                 rx_vlan_strip_set(port_id,  on);
3109         else if(!strcmp(res->what, "stripq")){
3110                 uint16_t queue_id = 0;
3111
3112                 /* No queue_id, return */
3113                 if(i + 1 >= len) {
3114                         printf("must specify (port,queue_id)\n");
3115                         return;
3116                 }
3117                 tmp = strtoul(str + i + 1, NULL, 0);
3118                 /* If queue_id greater that what 16-bits can represent, return */
3119                 if(tmp > 0xffff)
3120                         return;
3121
3122                 queue_id = (uint16_t)tmp;
3123                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3124         }
3125         else if (!strcmp(res->what, "filter"))
3126                 rx_vlan_filter_set(port_id, on);
3127         else
3128                 vlan_extend_set(port_id, on);
3129
3130         return;
3131 }
3132
3133 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3135                                  vlan, "vlan");
3136 cmdline_parse_token_string_t cmd_vlan_offload_set =
3137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3138                                  set, "set");
3139 cmdline_parse_token_string_t cmd_vlan_offload_what =
3140         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3141                                  what, "strip#filter#qinq#stripq");
3142 cmdline_parse_token_string_t cmd_vlan_offload_on =
3143         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3144                               on, "on#off");
3145 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3146         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3147                               port_id, NULL);
3148
3149 cmdline_parse_inst_t cmd_vlan_offload = {
3150         .f = cmd_vlan_offload_parsed,
3151         .data = NULL,
3152         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3153                 "<port_id[,queue_id]>: "
3154                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3155         .tokens = {
3156                 (void *)&cmd_vlan_offload_vlan,
3157                 (void *)&cmd_vlan_offload_set,
3158                 (void *)&cmd_vlan_offload_what,
3159                 (void *)&cmd_vlan_offload_on,
3160                 (void *)&cmd_vlan_offload_portid,
3161                 NULL,
3162         },
3163 };
3164
3165 /* *** VLAN TPID SET ON A PORT *** */
3166 struct cmd_vlan_tpid_result {
3167         cmdline_fixed_string_t vlan;
3168         cmdline_fixed_string_t set;
3169         cmdline_fixed_string_t vlan_type;
3170         cmdline_fixed_string_t what;
3171         uint16_t tp_id;
3172         uint8_t port_id;
3173 };
3174
3175 static void
3176 cmd_vlan_tpid_parsed(void *parsed_result,
3177                           __attribute__((unused)) struct cmdline *cl,
3178                           __attribute__((unused)) void *data)
3179 {
3180         struct cmd_vlan_tpid_result *res = parsed_result;
3181         enum rte_vlan_type vlan_type;
3182
3183         if (!strcmp(res->vlan_type, "inner"))
3184                 vlan_type = ETH_VLAN_TYPE_INNER;
3185         else if (!strcmp(res->vlan_type, "outer"))
3186                 vlan_type = ETH_VLAN_TYPE_OUTER;
3187         else {
3188                 printf("Unknown vlan type\n");
3189                 return;
3190         }
3191         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3192 }
3193
3194 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3196                                  vlan, "vlan");
3197 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3198         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3199                                  set, "set");
3200 cmdline_parse_token_string_t cmd_vlan_type =
3201         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3202                                  vlan_type, "inner#outer");
3203 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3204         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3205                                  what, "tpid");
3206 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3207         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3208                               tp_id, UINT16);
3209 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3210         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3211                               port_id, UINT8);
3212
3213 cmdline_parse_inst_t cmd_vlan_tpid = {
3214         .f = cmd_vlan_tpid_parsed,
3215         .data = NULL,
3216         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3217                 "Set the VLAN Ether type",
3218         .tokens = {
3219                 (void *)&cmd_vlan_tpid_vlan,
3220                 (void *)&cmd_vlan_tpid_set,
3221                 (void *)&cmd_vlan_type,
3222                 (void *)&cmd_vlan_tpid_what,
3223                 (void *)&cmd_vlan_tpid_tpid,
3224                 (void *)&cmd_vlan_tpid_portid,
3225                 NULL,
3226         },
3227 };
3228
3229 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3230 struct cmd_rx_vlan_filter_result {
3231         cmdline_fixed_string_t rx_vlan;
3232         cmdline_fixed_string_t what;
3233         uint16_t vlan_id;
3234         uint8_t port_id;
3235 };
3236
3237 static void
3238 cmd_rx_vlan_filter_parsed(void *parsed_result,
3239                           __attribute__((unused)) struct cmdline *cl,
3240                           __attribute__((unused)) void *data)
3241 {
3242         struct cmd_rx_vlan_filter_result *res = parsed_result;
3243
3244         if (!strcmp(res->what, "add"))
3245                 rx_vft_set(res->port_id, res->vlan_id, 1);
3246         else
3247                 rx_vft_set(res->port_id, res->vlan_id, 0);
3248 }
3249
3250 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3251         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3252                                  rx_vlan, "rx_vlan");
3253 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3254         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3255                                  what, "add#rm");
3256 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3257         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3258                               vlan_id, UINT16);
3259 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3260         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3261                               port_id, UINT8);
3262
3263 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3264         .f = cmd_rx_vlan_filter_parsed,
3265         .data = NULL,
3266         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3267                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3268                 "identifiers filtered by a port",
3269         .tokens = {
3270                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3271                 (void *)&cmd_rx_vlan_filter_what,
3272                 (void *)&cmd_rx_vlan_filter_vlanid,
3273                 (void *)&cmd_rx_vlan_filter_portid,
3274                 NULL,
3275         },
3276 };
3277
3278 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3279 struct cmd_tx_vlan_set_result {
3280         cmdline_fixed_string_t tx_vlan;
3281         cmdline_fixed_string_t set;
3282         uint8_t port_id;
3283         uint16_t vlan_id;
3284 };
3285
3286 static void
3287 cmd_tx_vlan_set_parsed(void *parsed_result,
3288                        __attribute__((unused)) struct cmdline *cl,
3289                        __attribute__((unused)) void *data)
3290 {
3291         struct cmd_tx_vlan_set_result *res = parsed_result;
3292
3293         tx_vlan_set(res->port_id, res->vlan_id);
3294 }
3295
3296 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3297         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3298                                  tx_vlan, "tx_vlan");
3299 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3300         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3301                                  set, "set");
3302 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3303         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3304                               port_id, UINT8);
3305 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3306         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3307                               vlan_id, UINT16);
3308
3309 cmdline_parse_inst_t cmd_tx_vlan_set = {
3310         .f = cmd_tx_vlan_set_parsed,
3311         .data = NULL,
3312         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3313                 "Enable hardware insertion of a single VLAN header "
3314                 "with a given TAG Identifier in packets sent on a port",
3315         .tokens = {
3316                 (void *)&cmd_tx_vlan_set_tx_vlan,
3317                 (void *)&cmd_tx_vlan_set_set,
3318                 (void *)&cmd_tx_vlan_set_portid,
3319                 (void *)&cmd_tx_vlan_set_vlanid,
3320                 NULL,
3321         },
3322 };
3323
3324 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3325 struct cmd_tx_vlan_set_qinq_result {
3326         cmdline_fixed_string_t tx_vlan;
3327         cmdline_fixed_string_t set;
3328         uint8_t port_id;
3329         uint16_t vlan_id;
3330         uint16_t vlan_id_outer;
3331 };
3332
3333 static void
3334 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3335                             __attribute__((unused)) struct cmdline *cl,
3336                             __attribute__((unused)) void *data)
3337 {
3338         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3339
3340         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3341 }
3342
3343 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3344         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3345                 tx_vlan, "tx_vlan");
3346 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3347         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3348                 set, "set");
3349 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3350         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3351                 port_id, UINT8);
3352 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3353         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3354                 vlan_id, UINT16);
3355 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3356         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3357                 vlan_id_outer, UINT16);
3358
3359 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3360         .f = cmd_tx_vlan_set_qinq_parsed,
3361         .data = NULL,
3362         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3363                 "Enable hardware insertion of double VLAN header "
3364                 "with given TAG Identifiers in packets sent on a port",
3365         .tokens = {
3366                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3367                 (void *)&cmd_tx_vlan_set_qinq_set,
3368                 (void *)&cmd_tx_vlan_set_qinq_portid,
3369                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3370                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3371                 NULL,
3372         },
3373 };
3374
3375 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3376 struct cmd_tx_vlan_set_pvid_result {
3377         cmdline_fixed_string_t tx_vlan;
3378         cmdline_fixed_string_t set;
3379         cmdline_fixed_string_t pvid;
3380         uint8_t port_id;
3381         uint16_t vlan_id;
3382         cmdline_fixed_string_t mode;
3383 };
3384
3385 static void
3386 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3387                             __attribute__((unused)) struct cmdline *cl,
3388                             __attribute__((unused)) void *data)
3389 {
3390         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3391
3392         if (strcmp(res->mode, "on") == 0)
3393                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3394         else
3395                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3396 }
3397
3398 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3399         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3400                                  tx_vlan, "tx_vlan");
3401 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3402         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3403                                  set, "set");
3404 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3405         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3406                                  pvid, "pvid");
3407 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3408         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3409                              port_id, UINT8);
3410 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3411         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3412                               vlan_id, UINT16);
3413 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3414         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3415                                  mode, "on#off");
3416
3417 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3418         .f = cmd_tx_vlan_set_pvid_parsed,
3419         .data = NULL,
3420         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3421         .tokens = {
3422                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3423                 (void *)&cmd_tx_vlan_set_pvid_set,
3424                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3425                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3426                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3427                 (void *)&cmd_tx_vlan_set_pvid_mode,
3428                 NULL,
3429         },
3430 };
3431
3432 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3433 struct cmd_tx_vlan_reset_result {
3434         cmdline_fixed_string_t tx_vlan;
3435         cmdline_fixed_string_t reset;
3436         uint8_t port_id;
3437 };
3438
3439 static void
3440 cmd_tx_vlan_reset_parsed(void *parsed_result,
3441                          __attribute__((unused)) struct cmdline *cl,
3442                          __attribute__((unused)) void *data)
3443 {
3444         struct cmd_tx_vlan_reset_result *res = parsed_result;
3445
3446         tx_vlan_reset(res->port_id);
3447 }
3448
3449 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3450         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3451                                  tx_vlan, "tx_vlan");
3452 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3453         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3454                                  reset, "reset");
3455 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3456         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3457                               port_id, UINT8);
3458
3459 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3460         .f = cmd_tx_vlan_reset_parsed,
3461         .data = NULL,
3462         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3463                 "VLAN header in packets sent on a port",
3464         .tokens = {
3465                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3466                 (void *)&cmd_tx_vlan_reset_reset,
3467                 (void *)&cmd_tx_vlan_reset_portid,
3468                 NULL,
3469         },
3470 };
3471
3472
3473 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3474 struct cmd_csum_result {
3475         cmdline_fixed_string_t csum;
3476         cmdline_fixed_string_t mode;
3477         cmdline_fixed_string_t proto;
3478         cmdline_fixed_string_t hwsw;
3479         uint8_t port_id;
3480 };
3481
3482 static void
3483 csum_show(int port_id)
3484 {
3485         struct rte_eth_dev_info dev_info;
3486         uint16_t ol_flags;
3487
3488         ol_flags = ports[port_id].tx_ol_flags;
3489         printf("Parse tunnel is %s\n",
3490                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3491         printf("IP checksum offload is %s\n",
3492                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3493         printf("UDP checksum offload is %s\n",
3494                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3495         printf("TCP checksum offload is %s\n",
3496                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3497         printf("SCTP checksum offload is %s\n",
3498                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3499         printf("Outer-Ip checksum offload is %s\n",
3500                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3501
3502         /* display warnings if configuration is not supported by the NIC */
3503         rte_eth_dev_info_get(port_id, &dev_info);
3504         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3505                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3506                 printf("Warning: hardware IP checksum enabled but not "
3507                         "supported by port %d\n", port_id);
3508         }
3509         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3510                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3511                 printf("Warning: hardware UDP checksum enabled but not "
3512                         "supported by port %d\n", port_id);
3513         }
3514         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3515                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3516                 printf("Warning: hardware TCP checksum enabled but not "
3517                         "supported by port %d\n", port_id);
3518         }
3519         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3520                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3521                 printf("Warning: hardware SCTP checksum enabled but not "
3522                         "supported by port %d\n", port_id);
3523         }
3524         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3525                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3526                 printf("Warning: hardware outer IP checksum enabled but not "
3527                         "supported by port %d\n", port_id);
3528         }
3529 }
3530
3531 static void
3532 cmd_csum_parsed(void *parsed_result,
3533                        __attribute__((unused)) struct cmdline *cl,
3534                        __attribute__((unused)) void *data)
3535 {
3536         struct cmd_csum_result *res = parsed_result;
3537         int hw = 0;
3538         uint16_t mask = 0;
3539
3540         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3541                 printf("invalid port %d\n", res->port_id);
3542                 return;
3543         }
3544
3545         if (!strcmp(res->mode, "set")) {
3546
3547                 if (!strcmp(res->hwsw, "hw"))
3548                         hw = 1;
3549
3550                 if (!strcmp(res->proto, "ip")) {
3551                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3552                 } else if (!strcmp(res->proto, "udp")) {
3553                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3554                 } else if (!strcmp(res->proto, "tcp")) {
3555                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3556                 } else if (!strcmp(res->proto, "sctp")) {
3557                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3558                 } else if (!strcmp(res->proto, "outer-ip")) {
3559                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3560                 }
3561
3562                 if (hw)
3563                         ports[res->port_id].tx_ol_flags |= mask;
3564                 else
3565                         ports[res->port_id].tx_ol_flags &= (~mask);
3566         }
3567         csum_show(res->port_id);
3568 }
3569
3570 cmdline_parse_token_string_t cmd_csum_csum =
3571         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3572                                 csum, "csum");
3573 cmdline_parse_token_string_t cmd_csum_mode =
3574         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3575                                 mode, "set");
3576 cmdline_parse_token_string_t cmd_csum_proto =
3577         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3578                                 proto, "ip#tcp#udp#sctp#outer-ip");
3579 cmdline_parse_token_string_t cmd_csum_hwsw =
3580         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3581                                 hwsw, "hw#sw");
3582 cmdline_parse_token_num_t cmd_csum_portid =
3583         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3584                                 port_id, UINT8);
3585
3586 cmdline_parse_inst_t cmd_csum_set = {
3587         .f = cmd_csum_parsed,
3588         .data = NULL,
3589         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3590                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3591                 "using csum forward engine",
3592         .tokens = {
3593                 (void *)&cmd_csum_csum,
3594                 (void *)&cmd_csum_mode,
3595                 (void *)&cmd_csum_proto,
3596                 (void *)&cmd_csum_hwsw,
3597                 (void *)&cmd_csum_portid,
3598                 NULL,
3599         },
3600 };
3601
3602 cmdline_parse_token_string_t cmd_csum_mode_show =
3603         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3604                                 mode, "show");
3605
3606 cmdline_parse_inst_t cmd_csum_show = {
3607         .f = cmd_csum_parsed,
3608         .data = NULL,
3609         .help_str = "csum show <port_id>: Show checksum offload configuration",
3610         .tokens = {
3611                 (void *)&cmd_csum_csum,
3612                 (void *)&cmd_csum_mode_show,
3613                 (void *)&cmd_csum_portid,
3614                 NULL,
3615         },
3616 };
3617
3618 /* Enable/disable tunnel parsing */
3619 struct cmd_csum_tunnel_result {
3620         cmdline_fixed_string_t csum;
3621         cmdline_fixed_string_t parse;
3622         cmdline_fixed_string_t onoff;
3623         uint8_t port_id;
3624 };
3625
3626 static void
3627 cmd_csum_tunnel_parsed(void *parsed_result,
3628                        __attribute__((unused)) struct cmdline *cl,
3629                        __attribute__((unused)) void *data)
3630 {
3631         struct cmd_csum_tunnel_result *res = parsed_result;
3632
3633         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3634                 return;
3635
3636         if (!strcmp(res->onoff, "on"))
3637                 ports[res->port_id].tx_ol_flags |=
3638                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3639         else
3640                 ports[res->port_id].tx_ol_flags &=
3641                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3642
3643         csum_show(res->port_id);
3644 }
3645
3646 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3647         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3648                                 csum, "csum");
3649 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3650         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3651                                 parse, "parse_tunnel");
3652 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3653         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3654                                 onoff, "on#off");
3655 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3656         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3657                                 port_id, UINT8);
3658
3659 cmdline_parse_inst_t cmd_csum_tunnel = {
3660         .f = cmd_csum_tunnel_parsed,
3661         .data = NULL,
3662         .help_str = "csum parse_tunnel on|off <port_id>: "
3663                 "Enable/Disable parsing of tunnels for csum engine",
3664         .tokens = {
3665                 (void *)&cmd_csum_tunnel_csum,
3666                 (void *)&cmd_csum_tunnel_parse,
3667                 (void *)&cmd_csum_tunnel_onoff,
3668                 (void *)&cmd_csum_tunnel_portid,
3669                 NULL,
3670         },
3671 };
3672
3673 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3674 struct cmd_tso_set_result {
3675         cmdline_fixed_string_t tso;
3676         cmdline_fixed_string_t mode;
3677         uint16_t tso_segsz;
3678         uint8_t port_id;
3679 };
3680
3681 static void
3682 cmd_tso_set_parsed(void *parsed_result,
3683                        __attribute__((unused)) struct cmdline *cl,
3684                        __attribute__((unused)) void *data)
3685 {
3686         struct cmd_tso_set_result *res = parsed_result;
3687         struct rte_eth_dev_info dev_info;
3688
3689         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3690                 return;
3691
3692         if (!strcmp(res->mode, "set"))
3693                 ports[res->port_id].tso_segsz = res->tso_segsz;
3694
3695         if (ports[res->port_id].tso_segsz == 0)
3696                 printf("TSO for non-tunneled packets is disabled\n");
3697         else
3698                 printf("TSO segment size for non-tunneled packets is %d\n",
3699                         ports[res->port_id].tso_segsz);
3700
3701         /* display warnings if configuration is not supported by the NIC */
3702         rte_eth_dev_info_get(res->port_id, &dev_info);
3703         if ((ports[res->port_id].tso_segsz != 0) &&
3704                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3705                 printf("Warning: TSO enabled but not "
3706                         "supported by port %d\n", res->port_id);
3707         }
3708 }
3709
3710 cmdline_parse_token_string_t cmd_tso_set_tso =
3711         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3712                                 tso, "tso");
3713 cmdline_parse_token_string_t cmd_tso_set_mode =
3714         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3715                                 mode, "set");
3716 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3717         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3718                                 tso_segsz, UINT16);
3719 cmdline_parse_token_num_t cmd_tso_set_portid =
3720         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3721                                 port_id, UINT8);
3722
3723 cmdline_parse_inst_t cmd_tso_set = {
3724         .f = cmd_tso_set_parsed,
3725         .data = NULL,
3726         .help_str = "tso set <tso_segsz> <port_id>: "
3727                 "Set TSO segment size of non-tunneled packets for csum engine "
3728                 "(0 to disable)",
3729         .tokens = {
3730                 (void *)&cmd_tso_set_tso,
3731                 (void *)&cmd_tso_set_mode,
3732                 (void *)&cmd_tso_set_tso_segsz,
3733                 (void *)&cmd_tso_set_portid,
3734                 NULL,
3735         },
3736 };
3737
3738 cmdline_parse_token_string_t cmd_tso_show_mode =
3739         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3740                                 mode, "show");
3741
3742
3743 cmdline_parse_inst_t cmd_tso_show = {
3744         .f = cmd_tso_set_parsed,
3745         .data = NULL,
3746         .help_str = "tso show <port_id>: "
3747                 "Show TSO segment size of non-tunneled packets for csum engine",
3748         .tokens = {
3749                 (void *)&cmd_tso_set_tso,
3750                 (void *)&cmd_tso_show_mode,
3751                 (void *)&cmd_tso_set_portid,
3752                 NULL,
3753         },
3754 };
3755
3756 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3757 struct cmd_tunnel_tso_set_result {
3758         cmdline_fixed_string_t tso;
3759         cmdline_fixed_string_t mode;
3760         uint16_t tso_segsz;
3761         uint8_t port_id;
3762 };
3763
3764 static void
3765 check_tunnel_tso_nic_support(uint8_t port_id)
3766 {
3767         struct rte_eth_dev_info dev_info;
3768
3769         rte_eth_dev_info_get(port_id, &dev_info);
3770         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3771                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3772                        "supported by port %d\n", port_id);
3773         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3774                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3775                         "supported by port %d\n", port_id);
3776         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3777                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3778                        "supported by port %d\n", port_id);
3779         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3780                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3781                        "supported by port %d\n", port_id);
3782 }
3783
3784 static void
3785 cmd_tunnel_tso_set_parsed(void *parsed_result,
3786                           __attribute__((unused)) struct cmdline *cl,
3787                           __attribute__((unused)) void *data)
3788 {
3789         struct cmd_tunnel_tso_set_result *res = parsed_result;
3790
3791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3792                 return;
3793
3794         if (!strcmp(res->mode, "set"))
3795                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3796
3797         if (ports[res->port_id].tunnel_tso_segsz == 0)
3798                 printf("TSO for tunneled packets is disabled\n");
3799         else {
3800                 printf("TSO segment size for tunneled packets is %d\n",
3801                         ports[res->port_id].tunnel_tso_segsz);
3802
3803                 /* Below conditions are needed to make it work:
3804                  * (1) tunnel TSO is supported by the NIC;
3805                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3806                  * are recognized;
3807                  * (3) for tunneled pkts with outer L3 of IPv4,
3808                  * "csum set outer-ip" must be set to hw, because after tso,
3809                  * total_len of outer IP header is changed, and the checksum
3810                  * of outer IP header calculated by sw should be wrong; that
3811                  * is not necessary for IPv6 tunneled pkts because there's no
3812                  * checksum in IP header anymore.
3813                  */
3814                 check_tunnel_tso_nic_support(res->port_id);
3815
3816                 if (!(ports[res->port_id].tx_ol_flags &
3817                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3818                         printf("Warning: csum parse_tunnel must be set "
3819                                 "so that tunneled packets are recognized\n");
3820                 if (!(ports[res->port_id].tx_ol_flags &
3821                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3822                         printf("Warning: csum set outer-ip must be set to hw "
3823                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3824         }
3825 }
3826
3827 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3828         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3829                                 tso, "tunnel_tso");
3830 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3831         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3832                                 mode, "set");
3833 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3834         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3835                                 tso_segsz, UINT16);
3836 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3837         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3838                                 port_id, UINT8);
3839
3840 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3841         .f = cmd_tunnel_tso_set_parsed,
3842         .data = NULL,
3843         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3844                 "Set TSO segment size of tunneled packets for csum engine "
3845                 "(0 to disable)",
3846         .tokens = {
3847                 (void *)&cmd_tunnel_tso_set_tso,
3848                 (void *)&cmd_tunnel_tso_set_mode,
3849                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3850                 (void *)&cmd_tunnel_tso_set_portid,
3851                 NULL,
3852         },
3853 };
3854
3855 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3856         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3857                                 mode, "show");
3858
3859
3860 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3861         .f = cmd_tunnel_tso_set_parsed,
3862         .data = NULL,
3863         .help_str = "tunnel_tso show <port_id> "
3864                 "Show TSO segment size of tunneled packets for csum engine",
3865         .tokens = {
3866                 (void *)&cmd_tunnel_tso_set_tso,
3867                 (void *)&cmd_tunnel_tso_show_mode,
3868                 (void *)&cmd_tunnel_tso_set_portid,
3869                 NULL,
3870         },
3871 };
3872
3873 /* *** SET GRO FOR A PORT *** */
3874 struct cmd_gro_enable_result {
3875         cmdline_fixed_string_t cmd_set;
3876         cmdline_fixed_string_t cmd_port;
3877         cmdline_fixed_string_t cmd_keyword;
3878         cmdline_fixed_string_t cmd_onoff;
3879         portid_t cmd_pid;
3880 };
3881
3882 static void
3883 cmd_gro_enable_parsed(void *parsed_result,
3884                 __attribute__((unused)) struct cmdline *cl,
3885                 __attribute__((unused)) void *data)
3886 {
3887         struct cmd_gro_enable_result *res;
3888
3889         res = parsed_result;
3890         if (!strcmp(res->cmd_keyword, "gro"))
3891                 setup_gro(res->cmd_onoff, res->cmd_pid);
3892 }
3893
3894 cmdline_parse_token_string_t cmd_gro_enable_set =
3895         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3896                         cmd_set, "set");
3897 cmdline_parse_token_string_t cmd_gro_enable_port =
3898         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3899                         cmd_keyword, "port");
3900 cmdline_parse_token_num_t cmd_gro_enable_pid =
3901         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3902                         cmd_pid, UINT16);
3903 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3904         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3905                         cmd_keyword, "gro");
3906 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3907         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3908                         cmd_onoff, "on#off");
3909
3910 cmdline_parse_inst_t cmd_gro_enable = {
3911         .f = cmd_gro_enable_parsed,
3912         .data = NULL,
3913         .help_str = "set port <port_id> gro on|off",
3914         .tokens = {
3915                 (void *)&cmd_gro_enable_set,
3916                 (void *)&cmd_gro_enable_port,
3917                 (void *)&cmd_gro_enable_pid,
3918                 (void *)&cmd_gro_enable_keyword,
3919                 (void *)&cmd_gro_enable_onoff,
3920                 NULL,
3921         },
3922 };
3923
3924 /* *** DISPLAY GRO CONFIGURATION *** */
3925 struct cmd_gro_show_result {
3926         cmdline_fixed_string_t cmd_show;
3927         cmdline_fixed_string_t cmd_port;
3928         cmdline_fixed_string_t cmd_keyword;
3929         portid_t cmd_pid;
3930 };
3931
3932 static void
3933 cmd_gro_show_parsed(void *parsed_result,
3934                 __attribute__((unused)) struct cmdline *cl,
3935                 __attribute__((unused)) void *data)
3936 {
3937         struct cmd_gro_show_result *res;
3938
3939         res = parsed_result;
3940         if (!strcmp(res->cmd_keyword, "gro"))
3941                 show_gro(res->cmd_pid);
3942 }
3943
3944 cmdline_parse_token_string_t cmd_gro_show_show =
3945         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3946                         cmd_show, "show");
3947 cmdline_parse_token_string_t cmd_gro_show_port =
3948         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3949                         cmd_port, "port");
3950 cmdline_parse_token_num_t cmd_gro_show_pid =
3951         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3952                         cmd_pid, UINT16);
3953 cmdline_parse_token_string_t cmd_gro_show_keyword =
3954         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3955                         cmd_keyword, "gro");
3956
3957 cmdline_parse_inst_t cmd_gro_show = {
3958         .f = cmd_gro_show_parsed,
3959         .data = NULL,
3960         .help_str = "show port <port_id> gro",
3961         .tokens = {
3962                 (void *)&cmd_gro_show_show,
3963                 (void *)&cmd_gro_show_port,
3964                 (void *)&cmd_gro_show_pid,
3965                 (void *)&cmd_gro_show_keyword,
3966                 NULL,
3967         },
3968 };
3969
3970 /* *** SET FLUSH CYCLES FOR GRO *** */
3971 struct cmd_gro_flush_result {
3972         cmdline_fixed_string_t cmd_set;
3973         cmdline_fixed_string_t cmd_keyword;
3974         cmdline_fixed_string_t cmd_flush;
3975         uint8_t cmd_cycles;
3976 };
3977
3978 static void
3979 cmd_gro_flush_parsed(void *parsed_result,
3980                 __attribute__((unused)) struct cmdline *cl,
3981                 __attribute__((unused)) void *data)
3982 {
3983         struct cmd_gro_flush_result *res;
3984
3985         res = parsed_result;
3986         if ((!strcmp(res->cmd_keyword, "gro")) &&
3987                         (!strcmp(res->cmd_flush, "flush")))
3988                 setup_gro_flush_cycles(res->cmd_cycles);
3989 }
3990
3991 cmdline_parse_token_string_t cmd_gro_flush_set =
3992         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
3993                         cmd_set, "set");
3994 cmdline_parse_token_string_t cmd_gro_flush_keyword =
3995         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
3996                         cmd_keyword, "gro");
3997 cmdline_parse_token_string_t cmd_gro_flush_flush =
3998         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
3999                         cmd_flush, "flush");
4000 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4001         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4002                         cmd_cycles, UINT8);
4003
4004 cmdline_parse_inst_t cmd_gro_flush = {
4005         .f = cmd_gro_flush_parsed,
4006         .data = NULL,
4007         .help_str = "set gro flush <cycles>",
4008         .tokens = {
4009                 (void *)&cmd_gro_flush_set,
4010                 (void *)&cmd_gro_flush_keyword,
4011                 (void *)&cmd_gro_flush_flush,
4012                 (void *)&cmd_gro_flush_cycles,
4013                 NULL,
4014         },
4015 };
4016
4017 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4018 struct cmd_set_flush_rx {
4019         cmdline_fixed_string_t set;
4020         cmdline_fixed_string_t flush_rx;
4021         cmdline_fixed_string_t mode;
4022 };
4023
4024 static void
4025 cmd_set_flush_rx_parsed(void *parsed_result,
4026                 __attribute__((unused)) struct cmdline *cl,
4027                 __attribute__((unused)) void *data)
4028 {
4029         struct cmd_set_flush_rx *res = parsed_result;
4030         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4031 }
4032
4033 cmdline_parse_token_string_t cmd_setflushrx_set =
4034         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4035                         set, "set");
4036 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4037         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4038                         flush_rx, "flush_rx");
4039 cmdline_parse_token_string_t cmd_setflushrx_mode =
4040         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4041                         mode, "on#off");
4042
4043
4044 cmdline_parse_inst_t cmd_set_flush_rx = {
4045         .f = cmd_set_flush_rx_parsed,
4046         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4047         .data = NULL,
4048         .tokens = {
4049                 (void *)&cmd_setflushrx_set,
4050                 (void *)&cmd_setflushrx_flush_rx,
4051                 (void *)&cmd_setflushrx_mode,
4052                 NULL,
4053         },
4054 };
4055
4056 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4057 struct cmd_set_link_check {
4058         cmdline_fixed_string_t set;
4059         cmdline_fixed_string_t link_check;
4060         cmdline_fixed_string_t mode;
4061 };
4062
4063 static void
4064 cmd_set_link_check_parsed(void *parsed_result,
4065                 __attribute__((unused)) struct cmdline *cl,
4066                 __attribute__((unused)) void *data)
4067 {
4068         struct cmd_set_link_check *res = parsed_result;
4069         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4070 }
4071
4072 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4073         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4074                         set, "set");
4075 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4076         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4077                         link_check, "link_check");
4078 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4079         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4080                         mode, "on#off");
4081
4082
4083 cmdline_parse_inst_t cmd_set_link_check = {
4084         .f = cmd_set_link_check_parsed,
4085         .help_str = "set link_check on|off: Enable/Disable link status check "
4086                     "when starting/stopping a port",
4087         .data = NULL,
4088         .tokens = {
4089                 (void *)&cmd_setlinkcheck_set,
4090                 (void *)&cmd_setlinkcheck_link_check,
4091                 (void *)&cmd_setlinkcheck_mode,
4092                 NULL,
4093         },
4094 };
4095
4096 /* *** SET NIC BYPASS MODE *** */
4097 struct cmd_set_bypass_mode_result {
4098         cmdline_fixed_string_t set;
4099         cmdline_fixed_string_t bypass;
4100         cmdline_fixed_string_t mode;
4101         cmdline_fixed_string_t value;
4102         uint8_t port_id;
4103 };
4104
4105 static void
4106 cmd_set_bypass_mode_parsed(void *parsed_result,
4107                 __attribute__((unused)) struct cmdline *cl,
4108                 __attribute__((unused)) void *data)
4109 {
4110         struct cmd_set_bypass_mode_result *res = parsed_result;
4111         portid_t port_id = res->port_id;
4112         int32_t rc = -EINVAL;
4113
4114 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4115         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4116
4117         if (!strcmp(res->value, "bypass"))
4118                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4119         else if (!strcmp(res->value, "isolate"))
4120                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4121         else
4122                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4123
4124         /* Set the bypass mode for the relevant port. */
4125         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4126 #endif
4127         if (rc != 0)
4128                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4129 }
4130
4131 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4132         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4133                         set, "set");
4134 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4135         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4136                         bypass, "bypass");
4137 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4138         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4139                         mode, "mode");
4140 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4141         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4142                         value, "normal#bypass#isolate");
4143 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4144         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4145                                 port_id, UINT8);
4146
4147 cmdline_parse_inst_t cmd_set_bypass_mode = {
4148         .f = cmd_set_bypass_mode_parsed,
4149         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4150                     "Set the NIC bypass mode for port_id",
4151         .data = NULL,
4152         .tokens = {
4153                 (void *)&cmd_setbypass_mode_set,
4154                 (void *)&cmd_setbypass_mode_bypass,
4155                 (void *)&cmd_setbypass_mode_mode,
4156                 (void *)&cmd_setbypass_mode_value,
4157                 (void *)&cmd_setbypass_mode_port,
4158                 NULL,
4159         },
4160 };
4161
4162 /* *** SET NIC BYPASS EVENT *** */
4163 struct cmd_set_bypass_event_result {
4164         cmdline_fixed_string_t set;
4165         cmdline_fixed_string_t bypass;
4166         cmdline_fixed_string_t event;
4167         cmdline_fixed_string_t event_value;
4168         cmdline_fixed_string_t mode;
4169         cmdline_fixed_string_t mode_value;
4170         uint8_t port_id;
4171 };
4172
4173 static void
4174 cmd_set_bypass_event_parsed(void *parsed_result,
4175                 __attribute__((unused)) struct cmdline *cl,
4176                 __attribute__((unused)) void *data)
4177 {
4178         int32_t rc = -EINVAL;
4179         struct cmd_set_bypass_event_result *res = parsed_result;
4180         portid_t port_id = res->port_id;
4181
4182 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4183         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4184         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4185
4186         if (!strcmp(res->event_value, "timeout"))
4187                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4188         else if (!strcmp(res->event_value, "os_on"))
4189                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4190         else if (!strcmp(res->event_value, "os_off"))
4191                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4192         else if (!strcmp(res->event_value, "power_on"))
4193                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4194         else if (!strcmp(res->event_value, "power_off"))
4195                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4196         else
4197                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4198
4199         if (!strcmp(res->mode_value, "bypass"))
4200                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4201         else if (!strcmp(res->mode_value, "isolate"))
4202                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4203         else
4204                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4205
4206         /* Set the watchdog timeout. */
4207         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4208
4209                 rc = -EINVAL;
4210                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4211                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4212                                                            bypass_timeout);
4213                 }
4214                 if (rc != 0) {
4215                         printf("Failed to set timeout value %u "
4216                         "for port %d, errto code: %d.\n",
4217                         bypass_timeout, port_id, rc);
4218                 }
4219         }
4220
4221         /* Set the bypass event to transition to bypass mode. */
4222         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4223                                               bypass_mode);
4224 #endif
4225
4226         if (rc != 0)
4227                 printf("\t Failed to set bypass event for port = %d.\n",
4228                        port_id);
4229 }
4230
4231 cmdline_parse_token_string_t cmd_setbypass_event_set =
4232         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4233                         set, "set");
4234 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4235         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4236                         bypass, "bypass");
4237 cmdline_parse_token_string_t cmd_setbypass_event_event =
4238         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4239                         event, "event");
4240 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4241         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4242                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4243 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4244         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4245                         mode, "mode");
4246 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4247         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4248                         mode_value, "normal#bypass#isolate");
4249 cmdline_parse_token_num_t cmd_setbypass_event_port =
4250         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4251                                 port_id, UINT8);
4252
4253 cmdline_parse_inst_t cmd_set_bypass_event = {
4254         .f = cmd_set_bypass_event_parsed,
4255         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4256                 "power_off mode normal|bypass|isolate <port_id>: "
4257                 "Set the NIC bypass event mode for port_id",
4258         .data = NULL,
4259         .tokens = {
4260                 (void *)&cmd_setbypass_event_set,
4261                 (void *)&cmd_setbypass_event_bypass,
4262                 (void *)&cmd_setbypass_event_event,
4263                 (void *)&cmd_setbypass_event_event_value,
4264                 (void *)&cmd_setbypass_event_mode,
4265                 (void *)&cmd_setbypass_event_mode_value,
4266                 (void *)&cmd_setbypass_event_port,
4267                 NULL,
4268         },
4269 };
4270
4271
4272 /* *** SET NIC BYPASS TIMEOUT *** */
4273 struct cmd_set_bypass_timeout_result {
4274         cmdline_fixed_string_t set;
4275         cmdline_fixed_string_t bypass;
4276         cmdline_fixed_string_t timeout;
4277         cmdline_fixed_string_t value;
4278 };
4279
4280 static void
4281 cmd_set_bypass_timeout_parsed(void *parsed_result,
4282                 __attribute__((unused)) struct cmdline *cl,
4283                 __attribute__((unused)) void *data)
4284 {
4285         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4286
4287 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4288         if (!strcmp(res->value, "1.5"))
4289                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4290         else if (!strcmp(res->value, "2"))
4291                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4292         else if (!strcmp(res->value, "3"))
4293                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4294         else if (!strcmp(res->value, "4"))
4295                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4296         else if (!strcmp(res->value, "8"))
4297                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4298         else if (!strcmp(res->value, "16"))
4299                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4300         else if (!strcmp(res->value, "32"))
4301                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4302         else
4303                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4304 #endif
4305 }
4306
4307 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4308         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4309                         set, "set");
4310 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4311         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4312                         bypass, "bypass");
4313 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4314         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4315                         timeout, "timeout");
4316 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4317         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4318                         value, "0#1.5#2#3#4#8#16#32");
4319
4320 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4321         .f = cmd_set_bypass_timeout_parsed,
4322         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4323                 "Set the NIC bypass watchdog timeout in seconds",
4324         .data = NULL,
4325         .tokens = {
4326                 (void *)&cmd_setbypass_timeout_set,
4327                 (void *)&cmd_setbypass_timeout_bypass,
4328                 (void *)&cmd_setbypass_timeout_timeout,
4329                 (void *)&cmd_setbypass_timeout_value,
4330                 NULL,
4331         },
4332 };
4333
4334 /* *** SHOW NIC BYPASS MODE *** */
4335 struct cmd_show_bypass_config_result {
4336         cmdline_fixed_string_t show;
4337         cmdline_fixed_string_t bypass;
4338         cmdline_fixed_string_t config;
4339         uint8_t port_id;
4340 };
4341
4342 static void
4343 cmd_show_bypass_config_parsed(void *parsed_result,
4344                 __attribute__((unused)) struct cmdline *cl,
4345                 __attribute__((unused)) void *data)
4346 {
4347         struct cmd_show_bypass_config_result *res = parsed_result;
4348         portid_t port_id = res->port_id;
4349         int rc = -EINVAL;
4350 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4351         uint32_t event_mode;
4352         uint32_t bypass_mode;
4353         uint32_t timeout = bypass_timeout;
4354         int i;
4355
4356         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4357                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4358         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4359                 {"UNKNOWN", "normal", "bypass", "isolate"};
4360         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4361                 "NONE",
4362                 "OS/board on",
4363                 "power supply on",
4364                 "OS/board off",
4365                 "power supply off",
4366                 "timeout"};
4367         int num_events = (sizeof events) / (sizeof events[0]);
4368
4369         /* Display the bypass mode.*/
4370         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4371                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4372                 return;
4373         }
4374         else {
4375                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4376                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4377
4378                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4379         }
4380
4381         /* Display the bypass timeout.*/
4382         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4383                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4384
4385         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4386
4387         /* Display the bypass events and associated modes. */
4388         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4389
4390                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4391                         printf("\tFailed to get bypass mode for event = %s\n",
4392                                 events[i]);
4393                 } else {
4394                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4395                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4396
4397                         printf("\tbypass event: %-16s = %s\n", events[i],
4398                                 modes[event_mode]);
4399                 }
4400         }
4401 #endif
4402         if (rc != 0)
4403                 printf("\tFailed to get bypass configuration for port = %d\n",
4404                        port_id);
4405 }
4406
4407 cmdline_parse_token_string_t cmd_showbypass_config_show =
4408         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4409                         show, "show");
4410 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4411         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4412                         bypass, "bypass");
4413 cmdline_parse_token_string_t cmd_showbypass_config_config =
4414         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4415                         config, "config");
4416 cmdline_parse_token_num_t cmd_showbypass_config_port =
4417         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4418                                 port_id, UINT8);
4419
4420 cmdline_parse_inst_t cmd_show_bypass_config = {
4421         .f = cmd_show_bypass_config_parsed,
4422         .help_str = "show bypass config <port_id>: "
4423                     "Show the NIC bypass config for port_id",
4424         .data = NULL,
4425         .tokens = {
4426                 (void *)&cmd_showbypass_config_show,
4427                 (void *)&cmd_showbypass_config_bypass,
4428                 (void *)&cmd_showbypass_config_config,
4429                 (void *)&cmd_showbypass_config_port,
4430                 NULL,
4431         },
4432 };
4433
4434 #ifdef RTE_LIBRTE_PMD_BOND
4435 /* *** SET BONDING MODE *** */
4436 struct cmd_set_bonding_mode_result {
4437         cmdline_fixed_string_t set;
4438         cmdline_fixed_string_t bonding;
4439         cmdline_fixed_string_t mode;
4440         uint8_t value;
4441         uint8_t port_id;
4442 };
4443
4444 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4445                 __attribute__((unused))  struct cmdline *cl,
4446                 __attribute__((unused)) void *data)
4447 {
4448         struct cmd_set_bonding_mode_result *res = parsed_result;
4449         portid_t port_id = res->port_id;
4450
4451         /* Set the bonding mode for the relevant port. */
4452         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4453                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4454 }
4455
4456 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4457 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4458                 set, "set");
4459 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4460 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4461                 bonding, "bonding");
4462 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4463 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4464                 mode, "mode");
4465 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4466 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4467                 value, UINT8);
4468 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4469 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4470                 port_id, UINT8);
4471
4472 cmdline_parse_inst_t cmd_set_bonding_mode = {
4473                 .f = cmd_set_bonding_mode_parsed,
4474                 .help_str = "set bonding mode <mode_value> <port_id>: "
4475                         "Set the bonding mode for port_id",
4476                 .data = NULL,
4477                 .tokens = {
4478                                 (void *) &cmd_setbonding_mode_set,
4479                                 (void *) &cmd_setbonding_mode_bonding,
4480                                 (void *) &cmd_setbonding_mode_mode,
4481                                 (void *) &cmd_setbonding_mode_value,
4482                                 (void *) &cmd_setbonding_mode_port,
4483                                 NULL
4484                 }
4485 };
4486
4487 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4488 struct cmd_set_bonding_lacp_dedicated_queues_result {
4489         cmdline_fixed_string_t set;
4490         cmdline_fixed_string_t bonding;
4491         cmdline_fixed_string_t lacp;
4492         cmdline_fixed_string_t dedicated_queues;
4493         uint8_t port_id;
4494         cmdline_fixed_string_t mode;
4495 };
4496
4497 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4498                 __attribute__((unused))  struct cmdline *cl,
4499                 __attribute__((unused)) void *data)
4500 {
4501         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4502         portid_t port_id = res->port_id;
4503         struct rte_port *port;
4504
4505         port = &ports[port_id];
4506
4507         /** Check if the port is not started **/
4508         if (port->port_status != RTE_PORT_STOPPED) {
4509                 printf("Please stop port %d first\n", port_id);
4510                 return;
4511         }
4512
4513         if (!strcmp(res->mode, "enable")) {
4514                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4515                         printf("Dedicate queues for LACP control packets"
4516                                         " enabled\n");
4517                 else
4518                         printf("Enabling dedicate queues for LACP control "
4519                                         "packets on port %d failed\n", port_id);
4520         } else if (!strcmp(res->mode, "disable")) {
4521                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4522                         printf("Dedicated queues for LACP control packets "
4523                                         "disabled\n");
4524                 else
4525                         printf("Disabling dedicated queues for LACP control "
4526                                         "traffic on port %d failed\n", port_id);
4527         }
4528 }
4529
4530 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4531 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4532                 set, "set");
4533 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4534 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4535                 bonding, "bonding");
4536 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4537 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4538                 lacp, "lacp");
4539 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4540 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4541                 dedicated_queues, "dedicated_queues");
4542 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4543 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4544                 port_id, UINT8);
4545 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4546 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4547                 mode, "enable#disable");
4548
4549 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4550                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4551                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4552                         "enable|disable: "
4553                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4554                 .data = NULL,
4555                 .tokens = {
4556                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4557                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4558                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4559                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4560                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4561                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4562                         NULL
4563                 }
4564 };
4565
4566 /* *** SET BALANCE XMIT POLICY *** */
4567 struct cmd_set_bonding_balance_xmit_policy_result {
4568         cmdline_fixed_string_t set;
4569         cmdline_fixed_string_t bonding;
4570         cmdline_fixed_string_t balance_xmit_policy;
4571         uint8_t port_id;
4572         cmdline_fixed_string_t policy;
4573 };
4574
4575 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4576                 __attribute__((unused))  struct cmdline *cl,
4577                 __attribute__((unused)) void *data)
4578 {
4579         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4580         portid_t port_id = res->port_id;
4581         uint8_t policy;
4582
4583         if (!strcmp(res->policy, "l2")) {
4584                 policy = BALANCE_XMIT_POLICY_LAYER2;
4585         } else if (!strcmp(res->policy, "l23")) {
4586                 policy = BALANCE_XMIT_POLICY_LAYER23;
4587         } else if (!strcmp(res->policy, "l34")) {
4588                 policy = BALANCE_XMIT_POLICY_LAYER34;
4589         } else {
4590                 printf("\t Invalid xmit policy selection");
4591                 return;
4592         }
4593
4594         /* Set the bonding mode for the relevant port. */
4595         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4596                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4597                                 port_id);
4598         }
4599 }
4600
4601 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4602 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4603                 set, "set");
4604 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4605 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4606                 bonding, "bonding");
4607 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4608 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4609                 balance_xmit_policy, "balance_xmit_policy");
4610 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4611 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4612                 port_id, UINT8);
4613 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4614 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4615                 policy, "l2#l23#l34");
4616
4617 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4618                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4619                 .help_str = "set bonding balance_xmit_policy <port_id> "
4620                         "l2|l23|l34: "
4621                         "Set the bonding balance_xmit_policy for port_id",
4622                 .data = NULL,
4623                 .tokens = {
4624                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4625                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4626                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4627                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4628                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4629                                 NULL
4630                 }
4631 };
4632
4633 /* *** SHOW NIC BONDING CONFIGURATION *** */
4634 struct cmd_show_bonding_config_result {
4635         cmdline_fixed_string_t show;
4636         cmdline_fixed_string_t bonding;
4637         cmdline_fixed_string_t config;
4638         portid_t port_id;
4639 };
4640
4641 static void cmd_show_bonding_config_parsed(void *parsed_result,
4642                 __attribute__((unused))  struct cmdline *cl,
4643                 __attribute__((unused)) void *data)
4644 {
4645         struct cmd_show_bonding_config_result *res = parsed_result;
4646         int bonding_mode, agg_mode;
4647         portid_t slaves[RTE_MAX_ETHPORTS];
4648         int num_slaves, num_active_slaves;
4649         int primary_id;
4650         int i;
4651         portid_t port_id = res->port_id;
4652
4653         /* Display the bonding mode.*/
4654         bonding_mode = rte_eth_bond_mode_get(port_id);
4655         if (bonding_mode < 0) {
4656                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4657                 return;
4658         } else
4659                 printf("\tBonding mode: %d\n", bonding_mode);
4660
4661         if (bonding_mode == BONDING_MODE_BALANCE) {
4662                 int balance_xmit_policy;
4663
4664                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4665                 if (balance_xmit_policy < 0) {
4666                         printf("\tFailed to get balance xmit policy for port = %d\n",
4667                                         port_id);
4668                         return;
4669                 } else {
4670                         printf("\tBalance Xmit Policy: ");
4671
4672                         switch (balance_xmit_policy) {
4673                         case BALANCE_XMIT_POLICY_LAYER2:
4674                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4675                                 break;
4676                         case BALANCE_XMIT_POLICY_LAYER23:
4677                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4678                                 break;
4679                         case BALANCE_XMIT_POLICY_LAYER34:
4680                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4681                                 break;
4682                         }
4683                         printf("\n");
4684                 }
4685         }
4686
4687         if (bonding_mode == BONDING_MODE_8023AD) {
4688                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4689                 printf("\tIEEE802.3AD Aggregator Mode: ");
4690                 switch (agg_mode) {
4691                 case AGG_BANDWIDTH:
4692                         printf("bandwidth");
4693                         break;
4694                 case AGG_STABLE:
4695                         printf("stable");
4696                         break;
4697                 case AGG_COUNT:
4698                         printf("count");
4699                         break;
4700                 }
4701                 printf("\n");
4702         }
4703
4704         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4705
4706         if (num_slaves < 0) {
4707                 printf("\tFailed to get slave list for port = %d\n", port_id);
4708                 return;
4709         }
4710         if (num_slaves > 0) {
4711                 printf("\tSlaves (%d): [", num_slaves);
4712                 for (i = 0; i < num_slaves - 1; i++)
4713                         printf("%d ", slaves[i]);
4714
4715                 printf("%d]\n", slaves[num_slaves - 1]);
4716         } else {
4717                 printf("\tSlaves: []\n");
4718
4719         }
4720
4721         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4722                         RTE_MAX_ETHPORTS);
4723
4724         if (num_active_slaves < 0) {
4725                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4726                 return;
4727         }
4728         if (num_active_slaves > 0) {
4729                 printf("\tActive Slaves (%d): [", num_active_slaves);
4730                 for (i = 0; i < num_active_slaves - 1; i++)
4731                         printf("%d ", slaves[i]);
4732
4733                 printf("%d]\n", slaves[num_active_slaves - 1]);
4734
4735         } else {
4736                 printf("\tActive Slaves: []\n");
4737
4738         }
4739
4740         primary_id = rte_eth_bond_primary_get(port_id);
4741         if (primary_id < 0) {
4742                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4743                 return;
4744         } else
4745                 printf("\tPrimary: [%d]\n", primary_id);
4746
4747 }
4748
4749 cmdline_parse_token_string_t cmd_showbonding_config_show =
4750 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4751                 show, "show");
4752 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4753 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4754                 bonding, "bonding");
4755 cmdline_parse_token_string_t cmd_showbonding_config_config =
4756 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4757                 config, "config");
4758 cmdline_parse_token_num_t cmd_showbonding_config_port =
4759 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4760                 port_id, UINT8);
4761
4762 cmdline_parse_inst_t cmd_show_bonding_config = {
4763                 .f = cmd_show_bonding_config_parsed,
4764                 .help_str = "show bonding config <port_id>: "
4765                         "Show the bonding config for port_id",
4766                 .data = NULL,
4767                 .tokens = {
4768                                 (void *)&cmd_showbonding_config_show,
4769                                 (void *)&cmd_showbonding_config_bonding,
4770                                 (void *)&cmd_showbonding_config_config,
4771                                 (void *)&cmd_showbonding_config_port,
4772                                 NULL
4773                 }
4774 };
4775
4776 /* *** SET BONDING PRIMARY *** */
4777 struct cmd_set_bonding_primary_result {
4778         cmdline_fixed_string_t set;
4779         cmdline_fixed_string_t bonding;
4780         cmdline_fixed_string_t primary;
4781         uint8_t slave_id;
4782         uint8_t port_id;
4783 };
4784
4785 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4786                 __attribute__((unused))  struct cmdline *cl,
4787                 __attribute__((unused)) void *data)
4788 {
4789         struct cmd_set_bonding_primary_result *res = parsed_result;
4790         portid_t master_port_id = res->port_id;
4791         portid_t slave_port_id = res->slave_id;
4792
4793         /* Set the primary slave for a bonded device. */
4794         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4795                 printf("\t Failed to set primary slave for port = %d.\n",
4796                                 master_port_id);
4797                 return;
4798         }
4799         init_port_config();
4800 }
4801
4802 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4803 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4804                 set, "set");
4805 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4806 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4807                 bonding, "bonding");
4808 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4809 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4810                 primary, "primary");
4811 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4812 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4813                 slave_id, UINT8);
4814 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4815 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4816                 port_id, UINT8);
4817
4818 cmdline_parse_inst_t cmd_set_bonding_primary = {
4819                 .f = cmd_set_bonding_primary_parsed,
4820                 .help_str = "set bonding primary <slave_id> <port_id>: "
4821                         "Set the primary slave for port_id",
4822                 .data = NULL,
4823                 .tokens = {
4824                                 (void *)&cmd_setbonding_primary_set,
4825                                 (void *)&cmd_setbonding_primary_bonding,
4826                                 (void *)&cmd_setbonding_primary_primary,
4827                                 (void *)&cmd_setbonding_primary_slave,
4828                                 (void *)&cmd_setbonding_primary_port,
4829                                 NULL
4830                 }
4831 };
4832
4833 /* *** ADD SLAVE *** */
4834 struct cmd_add_bonding_slave_result {
4835         cmdline_fixed_string_t add;
4836         cmdline_fixed_string_t bonding;
4837         cmdline_fixed_string_t slave;
4838         uint8_t slave_id;
4839         uint8_t port_id;
4840 };
4841
4842 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4843                 __attribute__((unused))  struct cmdline *cl,
4844                 __attribute__((unused)) void *data)
4845 {
4846         struct cmd_add_bonding_slave_result *res = parsed_result;
4847         portid_t master_port_id = res->port_id;
4848         portid_t slave_port_id = res->slave_id;
4849
4850         /* add the slave for a bonded device. */
4851         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4852                 printf("\t Failed to add slave %d to master port = %d.\n",
4853                                 slave_port_id, master_port_id);
4854                 return;
4855         }
4856         init_port_config();
4857         set_port_slave_flag(slave_port_id);
4858 }
4859
4860 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4861 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4862                 add, "add");
4863 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4864 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4865                 bonding, "bonding");
4866 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4867 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4868                 slave, "slave");
4869 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4870 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4871                 slave_id, UINT8);
4872 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4873 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4874                 port_id, UINT8);
4875
4876 cmdline_parse_inst_t cmd_add_bonding_slave = {
4877                 .f = cmd_add_bonding_slave_parsed,
4878                 .help_str = "add bonding slave <slave_id> <port_id>: "
4879                         "Add a slave device to a bonded device",
4880                 .data = NULL,
4881                 .tokens = {
4882                                 (void *)&cmd_addbonding_slave_add,
4883                                 (void *)&cmd_addbonding_slave_bonding,
4884                                 (void *)&cmd_addbonding_slave_slave,
4885                                 (void *)&cmd_addbonding_slave_slaveid,
4886                                 (void *)&cmd_addbonding_slave_port,
4887                                 NULL
4888                 }
4889 };
4890
4891 /* *** REMOVE SLAVE *** */
4892 struct cmd_remove_bonding_slave_result {
4893         cmdline_fixed_string_t remove;
4894         cmdline_fixed_string_t bonding;
4895         cmdline_fixed_string_t slave;
4896         uint8_t slave_id;
4897         uint8_t port_id;
4898 };
4899
4900 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4901                 __attribute__((unused))  struct cmdline *cl,
4902                 __attribute__((unused)) void *data)
4903 {
4904         struct cmd_remove_bonding_slave_result *res = parsed_result;
4905         portid_t master_port_id = res->port_id;
4906         portid_t slave_port_id = res->slave_id;
4907
4908         /* remove the slave from a bonded device. */
4909         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4910                 printf("\t Failed to remove slave %d from master port = %d.\n",
4911                                 slave_port_id, master_port_id);
4912                 return;
4913         }
4914         init_port_config();
4915         clear_port_slave_flag(slave_port_id);
4916 }
4917
4918 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4919                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4920                                 remove, "remove");
4921 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4922                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4923                                 bonding, "bonding");
4924 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4925                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4926                                 slave, "slave");
4927 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4928                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4929                                 slave_id, UINT8);
4930 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4931                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4932                                 port_id, UINT8);
4933
4934 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4935                 .f = cmd_remove_bonding_slave_parsed,
4936                 .help_str = "remove bonding slave <slave_id> <port_id>: "
4937                         "Remove a slave device from a bonded device",
4938                 .data = NULL,
4939                 .tokens = {
4940                                 (void *)&cmd_removebonding_slave_remove,
4941                                 (void *)&cmd_removebonding_slave_bonding,
4942                                 (void *)&cmd_removebonding_slave_slave,
4943                                 (void *)&cmd_removebonding_slave_slaveid,
4944                                 (void *)&cmd_removebonding_slave_port,
4945                                 NULL
4946                 }
4947 };
4948
4949 /* *** CREATE BONDED DEVICE *** */
4950 struct cmd_create_bonded_device_result {
4951         cmdline_fixed_string_t create;
4952         cmdline_fixed_string_t bonded;
4953         cmdline_fixed_string_t device;
4954         uint8_t mode;
4955         uint8_t socket;
4956 };
4957
4958 static int bond_dev_num = 0;
4959
4960 static void cmd_create_bonded_device_parsed(void *parsed_result,
4961                 __attribute__((unused))  struct cmdline *cl,
4962                 __attribute__((unused)) void *data)
4963 {
4964         struct cmd_create_bonded_device_result *res = parsed_result;
4965         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4966         int port_id;
4967
4968         if (test_done == 0) {
4969                 printf("Please stop forwarding first\n");
4970                 return;
4971         }
4972
4973         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
4974                         bond_dev_num++);
4975
4976         /* Create a new bonded device. */
4977         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4978         if (port_id < 0) {
4979                 printf("\t Failed to create bonded device.\n");
4980                 return;
4981         } else {
4982                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4983                                 port_id);
4984
4985                 /* Update number of ports */
4986                 nb_ports = rte_eth_dev_count();
4987                 reconfig(port_id, res->socket);
4988                 rte_eth_promiscuous_enable(port_id);
4989         }
4990
4991 }
4992
4993 cmdline_parse_token_string_t cmd_createbonded_device_create =
4994                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4995                                 create, "create");
4996 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4997                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4998                                 bonded, "bonded");
4999 cmdline_parse_token_string_t cmd_createbonded_device_device =
5000                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5001                                 device, "device");
5002 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5003                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5004                                 mode, UINT8);
5005 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5006                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5007                                 socket, UINT8);
5008
5009 cmdline_parse_inst_t cmd_create_bonded_device = {
5010                 .f = cmd_create_bonded_device_parsed,
5011                 .help_str = "create bonded device <mode> <socket>: "
5012                         "Create a new bonded device with specific bonding mode and socket",
5013                 .data = NULL,
5014                 .tokens = {
5015                                 (void *)&cmd_createbonded_device_create,
5016                                 (void *)&cmd_createbonded_device_bonded,
5017                                 (void *)&cmd_createbonded_device_device,
5018                                 (void *)&cmd_createbonded_device_mode,
5019                                 (void *)&cmd_createbonded_device_socket,
5020                                 NULL
5021                 }
5022 };
5023
5024 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5025 struct cmd_set_bond_mac_addr_result {
5026         cmdline_fixed_string_t set;
5027         cmdline_fixed_string_t bonding;
5028         cmdline_fixed_string_t mac_addr;
5029         uint8_t port_num;
5030         struct ether_addr address;
5031 };
5032
5033 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5034                 __attribute__((unused))  struct cmdline *cl,
5035                 __attribute__((unused)) void *data)
5036 {
5037         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5038         int ret;
5039
5040         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5041                 return;
5042
5043         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5044
5045         /* check the return value and print it if is < 0 */
5046         if (ret < 0)
5047                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5048 }
5049
5050 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5051                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5052 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5053                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5054                                 "bonding");
5055 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5056                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5057                                 "mac_addr");
5058 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5059                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5060 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5061                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5062
5063 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5064                 .f = cmd_set_bond_mac_addr_parsed,
5065                 .data = (void *) 0,
5066                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5067                 .tokens = {
5068                                 (void *)&cmd_set_bond_mac_addr_set,
5069                                 (void *)&cmd_set_bond_mac_addr_bonding,
5070                                 (void *)&cmd_set_bond_mac_addr_mac,
5071                                 (void *)&cmd_set_bond_mac_addr_portnum,
5072                                 (void *)&cmd_set_bond_mac_addr_addr,
5073                                 NULL
5074                 }
5075 };
5076
5077
5078 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5079 struct cmd_set_bond_mon_period_result {
5080         cmdline_fixed_string_t set;
5081         cmdline_fixed_string_t bonding;
5082         cmdline_fixed_string_t mon_period;
5083         uint8_t port_num;
5084         uint32_t period_ms;
5085 };
5086
5087 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5088                 __attribute__((unused))  struct cmdline *cl,
5089                 __attribute__((unused)) void *data)
5090 {
5091         struct cmd_set_bond_mon_period_result *res = parsed_result;
5092         int ret;
5093
5094         if (res->port_num >= nb_ports) {
5095                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5096                 return;
5097         }
5098
5099         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5100
5101         /* check the return value and print it if is < 0 */
5102         if (ret < 0)
5103                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5104 }
5105
5106 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5107                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5108                                 set, "set");
5109 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5110                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5111                                 bonding, "bonding");
5112 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5113                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5114                                 mon_period,     "mon_period");
5115 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5116                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5117                                 port_num, UINT8);
5118 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5119                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5120                                 period_ms, UINT32);
5121
5122 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5123                 .f = cmd_set_bond_mon_period_parsed,
5124                 .data = (void *) 0,
5125                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5126                 .tokens = {
5127                                 (void *)&cmd_set_bond_mon_period_set,
5128                                 (void *)&cmd_set_bond_mon_period_bonding,
5129                                 (void *)&cmd_set_bond_mon_period_mon_period,
5130                                 (void *)&cmd_set_bond_mon_period_portnum,
5131                                 (void *)&cmd_set_bond_mon_period_period_ms,
5132                                 NULL
5133                 }
5134 };
5135
5136
5137
5138 struct cmd_set_bonding_agg_mode_policy_result {
5139         cmdline_fixed_string_t set;
5140         cmdline_fixed_string_t bonding;
5141         cmdline_fixed_string_t agg_mode;
5142         uint8_t port_num;
5143         cmdline_fixed_string_t policy;
5144 };
5145
5146
5147 static void
5148 cmd_set_bonding_agg_mode(void *parsed_result,
5149                 __attribute__((unused)) struct cmdline *cl,
5150                 __attribute__((unused)) void *data)
5151 {
5152         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5153         uint8_t policy = AGG_BANDWIDTH;
5154
5155         if (res->port_num >= nb_ports) {
5156                 printf("Port id %d must be less than %d\n",
5157                                 res->port_num, nb_ports);
5158                 return;
5159         }
5160
5161         if (!strcmp(res->policy, "bandwidth"))
5162                 policy = AGG_BANDWIDTH;
5163         else if (!strcmp(res->policy, "stable"))
5164                 policy = AGG_STABLE;
5165         else if (!strcmp(res->policy, "count"))
5166                 policy = AGG_COUNT;
5167
5168         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5169 }
5170
5171
5172 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5173         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5174                                 set, "set");
5175 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5176         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5177                                 bonding, "bonding");
5178
5179 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5180         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5181                                 agg_mode, "agg_mode");
5182
5183 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5184         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5185                                 port_num, UINT8);
5186
5187 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5188         TOKEN_STRING_INITIALIZER(
5189                         struct cmd_set_bonding_balance_xmit_policy_result,
5190                 policy, "stable#bandwidth#count");
5191
5192 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5193         .f = cmd_set_bonding_agg_mode,
5194         .data = (void *) 0,
5195         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5196         .tokens = {
5197                         (void *)&cmd_set_bonding_agg_mode_set,
5198                         (void *)&cmd_set_bonding_agg_mode_bonding,
5199                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5200                         (void *)&cmd_set_bonding_agg_mode_portnum,
5201                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5202                         NULL
5203                 }
5204 };
5205
5206
5207 #endif /* RTE_LIBRTE_PMD_BOND */
5208
5209 /* *** SET FORWARDING MODE *** */
5210 struct cmd_set_fwd_mode_result {
5211         cmdline_fixed_string_t set;
5212         cmdline_fixed_string_t fwd;
5213         cmdline_fixed_string_t mode;
5214 };
5215
5216 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5217                                     __attribute__((unused)) struct cmdline *cl,
5218                                     __attribute__((unused)) void *data)
5219 {
5220         struct cmd_set_fwd_mode_result *res = parsed_result;
5221
5222         retry_enabled = 0;
5223         set_pkt_forwarding_mode(res->mode);
5224 }
5225
5226 cmdline_parse_token_string_t cmd_setfwd_set =
5227         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5228 cmdline_parse_token_string_t cmd_setfwd_fwd =
5229         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5230 cmdline_parse_token_string_t cmd_setfwd_mode =
5231         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5232                 "" /* defined at init */);
5233
5234 cmdline_parse_inst_t cmd_set_fwd_mode = {
5235         .f = cmd_set_fwd_mode_parsed,
5236         .data = NULL,
5237         .help_str = NULL, /* defined at init */
5238         .tokens = {
5239                 (void *)&cmd_setfwd_set,
5240                 (void *)&cmd_setfwd_fwd,
5241                 (void *)&cmd_setfwd_mode,
5242                 NULL,
5243         },
5244 };
5245
5246 static void cmd_set_fwd_mode_init(void)
5247 {
5248         char *modes, *c;
5249         static char token[128];
5250         static char help[256];
5251         cmdline_parse_token_string_t *token_struct;
5252
5253         modes = list_pkt_forwarding_modes();
5254         snprintf(help, sizeof(help), "set fwd %s: "
5255                 "Set packet forwarding mode", modes);
5256         cmd_set_fwd_mode.help_str = help;
5257
5258         /* string token separator is # */
5259         for (c = token; *modes != '\0'; modes++)
5260                 if (*modes == '|')
5261                         *c++ = '#';
5262                 else
5263                         *c++ = *modes;
5264         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5265         token_struct->string_data.str = token;
5266 }
5267
5268 /* *** SET RETRY FORWARDING MODE *** */
5269 struct cmd_set_fwd_retry_mode_result {
5270         cmdline_fixed_string_t set;
5271         cmdline_fixed_string_t fwd;
5272         cmdline_fixed_string_t mode;
5273         cmdline_fixed_string_t retry;
5274 };
5275
5276 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5277                             __attribute__((unused)) struct cmdline *cl,
5278                             __attribute__((unused)) void *data)
5279 {
5280         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5281
5282         retry_enabled = 1;
5283         set_pkt_forwarding_mode(res->mode);
5284 }
5285
5286 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5287         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5288                         set, "set");
5289 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5290         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5291                         fwd, "fwd");
5292 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5293         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5294                         mode,
5295                 "" /* defined at init */);
5296 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5297         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5298                         retry, "retry");
5299
5300 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5301         .f = cmd_set_fwd_retry_mode_parsed,
5302         .data = NULL,
5303         .help_str = NULL, /* defined at init */
5304         .tokens = {
5305                 (void *)&cmd_setfwd_retry_set,
5306                 (void *)&cmd_setfwd_retry_fwd,
5307                 (void *)&cmd_setfwd_retry_mode,
5308                 (void *)&cmd_setfwd_retry_retry,
5309                 NULL,
5310         },
5311 };
5312
5313 static void cmd_set_fwd_retry_mode_init(void)
5314 {
5315         char *modes, *c;
5316         static char token[128];
5317         static char help[256];
5318         cmdline_parse_token_string_t *token_struct;
5319
5320         modes = list_pkt_forwarding_retry_modes();
5321         snprintf(help, sizeof(help), "set fwd %s retry: "
5322                 "Set packet forwarding mode with retry", modes);
5323         cmd_set_fwd_retry_mode.help_str = help;
5324
5325         /* string token separator is # */
5326         for (c = token; *modes != '\0'; modes++)
5327                 if (*modes == '|')
5328                         *c++ = '#';
5329                 else
5330                         *c++ = *modes;
5331         token_struct = (cmdline_parse_token_string_t *)
5332                 cmd_set_fwd_retry_mode.tokens[2];
5333         token_struct->string_data.str = token;
5334 }
5335
5336 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5337 struct cmd_set_burst_tx_retry_result {
5338         cmdline_fixed_string_t set;
5339         cmdline_fixed_string_t burst;
5340         cmdline_fixed_string_t tx;
5341         cmdline_fixed_string_t delay;
5342         uint32_t time;
5343         cmdline_fixed_string_t retry;
5344         uint32_t retry_num;
5345 };
5346
5347 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5348                                         __attribute__((unused)) struct cmdline *cl,
5349                                         __attribute__((unused)) void *data)
5350 {
5351         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5352
5353         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5354                 && !strcmp(res->tx, "tx")) {
5355                 if (!strcmp(res->delay, "delay"))
5356                         burst_tx_delay_time = res->time;
5357                 if (!strcmp(res->retry, "retry"))
5358                         burst_tx_retry_num = res->retry_num;
5359         }
5360
5361 }
5362
5363 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5365 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5366         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5367                                  "burst");
5368 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5369         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5370 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5371         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5372 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5373         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5374 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5375         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5376 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5377         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5378
5379 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5380         .f = cmd_set_burst_tx_retry_parsed,
5381         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5382         .tokens = {
5383                 (void *)&cmd_set_burst_tx_retry_set,
5384                 (void *)&cmd_set_burst_tx_retry_burst,
5385                 (void *)&cmd_set_burst_tx_retry_tx,
5386                 (void *)&cmd_set_burst_tx_retry_delay,
5387                 (void *)&cmd_set_burst_tx_retry_time,
5388                 (void *)&cmd_set_burst_tx_retry_retry,
5389                 (void *)&cmd_set_burst_tx_retry_retry_num,
5390                 NULL,
5391         },
5392 };
5393
5394 /* *** SET PROMISC MODE *** */
5395 struct cmd_set_promisc_mode_result {
5396         cmdline_fixed_string_t set;
5397         cmdline_fixed_string_t promisc;
5398         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5399         uint8_t port_num;                /* valid if "allports" argument == 0 */
5400         cmdline_fixed_string_t mode;
5401 };
5402
5403 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5404                                         __attribute__((unused)) struct cmdline *cl,
5405                                         void *allports)
5406 {
5407         struct cmd_set_promisc_mode_result *res = parsed_result;
5408         int enable;
5409         portid_t i;
5410
5411         if (!strcmp(res->mode, "on"))
5412                 enable = 1;
5413         else
5414                 enable = 0;
5415
5416         /* all ports */
5417         if (allports) {
5418                 RTE_ETH_FOREACH_DEV(i) {
5419                         if (enable)
5420                                 rte_eth_promiscuous_enable(i);
5421                         else
5422                                 rte_eth_promiscuous_disable(i);
5423                 }
5424         }
5425         else {
5426                 if (enable)
5427                         rte_eth_promiscuous_enable(res->port_num);
5428                 else
5429                         rte_eth_promiscuous_disable(res->port_num);
5430         }
5431 }
5432
5433 cmdline_parse_token_string_t cmd_setpromisc_set =
5434         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5435 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5436         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5437                                  "promisc");
5438 cmdline_parse_token_string_t cmd_setpromisc_portall =
5439         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5440                                  "all");
5441 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5442         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5443                               UINT8);
5444 cmdline_parse_token_string_t cmd_setpromisc_mode =
5445         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5446                                  "on#off");
5447
5448 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5449         .f = cmd_set_promisc_mode_parsed,
5450         .data = (void *)1,
5451         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5452         .tokens = {
5453                 (void *)&cmd_setpromisc_set,
5454                 (void *)&cmd_setpromisc_promisc,
5455                 (void *)&cmd_setpromisc_portall,
5456                 (void *)&cmd_setpromisc_mode,
5457                 NULL,
5458         },
5459 };
5460
5461 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5462         .f = cmd_set_promisc_mode_parsed,
5463         .data = (void *)0,
5464         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5465         .tokens = {
5466                 (void *)&cmd_setpromisc_set,
5467                 (void *)&cmd_setpromisc_promisc,
5468                 (void *)&cmd_setpromisc_portnum,
5469                 (void *)&cmd_setpromisc_mode,
5470                 NULL,
5471         },
5472 };
5473
5474 /* *** SET ALLMULTI MODE *** */
5475 struct cmd_set_allmulti_mode_result {
5476         cmdline_fixed_string_t set;
5477         cmdline_fixed_string_t allmulti;
5478         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5479         uint8_t port_num;                /* valid if "allports" argument == 0 */
5480         cmdline_fixed_string_t mode;
5481 };
5482
5483 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5484                                         __attribute__((unused)) struct cmdline *cl,
5485                                         void *allports)
5486 {
5487         struct cmd_set_allmulti_mode_result *res = parsed_result;
5488         int enable;
5489         portid_t i;
5490
5491         if (!strcmp(res->mode, "on"))
5492                 enable = 1;
5493         else
5494                 enable = 0;
5495
5496         /* all ports */
5497         if (allports) {
5498                 RTE_ETH_FOREACH_DEV(i) {
5499                         if (enable)
5500                                 rte_eth_allmulticast_enable(i);
5501                         else
5502                                 rte_eth_allmulticast_disable(i);
5503                 }
5504         }
5505         else {
5506                 if (enable)
5507                         rte_eth_allmulticast_enable(res->port_num);
5508                 else
5509                         rte_eth_allmulticast_disable(res->port_num);
5510         }
5511 }
5512
5513 cmdline_parse_token_string_t cmd_setallmulti_set =
5514         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5515 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5516         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5517                                  "allmulti");
5518 cmdline_parse_token_string_t cmd_setallmulti_portall =
5519         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5520                                  "all");
5521 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5522         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5523                               UINT8);
5524 cmdline_parse_token_string_t cmd_setallmulti_mode =
5525         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5526                                  "on#off");
5527
5528 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5529         .f = cmd_set_allmulti_mode_parsed,
5530         .data = (void *)1,
5531         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5532         .tokens = {
5533                 (void *)&cmd_setallmulti_set,
5534                 (void *)&cmd_setallmulti_allmulti,
5535                 (void *)&cmd_setallmulti_portall,
5536                 (void *)&cmd_setallmulti_mode,
5537                 NULL,
5538         },
5539 };
5540
5541 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5542         .f = cmd_set_allmulti_mode_parsed,
5543         .data = (void *)0,
5544         .help_str = "set allmulti <port_id> on|off: "
5545                 "Set allmulti mode on port_id",
5546         .tokens = {
5547                 (void *)&cmd_setallmulti_set,
5548                 (void *)&cmd_setallmulti_allmulti,
5549                 (void *)&cmd_setallmulti_portnum,
5550                 (void *)&cmd_setallmulti_mode,
5551                 NULL,
5552         },
5553 };
5554
5555 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5556 struct cmd_link_flow_ctrl_set_result {
5557         cmdline_fixed_string_t set;
5558         cmdline_fixed_string_t flow_ctrl;
5559         cmdline_fixed_string_t rx;
5560         cmdline_fixed_string_t rx_lfc_mode;
5561         cmdline_fixed_string_t tx;
5562         cmdline_fixed_string_t tx_lfc_mode;
5563         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5564         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5565         cmdline_fixed_string_t autoneg_str;
5566         cmdline_fixed_string_t autoneg;
5567         cmdline_fixed_string_t hw_str;
5568         uint32_t high_water;
5569         cmdline_fixed_string_t lw_str;
5570         uint32_t low_water;
5571         cmdline_fixed_string_t pt_str;
5572         uint16_t pause_time;
5573         cmdline_fixed_string_t xon_str;
5574         uint16_t send_xon;
5575         uint8_t  port_id;
5576 };
5577
5578 cmdline_parse_token_string_t cmd_lfc_set_set =
5579         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5580                                 set, "set");
5581 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5582         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5583                                 flow_ctrl, "flow_ctrl");
5584 cmdline_parse_token_string_t cmd_lfc_set_rx =
5585         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5586                                 rx, "rx");
5587 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5588         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5589                                 rx_lfc_mode, "on#off");
5590 cmdline_parse_token_string_t cmd_lfc_set_tx =
5591         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5592                                 tx, "tx");
5593 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5594         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5595                                 tx_lfc_mode, "on#off");
5596 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5597         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5598                                 hw_str, "high_water");
5599 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5600         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5601                                 high_water, UINT32);
5602 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5603         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5604                                 lw_str, "low_water");
5605 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5606         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5607                                 low_water, UINT32);
5608 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5609         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5610                                 pt_str, "pause_time");
5611 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5612         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5613                                 pause_time, UINT16);
5614 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5615         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5616                                 xon_str, "send_xon");
5617 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5618         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5619                                 send_xon, UINT16);
5620 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5621         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5622                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5623 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5624         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5625                                 mac_ctrl_frame_fwd_mode, "on#off");
5626 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5627         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5628                                 autoneg_str, "autoneg");
5629 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5630         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5631                                 autoneg, "on#off");
5632 cmdline_parse_token_num_t cmd_lfc_set_portid =
5633         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5634                                 port_id, UINT8);
5635
5636 /* forward declaration */
5637 static void
5638 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5639                               void *data);
5640
5641 cmdline_parse_inst_t cmd_link_flow_control_set = {
5642         .f = cmd_link_flow_ctrl_set_parsed,
5643         .data = NULL,
5644         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5645                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5646                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5647         .tokens = {
5648                 (void *)&cmd_lfc_set_set,
5649                 (void *)&cmd_lfc_set_flow_ctrl,
5650                 (void *)&cmd_lfc_set_rx,
5651                 (void *)&cmd_lfc_set_rx_mode,
5652                 (void *)&cmd_lfc_set_tx,
5653                 (void *)&cmd_lfc_set_tx_mode,
5654                 (void *)&cmd_lfc_set_high_water,
5655                 (void *)&cmd_lfc_set_low_water,
5656                 (void *)&cmd_lfc_set_pause_time,
5657                 (void *)&cmd_lfc_set_send_xon,
5658                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5659                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5660                 (void *)&cmd_lfc_set_autoneg_str,
5661                 (void *)&cmd_lfc_set_autoneg,
5662                 (void *)&cmd_lfc_set_portid,
5663                 NULL,
5664         },
5665 };
5666
5667 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5668         .f = cmd_link_flow_ctrl_set_parsed,
5669         .data = (void *)&cmd_link_flow_control_set_rx,
5670         .help_str = "set flow_ctrl rx on|off <port_id>: "
5671                 "Change rx flow control parameter",
5672         .tokens = {
5673                 (void *)&cmd_lfc_set_set,
5674                 (void *)&cmd_lfc_set_flow_ctrl,
5675                 (void *)&cmd_lfc_set_rx,
5676                 (void *)&cmd_lfc_set_rx_mode,
5677                 (void *)&cmd_lfc_set_portid,
5678                 NULL,
5679         },
5680 };
5681
5682 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5683         .f = cmd_link_flow_ctrl_set_parsed,
5684         .data = (void *)&cmd_link_flow_control_set_tx,
5685         .help_str = "set flow_ctrl tx on|off <port_id>: "
5686                 "Change tx flow control parameter",
5687         .tokens = {
5688                 (void *)&cmd_lfc_set_set,
5689                 (void *)&cmd_lfc_set_flow_ctrl,
5690                 (void *)&cmd_lfc_set_tx,
5691                 (void *)&cmd_lfc_set_tx_mode,
5692                 (void *)&cmd_lfc_set_portid,
5693                 NULL,
5694         },
5695 };
5696
5697 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5698         .f = cmd_link_flow_ctrl_set_parsed,
5699         .data = (void *)&cmd_link_flow_control_set_hw,
5700         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5701                 "Change high water flow control parameter",
5702         .tokens = {
5703                 (void *)&cmd_lfc_set_set,
5704                 (void *)&cmd_lfc_set_flow_ctrl,
5705                 (void *)&cmd_lfc_set_high_water_str,
5706                 (void *)&cmd_lfc_set_high_water,
5707                 (void *)&cmd_lfc_set_portid,
5708                 NULL,
5709         },
5710 };
5711
5712 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5713         .f = cmd_link_flow_ctrl_set_parsed,
5714         .data = (void *)&cmd_link_flow_control_set_lw,
5715         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5716                 "Change low water flow control parameter",
5717         .tokens = {
5718                 (void *)&cmd_lfc_set_set,
5719                 (void *)&cmd_lfc_set_flow_ctrl,
5720                 (void *)&cmd_lfc_set_low_water_str,
5721                 (void *)&cmd_lfc_set_low_water,
5722                 (void *)&cmd_lfc_set_portid,
5723                 NULL,
5724         },
5725 };
5726
5727 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5728         .f = cmd_link_flow_ctrl_set_parsed,
5729         .data = (void *)&cmd_link_flow_control_set_pt,
5730         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5731                 "Change pause time flow control parameter",
5732         .tokens = {
5733                 (void *)&cmd_lfc_set_set,
5734                 (void *)&cmd_lfc_set_flow_ctrl,
5735                 (void *)&cmd_lfc_set_pause_time_str,
5736                 (void *)&cmd_lfc_set_pause_time,
5737                 (void *)&cmd_lfc_set_portid,
5738                 NULL,
5739         },
5740 };
5741
5742 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5743         .f = cmd_link_flow_ctrl_set_parsed,
5744         .data = (void *)&cmd_link_flow_control_set_xon,
5745         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5746                 "Change send_xon flow control parameter",
5747         .tokens = {
5748                 (void *)&cmd_lfc_set_set,
5749                 (void *)&cmd_lfc_set_flow_ctrl,
5750                 (void *)&cmd_lfc_set_send_xon_str,
5751                 (void *)&cmd_lfc_set_send_xon,
5752                 (void *)&cmd_lfc_set_portid,
5753                 NULL,
5754         },
5755 };
5756
5757 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5758         .f = cmd_link_flow_ctrl_set_parsed,
5759         .data = (void *)&cmd_link_flow_control_set_macfwd,
5760         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5761                 "Change mac ctrl fwd flow control parameter",
5762         .tokens = {
5763                 (void *)&cmd_lfc_set_set,
5764                 (void *)&cmd_lfc_set_flow_ctrl,
5765                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5766                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5767                 (void *)&cmd_lfc_set_portid,
5768                 NULL,
5769         },
5770 };
5771
5772 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5773         .f = cmd_link_flow_ctrl_set_parsed,
5774         .data = (void *)&cmd_link_flow_control_set_autoneg,
5775         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5776                 "Change autoneg flow control parameter",
5777         .tokens = {
5778                 (void *)&cmd_lfc_set_set,
5779                 (void *)&cmd_lfc_set_flow_ctrl,
5780                 (void *)&cmd_lfc_set_autoneg_str,
5781                 (void *)&cmd_lfc_set_autoneg,
5782                 (void *)&cmd_lfc_set_portid,
5783                 NULL,
5784         },
5785 };
5786
5787 static void
5788 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5789                               __attribute__((unused)) struct cmdline *cl,
5790                               void *data)
5791 {
5792         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5793         cmdline_parse_inst_t *cmd = data;
5794         struct rte_eth_fc_conf fc_conf;
5795         int rx_fc_en = 0;
5796         int tx_fc_en = 0;
5797         int ret;
5798
5799         /*
5800          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5801          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5802          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5803          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5804          */
5805         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5806                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5807         };
5808
5809         /* Partial command line, retrieve current configuration */
5810         if (cmd) {
5811                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5812                 if (ret != 0) {
5813                         printf("cannot get current flow ctrl parameters, return"
5814                                "code = %d\n", ret);
5815                         return;
5816                 }
5817
5818                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5819                     (fc_conf.mode == RTE_FC_FULL))
5820                         rx_fc_en = 1;
5821                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5822                     (fc_conf.mode == RTE_FC_FULL))
5823                         tx_fc_en = 1;
5824         }
5825
5826         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5827                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5828
5829         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5830                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5831
5832         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5833
5834         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5835                 fc_conf.high_water = res->high_water;
5836
5837         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5838                 fc_conf.low_water = res->low_water;
5839
5840         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5841                 fc_conf.pause_time = res->pause_time;
5842
5843         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5844                 fc_conf.send_xon = res->send_xon;
5845
5846         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5847                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5848                         fc_conf.mac_ctrl_frame_fwd = 1;
5849                 else
5850                         fc_conf.mac_ctrl_frame_fwd = 0;
5851         }
5852
5853         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5854                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5855
5856         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5857         if (ret != 0)
5858                 printf("bad flow contrl parameter, return code = %d \n", ret);
5859 }
5860
5861 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5862 struct cmd_priority_flow_ctrl_set_result {
5863         cmdline_fixed_string_t set;
5864         cmdline_fixed_string_t pfc_ctrl;
5865         cmdline_fixed_string_t rx;
5866         cmdline_fixed_string_t rx_pfc_mode;
5867         cmdline_fixed_string_t tx;
5868         cmdline_fixed_string_t tx_pfc_mode;
5869         uint32_t high_water;
5870         uint32_t low_water;
5871         uint16_t pause_time;
5872         uint8_t  priority;
5873         uint8_t  port_id;
5874 };
5875
5876 static void
5877 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5878                        __attribute__((unused)) struct cmdline *cl,
5879                        __attribute__((unused)) void *data)
5880 {
5881         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5882         struct rte_eth_pfc_conf pfc_conf;
5883         int rx_fc_enable, tx_fc_enable;
5884         int ret;
5885
5886         /*
5887          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5888          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5889          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5890          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5891          */
5892         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5893                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5894         };
5895
5896         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5897         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5898         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5899         pfc_conf.fc.high_water = res->high_water;
5900         pfc_conf.fc.low_water  = res->low_water;
5901         pfc_conf.fc.pause_time = res->pause_time;
5902         pfc_conf.priority      = res->priority;
5903
5904         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5905         if (ret != 0)
5906                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5907 }
5908
5909 cmdline_parse_token_string_t cmd_pfc_set_set =
5910         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5911                                 set, "set");
5912 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5913         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5914                                 pfc_ctrl, "pfc_ctrl");
5915 cmdline_parse_token_string_t cmd_pfc_set_rx =
5916         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5917                                 rx, "rx");
5918 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5919         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5920                                 rx_pfc_mode, "on#off");
5921 cmdline_parse_token_string_t cmd_pfc_set_tx =
5922         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5923                                 tx, "tx");
5924 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5925         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5926                                 tx_pfc_mode, "on#off");
5927 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5928         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5929                                 high_water, UINT32);
5930 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5931         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5932                                 low_water, UINT32);
5933 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5934         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5935                                 pause_time, UINT16);
5936 cmdline_parse_token_num_t cmd_pfc_set_priority =
5937         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5938                                 priority, UINT8);
5939 cmdline_parse_token_num_t cmd_pfc_set_portid =
5940         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5941                                 port_id, UINT8);
5942
5943 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5944         .f = cmd_priority_flow_ctrl_set_parsed,
5945         .data = NULL,
5946         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5947                 "<pause_time> <priority> <port_id>: "
5948                 "Configure the Ethernet priority flow control",
5949         .tokens = {
5950                 (void *)&cmd_pfc_set_set,
5951                 (void *)&cmd_pfc_set_flow_ctrl,
5952                 (void *)&cmd_pfc_set_rx,
5953                 (void *)&cmd_pfc_set_rx_mode,
5954                 (void *)&cmd_pfc_set_tx,
5955                 (void *)&cmd_pfc_set_tx_mode,
5956                 (void *)&cmd_pfc_set_high_water,
5957                 (void *)&cmd_pfc_set_low_water,
5958                 (void *)&cmd_pfc_set_pause_time,
5959                 (void *)&cmd_pfc_set_priority,
5960                 (void *)&cmd_pfc_set_portid,
5961                 NULL,
5962         },
5963 };
5964
5965 /* *** RESET CONFIGURATION *** */
5966 struct cmd_reset_result {
5967         cmdline_fixed_string_t reset;
5968         cmdline_fixed_string_t def;
5969 };
5970
5971 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5972                              struct cmdline *cl,
5973                              __attribute__((unused)) void *data)
5974 {
5975         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5976         set_def_fwd_config();
5977 }
5978
5979 cmdline_parse_token_string_t cmd_reset_set =
5980         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5981 cmdline_parse_token_string_t cmd_reset_def =
5982         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5983                                  "default");
5984
5985 cmdline_parse_inst_t cmd_reset = {
5986         .f = cmd_reset_parsed,
5987         .data = NULL,
5988         .help_str = "set default: Reset default forwarding configuration",
5989         .tokens = {
5990                 (void *)&cmd_reset_set,
5991                 (void *)&cmd_reset_def,
5992                 NULL,
5993         },
5994 };
5995
5996 /* *** START FORWARDING *** */
5997 struct cmd_start_result {
5998         cmdline_fixed_string_t start;
5999 };
6000
6001 cmdline_parse_token_string_t cmd_start_start =
6002         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6003
6004 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6005                              __attribute__((unused)) struct cmdline *cl,
6006                              __attribute__((unused)) void *data)
6007 {
6008         start_packet_forwarding(0);
6009 }
6010
6011 cmdline_parse_inst_t cmd_start = {
6012         .f = cmd_start_parsed,
6013         .data = NULL,
6014         .help_str = "start: Start packet forwarding",
6015         .tokens = {
6016                 (void *)&cmd_start_start,
6017                 NULL,
6018         },
6019 };
6020
6021 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6022 struct cmd_start_tx_first_result {
6023         cmdline_fixed_string_t start;
6024         cmdline_fixed_string_t tx_first;
6025 };
6026
6027 static void
6028 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6029                           __attribute__((unused)) struct cmdline *cl,
6030                           __attribute__((unused)) void *data)
6031 {
6032         start_packet_forwarding(1);
6033 }
6034
6035 cmdline_parse_token_string_t cmd_start_tx_first_start =
6036         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6037                                  "start");
6038 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6039         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6040                                  tx_first, "tx_first");
6041
6042 cmdline_parse_inst_t cmd_start_tx_first = {
6043         .f = cmd_start_tx_first_parsed,
6044         .data = NULL,
6045         .help_str = "start tx_first: Start packet forwarding, "
6046                 "after sending 1 burst of packets",
6047         .tokens = {
6048                 (void *)&cmd_start_tx_first_start,
6049                 (void *)&cmd_start_tx_first_tx_first,
6050                 NULL,
6051         },
6052 };
6053
6054 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6055 struct cmd_start_tx_first_n_result {
6056         cmdline_fixed_string_t start;
6057         cmdline_fixed_string_t tx_first;
6058         uint32_t tx_num;
6059 };
6060
6061 static void
6062 cmd_start_tx_first_n_parsed(void *parsed_result,
6063                           __attribute__((unused)) struct cmdline *cl,
6064                           __attribute__((unused)) void *data)
6065 {
6066         struct cmd_start_tx_first_n_result *res = parsed_result;
6067
6068         start_packet_forwarding(res->tx_num);
6069 }
6070
6071 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6072         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6073                         start, "start");
6074 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6075         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6076                         tx_first, "tx_first");
6077 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6078         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6079                         tx_num, UINT32);
6080
6081 cmdline_parse_inst_t cmd_start_tx_first_n = {
6082         .f = cmd_start_tx_first_n_parsed,
6083         .data = NULL,
6084         .help_str = "start tx_first <num>: "
6085                 "packet forwarding, after sending <num> bursts of packets",
6086         .tokens = {
6087                 (void *)&cmd_start_tx_first_n_start,
6088                 (void *)&cmd_start_tx_first_n_tx_first,
6089                 (void *)&cmd_start_tx_first_n_tx_num,
6090                 NULL,
6091         },
6092 };
6093
6094 /* *** SET LINK UP *** */
6095 struct cmd_set_link_up_result {
6096         cmdline_fixed_string_t set;
6097         cmdline_fixed_string_t link_up;
6098         cmdline_fixed_string_t port;
6099         uint8_t port_id;
6100 };
6101
6102 cmdline_parse_token_string_t cmd_set_link_up_set =
6103         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6104 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6105         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6106                                 "link-up");
6107 cmdline_parse_token_string_t cmd_set_link_up_port =
6108         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6109 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6110         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6111
6112 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6113                              __attribute__((unused)) struct cmdline *cl,
6114                              __attribute__((unused)) void *data)
6115 {
6116         struct cmd_set_link_up_result *res = parsed_result;
6117         dev_set_link_up(res->port_id);
6118 }
6119
6120 cmdline_parse_inst_t cmd_set_link_up = {
6121         .f = cmd_set_link_up_parsed,
6122         .data = NULL,
6123         .help_str = "set link-up port <port id>",
6124         .tokens = {
6125                 (void *)&cmd_set_link_up_set,
6126                 (void *)&cmd_set_link_up_link_up,
6127                 (void *)&cmd_set_link_up_port,
6128                 (void *)&cmd_set_link_up_port_id,
6129                 NULL,
6130         },
6131 };
6132
6133 /* *** SET LINK DOWN *** */
6134 struct cmd_set_link_down_result {
6135         cmdline_fixed_string_t set;
6136         cmdline_fixed_string_t link_down;
6137         cmdline_fixed_string_t port;
6138         uint8_t port_id;
6139 };
6140
6141 cmdline_parse_token_string_t cmd_set_link_down_set =
6142         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6143 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6144         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6145                                 "link-down");
6146 cmdline_parse_token_string_t cmd_set_link_down_port =
6147         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6148 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6149         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6150
6151 static void cmd_set_link_down_parsed(
6152                                 __attribute__((unused)) void *parsed_result,
6153                                 __attribute__((unused)) struct cmdline *cl,
6154                                 __attribute__((unused)) void *data)
6155 {
6156         struct cmd_set_link_down_result *res = parsed_result;
6157         dev_set_link_down(res->port_id);
6158 }
6159
6160 cmdline_parse_inst_t cmd_set_link_down = {
6161         .f = cmd_set_link_down_parsed,
6162         .data = NULL,
6163         .help_str = "set link-down port <port id>",
6164         .tokens = {
6165                 (void *)&cmd_set_link_down_set,
6166                 (void *)&cmd_set_link_down_link_down,
6167                 (void *)&cmd_set_link_down_port,
6168                 (void *)&cmd_set_link_down_port_id,
6169                 NULL,
6170         },
6171 };
6172
6173 /* *** SHOW CFG *** */
6174 struct cmd_showcfg_result {
6175         cmdline_fixed_string_t show;
6176         cmdline_fixed_string_t cfg;
6177         cmdline_fixed_string_t what;
6178 };
6179
6180 static void cmd_showcfg_parsed(void *parsed_result,
6181                                __attribute__((unused)) struct cmdline *cl,
6182                                __attribute__((unused)) void *data)
6183 {
6184         struct cmd_showcfg_result *res = parsed_result;
6185         if (!strcmp(res->what, "rxtx"))
6186                 rxtx_config_display();
6187         else if (!strcmp(res->what, "cores"))
6188                 fwd_lcores_config_display();
6189         else if (!strcmp(res->what, "fwd"))
6190                 pkt_fwd_config_display(&cur_fwd_config);
6191         else if (!strcmp(res->what, "txpkts"))
6192                 show_tx_pkt_segments();
6193 }
6194
6195 cmdline_parse_token_string_t cmd_showcfg_show =
6196         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6197 cmdline_parse_token_string_t cmd_showcfg_port =
6198         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6199 cmdline_parse_token_string_t cmd_showcfg_what =
6200         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6201                                  "rxtx#cores#fwd#txpkts");
6202
6203 cmdline_parse_inst_t cmd_showcfg = {
6204         .f = cmd_showcfg_parsed,
6205         .data = NULL,
6206         .help_str = "show config rxtx|cores|fwd|txpkts",
6207         .tokens = {
6208                 (void *)&cmd_showcfg_show,
6209                 (void *)&cmd_showcfg_port,
6210                 (void *)&cmd_showcfg_what,
6211                 NULL,
6212         },
6213 };
6214
6215 /* *** SHOW ALL PORT INFO *** */
6216 struct cmd_showportall_result {
6217         cmdline_fixed_string_t show;
6218         cmdline_fixed_string_t port;
6219         cmdline_fixed_string_t what;
6220         cmdline_fixed_string_t all;
6221 };
6222
6223 static void cmd_showportall_parsed(void *parsed_result,
6224                                 __attribute__((unused)) struct cmdline *cl,
6225                                 __attribute__((unused)) void *data)
6226 {
6227         portid_t i;
6228
6229         struct cmd_showportall_result *res = parsed_result;
6230         if (!strcmp(res->show, "clear")) {
6231                 if (!strcmp(res->what, "stats"))
6232                         RTE_ETH_FOREACH_DEV(i)
6233                                 nic_stats_clear(i);
6234                 else if (!strcmp(res->what, "xstats"))
6235                         RTE_ETH_FOREACH_DEV(i)
6236                                 nic_xstats_clear(i);
6237         } else if (!strcmp(res->what, "info"))
6238                 RTE_ETH_FOREACH_DEV(i)
6239                         port_infos_display(i);
6240         else if (!strcmp(res->what, "stats"))
6241                 RTE_ETH_FOREACH_DEV(i)
6242                         nic_stats_display(i);
6243         else if (!strcmp(res->what, "xstats"))
6244                 RTE_ETH_FOREACH_DEV(i)
6245                         nic_xstats_display(i);
6246         else if (!strcmp(res->what, "fdir"))
6247                 RTE_ETH_FOREACH_DEV(i)
6248                         fdir_get_infos(i);
6249         else if (!strcmp(res->what, "stat_qmap"))
6250                 RTE_ETH_FOREACH_DEV(i)
6251                         nic_stats_mapping_display(i);
6252         else if (!strcmp(res->what, "dcb_tc"))
6253                 RTE_ETH_FOREACH_DEV(i)
6254                         port_dcb_info_display(i);
6255         else if (!strcmp(res->what, "cap"))
6256                 RTE_ETH_FOREACH_DEV(i)
6257                         port_offload_cap_display(i);
6258 }
6259
6260 cmdline_parse_token_string_t cmd_showportall_show =
6261         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6262                                  "show#clear");
6263 cmdline_parse_token_string_t cmd_showportall_port =
6264         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6265 cmdline_parse_token_string_t cmd_showportall_what =
6266         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6267                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6268 cmdline_parse_token_string_t cmd_showportall_all =
6269         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6270 cmdline_parse_inst_t cmd_showportall = {
6271         .f = cmd_showportall_parsed,
6272         .data = NULL,
6273         .help_str = "show|clear port "
6274                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6275         .tokens = {
6276                 (void *)&cmd_showportall_show,
6277                 (void *)&cmd_showportall_port,
6278                 (void *)&cmd_showportall_what,
6279                 (void *)&cmd_showportall_all,
6280                 NULL,
6281         },
6282 };
6283
6284 /* *** SHOW PORT INFO *** */
6285 struct cmd_showport_result {
6286         cmdline_fixed_string_t show;
6287         cmdline_fixed_string_t port;
6288         cmdline_fixed_string_t what;
6289         uint8_t portnum;
6290 };
6291
6292 static void cmd_showport_parsed(void *parsed_result,
6293                                 __attribute__((unused)) struct cmdline *cl,
6294                                 __attribute__((unused)) void *data)
6295 {
6296         struct cmd_showport_result *res = parsed_result;
6297         if (!strcmp(res->show, "clear")) {
6298                 if (!strcmp(res->what, "stats"))
6299                         nic_stats_clear(res->portnum);
6300                 else if (!strcmp(res->what, "xstats"))
6301                         nic_xstats_clear(res->portnum);
6302         } else if (!strcmp(res->what, "info"))
6303                 port_infos_display(res->portnum);
6304         else if (!strcmp(res->what, "stats"))
6305                 nic_stats_display(res->portnum);
6306         else if (!strcmp(res->what, "xstats"))
6307                 nic_xstats_display(res->portnum);
6308         else if (!strcmp(res->what, "fdir"))
6309                  fdir_get_infos(res->portnum);
6310         else if (!strcmp(res->what, "stat_qmap"))
6311                 nic_stats_mapping_display(res->portnum);
6312         else if (!strcmp(res->what, "dcb_tc"))
6313                 port_dcb_info_display(res->portnum);
6314         else if (!strcmp(res->what, "cap"))
6315                 port_offload_cap_display(res->portnum);
6316 }
6317
6318 cmdline_parse_token_string_t cmd_showport_show =
6319         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6320                                  "show#clear");
6321 cmdline_parse_token_string_t cmd_showport_port =
6322         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6323 cmdline_parse_token_string_t cmd_showport_what =
6324         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6325                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6326 cmdline_parse_token_num_t cmd_showport_portnum =
6327         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6328
6329 cmdline_parse_inst_t cmd_showport = {
6330         .f = cmd_showport_parsed,
6331         .data = NULL,
6332         .help_str = "show|clear port "
6333                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6334                 "<port_id>",
6335         .tokens = {
6336                 (void *)&cmd_showport_show,
6337                 (void *)&cmd_showport_port,
6338                 (void *)&cmd_showport_what,
6339                 (void *)&cmd_showport_portnum,
6340                 NULL,
6341         },
6342 };
6343
6344 /* *** SHOW QUEUE INFO *** */
6345 struct cmd_showqueue_result {
6346         cmdline_fixed_string_t show;
6347         cmdline_fixed_string_t type;
6348         cmdline_fixed_string_t what;
6349         uint8_t portnum;
6350         uint16_t queuenum;
6351 };
6352
6353 static void
6354 cmd_showqueue_parsed(void *parsed_result,
6355         __attribute__((unused)) struct cmdline *cl,
6356         __attribute__((unused)) void *data)
6357 {
6358         struct cmd_showqueue_result *res = parsed_result;
6359
6360         if (!strcmp(res->type, "rxq"))
6361                 rx_queue_infos_display(res->portnum, res->queuenum);
6362         else if (!strcmp(res->type, "txq"))
6363                 tx_queue_infos_display(res->portnum, res->queuenum);
6364 }
6365
6366 cmdline_parse_token_string_t cmd_showqueue_show =
6367         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6368 cmdline_parse_token_string_t cmd_showqueue_type =
6369         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6370 cmdline_parse_token_string_t cmd_showqueue_what =
6371         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6372 cmdline_parse_token_num_t cmd_showqueue_portnum =
6373         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6374 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6375         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6376
6377 cmdline_parse_inst_t cmd_showqueue = {
6378         .f = cmd_showqueue_parsed,
6379         .data = NULL,
6380         .help_str = "show rxq|txq info <port_id> <queue_id>",
6381         .tokens = {
6382                 (void *)&cmd_showqueue_show,
6383                 (void *)&cmd_showqueue_type,
6384                 (void *)&cmd_showqueue_what,
6385                 (void *)&cmd_showqueue_portnum,
6386                 (void *)&cmd_showqueue_queuenum,
6387                 NULL,
6388         },
6389 };
6390
6391 /* *** READ PORT REGISTER *** */
6392 struct cmd_read_reg_result {
6393         cmdline_fixed_string_t read;
6394         cmdline_fixed_string_t reg;
6395         uint8_t port_id;
6396         uint32_t reg_off;
6397 };
6398
6399 static void
6400 cmd_read_reg_parsed(void *parsed_result,
6401                     __attribute__((unused)) struct cmdline *cl,
6402                     __attribute__((unused)) void *data)
6403 {
6404         struct cmd_read_reg_result *res = parsed_result;
6405         port_reg_display(res->port_id, res->reg_off);
6406 }
6407
6408 cmdline_parse_token_string_t cmd_read_reg_read =
6409         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6410 cmdline_parse_token_string_t cmd_read_reg_reg =
6411         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6412 cmdline_parse_token_num_t cmd_read_reg_port_id =
6413         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6414 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6415         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6416
6417 cmdline_parse_inst_t cmd_read_reg = {
6418         .f = cmd_read_reg_parsed,
6419         .data = NULL,
6420         .help_str = "read reg <port_id> <reg_off>",
6421         .tokens = {
6422                 (void *)&cmd_read_reg_read,
6423                 (void *)&cmd_read_reg_reg,
6424                 (void *)&cmd_read_reg_port_id,
6425                 (void *)&cmd_read_reg_reg_off,
6426                 NULL,
6427         },
6428 };
6429
6430 /* *** READ PORT REGISTER BIT FIELD *** */
6431 struct cmd_read_reg_bit_field_result {
6432         cmdline_fixed_string_t read;
6433         cmdline_fixed_string_t regfield;
6434         uint8_t port_id;
6435         uint32_t reg_off;
6436         uint8_t bit1_pos;
6437         uint8_t bit2_pos;
6438 };
6439
6440 static void
6441 cmd_read_reg_bit_field_parsed(void *parsed_result,
6442                               __attribute__((unused)) struct cmdline *cl,
6443                               __attribute__((unused)) void *data)
6444 {
6445         struct cmd_read_reg_bit_field_result *res = parsed_result;
6446         port_reg_bit_field_display(res->port_id, res->reg_off,
6447                                    res->bit1_pos, res->bit2_pos);
6448 }
6449
6450 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6451         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6452                                  "read");
6453 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6454         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6455                                  regfield, "regfield");
6456 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6457         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6458                               UINT8);
6459 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6460         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6461                               UINT32);
6462 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6463         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6464                               UINT8);
6465 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6466         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6467                               UINT8);
6468
6469 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6470         .f = cmd_read_reg_bit_field_parsed,
6471         .data = NULL,
6472         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6473         "Read register bit field between bit_x and bit_y included",
6474         .tokens = {
6475                 (void *)&cmd_read_reg_bit_field_read,
6476                 (void *)&cmd_read_reg_bit_field_regfield,
6477                 (void *)&cmd_read_reg_bit_field_port_id,
6478                 (void *)&cmd_read_reg_bit_field_reg_off,
6479                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6480                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6481                 NULL,
6482         },
6483 };
6484
6485 /* *** READ PORT REGISTER BIT *** */
6486 struct cmd_read_reg_bit_result {
6487         cmdline_fixed_string_t read;
6488         cmdline_fixed_string_t regbit;
6489         uint8_t port_id;
6490         uint32_t reg_off;
6491         uint8_t bit_pos;
6492 };
6493
6494 static void
6495 cmd_read_reg_bit_parsed(void *parsed_result,
6496                         __attribute__((unused)) struct cmdline *cl,
6497                         __attribute__((unused)) void *data)
6498 {
6499         struct cmd_read_reg_bit_result *res = parsed_result;
6500         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6501 }
6502
6503 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6504         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6505 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6506         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6507                                  regbit, "regbit");
6508 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6509         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6510 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6511         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6512 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6513         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6514
6515 cmdline_parse_inst_t cmd_read_reg_bit = {
6516         .f = cmd_read_reg_bit_parsed,
6517         .data = NULL,
6518         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6519         .tokens = {
6520                 (void *)&cmd_read_reg_bit_read,
6521                 (void *)&cmd_read_reg_bit_regbit,
6522                 (void *)&cmd_read_reg_bit_port_id,
6523                 (void *)&cmd_read_reg_bit_reg_off,
6524                 (void *)&cmd_read_reg_bit_bit_pos,
6525                 NULL,
6526         },
6527 };
6528
6529 /* *** WRITE PORT REGISTER *** */
6530 struct cmd_write_reg_result {
6531         cmdline_fixed_string_t write;
6532         cmdline_fixed_string_t reg;
6533         uint8_t port_id;
6534         uint32_t reg_off;
6535         uint32_t value;
6536 };
6537
6538 static void
6539 cmd_write_reg_parsed(void *parsed_result,
6540                      __attribute__((unused)) struct cmdline *cl,
6541                      __attribute__((unused)) void *data)
6542 {
6543         struct cmd_write_reg_result *res = parsed_result;
6544         port_reg_set(res->port_id, res->reg_off, res->value);
6545 }
6546
6547 cmdline_parse_token_string_t cmd_write_reg_write =
6548         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6549 cmdline_parse_token_string_t cmd_write_reg_reg =
6550         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6551 cmdline_parse_token_num_t cmd_write_reg_port_id =
6552         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6553 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6554         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6555 cmdline_parse_token_num_t cmd_write_reg_value =
6556         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6557
6558 cmdline_parse_inst_t cmd_write_reg = {
6559         .f = cmd_write_reg_parsed,
6560         .data = NULL,
6561         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6562         .tokens = {
6563                 (void *)&cmd_write_reg_write,
6564                 (void *)&cmd_write_reg_reg,
6565                 (void *)&cmd_write_reg_port_id,
6566                 (void *)&cmd_write_reg_reg_off,
6567                 (void *)&cmd_write_reg_value,
6568                 NULL,
6569         },
6570 };
6571
6572 /* *** WRITE PORT REGISTER BIT FIELD *** */
6573 struct cmd_write_reg_bit_field_result {
6574         cmdline_fixed_string_t write;
6575         cmdline_fixed_string_t regfield;
6576         uint8_t port_id;
6577         uint32_t reg_off;
6578         uint8_t bit1_pos;
6579         uint8_t bit2_pos;
6580         uint32_t value;
6581 };
6582
6583 static void
6584 cmd_write_reg_bit_field_parsed(void *parsed_result,
6585                                __attribute__((unused)) struct cmdline *cl,
6586                                __attribute__((unused)) void *data)
6587 {
6588         struct cmd_write_reg_bit_field_result *res = parsed_result;
6589         port_reg_bit_field_set(res->port_id, res->reg_off,
6590                           res->bit1_pos, res->bit2_pos, res->value);
6591 }
6592
6593 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6594         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6595                                  "write");
6596 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6597         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6598                                  regfield, "regfield");
6599 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6600         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6601                               UINT8);
6602 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6603         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6604                               UINT32);
6605 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6606         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6607                               UINT8);
6608 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6609         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6610                               UINT8);
6611 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6612         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6613                               UINT32);
6614
6615 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6616         .f = cmd_write_reg_bit_field_parsed,
6617         .data = NULL,
6618         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6619                 "<reg_value>: "
6620                 "Set register bit field between bit_x and bit_y included",
6621         .tokens = {
6622                 (void *)&cmd_write_reg_bit_field_write,
6623                 (void *)&cmd_write_reg_bit_field_regfield,
6624                 (void *)&cmd_write_reg_bit_field_port_id,
6625                 (void *)&cmd_write_reg_bit_field_reg_off,
6626                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6627                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6628                 (void *)&cmd_write_reg_bit_field_value,
6629                 NULL,
6630         },
6631 };
6632
6633 /* *** WRITE PORT REGISTER BIT *** */
6634 struct cmd_write_reg_bit_result {
6635         cmdline_fixed_string_t write;
6636         cmdline_fixed_string_t regbit;
6637         uint8_t port_id;
6638         uint32_t reg_off;
6639         uint8_t bit_pos;
6640         uint8_t value;
6641 };
6642
6643 static void
6644 cmd_write_reg_bit_parsed(void *parsed_result,
6645                          __attribute__((unused)) struct cmdline *cl,
6646                          __attribute__((unused)) void *data)
6647 {
6648         struct cmd_write_reg_bit_result *res = parsed_result;
6649         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6650 }
6651
6652 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6653         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6654                                  "write");
6655 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6656         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6657                                  regbit, "regbit");
6658 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6659         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6660 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6661         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6662 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6663         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6664 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6665         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6666
6667 cmdline_parse_inst_t cmd_write_reg_bit = {
6668         .f = cmd_write_reg_bit_parsed,
6669         .data = NULL,
6670         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6671                 "0 <= bit_x <= 31",
6672         .tokens = {
6673                 (void *)&cmd_write_reg_bit_write,
6674                 (void *)&cmd_write_reg_bit_regbit,
6675                 (void *)&cmd_write_reg_bit_port_id,
6676                 (void *)&cmd_write_reg_bit_reg_off,
6677                 (void *)&cmd_write_reg_bit_bit_pos,
6678                 (void *)&cmd_write_reg_bit_value,
6679                 NULL,
6680         },
6681 };
6682
6683 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6684 struct cmd_read_rxd_txd_result {
6685         cmdline_fixed_string_t read;
6686         cmdline_fixed_string_t rxd_txd;
6687         uint8_t port_id;
6688         uint16_t queue_id;
6689         uint16_t desc_id;
6690 };
6691
6692 static void
6693 cmd_read_rxd_txd_parsed(void *parsed_result,
6694                         __attribute__((unused)) struct cmdline *cl,
6695                         __attribute__((unused)) void *data)
6696 {
6697         struct cmd_read_rxd_txd_result *res = parsed_result;
6698
6699         if (!strcmp(res->rxd_txd, "rxd"))
6700                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6701         else if (!strcmp(res->rxd_txd, "txd"))
6702                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6703 }
6704
6705 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6706         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6707 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6708         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6709                                  "rxd#txd");
6710 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6711         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6712 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6713         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6714 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6715         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6716
6717 cmdline_parse_inst_t cmd_read_rxd_txd = {
6718         .f = cmd_read_rxd_txd_parsed,
6719         .data = NULL,
6720         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6721         .tokens = {
6722                 (void *)&cmd_read_rxd_txd_read,
6723                 (void *)&cmd_read_rxd_txd_rxd_txd,
6724                 (void *)&cmd_read_rxd_txd_port_id,
6725                 (void *)&cmd_read_rxd_txd_queue_id,
6726                 (void *)&cmd_read_rxd_txd_desc_id,
6727                 NULL,
6728         },
6729 };
6730
6731 /* *** QUIT *** */
6732 struct cmd_quit_result {
6733         cmdline_fixed_string_t quit;
6734 };
6735
6736 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6737                             struct cmdline *cl,
6738                             __attribute__((unused)) void *data)
6739 {
6740         pmd_test_exit();
6741         cmdline_quit(cl);
6742 }
6743
6744 cmdline_parse_token_string_t cmd_quit_quit =
6745         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6746
6747 cmdline_parse_inst_t cmd_quit = {
6748         .f = cmd_quit_parsed,
6749         .data = NULL,
6750         .help_str = "quit: Exit application",
6751         .tokens = {
6752                 (void *)&cmd_quit_quit,
6753                 NULL,
6754         },
6755 };
6756
6757 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6758 struct cmd_mac_addr_result {
6759         cmdline_fixed_string_t mac_addr_cmd;
6760         cmdline_fixed_string_t what;
6761         uint8_t port_num;
6762         struct ether_addr address;
6763 };
6764
6765 static void cmd_mac_addr_parsed(void *parsed_result,
6766                 __attribute__((unused)) struct cmdline *cl,
6767                 __attribute__((unused)) void *data)
6768 {
6769         struct cmd_mac_addr_result *res = parsed_result;
6770         int ret;
6771
6772         if (strcmp(res->what, "add") == 0)
6773                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6774         else if (strcmp(res->what, "set") == 0)
6775                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6776                                                        &res->address);
6777         else
6778                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6779
6780         /* check the return value and print it if is < 0 */
6781         if(ret < 0)
6782                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6783
6784 }
6785
6786 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6787         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6788                                 "mac_addr");
6789 cmdline_parse_token_string_t cmd_mac_addr_what =
6790         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6791                                 "add#remove#set");
6792 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6793                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6794 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6795                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6796
6797 cmdline_parse_inst_t cmd_mac_addr = {
6798         .f = cmd_mac_addr_parsed,
6799         .data = (void *)0,
6800         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6801                         "Add/Remove/Set MAC address on port_id",
6802         .tokens = {
6803                 (void *)&cmd_mac_addr_cmd,
6804                 (void *)&cmd_mac_addr_what,
6805                 (void *)&cmd_mac_addr_portnum,
6806                 (void *)&cmd_mac_addr_addr,
6807                 NULL,
6808         },
6809 };
6810
6811
6812 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6813 struct cmd_set_qmap_result {
6814         cmdline_fixed_string_t set;
6815         cmdline_fixed_string_t qmap;
6816         cmdline_fixed_string_t what;
6817         uint8_t port_id;
6818         uint16_t queue_id;
6819         uint8_t map_value;
6820 };
6821
6822 static void
6823 cmd_set_qmap_parsed(void *parsed_result,
6824                        __attribute__((unused)) struct cmdline *cl,
6825                        __attribute__((unused)) void *data)
6826 {
6827         struct cmd_set_qmap_result *res = parsed_result;
6828         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6829
6830         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6831 }
6832
6833 cmdline_parse_token_string_t cmd_setqmap_set =
6834         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6835                                  set, "set");
6836 cmdline_parse_token_string_t cmd_setqmap_qmap =
6837         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6838                                  qmap, "stat_qmap");
6839 cmdline_parse_token_string_t cmd_setqmap_what =
6840         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6841                                  what, "tx#rx");
6842 cmdline_parse_token_num_t cmd_setqmap_portid =
6843         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6844                               port_id, UINT8);
6845 cmdline_parse_token_num_t cmd_setqmap_queueid =
6846         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6847                               queue_id, UINT16);
6848 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6849         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6850                               map_value, UINT8);
6851
6852 cmdline_parse_inst_t cmd_set_qmap = {
6853         .f = cmd_set_qmap_parsed,
6854         .data = NULL,
6855         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6856                 "Set statistics mapping value on tx|rx queue_id of port_id",
6857         .tokens = {
6858                 (void *)&cmd_setqmap_set,
6859                 (void *)&cmd_setqmap_qmap,
6860                 (void *)&cmd_setqmap_what,
6861                 (void *)&cmd_setqmap_portid,
6862                 (void *)&cmd_setqmap_queueid,
6863                 (void *)&cmd_setqmap_mapvalue,
6864                 NULL,
6865         },
6866 };
6867
6868 /* *** CONFIGURE UNICAST HASH TABLE *** */
6869 struct cmd_set_uc_hash_table {
6870         cmdline_fixed_string_t set;
6871         cmdline_fixed_string_t port;
6872         uint8_t port_id;
6873         cmdline_fixed_string_t what;
6874         struct ether_addr address;
6875         cmdline_fixed_string_t mode;
6876 };
6877
6878 static void
6879 cmd_set_uc_hash_parsed(void *parsed_result,
6880                        __attribute__((unused)) struct cmdline *cl,
6881                        __attribute__((unused)) void *data)
6882 {
6883         int ret=0;
6884         struct cmd_set_uc_hash_table *res = parsed_result;
6885
6886         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6887
6888         if (strcmp(res->what, "uta") == 0)
6889                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6890                                                 &res->address,(uint8_t)is_on);
6891         if (ret < 0)
6892                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6893
6894 }
6895
6896 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6897         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6898                                  set, "set");
6899 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6900         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6901                                  port, "port");
6902 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6903         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6904                               port_id, UINT8);
6905 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6906         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6907                                  what, "uta");
6908 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6909         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6910                                 address);
6911 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6912         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6913                                  mode, "on#off");
6914
6915 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6916         .f = cmd_set_uc_hash_parsed,
6917         .data = NULL,
6918         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6919         .tokens = {
6920                 (void *)&cmd_set_uc_hash_set,
6921                 (void *)&cmd_set_uc_hash_port,
6922                 (void *)&cmd_set_uc_hash_portid,
6923                 (void *)&cmd_set_uc_hash_what,
6924                 (void *)&cmd_set_uc_hash_mac,
6925                 (void *)&cmd_set_uc_hash_mode,
6926                 NULL,
6927         },
6928 };
6929
6930 struct cmd_set_uc_all_hash_table {
6931         cmdline_fixed_string_t set;
6932         cmdline_fixed_string_t port;
6933         uint8_t port_id;
6934         cmdline_fixed_string_t what;
6935         cmdline_fixed_string_t value;
6936         cmdline_fixed_string_t mode;
6937 };
6938
6939 static void
6940 cmd_set_uc_all_hash_parsed(void *parsed_result,
6941                        __attribute__((unused)) struct cmdline *cl,
6942                        __attribute__((unused)) void *data)
6943 {
6944         int ret=0;
6945         struct cmd_set_uc_all_hash_table *res = parsed_result;
6946
6947         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6948
6949         if ((strcmp(res->what, "uta") == 0) &&
6950                 (strcmp(res->value, "all") == 0))
6951                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6952         if (ret < 0)
6953                 printf("bad unicast hash table parameter,"
6954                         "return code = %d \n", ret);
6955 }
6956
6957 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6958         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6959                                  set, "set");
6960 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6961         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6962                                  port, "port");
6963 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6964         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6965                               port_id, UINT8);
6966 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6967         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6968                                  what, "uta");
6969 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6970         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6971                                 value,"all");
6972 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6973         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6974                                  mode, "on#off");
6975
6976 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6977         .f = cmd_set_uc_all_hash_parsed,
6978         .data = NULL,
6979         .help_str = "set port <port_id> uta all on|off",
6980         .tokens = {
6981                 (void *)&cmd_set_uc_all_hash_set,
6982                 (void *)&cmd_set_uc_all_hash_port,
6983                 (void *)&cmd_set_uc_all_hash_portid,
6984                 (void *)&cmd_set_uc_all_hash_what,
6985                 (void *)&cmd_set_uc_all_hash_value,
6986                 (void *)&cmd_set_uc_all_hash_mode,
6987                 NULL,
6988         },
6989 };
6990
6991 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6992 struct cmd_set_vf_macvlan_filter {
6993         cmdline_fixed_string_t set;
6994         cmdline_fixed_string_t port;
6995         uint8_t port_id;
6996         cmdline_fixed_string_t vf;
6997         uint8_t vf_id;
6998         struct ether_addr address;
6999         cmdline_fixed_string_t filter_type;
7000         cmdline_fixed_string_t mode;
7001 };
7002
7003 static void
7004 cmd_set_vf_macvlan_parsed(void *parsed_result,
7005                        __attribute__((unused)) struct cmdline *cl,
7006                        __attribute__((unused)) void *data)
7007 {
7008         int is_on, ret = 0;
7009         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7010         struct rte_eth_mac_filter filter;
7011
7012         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7013
7014         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7015
7016         /* set VF MAC filter */
7017         filter.is_vf = 1;
7018
7019         /* set VF ID */
7020         filter.dst_id = res->vf_id;
7021
7022         if (!strcmp(res->filter_type, "exact-mac"))
7023                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7024         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7025                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7026         else if (!strcmp(res->filter_type, "hashmac"))
7027                 filter.filter_type = RTE_MAC_HASH_MATCH;
7028         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7029                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7030
7031         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7032
7033         if (is_on)
7034                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7035                                         RTE_ETH_FILTER_MACVLAN,
7036                                         RTE_ETH_FILTER_ADD,
7037                                          &filter);
7038         else
7039                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7040                                         RTE_ETH_FILTER_MACVLAN,
7041                                         RTE_ETH_FILTER_DELETE,
7042                                         &filter);
7043
7044         if (ret < 0)
7045                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7046
7047 }
7048
7049 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7050         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7051                                  set, "set");
7052 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7053         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7054                                  port, "port");
7055 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7056         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7057                               port_id, UINT8);
7058 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7059         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7060                                  vf, "vf");
7061 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7062         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7063                                 vf_id, UINT8);
7064 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7065         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7066                                 address);
7067 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7068         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7069                                 filter_type, "exact-mac#exact-mac-vlan"
7070                                 "#hashmac#hashmac-vlan");
7071 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7072         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7073                                  mode, "on#off");
7074
7075 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7076         .f = cmd_set_vf_macvlan_parsed,
7077         .data = NULL,
7078         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7079                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7080                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7081                 "hash match rule: hash match of MAC and exact match of VLAN",
7082         .tokens = {
7083                 (void *)&cmd_set_vf_macvlan_set,
7084                 (void *)&cmd_set_vf_macvlan_port,
7085                 (void *)&cmd_set_vf_macvlan_portid,
7086                 (void *)&cmd_set_vf_macvlan_vf,
7087                 (void *)&cmd_set_vf_macvlan_vf_id,
7088                 (void *)&cmd_set_vf_macvlan_mac,
7089                 (void *)&cmd_set_vf_macvlan_filter_type,
7090                 (void *)&cmd_set_vf_macvlan_mode,
7091                 NULL,
7092         },
7093 };
7094
7095 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7096 struct cmd_set_vf_traffic {
7097         cmdline_fixed_string_t set;
7098         cmdline_fixed_string_t port;
7099         uint8_t port_id;
7100         cmdline_fixed_string_t vf;
7101         uint8_t vf_id;
7102         cmdline_fixed_string_t what;
7103         cmdline_fixed_string_t mode;
7104 };
7105
7106 static void
7107 cmd_set_vf_traffic_parsed(void *parsed_result,
7108                        __attribute__((unused)) struct cmdline *cl,
7109                        __attribute__((unused)) void *data)
7110 {
7111         struct cmd_set_vf_traffic *res = parsed_result;
7112         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7113         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7114
7115         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7116 }
7117
7118 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7119         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7120                                  set, "set");
7121 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7122         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7123                                  port, "port");
7124 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7125         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7126                               port_id, UINT8);
7127 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7129                                  vf, "vf");
7130 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7131         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7132                               vf_id, UINT8);
7133 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7134         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7135                                  what, "tx#rx");
7136 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7137         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7138                                  mode, "on#off");
7139
7140 cmdline_parse_inst_t cmd_set_vf_traffic = {
7141         .f = cmd_set_vf_traffic_parsed,
7142         .data = NULL,
7143         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7144         .tokens = {
7145                 (void *)&cmd_setvf_traffic_set,
7146                 (void *)&cmd_setvf_traffic_port,
7147                 (void *)&cmd_setvf_traffic_portid,
7148                 (void *)&cmd_setvf_traffic_vf,
7149                 (void *)&cmd_setvf_traffic_vfid,
7150                 (void *)&cmd_setvf_traffic_what,
7151                 (void *)&cmd_setvf_traffic_mode,
7152                 NULL,
7153         },
7154 };
7155
7156 /* *** CONFIGURE VF RECEIVE MODE *** */
7157 struct cmd_set_vf_rxmode {
7158         cmdline_fixed_string_t set;
7159         cmdline_fixed_string_t port;
7160         uint8_t port_id;
7161         cmdline_fixed_string_t vf;
7162         uint8_t vf_id;
7163         cmdline_fixed_string_t what;
7164         cmdline_fixed_string_t mode;
7165         cmdline_fixed_string_t on;
7166 };
7167
7168 static void
7169 cmd_set_vf_rxmode_parsed(void *parsed_result,
7170                        __attribute__((unused)) struct cmdline *cl,
7171                        __attribute__((unused)) void *data)
7172 {
7173         int ret = -ENOTSUP;
7174         uint16_t rx_mode = 0;
7175         struct cmd_set_vf_rxmode *res = parsed_result;
7176
7177         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7178         if (!strcmp(res->what,"rxmode")) {
7179                 if (!strcmp(res->mode, "AUPE"))
7180                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7181                 else if (!strcmp(res->mode, "ROPE"))
7182                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7183                 else if (!strcmp(res->mode, "BAM"))
7184                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7185                 else if (!strncmp(res->mode, "MPE",3))
7186                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7187         }
7188
7189 #ifdef RTE_LIBRTE_IXGBE_PMD
7190         if (ret == -ENOTSUP)
7191                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7192                                                   rx_mode, (uint8_t)is_on);
7193 #endif
7194 #ifdef RTE_LIBRTE_BNXT_PMD
7195         if (ret == -ENOTSUP)
7196                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7197                                                  rx_mode, (uint8_t)is_on);
7198 #endif
7199         if (ret < 0)
7200                 printf("bad VF receive mode parameter, return code = %d \n",
7201                 ret);
7202 }
7203
7204 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7205         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7206                                  set, "set");
7207 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7209                                  port, "port");
7210 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7211         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7212                               port_id, UINT8);
7213 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7215                                  vf, "vf");
7216 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7218                               vf_id, UINT8);
7219 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7221                                  what, "rxmode");
7222 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7223         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7224                                  mode, "AUPE#ROPE#BAM#MPE");
7225 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7226         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7227                                  on, "on#off");
7228
7229 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7230         .f = cmd_set_vf_rxmode_parsed,
7231         .data = NULL,
7232         .help_str = "set port <port_id> vf <vf_id> rxmode "
7233                 "AUPE|ROPE|BAM|MPE on|off",
7234         .tokens = {
7235                 (void *)&cmd_set_vf_rxmode_set,
7236                 (void *)&cmd_set_vf_rxmode_port,
7237                 (void *)&cmd_set_vf_rxmode_portid,
7238                 (void *)&cmd_set_vf_rxmode_vf,
7239                 (void *)&cmd_set_vf_rxmode_vfid,
7240                 (void *)&cmd_set_vf_rxmode_what,
7241                 (void *)&cmd_set_vf_rxmode_mode,
7242                 (void *)&cmd_set_vf_rxmode_on,
7243                 NULL,
7244         },
7245 };
7246
7247 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7248 struct cmd_vf_mac_addr_result {
7249         cmdline_fixed_string_t mac_addr_cmd;
7250         cmdline_fixed_string_t what;
7251         cmdline_fixed_string_t port;
7252         uint8_t port_num;
7253         cmdline_fixed_string_t vf;
7254         uint8_t vf_num;
7255         struct ether_addr address;
7256 };
7257
7258 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7259                 __attribute__((unused)) struct cmdline *cl,
7260                 __attribute__((unused)) void *data)
7261 {
7262         struct cmd_vf_mac_addr_result *res = parsed_result;
7263         int ret = -ENOTSUP;
7264
7265         if (strcmp(res->what, "add") != 0)
7266                 return;
7267
7268 #ifdef RTE_LIBRTE_I40E_PMD
7269         if (ret == -ENOTSUP)
7270                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7271                                                    &res->address);
7272 #endif
7273 #ifdef RTE_LIBRTE_BNXT_PMD
7274         if (ret == -ENOTSUP)
7275                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7276                                                 res->vf_num);
7277 #endif
7278
7279         if(ret < 0)
7280                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7281
7282 }
7283
7284 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7285         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7286                                 mac_addr_cmd,"mac_addr");
7287 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7288         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7289                                 what,"add");
7290 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7291         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7292                                 port,"port");
7293 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7294         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7295                                 port_num, UINT8);
7296 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7297         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7298                                 vf,"vf");
7299 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7300         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7301                                 vf_num, UINT8);
7302 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7303         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7304                                 address);
7305
7306 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7307         .f = cmd_vf_mac_addr_parsed,
7308         .data = (void *)0,
7309         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7310                 "Add MAC address filtering for a VF on port_id",
7311         .tokens = {
7312                 (void *)&cmd_vf_mac_addr_cmd,
7313                 (void *)&cmd_vf_mac_addr_what,
7314                 (void *)&cmd_vf_mac_addr_port,
7315                 (void *)&cmd_vf_mac_addr_portnum,
7316                 (void *)&cmd_vf_mac_addr_vf,
7317                 (void *)&cmd_vf_mac_addr_vfnum,
7318                 (void *)&cmd_vf_mac_addr_addr,
7319                 NULL,
7320         },
7321 };
7322
7323 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7324 struct cmd_vf_rx_vlan_filter {
7325         cmdline_fixed_string_t rx_vlan;
7326         cmdline_fixed_string_t what;
7327         uint16_t vlan_id;
7328         cmdline_fixed_string_t port;
7329         uint8_t port_id;
7330         cmdline_fixed_string_t vf;
7331         uint64_t vf_mask;
7332 };
7333
7334 static void
7335 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7336                           __attribute__((unused)) struct cmdline *cl,
7337                           __attribute__((unused)) void *data)
7338 {
7339         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7340         int ret = -ENOTSUP;
7341
7342         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7343
7344 #ifdef RTE_LIBRTE_IXGBE_PMD
7345         if (ret == -ENOTSUP)
7346                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7347                                 res->vlan_id, res->vf_mask, is_add);
7348 #endif
7349 #ifdef RTE_LIBRTE_I40E_PMD
7350         if (ret == -ENOTSUP)
7351                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7352                                 res->vlan_id, res->vf_mask, is_add);
7353 #endif
7354 #ifdef RTE_LIBRTE_BNXT_PMD
7355         if (ret == -ENOTSUP)
7356                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7357                                 res->vlan_id, res->vf_mask, is_add);
7358 #endif
7359
7360         switch (ret) {
7361         case 0:
7362                 break;
7363         case -EINVAL:
7364                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7365                                 res->vlan_id, res->vf_mask);
7366                 break;
7367         case -ENODEV:
7368                 printf("invalid port_id %d\n", res->port_id);
7369                 break;
7370         case -ENOTSUP:
7371                 printf("function not implemented or supported\n");
7372                 break;
7373         default:
7374                 printf("programming error: (%s)\n", strerror(-ret));
7375         }
7376 }
7377
7378 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7379         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7380                                  rx_vlan, "rx_vlan");
7381 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7382         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7383                                  what, "add#rm");
7384 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7385         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7386                               vlan_id, UINT16);
7387 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7388         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7389                                  port, "port");
7390 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7391         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7392                               port_id, UINT8);
7393 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7394         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7395                                  vf, "vf");
7396 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7397         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7398                               vf_mask, UINT64);
7399
7400 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7401         .f = cmd_vf_rx_vlan_filter_parsed,
7402         .data = NULL,
7403         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7404                 "(vf_mask = hexadecimal VF mask)",
7405         .tokens = {
7406                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7407                 (void *)&cmd_vf_rx_vlan_filter_what,
7408                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7409                 (void *)&cmd_vf_rx_vlan_filter_port,
7410                 (void *)&cmd_vf_rx_vlan_filter_portid,
7411                 (void *)&cmd_vf_rx_vlan_filter_vf,
7412                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7413                 NULL,
7414         },
7415 };
7416
7417 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7418 struct cmd_queue_rate_limit_result {
7419         cmdline_fixed_string_t set;
7420         cmdline_fixed_string_t port;
7421         uint8_t port_num;
7422         cmdline_fixed_string_t queue;
7423         uint8_t queue_num;
7424         cmdline_fixed_string_t rate;
7425         uint16_t rate_num;
7426 };
7427
7428 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7429                 __attribute__((unused)) struct cmdline *cl,
7430                 __attribute__((unused)) void *data)
7431 {
7432         struct cmd_queue_rate_limit_result *res = parsed_result;
7433         int ret = 0;
7434
7435         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7436                 && (strcmp(res->queue, "queue") == 0)
7437                 && (strcmp(res->rate, "rate") == 0))
7438                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7439                                         res->rate_num);
7440         if (ret < 0)
7441                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7442
7443 }
7444
7445 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7446         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7447                                 set, "set");
7448 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7449         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7450                                 port, "port");
7451 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7452         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7453                                 port_num, UINT8);
7454 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7455         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7456                                 queue, "queue");
7457 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7458         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7459                                 queue_num, UINT8);
7460 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7461         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7462                                 rate, "rate");
7463 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7464         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7465                                 rate_num, UINT16);
7466
7467 cmdline_parse_inst_t cmd_queue_rate_limit = {
7468         .f = cmd_queue_rate_limit_parsed,
7469         .data = (void *)0,
7470         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7471                 "Set rate limit for a queue on port_id",
7472         .tokens = {
7473                 (void *)&cmd_queue_rate_limit_set,
7474                 (void *)&cmd_queue_rate_limit_port,
7475                 (void *)&cmd_queue_rate_limit_portnum,
7476                 (void *)&cmd_queue_rate_limit_queue,
7477                 (void *)&cmd_queue_rate_limit_queuenum,
7478                 (void *)&cmd_queue_rate_limit_rate,
7479                 (void *)&cmd_queue_rate_limit_ratenum,
7480                 NULL,
7481         },
7482 };
7483
7484 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7485 struct cmd_vf_rate_limit_result {
7486         cmdline_fixed_string_t set;
7487         cmdline_fixed_string_t port;
7488         uint8_t port_num;
7489         cmdline_fixed_string_t vf;
7490         uint8_t vf_num;
7491         cmdline_fixed_string_t rate;
7492         uint16_t rate_num;
7493         cmdline_fixed_string_t q_msk;
7494         uint64_t q_msk_val;
7495 };
7496
7497 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7498                 __attribute__((unused)) struct cmdline *cl,
7499                 __attribute__((unused)) void *data)
7500 {
7501         struct cmd_vf_rate_limit_result *res = parsed_result;
7502         int ret = 0;
7503
7504         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7505                 && (strcmp(res->vf, "vf") == 0)
7506                 && (strcmp(res->rate, "rate") == 0)
7507                 && (strcmp(res->q_msk, "queue_mask") == 0))
7508                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7509                                         res->rate_num, res->q_msk_val);
7510         if (ret < 0)
7511                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7512
7513 }
7514
7515 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7516         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7517                                 set, "set");
7518 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7519         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7520                                 port, "port");
7521 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7522         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7523                                 port_num, UINT8);
7524 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7525         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7526                                 vf, "vf");
7527 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7528         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7529                                 vf_num, UINT8);
7530 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7531         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7532                                 rate, "rate");
7533 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7534         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7535                                 rate_num, UINT16);
7536 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7537         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7538                                 q_msk, "queue_mask");
7539 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7540         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7541                                 q_msk_val, UINT64);
7542
7543 cmdline_parse_inst_t cmd_vf_rate_limit = {
7544         .f = cmd_vf_rate_limit_parsed,
7545         .data = (void *)0,
7546         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7547                 "queue_mask <queue_mask_value>: "
7548                 "Set rate limit for queues of VF on port_id",
7549         .tokens = {
7550                 (void *)&cmd_vf_rate_limit_set,
7551                 (void *)&cmd_vf_rate_limit_port,
7552                 (void *)&cmd_vf_rate_limit_portnum,
7553                 (void *)&cmd_vf_rate_limit_vf,
7554                 (void *)&cmd_vf_rate_limit_vfnum,
7555                 (void *)&cmd_vf_rate_limit_rate,
7556                 (void *)&cmd_vf_rate_limit_ratenum,
7557                 (void *)&cmd_vf_rate_limit_q_msk,
7558                 (void *)&cmd_vf_rate_limit_q_msk_val,
7559                 NULL,
7560         },
7561 };
7562
7563 /* *** ADD TUNNEL FILTER OF A PORT *** */
7564 struct cmd_tunnel_filter_result {
7565         cmdline_fixed_string_t cmd;
7566         cmdline_fixed_string_t what;
7567         uint8_t port_id;
7568         struct ether_addr outer_mac;
7569         struct ether_addr inner_mac;
7570         cmdline_ipaddr_t ip_value;
7571         uint16_t inner_vlan;
7572         cmdline_fixed_string_t tunnel_type;
7573         cmdline_fixed_string_t filter_type;
7574         uint32_t tenant_id;
7575         uint16_t queue_num;
7576 };
7577
7578 static void
7579 cmd_tunnel_filter_parsed(void *parsed_result,
7580                           __attribute__((unused)) struct cmdline *cl,
7581                           __attribute__((unused)) void *data)
7582 {
7583         struct cmd_tunnel_filter_result *res = parsed_result;
7584         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7585         int ret = 0;
7586
7587         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7588
7589         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7590         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7591         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7592
7593         if (res->ip_value.family == AF_INET) {
7594                 tunnel_filter_conf.ip_addr.ipv4_addr =
7595                         res->ip_value.addr.ipv4.s_addr;
7596                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7597         } else {
7598                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7599                         &(res->ip_value.addr.ipv6),
7600                         sizeof(struct in6_addr));
7601                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7602         }
7603
7604         if (!strcmp(res->filter_type, "imac-ivlan"))
7605                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7606         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7607                 tunnel_filter_conf.filter_type =
7608                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7609         else if (!strcmp(res->filter_type, "imac-tenid"))
7610                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7611         else if (!strcmp(res->filter_type, "imac"))
7612                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7613         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7614                 tunnel_filter_conf.filter_type =
7615                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7616         else if (!strcmp(res->filter_type, "oip"))
7617                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7618         else if (!strcmp(res->filter_type, "iip"))
7619                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7620         else {
7621                 printf("The filter type is not supported");
7622                 return;
7623         }
7624
7625         if (!strcmp(res->tunnel_type, "vxlan"))
7626                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7627         else if (!strcmp(res->tunnel_type, "nvgre"))
7628                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7629         else if (!strcmp(res->tunnel_type, "ipingre"))
7630                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7631         else {
7632                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7633                 return;
7634         }
7635
7636         tunnel_filter_conf.tenant_id = res->tenant_id;
7637         tunnel_filter_conf.queue_id = res->queue_num;
7638         if (!strcmp(res->what, "add"))
7639                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7640                                         RTE_ETH_FILTER_TUNNEL,
7641                                         RTE_ETH_FILTER_ADD,
7642                                         &tunnel_filter_conf);
7643         else
7644                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7645                                         RTE_ETH_FILTER_TUNNEL,
7646                                         RTE_ETH_FILTER_DELETE,
7647                                         &tunnel_filter_conf);
7648         if (ret < 0)
7649                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7650                                 strerror(-ret));
7651
7652 }
7653 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7654         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7655         cmd, "tunnel_filter");
7656 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7657         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7658         what, "add#rm");
7659 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7660         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7661         port_id, UINT8);
7662 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7664         outer_mac);
7665 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7667         inner_mac);
7668 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7669         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7670         inner_vlan, UINT16);
7671 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7672         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7673         ip_value);
7674 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7675         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7676         tunnel_type, "vxlan#nvgre#ipingre");
7677
7678 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7679         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7680         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7681                 "imac#omac-imac-tenid");
7682 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7683         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7684         tenant_id, UINT32);
7685 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7686         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7687         queue_num, UINT16);
7688
7689 cmdline_parse_inst_t cmd_tunnel_filter = {
7690         .f = cmd_tunnel_filter_parsed,
7691         .data = (void *)0,
7692         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7693                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7694                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7695                 "<queue_id>: Add/Rm tunnel filter of a port",
7696         .tokens = {
7697                 (void *)&cmd_tunnel_filter_cmd,
7698                 (void *)&cmd_tunnel_filter_what,
7699                 (void *)&cmd_tunnel_filter_port_id,
7700                 (void *)&cmd_tunnel_filter_outer_mac,
7701                 (void *)&cmd_tunnel_filter_inner_mac,
7702                 (void *)&cmd_tunnel_filter_ip_value,
7703                 (void *)&cmd_tunnel_filter_innner_vlan,
7704                 (void *)&cmd_tunnel_filter_tunnel_type,
7705                 (void *)&cmd_tunnel_filter_filter_type,
7706                 (void *)&cmd_tunnel_filter_tenant_id,
7707                 (void *)&cmd_tunnel_filter_queue_num,
7708                 NULL,
7709         },
7710 };
7711
7712 /* *** CONFIGURE TUNNEL UDP PORT *** */
7713 struct cmd_tunnel_udp_config {
7714         cmdline_fixed_string_t cmd;
7715         cmdline_fixed_string_t what;
7716         uint16_t udp_port;
7717         uint8_t port_id;
7718 };
7719
7720 static void
7721 cmd_tunnel_udp_config_parsed(void *parsed_result,
7722                           __attribute__((unused)) struct cmdline *cl,
7723                           __attribute__((unused)) void *data)
7724 {
7725         struct cmd_tunnel_udp_config *res = parsed_result;
7726         struct rte_eth_udp_tunnel tunnel_udp;
7727         int ret;
7728
7729         tunnel_udp.udp_port = res->udp_port;
7730
7731         if (!strcmp(res->cmd, "rx_vxlan_port"))
7732                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7733
7734         if (!strcmp(res->what, "add"))
7735                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7736                                                       &tunnel_udp);
7737         else
7738                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7739                                                          &tunnel_udp);
7740
7741         if (ret < 0)
7742                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7743 }
7744
7745 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7746         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7747                                 cmd, "rx_vxlan_port");
7748 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7749         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7750                                 what, "add#rm");
7751 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7752         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7753                                 udp_port, UINT16);
7754 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7755         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7756                                 port_id, UINT8);
7757
7758 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7759         .f = cmd_tunnel_udp_config_parsed,
7760         .data = (void *)0,
7761         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7762                 "Add/Remove a tunneling UDP port filter",
7763         .tokens = {
7764                 (void *)&cmd_tunnel_udp_config_cmd,
7765                 (void *)&cmd_tunnel_udp_config_what,
7766                 (void *)&cmd_tunnel_udp_config_udp_port,
7767                 (void *)&cmd_tunnel_udp_config_port_id,
7768                 NULL,
7769         },
7770 };
7771
7772 /* *** GLOBAL CONFIG *** */
7773 struct cmd_global_config_result {
7774         cmdline_fixed_string_t cmd;
7775         uint8_t port_id;
7776         cmdline_fixed_string_t cfg_type;
7777         uint8_t len;
7778 };
7779
7780 static void
7781 cmd_global_config_parsed(void *parsed_result,
7782                          __attribute__((unused)) struct cmdline *cl,
7783                          __attribute__((unused)) void *data)
7784 {
7785         struct cmd_global_config_result *res = parsed_result;
7786         struct rte_eth_global_cfg conf;
7787         int ret;
7788
7789         memset(&conf, 0, sizeof(conf));
7790         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7791         conf.cfg.gre_key_len = res->len;
7792         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7793                                       RTE_ETH_FILTER_SET, &conf);
7794         if (ret != 0)
7795                 printf("Global config error\n");
7796 }
7797
7798 cmdline_parse_token_string_t cmd_global_config_cmd =
7799         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7800                 "global_config");
7801 cmdline_parse_token_num_t cmd_global_config_port_id =
7802         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7803 cmdline_parse_token_string_t cmd_global_config_type =
7804         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7805                 cfg_type, "gre-key-len");
7806 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7807         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7808                 len, UINT8);
7809
7810 cmdline_parse_inst_t cmd_global_config = {
7811         .f = cmd_global_config_parsed,
7812         .data = (void *)NULL,
7813         .help_str = "global_config <port_id> gre-key-len <key_len>",
7814         .tokens = {
7815                 (void *)&cmd_global_config_cmd,
7816                 (void *)&cmd_global_config_port_id,
7817                 (void *)&cmd_global_config_type,
7818                 (void *)&cmd_global_config_gre_key_len,
7819                 NULL,
7820         },
7821 };
7822
7823 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7824 struct cmd_set_mirror_mask_result {
7825         cmdline_fixed_string_t set;
7826         cmdline_fixed_string_t port;
7827         uint8_t port_id;
7828         cmdline_fixed_string_t mirror;
7829         uint8_t rule_id;
7830         cmdline_fixed_string_t what;
7831         cmdline_fixed_string_t value;
7832         cmdline_fixed_string_t dstpool;
7833         uint8_t dstpool_id;
7834         cmdline_fixed_string_t on;
7835 };
7836
7837 cmdline_parse_token_string_t cmd_mirror_mask_set =
7838         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7839                                 set, "set");
7840 cmdline_parse_token_string_t cmd_mirror_mask_port =
7841         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7842                                 port, "port");
7843 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7844         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7845                                 port_id, UINT8);
7846 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7847         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7848                                 mirror, "mirror-rule");
7849 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7850         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7851                                 rule_id, UINT8);
7852 cmdline_parse_token_string_t cmd_mirror_mask_what =
7853         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7854                                 what, "pool-mirror-up#pool-mirror-down"
7855                                       "#vlan-mirror");
7856 cmdline_parse_token_string_t cmd_mirror_mask_value =
7857         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7858                                 value, NULL);
7859 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7860         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7861                                 dstpool, "dst-pool");
7862 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7863         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7864                                 dstpool_id, UINT8);
7865 cmdline_parse_token_string_t cmd_mirror_mask_on =
7866         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7867                                 on, "on#off");
7868
7869 static void
7870 cmd_set_mirror_mask_parsed(void *parsed_result,
7871                        __attribute__((unused)) struct cmdline *cl,
7872                        __attribute__((unused)) void *data)
7873 {
7874         int ret,nb_item,i;
7875         struct cmd_set_mirror_mask_result *res = parsed_result;
7876         struct rte_eth_mirror_conf mr_conf;
7877
7878         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7879
7880         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7881
7882         mr_conf.dst_pool = res->dstpool_id;
7883
7884         if (!strcmp(res->what, "pool-mirror-up")) {
7885                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7886                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7887         } else if (!strcmp(res->what, "pool-mirror-down")) {
7888                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7889                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7890         } else if (!strcmp(res->what, "vlan-mirror")) {
7891                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7892                 nb_item = parse_item_list(res->value, "vlan",
7893                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7894                 if (nb_item <= 0)
7895                         return;
7896
7897                 for (i = 0; i < nb_item; i++) {
7898                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7899                                 printf("Invalid vlan_id: must be < 4096\n");
7900                                 return;
7901                         }
7902
7903                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7904                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7905                 }
7906         }
7907
7908         if (!strcmp(res->on, "on"))
7909                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7910                                                 res->rule_id, 1);
7911         else
7912                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7913                                                 res->rule_id, 0);
7914         if (ret < 0)
7915                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7916 }
7917
7918 cmdline_parse_inst_t cmd_set_mirror_mask = {
7919                 .f = cmd_set_mirror_mask_parsed,
7920                 .data = NULL,
7921                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7922                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7923                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7924                 .tokens = {
7925                         (void *)&cmd_mirror_mask_set,
7926                         (void *)&cmd_mirror_mask_port,
7927                         (void *)&cmd_mirror_mask_portid,
7928                         (void *)&cmd_mirror_mask_mirror,
7929                         (void *)&cmd_mirror_mask_ruleid,
7930                         (void *)&cmd_mirror_mask_what,
7931                         (void *)&cmd_mirror_mask_value,
7932                         (void *)&cmd_mirror_mask_dstpool,
7933                         (void *)&cmd_mirror_mask_poolid,
7934                         (void *)&cmd_mirror_mask_on,
7935                         NULL,
7936                 },
7937 };
7938
7939 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7940 struct cmd_set_mirror_link_result {
7941         cmdline_fixed_string_t set;
7942         cmdline_fixed_string_t port;
7943         uint8_t port_id;
7944         cmdline_fixed_string_t mirror;
7945         uint8_t rule_id;
7946         cmdline_fixed_string_t what;
7947         cmdline_fixed_string_t dstpool;
7948         uint8_t dstpool_id;
7949         cmdline_fixed_string_t on;
7950 };
7951
7952 cmdline_parse_token_string_t cmd_mirror_link_set =
7953         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7954                                  set, "set");
7955 cmdline_parse_token_string_t cmd_mirror_link_port =
7956         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7957                                 port, "port");
7958 cmdline_parse_token_num_t cmd_mirror_link_portid =
7959         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7960                                 port_id, UINT8);
7961 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7962         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7963                                 mirror, "mirror-rule");
7964 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7965         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7966                             rule_id, UINT8);
7967 cmdline_parse_token_string_t cmd_mirror_link_what =
7968         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7969                                 what, "uplink-mirror#downlink-mirror");
7970 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7971         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7972                                 dstpool, "dst-pool");
7973 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7974         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7975                                 dstpool_id, UINT8);
7976 cmdline_parse_token_string_t cmd_mirror_link_on =
7977         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7978                                 on, "on#off");
7979
7980 static void
7981 cmd_set_mirror_link_parsed(void *parsed_result,
7982                        __attribute__((unused)) struct cmdline *cl,
7983                        __attribute__((unused)) void *data)
7984 {
7985         int ret;
7986         struct cmd_set_mirror_link_result *res = parsed_result;
7987         struct rte_eth_mirror_conf mr_conf;
7988
7989         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7990         if (!strcmp(res->what, "uplink-mirror"))
7991                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7992         else
7993                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7994
7995         mr_conf.dst_pool = res->dstpool_id;
7996
7997         if (!strcmp(res->on, "on"))
7998                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7999                                                 res->rule_id, 1);
8000         else
8001                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8002                                                 res->rule_id, 0);
8003
8004         /* check the return value and print it if is < 0 */
8005         if (ret < 0)
8006                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8007
8008 }
8009
8010 cmdline_parse_inst_t cmd_set_mirror_link = {
8011                 .f = cmd_set_mirror_link_parsed,
8012                 .data = NULL,
8013                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8014                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8015                 .tokens = {
8016                         (void *)&cmd_mirror_link_set,
8017                         (void *)&cmd_mirror_link_port,
8018                         (void *)&cmd_mirror_link_portid,
8019                         (void *)&cmd_mirror_link_mirror,
8020                         (void *)&cmd_mirror_link_ruleid,
8021                         (void *)&cmd_mirror_link_what,
8022                         (void *)&cmd_mirror_link_dstpool,
8023                         (void *)&cmd_mirror_link_poolid,
8024                         (void *)&cmd_mirror_link_on,
8025                         NULL,
8026                 },
8027 };
8028
8029 /* *** RESET VM MIRROR RULE *** */
8030 struct cmd_rm_mirror_rule_result {
8031         cmdline_fixed_string_t reset;
8032         cmdline_fixed_string_t port;
8033         uint8_t port_id;
8034         cmdline_fixed_string_t mirror;
8035         uint8_t rule_id;
8036 };
8037
8038 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8039         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8040                                  reset, "reset");
8041 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8042         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8043                                 port, "port");
8044 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8045         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8046                                 port_id, UINT8);
8047 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8048         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8049                                 mirror, "mirror-rule");
8050 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8051         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8052                                 rule_id, UINT8);
8053
8054 static void
8055 cmd_reset_mirror_rule_parsed(void *parsed_result,
8056                        __attribute__((unused)) struct cmdline *cl,
8057                        __attribute__((unused)) void *data)
8058 {
8059         int ret;
8060         struct cmd_set_mirror_link_result *res = parsed_result;
8061         /* check rule_id */
8062         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8063         if(ret < 0)
8064                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8065 }
8066
8067 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8068                 .f = cmd_reset_mirror_rule_parsed,
8069                 .data = NULL,
8070                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8071                 .tokens = {
8072                         (void *)&cmd_rm_mirror_rule_reset,
8073                         (void *)&cmd_rm_mirror_rule_port,
8074                         (void *)&cmd_rm_mirror_rule_portid,
8075                         (void *)&cmd_rm_mirror_rule_mirror,
8076                         (void *)&cmd_rm_mirror_rule_ruleid,
8077                         NULL,
8078                 },
8079 };
8080
8081 /* ******************************************************************************** */
8082
8083 struct cmd_dump_result {
8084         cmdline_fixed_string_t dump;
8085 };
8086
8087 static void
8088 dump_struct_sizes(void)
8089 {
8090 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8091         DUMP_SIZE(struct rte_mbuf);
8092         DUMP_SIZE(struct rte_mempool);
8093         DUMP_SIZE(struct rte_ring);
8094 #undef DUMP_SIZE
8095 }
8096
8097 static void cmd_dump_parsed(void *parsed_result,
8098                             __attribute__((unused)) struct cmdline *cl,
8099                             __attribute__((unused)) void *data)
8100 {
8101         struct cmd_dump_result *res = parsed_result;
8102
8103         if (!strcmp(res->dump, "dump_physmem"))
8104                 rte_dump_physmem_layout(stdout);
8105         else if (!strcmp(res->dump, "dump_memzone"))
8106                 rte_memzone_dump(stdout);
8107         else if (!strcmp(res->dump, "dump_struct_sizes"))
8108                 dump_struct_sizes();
8109         else if (!strcmp(res->dump, "dump_ring"))
8110                 rte_ring_list_dump(stdout);
8111         else if (!strcmp(res->dump, "dump_mempool"))
8112                 rte_mempool_list_dump(stdout);
8113         else if (!strcmp(res->dump, "dump_devargs"))
8114                 rte_eal_devargs_dump(stdout);
8115         else if (!strcmp(res->dump, "dump_log_types"))
8116                 rte_log_dump(stdout);
8117 }
8118
8119 cmdline_parse_token_string_t cmd_dump_dump =
8120         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8121                 "dump_physmem#"
8122                 "dump_memzone#"
8123                 "dump_struct_sizes#"
8124                 "dump_ring#"
8125                 "dump_mempool#"
8126                 "dump_devargs#"
8127                 "dump_log_types");
8128
8129 cmdline_parse_inst_t cmd_dump = {
8130         .f = cmd_dump_parsed,  /* function to call */
8131         .data = NULL,      /* 2nd arg of func */
8132         .help_str = "Dump status",
8133         .tokens = {        /* token list, NULL terminated */
8134                 (void *)&cmd_dump_dump,
8135                 NULL,
8136         },
8137 };
8138
8139 /* ******************************************************************************** */
8140
8141 struct cmd_dump_one_result {
8142         cmdline_fixed_string_t dump;
8143         cmdline_fixed_string_t name;
8144 };
8145
8146 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8147                                 __attribute__((unused)) void *data)
8148 {
8149         struct cmd_dump_one_result *res = parsed_result;
8150
8151         if (!strcmp(res->dump, "dump_ring")) {
8152                 struct rte_ring *r;
8153                 r = rte_ring_lookup(res->name);
8154                 if (r == NULL) {
8155                         cmdline_printf(cl, "Cannot find ring\n");
8156                         return;
8157                 }
8158                 rte_ring_dump(stdout, r);
8159         } else if (!strcmp(res->dump, "dump_mempool")) {
8160                 struct rte_mempool *mp;
8161                 mp = rte_mempool_lookup(res->name);
8162                 if (mp == NULL) {
8163                         cmdline_printf(cl, "Cannot find mempool\n");
8164                         return;
8165                 }
8166                 rte_mempool_dump(stdout, mp);
8167         }
8168 }
8169
8170 cmdline_parse_token_string_t cmd_dump_one_dump =
8171         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8172                                  "dump_ring#dump_mempool");
8173
8174 cmdline_parse_token_string_t cmd_dump_one_name =
8175         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8176
8177 cmdline_parse_inst_t cmd_dump_one = {
8178         .f = cmd_dump_one_parsed,  /* function to call */
8179         .data = NULL,      /* 2nd arg of func */
8180         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8181         .tokens = {        /* token list, NULL terminated */
8182                 (void *)&cmd_dump_one_dump,
8183                 (void *)&cmd_dump_one_name,
8184                 NULL,
8185         },
8186 };
8187
8188 /* *** Add/Del syn filter *** */
8189 struct cmd_syn_filter_result {
8190         cmdline_fixed_string_t filter;
8191         uint8_t port_id;
8192         cmdline_fixed_string_t ops;
8193         cmdline_fixed_string_t priority;
8194         cmdline_fixed_string_t high;
8195         cmdline_fixed_string_t queue;
8196         uint16_t queue_id;
8197 };
8198
8199 static void
8200 cmd_syn_filter_parsed(void *parsed_result,
8201                         __attribute__((unused)) struct cmdline *cl,
8202                         __attribute__((unused)) void *data)
8203 {
8204         struct cmd_syn_filter_result *res = parsed_result;
8205         struct rte_eth_syn_filter syn_filter;
8206         int ret = 0;
8207
8208         ret = rte_eth_dev_filter_supported(res->port_id,
8209                                         RTE_ETH_FILTER_SYN);
8210         if (ret < 0) {
8211                 printf("syn filter is not supported on port %u.\n",
8212                                 res->port_id);
8213                 return;
8214         }
8215
8216         memset(&syn_filter, 0, sizeof(syn_filter));
8217
8218         if (!strcmp(res->ops, "add")) {
8219                 if (!strcmp(res->high, "high"))
8220                         syn_filter.hig_pri = 1;
8221                 else
8222                         syn_filter.hig_pri = 0;
8223
8224                 syn_filter.queue = res->queue_id;
8225                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8226                                                 RTE_ETH_FILTER_SYN,
8227                                                 RTE_ETH_FILTER_ADD,
8228                                                 &syn_filter);
8229         } else
8230                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8231                                                 RTE_ETH_FILTER_SYN,
8232                                                 RTE_ETH_FILTER_DELETE,
8233                                                 &syn_filter);
8234
8235         if (ret < 0)
8236                 printf("syn filter programming error: (%s)\n",
8237                                 strerror(-ret));
8238 }
8239
8240 cmdline_parse_token_string_t cmd_syn_filter_filter =
8241         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8242         filter, "syn_filter");
8243 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8244         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8245         port_id, UINT8);
8246 cmdline_parse_token_string_t cmd_syn_filter_ops =
8247         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8248         ops, "add#del");
8249 cmdline_parse_token_string_t cmd_syn_filter_priority =
8250         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8251                                 priority, "priority");
8252 cmdline_parse_token_string_t cmd_syn_filter_high =
8253         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8254                                 high, "high#low");
8255 cmdline_parse_token_string_t cmd_syn_filter_queue =
8256         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8257                                 queue, "queue");
8258 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8259         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8260                                 queue_id, UINT16);
8261
8262 cmdline_parse_inst_t cmd_syn_filter = {
8263         .f = cmd_syn_filter_parsed,
8264         .data = NULL,
8265         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8266                 "<queue_id>: Add/Delete syn filter",
8267         .tokens = {
8268                 (void *)&cmd_syn_filter_filter,
8269                 (void *)&cmd_syn_filter_port_id,
8270                 (void *)&cmd_syn_filter_ops,
8271                 (void *)&cmd_syn_filter_priority,
8272                 (void *)&cmd_syn_filter_high,
8273                 (void *)&cmd_syn_filter_queue,
8274                 (void *)&cmd_syn_filter_queue_id,
8275                 NULL,
8276         },
8277 };
8278
8279 /* *** ADD/REMOVE A 2tuple FILTER *** */
8280 struct cmd_2tuple_filter_result {
8281         cmdline_fixed_string_t filter;
8282         uint8_t  port_id;
8283         cmdline_fixed_string_t ops;
8284         cmdline_fixed_string_t dst_port;
8285         uint16_t dst_port_value;
8286         cmdline_fixed_string_t protocol;
8287         uint8_t protocol_value;
8288         cmdline_fixed_string_t mask;
8289         uint8_t  mask_value;
8290         cmdline_fixed_string_t tcp_flags;
8291         uint8_t tcp_flags_value;
8292         cmdline_fixed_string_t priority;
8293         uint8_t  priority_value;
8294         cmdline_fixed_string_t queue;
8295         uint16_t  queue_id;
8296 };
8297
8298 static void
8299 cmd_2tuple_filter_parsed(void *parsed_result,
8300                         __attribute__((unused)) struct cmdline *cl,
8301                         __attribute__((unused)) void *data)
8302 {
8303         struct rte_eth_ntuple_filter filter;
8304         struct cmd_2tuple_filter_result *res = parsed_result;
8305         int ret = 0;
8306
8307         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8308         if (ret < 0) {
8309                 printf("ntuple filter is not supported on port %u.\n",
8310                         res->port_id);
8311                 return;
8312         }
8313
8314         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8315
8316         filter.flags = RTE_2TUPLE_FLAGS;
8317         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8318         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8319         filter.proto = res->protocol_value;
8320         filter.priority = res->priority_value;
8321         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8322                 printf("nonzero tcp_flags is only meaningful"
8323                         " when protocol is TCP.\n");
8324                 return;
8325         }
8326         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8327                 printf("invalid TCP flags.\n");
8328                 return;
8329         }
8330
8331         if (res->tcp_flags_value != 0) {
8332                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8333                 filter.tcp_flags = res->tcp_flags_value;
8334         }
8335
8336         /* need convert to big endian. */
8337         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8338         filter.queue = res->queue_id;
8339
8340         if (!strcmp(res->ops, "add"))
8341                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8342                                 RTE_ETH_FILTER_NTUPLE,
8343                                 RTE_ETH_FILTER_ADD,
8344                                 &filter);
8345         else
8346                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8347                                 RTE_ETH_FILTER_NTUPLE,
8348                                 RTE_ETH_FILTER_DELETE,
8349                                 &filter);
8350         if (ret < 0)
8351                 printf("2tuple filter programming error: (%s)\n",
8352                         strerror(-ret));
8353
8354 }
8355
8356 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8357         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8358                                  filter, "2tuple_filter");
8359 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8360         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8361                                 port_id, UINT8);
8362 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8363         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8364                                  ops, "add#del");
8365 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8366         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8367                                 dst_port, "dst_port");
8368 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8369         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8370                                 dst_port_value, UINT16);
8371 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8372         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8373                                 protocol, "protocol");
8374 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8375         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8376                                 protocol_value, UINT8);
8377 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8378         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8379                                 mask, "mask");
8380 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8381         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8382                                 mask_value, INT8);
8383 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8384         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8385                                 tcp_flags, "tcp_flags");
8386 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8387         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8388                                 tcp_flags_value, UINT8);
8389 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8390         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8391                                 priority, "priority");
8392 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8393         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8394                                 priority_value, UINT8);
8395 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8396         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8397                                 queue, "queue");
8398 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8399         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8400                                 queue_id, UINT16);
8401
8402 cmdline_parse_inst_t cmd_2tuple_filter = {
8403         .f = cmd_2tuple_filter_parsed,
8404         .data = NULL,
8405         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8406                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8407                 "<queue_id>: Add a 2tuple filter",
8408         .tokens = {
8409                 (void *)&cmd_2tuple_filter_filter,
8410                 (void *)&cmd_2tuple_filter_port_id,
8411                 (void *)&cmd_2tuple_filter_ops,
8412                 (void *)&cmd_2tuple_filter_dst_port,
8413                 (void *)&cmd_2tuple_filter_dst_port_value,
8414                 (void *)&cmd_2tuple_filter_protocol,
8415                 (void *)&cmd_2tuple_filter_protocol_value,
8416                 (void *)&cmd_2tuple_filter_mask,
8417                 (void *)&cmd_2tuple_filter_mask_value,
8418                 (void *)&cmd_2tuple_filter_tcp_flags,
8419                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8420                 (void *)&cmd_2tuple_filter_priority,
8421                 (void *)&cmd_2tuple_filter_priority_value,
8422                 (void *)&cmd_2tuple_filter_queue,
8423                 (void *)&cmd_2tuple_filter_queue_id,
8424                 NULL,
8425         },
8426 };
8427
8428 /* *** ADD/REMOVE A 5tuple FILTER *** */
8429 struct cmd_5tuple_filter_result {
8430         cmdline_fixed_string_t filter;
8431         uint8_t  port_id;
8432         cmdline_fixed_string_t ops;
8433         cmdline_fixed_string_t dst_ip;
8434         cmdline_ipaddr_t dst_ip_value;
8435         cmdline_fixed_string_t src_ip;
8436         cmdline_ipaddr_t src_ip_value;
8437         cmdline_fixed_string_t dst_port;
8438         uint16_t dst_port_value;
8439         cmdline_fixed_string_t src_port;
8440         uint16_t src_port_value;
8441         cmdline_fixed_string_t protocol;
8442         uint8_t protocol_value;
8443         cmdline_fixed_string_t mask;
8444         uint8_t  mask_value;
8445         cmdline_fixed_string_t tcp_flags;
8446         uint8_t tcp_flags_value;
8447         cmdline_fixed_string_t priority;
8448         uint8_t  priority_value;
8449         cmdline_fixed_string_t queue;
8450         uint16_t  queue_id;
8451 };
8452
8453 static void
8454 cmd_5tuple_filter_parsed(void *parsed_result,
8455                         __attribute__((unused)) struct cmdline *cl,
8456                         __attribute__((unused)) void *data)
8457 {
8458         struct rte_eth_ntuple_filter filter;
8459         struct cmd_5tuple_filter_result *res = parsed_result;
8460         int ret = 0;
8461
8462         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8463         if (ret < 0) {
8464                 printf("ntuple filter is not supported on port %u.\n",
8465                         res->port_id);
8466                 return;
8467         }
8468
8469         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8470
8471         filter.flags = RTE_5TUPLE_FLAGS;
8472         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8473         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8474         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8475         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8476         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8477         filter.proto = res->protocol_value;
8478         filter.priority = res->priority_value;
8479         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8480                 printf("nonzero tcp_flags is only meaningful"
8481                         " when protocol is TCP.\n");
8482                 return;
8483         }
8484         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8485                 printf("invalid TCP flags.\n");
8486                 return;
8487         }
8488
8489         if (res->tcp_flags_value != 0) {
8490                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8491                 filter.tcp_flags = res->tcp_flags_value;
8492         }
8493
8494         if (res->dst_ip_value.family == AF_INET)
8495                 /* no need to convert, already big endian. */
8496                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8497         else {
8498                 if (filter.dst_ip_mask == 0) {
8499                         printf("can not support ipv6 involved compare.\n");
8500                         return;
8501                 }
8502                 filter.dst_ip = 0;
8503         }
8504
8505         if (res->src_ip_value.family == AF_INET)
8506                 /* no need to convert, already big endian. */
8507                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8508         else {
8509                 if (filter.src_ip_mask == 0) {
8510                         printf("can not support ipv6 involved compare.\n");
8511                         return;
8512                 }
8513                 filter.src_ip = 0;
8514         }
8515         /* need convert to big endian. */
8516         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8517         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8518         filter.queue = res->queue_id;
8519
8520         if (!strcmp(res->ops, "add"))
8521                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8522                                 RTE_ETH_FILTER_NTUPLE,
8523                                 RTE_ETH_FILTER_ADD,
8524                                 &filter);
8525         else
8526                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8527                                 RTE_ETH_FILTER_NTUPLE,
8528                                 RTE_ETH_FILTER_DELETE,
8529                                 &filter);
8530         if (ret < 0)
8531                 printf("5tuple filter programming error: (%s)\n",
8532                         strerror(-ret));
8533 }
8534
8535 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8536         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8537                                  filter, "5tuple_filter");
8538 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8539         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8540                                 port_id, UINT8);
8541 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8542         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8543                                  ops, "add#del");
8544 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8545         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8546                                 dst_ip, "dst_ip");
8547 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8548         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8549                                 dst_ip_value);
8550 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8551         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8552                                 src_ip, "src_ip");
8553 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8554         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8555                                 src_ip_value);
8556 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8557         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8558                                 dst_port, "dst_port");
8559 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8560         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8561                                 dst_port_value, UINT16);
8562 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8563         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8564                                 src_port, "src_port");
8565 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8566         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8567                                 src_port_value, UINT16);
8568 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8569         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8570                                 protocol, "protocol");
8571 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8572         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8573                                 protocol_value, UINT8);
8574 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8575         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8576                                 mask, "mask");
8577 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8578         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8579                                 mask_value, INT8);
8580 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8581         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8582                                 tcp_flags, "tcp_flags");
8583 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8584         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8585                                 tcp_flags_value, UINT8);
8586 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8587         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8588                                 priority, "priority");
8589 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8590         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8591                                 priority_value, UINT8);
8592 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8593         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8594                                 queue, "queue");
8595 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8596         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8597                                 queue_id, UINT16);
8598
8599 cmdline_parse_inst_t cmd_5tuple_filter = {
8600         .f = cmd_5tuple_filter_parsed,
8601         .data = NULL,
8602         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8603                 "src_ip <value> dst_port <value> src_port <value> "
8604                 "protocol <value>  mask <value> tcp_flags <value> "
8605                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8606         .tokens = {
8607                 (void *)&cmd_5tuple_filter_filter,
8608                 (void *)&cmd_5tuple_filter_port_id,
8609                 (void *)&cmd_5tuple_filter_ops,
8610                 (void *)&cmd_5tuple_filter_dst_ip,
8611                 (void *)&cmd_5tuple_filter_dst_ip_value,
8612                 (void *)&cmd_5tuple_filter_src_ip,
8613                 (void *)&cmd_5tuple_filter_src_ip_value,
8614                 (void *)&cmd_5tuple_filter_dst_port,
8615                 (void *)&cmd_5tuple_filter_dst_port_value,
8616                 (void *)&cmd_5tuple_filter_src_port,
8617                 (void *)&cmd_5tuple_filter_src_port_value,
8618                 (void *)&cmd_5tuple_filter_protocol,
8619                 (void *)&cmd_5tuple_filter_protocol_value,
8620                 (void *)&cmd_5tuple_filter_mask,
8621                 (void *)&cmd_5tuple_filter_mask_value,
8622                 (void *)&cmd_5tuple_filter_tcp_flags,
8623                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8624                 (void *)&cmd_5tuple_filter_priority,
8625                 (void *)&cmd_5tuple_filter_priority_value,
8626                 (void *)&cmd_5tuple_filter_queue,
8627                 (void *)&cmd_5tuple_filter_queue_id,
8628                 NULL,
8629         },
8630 };
8631
8632 /* *** ADD/REMOVE A flex FILTER *** */
8633 struct cmd_flex_filter_result {
8634         cmdline_fixed_string_t filter;
8635         cmdline_fixed_string_t ops;
8636         uint8_t port_id;
8637         cmdline_fixed_string_t len;
8638         uint8_t len_value;
8639         cmdline_fixed_string_t bytes;
8640         cmdline_fixed_string_t bytes_value;
8641         cmdline_fixed_string_t mask;
8642         cmdline_fixed_string_t mask_value;
8643         cmdline_fixed_string_t priority;
8644         uint8_t priority_value;
8645         cmdline_fixed_string_t queue;
8646         uint16_t queue_id;
8647 };
8648
8649 static int xdigit2val(unsigned char c)
8650 {
8651         int val;
8652         if (isdigit(c))
8653                 val = c - '0';
8654         else if (isupper(c))
8655                 val = c - 'A' + 10;
8656         else
8657                 val = c - 'a' + 10;
8658         return val;
8659 }
8660
8661 static void
8662 cmd_flex_filter_parsed(void *parsed_result,
8663                           __attribute__((unused)) struct cmdline *cl,
8664                           __attribute__((unused)) void *data)
8665 {
8666         int ret = 0;
8667         struct rte_eth_flex_filter filter;
8668         struct cmd_flex_filter_result *res = parsed_result;
8669         char *bytes_ptr, *mask_ptr;
8670         uint16_t len, i, j = 0;
8671         char c;
8672         int val;
8673         uint8_t byte = 0;
8674
8675         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8676                 printf("the len exceed the max length 128\n");
8677                 return;
8678         }
8679         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8680         filter.len = res->len_value;
8681         filter.priority = res->priority_value;
8682         filter.queue = res->queue_id;
8683         bytes_ptr = res->bytes_value;
8684         mask_ptr = res->mask_value;
8685
8686          /* translate bytes string to array. */
8687         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8688                 (bytes_ptr[1] == 'X')))
8689                 bytes_ptr += 2;
8690         len = strnlen(bytes_ptr, res->len_value * 2);
8691         if (len == 0 || (len % 8 != 0)) {
8692                 printf("please check len and bytes input\n");
8693                 return;
8694         }
8695         for (i = 0; i < len; i++) {
8696                 c = bytes_ptr[i];
8697                 if (isxdigit(c) == 0) {
8698                         /* invalid characters. */
8699                         printf("invalid input\n");
8700                         return;
8701                 }
8702                 val = xdigit2val(c);
8703                 if (i % 2) {
8704                         byte |= val;
8705                         filter.bytes[j] = byte;
8706                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8707                         j++;
8708                         byte = 0;
8709                 } else
8710                         byte |= val << 4;
8711         }
8712         printf("\n");
8713          /* translate mask string to uint8_t array. */
8714         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8715                 (mask_ptr[1] == 'X')))
8716                 mask_ptr += 2;
8717         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8718         if (len == 0) {
8719                 printf("invalid input\n");
8720                 return;
8721         }
8722         j = 0;
8723         byte = 0;
8724         for (i = 0; i < len; i++) {
8725                 c = mask_ptr[i];
8726                 if (isxdigit(c) == 0) {
8727                         /* invalid characters. */
8728                         printf("invalid input\n");
8729                         return;
8730                 }
8731                 val = xdigit2val(c);
8732                 if (i % 2) {
8733                         byte |= val;
8734                         filter.mask[j] = byte;
8735                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8736                         j++;
8737                         byte = 0;
8738                 } else
8739                         byte |= val << 4;
8740         }
8741         printf("\n");
8742
8743         if (!strcmp(res->ops, "add"))
8744                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8745                                 RTE_ETH_FILTER_FLEXIBLE,
8746                                 RTE_ETH_FILTER_ADD,
8747                                 &filter);
8748         else
8749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8750                                 RTE_ETH_FILTER_FLEXIBLE,
8751                                 RTE_ETH_FILTER_DELETE,
8752                                 &filter);
8753
8754         if (ret < 0)
8755                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8756 }
8757
8758 cmdline_parse_token_string_t cmd_flex_filter_filter =
8759         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8760                                 filter, "flex_filter");
8761 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8762         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8763                                 port_id, UINT8);
8764 cmdline_parse_token_string_t cmd_flex_filter_ops =
8765         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8766                                 ops, "add#del");
8767 cmdline_parse_token_string_t cmd_flex_filter_len =
8768         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8769                                 len, "len");
8770 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8771         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8772                                 len_value, UINT8);
8773 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8774         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8775                                 bytes, "bytes");
8776 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8777         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8778                                 bytes_value, NULL);
8779 cmdline_parse_token_string_t cmd_flex_filter_mask =
8780         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8781                                 mask, "mask");
8782 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8783         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8784                                 mask_value, NULL);
8785 cmdline_parse_token_string_t cmd_flex_filter_priority =
8786         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8787                                 priority, "priority");
8788 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8789         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8790                                 priority_value, UINT8);
8791 cmdline_parse_token_string_t cmd_flex_filter_queue =
8792         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8793                                 queue, "queue");
8794 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8795         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8796                                 queue_id, UINT16);
8797 cmdline_parse_inst_t cmd_flex_filter = {
8798         .f = cmd_flex_filter_parsed,
8799         .data = NULL,
8800         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8801                 "<value> mask <value> priority <value> queue <queue_id>: "
8802                 "Add/Del a flex filter",
8803         .tokens = {
8804                 (void *)&cmd_flex_filter_filter,
8805                 (void *)&cmd_flex_filter_port_id,
8806                 (void *)&cmd_flex_filter_ops,
8807                 (void *)&cmd_flex_filter_len,
8808                 (void *)&cmd_flex_filter_len_value,
8809                 (void *)&cmd_flex_filter_bytes,
8810                 (void *)&cmd_flex_filter_bytes_value,
8811                 (void *)&cmd_flex_filter_mask,
8812                 (void *)&cmd_flex_filter_mask_value,
8813                 (void *)&cmd_flex_filter_priority,
8814                 (void *)&cmd_flex_filter_priority_value,
8815                 (void *)&cmd_flex_filter_queue,
8816                 (void *)&cmd_flex_filter_queue_id,
8817                 NULL,
8818         },
8819 };
8820
8821 /* *** Filters Control *** */
8822
8823 /* *** deal with ethertype filter *** */
8824 struct cmd_ethertype_filter_result {
8825         cmdline_fixed_string_t filter;
8826         uint8_t port_id;
8827         cmdline_fixed_string_t ops;
8828         cmdline_fixed_string_t mac;
8829         struct ether_addr mac_addr;
8830         cmdline_fixed_string_t ethertype;
8831         uint16_t ethertype_value;
8832         cmdline_fixed_string_t drop;
8833         cmdline_fixed_string_t queue;
8834         uint16_t  queue_id;
8835 };
8836
8837 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8838         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8839                                  filter, "ethertype_filter");
8840 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8841         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8842                               port_id, UINT8);
8843 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8844         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8845                                  ops, "add#del");
8846 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8847         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8848                                  mac, "mac_addr#mac_ignr");
8849 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8851                                      mac_addr);
8852 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8853         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8854                                  ethertype, "ethertype");
8855 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8856         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8857                               ethertype_value, UINT16);
8858 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8859         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8860                                  drop, "drop#fwd");
8861 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8862         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8863                                  queue, "queue");
8864 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8865         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8866                               queue_id, UINT16);
8867
8868 static void
8869 cmd_ethertype_filter_parsed(void *parsed_result,
8870                           __attribute__((unused)) struct cmdline *cl,
8871                           __attribute__((unused)) void *data)
8872 {
8873         struct cmd_ethertype_filter_result *res = parsed_result;
8874         struct rte_eth_ethertype_filter filter;
8875         int ret = 0;
8876
8877         ret = rte_eth_dev_filter_supported(res->port_id,
8878                         RTE_ETH_FILTER_ETHERTYPE);
8879         if (ret < 0) {
8880                 printf("ethertype filter is not supported on port %u.\n",
8881                         res->port_id);
8882                 return;
8883         }
8884
8885         memset(&filter, 0, sizeof(filter));
8886         if (!strcmp(res->mac, "mac_addr")) {
8887                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8888                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
8889                         sizeof(struct ether_addr));
8890         }
8891         if (!strcmp(res->drop, "drop"))
8892                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8893         filter.ether_type = res->ethertype_value;
8894         filter.queue = res->queue_id;
8895
8896         if (!strcmp(res->ops, "add"))
8897                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8898                                 RTE_ETH_FILTER_ETHERTYPE,
8899                                 RTE_ETH_FILTER_ADD,
8900                                 &filter);
8901         else
8902                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8903                                 RTE_ETH_FILTER_ETHERTYPE,
8904                                 RTE_ETH_FILTER_DELETE,
8905                                 &filter);
8906         if (ret < 0)
8907                 printf("ethertype filter programming error: (%s)\n",
8908                         strerror(-ret));
8909 }
8910
8911 cmdline_parse_inst_t cmd_ethertype_filter = {
8912         .f = cmd_ethertype_filter_parsed,
8913         .data = NULL,
8914         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8915                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8916                 "Add or delete an ethertype filter entry",
8917         .tokens = {
8918                 (void *)&cmd_ethertype_filter_filter,
8919                 (void *)&cmd_ethertype_filter_port_id,
8920                 (void *)&cmd_ethertype_filter_ops,
8921                 (void *)&cmd_ethertype_filter_mac,
8922                 (void *)&cmd_ethertype_filter_mac_addr,
8923                 (void *)&cmd_ethertype_filter_ethertype,
8924                 (void *)&cmd_ethertype_filter_ethertype_value,
8925                 (void *)&cmd_ethertype_filter_drop,
8926                 (void *)&cmd_ethertype_filter_queue,
8927                 (void *)&cmd_ethertype_filter_queue_id,
8928                 NULL,
8929         },
8930 };
8931
8932 /* *** deal with flow director filter *** */
8933 struct cmd_flow_director_result {
8934         cmdline_fixed_string_t flow_director_filter;
8935         uint8_t port_id;
8936         cmdline_fixed_string_t mode;
8937         cmdline_fixed_string_t mode_value;
8938         cmdline_fixed_string_t ops;
8939         cmdline_fixed_string_t flow;
8940         cmdline_fixed_string_t flow_type;
8941         cmdline_fixed_string_t ether;
8942         uint16_t ether_type;
8943         cmdline_fixed_string_t src;
8944         cmdline_ipaddr_t ip_src;
8945         uint16_t port_src;
8946         cmdline_fixed_string_t dst;
8947         cmdline_ipaddr_t ip_dst;
8948         uint16_t port_dst;
8949         cmdline_fixed_string_t verify_tag;
8950         uint32_t verify_tag_value;
8951         cmdline_ipaddr_t tos;
8952         uint8_t tos_value;
8953         cmdline_ipaddr_t proto;
8954         uint8_t proto_value;
8955         cmdline_ipaddr_t ttl;
8956         uint8_t ttl_value;
8957         cmdline_fixed_string_t vlan;
8958         uint16_t vlan_value;
8959         cmdline_fixed_string_t flexbytes;
8960         cmdline_fixed_string_t flexbytes_value;
8961         cmdline_fixed_string_t pf_vf;
8962         cmdline_fixed_string_t drop;
8963         cmdline_fixed_string_t queue;
8964         uint16_t  queue_id;
8965         cmdline_fixed_string_t fd_id;
8966         uint32_t  fd_id_value;
8967         cmdline_fixed_string_t mac;
8968         struct ether_addr mac_addr;
8969         cmdline_fixed_string_t tunnel;
8970         cmdline_fixed_string_t tunnel_type;
8971         cmdline_fixed_string_t tunnel_id;
8972         uint32_t tunnel_id_value;
8973 };
8974
8975 static inline int
8976 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8977 {
8978         char s[256];
8979         const char *p, *p0 = q_arg;
8980         char *end;
8981         unsigned long int_fld;
8982         char *str_fld[max_num];
8983         int i;
8984         unsigned size;
8985         int ret = -1;
8986
8987         p = strchr(p0, '(');
8988         if (p == NULL)
8989                 return -1;
8990         ++p;
8991         p0 = strchr(p, ')');
8992         if (p0 == NULL)
8993                 return -1;
8994
8995         size = p0 - p;
8996         if (size >= sizeof(s))
8997                 return -1;
8998
8999         snprintf(s, sizeof(s), "%.*s", size, p);
9000         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9001         if (ret < 0 || ret > max_num)
9002                 return -1;
9003         for (i = 0; i < ret; i++) {
9004                 errno = 0;
9005                 int_fld = strtoul(str_fld[i], &end, 0);
9006                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9007                         return -1;
9008                 flexbytes[i] = (uint8_t)int_fld;
9009         }
9010         return ret;
9011 }
9012
9013 static uint16_t
9014 str2flowtype(char *string)
9015 {
9016         uint8_t i = 0;
9017         static const struct {
9018                 char str[32];
9019                 uint16_t type;
9020         } flowtype_str[] = {
9021                 {"raw", RTE_ETH_FLOW_RAW},
9022                 {"ipv4", RTE_ETH_FLOW_IPV4},
9023                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9024                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9025                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9026                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9027                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9028                 {"ipv6", RTE_ETH_FLOW_IPV6},
9029                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9030                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9031                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9032                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9033                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9034                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9035         };
9036
9037         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9038                 if (!strcmp(flowtype_str[i].str, string))
9039                         return flowtype_str[i].type;
9040         }
9041
9042         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9043                 return (uint16_t)atoi(string);
9044
9045         return RTE_ETH_FLOW_UNKNOWN;
9046 }
9047
9048 static enum rte_eth_fdir_tunnel_type
9049 str2fdir_tunneltype(char *string)
9050 {
9051         uint8_t i = 0;
9052
9053         static const struct {
9054                 char str[32];
9055                 enum rte_eth_fdir_tunnel_type type;
9056         } tunneltype_str[] = {
9057                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9058                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9059         };
9060
9061         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9062                 if (!strcmp(tunneltype_str[i].str, string))
9063                         return tunneltype_str[i].type;
9064         }
9065         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9066 }
9067
9068 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9069 do { \
9070         if ((ip_addr).family == AF_INET) \
9071                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9072         else { \
9073                 printf("invalid parameter.\n"); \
9074                 return; \
9075         } \
9076 } while (0)
9077
9078 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9079 do { \
9080         if ((ip_addr).family == AF_INET6) \
9081                 rte_memcpy(&(ip), \
9082                                  &((ip_addr).addr.ipv6), \
9083                                  sizeof(struct in6_addr)); \
9084         else { \
9085                 printf("invalid parameter.\n"); \
9086                 return; \
9087         } \
9088 } while (0)
9089
9090 static void
9091 cmd_flow_director_filter_parsed(void *parsed_result,
9092                           __attribute__((unused)) struct cmdline *cl,
9093                           __attribute__((unused)) void *data)
9094 {
9095         struct cmd_flow_director_result *res = parsed_result;
9096         struct rte_eth_fdir_filter entry;
9097         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9098         char *end;
9099         unsigned long vf_id;
9100         int ret = 0;
9101
9102         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9103         if (ret < 0) {
9104                 printf("flow director is not supported on port %u.\n",
9105                         res->port_id);
9106                 return;
9107         }
9108         memset(flexbytes, 0, sizeof(flexbytes));
9109         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9110
9111         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9112                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9113                         printf("Please set mode to MAC-VLAN.\n");
9114                         return;
9115                 }
9116         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9117                 if (strcmp(res->mode_value, "Tunnel")) {
9118                         printf("Please set mode to Tunnel.\n");
9119                         return;
9120                 }
9121         } else {
9122                 if (strcmp(res->mode_value, "IP")) {
9123                         printf("Please set mode to IP.\n");
9124                         return;
9125                 }
9126                 entry.input.flow_type = str2flowtype(res->flow_type);
9127         }
9128
9129         ret = parse_flexbytes(res->flexbytes_value,
9130                                         flexbytes,
9131                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9132         if (ret < 0) {
9133                 printf("error: Cannot parse flexbytes input.\n");
9134                 return;
9135         }
9136
9137         switch (entry.input.flow_type) {
9138         case RTE_ETH_FLOW_FRAG_IPV4:
9139         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9140                 entry.input.flow.ip4_flow.proto = res->proto_value;
9141                 /* fall-through */
9142         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9143         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9144                 IPV4_ADDR_TO_UINT(res->ip_dst,
9145                         entry.input.flow.ip4_flow.dst_ip);
9146                 IPV4_ADDR_TO_UINT(res->ip_src,
9147                         entry.input.flow.ip4_flow.src_ip);
9148                 entry.input.flow.ip4_flow.tos = res->tos_value;
9149                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9150                 /* need convert to big endian. */
9151                 entry.input.flow.udp4_flow.dst_port =
9152                                 rte_cpu_to_be_16(res->port_dst);
9153                 entry.input.flow.udp4_flow.src_port =
9154                                 rte_cpu_to_be_16(res->port_src);
9155                 break;
9156         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9157                 IPV4_ADDR_TO_UINT(res->ip_dst,
9158                         entry.input.flow.sctp4_flow.ip.dst_ip);
9159                 IPV4_ADDR_TO_UINT(res->ip_src,
9160                         entry.input.flow.sctp4_flow.ip.src_ip);
9161                 entry.input.flow.ip4_flow.tos = res->tos_value;
9162                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9163                 /* need convert to big endian. */
9164                 entry.input.flow.sctp4_flow.dst_port =
9165                                 rte_cpu_to_be_16(res->port_dst);
9166                 entry.input.flow.sctp4_flow.src_port =
9167                                 rte_cpu_to_be_16(res->port_src);
9168                 entry.input.flow.sctp4_flow.verify_tag =
9169                                 rte_cpu_to_be_32(res->verify_tag_value);
9170                 break;
9171         case RTE_ETH_FLOW_FRAG_IPV6:
9172         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9173                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9174                 /* fall-through */
9175         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9176         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9177                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9178                         entry.input.flow.ipv6_flow.dst_ip);
9179                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9180                         entry.input.flow.ipv6_flow.src_ip);
9181                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9182                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9183                 /* need convert to big endian. */
9184                 entry.input.flow.udp6_flow.dst_port =
9185                                 rte_cpu_to_be_16(res->port_dst);
9186                 entry.input.flow.udp6_flow.src_port =
9187                                 rte_cpu_to_be_16(res->port_src);
9188                 break;
9189         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9190                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9191                         entry.input.flow.sctp6_flow.ip.dst_ip);
9192                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9193                         entry.input.flow.sctp6_flow.ip.src_ip);
9194                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9195                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9196                 /* need convert to big endian. */
9197                 entry.input.flow.sctp6_flow.dst_port =
9198                                 rte_cpu_to_be_16(res->port_dst);
9199                 entry.input.flow.sctp6_flow.src_port =
9200                                 rte_cpu_to_be_16(res->port_src);
9201                 entry.input.flow.sctp6_flow.verify_tag =
9202                                 rte_cpu_to_be_32(res->verify_tag_value);
9203                 break;
9204         case RTE_ETH_FLOW_L2_PAYLOAD:
9205                 entry.input.flow.l2_flow.ether_type =
9206                         rte_cpu_to_be_16(res->ether_type);
9207                 break;
9208         default:
9209                 break;
9210         }
9211
9212         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9213                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9214                                  &res->mac_addr,
9215                                  sizeof(struct ether_addr));
9216
9217         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9218                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9219                                  &res->mac_addr,
9220                                  sizeof(struct ether_addr));
9221                 entry.input.flow.tunnel_flow.tunnel_type =
9222                         str2fdir_tunneltype(res->tunnel_type);
9223                 entry.input.flow.tunnel_flow.tunnel_id =
9224                         rte_cpu_to_be_32(res->tunnel_id_value);
9225         }
9226
9227         rte_memcpy(entry.input.flow_ext.flexbytes,
9228                    flexbytes,
9229                    RTE_ETH_FDIR_MAX_FLEXLEN);
9230
9231         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9232
9233         entry.action.flex_off = 0;  /*use 0 by default */
9234         if (!strcmp(res->drop, "drop"))
9235                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9236         else
9237                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9238
9239         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9240             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9241                 if (!strcmp(res->pf_vf, "pf"))
9242                         entry.input.flow_ext.is_vf = 0;
9243                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9244                         struct rte_eth_dev_info dev_info;
9245
9246                         memset(&dev_info, 0, sizeof(dev_info));
9247                         rte_eth_dev_info_get(res->port_id, &dev_info);
9248                         errno = 0;
9249                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9250                         if (errno != 0 || *end != '\0' ||
9251                             vf_id >= dev_info.max_vfs) {
9252                                 printf("invalid parameter %s.\n", res->pf_vf);
9253                                 return;
9254                         }
9255                         entry.input.flow_ext.is_vf = 1;
9256                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9257                 } else {
9258                         printf("invalid parameter %s.\n", res->pf_vf);
9259                         return;
9260                 }
9261         }
9262
9263         /* set to report FD ID by default */
9264         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9265         entry.action.rx_queue = res->queue_id;
9266         entry.soft_id = res->fd_id_value;
9267         if (!strcmp(res->ops, "add"))
9268                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9269                                              RTE_ETH_FILTER_ADD, &entry);
9270         else if (!strcmp(res->ops, "del"))
9271                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9272                                              RTE_ETH_FILTER_DELETE, &entry);
9273         else
9274                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9275                                              RTE_ETH_FILTER_UPDATE, &entry);
9276         if (ret < 0)
9277                 printf("flow director programming error: (%s)\n",
9278                         strerror(-ret));
9279 }
9280
9281 cmdline_parse_token_string_t cmd_flow_director_filter =
9282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9283                                  flow_director_filter, "flow_director_filter");
9284 cmdline_parse_token_num_t cmd_flow_director_port_id =
9285         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9286                               port_id, UINT8);
9287 cmdline_parse_token_string_t cmd_flow_director_ops =
9288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9289                                  ops, "add#del#update");
9290 cmdline_parse_token_string_t cmd_flow_director_flow =
9291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9292                                  flow, "flow");
9293 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9295                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9296                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9297 cmdline_parse_token_string_t cmd_flow_director_ether =
9298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9299                                  ether, "ether");
9300 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9301         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9302                               ether_type, UINT16);
9303 cmdline_parse_token_string_t cmd_flow_director_src =
9304         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9305                                  src, "src");
9306 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9307         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9308                                  ip_src);
9309 cmdline_parse_token_num_t cmd_flow_director_port_src =
9310         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9311                               port_src, UINT16);
9312 cmdline_parse_token_string_t cmd_flow_director_dst =
9313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9314                                  dst, "dst");
9315 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9316         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9317                                  ip_dst);
9318 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9319         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9320                               port_dst, UINT16);
9321 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9323                                   verify_tag, "verify_tag");
9324 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9325         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9326                               verify_tag_value, UINT32);
9327 cmdline_parse_token_string_t cmd_flow_director_tos =
9328         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9329                                  tos, "tos");
9330 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9331         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9332                               tos_value, UINT8);
9333 cmdline_parse_token_string_t cmd_flow_director_proto =
9334         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9335                                  proto, "proto");
9336 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9337         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9338                               proto_value, UINT8);
9339 cmdline_parse_token_string_t cmd_flow_director_ttl =
9340         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9341                                  ttl, "ttl");
9342 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9343         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9344                               ttl_value, UINT8);
9345 cmdline_parse_token_string_t cmd_flow_director_vlan =
9346         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9347                                  vlan, "vlan");
9348 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9349         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9350                               vlan_value, UINT16);
9351 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9352         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9353                                  flexbytes, "flexbytes");
9354 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9355         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9356                               flexbytes_value, NULL);
9357 cmdline_parse_token_string_t cmd_flow_director_drop =
9358         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9359                                  drop, "drop#fwd");
9360 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9361         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9362                               pf_vf, NULL);
9363 cmdline_parse_token_string_t cmd_flow_director_queue =
9364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9365                                  queue, "queue");
9366 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9367         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9368                               queue_id, UINT16);
9369 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9371                                  fd_id, "fd_id");
9372 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9373         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9374                               fd_id_value, UINT32);
9375
9376 cmdline_parse_token_string_t cmd_flow_director_mode =
9377         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9378                                  mode, "mode");
9379 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9381                                  mode_value, "IP");
9382 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9384                                  mode_value, "MAC-VLAN");
9385 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9387                                  mode_value, "Tunnel");
9388 cmdline_parse_token_string_t cmd_flow_director_mac =
9389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9390                                  mac, "mac");
9391 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9392         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9393                                     mac_addr);
9394 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9395         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9396                                  tunnel, "tunnel");
9397 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9398         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9399                                  tunnel_type, "NVGRE#VxLAN");
9400 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9401         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9402                                  tunnel_id, "tunnel-id");
9403 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9404         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9405                               tunnel_id_value, UINT32);
9406
9407 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9408         .f = cmd_flow_director_filter_parsed,
9409         .data = NULL,
9410         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9411                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9412                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9413                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9414                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9415                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9416                 "fd_id <fd_id_value>: "
9417                 "Add or delete an ip flow director entry on NIC",
9418         .tokens = {
9419                 (void *)&cmd_flow_director_filter,
9420                 (void *)&cmd_flow_director_port_id,
9421                 (void *)&cmd_flow_director_mode,
9422                 (void *)&cmd_flow_director_mode_ip,
9423                 (void *)&cmd_flow_director_ops,
9424                 (void *)&cmd_flow_director_flow,
9425                 (void *)&cmd_flow_director_flow_type,
9426                 (void *)&cmd_flow_director_src,
9427                 (void *)&cmd_flow_director_ip_src,
9428                 (void *)&cmd_flow_director_dst,
9429                 (void *)&cmd_flow_director_ip_dst,
9430                 (void *)&cmd_flow_director_tos,
9431                 (void *)&cmd_flow_director_tos_value,
9432                 (void *)&cmd_flow_director_proto,
9433                 (void *)&cmd_flow_director_proto_value,
9434                 (void *)&cmd_flow_director_ttl,
9435                 (void *)&cmd_flow_director_ttl_value,
9436                 (void *)&cmd_flow_director_vlan,
9437                 (void *)&cmd_flow_director_vlan_value,
9438                 (void *)&cmd_flow_director_flexbytes,
9439                 (void *)&cmd_flow_director_flexbytes_value,
9440                 (void *)&cmd_flow_director_drop,
9441                 (void *)&cmd_flow_director_pf_vf,
9442                 (void *)&cmd_flow_director_queue,
9443                 (void *)&cmd_flow_director_queue_id,
9444                 (void *)&cmd_flow_director_fd_id,
9445                 (void *)&cmd_flow_director_fd_id_value,
9446                 NULL,
9447         },
9448 };
9449
9450 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9451         .f = cmd_flow_director_filter_parsed,
9452         .data = NULL,
9453         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9454                 "director entry on NIC",
9455         .tokens = {
9456                 (void *)&cmd_flow_director_filter,
9457                 (void *)&cmd_flow_director_port_id,
9458                 (void *)&cmd_flow_director_mode,
9459                 (void *)&cmd_flow_director_mode_ip,
9460                 (void *)&cmd_flow_director_ops,
9461                 (void *)&cmd_flow_director_flow,
9462                 (void *)&cmd_flow_director_flow_type,
9463                 (void *)&cmd_flow_director_src,
9464                 (void *)&cmd_flow_director_ip_src,
9465                 (void *)&cmd_flow_director_port_src,
9466                 (void *)&cmd_flow_director_dst,
9467                 (void *)&cmd_flow_director_ip_dst,
9468                 (void *)&cmd_flow_director_port_dst,
9469                 (void *)&cmd_flow_director_tos,
9470                 (void *)&cmd_flow_director_tos_value,
9471                 (void *)&cmd_flow_director_ttl,
9472                 (void *)&cmd_flow_director_ttl_value,
9473                 (void *)&cmd_flow_director_vlan,
9474                 (void *)&cmd_flow_director_vlan_value,
9475                 (void *)&cmd_flow_director_flexbytes,
9476                 (void *)&cmd_flow_director_flexbytes_value,
9477                 (void *)&cmd_flow_director_drop,
9478                 (void *)&cmd_flow_director_pf_vf,
9479                 (void *)&cmd_flow_director_queue,
9480                 (void *)&cmd_flow_director_queue_id,
9481                 (void *)&cmd_flow_director_fd_id,
9482                 (void *)&cmd_flow_director_fd_id_value,
9483                 NULL,
9484         },
9485 };
9486
9487 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9488         .f = cmd_flow_director_filter_parsed,
9489         .data = NULL,
9490         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9491                 "director entry on NIC",
9492         .tokens = {
9493                 (void *)&cmd_flow_director_filter,
9494                 (void *)&cmd_flow_director_port_id,
9495                 (void *)&cmd_flow_director_mode,
9496                 (void *)&cmd_flow_director_mode_ip,
9497                 (void *)&cmd_flow_director_ops,
9498                 (void *)&cmd_flow_director_flow,
9499                 (void *)&cmd_flow_director_flow_type,
9500                 (void *)&cmd_flow_director_src,
9501                 (void *)&cmd_flow_director_ip_src,
9502                 (void *)&cmd_flow_director_port_dst,
9503                 (void *)&cmd_flow_director_dst,
9504                 (void *)&cmd_flow_director_ip_dst,
9505                 (void *)&cmd_flow_director_port_dst,
9506                 (void *)&cmd_flow_director_verify_tag,
9507                 (void *)&cmd_flow_director_verify_tag_value,
9508                 (void *)&cmd_flow_director_tos,
9509                 (void *)&cmd_flow_director_tos_value,
9510                 (void *)&cmd_flow_director_ttl,
9511                 (void *)&cmd_flow_director_ttl_value,
9512                 (void *)&cmd_flow_director_vlan,
9513                 (void *)&cmd_flow_director_vlan_value,
9514                 (void *)&cmd_flow_director_flexbytes,
9515                 (void *)&cmd_flow_director_flexbytes_value,
9516                 (void *)&cmd_flow_director_drop,
9517                 (void *)&cmd_flow_director_pf_vf,
9518                 (void *)&cmd_flow_director_queue,
9519                 (void *)&cmd_flow_director_queue_id,
9520                 (void *)&cmd_flow_director_fd_id,
9521                 (void *)&cmd_flow_director_fd_id_value,
9522                 NULL,
9523         },
9524 };
9525
9526 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9527         .f = cmd_flow_director_filter_parsed,
9528         .data = NULL,
9529         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9530                 "director entry on NIC",
9531         .tokens = {
9532                 (void *)&cmd_flow_director_filter,
9533                 (void *)&cmd_flow_director_port_id,
9534                 (void *)&cmd_flow_director_mode,
9535                 (void *)&cmd_flow_director_mode_ip,
9536                 (void *)&cmd_flow_director_ops,
9537                 (void *)&cmd_flow_director_flow,
9538                 (void *)&cmd_flow_director_flow_type,
9539                 (void *)&cmd_flow_director_ether,
9540                 (void *)&cmd_flow_director_ether_type,
9541                 (void *)&cmd_flow_director_flexbytes,
9542                 (void *)&cmd_flow_director_flexbytes_value,
9543                 (void *)&cmd_flow_director_drop,
9544                 (void *)&cmd_flow_director_pf_vf,
9545                 (void *)&cmd_flow_director_queue,
9546                 (void *)&cmd_flow_director_queue_id,
9547                 (void *)&cmd_flow_director_fd_id,
9548                 (void *)&cmd_flow_director_fd_id_value,
9549                 NULL,
9550         },
9551 };
9552
9553 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9554         .f = cmd_flow_director_filter_parsed,
9555         .data = NULL,
9556         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9557                 "director entry on NIC",
9558         .tokens = {
9559                 (void *)&cmd_flow_director_filter,
9560                 (void *)&cmd_flow_director_port_id,
9561                 (void *)&cmd_flow_director_mode,
9562                 (void *)&cmd_flow_director_mode_mac_vlan,
9563                 (void *)&cmd_flow_director_ops,
9564                 (void *)&cmd_flow_director_mac,
9565                 (void *)&cmd_flow_director_mac_addr,
9566                 (void *)&cmd_flow_director_vlan,
9567                 (void *)&cmd_flow_director_vlan_value,
9568                 (void *)&cmd_flow_director_flexbytes,
9569                 (void *)&cmd_flow_director_flexbytes_value,
9570                 (void *)&cmd_flow_director_drop,
9571                 (void *)&cmd_flow_director_queue,
9572                 (void *)&cmd_flow_director_queue_id,
9573                 (void *)&cmd_flow_director_fd_id,
9574                 (void *)&cmd_flow_director_fd_id_value,
9575                 NULL,
9576         },
9577 };
9578
9579 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9580         .f = cmd_flow_director_filter_parsed,
9581         .data = NULL,
9582         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9583                 "director entry on NIC",
9584         .tokens = {
9585                 (void *)&cmd_flow_director_filter,
9586                 (void *)&cmd_flow_director_port_id,
9587                 (void *)&cmd_flow_director_mode,
9588                 (void *)&cmd_flow_director_mode_tunnel,
9589                 (void *)&cmd_flow_director_ops,
9590                 (void *)&cmd_flow_director_mac,
9591                 (void *)&cmd_flow_director_mac_addr,
9592                 (void *)&cmd_flow_director_vlan,
9593                 (void *)&cmd_flow_director_vlan_value,
9594                 (void *)&cmd_flow_director_tunnel,
9595                 (void *)&cmd_flow_director_tunnel_type,
9596                 (void *)&cmd_flow_director_tunnel_id,
9597                 (void *)&cmd_flow_director_tunnel_id_value,
9598                 (void *)&cmd_flow_director_flexbytes,
9599                 (void *)&cmd_flow_director_flexbytes_value,
9600                 (void *)&cmd_flow_director_drop,
9601                 (void *)&cmd_flow_director_queue,
9602                 (void *)&cmd_flow_director_queue_id,
9603                 (void *)&cmd_flow_director_fd_id,
9604                 (void *)&cmd_flow_director_fd_id_value,
9605                 NULL,
9606         },
9607 };
9608
9609 struct cmd_flush_flow_director_result {
9610         cmdline_fixed_string_t flush_flow_director;
9611         uint8_t port_id;
9612 };
9613
9614 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9615         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9616                                  flush_flow_director, "flush_flow_director");
9617 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9618         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9619                               port_id, UINT8);
9620
9621 static void
9622 cmd_flush_flow_director_parsed(void *parsed_result,
9623                           __attribute__((unused)) struct cmdline *cl,
9624                           __attribute__((unused)) void *data)
9625 {
9626         struct cmd_flow_director_result *res = parsed_result;
9627         int ret = 0;
9628
9629         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9630         if (ret < 0) {
9631                 printf("flow director is not supported on port %u.\n",
9632                         res->port_id);
9633                 return;
9634         }
9635
9636         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9637                         RTE_ETH_FILTER_FLUSH, NULL);
9638         if (ret < 0)
9639                 printf("flow director table flushing error: (%s)\n",
9640                         strerror(-ret));
9641 }
9642
9643 cmdline_parse_inst_t cmd_flush_flow_director = {
9644         .f = cmd_flush_flow_director_parsed,
9645         .data = NULL,
9646         .help_str = "flush_flow_director <port_id>: "
9647                 "Flush all flow director entries of a device on NIC",
9648         .tokens = {
9649                 (void *)&cmd_flush_flow_director_flush,
9650                 (void *)&cmd_flush_flow_director_port_id,
9651                 NULL,
9652         },
9653 };
9654
9655 /* *** deal with flow director mask *** */
9656 struct cmd_flow_director_mask_result {
9657         cmdline_fixed_string_t flow_director_mask;
9658         uint8_t port_id;
9659         cmdline_fixed_string_t mode;
9660         cmdline_fixed_string_t mode_value;
9661         cmdline_fixed_string_t vlan;
9662         uint16_t vlan_mask;
9663         cmdline_fixed_string_t src_mask;
9664         cmdline_ipaddr_t ipv4_src;
9665         cmdline_ipaddr_t ipv6_src;
9666         uint16_t port_src;
9667         cmdline_fixed_string_t dst_mask;
9668         cmdline_ipaddr_t ipv4_dst;
9669         cmdline_ipaddr_t ipv6_dst;
9670         uint16_t port_dst;
9671         cmdline_fixed_string_t mac;
9672         uint8_t mac_addr_byte_mask;
9673         cmdline_fixed_string_t tunnel_id;
9674         uint32_t tunnel_id_mask;
9675         cmdline_fixed_string_t tunnel_type;
9676         uint8_t tunnel_type_mask;
9677 };
9678
9679 static void
9680 cmd_flow_director_mask_parsed(void *parsed_result,
9681                           __attribute__((unused)) struct cmdline *cl,
9682                           __attribute__((unused)) void *data)
9683 {
9684         struct cmd_flow_director_mask_result *res = parsed_result;
9685         struct rte_eth_fdir_masks *mask;
9686         struct rte_port *port;
9687
9688         if (res->port_id > nb_ports) {
9689                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9690                 return;
9691         }
9692
9693         port = &ports[res->port_id];
9694         /** Check if the port is not started **/
9695         if (port->port_status != RTE_PORT_STOPPED) {
9696                 printf("Please stop port %d first\n", res->port_id);
9697                 return;
9698         }
9699
9700         mask = &port->dev_conf.fdir_conf.mask;
9701
9702         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9703                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9704                         printf("Please set mode to MAC-VLAN.\n");
9705                         return;
9706                 }
9707
9708                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9709         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9710                 if (strcmp(res->mode_value, "Tunnel")) {
9711                         printf("Please set mode to Tunnel.\n");
9712                         return;
9713                 }
9714
9715                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9716                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9717                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9718                 mask->tunnel_type_mask = res->tunnel_type_mask;
9719         } else {
9720                 if (strcmp(res->mode_value, "IP")) {
9721                         printf("Please set mode to IP.\n");
9722                         return;
9723                 }
9724
9725                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9726                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9727                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9728                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9729                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9730                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9731                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9732         }
9733
9734         cmd_reconfig_device_queue(res->port_id, 1, 1);
9735 }
9736
9737 cmdline_parse_token_string_t cmd_flow_director_mask =
9738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9739                                  flow_director_mask, "flow_director_mask");
9740 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9741         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9742                               port_id, UINT8);
9743 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9744         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9745                                  vlan, "vlan");
9746 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9747         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9748                               vlan_mask, UINT16);
9749 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9751                                  src_mask, "src_mask");
9752 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9753         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9754                                  ipv4_src);
9755 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9756         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9757                                  ipv6_src);
9758 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9759         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9760                               port_src, UINT16);
9761 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9763                                  dst_mask, "dst_mask");
9764 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9765         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9766                                  ipv4_dst);
9767 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9768         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9769                                  ipv6_dst);
9770 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9771         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9772                               port_dst, UINT16);
9773
9774 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9776                                  mode, "mode");
9777 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9779                                  mode_value, "IP");
9780 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9781         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9782                                  mode_value, "MAC-VLAN");
9783 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9784         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9785                                  mode_value, "Tunnel");
9786 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9787         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9788                                  mac, "mac");
9789 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9790         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9791                               mac_addr_byte_mask, UINT8);
9792 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9794                                  tunnel_type, "tunnel-type");
9795 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9796         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9797                               tunnel_type_mask, UINT8);
9798 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9800                                  tunnel_id, "tunnel-id");
9801 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9802         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9803                               tunnel_id_mask, UINT32);
9804
9805 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9806         .f = cmd_flow_director_mask_parsed,
9807         .data = NULL,
9808         .help_str = "flow_director_mask ... : "
9809                 "Set IP mode flow director's mask on NIC",
9810         .tokens = {
9811                 (void *)&cmd_flow_director_mask,
9812                 (void *)&cmd_flow_director_mask_port_id,
9813                 (void *)&cmd_flow_director_mask_mode,
9814                 (void *)&cmd_flow_director_mask_mode_ip,
9815                 (void *)&cmd_flow_director_mask_vlan,
9816                 (void *)&cmd_flow_director_mask_vlan_value,
9817                 (void *)&cmd_flow_director_mask_src,
9818                 (void *)&cmd_flow_director_mask_ipv4_src,
9819                 (void *)&cmd_flow_director_mask_ipv6_src,
9820                 (void *)&cmd_flow_director_mask_port_src,
9821                 (void *)&cmd_flow_director_mask_dst,
9822                 (void *)&cmd_flow_director_mask_ipv4_dst,
9823                 (void *)&cmd_flow_director_mask_ipv6_dst,
9824                 (void *)&cmd_flow_director_mask_port_dst,
9825                 NULL,
9826         },
9827 };
9828
9829 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9830         .f = cmd_flow_director_mask_parsed,
9831         .data = NULL,
9832         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9833                 "flow director's mask on NIC",
9834         .tokens = {
9835                 (void *)&cmd_flow_director_mask,
9836                 (void *)&cmd_flow_director_mask_port_id,
9837                 (void *)&cmd_flow_director_mask_mode,
9838                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9839                 (void *)&cmd_flow_director_mask_vlan,
9840                 (void *)&cmd_flow_director_mask_vlan_value,
9841                 NULL,
9842         },
9843 };
9844
9845 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9846         .f = cmd_flow_director_mask_parsed,
9847         .data = NULL,
9848         .help_str = "flow_director_mask ... : Set tunnel mode "
9849                 "flow director's mask on NIC",
9850         .tokens = {
9851                 (void *)&cmd_flow_director_mask,
9852                 (void *)&cmd_flow_director_mask_port_id,
9853                 (void *)&cmd_flow_director_mask_mode,
9854                 (void *)&cmd_flow_director_mask_mode_tunnel,
9855                 (void *)&cmd_flow_director_mask_vlan,
9856                 (void *)&cmd_flow_director_mask_vlan_value,
9857                 (void *)&cmd_flow_director_mask_mac,
9858                 (void *)&cmd_flow_director_mask_mac_value,
9859                 (void *)&cmd_flow_director_mask_tunnel_type,
9860                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9861                 (void *)&cmd_flow_director_mask_tunnel_id,
9862                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9863                 NULL,
9864         },
9865 };
9866
9867 /* *** deal with flow director mask on flexible payload *** */
9868 struct cmd_flow_director_flex_mask_result {
9869         cmdline_fixed_string_t flow_director_flexmask;
9870         uint8_t port_id;
9871         cmdline_fixed_string_t flow;
9872         cmdline_fixed_string_t flow_type;
9873         cmdline_fixed_string_t mask;
9874 };
9875
9876 static void
9877 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9878                           __attribute__((unused)) struct cmdline *cl,
9879                           __attribute__((unused)) void *data)
9880 {
9881         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9882         struct rte_eth_fdir_info fdir_info;
9883         struct rte_eth_fdir_flex_mask flex_mask;
9884         struct rte_port *port;
9885         uint32_t flow_type_mask;
9886         uint16_t i;
9887         int ret;
9888
9889         if (res->port_id > nb_ports) {
9890                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9891                 return;
9892         }
9893
9894         port = &ports[res->port_id];
9895         /** Check if the port is not started **/
9896         if (port->port_status != RTE_PORT_STOPPED) {
9897                 printf("Please stop port %d first\n", res->port_id);
9898                 return;
9899         }
9900
9901         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9902         ret = parse_flexbytes(res->mask,
9903                         flex_mask.mask,
9904                         RTE_ETH_FDIR_MAX_FLEXLEN);
9905         if (ret < 0) {
9906                 printf("error: Cannot parse mask input.\n");
9907                 return;
9908         }
9909
9910         memset(&fdir_info, 0, sizeof(fdir_info));
9911         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9912                                 RTE_ETH_FILTER_INFO, &fdir_info);
9913         if (ret < 0) {
9914                 printf("Cannot get FDir filter info\n");
9915                 return;
9916         }
9917
9918         if (!strcmp(res->flow_type, "none")) {
9919                 /* means don't specify the flow type */
9920                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9921                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9922                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9923                                0, sizeof(struct rte_eth_fdir_flex_mask));
9924                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9925                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9926                                  &flex_mask,
9927                                  sizeof(struct rte_eth_fdir_flex_mask));
9928                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9929                 return;
9930         }
9931         flow_type_mask = fdir_info.flow_types_mask[0];
9932         if (!strcmp(res->flow_type, "all")) {
9933                 if (!flow_type_mask) {
9934                         printf("No flow type supported\n");
9935                         return;
9936                 }
9937                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9938                         if (flow_type_mask & (1 << i)) {
9939                                 flex_mask.flow_type = i;
9940                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9941                         }
9942                 }
9943                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9944                 return;
9945         }
9946         flex_mask.flow_type = str2flowtype(res->flow_type);
9947         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9948                 printf("Flow type %s not supported on port %d\n",
9949                                 res->flow_type, res->port_id);
9950                 return;
9951         }
9952         fdir_set_flex_mask(res->port_id, &flex_mask);
9953         cmd_reconfig_device_queue(res->port_id, 1, 1);
9954 }
9955
9956 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9957         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9958                                  flow_director_flexmask,
9959                                  "flow_director_flex_mask");
9960 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9961         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9962                               port_id, UINT8);
9963 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9964         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9965                                  flow, "flow");
9966 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9967         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9968                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9969                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9970 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9971         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9972                                  mask, NULL);
9973
9974 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9975         .f = cmd_flow_director_flex_mask_parsed,
9976         .data = NULL,
9977         .help_str = "flow_director_flex_mask ... : "
9978                 "Set flow director's flex mask on NIC",
9979         .tokens = {
9980                 (void *)&cmd_flow_director_flexmask,
9981                 (void *)&cmd_flow_director_flexmask_port_id,
9982                 (void *)&cmd_flow_director_flexmask_flow,
9983                 (void *)&cmd_flow_director_flexmask_flow_type,
9984                 (void *)&cmd_flow_director_flexmask_mask,
9985                 NULL,
9986         },
9987 };
9988
9989 /* *** deal with flow director flexible payload configuration *** */
9990 struct cmd_flow_director_flexpayload_result {
9991         cmdline_fixed_string_t flow_director_flexpayload;
9992         uint8_t port_id;
9993         cmdline_fixed_string_t payload_layer;
9994         cmdline_fixed_string_t payload_cfg;
9995 };
9996
9997 static inline int
9998 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9999 {
10000         char s[256];
10001         const char *p, *p0 = q_arg;
10002         char *end;
10003         unsigned long int_fld;
10004         char *str_fld[max_num];
10005         int i;
10006         unsigned size;
10007         int ret = -1;
10008
10009         p = strchr(p0, '(');
10010         if (p == NULL)
10011                 return -1;
10012         ++p;
10013         p0 = strchr(p, ')');
10014         if (p0 == NULL)
10015                 return -1;
10016
10017         size = p0 - p;
10018         if (size >= sizeof(s))
10019                 return -1;
10020
10021         snprintf(s, sizeof(s), "%.*s", size, p);
10022         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10023         if (ret < 0 || ret > max_num)
10024                 return -1;
10025         for (i = 0; i < ret; i++) {
10026                 errno = 0;
10027                 int_fld = strtoul(str_fld[i], &end, 0);
10028                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10029                         return -1;
10030                 offsets[i] = (uint16_t)int_fld;
10031         }
10032         return ret;
10033 }
10034
10035 static void
10036 cmd_flow_director_flxpld_parsed(void *parsed_result,
10037                           __attribute__((unused)) struct cmdline *cl,
10038                           __attribute__((unused)) void *data)
10039 {
10040         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10041         struct rte_eth_flex_payload_cfg flex_cfg;
10042         struct rte_port *port;
10043         int ret = 0;
10044
10045         if (res->port_id > nb_ports) {
10046                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10047                 return;
10048         }
10049
10050         port = &ports[res->port_id];
10051         /** Check if the port is not started **/
10052         if (port->port_status != RTE_PORT_STOPPED) {
10053                 printf("Please stop port %d first\n", res->port_id);
10054                 return;
10055         }
10056
10057         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10058
10059         if (!strcmp(res->payload_layer, "raw"))
10060                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10061         else if (!strcmp(res->payload_layer, "l2"))
10062                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10063         else if (!strcmp(res->payload_layer, "l3"))
10064                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10065         else if (!strcmp(res->payload_layer, "l4"))
10066                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10067
10068         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10069                             RTE_ETH_FDIR_MAX_FLEXLEN);
10070         if (ret < 0) {
10071                 printf("error: Cannot parse flex payload input.\n");
10072                 return;
10073         }
10074
10075         fdir_set_flex_payload(res->port_id, &flex_cfg);
10076         cmd_reconfig_device_queue(res->port_id, 1, 1);
10077 }
10078
10079 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10081                                  flow_director_flexpayload,
10082                                  "flow_director_flex_payload");
10083 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10084         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10085                               port_id, UINT8);
10086 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10088                                  payload_layer, "raw#l2#l3#l4");
10089 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10090         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10091                                  payload_cfg, NULL);
10092
10093 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10094         .f = cmd_flow_director_flxpld_parsed,
10095         .data = NULL,
10096         .help_str = "flow_director_flexpayload ... : "
10097                 "Set flow director's flex payload on NIC",
10098         .tokens = {
10099                 (void *)&cmd_flow_director_flexpayload,
10100                 (void *)&cmd_flow_director_flexpayload_port_id,
10101                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10102                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10103                 NULL,
10104         },
10105 };
10106
10107 /* Generic flow interface command. */
10108 extern cmdline_parse_inst_t cmd_flow;
10109
10110 /* *** Classification Filters Control *** */
10111 /* *** Get symmetric hash enable per port *** */
10112 struct cmd_get_sym_hash_ena_per_port_result {
10113         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10114         uint8_t port_id;
10115 };
10116
10117 static void
10118 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10119                                  __rte_unused struct cmdline *cl,
10120                                  __rte_unused void *data)
10121 {
10122         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10123         struct rte_eth_hash_filter_info info;
10124         int ret;
10125
10126         if (rte_eth_dev_filter_supported(res->port_id,
10127                                 RTE_ETH_FILTER_HASH) < 0) {
10128                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10129                                                         res->port_id);
10130                 return;
10131         }
10132
10133         memset(&info, 0, sizeof(info));
10134         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10135         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10136                                                 RTE_ETH_FILTER_GET, &info);
10137
10138         if (ret < 0) {
10139                 printf("Cannot get symmetric hash enable per port "
10140                                         "on port %u\n", res->port_id);
10141                 return;
10142         }
10143
10144         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10145                                 "enabled" : "disabled", res->port_id);
10146 }
10147
10148 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10149         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10150                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10151 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10152         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10153                 port_id, UINT8);
10154
10155 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10156         .f = cmd_get_sym_hash_per_port_parsed,
10157         .data = NULL,
10158         .help_str = "get_sym_hash_ena_per_port <port_id>",
10159         .tokens = {
10160                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10161                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10162                 NULL,
10163         },
10164 };
10165
10166 /* *** Set symmetric hash enable per port *** */
10167 struct cmd_set_sym_hash_ena_per_port_result {
10168         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10169         cmdline_fixed_string_t enable;
10170         uint8_t port_id;
10171 };
10172
10173 static void
10174 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10175                                  __rte_unused struct cmdline *cl,
10176                                  __rte_unused void *data)
10177 {
10178         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10179         struct rte_eth_hash_filter_info info;
10180         int ret;
10181
10182         if (rte_eth_dev_filter_supported(res->port_id,
10183                                 RTE_ETH_FILTER_HASH) < 0) {
10184                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10185                                                         res->port_id);
10186                 return;
10187         }
10188
10189         memset(&info, 0, sizeof(info));
10190         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10191         if (!strcmp(res->enable, "enable"))
10192                 info.info.enable = 1;
10193         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10194                                         RTE_ETH_FILTER_SET, &info);
10195         if (ret < 0) {
10196                 printf("Cannot set symmetric hash enable per port on "
10197                                         "port %u\n", res->port_id);
10198                 return;
10199         }
10200         printf("Symmetric hash has been set to %s on port %u\n",
10201                                         res->enable, res->port_id);
10202 }
10203
10204 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10205         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10206                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10207 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10208         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10209                 port_id, UINT8);
10210 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10211         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10212                 enable, "enable#disable");
10213
10214 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10215         .f = cmd_set_sym_hash_per_port_parsed,
10216         .data = NULL,
10217         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10218         .tokens = {
10219                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10220                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10221                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10222                 NULL,
10223         },
10224 };
10225
10226 /* Get global config of hash function */
10227 struct cmd_get_hash_global_config_result {
10228         cmdline_fixed_string_t get_hash_global_config;
10229         uint8_t port_id;
10230 };
10231
10232 static char *
10233 flowtype_to_str(uint16_t ftype)
10234 {
10235         uint16_t i;
10236         static struct {
10237                 char str[16];
10238                 uint16_t ftype;
10239         } ftype_table[] = {
10240                 {"ipv4", RTE_ETH_FLOW_IPV4},
10241                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10242                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10243                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10244                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10245                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10246                 {"ipv6", RTE_ETH_FLOW_IPV6},
10247                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10248                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10249                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10250                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10251                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10252                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10253                 {"port", RTE_ETH_FLOW_PORT},
10254                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10255                 {"geneve", RTE_ETH_FLOW_GENEVE},
10256                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10257         };
10258
10259         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10260                 if (ftype_table[i].ftype == ftype)
10261                         return ftype_table[i].str;
10262         }
10263
10264         return NULL;
10265 }
10266
10267 static void
10268 cmd_get_hash_global_config_parsed(void *parsed_result,
10269                                   __rte_unused struct cmdline *cl,
10270                                   __rte_unused void *data)
10271 {
10272         struct cmd_get_hash_global_config_result *res = parsed_result;
10273         struct rte_eth_hash_filter_info info;
10274         uint32_t idx, offset;
10275         uint16_t i;
10276         char *str;
10277         int ret;
10278
10279         if (rte_eth_dev_filter_supported(res->port_id,
10280                         RTE_ETH_FILTER_HASH) < 0) {
10281                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10282                                                         res->port_id);
10283                 return;
10284         }
10285
10286         memset(&info, 0, sizeof(info));
10287         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10288         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10289                                         RTE_ETH_FILTER_GET, &info);
10290         if (ret < 0) {
10291                 printf("Cannot get hash global configurations by port %d\n",
10292                                                         res->port_id);
10293                 return;
10294         }
10295
10296         switch (info.info.global_conf.hash_func) {
10297         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10298                 printf("Hash function is Toeplitz\n");
10299                 break;
10300         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10301                 printf("Hash function is Simple XOR\n");
10302                 break;
10303         default:
10304                 printf("Unknown hash function\n");
10305                 break;
10306         }
10307
10308         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10309                 idx = i / UINT32_BIT;
10310                 offset = i % UINT32_BIT;
10311                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10312                                                 (1UL << offset)))
10313                         continue;
10314                 str = flowtype_to_str(i);
10315                 if (!str)
10316                         continue;
10317                 printf("Symmetric hash is %s globally for flow type %s "
10318                                                         "by port %d\n",
10319                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10320                         (1UL << offset)) ? "enabled" : "disabled"), str,
10321                                                         res->port_id);
10322         }
10323 }
10324
10325 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10326         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10327                 get_hash_global_config, "get_hash_global_config");
10328 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10329         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10330                 port_id, UINT8);
10331
10332 cmdline_parse_inst_t cmd_get_hash_global_config = {
10333         .f = cmd_get_hash_global_config_parsed,
10334         .data = NULL,
10335         .help_str = "get_hash_global_config <port_id>",
10336         .tokens = {
10337                 (void *)&cmd_get_hash_global_config_all,
10338                 (void *)&cmd_get_hash_global_config_port_id,
10339                 NULL,
10340         },
10341 };
10342
10343 /* Set global config of hash function */
10344 struct cmd_set_hash_global_config_result {
10345         cmdline_fixed_string_t set_hash_global_config;
10346         uint8_t port_id;
10347         cmdline_fixed_string_t hash_func;
10348         cmdline_fixed_string_t flow_type;
10349         cmdline_fixed_string_t enable;
10350 };
10351
10352 static void
10353 cmd_set_hash_global_config_parsed(void *parsed_result,
10354                                   __rte_unused struct cmdline *cl,
10355                                   __rte_unused void *data)
10356 {
10357         struct cmd_set_hash_global_config_result *res = parsed_result;
10358         struct rte_eth_hash_filter_info info;
10359         uint32_t ftype, idx, offset;
10360         int ret;
10361
10362         if (rte_eth_dev_filter_supported(res->port_id,
10363                                 RTE_ETH_FILTER_HASH) < 0) {
10364                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10365                                                         res->port_id);
10366                 return;
10367         }
10368         memset(&info, 0, sizeof(info));
10369         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10370         if (!strcmp(res->hash_func, "toeplitz"))
10371                 info.info.global_conf.hash_func =
10372                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10373         else if (!strcmp(res->hash_func, "simple_xor"))
10374                 info.info.global_conf.hash_func =
10375                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10376         else if (!strcmp(res->hash_func, "default"))
10377                 info.info.global_conf.hash_func =
10378                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10379
10380         ftype = str2flowtype(res->flow_type);
10381         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10382         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10383         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10384         if (!strcmp(res->enable, "enable"))
10385                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10386                                                 (1UL << offset);
10387         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10388                                         RTE_ETH_FILTER_SET, &info);
10389         if (ret < 0)
10390                 printf("Cannot set global hash configurations by port %d\n",
10391                                                         res->port_id);
10392         else
10393                 printf("Global hash configurations have been set "
10394                         "succcessfully by port %d\n", res->port_id);
10395 }
10396
10397 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10398         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10399                 set_hash_global_config, "set_hash_global_config");
10400 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10401         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10402                 port_id, UINT8);
10403 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10404         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10405                 hash_func, "toeplitz#simple_xor#default");
10406 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10407         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10408                 flow_type,
10409                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10410                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10411 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10412         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10413                 enable, "enable#disable");
10414
10415 cmdline_parse_inst_t cmd_set_hash_global_config = {
10416         .f = cmd_set_hash_global_config_parsed,
10417         .data = NULL,
10418         .help_str = "set_hash_global_config <port_id> "
10419                 "toeplitz|simple_xor|default "
10420                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10421                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10422                 "l2_payload enable|disable",
10423         .tokens = {
10424                 (void *)&cmd_set_hash_global_config_all,
10425                 (void *)&cmd_set_hash_global_config_port_id,
10426                 (void *)&cmd_set_hash_global_config_hash_func,
10427                 (void *)&cmd_set_hash_global_config_flow_type,
10428                 (void *)&cmd_set_hash_global_config_enable,
10429                 NULL,
10430         },
10431 };
10432
10433 /* Set hash input set */
10434 struct cmd_set_hash_input_set_result {
10435         cmdline_fixed_string_t set_hash_input_set;
10436         uint8_t port_id;
10437         cmdline_fixed_string_t flow_type;
10438         cmdline_fixed_string_t inset_field;
10439         cmdline_fixed_string_t select;
10440 };
10441
10442 static enum rte_eth_input_set_field
10443 str2inset(char *string)
10444 {
10445         uint16_t i;
10446
10447         static const struct {
10448                 char str[32];
10449                 enum rte_eth_input_set_field inset;
10450         } inset_table[] = {
10451                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10452                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10453                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10454                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10455                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10456                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10457                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10458                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10459                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10460                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10461                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10462                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10463                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10464                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10465                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10466                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10467                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10468                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10469                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10470                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10471                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10472                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10473                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10474                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10475                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10476                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10477                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10478                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10479                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10480                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10481                 {"none", RTE_ETH_INPUT_SET_NONE},
10482         };
10483
10484         for (i = 0; i < RTE_DIM(inset_table); i++) {
10485                 if (!strcmp(string, inset_table[i].str))
10486                         return inset_table[i].inset;
10487         }
10488
10489         return RTE_ETH_INPUT_SET_UNKNOWN;
10490 }
10491
10492 static void
10493 cmd_set_hash_input_set_parsed(void *parsed_result,
10494                               __rte_unused struct cmdline *cl,
10495                               __rte_unused void *data)
10496 {
10497         struct cmd_set_hash_input_set_result *res = parsed_result;
10498         struct rte_eth_hash_filter_info info;
10499
10500         memset(&info, 0, sizeof(info));
10501         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10502         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10503         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10504         info.info.input_set_conf.inset_size = 1;
10505         if (!strcmp(res->select, "select"))
10506                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10507         else if (!strcmp(res->select, "add"))
10508                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10509         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10510                                 RTE_ETH_FILTER_SET, &info);
10511 }
10512
10513 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10514         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10515                 set_hash_input_set, "set_hash_input_set");
10516 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10517         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10518                 port_id, UINT8);
10519 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10520         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10521                 flow_type, NULL);
10522 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10523         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10524                 inset_field,
10525                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10526                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10527                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10528                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10529                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10530                 "fld-8th#none");
10531 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10532         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10533                 select, "select#add");
10534
10535 cmdline_parse_inst_t cmd_set_hash_input_set = {
10536         .f = cmd_set_hash_input_set_parsed,
10537         .data = NULL,
10538         .help_str = "set_hash_input_set <port_id> "
10539         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10540         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10541         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10542         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10543         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10544         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10545         "fld-7th|fld-8th|none select|add",
10546         .tokens = {
10547                 (void *)&cmd_set_hash_input_set_cmd,
10548                 (void *)&cmd_set_hash_input_set_port_id,
10549                 (void *)&cmd_set_hash_input_set_flow_type,
10550                 (void *)&cmd_set_hash_input_set_field,
10551                 (void *)&cmd_set_hash_input_set_select,
10552                 NULL,
10553         },
10554 };
10555
10556 /* Set flow director input set */
10557 struct cmd_set_fdir_input_set_result {
10558         cmdline_fixed_string_t set_fdir_input_set;
10559         uint8_t port_id;
10560         cmdline_fixed_string_t flow_type;
10561         cmdline_fixed_string_t inset_field;
10562         cmdline_fixed_string_t select;
10563 };
10564
10565 static void
10566 cmd_set_fdir_input_set_parsed(void *parsed_result,
10567         __rte_unused struct cmdline *cl,
10568         __rte_unused void *data)
10569 {
10570         struct cmd_set_fdir_input_set_result *res = parsed_result;
10571         struct rte_eth_fdir_filter_info info;
10572
10573         memset(&info, 0, sizeof(info));
10574         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10575         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10576         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10577         info.info.input_set_conf.inset_size = 1;
10578         if (!strcmp(res->select, "select"))
10579                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10580         else if (!strcmp(res->select, "add"))
10581                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10582         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10583                 RTE_ETH_FILTER_SET, &info);
10584 }
10585
10586 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10587         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10588         set_fdir_input_set, "set_fdir_input_set");
10589 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10590         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10591         port_id, UINT8);
10592 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10593         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10594         flow_type,
10595         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10596         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10597 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10598         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10599         inset_field,
10600         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10601         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10602         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10603         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10604         "sctp-veri-tag#none");
10605 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10606         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10607         select, "select#add");
10608
10609 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10610         .f = cmd_set_fdir_input_set_parsed,
10611         .data = NULL,
10612         .help_str = "set_fdir_input_set <port_id> "
10613         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10614         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10615         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10616         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10617         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10618         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10619         "sctp-veri-tag|none select|add",
10620         .tokens = {
10621                 (void *)&cmd_set_fdir_input_set_cmd,
10622                 (void *)&cmd_set_fdir_input_set_port_id,
10623                 (void *)&cmd_set_fdir_input_set_flow_type,
10624                 (void *)&cmd_set_fdir_input_set_field,
10625                 (void *)&cmd_set_fdir_input_set_select,
10626                 NULL,
10627         },
10628 };
10629
10630 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10631 struct cmd_mcast_addr_result {
10632         cmdline_fixed_string_t mcast_addr_cmd;
10633         cmdline_fixed_string_t what;
10634         uint8_t port_num;
10635         struct ether_addr mc_addr;
10636 };
10637
10638 static void cmd_mcast_addr_parsed(void *parsed_result,
10639                 __attribute__((unused)) struct cmdline *cl,
10640                 __attribute__((unused)) void *data)
10641 {
10642         struct cmd_mcast_addr_result *res = parsed_result;
10643
10644         if (!is_multicast_ether_addr(&res->mc_addr)) {
10645                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10646                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10647                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10648                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10649                 return;
10650         }
10651         if (strcmp(res->what, "add") == 0)
10652                 mcast_addr_add(res->port_num, &res->mc_addr);
10653         else
10654                 mcast_addr_remove(res->port_num, &res->mc_addr);
10655 }
10656
10657 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10658         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10659                                  mcast_addr_cmd, "mcast_addr");
10660 cmdline_parse_token_string_t cmd_mcast_addr_what =
10661         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10662                                  "add#remove");
10663 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10664         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10665 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10667
10668 cmdline_parse_inst_t cmd_mcast_addr = {
10669         .f = cmd_mcast_addr_parsed,
10670         .data = (void *)0,
10671         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10672                 "Add/Remove multicast MAC address on port_id",
10673         .tokens = {
10674                 (void *)&cmd_mcast_addr_cmd,
10675                 (void *)&cmd_mcast_addr_what,
10676                 (void *)&cmd_mcast_addr_portnum,
10677                 (void *)&cmd_mcast_addr_addr,
10678                 NULL,
10679         },
10680 };
10681
10682 /* l2 tunnel config
10683  * only support E-tag now.
10684  */
10685
10686 /* Ether type config */
10687 struct cmd_config_l2_tunnel_eth_type_result {
10688         cmdline_fixed_string_t port;
10689         cmdline_fixed_string_t config;
10690         cmdline_fixed_string_t all;
10691         uint8_t id;
10692         cmdline_fixed_string_t l2_tunnel;
10693         cmdline_fixed_string_t l2_tunnel_type;
10694         cmdline_fixed_string_t eth_type;
10695         uint16_t eth_type_val;
10696 };
10697
10698 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10699         TOKEN_STRING_INITIALIZER
10700                 (struct cmd_config_l2_tunnel_eth_type_result,
10701                  port, "port");
10702 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10703         TOKEN_STRING_INITIALIZER
10704                 (struct cmd_config_l2_tunnel_eth_type_result,
10705                  config, "config");
10706 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10707         TOKEN_STRING_INITIALIZER
10708                 (struct cmd_config_l2_tunnel_eth_type_result,
10709                  all, "all");
10710 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10711         TOKEN_NUM_INITIALIZER
10712                 (struct cmd_config_l2_tunnel_eth_type_result,
10713                  id, UINT8);
10714 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10715         TOKEN_STRING_INITIALIZER
10716                 (struct cmd_config_l2_tunnel_eth_type_result,
10717                  l2_tunnel, "l2-tunnel");
10718 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10719         TOKEN_STRING_INITIALIZER
10720                 (struct cmd_config_l2_tunnel_eth_type_result,
10721                  l2_tunnel_type, "E-tag");
10722 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10723         TOKEN_STRING_INITIALIZER
10724                 (struct cmd_config_l2_tunnel_eth_type_result,
10725                  eth_type, "ether-type");
10726 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10727         TOKEN_NUM_INITIALIZER
10728                 (struct cmd_config_l2_tunnel_eth_type_result,
10729                  eth_type_val, UINT16);
10730
10731 static enum rte_eth_tunnel_type
10732 str2fdir_l2_tunnel_type(char *string)
10733 {
10734         uint32_t i = 0;
10735
10736         static const struct {
10737                 char str[32];
10738                 enum rte_eth_tunnel_type type;
10739         } l2_tunnel_type_str[] = {
10740                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10741         };
10742
10743         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10744                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10745                         return l2_tunnel_type_str[i].type;
10746         }
10747         return RTE_TUNNEL_TYPE_NONE;
10748 }
10749
10750 /* ether type config for all ports */
10751 static void
10752 cmd_config_l2_tunnel_eth_type_all_parsed
10753         (void *parsed_result,
10754          __attribute__((unused)) struct cmdline *cl,
10755          __attribute__((unused)) void *data)
10756 {
10757         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10758         struct rte_eth_l2_tunnel_conf entry;
10759         portid_t pid;
10760
10761         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10762         entry.ether_type = res->eth_type_val;
10763
10764         RTE_ETH_FOREACH_DEV(pid) {
10765                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10766         }
10767 }
10768
10769 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10770         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10771         .data = NULL,
10772         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10773         .tokens = {
10774                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10775                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10776                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10777                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10778                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10779                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10780                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10781                 NULL,
10782         },
10783 };
10784
10785 /* ether type config for a specific port */
10786 static void
10787 cmd_config_l2_tunnel_eth_type_specific_parsed(
10788         void *parsed_result,
10789         __attribute__((unused)) struct cmdline *cl,
10790         __attribute__((unused)) void *data)
10791 {
10792         struct cmd_config_l2_tunnel_eth_type_result *res =
10793                  parsed_result;
10794         struct rte_eth_l2_tunnel_conf entry;
10795
10796         if (port_id_is_invalid(res->id, ENABLED_WARN))
10797                 return;
10798
10799         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10800         entry.ether_type = res->eth_type_val;
10801
10802         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10803 }
10804
10805 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10806         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10807         .data = NULL,
10808         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10809         .tokens = {
10810                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10811                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10812                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10813                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10814                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10815                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10816                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10817                 NULL,
10818         },
10819 };
10820
10821 /* Enable/disable l2 tunnel */
10822 struct cmd_config_l2_tunnel_en_dis_result {
10823         cmdline_fixed_string_t port;
10824         cmdline_fixed_string_t config;
10825         cmdline_fixed_string_t all;
10826         uint8_t id;
10827         cmdline_fixed_string_t l2_tunnel;
10828         cmdline_fixed_string_t l2_tunnel_type;
10829         cmdline_fixed_string_t en_dis;
10830 };
10831
10832 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10833         TOKEN_STRING_INITIALIZER
10834                 (struct cmd_config_l2_tunnel_en_dis_result,
10835                  port, "port");
10836 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10837         TOKEN_STRING_INITIALIZER
10838                 (struct cmd_config_l2_tunnel_en_dis_result,
10839                  config, "config");
10840 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10841         TOKEN_STRING_INITIALIZER
10842                 (struct cmd_config_l2_tunnel_en_dis_result,
10843                  all, "all");
10844 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10845         TOKEN_NUM_INITIALIZER
10846                 (struct cmd_config_l2_tunnel_en_dis_result,
10847                  id, UINT8);
10848 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10849         TOKEN_STRING_INITIALIZER
10850                 (struct cmd_config_l2_tunnel_en_dis_result,
10851                  l2_tunnel, "l2-tunnel");
10852 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10853         TOKEN_STRING_INITIALIZER
10854                 (struct cmd_config_l2_tunnel_en_dis_result,
10855                  l2_tunnel_type, "E-tag");
10856 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10857         TOKEN_STRING_INITIALIZER
10858                 (struct cmd_config_l2_tunnel_en_dis_result,
10859                  en_dis, "enable#disable");
10860
10861 /* enable/disable l2 tunnel for all ports */
10862 static void
10863 cmd_config_l2_tunnel_en_dis_all_parsed(
10864         void *parsed_result,
10865         __attribute__((unused)) struct cmdline *cl,
10866         __attribute__((unused)) void *data)
10867 {
10868         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10869         struct rte_eth_l2_tunnel_conf entry;
10870         portid_t pid;
10871         uint8_t en;
10872
10873         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10874
10875         if (!strcmp("enable", res->en_dis))
10876                 en = 1;
10877         else
10878                 en = 0;
10879
10880         RTE_ETH_FOREACH_DEV(pid) {
10881                 rte_eth_dev_l2_tunnel_offload_set(pid,
10882                                                   &entry,
10883                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10884                                                   en);
10885         }
10886 }
10887
10888 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10889         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10890         .data = NULL,
10891         .help_str = "port config all l2-tunnel E-tag enable|disable",
10892         .tokens = {
10893                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10894                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10895                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10896                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10897                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10898                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10899                 NULL,
10900         },
10901 };
10902
10903 /* enable/disable l2 tunnel for a port */
10904 static void
10905 cmd_config_l2_tunnel_en_dis_specific_parsed(
10906         void *parsed_result,
10907         __attribute__((unused)) struct cmdline *cl,
10908         __attribute__((unused)) void *data)
10909 {
10910         struct cmd_config_l2_tunnel_en_dis_result *res =
10911                 parsed_result;
10912         struct rte_eth_l2_tunnel_conf entry;
10913
10914         if (port_id_is_invalid(res->id, ENABLED_WARN))
10915                 return;
10916
10917         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10918
10919         if (!strcmp("enable", res->en_dis))
10920                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10921                                                   &entry,
10922                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10923                                                   1);
10924         else
10925                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10926                                                   &entry,
10927                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10928                                                   0);
10929 }
10930
10931 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10932         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10933         .data = NULL,
10934         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10935         .tokens = {
10936                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10937                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10938                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10939                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10940                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10941                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10942                 NULL,
10943         },
10944 };
10945
10946 /* E-tag configuration */
10947
10948 /* Common result structure for all E-tag configuration */
10949 struct cmd_config_e_tag_result {
10950         cmdline_fixed_string_t e_tag;
10951         cmdline_fixed_string_t set;
10952         cmdline_fixed_string_t insertion;
10953         cmdline_fixed_string_t stripping;
10954         cmdline_fixed_string_t forwarding;
10955         cmdline_fixed_string_t filter;
10956         cmdline_fixed_string_t add;
10957         cmdline_fixed_string_t del;
10958         cmdline_fixed_string_t on;
10959         cmdline_fixed_string_t off;
10960         cmdline_fixed_string_t on_off;
10961         cmdline_fixed_string_t port_tag_id;
10962         uint32_t port_tag_id_val;
10963         cmdline_fixed_string_t e_tag_id;
10964         uint16_t e_tag_id_val;
10965         cmdline_fixed_string_t dst_pool;
10966         uint8_t dst_pool_val;
10967         cmdline_fixed_string_t port;
10968         uint8_t port_id;
10969         cmdline_fixed_string_t vf;
10970         uint8_t vf_id;
10971 };
10972
10973 /* Common CLI fields for all E-tag configuration */
10974 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10975         TOKEN_STRING_INITIALIZER
10976                 (struct cmd_config_e_tag_result,
10977                  e_tag, "E-tag");
10978 cmdline_parse_token_string_t cmd_config_e_tag_set =
10979         TOKEN_STRING_INITIALIZER
10980                 (struct cmd_config_e_tag_result,
10981                  set, "set");
10982 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10983         TOKEN_STRING_INITIALIZER
10984                 (struct cmd_config_e_tag_result,
10985                  insertion, "insertion");
10986 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10987         TOKEN_STRING_INITIALIZER
10988                 (struct cmd_config_e_tag_result,
10989                  stripping, "stripping");
10990 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10991         TOKEN_STRING_INITIALIZER
10992                 (struct cmd_config_e_tag_result,
10993                  forwarding, "forwarding");
10994 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10995         TOKEN_STRING_INITIALIZER
10996                 (struct cmd_config_e_tag_result,
10997                  filter, "filter");
10998 cmdline_parse_token_string_t cmd_config_e_tag_add =
10999         TOKEN_STRING_INITIALIZER
11000                 (struct cmd_config_e_tag_result,
11001                  add, "add");
11002 cmdline_parse_token_string_t cmd_config_e_tag_del =
11003         TOKEN_STRING_INITIALIZER
11004                 (struct cmd_config_e_tag_result,
11005                  del, "del");
11006 cmdline_parse_token_string_t cmd_config_e_tag_on =
11007         TOKEN_STRING_INITIALIZER
11008                 (struct cmd_config_e_tag_result,
11009                  on, "on");
11010 cmdline_parse_token_string_t cmd_config_e_tag_off =
11011         TOKEN_STRING_INITIALIZER
11012                 (struct cmd_config_e_tag_result,
11013                  off, "off");
11014 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11015         TOKEN_STRING_INITIALIZER
11016                 (struct cmd_config_e_tag_result,
11017                  on_off, "on#off");
11018 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11019         TOKEN_STRING_INITIALIZER
11020                 (struct cmd_config_e_tag_result,
11021                  port_tag_id, "port-tag-id");
11022 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11023         TOKEN_NUM_INITIALIZER
11024                 (struct cmd_config_e_tag_result,
11025                  port_tag_id_val, UINT32);
11026 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11027         TOKEN_STRING_INITIALIZER
11028                 (struct cmd_config_e_tag_result,
11029                  e_tag_id, "e-tag-id");
11030 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11031         TOKEN_NUM_INITIALIZER
11032                 (struct cmd_config_e_tag_result,
11033                  e_tag_id_val, UINT16);
11034 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11035         TOKEN_STRING_INITIALIZER
11036                 (struct cmd_config_e_tag_result,
11037                  dst_pool, "dst-pool");
11038 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11039         TOKEN_NUM_INITIALIZER
11040                 (struct cmd_config_e_tag_result,
11041                  dst_pool_val, UINT8);
11042 cmdline_parse_token_string_t cmd_config_e_tag_port =
11043         TOKEN_STRING_INITIALIZER
11044                 (struct cmd_config_e_tag_result,
11045                  port, "port");
11046 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11047         TOKEN_NUM_INITIALIZER
11048                 (struct cmd_config_e_tag_result,
11049                  port_id, UINT8);
11050 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11051         TOKEN_STRING_INITIALIZER
11052                 (struct cmd_config_e_tag_result,
11053                  vf, "vf");
11054 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11055         TOKEN_NUM_INITIALIZER
11056                 (struct cmd_config_e_tag_result,
11057                  vf_id, UINT8);
11058
11059 /* E-tag insertion configuration */
11060 static void
11061 cmd_config_e_tag_insertion_en_parsed(
11062         void *parsed_result,
11063         __attribute__((unused)) struct cmdline *cl,
11064         __attribute__((unused)) void *data)
11065 {
11066         struct cmd_config_e_tag_result *res =
11067                 parsed_result;
11068         struct rte_eth_l2_tunnel_conf entry;
11069
11070         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11071                 return;
11072
11073         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11074         entry.tunnel_id = res->port_tag_id_val;
11075         entry.vf_id = res->vf_id;
11076         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11077                                           &entry,
11078                                           ETH_L2_TUNNEL_INSERTION_MASK,
11079                                           1);
11080 }
11081
11082 static void
11083 cmd_config_e_tag_insertion_dis_parsed(
11084         void *parsed_result,
11085         __attribute__((unused)) struct cmdline *cl,
11086         __attribute__((unused)) void *data)
11087 {
11088         struct cmd_config_e_tag_result *res =
11089                 parsed_result;
11090         struct rte_eth_l2_tunnel_conf entry;
11091
11092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11093                 return;
11094
11095         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11096         entry.vf_id = res->vf_id;
11097
11098         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11099                                           &entry,
11100                                           ETH_L2_TUNNEL_INSERTION_MASK,
11101                                           0);
11102 }
11103
11104 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11105         .f = cmd_config_e_tag_insertion_en_parsed,
11106         .data = NULL,
11107         .help_str = "E-tag ... : E-tag insertion enable",
11108         .tokens = {
11109                 (void *)&cmd_config_e_tag_e_tag,
11110                 (void *)&cmd_config_e_tag_set,
11111                 (void *)&cmd_config_e_tag_insertion,
11112                 (void *)&cmd_config_e_tag_on,
11113                 (void *)&cmd_config_e_tag_port_tag_id,
11114                 (void *)&cmd_config_e_tag_port_tag_id_val,
11115                 (void *)&cmd_config_e_tag_port,
11116                 (void *)&cmd_config_e_tag_port_id,
11117                 (void *)&cmd_config_e_tag_vf,
11118                 (void *)&cmd_config_e_tag_vf_id,
11119                 NULL,
11120         },
11121 };
11122
11123 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11124         .f = cmd_config_e_tag_insertion_dis_parsed,
11125         .data = NULL,
11126         .help_str = "E-tag ... : E-tag insertion disable",
11127         .tokens = {
11128                 (void *)&cmd_config_e_tag_e_tag,
11129                 (void *)&cmd_config_e_tag_set,
11130                 (void *)&cmd_config_e_tag_insertion,
11131                 (void *)&cmd_config_e_tag_off,
11132                 (void *)&cmd_config_e_tag_port,
11133                 (void *)&cmd_config_e_tag_port_id,
11134                 (void *)&cmd_config_e_tag_vf,
11135                 (void *)&cmd_config_e_tag_vf_id,
11136                 NULL,
11137         },
11138 };
11139
11140 /* E-tag stripping configuration */
11141 static void
11142 cmd_config_e_tag_stripping_parsed(
11143         void *parsed_result,
11144         __attribute__((unused)) struct cmdline *cl,
11145         __attribute__((unused)) void *data)
11146 {
11147         struct cmd_config_e_tag_result *res =
11148                 parsed_result;
11149         struct rte_eth_l2_tunnel_conf entry;
11150
11151         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11152                 return;
11153
11154         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11155
11156         if (!strcmp(res->on_off, "on"))
11157                 rte_eth_dev_l2_tunnel_offload_set
11158                         (res->port_id,
11159                          &entry,
11160                          ETH_L2_TUNNEL_STRIPPING_MASK,
11161                          1);
11162         else
11163                 rte_eth_dev_l2_tunnel_offload_set
11164                         (res->port_id,
11165                          &entry,
11166                          ETH_L2_TUNNEL_STRIPPING_MASK,
11167                          0);
11168 }
11169
11170 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11171         .f = cmd_config_e_tag_stripping_parsed,
11172         .data = NULL,
11173         .help_str = "E-tag ... : E-tag stripping enable/disable",
11174         .tokens = {
11175                 (void *)&cmd_config_e_tag_e_tag,
11176                 (void *)&cmd_config_e_tag_set,
11177                 (void *)&cmd_config_e_tag_stripping,
11178                 (void *)&cmd_config_e_tag_on_off,
11179                 (void *)&cmd_config_e_tag_port,
11180                 (void *)&cmd_config_e_tag_port_id,
11181                 NULL,
11182         },
11183 };
11184
11185 /* E-tag forwarding configuration */
11186 static void
11187 cmd_config_e_tag_forwarding_parsed(
11188         void *parsed_result,
11189         __attribute__((unused)) struct cmdline *cl,
11190         __attribute__((unused)) void *data)
11191 {
11192         struct cmd_config_e_tag_result *res = parsed_result;
11193         struct rte_eth_l2_tunnel_conf entry;
11194
11195         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11196                 return;
11197
11198         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11199
11200         if (!strcmp(res->on_off, "on"))
11201                 rte_eth_dev_l2_tunnel_offload_set
11202                         (res->port_id,
11203                          &entry,
11204                          ETH_L2_TUNNEL_FORWARDING_MASK,
11205                          1);
11206         else
11207                 rte_eth_dev_l2_tunnel_offload_set
11208                         (res->port_id,
11209                          &entry,
11210                          ETH_L2_TUNNEL_FORWARDING_MASK,
11211                          0);
11212 }
11213
11214 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11215         .f = cmd_config_e_tag_forwarding_parsed,
11216         .data = NULL,
11217         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11218         .tokens = {
11219                 (void *)&cmd_config_e_tag_e_tag,
11220                 (void *)&cmd_config_e_tag_set,
11221                 (void *)&cmd_config_e_tag_forwarding,
11222                 (void *)&cmd_config_e_tag_on_off,
11223                 (void *)&cmd_config_e_tag_port,
11224                 (void *)&cmd_config_e_tag_port_id,
11225                 NULL,
11226         },
11227 };
11228
11229 /* E-tag filter configuration */
11230 static void
11231 cmd_config_e_tag_filter_add_parsed(
11232         void *parsed_result,
11233         __attribute__((unused)) struct cmdline *cl,
11234         __attribute__((unused)) void *data)
11235 {
11236         struct cmd_config_e_tag_result *res = parsed_result;
11237         struct rte_eth_l2_tunnel_conf entry;
11238         int ret = 0;
11239
11240         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11241                 return;
11242
11243         if (res->e_tag_id_val > 0x3fff) {
11244                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11245                 return;
11246         }
11247
11248         ret = rte_eth_dev_filter_supported(res->port_id,
11249                                            RTE_ETH_FILTER_L2_TUNNEL);
11250         if (ret < 0) {
11251                 printf("E-tag filter is not supported on port %u.\n",
11252                        res->port_id);
11253                 return;
11254         }
11255
11256         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11257         entry.tunnel_id = res->e_tag_id_val;
11258         entry.pool = res->dst_pool_val;
11259
11260         ret = rte_eth_dev_filter_ctrl(res->port_id,
11261                                       RTE_ETH_FILTER_L2_TUNNEL,
11262                                       RTE_ETH_FILTER_ADD,
11263                                       &entry);
11264         if (ret < 0)
11265                 printf("E-tag filter programming error: (%s)\n",
11266                        strerror(-ret));
11267 }
11268
11269 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11270         .f = cmd_config_e_tag_filter_add_parsed,
11271         .data = NULL,
11272         .help_str = "E-tag ... : E-tag filter add",
11273         .tokens = {
11274                 (void *)&cmd_config_e_tag_e_tag,
11275                 (void *)&cmd_config_e_tag_set,
11276                 (void *)&cmd_config_e_tag_filter,
11277                 (void *)&cmd_config_e_tag_add,
11278                 (void *)&cmd_config_e_tag_e_tag_id,
11279                 (void *)&cmd_config_e_tag_e_tag_id_val,
11280                 (void *)&cmd_config_e_tag_dst_pool,
11281                 (void *)&cmd_config_e_tag_dst_pool_val,
11282                 (void *)&cmd_config_e_tag_port,
11283                 (void *)&cmd_config_e_tag_port_id,
11284                 NULL,
11285         },
11286 };
11287
11288 static void
11289 cmd_config_e_tag_filter_del_parsed(
11290         void *parsed_result,
11291         __attribute__((unused)) struct cmdline *cl,
11292         __attribute__((unused)) void *data)
11293 {
11294         struct cmd_config_e_tag_result *res = parsed_result;
11295         struct rte_eth_l2_tunnel_conf entry;
11296         int ret = 0;
11297
11298         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11299                 return;
11300
11301         if (res->e_tag_id_val > 0x3fff) {
11302                 printf("e-tag-id must be less than 0x3fff.\n");
11303                 return;
11304         }
11305
11306         ret = rte_eth_dev_filter_supported(res->port_id,
11307                                            RTE_ETH_FILTER_L2_TUNNEL);
11308         if (ret < 0) {
11309                 printf("E-tag filter is not supported on port %u.\n",
11310                        res->port_id);
11311                 return;
11312         }
11313
11314         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11315         entry.tunnel_id = res->e_tag_id_val;
11316
11317         ret = rte_eth_dev_filter_ctrl(res->port_id,
11318                                       RTE_ETH_FILTER_L2_TUNNEL,
11319                                       RTE_ETH_FILTER_DELETE,
11320                                       &entry);
11321         if (ret < 0)
11322                 printf("E-tag filter programming error: (%s)\n",
11323                        strerror(-ret));
11324 }
11325
11326 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11327         .f = cmd_config_e_tag_filter_del_parsed,
11328         .data = NULL,
11329         .help_str = "E-tag ... : E-tag filter delete",
11330         .tokens = {
11331                 (void *)&cmd_config_e_tag_e_tag,
11332                 (void *)&cmd_config_e_tag_set,
11333                 (void *)&cmd_config_e_tag_filter,
11334                 (void *)&cmd_config_e_tag_del,
11335                 (void *)&cmd_config_e_tag_e_tag_id,
11336                 (void *)&cmd_config_e_tag_e_tag_id_val,
11337                 (void *)&cmd_config_e_tag_port,
11338                 (void *)&cmd_config_e_tag_port_id,
11339                 NULL,
11340         },
11341 };
11342
11343 /* vf vlan anti spoof configuration */
11344
11345 /* Common result structure for vf vlan anti spoof */
11346 struct cmd_vf_vlan_anti_spoof_result {
11347         cmdline_fixed_string_t set;
11348         cmdline_fixed_string_t vf;
11349         cmdline_fixed_string_t vlan;
11350         cmdline_fixed_string_t antispoof;
11351         uint8_t port_id;
11352         uint32_t vf_id;
11353         cmdline_fixed_string_t on_off;
11354 };
11355
11356 /* Common CLI fields for vf vlan anti spoof enable disable */
11357 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11358         TOKEN_STRING_INITIALIZER
11359                 (struct cmd_vf_vlan_anti_spoof_result,
11360                  set, "set");
11361 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11362         TOKEN_STRING_INITIALIZER
11363                 (struct cmd_vf_vlan_anti_spoof_result,
11364                  vf, "vf");
11365 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11366         TOKEN_STRING_INITIALIZER
11367                 (struct cmd_vf_vlan_anti_spoof_result,
11368                  vlan, "vlan");
11369 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11370         TOKEN_STRING_INITIALIZER
11371                 (struct cmd_vf_vlan_anti_spoof_result,
11372                  antispoof, "antispoof");
11373 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11374         TOKEN_NUM_INITIALIZER
11375                 (struct cmd_vf_vlan_anti_spoof_result,
11376                  port_id, UINT8);
11377 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11378         TOKEN_NUM_INITIALIZER
11379                 (struct cmd_vf_vlan_anti_spoof_result,
11380                  vf_id, UINT32);
11381 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11382         TOKEN_STRING_INITIALIZER
11383                 (struct cmd_vf_vlan_anti_spoof_result,
11384                  on_off, "on#off");
11385
11386 static void
11387 cmd_set_vf_vlan_anti_spoof_parsed(
11388         void *parsed_result,
11389         __attribute__((unused)) struct cmdline *cl,
11390         __attribute__((unused)) void *data)
11391 {
11392         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11393         int ret = -ENOTSUP;
11394
11395         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11396
11397         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11398                 return;
11399
11400 #ifdef RTE_LIBRTE_IXGBE_PMD
11401         if (ret == -ENOTSUP)
11402                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11403                                 res->vf_id, is_on);
11404 #endif
11405 #ifdef RTE_LIBRTE_I40E_PMD
11406         if (ret == -ENOTSUP)
11407                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11408                                 res->vf_id, is_on);
11409 #endif
11410 #ifdef RTE_LIBRTE_BNXT_PMD
11411         if (ret == -ENOTSUP)
11412                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11413                                 res->vf_id, is_on);
11414 #endif
11415
11416         switch (ret) {
11417         case 0:
11418                 break;
11419         case -EINVAL:
11420                 printf("invalid vf_id %d\n", res->vf_id);
11421                 break;
11422         case -ENODEV:
11423                 printf("invalid port_id %d\n", res->port_id);
11424                 break;
11425         case -ENOTSUP:
11426                 printf("function not implemented\n");
11427                 break;
11428         default:
11429                 printf("programming error: (%s)\n", strerror(-ret));
11430         }
11431 }
11432
11433 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11434         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11435         .data = NULL,
11436         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11437         .tokens = {
11438                 (void *)&cmd_vf_vlan_anti_spoof_set,
11439                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11440                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11441                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11442                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11443                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11444                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11445                 NULL,
11446         },
11447 };
11448
11449 /* vf mac anti spoof configuration */
11450
11451 /* Common result structure for vf mac anti spoof */
11452 struct cmd_vf_mac_anti_spoof_result {
11453         cmdline_fixed_string_t set;
11454         cmdline_fixed_string_t vf;
11455         cmdline_fixed_string_t mac;
11456         cmdline_fixed_string_t antispoof;
11457         uint8_t port_id;
11458         uint32_t vf_id;
11459         cmdline_fixed_string_t on_off;
11460 };
11461
11462 /* Common CLI fields for vf mac anti spoof enable disable */
11463 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11464         TOKEN_STRING_INITIALIZER
11465                 (struct cmd_vf_mac_anti_spoof_result,
11466                  set, "set");
11467 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11468         TOKEN_STRING_INITIALIZER
11469                 (struct cmd_vf_mac_anti_spoof_result,
11470                  vf, "vf");
11471 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11472         TOKEN_STRING_INITIALIZER
11473                 (struct cmd_vf_mac_anti_spoof_result,
11474                  mac, "mac");
11475 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11476         TOKEN_STRING_INITIALIZER
11477                 (struct cmd_vf_mac_anti_spoof_result,
11478                  antispoof, "antispoof");
11479 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11480         TOKEN_NUM_INITIALIZER
11481                 (struct cmd_vf_mac_anti_spoof_result,
11482                  port_id, UINT8);
11483 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11484         TOKEN_NUM_INITIALIZER
11485                 (struct cmd_vf_mac_anti_spoof_result,
11486                  vf_id, UINT32);
11487 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11488         TOKEN_STRING_INITIALIZER
11489                 (struct cmd_vf_mac_anti_spoof_result,
11490                  on_off, "on#off");
11491
11492 static void
11493 cmd_set_vf_mac_anti_spoof_parsed(
11494         void *parsed_result,
11495         __attribute__((unused)) struct cmdline *cl,
11496         __attribute__((unused)) void *data)
11497 {
11498         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11499         int ret = -ENOTSUP;
11500
11501         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11502
11503         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11504                 return;
11505
11506 #ifdef RTE_LIBRTE_IXGBE_PMD
11507         if (ret == -ENOTSUP)
11508                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11509                         res->vf_id, is_on);
11510 #endif
11511 #ifdef RTE_LIBRTE_I40E_PMD
11512         if (ret == -ENOTSUP)
11513                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11514                         res->vf_id, is_on);
11515 #endif
11516 #ifdef RTE_LIBRTE_BNXT_PMD
11517         if (ret == -ENOTSUP)
11518                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11519                         res->vf_id, is_on);
11520 #endif
11521
11522         switch (ret) {
11523         case 0:
11524                 break;
11525         case -EINVAL:
11526                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11527                 break;
11528         case -ENODEV:
11529                 printf("invalid port_id %d\n", res->port_id);
11530                 break;
11531         case -ENOTSUP:
11532                 printf("function not implemented\n");
11533                 break;
11534         default:
11535                 printf("programming error: (%s)\n", strerror(-ret));
11536         }
11537 }
11538
11539 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11540         .f = cmd_set_vf_mac_anti_spoof_parsed,
11541         .data = NULL,
11542         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11543         .tokens = {
11544                 (void *)&cmd_vf_mac_anti_spoof_set,
11545                 (void *)&cmd_vf_mac_anti_spoof_vf,
11546                 (void *)&cmd_vf_mac_anti_spoof_mac,
11547                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11548                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11549                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11550                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11551                 NULL,
11552         },
11553 };
11554
11555 /* vf vlan strip queue configuration */
11556
11557 /* Common result structure for vf mac anti spoof */
11558 struct cmd_vf_vlan_stripq_result {
11559         cmdline_fixed_string_t set;
11560         cmdline_fixed_string_t vf;
11561         cmdline_fixed_string_t vlan;
11562         cmdline_fixed_string_t stripq;
11563         portid_t port_id;
11564         uint16_t vf_id;
11565         cmdline_fixed_string_t on_off;
11566 };
11567
11568 /* Common CLI fields for vf vlan strip enable disable */
11569 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11570         TOKEN_STRING_INITIALIZER
11571                 (struct cmd_vf_vlan_stripq_result,
11572                  set, "set");
11573 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11574         TOKEN_STRING_INITIALIZER
11575                 (struct cmd_vf_vlan_stripq_result,
11576                  vf, "vf");
11577 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11578         TOKEN_STRING_INITIALIZER
11579                 (struct cmd_vf_vlan_stripq_result,
11580                  vlan, "vlan");
11581 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11582         TOKEN_STRING_INITIALIZER
11583                 (struct cmd_vf_vlan_stripq_result,
11584                  stripq, "stripq");
11585 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11586         TOKEN_NUM_INITIALIZER
11587                 (struct cmd_vf_vlan_stripq_result,
11588                  port_id, UINT8);
11589 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11590         TOKEN_NUM_INITIALIZER
11591                 (struct cmd_vf_vlan_stripq_result,
11592                  vf_id, UINT16);
11593 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11594         TOKEN_STRING_INITIALIZER
11595                 (struct cmd_vf_vlan_stripq_result,
11596                  on_off, "on#off");
11597
11598 static void
11599 cmd_set_vf_vlan_stripq_parsed(
11600         void *parsed_result,
11601         __attribute__((unused)) struct cmdline *cl,
11602         __attribute__((unused)) void *data)
11603 {
11604         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11605         int ret = -ENOTSUP;
11606
11607         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11608
11609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11610                 return;
11611
11612 #ifdef RTE_LIBRTE_IXGBE_PMD
11613         if (ret == -ENOTSUP)
11614                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11615                         res->vf_id, is_on);
11616 #endif
11617 #ifdef RTE_LIBRTE_I40E_PMD
11618         if (ret == -ENOTSUP)
11619                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11620                         res->vf_id, is_on);
11621 #endif
11622 #ifdef RTE_LIBRTE_BNXT_PMD
11623         if (ret == -ENOTSUP)
11624                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11625                         res->vf_id, is_on);
11626 #endif
11627
11628         switch (ret) {
11629         case 0:
11630                 break;
11631         case -EINVAL:
11632                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11633                 break;
11634         case -ENODEV:
11635                 printf("invalid port_id %d\n", res->port_id);
11636                 break;
11637         case -ENOTSUP:
11638                 printf("function not implemented\n");
11639                 break;
11640         default:
11641                 printf("programming error: (%s)\n", strerror(-ret));
11642         }
11643 }
11644
11645 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11646         .f = cmd_set_vf_vlan_stripq_parsed,
11647         .data = NULL,
11648         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11649         .tokens = {
11650                 (void *)&cmd_vf_vlan_stripq_set,
11651                 (void *)&cmd_vf_vlan_stripq_vf,
11652                 (void *)&cmd_vf_vlan_stripq_vlan,
11653                 (void *)&cmd_vf_vlan_stripq_stripq,
11654                 (void *)&cmd_vf_vlan_stripq_port_id,
11655                 (void *)&cmd_vf_vlan_stripq_vf_id,
11656                 (void *)&cmd_vf_vlan_stripq_on_off,
11657                 NULL,
11658         },
11659 };
11660
11661 /* vf vlan insert configuration */
11662
11663 /* Common result structure for vf vlan insert */
11664 struct cmd_vf_vlan_insert_result {
11665         cmdline_fixed_string_t set;
11666         cmdline_fixed_string_t vf;
11667         cmdline_fixed_string_t vlan;
11668         cmdline_fixed_string_t insert;
11669         uint8_t port_id;
11670         uint16_t vf_id;
11671         uint16_t vlan_id;
11672 };
11673
11674 /* Common CLI fields for vf vlan insert enable disable */
11675 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11676         TOKEN_STRING_INITIALIZER
11677                 (struct cmd_vf_vlan_insert_result,
11678                  set, "set");
11679 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11680         TOKEN_STRING_INITIALIZER
11681                 (struct cmd_vf_vlan_insert_result,
11682                  vf, "vf");
11683 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11684         TOKEN_STRING_INITIALIZER
11685                 (struct cmd_vf_vlan_insert_result,
11686                  vlan, "vlan");
11687 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11688         TOKEN_STRING_INITIALIZER
11689                 (struct cmd_vf_vlan_insert_result,
11690                  insert, "insert");
11691 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11692         TOKEN_NUM_INITIALIZER
11693                 (struct cmd_vf_vlan_insert_result,
11694                  port_id, UINT8);
11695 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11696         TOKEN_NUM_INITIALIZER
11697                 (struct cmd_vf_vlan_insert_result,
11698                  vf_id, UINT16);
11699 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11700         TOKEN_NUM_INITIALIZER
11701                 (struct cmd_vf_vlan_insert_result,
11702                  vlan_id, UINT16);
11703
11704 static void
11705 cmd_set_vf_vlan_insert_parsed(
11706         void *parsed_result,
11707         __attribute__((unused)) struct cmdline *cl,
11708         __attribute__((unused)) void *data)
11709 {
11710         struct cmd_vf_vlan_insert_result *res = parsed_result;
11711         int ret = -ENOTSUP;
11712
11713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11714                 return;
11715
11716 #ifdef RTE_LIBRTE_IXGBE_PMD
11717         if (ret == -ENOTSUP)
11718                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11719                         res->vlan_id);
11720 #endif
11721 #ifdef RTE_LIBRTE_I40E_PMD
11722         if (ret == -ENOTSUP)
11723                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11724                         res->vlan_id);
11725 #endif
11726 #ifdef RTE_LIBRTE_BNXT_PMD
11727         if (ret == -ENOTSUP)
11728                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11729                         res->vlan_id);
11730 #endif
11731
11732         switch (ret) {
11733         case 0:
11734                 break;
11735         case -EINVAL:
11736                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11737                 break;
11738         case -ENODEV:
11739                 printf("invalid port_id %d\n", res->port_id);
11740                 break;
11741         case -ENOTSUP:
11742                 printf("function not implemented\n");
11743                 break;
11744         default:
11745                 printf("programming error: (%s)\n", strerror(-ret));
11746         }
11747 }
11748
11749 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11750         .f = cmd_set_vf_vlan_insert_parsed,
11751         .data = NULL,
11752         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11753         .tokens = {
11754                 (void *)&cmd_vf_vlan_insert_set,
11755                 (void *)&cmd_vf_vlan_insert_vf,
11756                 (void *)&cmd_vf_vlan_insert_vlan,
11757                 (void *)&cmd_vf_vlan_insert_insert,
11758                 (void *)&cmd_vf_vlan_insert_port_id,
11759                 (void *)&cmd_vf_vlan_insert_vf_id,
11760                 (void *)&cmd_vf_vlan_insert_vlan_id,
11761                 NULL,
11762         },
11763 };
11764
11765 /* tx loopback configuration */
11766
11767 /* Common result structure for tx loopback */
11768 struct cmd_tx_loopback_result {
11769         cmdline_fixed_string_t set;
11770         cmdline_fixed_string_t tx;
11771         cmdline_fixed_string_t loopback;
11772         uint8_t port_id;
11773         cmdline_fixed_string_t on_off;
11774 };
11775
11776 /* Common CLI fields for tx loopback enable disable */
11777 cmdline_parse_token_string_t cmd_tx_loopback_set =
11778         TOKEN_STRING_INITIALIZER
11779                 (struct cmd_tx_loopback_result,
11780                  set, "set");
11781 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11782         TOKEN_STRING_INITIALIZER
11783                 (struct cmd_tx_loopback_result,
11784                  tx, "tx");
11785 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_tx_loopback_result,
11788                  loopback, "loopback");
11789 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11790         TOKEN_NUM_INITIALIZER
11791                 (struct cmd_tx_loopback_result,
11792                  port_id, UINT8);
11793 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_tx_loopback_result,
11796                  on_off, "on#off");
11797
11798 static void
11799 cmd_set_tx_loopback_parsed(
11800         void *parsed_result,
11801         __attribute__((unused)) struct cmdline *cl,
11802         __attribute__((unused)) void *data)
11803 {
11804         struct cmd_tx_loopback_result *res = parsed_result;
11805         int ret = -ENOTSUP;
11806
11807         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11808
11809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11810                 return;
11811
11812 #ifdef RTE_LIBRTE_IXGBE_PMD
11813         if (ret == -ENOTSUP)
11814                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11815 #endif
11816 #ifdef RTE_LIBRTE_I40E_PMD
11817         if (ret == -ENOTSUP)
11818                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11819 #endif
11820 #ifdef RTE_LIBRTE_BNXT_PMD
11821         if (ret == -ENOTSUP)
11822                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11823 #endif
11824
11825         switch (ret) {
11826         case 0:
11827                 break;
11828         case -EINVAL:
11829                 printf("invalid is_on %d\n", is_on);
11830                 break;
11831         case -ENODEV:
11832                 printf("invalid port_id %d\n", res->port_id);
11833                 break;
11834         case -ENOTSUP:
11835                 printf("function not implemented\n");
11836                 break;
11837         default:
11838                 printf("programming error: (%s)\n", strerror(-ret));
11839         }
11840 }
11841
11842 cmdline_parse_inst_t cmd_set_tx_loopback = {
11843         .f = cmd_set_tx_loopback_parsed,
11844         .data = NULL,
11845         .help_str = "set tx loopback <port_id> on|off",
11846         .tokens = {
11847                 (void *)&cmd_tx_loopback_set,
11848                 (void *)&cmd_tx_loopback_tx,
11849                 (void *)&cmd_tx_loopback_loopback,
11850                 (void *)&cmd_tx_loopback_port_id,
11851                 (void *)&cmd_tx_loopback_on_off,
11852                 NULL,
11853         },
11854 };
11855
11856 /* all queues drop enable configuration */
11857
11858 /* Common result structure for all queues drop enable */
11859 struct cmd_all_queues_drop_en_result {
11860         cmdline_fixed_string_t set;
11861         cmdline_fixed_string_t all;
11862         cmdline_fixed_string_t queues;
11863         cmdline_fixed_string_t drop;
11864         uint8_t port_id;
11865         cmdline_fixed_string_t on_off;
11866 };
11867
11868 /* Common CLI fields for tx loopback enable disable */
11869 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11870         TOKEN_STRING_INITIALIZER
11871                 (struct cmd_all_queues_drop_en_result,
11872                  set, "set");
11873 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11874         TOKEN_STRING_INITIALIZER
11875                 (struct cmd_all_queues_drop_en_result,
11876                  all, "all");
11877 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11878         TOKEN_STRING_INITIALIZER
11879                 (struct cmd_all_queues_drop_en_result,
11880                  queues, "queues");
11881 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11882         TOKEN_STRING_INITIALIZER
11883                 (struct cmd_all_queues_drop_en_result,
11884                  drop, "drop");
11885 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11886         TOKEN_NUM_INITIALIZER
11887                 (struct cmd_all_queues_drop_en_result,
11888                  port_id, UINT8);
11889 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11890         TOKEN_STRING_INITIALIZER
11891                 (struct cmd_all_queues_drop_en_result,
11892                  on_off, "on#off");
11893
11894 static void
11895 cmd_set_all_queues_drop_en_parsed(
11896         void *parsed_result,
11897         __attribute__((unused)) struct cmdline *cl,
11898         __attribute__((unused)) void *data)
11899 {
11900         struct cmd_all_queues_drop_en_result *res = parsed_result;
11901         int ret = -ENOTSUP;
11902         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11903
11904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11905                 return;
11906
11907 #ifdef RTE_LIBRTE_IXGBE_PMD
11908         if (ret == -ENOTSUP)
11909                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11910 #endif
11911 #ifdef RTE_LIBRTE_BNXT_PMD
11912         if (ret == -ENOTSUP)
11913                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11914 #endif
11915         switch (ret) {
11916         case 0:
11917                 break;
11918         case -EINVAL:
11919                 printf("invalid is_on %d\n", is_on);
11920                 break;
11921         case -ENODEV:
11922                 printf("invalid port_id %d\n", res->port_id);
11923                 break;
11924         case -ENOTSUP:
11925                 printf("function not implemented\n");
11926                 break;
11927         default:
11928                 printf("programming error: (%s)\n", strerror(-ret));
11929         }
11930 }
11931
11932 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11933         .f = cmd_set_all_queues_drop_en_parsed,
11934         .data = NULL,
11935         .help_str = "set all queues drop <port_id> on|off",
11936         .tokens = {
11937                 (void *)&cmd_all_queues_drop_en_set,
11938                 (void *)&cmd_all_queues_drop_en_all,
11939                 (void *)&cmd_all_queues_drop_en_queues,
11940                 (void *)&cmd_all_queues_drop_en_drop,
11941                 (void *)&cmd_all_queues_drop_en_port_id,
11942                 (void *)&cmd_all_queues_drop_en_on_off,
11943                 NULL,
11944         },
11945 };
11946
11947 /* vf split drop enable configuration */
11948
11949 /* Common result structure for vf split drop enable */
11950 struct cmd_vf_split_drop_en_result {
11951         cmdline_fixed_string_t set;
11952         cmdline_fixed_string_t vf;
11953         cmdline_fixed_string_t split;
11954         cmdline_fixed_string_t drop;
11955         uint8_t port_id;
11956         uint16_t vf_id;
11957         cmdline_fixed_string_t on_off;
11958 };
11959
11960 /* Common CLI fields for vf split drop enable disable */
11961 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11962         TOKEN_STRING_INITIALIZER
11963                 (struct cmd_vf_split_drop_en_result,
11964                  set, "set");
11965 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11966         TOKEN_STRING_INITIALIZER
11967                 (struct cmd_vf_split_drop_en_result,
11968                  vf, "vf");
11969 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11970         TOKEN_STRING_INITIALIZER
11971                 (struct cmd_vf_split_drop_en_result,
11972                  split, "split");
11973 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11974         TOKEN_STRING_INITIALIZER
11975                 (struct cmd_vf_split_drop_en_result,
11976                  drop, "drop");
11977 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11978         TOKEN_NUM_INITIALIZER
11979                 (struct cmd_vf_split_drop_en_result,
11980                  port_id, UINT8);
11981 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11982         TOKEN_NUM_INITIALIZER
11983                 (struct cmd_vf_split_drop_en_result,
11984                  vf_id, UINT16);
11985 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11986         TOKEN_STRING_INITIALIZER
11987                 (struct cmd_vf_split_drop_en_result,
11988                  on_off, "on#off");
11989
11990 static void
11991 cmd_set_vf_split_drop_en_parsed(
11992         void *parsed_result,
11993         __attribute__((unused)) struct cmdline *cl,
11994         __attribute__((unused)) void *data)
11995 {
11996         struct cmd_vf_split_drop_en_result *res = parsed_result;
11997         int ret = -ENOTSUP;
11998         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11999
12000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12001                 return;
12002
12003 #ifdef RTE_LIBRTE_IXGBE_PMD
12004         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12005                         is_on);
12006 #endif
12007         switch (ret) {
12008         case 0:
12009                 break;
12010         case -EINVAL:
12011                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12012                 break;
12013         case -ENODEV:
12014                 printf("invalid port_id %d\n", res->port_id);
12015                 break;
12016         case -ENOTSUP:
12017                 printf("not supported on port %d\n", res->port_id);
12018                 break;
12019         default:
12020                 printf("programming error: (%s)\n", strerror(-ret));
12021         }
12022 }
12023
12024 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12025         .f = cmd_set_vf_split_drop_en_parsed,
12026         .data = NULL,
12027         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12028         .tokens = {
12029                 (void *)&cmd_vf_split_drop_en_set,
12030                 (void *)&cmd_vf_split_drop_en_vf,
12031                 (void *)&cmd_vf_split_drop_en_split,
12032                 (void *)&cmd_vf_split_drop_en_drop,
12033                 (void *)&cmd_vf_split_drop_en_port_id,
12034                 (void *)&cmd_vf_split_drop_en_vf_id,
12035                 (void *)&cmd_vf_split_drop_en_on_off,
12036                 NULL,
12037         },
12038 };
12039
12040 /* vf mac address configuration */
12041
12042 /* Common result structure for vf mac address */
12043 struct cmd_set_vf_mac_addr_result {
12044         cmdline_fixed_string_t set;
12045         cmdline_fixed_string_t vf;
12046         cmdline_fixed_string_t mac;
12047         cmdline_fixed_string_t addr;
12048         uint8_t port_id;
12049         uint16_t vf_id;
12050         struct ether_addr mac_addr;
12051
12052 };
12053
12054 /* Common CLI fields for vf split drop enable disable */
12055 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12056         TOKEN_STRING_INITIALIZER
12057                 (struct cmd_set_vf_mac_addr_result,
12058                  set, "set");
12059 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12060         TOKEN_STRING_INITIALIZER
12061                 (struct cmd_set_vf_mac_addr_result,
12062                  vf, "vf");
12063 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12064         TOKEN_STRING_INITIALIZER
12065                 (struct cmd_set_vf_mac_addr_result,
12066                  mac, "mac");
12067 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_set_vf_mac_addr_result,
12070                  addr, "addr");
12071 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12072         TOKEN_NUM_INITIALIZER
12073                 (struct cmd_set_vf_mac_addr_result,
12074                  port_id, UINT8);
12075 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12076         TOKEN_NUM_INITIALIZER
12077                 (struct cmd_set_vf_mac_addr_result,
12078                  vf_id, UINT16);
12079 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12080         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12081                  mac_addr);
12082
12083 static void
12084 cmd_set_vf_mac_addr_parsed(
12085         void *parsed_result,
12086         __attribute__((unused)) struct cmdline *cl,
12087         __attribute__((unused)) void *data)
12088 {
12089         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12090         int ret = -ENOTSUP;
12091
12092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12093                 return;
12094
12095 #ifdef RTE_LIBRTE_IXGBE_PMD
12096         if (ret == -ENOTSUP)
12097                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12098                                 &res->mac_addr);
12099 #endif
12100 #ifdef RTE_LIBRTE_I40E_PMD
12101         if (ret == -ENOTSUP)
12102                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12103                                 &res->mac_addr);
12104 #endif
12105 #ifdef RTE_LIBRTE_BNXT_PMD
12106         if (ret == -ENOTSUP)
12107                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12108                                 &res->mac_addr);
12109 #endif
12110
12111         switch (ret) {
12112         case 0:
12113                 break;
12114         case -EINVAL:
12115                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12116                 break;
12117         case -ENODEV:
12118                 printf("invalid port_id %d\n", res->port_id);
12119                 break;
12120         case -ENOTSUP:
12121                 printf("function not implemented\n");
12122                 break;
12123         default:
12124                 printf("programming error: (%s)\n", strerror(-ret));
12125         }
12126 }
12127
12128 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12129         .f = cmd_set_vf_mac_addr_parsed,
12130         .data = NULL,
12131         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12132         .tokens = {
12133                 (void *)&cmd_set_vf_mac_addr_set,
12134                 (void *)&cmd_set_vf_mac_addr_vf,
12135                 (void *)&cmd_set_vf_mac_addr_mac,
12136                 (void *)&cmd_set_vf_mac_addr_addr,
12137                 (void *)&cmd_set_vf_mac_addr_port_id,
12138                 (void *)&cmd_set_vf_mac_addr_vf_id,
12139                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12140                 NULL,
12141         },
12142 };
12143
12144 /* MACsec configuration */
12145
12146 /* Common result structure for MACsec offload enable */
12147 struct cmd_macsec_offload_on_result {
12148         cmdline_fixed_string_t set;
12149         cmdline_fixed_string_t macsec;
12150         cmdline_fixed_string_t offload;
12151         uint8_t port_id;
12152         cmdline_fixed_string_t on;
12153         cmdline_fixed_string_t encrypt;
12154         cmdline_fixed_string_t en_on_off;
12155         cmdline_fixed_string_t replay_protect;
12156         cmdline_fixed_string_t rp_on_off;
12157 };
12158
12159 /* Common CLI fields for MACsec offload disable */
12160 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12161         TOKEN_STRING_INITIALIZER
12162                 (struct cmd_macsec_offload_on_result,
12163                  set, "set");
12164 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12165         TOKEN_STRING_INITIALIZER
12166                 (struct cmd_macsec_offload_on_result,
12167                  macsec, "macsec");
12168 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12169         TOKEN_STRING_INITIALIZER
12170                 (struct cmd_macsec_offload_on_result,
12171                  offload, "offload");
12172 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12173         TOKEN_NUM_INITIALIZER
12174                 (struct cmd_macsec_offload_on_result,
12175                  port_id, UINT8);
12176 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12177         TOKEN_STRING_INITIALIZER
12178                 (struct cmd_macsec_offload_on_result,
12179                  on, "on");
12180 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12181         TOKEN_STRING_INITIALIZER
12182                 (struct cmd_macsec_offload_on_result,
12183                  encrypt, "encrypt");
12184 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12185         TOKEN_STRING_INITIALIZER
12186                 (struct cmd_macsec_offload_on_result,
12187                  en_on_off, "on#off");
12188 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12189         TOKEN_STRING_INITIALIZER
12190                 (struct cmd_macsec_offload_on_result,
12191                  replay_protect, "replay-protect");
12192 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12193         TOKEN_STRING_INITIALIZER
12194                 (struct cmd_macsec_offload_on_result,
12195                  rp_on_off, "on#off");
12196
12197 static void
12198 cmd_set_macsec_offload_on_parsed(
12199         void *parsed_result,
12200         __attribute__((unused)) struct cmdline *cl,
12201         __attribute__((unused)) void *data)
12202 {
12203         struct cmd_macsec_offload_on_result *res = parsed_result;
12204         int ret = -ENOTSUP;
12205         portid_t port_id = res->port_id;
12206         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12207         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12208
12209         if (port_id_is_invalid(port_id, ENABLED_WARN))
12210                 return;
12211
12212         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12213 #ifdef RTE_LIBRTE_IXGBE_PMD
12214         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12215 #endif
12216         RTE_SET_USED(en);
12217         RTE_SET_USED(rp);
12218
12219         switch (ret) {
12220         case 0:
12221                 break;
12222         case -ENODEV:
12223                 printf("invalid port_id %d\n", port_id);
12224                 break;
12225         case -ENOTSUP:
12226                 printf("not supported on port %d\n", port_id);
12227                 break;
12228         default:
12229                 printf("programming error: (%s)\n", strerror(-ret));
12230         }
12231 }
12232
12233 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12234         .f = cmd_set_macsec_offload_on_parsed,
12235         .data = NULL,
12236         .help_str = "set macsec offload <port_id> on "
12237                 "encrypt on|off replay-protect on|off",
12238         .tokens = {
12239                 (void *)&cmd_macsec_offload_on_set,
12240                 (void *)&cmd_macsec_offload_on_macsec,
12241                 (void *)&cmd_macsec_offload_on_offload,
12242                 (void *)&cmd_macsec_offload_on_port_id,
12243                 (void *)&cmd_macsec_offload_on_on,
12244                 (void *)&cmd_macsec_offload_on_encrypt,
12245                 (void *)&cmd_macsec_offload_on_en_on_off,
12246                 (void *)&cmd_macsec_offload_on_replay_protect,
12247                 (void *)&cmd_macsec_offload_on_rp_on_off,
12248                 NULL,
12249         },
12250 };
12251
12252 /* Common result structure for MACsec offload disable */
12253 struct cmd_macsec_offload_off_result {
12254         cmdline_fixed_string_t set;
12255         cmdline_fixed_string_t macsec;
12256         cmdline_fixed_string_t offload;
12257         uint8_t port_id;
12258         cmdline_fixed_string_t off;
12259 };
12260
12261 /* Common CLI fields for MACsec offload disable */
12262 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12263         TOKEN_STRING_INITIALIZER
12264                 (struct cmd_macsec_offload_off_result,
12265                  set, "set");
12266 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12267         TOKEN_STRING_INITIALIZER
12268                 (struct cmd_macsec_offload_off_result,
12269                  macsec, "macsec");
12270 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12271         TOKEN_STRING_INITIALIZER
12272                 (struct cmd_macsec_offload_off_result,
12273                  offload, "offload");
12274 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12275         TOKEN_NUM_INITIALIZER
12276                 (struct cmd_macsec_offload_off_result,
12277                  port_id, UINT8);
12278 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12279         TOKEN_STRING_INITIALIZER
12280                 (struct cmd_macsec_offload_off_result,
12281                  off, "off");
12282
12283 static void
12284 cmd_set_macsec_offload_off_parsed(
12285         void *parsed_result,
12286         __attribute__((unused)) struct cmdline *cl,
12287         __attribute__((unused)) void *data)
12288 {
12289         struct cmd_macsec_offload_off_result *res = parsed_result;
12290         int ret = -ENOTSUP;
12291         portid_t port_id = res->port_id;
12292
12293         if (port_id_is_invalid(port_id, ENABLED_WARN))
12294                 return;
12295
12296         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12297 #ifdef RTE_LIBRTE_IXGBE_PMD
12298         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12299 #endif
12300
12301         switch (ret) {
12302         case 0:
12303                 break;
12304         case -ENODEV:
12305                 printf("invalid port_id %d\n", port_id);
12306                 break;
12307         case -ENOTSUP:
12308                 printf("not supported on port %d\n", port_id);
12309                 break;
12310         default:
12311                 printf("programming error: (%s)\n", strerror(-ret));
12312         }
12313 }
12314
12315 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12316         .f = cmd_set_macsec_offload_off_parsed,
12317         .data = NULL,
12318         .help_str = "set macsec offload <port_id> off",
12319         .tokens = {
12320                 (void *)&cmd_macsec_offload_off_set,
12321                 (void *)&cmd_macsec_offload_off_macsec,
12322                 (void *)&cmd_macsec_offload_off_offload,
12323                 (void *)&cmd_macsec_offload_off_port_id,
12324                 (void *)&cmd_macsec_offload_off_off,
12325                 NULL,
12326         },
12327 };
12328
12329 /* Common result structure for MACsec secure connection configure */
12330 struct cmd_macsec_sc_result {
12331         cmdline_fixed_string_t set;
12332         cmdline_fixed_string_t macsec;
12333         cmdline_fixed_string_t sc;
12334         cmdline_fixed_string_t tx_rx;
12335         uint8_t port_id;
12336         struct ether_addr mac;
12337         uint16_t pi;
12338 };
12339
12340 /* Common CLI fields for MACsec secure connection configure */
12341 cmdline_parse_token_string_t cmd_macsec_sc_set =
12342         TOKEN_STRING_INITIALIZER
12343                 (struct cmd_macsec_sc_result,
12344                  set, "set");
12345 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12346         TOKEN_STRING_INITIALIZER
12347                 (struct cmd_macsec_sc_result,
12348                  macsec, "macsec");
12349 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12350         TOKEN_STRING_INITIALIZER
12351                 (struct cmd_macsec_sc_result,
12352                  sc, "sc");
12353 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12354         TOKEN_STRING_INITIALIZER
12355                 (struct cmd_macsec_sc_result,
12356                  tx_rx, "tx#rx");
12357 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12358         TOKEN_NUM_INITIALIZER
12359                 (struct cmd_macsec_sc_result,
12360                  port_id, UINT8);
12361 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12362         TOKEN_ETHERADDR_INITIALIZER
12363                 (struct cmd_macsec_sc_result,
12364                  mac);
12365 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12366         TOKEN_NUM_INITIALIZER
12367                 (struct cmd_macsec_sc_result,
12368                  pi, UINT16);
12369
12370 static void
12371 cmd_set_macsec_sc_parsed(
12372         void *parsed_result,
12373         __attribute__((unused)) struct cmdline *cl,
12374         __attribute__((unused)) void *data)
12375 {
12376         struct cmd_macsec_sc_result *res = parsed_result;
12377         int ret = -ENOTSUP;
12378         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12379
12380 #ifdef RTE_LIBRTE_IXGBE_PMD
12381         ret = is_tx ?
12382                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12383                                 res->mac.addr_bytes) :
12384                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12385                                 res->mac.addr_bytes, res->pi);
12386 #endif
12387         RTE_SET_USED(is_tx);
12388
12389         switch (ret) {
12390         case 0:
12391                 break;
12392         case -ENODEV:
12393                 printf("invalid port_id %d\n", res->port_id);
12394                 break;
12395         case -ENOTSUP:
12396                 printf("not supported on port %d\n", res->port_id);
12397                 break;
12398         default:
12399                 printf("programming error: (%s)\n", strerror(-ret));
12400         }
12401 }
12402
12403 cmdline_parse_inst_t cmd_set_macsec_sc = {
12404         .f = cmd_set_macsec_sc_parsed,
12405         .data = NULL,
12406         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12407         .tokens = {
12408                 (void *)&cmd_macsec_sc_set,
12409                 (void *)&cmd_macsec_sc_macsec,
12410                 (void *)&cmd_macsec_sc_sc,
12411                 (void *)&cmd_macsec_sc_tx_rx,
12412                 (void *)&cmd_macsec_sc_port_id,
12413                 (void *)&cmd_macsec_sc_mac,
12414                 (void *)&cmd_macsec_sc_pi,
12415                 NULL,
12416         },
12417 };
12418
12419 /* Common result structure for MACsec secure connection configure */
12420 struct cmd_macsec_sa_result {
12421         cmdline_fixed_string_t set;
12422         cmdline_fixed_string_t macsec;
12423         cmdline_fixed_string_t sa;
12424         cmdline_fixed_string_t tx_rx;
12425         uint8_t port_id;
12426         uint8_t idx;
12427         uint8_t an;
12428         uint32_t pn;
12429         cmdline_fixed_string_t key;
12430 };
12431
12432 /* Common CLI fields for MACsec secure connection configure */
12433 cmdline_parse_token_string_t cmd_macsec_sa_set =
12434         TOKEN_STRING_INITIALIZER
12435                 (struct cmd_macsec_sa_result,
12436                  set, "set");
12437 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12438         TOKEN_STRING_INITIALIZER
12439                 (struct cmd_macsec_sa_result,
12440                  macsec, "macsec");
12441 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12442         TOKEN_STRING_INITIALIZER
12443                 (struct cmd_macsec_sa_result,
12444                  sa, "sa");
12445 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12446         TOKEN_STRING_INITIALIZER
12447                 (struct cmd_macsec_sa_result,
12448                  tx_rx, "tx#rx");
12449 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12450         TOKEN_NUM_INITIALIZER
12451                 (struct cmd_macsec_sa_result,
12452                  port_id, UINT8);
12453 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12454         TOKEN_NUM_INITIALIZER
12455                 (struct cmd_macsec_sa_result,
12456                  idx, UINT8);
12457 cmdline_parse_token_num_t cmd_macsec_sa_an =
12458         TOKEN_NUM_INITIALIZER
12459                 (struct cmd_macsec_sa_result,
12460                  an, UINT8);
12461 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12462         TOKEN_NUM_INITIALIZER
12463                 (struct cmd_macsec_sa_result,
12464                  pn, UINT32);
12465 cmdline_parse_token_string_t cmd_macsec_sa_key =
12466         TOKEN_STRING_INITIALIZER
12467                 (struct cmd_macsec_sa_result,
12468                  key, NULL);
12469
12470 static void
12471 cmd_set_macsec_sa_parsed(
12472         void *parsed_result,
12473         __attribute__((unused)) struct cmdline *cl,
12474         __attribute__((unused)) void *data)
12475 {
12476         struct cmd_macsec_sa_result *res = parsed_result;
12477         int ret = -ENOTSUP;
12478         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12479         uint8_t key[16] = { 0 };
12480         uint8_t xdgt0;
12481         uint8_t xdgt1;
12482         int key_len;
12483         int i;
12484
12485         key_len = strlen(res->key) / 2;
12486         if (key_len > 16)
12487                 key_len = 16;
12488
12489         for (i = 0; i < key_len; i++) {
12490                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12491                 if (xdgt0 == 0xFF)
12492                         return;
12493                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12494                 if (xdgt1 == 0xFF)
12495                         return;
12496                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12497         }
12498
12499 #ifdef RTE_LIBRTE_IXGBE_PMD
12500         ret = is_tx ?
12501                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12502                         res->idx, res->an, res->pn, key) :
12503                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12504                         res->idx, res->an, res->pn, key);
12505 #endif
12506         RTE_SET_USED(is_tx);
12507         RTE_SET_USED(key);
12508
12509         switch (ret) {
12510         case 0:
12511                 break;
12512         case -EINVAL:
12513                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12514                 break;
12515         case -ENODEV:
12516                 printf("invalid port_id %d\n", res->port_id);
12517                 break;
12518         case -ENOTSUP:
12519                 printf("not supported on port %d\n", res->port_id);
12520                 break;
12521         default:
12522                 printf("programming error: (%s)\n", strerror(-ret));
12523         }
12524 }
12525
12526 cmdline_parse_inst_t cmd_set_macsec_sa = {
12527         .f = cmd_set_macsec_sa_parsed,
12528         .data = NULL,
12529         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12530         .tokens = {
12531                 (void *)&cmd_macsec_sa_set,
12532                 (void *)&cmd_macsec_sa_macsec,
12533                 (void *)&cmd_macsec_sa_sa,
12534                 (void *)&cmd_macsec_sa_tx_rx,
12535                 (void *)&cmd_macsec_sa_port_id,
12536                 (void *)&cmd_macsec_sa_idx,
12537                 (void *)&cmd_macsec_sa_an,
12538                 (void *)&cmd_macsec_sa_pn,
12539                 (void *)&cmd_macsec_sa_key,
12540                 NULL,
12541         },
12542 };
12543
12544 /* VF unicast promiscuous mode configuration */
12545
12546 /* Common result structure for VF unicast promiscuous mode */
12547 struct cmd_vf_promisc_result {
12548         cmdline_fixed_string_t set;
12549         cmdline_fixed_string_t vf;
12550         cmdline_fixed_string_t promisc;
12551         uint8_t port_id;
12552         uint32_t vf_id;
12553         cmdline_fixed_string_t on_off;
12554 };
12555
12556 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12557 cmdline_parse_token_string_t cmd_vf_promisc_set =
12558         TOKEN_STRING_INITIALIZER
12559                 (struct cmd_vf_promisc_result,
12560                  set, "set");
12561 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12562         TOKEN_STRING_INITIALIZER
12563                 (struct cmd_vf_promisc_result,
12564                  vf, "vf");
12565 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12566         TOKEN_STRING_INITIALIZER
12567                 (struct cmd_vf_promisc_result,
12568                  promisc, "promisc");
12569 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12570         TOKEN_NUM_INITIALIZER
12571                 (struct cmd_vf_promisc_result,
12572                  port_id, UINT8);
12573 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12574         TOKEN_NUM_INITIALIZER
12575                 (struct cmd_vf_promisc_result,
12576                  vf_id, UINT32);
12577 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12578         TOKEN_STRING_INITIALIZER
12579                 (struct cmd_vf_promisc_result,
12580                  on_off, "on#off");
12581
12582 static void
12583 cmd_set_vf_promisc_parsed(
12584         void *parsed_result,
12585         __attribute__((unused)) struct cmdline *cl,
12586         __attribute__((unused)) void *data)
12587 {
12588         struct cmd_vf_promisc_result *res = parsed_result;
12589         int ret = -ENOTSUP;
12590
12591         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12592
12593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12594                 return;
12595
12596 #ifdef RTE_LIBRTE_I40E_PMD
12597         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12598                                                   res->vf_id, is_on);
12599 #endif
12600
12601         switch (ret) {
12602         case 0:
12603                 break;
12604         case -EINVAL:
12605                 printf("invalid vf_id %d\n", res->vf_id);
12606                 break;
12607         case -ENODEV:
12608                 printf("invalid port_id %d\n", res->port_id);
12609                 break;
12610         case -ENOTSUP:
12611                 printf("function not implemented\n");
12612                 break;
12613         default:
12614                 printf("programming error: (%s)\n", strerror(-ret));
12615         }
12616 }
12617
12618 cmdline_parse_inst_t cmd_set_vf_promisc = {
12619         .f = cmd_set_vf_promisc_parsed,
12620         .data = NULL,
12621         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12622                 "Set unicast promiscuous mode for a VF from the PF",
12623         .tokens = {
12624                 (void *)&cmd_vf_promisc_set,
12625                 (void *)&cmd_vf_promisc_vf,
12626                 (void *)&cmd_vf_promisc_promisc,
12627                 (void *)&cmd_vf_promisc_port_id,
12628                 (void *)&cmd_vf_promisc_vf_id,
12629                 (void *)&cmd_vf_promisc_on_off,
12630                 NULL,
12631         },
12632 };
12633
12634 /* VF multicast promiscuous mode configuration */
12635
12636 /* Common result structure for VF multicast promiscuous mode */
12637 struct cmd_vf_allmulti_result {
12638         cmdline_fixed_string_t set;
12639         cmdline_fixed_string_t vf;
12640         cmdline_fixed_string_t allmulti;
12641         uint8_t port_id;
12642         uint32_t vf_id;
12643         cmdline_fixed_string_t on_off;
12644 };
12645
12646 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12647 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12648         TOKEN_STRING_INITIALIZER
12649                 (struct cmd_vf_allmulti_result,
12650                  set, "set");
12651 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12652         TOKEN_STRING_INITIALIZER
12653                 (struct cmd_vf_allmulti_result,
12654                  vf, "vf");
12655 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12656         TOKEN_STRING_INITIALIZER
12657                 (struct cmd_vf_allmulti_result,
12658                  allmulti, "allmulti");
12659 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12660         TOKEN_NUM_INITIALIZER
12661                 (struct cmd_vf_allmulti_result,
12662                  port_id, UINT8);
12663 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12664         TOKEN_NUM_INITIALIZER
12665                 (struct cmd_vf_allmulti_result,
12666                  vf_id, UINT32);
12667 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12668         TOKEN_STRING_INITIALIZER
12669                 (struct cmd_vf_allmulti_result,
12670                  on_off, "on#off");
12671
12672 static void
12673 cmd_set_vf_allmulti_parsed(
12674         void *parsed_result,
12675         __attribute__((unused)) struct cmdline *cl,
12676         __attribute__((unused)) void *data)
12677 {
12678         struct cmd_vf_allmulti_result *res = parsed_result;
12679         int ret = -ENOTSUP;
12680
12681         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12682
12683         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12684                 return;
12685
12686 #ifdef RTE_LIBRTE_I40E_PMD
12687         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12688                                                     res->vf_id, is_on);
12689 #endif
12690
12691         switch (ret) {
12692         case 0:
12693                 break;
12694         case -EINVAL:
12695                 printf("invalid vf_id %d\n", res->vf_id);
12696                 break;
12697         case -ENODEV:
12698                 printf("invalid port_id %d\n", res->port_id);
12699                 break;
12700         case -ENOTSUP:
12701                 printf("function not implemented\n");
12702                 break;
12703         default:
12704                 printf("programming error: (%s)\n", strerror(-ret));
12705         }
12706 }
12707
12708 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12709         .f = cmd_set_vf_allmulti_parsed,
12710         .data = NULL,
12711         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12712                 "Set multicast promiscuous mode for a VF from the PF",
12713         .tokens = {
12714                 (void *)&cmd_vf_allmulti_set,
12715                 (void *)&cmd_vf_allmulti_vf,
12716                 (void *)&cmd_vf_allmulti_allmulti,
12717                 (void *)&cmd_vf_allmulti_port_id,
12718                 (void *)&cmd_vf_allmulti_vf_id,
12719                 (void *)&cmd_vf_allmulti_on_off,
12720                 NULL,
12721         },
12722 };
12723
12724 /* vf broadcast mode configuration */
12725
12726 /* Common result structure for vf broadcast */
12727 struct cmd_set_vf_broadcast_result {
12728         cmdline_fixed_string_t set;
12729         cmdline_fixed_string_t vf;
12730         cmdline_fixed_string_t broadcast;
12731         uint8_t port_id;
12732         uint16_t vf_id;
12733         cmdline_fixed_string_t on_off;
12734 };
12735
12736 /* Common CLI fields for vf broadcast enable disable */
12737 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12738         TOKEN_STRING_INITIALIZER
12739                 (struct cmd_set_vf_broadcast_result,
12740                  set, "set");
12741 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_set_vf_broadcast_result,
12744                  vf, "vf");
12745 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_set_vf_broadcast_result,
12748                  broadcast, "broadcast");
12749 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12750         TOKEN_NUM_INITIALIZER
12751                 (struct cmd_set_vf_broadcast_result,
12752                  port_id, UINT8);
12753 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12754         TOKEN_NUM_INITIALIZER
12755                 (struct cmd_set_vf_broadcast_result,
12756                  vf_id, UINT16);
12757 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12758         TOKEN_STRING_INITIALIZER
12759                 (struct cmd_set_vf_broadcast_result,
12760                  on_off, "on#off");
12761
12762 static void
12763 cmd_set_vf_broadcast_parsed(
12764         void *parsed_result,
12765         __attribute__((unused)) struct cmdline *cl,
12766         __attribute__((unused)) void *data)
12767 {
12768         struct cmd_set_vf_broadcast_result *res = parsed_result;
12769         int ret = -ENOTSUP;
12770
12771         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12772
12773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12774                 return;
12775
12776 #ifdef RTE_LIBRTE_I40E_PMD
12777         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12778                                             res->vf_id, is_on);
12779 #endif
12780
12781         switch (ret) {
12782         case 0:
12783                 break;
12784         case -EINVAL:
12785                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12786                 break;
12787         case -ENODEV:
12788                 printf("invalid port_id %d\n", res->port_id);
12789                 break;
12790         case -ENOTSUP:
12791                 printf("function not implemented\n");
12792                 break;
12793         default:
12794                 printf("programming error: (%s)\n", strerror(-ret));
12795         }
12796 }
12797
12798 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12799         .f = cmd_set_vf_broadcast_parsed,
12800         .data = NULL,
12801         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12802         .tokens = {
12803                 (void *)&cmd_set_vf_broadcast_set,
12804                 (void *)&cmd_set_vf_broadcast_vf,
12805                 (void *)&cmd_set_vf_broadcast_broadcast,
12806                 (void *)&cmd_set_vf_broadcast_port_id,
12807                 (void *)&cmd_set_vf_broadcast_vf_id,
12808                 (void *)&cmd_set_vf_broadcast_on_off,
12809                 NULL,
12810         },
12811 };
12812
12813 /* vf vlan tag configuration */
12814
12815 /* Common result structure for vf vlan tag */
12816 struct cmd_set_vf_vlan_tag_result {
12817         cmdline_fixed_string_t set;
12818         cmdline_fixed_string_t vf;
12819         cmdline_fixed_string_t vlan;
12820         cmdline_fixed_string_t tag;
12821         uint8_t port_id;
12822         uint16_t vf_id;
12823         cmdline_fixed_string_t on_off;
12824 };
12825
12826 /* Common CLI fields for vf vlan tag enable disable */
12827 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12828         TOKEN_STRING_INITIALIZER
12829                 (struct cmd_set_vf_vlan_tag_result,
12830                  set, "set");
12831 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12832         TOKEN_STRING_INITIALIZER
12833                 (struct cmd_set_vf_vlan_tag_result,
12834                  vf, "vf");
12835 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12836         TOKEN_STRING_INITIALIZER
12837                 (struct cmd_set_vf_vlan_tag_result,
12838                  vlan, "vlan");
12839 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12840         TOKEN_STRING_INITIALIZER
12841                 (struct cmd_set_vf_vlan_tag_result,
12842                  tag, "tag");
12843 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12844         TOKEN_NUM_INITIALIZER
12845                 (struct cmd_set_vf_vlan_tag_result,
12846                  port_id, UINT8);
12847 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12848         TOKEN_NUM_INITIALIZER
12849                 (struct cmd_set_vf_vlan_tag_result,
12850                  vf_id, UINT16);
12851 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_set_vf_vlan_tag_result,
12854                  on_off, "on#off");
12855
12856 static void
12857 cmd_set_vf_vlan_tag_parsed(
12858         void *parsed_result,
12859         __attribute__((unused)) struct cmdline *cl,
12860         __attribute__((unused)) void *data)
12861 {
12862         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12863         int ret = -ENOTSUP;
12864
12865         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12866
12867         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12868                 return;
12869
12870 #ifdef RTE_LIBRTE_I40E_PMD
12871         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12872                                            res->vf_id, is_on);
12873 #endif
12874
12875         switch (ret) {
12876         case 0:
12877                 break;
12878         case -EINVAL:
12879                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12880                 break;
12881         case -ENODEV:
12882                 printf("invalid port_id %d\n", res->port_id);
12883                 break;
12884         case -ENOTSUP:
12885                 printf("function not implemented\n");
12886                 break;
12887         default:
12888                 printf("programming error: (%s)\n", strerror(-ret));
12889         }
12890 }
12891
12892 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12893         .f = cmd_set_vf_vlan_tag_parsed,
12894         .data = NULL,
12895         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12896         .tokens = {
12897                 (void *)&cmd_set_vf_vlan_tag_set,
12898                 (void *)&cmd_set_vf_vlan_tag_vf,
12899                 (void *)&cmd_set_vf_vlan_tag_vlan,
12900                 (void *)&cmd_set_vf_vlan_tag_tag,
12901                 (void *)&cmd_set_vf_vlan_tag_port_id,
12902                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12903                 (void *)&cmd_set_vf_vlan_tag_on_off,
12904                 NULL,
12905         },
12906 };
12907
12908 /* Common definition of VF and TC TX bandwidth configuration */
12909 struct cmd_vf_tc_bw_result {
12910         cmdline_fixed_string_t set;
12911         cmdline_fixed_string_t vf;
12912         cmdline_fixed_string_t tc;
12913         cmdline_fixed_string_t tx;
12914         cmdline_fixed_string_t min_bw;
12915         cmdline_fixed_string_t max_bw;
12916         cmdline_fixed_string_t strict_link_prio;
12917         uint8_t port_id;
12918         uint16_t vf_id;
12919         uint8_t tc_no;
12920         uint32_t bw;
12921         cmdline_fixed_string_t bw_list;
12922         uint8_t tc_map;
12923 };
12924
12925 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_vf_tc_bw_result,
12928                  set, "set");
12929 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12930         TOKEN_STRING_INITIALIZER
12931                 (struct cmd_vf_tc_bw_result,
12932                  vf, "vf");
12933 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12934         TOKEN_STRING_INITIALIZER
12935                 (struct cmd_vf_tc_bw_result,
12936                  tc, "tc");
12937 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12938         TOKEN_STRING_INITIALIZER
12939                 (struct cmd_vf_tc_bw_result,
12940                  tx, "tx");
12941 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_vf_tc_bw_result,
12944                  strict_link_prio, "strict-link-priority");
12945 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12946         TOKEN_STRING_INITIALIZER
12947                 (struct cmd_vf_tc_bw_result,
12948                  min_bw, "min-bandwidth");
12949 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12950         TOKEN_STRING_INITIALIZER
12951                 (struct cmd_vf_tc_bw_result,
12952                  max_bw, "max-bandwidth");
12953 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12954         TOKEN_NUM_INITIALIZER
12955                 (struct cmd_vf_tc_bw_result,
12956                  port_id, UINT8);
12957 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12958         TOKEN_NUM_INITIALIZER
12959                 (struct cmd_vf_tc_bw_result,
12960                  vf_id, UINT16);
12961 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12962         TOKEN_NUM_INITIALIZER
12963                 (struct cmd_vf_tc_bw_result,
12964                  tc_no, UINT8);
12965 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12966         TOKEN_NUM_INITIALIZER
12967                 (struct cmd_vf_tc_bw_result,
12968                  bw, UINT32);
12969 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12970         TOKEN_STRING_INITIALIZER
12971                 (struct cmd_vf_tc_bw_result,
12972                  bw_list, NULL);
12973 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12974         TOKEN_NUM_INITIALIZER
12975                 (struct cmd_vf_tc_bw_result,
12976                  tc_map, UINT8);
12977
12978 /* VF max bandwidth setting */
12979 static void
12980 cmd_vf_max_bw_parsed(
12981         void *parsed_result,
12982         __attribute__((unused)) struct cmdline *cl,
12983         __attribute__((unused)) void *data)
12984 {
12985         struct cmd_vf_tc_bw_result *res = parsed_result;
12986         int ret = -ENOTSUP;
12987
12988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12989                 return;
12990
12991 #ifdef RTE_LIBRTE_I40E_PMD
12992         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12993                                          res->vf_id, res->bw);
12994 #endif
12995
12996         switch (ret) {
12997         case 0:
12998                 break;
12999         case -EINVAL:
13000                 printf("invalid vf_id %d or bandwidth %d\n",
13001                        res->vf_id, res->bw);
13002                 break;
13003         case -ENODEV:
13004                 printf("invalid port_id %d\n", res->port_id);
13005                 break;
13006         case -ENOTSUP:
13007                 printf("function not implemented\n");
13008                 break;
13009         default:
13010                 printf("programming error: (%s)\n", strerror(-ret));
13011         }
13012 }
13013
13014 cmdline_parse_inst_t cmd_vf_max_bw = {
13015         .f = cmd_vf_max_bw_parsed,
13016         .data = NULL,
13017         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13018         .tokens = {
13019                 (void *)&cmd_vf_tc_bw_set,
13020                 (void *)&cmd_vf_tc_bw_vf,
13021                 (void *)&cmd_vf_tc_bw_tx,
13022                 (void *)&cmd_vf_tc_bw_max_bw,
13023                 (void *)&cmd_vf_tc_bw_port_id,
13024                 (void *)&cmd_vf_tc_bw_vf_id,
13025                 (void *)&cmd_vf_tc_bw_bw,
13026                 NULL,
13027         },
13028 };
13029
13030 static int
13031 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13032                            uint8_t *tc_num,
13033                            char *str)
13034 {
13035         uint32_t size;
13036         const char *p, *p0 = str;
13037         char s[256];
13038         char *end;
13039         char *str_fld[16];
13040         uint16_t i;
13041         int ret;
13042
13043         p = strchr(p0, '(');
13044         if (p == NULL) {
13045                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13046                 return -1;
13047         }
13048         p++;
13049         p0 = strchr(p, ')');
13050         if (p0 == NULL) {
13051                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13052                 return -1;
13053         }
13054         size = p0 - p;
13055         if (size >= sizeof(s)) {
13056                 printf("The string size exceeds the internal buffer size\n");
13057                 return -1;
13058         }
13059         snprintf(s, sizeof(s), "%.*s", size, p);
13060         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13061         if (ret <= 0) {
13062                 printf("Failed to get the bandwidth list. ");
13063                 return -1;
13064         }
13065         *tc_num = ret;
13066         for (i = 0; i < ret; i++)
13067                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13068
13069         return 0;
13070 }
13071
13072 /* TC min bandwidth setting */
13073 static void
13074 cmd_vf_tc_min_bw_parsed(
13075         void *parsed_result,
13076         __attribute__((unused)) struct cmdline *cl,
13077         __attribute__((unused)) void *data)
13078 {
13079         struct cmd_vf_tc_bw_result *res = parsed_result;
13080         uint8_t tc_num;
13081         uint8_t bw[16];
13082         int ret = -ENOTSUP;
13083
13084         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13085                 return;
13086
13087         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13088         if (ret)
13089                 return;
13090
13091 #ifdef RTE_LIBRTE_I40E_PMD
13092         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13093                                               tc_num, bw);
13094 #endif
13095
13096         switch (ret) {
13097         case 0:
13098                 break;
13099         case -EINVAL:
13100                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13101                 break;
13102         case -ENODEV:
13103                 printf("invalid port_id %d\n", res->port_id);
13104                 break;
13105         case -ENOTSUP:
13106                 printf("function not implemented\n");
13107                 break;
13108         default:
13109                 printf("programming error: (%s)\n", strerror(-ret));
13110         }
13111 }
13112
13113 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13114         .f = cmd_vf_tc_min_bw_parsed,
13115         .data = NULL,
13116         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13117                     " <bw1, bw2, ...>",
13118         .tokens = {
13119                 (void *)&cmd_vf_tc_bw_set,
13120                 (void *)&cmd_vf_tc_bw_vf,
13121                 (void *)&cmd_vf_tc_bw_tc,
13122                 (void *)&cmd_vf_tc_bw_tx,
13123                 (void *)&cmd_vf_tc_bw_min_bw,
13124                 (void *)&cmd_vf_tc_bw_port_id,
13125                 (void *)&cmd_vf_tc_bw_vf_id,
13126                 (void *)&cmd_vf_tc_bw_bw_list,
13127                 NULL,
13128         },
13129 };
13130
13131 static void
13132 cmd_tc_min_bw_parsed(
13133         void *parsed_result,
13134         __attribute__((unused)) struct cmdline *cl,
13135         __attribute__((unused)) void *data)
13136 {
13137         struct cmd_vf_tc_bw_result *res = parsed_result;
13138         struct rte_port *port;
13139         uint8_t tc_num;
13140         uint8_t bw[16];
13141         int ret = -ENOTSUP;
13142
13143         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13144                 return;
13145
13146         port = &ports[res->port_id];
13147         /** Check if the port is not started **/
13148         if (port->port_status != RTE_PORT_STOPPED) {
13149                 printf("Please stop port %d first\n", res->port_id);
13150                 return;
13151         }
13152
13153         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13154         if (ret)
13155                 return;
13156
13157 #ifdef RTE_LIBRTE_IXGBE_PMD
13158         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13159 #endif
13160
13161         switch (ret) {
13162         case 0:
13163                 break;
13164         case -EINVAL:
13165                 printf("invalid bandwidth\n");
13166                 break;
13167         case -ENODEV:
13168                 printf("invalid port_id %d\n", res->port_id);
13169                 break;
13170         case -ENOTSUP:
13171                 printf("function not implemented\n");
13172                 break;
13173         default:
13174                 printf("programming error: (%s)\n", strerror(-ret));
13175         }
13176 }
13177
13178 cmdline_parse_inst_t cmd_tc_min_bw = {
13179         .f = cmd_tc_min_bw_parsed,
13180         .data = NULL,
13181         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13182         .tokens = {
13183                 (void *)&cmd_vf_tc_bw_set,
13184                 (void *)&cmd_vf_tc_bw_tc,
13185                 (void *)&cmd_vf_tc_bw_tx,
13186                 (void *)&cmd_vf_tc_bw_min_bw,
13187                 (void *)&cmd_vf_tc_bw_port_id,
13188                 (void *)&cmd_vf_tc_bw_bw_list,
13189                 NULL,
13190         },
13191 };
13192
13193 /* TC max bandwidth setting */
13194 static void
13195 cmd_vf_tc_max_bw_parsed(
13196         void *parsed_result,
13197         __attribute__((unused)) struct cmdline *cl,
13198         __attribute__((unused)) void *data)
13199 {
13200         struct cmd_vf_tc_bw_result *res = parsed_result;
13201         int ret = -ENOTSUP;
13202
13203         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13204                 return;
13205
13206 #ifdef RTE_LIBRTE_I40E_PMD
13207         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13208                                             res->tc_no, res->bw);
13209 #endif
13210
13211         switch (ret) {
13212         case 0:
13213                 break;
13214         case -EINVAL:
13215                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13216                        res->vf_id, res->tc_no, res->bw);
13217                 break;
13218         case -ENODEV:
13219                 printf("invalid port_id %d\n", res->port_id);
13220                 break;
13221         case -ENOTSUP:
13222                 printf("function not implemented\n");
13223                 break;
13224         default:
13225                 printf("programming error: (%s)\n", strerror(-ret));
13226         }
13227 }
13228
13229 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13230         .f = cmd_vf_tc_max_bw_parsed,
13231         .data = NULL,
13232         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13233                     " <bandwidth>",
13234         .tokens = {
13235                 (void *)&cmd_vf_tc_bw_set,
13236                 (void *)&cmd_vf_tc_bw_vf,
13237                 (void *)&cmd_vf_tc_bw_tc,
13238                 (void *)&cmd_vf_tc_bw_tx,
13239                 (void *)&cmd_vf_tc_bw_max_bw,
13240                 (void *)&cmd_vf_tc_bw_port_id,
13241                 (void *)&cmd_vf_tc_bw_vf_id,
13242                 (void *)&cmd_vf_tc_bw_tc_no,
13243                 (void *)&cmd_vf_tc_bw_bw,
13244                 NULL,
13245         },
13246 };
13247
13248 /* Strict link priority scheduling mode setting */
13249 static void
13250 cmd_strict_link_prio_parsed(
13251         void *parsed_result,
13252         __attribute__((unused)) struct cmdline *cl,
13253         __attribute__((unused)) void *data)
13254 {
13255         struct cmd_vf_tc_bw_result *res = parsed_result;
13256         int ret = -ENOTSUP;
13257
13258         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13259                 return;
13260
13261 #ifdef RTE_LIBRTE_I40E_PMD
13262         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13263 #endif
13264
13265         switch (ret) {
13266         case 0:
13267                 break;
13268         case -EINVAL:
13269                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13270                 break;
13271         case -ENODEV:
13272                 printf("invalid port_id %d\n", res->port_id);
13273                 break;
13274         case -ENOTSUP:
13275                 printf("function not implemented\n");
13276                 break;
13277         default:
13278                 printf("programming error: (%s)\n", strerror(-ret));
13279         }
13280 }
13281
13282 cmdline_parse_inst_t cmd_strict_link_prio = {
13283         .f = cmd_strict_link_prio_parsed,
13284         .data = NULL,
13285         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13286         .tokens = {
13287                 (void *)&cmd_vf_tc_bw_set,
13288                 (void *)&cmd_vf_tc_bw_tx,
13289                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13290                 (void *)&cmd_vf_tc_bw_port_id,
13291                 (void *)&cmd_vf_tc_bw_tc_map,
13292                 NULL,
13293         },
13294 };
13295
13296 /* Load dynamic device personalization*/
13297 struct cmd_ddp_add_result {
13298         cmdline_fixed_string_t ddp;
13299         cmdline_fixed_string_t add;
13300         uint8_t port_id;
13301         char filepath[];
13302 };
13303
13304 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13305         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13306 cmdline_parse_token_string_t cmd_ddp_add_add =
13307         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13308 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13309         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13310 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13311         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13312
13313 static void
13314 cmd_ddp_add_parsed(
13315         void *parsed_result,
13316         __attribute__((unused)) struct cmdline *cl,
13317         __attribute__((unused)) void *data)
13318 {
13319         struct cmd_ddp_add_result *res = parsed_result;
13320         uint8_t *buff;
13321         uint32_t size;
13322         char *filepath;
13323         char *file_fld[2];
13324         int file_num;
13325         int ret = -ENOTSUP;
13326
13327         if (res->port_id > nb_ports) {
13328                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13329                 return;
13330         }
13331
13332         if (!all_ports_stopped()) {
13333                 printf("Please stop all ports first\n");
13334                 return;
13335         }
13336
13337         filepath = strdup(res->filepath);
13338         if (filepath == NULL) {
13339                 printf("Failed to allocate memory\n");
13340                 return;
13341         }
13342         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13343
13344         buff = open_ddp_package_file(file_fld[0], &size);
13345         if (!buff) {
13346                 free((void *)filepath);
13347                 return;
13348         }
13349
13350 #ifdef RTE_LIBRTE_I40E_PMD
13351         if (ret == -ENOTSUP)
13352                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13353                                                buff, size,
13354                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13355 #endif
13356
13357         if (ret == -EEXIST)
13358                 printf("Profile has already existed.\n");
13359         else if (ret < 0)
13360                 printf("Failed to load profile.\n");
13361         else if (file_num == 2)
13362                 save_ddp_package_file(file_fld[1], buff, size);
13363
13364         close_ddp_package_file(buff);
13365         free((void *)filepath);
13366 }
13367
13368 cmdline_parse_inst_t cmd_ddp_add = {
13369         .f = cmd_ddp_add_parsed,
13370         .data = NULL,
13371         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13372         .tokens = {
13373                 (void *)&cmd_ddp_add_ddp,
13374                 (void *)&cmd_ddp_add_add,
13375                 (void *)&cmd_ddp_add_port_id,
13376                 (void *)&cmd_ddp_add_filepath,
13377                 NULL,
13378         },
13379 };
13380
13381 /* Delete dynamic device personalization*/
13382 struct cmd_ddp_del_result {
13383         cmdline_fixed_string_t ddp;
13384         cmdline_fixed_string_t del;
13385         uint8_t port_id;
13386         char filepath[];
13387 };
13388
13389 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13390         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13391 cmdline_parse_token_string_t cmd_ddp_del_del =
13392         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13393 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13394         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13395 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13396         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13397
13398 static void
13399 cmd_ddp_del_parsed(
13400         void *parsed_result,
13401         __attribute__((unused)) struct cmdline *cl,
13402         __attribute__((unused)) void *data)
13403 {
13404         struct cmd_ddp_del_result *res = parsed_result;
13405         uint8_t *buff;
13406         uint32_t size;
13407         int ret = -ENOTSUP;
13408
13409         if (res->port_id > nb_ports) {
13410                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13411                 return;
13412         }
13413
13414         if (!all_ports_stopped()) {
13415                 printf("Please stop all ports first\n");
13416                 return;
13417         }
13418
13419         buff = open_ddp_package_file(res->filepath, &size);
13420         if (!buff)
13421                 return;
13422
13423 #ifdef RTE_LIBRTE_I40E_PMD
13424         if (ret == -ENOTSUP)
13425                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13426                                                buff, size,
13427                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13428 #endif
13429
13430         if (ret == -EACCES)
13431                 printf("Profile does not exist.\n");
13432         else if (ret < 0)
13433                 printf("Failed to delete profile.\n");
13434
13435         close_ddp_package_file(buff);
13436 }
13437
13438 cmdline_parse_inst_t cmd_ddp_del = {
13439         .f = cmd_ddp_del_parsed,
13440         .data = NULL,
13441         .help_str = "ddp del <port_id> <profile_path>",
13442         .tokens = {
13443                 (void *)&cmd_ddp_del_ddp,
13444                 (void *)&cmd_ddp_del_del,
13445                 (void *)&cmd_ddp_del_port_id,
13446                 (void *)&cmd_ddp_del_filepath,
13447                 NULL,
13448         },
13449 };
13450
13451 /* Get dynamic device personalization profile info */
13452 struct cmd_ddp_info_result {
13453         cmdline_fixed_string_t ddp;
13454         cmdline_fixed_string_t get;
13455         cmdline_fixed_string_t info;
13456         char filepath[];
13457 };
13458
13459 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13460         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13461 cmdline_parse_token_string_t cmd_ddp_info_get =
13462         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13463 cmdline_parse_token_string_t cmd_ddp_info_info =
13464         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13465 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13466         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13467
13468 static void
13469 cmd_ddp_info_parsed(
13470         void *parsed_result,
13471         __attribute__((unused)) struct cmdline *cl,
13472         __attribute__((unused)) void *data)
13473 {
13474         struct cmd_ddp_info_result *res = parsed_result;
13475         uint8_t *pkg;
13476         uint32_t pkg_size;
13477         int ret = -ENOTSUP;
13478 #ifdef RTE_LIBRTE_I40E_PMD
13479         uint32_t i, j, n;
13480         uint8_t *buff;
13481         uint32_t buff_size = 0;
13482         struct rte_pmd_i40e_profile_info info;
13483         uint32_t dev_num = 0;
13484         struct rte_pmd_i40e_ddp_device_id *devs;
13485         uint32_t proto_num = 0;
13486         struct rte_pmd_i40e_proto_info *proto;
13487         uint32_t pctype_num = 0;
13488         struct rte_pmd_i40e_ptype_info *pctype;
13489         uint32_t ptype_num = 0;
13490         struct rte_pmd_i40e_ptype_info *ptype;
13491         uint8_t proto_id;
13492
13493 #endif
13494
13495         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13496         if (!pkg)
13497                 return;
13498
13499 #ifdef RTE_LIBRTE_I40E_PMD
13500         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13501                                 (uint8_t *)&info, sizeof(info),
13502                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13503         if (!ret) {
13504                 printf("Global Track id:       0x%x\n", info.track_id);
13505                 printf("Global Version:        %d.%d.%d.%d\n",
13506                         info.version.major,
13507                         info.version.minor,
13508                         info.version.update,
13509                         info.version.draft);
13510                 printf("Global Package name:   %s\n\n", info.name);
13511         }
13512
13513         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13514                                 (uint8_t *)&info, sizeof(info),
13515                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13516         if (!ret) {
13517                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13518                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13519                         info.version.major,
13520                         info.version.minor,
13521                         info.version.update,
13522                         info.version.draft);
13523                 printf("i40e Profile name:     %s\n\n", info.name);
13524         }
13525
13526         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13527                                 (uint8_t *)&buff_size, sizeof(buff_size),
13528                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13529         if (!ret && buff_size) {
13530                 buff = (uint8_t *)malloc(buff_size);
13531                 if (buff) {
13532                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13533                                                 buff, buff_size,
13534                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13535                         if (!ret)
13536                                 printf("Package Notes:\n%s\n\n", buff);
13537                         free(buff);
13538                 }
13539         }
13540
13541         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13542                                 (uint8_t *)&dev_num, sizeof(dev_num),
13543                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13544         if (!ret && dev_num) {
13545                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13546                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13547                 if (devs) {
13548                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13549                                                 (uint8_t *)devs, buff_size,
13550                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13551                         if (!ret) {
13552                                 printf("List of supported devices:\n");
13553                                 for (i = 0; i < dev_num; i++) {
13554                                         printf("  %04X:%04X %04X:%04X\n",
13555                                                 devs[i].vendor_dev_id >> 16,
13556                                                 devs[i].vendor_dev_id & 0xFFFF,
13557                                                 devs[i].sub_vendor_dev_id >> 16,
13558                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13559                                 }
13560                                 printf("\n");
13561                         }
13562                         free(devs);
13563                 }
13564         }
13565
13566         /* get information about protocols and packet types */
13567         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13568                 (uint8_t *)&proto_num, sizeof(proto_num),
13569                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13570         if (ret || !proto_num)
13571                 goto no_print_return;
13572
13573         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13574         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13575         if (!proto)
13576                 goto no_print_return;
13577
13578         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13579                                         buff_size,
13580                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13581         if (!ret) {
13582                 printf("List of used protocols:\n");
13583                 for (i = 0; i < proto_num; i++)
13584                         printf("  %2u: %s\n", proto[i].proto_id,
13585                                proto[i].name);
13586                 printf("\n");
13587         }
13588         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13589                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13590                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13591         if (ret || !pctype_num)
13592                 goto no_print_pctypes;
13593
13594         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13595         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13596         if (!pctype)
13597                 goto no_print_pctypes;
13598
13599         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13600                                         buff_size,
13601                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13602         if (ret) {
13603                 free(pctype);
13604                 goto no_print_pctypes;
13605         }
13606
13607         printf("List of defined packet classification types:\n");
13608         for (i = 0; i < pctype_num; i++) {
13609                 printf("  %2u:", pctype[i].ptype_id);
13610                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13611                         proto_id = pctype[i].protocols[j];
13612                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13613                                 for (n = 0; n < proto_num; n++) {
13614                                         if (proto[n].proto_id == proto_id) {
13615                                                 printf(" %s", proto[n].name);
13616                                                 break;
13617                                         }
13618                                 }
13619                         }
13620                 }
13621                 printf("\n");
13622         }
13623         printf("\n");
13624         free(pctype);
13625
13626 no_print_pctypes:
13627
13628         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13629                                         sizeof(ptype_num),
13630                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13631         if (ret || !ptype_num)
13632                 goto no_print_return;
13633
13634         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13635         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13636         if (!ptype)
13637                 goto no_print_return;
13638
13639         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13640                                         buff_size,
13641                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13642         if (ret) {
13643                 free(ptype);
13644                 goto no_print_return;
13645         }
13646         printf("List of defined packet types:\n");
13647         for (i = 0; i < ptype_num; i++) {
13648                 printf("  %2u:", ptype[i].ptype_id);
13649                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13650                         proto_id = ptype[i].protocols[j];
13651                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13652                                 for (n = 0; n < proto_num; n++) {
13653                                         if (proto[n].proto_id == proto_id) {
13654                                                 printf(" %s", proto[n].name);
13655                                                 break;
13656                                         }
13657                                 }
13658                         }
13659                 }
13660                 printf("\n");
13661         }
13662         free(ptype);
13663         printf("\n");
13664
13665         free(proto);
13666         ret = 0;
13667 #endif
13668 no_print_return:
13669         if (ret == -ENOTSUP)
13670                 printf("Function not supported in PMD driver\n");
13671         close_ddp_package_file(pkg);
13672 }
13673
13674 cmdline_parse_inst_t cmd_ddp_get_info = {
13675         .f = cmd_ddp_info_parsed,
13676         .data = NULL,
13677         .help_str = "ddp get info <profile_path>",
13678         .tokens = {
13679                 (void *)&cmd_ddp_info_ddp,
13680                 (void *)&cmd_ddp_info_get,
13681                 (void *)&cmd_ddp_info_info,
13682                 (void *)&cmd_ddp_info_filepath,
13683                 NULL,
13684         },
13685 };
13686
13687 /* Get dynamic device personalization profile info list*/
13688 #define PROFILE_INFO_SIZE 48
13689 #define MAX_PROFILE_NUM 16
13690
13691 struct cmd_ddp_get_list_result {
13692         cmdline_fixed_string_t ddp;
13693         cmdline_fixed_string_t get;
13694         cmdline_fixed_string_t list;
13695         uint8_t port_id;
13696 };
13697
13698 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13699         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13700 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13701         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13702 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13703         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13704 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13705         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13706
13707 static void
13708 cmd_ddp_get_list_parsed(
13709         void *parsed_result,
13710         __attribute__((unused)) struct cmdline *cl,
13711         __attribute__((unused)) void *data)
13712 {
13713         struct cmd_ddp_get_list_result *res = parsed_result;
13714 #ifdef RTE_LIBRTE_I40E_PMD
13715         struct rte_pmd_i40e_profile_list *p_list;
13716         struct rte_pmd_i40e_profile_info *p_info;
13717         uint32_t p_num;
13718         uint32_t size;
13719         uint32_t i;
13720 #endif
13721         int ret = -ENOTSUP;
13722
13723         if (res->port_id > nb_ports) {
13724                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13725                 return;
13726         }
13727
13728 #ifdef RTE_LIBRTE_I40E_PMD
13729         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13730         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13731         if (!p_list)
13732                 printf("%s: Failed to malloc buffer\n", __func__);
13733
13734         if (ret == -ENOTSUP)
13735                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13736                                                 (uint8_t *)p_list, size);
13737
13738         if (!ret) {
13739                 p_num = p_list->p_count;
13740                 printf("Profile number is: %d\n\n", p_num);
13741
13742                 for (i = 0; i < p_num; i++) {
13743                         p_info = &p_list->p_info[i];
13744                         printf("Profile %d:\n", i);
13745                         printf("Track id:     0x%x\n", p_info->track_id);
13746                         printf("Version:      %d.%d.%d.%d\n",
13747                                p_info->version.major,
13748                                p_info->version.minor,
13749                                p_info->version.update,
13750                                p_info->version.draft);
13751                         printf("Profile name: %s\n\n", p_info->name);
13752                 }
13753         }
13754
13755         free(p_list);
13756 #endif
13757
13758         if (ret < 0)
13759                 printf("Failed to get ddp list\n");
13760 }
13761
13762 cmdline_parse_inst_t cmd_ddp_get_list = {
13763         .f = cmd_ddp_get_list_parsed,
13764         .data = NULL,
13765         .help_str = "ddp get list <port_id>",
13766         .tokens = {
13767                 (void *)&cmd_ddp_get_list_ddp,
13768                 (void *)&cmd_ddp_get_list_get,
13769                 (void *)&cmd_ddp_get_list_list,
13770                 (void *)&cmd_ddp_get_list_port_id,
13771                 NULL,
13772         },
13773 };
13774
13775 /* show vf stats */
13776
13777 /* Common result structure for show vf stats */
13778 struct cmd_show_vf_stats_result {
13779         cmdline_fixed_string_t show;
13780         cmdline_fixed_string_t vf;
13781         cmdline_fixed_string_t stats;
13782         uint8_t port_id;
13783         uint16_t vf_id;
13784 };
13785
13786 /* Common CLI fields show vf stats*/
13787 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13788         TOKEN_STRING_INITIALIZER
13789                 (struct cmd_show_vf_stats_result,
13790                  show, "show");
13791 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13792         TOKEN_STRING_INITIALIZER
13793                 (struct cmd_show_vf_stats_result,
13794                  vf, "vf");
13795 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_show_vf_stats_result,
13798                  stats, "stats");
13799 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13800         TOKEN_NUM_INITIALIZER
13801                 (struct cmd_show_vf_stats_result,
13802                  port_id, UINT8);
13803 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13804         TOKEN_NUM_INITIALIZER
13805                 (struct cmd_show_vf_stats_result,
13806                  vf_id, UINT16);
13807
13808 static void
13809 cmd_show_vf_stats_parsed(
13810         void *parsed_result,
13811         __attribute__((unused)) struct cmdline *cl,
13812         __attribute__((unused)) void *data)
13813 {
13814         struct cmd_show_vf_stats_result *res = parsed_result;
13815         struct rte_eth_stats stats;
13816         int ret = -ENOTSUP;
13817         static const char *nic_stats_border = "########################";
13818
13819         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13820                 return;
13821
13822         memset(&stats, 0, sizeof(stats));
13823
13824 #ifdef RTE_LIBRTE_I40E_PMD
13825         if (ret == -ENOTSUP)
13826                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13827                                                 res->vf_id,
13828                                                 &stats);
13829 #endif
13830 #ifdef RTE_LIBRTE_BNXT_PMD
13831         if (ret == -ENOTSUP)
13832                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
13833                                                 res->vf_id,
13834                                                 &stats);
13835 #endif
13836
13837         switch (ret) {
13838         case 0:
13839                 break;
13840         case -EINVAL:
13841                 printf("invalid vf_id %d\n", res->vf_id);
13842                 break;
13843         case -ENODEV:
13844                 printf("invalid port_id %d\n", res->port_id);
13845                 break;
13846         case -ENOTSUP:
13847                 printf("function not implemented\n");
13848                 break;
13849         default:
13850                 printf("programming error: (%s)\n", strerror(-ret));
13851         }
13852
13853         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13854                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13855
13856         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13857                "%-"PRIu64"\n",
13858                stats.ipackets, stats.imissed, stats.ibytes);
13859         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13860         printf("  RX-nombuf:  %-10"PRIu64"\n",
13861                stats.rx_nombuf);
13862         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13863                "%-"PRIu64"\n",
13864                stats.opackets, stats.oerrors, stats.obytes);
13865
13866         printf("  %s############################%s\n",
13867                                nic_stats_border, nic_stats_border);
13868 }
13869
13870 cmdline_parse_inst_t cmd_show_vf_stats = {
13871         .f = cmd_show_vf_stats_parsed,
13872         .data = NULL,
13873         .help_str = "show vf stats <port_id> <vf_id>",
13874         .tokens = {
13875                 (void *)&cmd_show_vf_stats_show,
13876                 (void *)&cmd_show_vf_stats_vf,
13877                 (void *)&cmd_show_vf_stats_stats,
13878                 (void *)&cmd_show_vf_stats_port_id,
13879                 (void *)&cmd_show_vf_stats_vf_id,
13880                 NULL,
13881         },
13882 };
13883
13884 /* clear vf stats */
13885
13886 /* Common result structure for clear vf stats */
13887 struct cmd_clear_vf_stats_result {
13888         cmdline_fixed_string_t clear;
13889         cmdline_fixed_string_t vf;
13890         cmdline_fixed_string_t stats;
13891         uint8_t port_id;
13892         uint16_t vf_id;
13893 };
13894
13895 /* Common CLI fields clear vf stats*/
13896 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13897         TOKEN_STRING_INITIALIZER
13898                 (struct cmd_clear_vf_stats_result,
13899                  clear, "clear");
13900 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13901         TOKEN_STRING_INITIALIZER
13902                 (struct cmd_clear_vf_stats_result,
13903                  vf, "vf");
13904 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13905         TOKEN_STRING_INITIALIZER
13906                 (struct cmd_clear_vf_stats_result,
13907                  stats, "stats");
13908 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13909         TOKEN_NUM_INITIALIZER
13910                 (struct cmd_clear_vf_stats_result,
13911                  port_id, UINT8);
13912 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13913         TOKEN_NUM_INITIALIZER
13914                 (struct cmd_clear_vf_stats_result,
13915                  vf_id, UINT16);
13916
13917 static void
13918 cmd_clear_vf_stats_parsed(
13919         void *parsed_result,
13920         __attribute__((unused)) struct cmdline *cl,
13921         __attribute__((unused)) void *data)
13922 {
13923         struct cmd_clear_vf_stats_result *res = parsed_result;
13924         int ret = -ENOTSUP;
13925
13926         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13927                 return;
13928
13929 #ifdef RTE_LIBRTE_I40E_PMD
13930         if (ret == -ENOTSUP)
13931                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13932                                                   res->vf_id);
13933 #endif
13934 #ifdef RTE_LIBRTE_BNXT_PMD
13935         if (ret == -ENOTSUP)
13936                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
13937                                                   res->vf_id);
13938 #endif
13939
13940         switch (ret) {
13941         case 0:
13942                 break;
13943         case -EINVAL:
13944                 printf("invalid vf_id %d\n", res->vf_id);
13945                 break;
13946         case -ENODEV:
13947                 printf("invalid port_id %d\n", res->port_id);
13948                 break;
13949         case -ENOTSUP:
13950                 printf("function not implemented\n");
13951                 break;
13952         default:
13953                 printf("programming error: (%s)\n", strerror(-ret));
13954         }
13955 }
13956
13957 cmdline_parse_inst_t cmd_clear_vf_stats = {
13958         .f = cmd_clear_vf_stats_parsed,
13959         .data = NULL,
13960         .help_str = "clear vf stats <port_id> <vf_id>",
13961         .tokens = {
13962                 (void *)&cmd_clear_vf_stats_clear,
13963                 (void *)&cmd_clear_vf_stats_vf,
13964                 (void *)&cmd_clear_vf_stats_stats,
13965                 (void *)&cmd_clear_vf_stats_port_id,
13966                 (void *)&cmd_clear_vf_stats_vf_id,
13967                 NULL,
13968         },
13969 };
13970
13971 /* port config pctype mapping reset */
13972
13973 /* Common result structure for port config pctype mapping reset */
13974 struct cmd_pctype_mapping_reset_result {
13975         cmdline_fixed_string_t port;
13976         cmdline_fixed_string_t config;
13977         uint8_t port_id;
13978         cmdline_fixed_string_t pctype;
13979         cmdline_fixed_string_t mapping;
13980         cmdline_fixed_string_t reset;
13981 };
13982
13983 /* Common CLI fields for port config pctype mapping reset*/
13984 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
13985         TOKEN_STRING_INITIALIZER
13986                 (struct cmd_pctype_mapping_reset_result,
13987                  port, "port");
13988 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
13989         TOKEN_STRING_INITIALIZER
13990                 (struct cmd_pctype_mapping_reset_result,
13991                  config, "config");
13992 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
13993         TOKEN_NUM_INITIALIZER
13994                 (struct cmd_pctype_mapping_reset_result,
13995                  port_id, UINT8);
13996 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
13997         TOKEN_STRING_INITIALIZER
13998                 (struct cmd_pctype_mapping_reset_result,
13999                  pctype, "pctype");
14000 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14001         TOKEN_STRING_INITIALIZER
14002                 (struct cmd_pctype_mapping_reset_result,
14003                  mapping, "mapping");
14004 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14005         TOKEN_STRING_INITIALIZER
14006                 (struct cmd_pctype_mapping_reset_result,
14007                  reset, "reset");
14008
14009 static void
14010 cmd_pctype_mapping_reset_parsed(
14011         void *parsed_result,
14012         __attribute__((unused)) struct cmdline *cl,
14013         __attribute__((unused)) void *data)
14014 {
14015         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14016         int ret = -ENOTSUP;
14017
14018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14019                 return;
14020
14021 #ifdef RTE_LIBRTE_I40E_PMD
14022         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14023 #endif
14024
14025         switch (ret) {
14026         case 0:
14027                 break;
14028         case -ENODEV:
14029                 printf("invalid port_id %d\n", res->port_id);
14030                 break;
14031         case -ENOTSUP:
14032                 printf("function not implemented\n");
14033                 break;
14034         default:
14035                 printf("programming error: (%s)\n", strerror(-ret));
14036         }
14037 }
14038
14039 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14040         .f = cmd_pctype_mapping_reset_parsed,
14041         .data = NULL,
14042         .help_str = "port config <port_id> pctype mapping reset",
14043         .tokens = {
14044                 (void *)&cmd_pctype_mapping_reset_port,
14045                 (void *)&cmd_pctype_mapping_reset_config,
14046                 (void *)&cmd_pctype_mapping_reset_port_id,
14047                 (void *)&cmd_pctype_mapping_reset_pctype,
14048                 (void *)&cmd_pctype_mapping_reset_mapping,
14049                 (void *)&cmd_pctype_mapping_reset_reset,
14050                 NULL,
14051         },
14052 };
14053
14054 /* show port pctype mapping */
14055
14056 /* Common result structure for show port pctype mapping */
14057 struct cmd_pctype_mapping_get_result {
14058         cmdline_fixed_string_t show;
14059         cmdline_fixed_string_t port;
14060         uint8_t port_id;
14061         cmdline_fixed_string_t pctype;
14062         cmdline_fixed_string_t mapping;
14063 };
14064
14065 /* Common CLI fields for pctype mapping get */
14066 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14067         TOKEN_STRING_INITIALIZER
14068                 (struct cmd_pctype_mapping_get_result,
14069                  show, "show");
14070 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14071         TOKEN_STRING_INITIALIZER
14072                 (struct cmd_pctype_mapping_get_result,
14073                  port, "port");
14074 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14075         TOKEN_NUM_INITIALIZER
14076                 (struct cmd_pctype_mapping_get_result,
14077                  port_id, UINT8);
14078 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14079         TOKEN_STRING_INITIALIZER
14080                 (struct cmd_pctype_mapping_get_result,
14081                  pctype, "pctype");
14082 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14083         TOKEN_STRING_INITIALIZER
14084                 (struct cmd_pctype_mapping_get_result,
14085                  mapping, "mapping");
14086
14087 static void
14088 cmd_pctype_mapping_get_parsed(
14089         void *parsed_result,
14090         __attribute__((unused)) struct cmdline *cl,
14091         __attribute__((unused)) void *data)
14092 {
14093         struct cmd_pctype_mapping_get_result *res = parsed_result;
14094         int ret = -ENOTSUP;
14095 #ifdef RTE_LIBRTE_I40E_PMD
14096         struct rte_pmd_i40e_flow_type_mapping
14097                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14098         int i, j, first_pctype;
14099 #endif
14100
14101         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14102                 return;
14103
14104 #ifdef RTE_LIBRTE_I40E_PMD
14105         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14106 #endif
14107
14108         switch (ret) {
14109         case 0:
14110                 break;
14111         case -ENODEV:
14112                 printf("invalid port_id %d\n", res->port_id);
14113                 return;
14114         case -ENOTSUP:
14115                 printf("function not implemented\n");
14116                 return;
14117         default:
14118                 printf("programming error: (%s)\n", strerror(-ret));
14119                 return;
14120         }
14121
14122 #ifdef RTE_LIBRTE_I40E_PMD
14123         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14124                 if (mapping[i].pctype != 0ULL) {
14125                         first_pctype = 1;
14126
14127                         printf("pctype: ");
14128                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14129                                 if (mapping[i].pctype & (1ULL << j)) {
14130                                         printf(first_pctype ?
14131                                                "%02d" : ",%02d", j);
14132                                         first_pctype = 0;
14133                                 }
14134                         }
14135                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14136                 }
14137         }
14138 #endif
14139 }
14140
14141 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14142         .f = cmd_pctype_mapping_get_parsed,
14143         .data = NULL,
14144         .help_str = "show port <port_id> pctype mapping",
14145         .tokens = {
14146                 (void *)&cmd_pctype_mapping_get_show,
14147                 (void *)&cmd_pctype_mapping_get_port,
14148                 (void *)&cmd_pctype_mapping_get_port_id,
14149                 (void *)&cmd_pctype_mapping_get_pctype,
14150                 (void *)&cmd_pctype_mapping_get_mapping,
14151                 NULL,
14152         },
14153 };
14154
14155 /* port config pctype mapping update */
14156
14157 /* Common result structure for port config pctype mapping update */
14158 struct cmd_pctype_mapping_update_result {
14159         cmdline_fixed_string_t port;
14160         cmdline_fixed_string_t config;
14161         uint8_t port_id;
14162         cmdline_fixed_string_t pctype;
14163         cmdline_fixed_string_t mapping;
14164         cmdline_fixed_string_t update;
14165         cmdline_fixed_string_t pctype_list;
14166         uint16_t flow_type;
14167 };
14168
14169 /* Common CLI fields for pctype mapping update*/
14170 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14171         TOKEN_STRING_INITIALIZER
14172                 (struct cmd_pctype_mapping_update_result,
14173                  port, "port");
14174 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14175         TOKEN_STRING_INITIALIZER
14176                 (struct cmd_pctype_mapping_update_result,
14177                  config, "config");
14178 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14179         TOKEN_NUM_INITIALIZER
14180                 (struct cmd_pctype_mapping_update_result,
14181                  port_id, UINT8);
14182 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14183         TOKEN_STRING_INITIALIZER
14184                 (struct cmd_pctype_mapping_update_result,
14185                  pctype, "pctype");
14186 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14187         TOKEN_STRING_INITIALIZER
14188                 (struct cmd_pctype_mapping_update_result,
14189                  mapping, "mapping");
14190 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14191         TOKEN_STRING_INITIALIZER
14192                 (struct cmd_pctype_mapping_update_result,
14193                  update, "update");
14194 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14195         TOKEN_STRING_INITIALIZER
14196                 (struct cmd_pctype_mapping_update_result,
14197                  pctype_list, NULL);
14198 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14199         TOKEN_NUM_INITIALIZER
14200                 (struct cmd_pctype_mapping_update_result,
14201                  flow_type, UINT16);
14202
14203 static void
14204 cmd_pctype_mapping_update_parsed(
14205         void *parsed_result,
14206         __attribute__((unused)) struct cmdline *cl,
14207         __attribute__((unused)) void *data)
14208 {
14209         struct cmd_pctype_mapping_update_result *res = parsed_result;
14210         int ret = -ENOTSUP;
14211 #ifdef RTE_LIBRTE_I40E_PMD
14212         struct rte_pmd_i40e_flow_type_mapping mapping;
14213         unsigned int i;
14214 #endif
14215         unsigned int nb_item;
14216         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14217
14218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14219                 return;
14220
14221         nb_item = parse_item_list(res->pctype_list, "pctypes",
14222                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14223
14224 #ifdef RTE_LIBRTE_I40E_PMD
14225         mapping.flow_type = res->flow_type;
14226         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14227                 mapping.pctype |= (1ULL << pctype_list[i]);
14228         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14229                                                 &mapping,
14230                                                 1,
14231                                                 0);
14232 #endif
14233
14234         switch (ret) {
14235         case 0:
14236                 break;
14237         case -EINVAL:
14238                 printf("invalid pctype or flow type\n");
14239                 break;
14240         case -ENODEV:
14241                 printf("invalid port_id %d\n", res->port_id);
14242                 break;
14243         case -ENOTSUP:
14244                 printf("function not implemented\n");
14245                 break;
14246         default:
14247                 printf("programming error: (%s)\n", strerror(-ret));
14248         }
14249 }
14250
14251 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14252         .f = cmd_pctype_mapping_update_parsed,
14253         .data = NULL,
14254         .help_str = "port config <port_id> pctype mapping update"
14255         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14256         .tokens = {
14257                 (void *)&cmd_pctype_mapping_update_port,
14258                 (void *)&cmd_pctype_mapping_update_config,
14259                 (void *)&cmd_pctype_mapping_update_port_id,
14260                 (void *)&cmd_pctype_mapping_update_pctype,
14261                 (void *)&cmd_pctype_mapping_update_mapping,
14262                 (void *)&cmd_pctype_mapping_update_update,
14263                 (void *)&cmd_pctype_mapping_update_pc_type,
14264                 (void *)&cmd_pctype_mapping_update_flow_type,
14265                 NULL,
14266         },
14267 };
14268
14269 /* ptype mapping get */
14270
14271 /* Common result structure for ptype mapping get */
14272 struct cmd_ptype_mapping_get_result {
14273         cmdline_fixed_string_t ptype;
14274         cmdline_fixed_string_t mapping;
14275         cmdline_fixed_string_t get;
14276         uint8_t port_id;
14277         uint8_t valid_only;
14278 };
14279
14280 /* Common CLI fields for ptype mapping get */
14281 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_ptype_mapping_get_result,
14284                  ptype, "ptype");
14285 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14286         TOKEN_STRING_INITIALIZER
14287                 (struct cmd_ptype_mapping_get_result,
14288                  mapping, "mapping");
14289 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14290         TOKEN_STRING_INITIALIZER
14291                 (struct cmd_ptype_mapping_get_result,
14292                  get, "get");
14293 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14294         TOKEN_NUM_INITIALIZER
14295                 (struct cmd_ptype_mapping_get_result,
14296                  port_id, UINT8);
14297 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14298         TOKEN_NUM_INITIALIZER
14299                 (struct cmd_ptype_mapping_get_result,
14300                  valid_only, UINT8);
14301
14302 static void
14303 cmd_ptype_mapping_get_parsed(
14304         void *parsed_result,
14305         __attribute__((unused)) struct cmdline *cl,
14306         __attribute__((unused)) void *data)
14307 {
14308         struct cmd_ptype_mapping_get_result *res = parsed_result;
14309         int ret = -ENOTSUP;
14310 #ifdef RTE_LIBRTE_I40E_PMD
14311         int max_ptype_num = 256;
14312         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14313         uint16_t count;
14314         int i;
14315 #endif
14316
14317         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14318                 return;
14319
14320 #ifdef RTE_LIBRTE_I40E_PMD
14321         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14322                                         mapping,
14323                                         max_ptype_num,
14324                                         &count,
14325                                         res->valid_only);
14326 #endif
14327
14328         switch (ret) {
14329         case 0:
14330                 break;
14331         case -ENODEV:
14332                 printf("invalid port_id %d\n", res->port_id);
14333                 break;
14334         case -ENOTSUP:
14335                 printf("function not implemented\n");
14336                 break;
14337         default:
14338                 printf("programming error: (%s)\n", strerror(-ret));
14339         }
14340
14341 #ifdef RTE_LIBRTE_I40E_PMD
14342         if (!ret) {
14343                 for (i = 0; i < count; i++)
14344                         printf("%3d\t0x%08x\n",
14345                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14346         }
14347 #endif
14348 }
14349
14350 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14351         .f = cmd_ptype_mapping_get_parsed,
14352         .data = NULL,
14353         .help_str = "ptype mapping get <port_id> <valid_only>",
14354         .tokens = {
14355                 (void *)&cmd_ptype_mapping_get_ptype,
14356                 (void *)&cmd_ptype_mapping_get_mapping,
14357                 (void *)&cmd_ptype_mapping_get_get,
14358                 (void *)&cmd_ptype_mapping_get_port_id,
14359                 (void *)&cmd_ptype_mapping_get_valid_only,
14360                 NULL,
14361         },
14362 };
14363
14364 /* ptype mapping replace */
14365
14366 /* Common result structure for ptype mapping replace */
14367 struct cmd_ptype_mapping_replace_result {
14368         cmdline_fixed_string_t ptype;
14369         cmdline_fixed_string_t mapping;
14370         cmdline_fixed_string_t replace;
14371         uint8_t port_id;
14372         uint32_t target;
14373         uint8_t mask;
14374         uint32_t pkt_type;
14375 };
14376
14377 /* Common CLI fields for ptype mapping replace */
14378 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_ptype_mapping_replace_result,
14381                  ptype, "ptype");
14382 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_ptype_mapping_replace_result,
14385                  mapping, "mapping");
14386 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14387         TOKEN_STRING_INITIALIZER
14388                 (struct cmd_ptype_mapping_replace_result,
14389                  replace, "replace");
14390 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14391         TOKEN_NUM_INITIALIZER
14392                 (struct cmd_ptype_mapping_replace_result,
14393                  port_id, UINT8);
14394 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14395         TOKEN_NUM_INITIALIZER
14396                 (struct cmd_ptype_mapping_replace_result,
14397                  target, UINT32);
14398 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14399         TOKEN_NUM_INITIALIZER
14400                 (struct cmd_ptype_mapping_replace_result,
14401                  mask, UINT8);
14402 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14403         TOKEN_NUM_INITIALIZER
14404                 (struct cmd_ptype_mapping_replace_result,
14405                  pkt_type, UINT32);
14406
14407 static void
14408 cmd_ptype_mapping_replace_parsed(
14409         void *parsed_result,
14410         __attribute__((unused)) struct cmdline *cl,
14411         __attribute__((unused)) void *data)
14412 {
14413         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14414         int ret = -ENOTSUP;
14415
14416         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14417                 return;
14418
14419 #ifdef RTE_LIBRTE_I40E_PMD
14420         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14421                                         res->target,
14422                                         res->mask,
14423                                         res->pkt_type);
14424 #endif
14425
14426         switch (ret) {
14427         case 0:
14428                 break;
14429         case -EINVAL:
14430                 printf("invalid ptype 0x%8x or 0x%8x\n",
14431                                 res->target, res->pkt_type);
14432                 break;
14433         case -ENODEV:
14434                 printf("invalid port_id %d\n", res->port_id);
14435                 break;
14436         case -ENOTSUP:
14437                 printf("function not implemented\n");
14438                 break;
14439         default:
14440                 printf("programming error: (%s)\n", strerror(-ret));
14441         }
14442 }
14443
14444 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14445         .f = cmd_ptype_mapping_replace_parsed,
14446         .data = NULL,
14447         .help_str =
14448                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14449         .tokens = {
14450                 (void *)&cmd_ptype_mapping_replace_ptype,
14451                 (void *)&cmd_ptype_mapping_replace_mapping,
14452                 (void *)&cmd_ptype_mapping_replace_replace,
14453                 (void *)&cmd_ptype_mapping_replace_port_id,
14454                 (void *)&cmd_ptype_mapping_replace_target,
14455                 (void *)&cmd_ptype_mapping_replace_mask,
14456                 (void *)&cmd_ptype_mapping_replace_pkt_type,
14457                 NULL,
14458         },
14459 };
14460
14461 /* ptype mapping reset */
14462
14463 /* Common result structure for ptype mapping reset */
14464 struct cmd_ptype_mapping_reset_result {
14465         cmdline_fixed_string_t ptype;
14466         cmdline_fixed_string_t mapping;
14467         cmdline_fixed_string_t reset;
14468         uint8_t port_id;
14469 };
14470
14471 /* Common CLI fields for ptype mapping reset*/
14472 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14473         TOKEN_STRING_INITIALIZER
14474                 (struct cmd_ptype_mapping_reset_result,
14475                  ptype, "ptype");
14476 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14477         TOKEN_STRING_INITIALIZER
14478                 (struct cmd_ptype_mapping_reset_result,
14479                  mapping, "mapping");
14480 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14481         TOKEN_STRING_INITIALIZER
14482                 (struct cmd_ptype_mapping_reset_result,
14483                  reset, "reset");
14484 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14485         TOKEN_NUM_INITIALIZER
14486                 (struct cmd_ptype_mapping_reset_result,
14487                  port_id, UINT8);
14488
14489 static void
14490 cmd_ptype_mapping_reset_parsed(
14491         void *parsed_result,
14492         __attribute__((unused)) struct cmdline *cl,
14493         __attribute__((unused)) void *data)
14494 {
14495         struct cmd_ptype_mapping_reset_result *res = parsed_result;
14496         int ret = -ENOTSUP;
14497
14498         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14499                 return;
14500
14501 #ifdef RTE_LIBRTE_I40E_PMD
14502         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14503 #endif
14504
14505         switch (ret) {
14506         case 0:
14507                 break;
14508         case -ENODEV:
14509                 printf("invalid port_id %d\n", res->port_id);
14510                 break;
14511         case -ENOTSUP:
14512                 printf("function not implemented\n");
14513                 break;
14514         default:
14515                 printf("programming error: (%s)\n", strerror(-ret));
14516         }
14517 }
14518
14519 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14520         .f = cmd_ptype_mapping_reset_parsed,
14521         .data = NULL,
14522         .help_str = "ptype mapping reset <port_id>",
14523         .tokens = {
14524                 (void *)&cmd_ptype_mapping_reset_ptype,
14525                 (void *)&cmd_ptype_mapping_reset_mapping,
14526                 (void *)&cmd_ptype_mapping_reset_reset,
14527                 (void *)&cmd_ptype_mapping_reset_port_id,
14528                 NULL,
14529         },
14530 };
14531
14532 /* ptype mapping update */
14533
14534 /* Common result structure for ptype mapping update */
14535 struct cmd_ptype_mapping_update_result {
14536         cmdline_fixed_string_t ptype;
14537         cmdline_fixed_string_t mapping;
14538         cmdline_fixed_string_t reset;
14539         uint8_t port_id;
14540         uint8_t hw_ptype;
14541         uint32_t sw_ptype;
14542 };
14543
14544 /* Common CLI fields for ptype mapping update*/
14545 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14546         TOKEN_STRING_INITIALIZER
14547                 (struct cmd_ptype_mapping_update_result,
14548                  ptype, "ptype");
14549 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14550         TOKEN_STRING_INITIALIZER
14551                 (struct cmd_ptype_mapping_update_result,
14552                  mapping, "mapping");
14553 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14554         TOKEN_STRING_INITIALIZER
14555                 (struct cmd_ptype_mapping_update_result,
14556                  reset, "update");
14557 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14558         TOKEN_NUM_INITIALIZER
14559                 (struct cmd_ptype_mapping_update_result,
14560                  port_id, UINT8);
14561 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14562         TOKEN_NUM_INITIALIZER
14563                 (struct cmd_ptype_mapping_update_result,
14564                  hw_ptype, UINT8);
14565 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14566         TOKEN_NUM_INITIALIZER
14567                 (struct cmd_ptype_mapping_update_result,
14568                  sw_ptype, UINT32);
14569
14570 static void
14571 cmd_ptype_mapping_update_parsed(
14572         void *parsed_result,
14573         __attribute__((unused)) struct cmdline *cl,
14574         __attribute__((unused)) void *data)
14575 {
14576         struct cmd_ptype_mapping_update_result *res = parsed_result;
14577         int ret = -ENOTSUP;
14578 #ifdef RTE_LIBRTE_I40E_PMD
14579         struct rte_pmd_i40e_ptype_mapping mapping;
14580 #endif
14581         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14582                 return;
14583
14584 #ifdef RTE_LIBRTE_I40E_PMD
14585         mapping.hw_ptype = res->hw_ptype;
14586         mapping.sw_ptype = res->sw_ptype;
14587         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14588                                                 &mapping,
14589                                                 1,
14590                                                 0);
14591 #endif
14592
14593         switch (ret) {
14594         case 0:
14595                 break;
14596         case -EINVAL:
14597                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
14598                 break;
14599         case -ENODEV:
14600                 printf("invalid port_id %d\n", res->port_id);
14601                 break;
14602         case -ENOTSUP:
14603                 printf("function not implemented\n");
14604                 break;
14605         default:
14606                 printf("programming error: (%s)\n", strerror(-ret));
14607         }
14608 }
14609
14610 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14611         .f = cmd_ptype_mapping_update_parsed,
14612         .data = NULL,
14613         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14614         .tokens = {
14615                 (void *)&cmd_ptype_mapping_update_ptype,
14616                 (void *)&cmd_ptype_mapping_update_mapping,
14617                 (void *)&cmd_ptype_mapping_update_update,
14618                 (void *)&cmd_ptype_mapping_update_port_id,
14619                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14620                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14621                 NULL,
14622         },
14623 };
14624
14625 /* Common result structure for file commands */
14626 struct cmd_cmdfile_result {
14627         cmdline_fixed_string_t load;
14628         cmdline_fixed_string_t filename;
14629 };
14630
14631 /* Common CLI fields for file commands */
14632 cmdline_parse_token_string_t cmd_load_cmdfile =
14633         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14634 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14635         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14636
14637 static void
14638 cmd_load_from_file_parsed(
14639         void *parsed_result,
14640         __attribute__((unused)) struct cmdline *cl,
14641         __attribute__((unused)) void *data)
14642 {
14643         struct cmd_cmdfile_result *res = parsed_result;
14644
14645         cmdline_read_from_file(res->filename);
14646 }
14647
14648 cmdline_parse_inst_t cmd_load_from_file = {
14649         .f = cmd_load_from_file_parsed,
14650         .data = NULL,
14651         .help_str = "load <filename>",
14652         .tokens = {
14653                 (void *)&cmd_load_cmdfile,
14654                 (void *)&cmd_load_cmdfile_filename,
14655                 NULL,
14656         },
14657 };
14658
14659 /* ******************************************************************************** */
14660
14661 /* list of instructions */
14662 cmdline_parse_ctx_t main_ctx[] = {
14663         (cmdline_parse_inst_t *)&cmd_help_brief,
14664         (cmdline_parse_inst_t *)&cmd_help_long,
14665         (cmdline_parse_inst_t *)&cmd_quit,
14666         (cmdline_parse_inst_t *)&cmd_load_from_file,
14667         (cmdline_parse_inst_t *)&cmd_showport,
14668         (cmdline_parse_inst_t *)&cmd_showqueue,
14669         (cmdline_parse_inst_t *)&cmd_showportall,
14670         (cmdline_parse_inst_t *)&cmd_showcfg,
14671         (cmdline_parse_inst_t *)&cmd_start,
14672         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14673         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14674         (cmdline_parse_inst_t *)&cmd_set_link_up,
14675         (cmdline_parse_inst_t *)&cmd_set_link_down,
14676         (cmdline_parse_inst_t *)&cmd_reset,
14677         (cmdline_parse_inst_t *)&cmd_set_numbers,
14678         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14679         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14680         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14681         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14682         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14683         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14684         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14685         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14686         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14687         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14688         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14689         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14690         (cmdline_parse_inst_t *)&cmd_set_link_check,
14691         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14692         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14693         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14694         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14695 #ifdef RTE_LIBRTE_PMD_BOND
14696         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14697         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14698         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14699         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14700         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14701         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14702         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14703         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14704         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14705         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14706         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14707 #endif
14708         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14709         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14710         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14711         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14712         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14713         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14714         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14715         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14716         (cmdline_parse_inst_t *)&cmd_csum_set,
14717         (cmdline_parse_inst_t *)&cmd_csum_show,
14718         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14719         (cmdline_parse_inst_t *)&cmd_tso_set,
14720         (cmdline_parse_inst_t *)&cmd_tso_show,
14721         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14722         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14723         (cmdline_parse_inst_t *)&cmd_gro_enable,
14724         (cmdline_parse_inst_t *)&cmd_gro_flush,
14725         (cmdline_parse_inst_t *)&cmd_gro_show,
14726         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14727         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14728         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14729         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14730         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14731         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14732         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14733         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14734         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14735         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14736         (cmdline_parse_inst_t *)&cmd_config_dcb,
14737         (cmdline_parse_inst_t *)&cmd_read_reg,
14738         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14739         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
14740         (cmdline_parse_inst_t *)&cmd_write_reg,
14741         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14742         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
14743         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14744         (cmdline_parse_inst_t *)&cmd_stop,
14745         (cmdline_parse_inst_t *)&cmd_mac_addr,
14746         (cmdline_parse_inst_t *)&cmd_set_qmap,
14747         (cmdline_parse_inst_t *)&cmd_operate_port,
14748         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
14749         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
14750         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
14751         (cmdline_parse_inst_t *)&cmd_config_speed_all,
14752         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
14753         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
14754         (cmdline_parse_inst_t *)&cmd_config_mtu,
14755         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14756         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14757         (cmdline_parse_inst_t *)&cmd_config_rss,
14758         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14759         (cmdline_parse_inst_t *)&cmd_config_txqflags,
14760         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
14761         (cmdline_parse_inst_t *)&cmd_showport_reta,
14762         (cmdline_parse_inst_t *)&cmd_config_burst,
14763         (cmdline_parse_inst_t *)&cmd_config_thresh,
14764         (cmdline_parse_inst_t *)&cmd_config_threshold,
14765         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14766         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14767         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14768         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14769         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14770         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
14771         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14772         (cmdline_parse_inst_t *)&cmd_global_config,
14773         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14774         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
14775         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14776         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14777         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14778         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14779         (cmdline_parse_inst_t *)&cmd_dump,
14780         (cmdline_parse_inst_t *)&cmd_dump_one,
14781         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
14782         (cmdline_parse_inst_t *)&cmd_syn_filter,
14783         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
14784         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
14785         (cmdline_parse_inst_t *)&cmd_flex_filter,
14786         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14787         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14788         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14789         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14790         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14791         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14792         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
14793         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14794         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14795         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14796         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14797         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14798         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14799         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14800         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14801         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14802         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14803         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14804         (cmdline_parse_inst_t *)&cmd_flow,
14805         (cmdline_parse_inst_t *)&cmd_mcast_addr,
14806         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14807         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14808         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14809         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14810         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14811         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14812         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14813         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14814         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14815         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14816         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14817         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14818         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14819         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
14820         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
14821         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
14822         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
14823         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
14824         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
14825         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
14826         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
14827         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
14828         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
14829         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
14830         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
14831         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
14832         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
14833         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
14834         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
14835         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
14836         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
14837         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
14838         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
14839         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
14840         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
14841         (cmdline_parse_inst_t *)&cmd_ddp_add,
14842         (cmdline_parse_inst_t *)&cmd_ddp_del,
14843         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
14844         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
14845         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
14846         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
14847         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
14848         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
14849         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
14850         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
14851
14852         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
14853         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
14854         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
14855         NULL,
14856 };
14857
14858 /* read cmdline commands from file */
14859 void
14860 cmdline_read_from_file(const char *filename)
14861 {
14862         struct cmdline *cl;
14863
14864         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
14865         if (cl == NULL) {
14866                 printf("Failed to create file based cmdline context: %s\n",
14867                        filename);
14868                 return;
14869         }
14870
14871         cmdline_interact(cl);
14872         cmdline_quit(cl);
14873
14874         cmdline_free(cl);
14875
14876         printf("Read CLI commands from %s\n", filename);
14877 }
14878
14879 /* prompt function, called from main on MASTER lcore */
14880 void
14881 prompt(void)
14882 {
14883         /* initialize non-constant commands */
14884         cmd_set_fwd_mode_init();
14885         cmd_set_fwd_retry_mode_init();
14886
14887         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
14888         if (testpmd_cl == NULL)
14889                 return;
14890         cmdline_interact(testpmd_cl);
14891         cmdline_stdin_exit(testpmd_cl);
14892 }
14893
14894 void
14895 prompt_exit(void)
14896 {
14897         if (testpmd_cl != NULL)
14898                 cmdline_quit(testpmd_cl);
14899 }
14900
14901 static void
14902 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
14903 {
14904         if (id == (portid_t)RTE_PORT_ALL) {
14905                 portid_t pid;
14906
14907                 RTE_ETH_FOREACH_DEV(pid) {
14908                         /* check if need_reconfig has been set to 1 */
14909                         if (ports[pid].need_reconfig == 0)
14910                                 ports[pid].need_reconfig = dev;
14911                         /* check if need_reconfig_queues has been set to 1 */
14912                         if (ports[pid].need_reconfig_queues == 0)
14913                                 ports[pid].need_reconfig_queues = queue;
14914                 }
14915         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
14916                 /* check if need_reconfig has been set to 1 */
14917                 if (ports[id].need_reconfig == 0)
14918                         ports[id].need_reconfig = dev;
14919                 /* check if need_reconfig_queues has been set to 1 */
14920                 if (ports[id].need_reconfig_queues == 0)
14921                         ports[id].need_reconfig_queues = queue;
14922         }
14923 }