app/testpmd: remove unnecessary void casts
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102
103 static struct cmdline *testpmd_cl;
104
105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
106
107 /* *** Help command with introduction. *** */
108 struct cmd_help_brief_result {
109         cmdline_fixed_string_t help;
110 };
111
112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
113                                   struct cmdline *cl,
114                                   __attribute__((unused)) void *data)
115 {
116         cmdline_printf(
117                 cl,
118                 "\n"
119                 "Help is available for the following sections:\n\n"
120                 "    help control    : Start and stop forwarding.\n"
121                 "    help display    : Displaying port, stats and config "
122                 "information.\n"
123                 "    help config     : Configuration information.\n"
124                 "    help ports      : Configuring ports.\n"
125                 "    help registers  : Reading and setting port registers.\n"
126                 "    help filters    : Filters configuration help.\n"
127                 "    help all        : All of the above sections.\n\n"
128         );
129
130 }
131
132 cmdline_parse_token_string_t cmd_help_brief_help =
133         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
134
135 cmdline_parse_inst_t cmd_help_brief = {
136         .f = cmd_help_brief_parsed,
137         .data = NULL,
138         .help_str = "help: Show help",
139         .tokens = {
140                 (void *)&cmd_help_brief_help,
141                 NULL,
142         },
143 };
144
145 /* *** Help command with help sections. *** */
146 struct cmd_help_long_result {
147         cmdline_fixed_string_t help;
148         cmdline_fixed_string_t section;
149 };
150
151 static void cmd_help_long_parsed(void *parsed_result,
152                                  struct cmdline *cl,
153                                  __attribute__((unused)) void *data)
154 {
155         int show_all = 0;
156         struct cmd_help_long_result *res = parsed_result;
157
158         if (!strcmp(res->section, "all"))
159                 show_all = 1;
160
161         if (show_all || !strcmp(res->section, "control")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Control forwarding:\n"
167                         "-------------------\n\n"
168
169                         "start\n"
170                         "    Start packet forwarding with current configuration.\n\n"
171
172                         "start tx_first\n"
173                         "    Start packet forwarding with current config"
174                         " after sending one burst of packets.\n\n"
175
176                         "stop\n"
177                         "    Stop packet forwarding, and display accumulated"
178                         " statistics.\n\n"
179
180                         "quit\n"
181                         "    Quit to prompt.\n\n"
182                 );
183         }
184
185         if (show_all || !strcmp(res->section, "display")) {
186
187                 cmdline_printf(
188                         cl,
189                         "\n"
190                         "Display:\n"
191                         "--------\n\n"
192
193                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
194                         "    Display information for port_id, or all.\n\n"
195
196                         "show port X rss reta (size) (mask0,mask1,...)\n"
197                         "    Display the rss redirection table entry indicated"
198                         " by masks on port X. size is used to indicate the"
199                         " hardware supported reta size\n\n"
200
201                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
202                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
203                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
204                         "    Display the RSS hash functions and RSS hash key"
205                         " of port X\n\n"
206
207                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
208                         "    Clear information for port_id, or all.\n\n"
209
210                         "show (rxq|txq) info (port_id) (queue_id)\n"
211                         "    Display information for configured RX/TX queue.\n\n"
212
213                         "show config (rxtx|cores|fwd|txpkts)\n"
214                         "    Display the given configuration.\n\n"
215
216                         "read rxd (port_id) (queue_id) (rxd_id)\n"
217                         "    Display an RX descriptor of a port RX queue.\n\n"
218
219                         "read txd (port_id) (queue_id) (txd_id)\n"
220                         "    Display a TX descriptor of a port TX queue.\n\n"
221
222                         "ddp get list (port_id)\n"
223                         "    Get ddp profile info list\n\n"
224
225                         "ddp get info (profile_path)\n"
226                         "    Get ddp profile information.\n\n"
227
228                         "show vf stats (port_id) (vf_id)\n"
229                         "    Display a VF's statistics.\n\n"
230
231                         "clear vf stats (port_id) (vf_id)\n"
232                         "    Reset a VF's statistics.\n\n"
233                 );
234         }
235
236         if (show_all || !strcmp(res->section, "config")) {
237                 cmdline_printf(
238                         cl,
239                         "\n"
240                         "Configuration:\n"
241                         "--------------\n"
242                         "Configuration changes only become active when"
243                         " forwarding is started/restarted.\n\n"
244
245                         "set default\n"
246                         "    Reset forwarding to the default configuration.\n\n"
247
248                         "set verbose (level)\n"
249                         "    Set the debug verbosity level X.\n\n"
250
251                         "set nbport (num)\n"
252                         "    Set number of ports.\n\n"
253
254                         "set nbcore (num)\n"
255                         "    Set number of cores.\n\n"
256
257                         "set coremask (mask)\n"
258                         "    Set the forwarding cores hexadecimal mask.\n\n"
259
260                         "set portmask (mask)\n"
261                         "    Set the forwarding ports hexadecimal mask.\n\n"
262
263                         "set burst (num)\n"
264                         "    Set number of packets per burst.\n\n"
265
266                         "set burst tx delay (microseconds) retry (num)\n"
267                         "    Set the transmit delay time and number of retries,"
268                         " effective when retry is enabled.\n\n"
269
270                         "set txpkts (x[,y]*)\n"
271                         "    Set the length of each segment of TXONLY"
272                         " and optionally CSUM packets.\n\n"
273
274                         "set txsplit (off|on|rand)\n"
275                         "    Set the split policy for the TX packets."
276                         " Right now only applicable for CSUM and TXONLY"
277                         " modes\n\n"
278
279                         "set corelist (x[,y]*)\n"
280                         "    Set the list of forwarding cores.\n\n"
281
282                         "set portlist (x[,y]*)\n"
283                         "    Set the list of forwarding ports.\n\n"
284
285                         "set tx loopback (port_id) (on|off)\n"
286                         "    Enable or disable tx loopback.\n\n"
287
288                         "set all queues drop (port_id) (on|off)\n"
289                         "    Set drop enable bit for all queues.\n\n"
290
291                         "set vf split drop (port_id) (vf_id) (on|off)\n"
292                         "    Set split drop enable bit for a VF from the PF.\n\n"
293
294                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
295                         "    Set MAC antispoof for a VF from the PF.\n\n"
296
297                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
298                         "    Enable MACsec offload.\n\n"
299
300                         "set macsec offload (port_id) off\n"
301                         "    Disable MACsec offload.\n\n"
302
303                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
304                         "    Configure MACsec secure connection (SC).\n\n"
305
306                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
307                         "    Configure MACsec secure association (SA).\n\n"
308
309                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
310                         "    Set VF broadcast for a VF from the PF.\n\n"
311
312                         "vlan set strip (on|off) (port_id)\n"
313                         "    Set the VLAN strip on a port.\n\n"
314
315                         "vlan set stripq (on|off) (port_id,queue_id)\n"
316                         "    Set the VLAN strip for a queue on a port.\n\n"
317
318                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
319                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
320
321                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
322                         "    Set VLAN insert for a VF from the PF.\n\n"
323
324                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
325                         "    Set VLAN antispoof for a VF from the PF.\n\n"
326
327                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
328                         "    Set VLAN tag for a VF from the PF.\n\n"
329
330                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
331                         "    Set a VF's max bandwidth(Mbps).\n\n"
332
333                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
334                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
335
336                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
337                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
338
339                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
340                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
341
342                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
343                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
344
345                         "vlan set filter (on|off) (port_id)\n"
346                         "    Set the VLAN filter on a port.\n\n"
347
348                         "vlan set qinq (on|off) (port_id)\n"
349                         "    Set the VLAN QinQ (extended queue in queue)"
350                         " on a port.\n\n"
351
352                         "vlan set (inner|outer) tpid (value) (port_id)\n"
353                         "    Set the VLAN TPID for Packet Filtering on"
354                         " a port\n\n"
355
356                         "rx_vlan add (vlan_id|all) (port_id)\n"
357                         "    Add a vlan_id, or all identifiers, to the set"
358                         " of VLAN identifiers filtered by port_id.\n\n"
359
360                         "rx_vlan rm (vlan_id|all) (port_id)\n"
361                         "    Remove a vlan_id, or all identifiers, from the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
365                         "    Add a vlan_id, to the set of VLAN identifiers"
366                         "filtered for VF(s) from port_id.\n\n"
367
368                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Remove a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
373                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
374                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
375                         "   add a tunnel filter of a port.\n\n"
376
377                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
378                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
379                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
380                         "   remove a tunnel filter of a port.\n\n"
381
382                         "rx_vxlan_port add (udp_port) (port_id)\n"
383                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
384
385                         "rx_vxlan_port rm (udp_port) (port_id)\n"
386                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
387
388                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
389                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
390                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
391
392                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
393                         "    Set port based TX VLAN insertion.\n\n"
394
395                         "tx_vlan reset (port_id)\n"
396                         "    Disable hardware insertion of a VLAN header in"
397                         " packets sent on a port.\n\n"
398
399                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
400                         "    Select hardware or software calculation of the"
401                         " checksum when transmitting a packet using the"
402                         " csum forward engine.\n"
403                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
404                         "    outer-ip concerns the outer IP layer in"
405                         " case the packet is recognized as a tunnel packet by"
406                         " the forward engine (vxlan, gre and ipip are supported)\n"
407                         "    Please check the NIC datasheet for HW limits.\n\n"
408
409                         "csum parse-tunnel (on|off) (tx_port_id)\n"
410                         "    If disabled, treat tunnel packets as non-tunneled"
411                         " packets (treat inner headers as payload). The port\n"
412                         "    argument is the port used for TX in csum forward"
413                         " engine.\n\n"
414
415                         "csum show (port_id)\n"
416                         "    Display tx checksum offload configuration\n\n"
417
418                         "tso set (segsize) (portid)\n"
419                         "    Enable TCP Segmentation Offload in csum forward"
420                         " engine.\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "tso show (portid)"
424                         "    Display the status of TCP Segmentation Offload.\n\n"
425
426                         "gro (on|off) (port_id)"
427                         "    Enable or disable Generic Receive Offload in"
428                         " csum forwarding engine.\n\n"
429
430                         "gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n"
431                         "    Set max flow number and max packet number per-flow"
432                         " for GRO.\n\n"
433
434                         "set fwd (%s)\n"
435                         "    Set packet forwarding mode.\n\n"
436
437                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
438                         "    Add a MAC address on port_id.\n\n"
439
440                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
441                         "    Remove a MAC address from port_id.\n\n"
442
443                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
444                         "    Set the default MAC address for port_id.\n\n"
445
446                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
447                         "    Add a MAC address for a VF on the port.\n\n"
448
449                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
450                         "    Set the MAC address for a VF from the PF.\n\n"
451
452                         "set port (port_id) uta (mac_address|all) (on|off)\n"
453                         "    Add/Remove a or all unicast hash filter(s)"
454                         "from port X.\n\n"
455
456                         "set promisc (port_id|all) (on|off)\n"
457                         "    Set the promiscuous mode on port_id, or all.\n\n"
458
459                         "set allmulti (port_id|all) (on|off)\n"
460                         "    Set the allmulti mode on port_id, or all.\n\n"
461
462                         "set vf promisc (port_id) (vf_id) (on|off)\n"
463                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
464
465                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
466                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
467
468                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
469                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
470                         " (on|off) autoneg (on|off) (port_id)\n"
471                         "set flow_ctrl rx (on|off) (portid)\n"
472                         "set flow_ctrl tx (on|off) (portid)\n"
473                         "set flow_ctrl high_water (high_water) (portid)\n"
474                         "set flow_ctrl low_water (low_water) (portid)\n"
475                         "set flow_ctrl pause_time (pause_time) (portid)\n"
476                         "set flow_ctrl send_xon (send_xon) (portid)\n"
477                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
478                         "set flow_ctrl autoneg (on|off) (port_id)\n"
479                         "    Set the link flow control parameter on a port.\n\n"
480
481                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
482                         " (low_water) (pause_time) (priority) (port_id)\n"
483                         "    Set the priority flow control parameter on a"
484                         " port.\n\n"
485
486                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
487                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
488                         " queue on port.\n"
489                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
490                         " on port 0 to mapping 5.\n\n"
491
492                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
493                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
494
495                         "set port (port_id) vf (vf_id) (mac_addr)"
496                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
497                         "   Add/Remove unicast or multicast MAC addr filter"
498                         " for a VF.\n\n"
499
500                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
501                         "|MPE) (on|off)\n"
502                         "    AUPE:accepts untagged VLAN;"
503                         "ROPE:accept unicast hash\n\n"
504                         "    BAM:accepts broadcast packets;"
505                         "MPE:accepts all multicast packets\n\n"
506                         "    Enable/Disable a VF receive mode of a port\n\n"
507
508                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
509                         "    Set rate limit for a queue of a port\n\n"
510
511                         "set port (port_id) vf (vf_id) rate (rate_num) "
512                         "queue_mask (queue_mask_value)\n"
513                         "    Set rate limit for queues in VF of a port\n\n"
514
515                         "set port (port_id) mirror-rule (rule_id)"
516                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
517                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
518                         "   Set pool or vlan type mirror rule on a port.\n"
519                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
520                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
521                         " to pool 0.\n\n"
522
523                         "set port (port_id) mirror-rule (rule_id)"
524                         " (uplink-mirror|downlink-mirror) dst-pool"
525                         " (pool_id) (on|off)\n"
526                         "   Set uplink or downlink type mirror rule on a port.\n"
527                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
528                         " 0 on' enable mirror income traffic to pool 0.\n\n"
529
530                         "reset port (port_id) mirror-rule (rule_id)\n"
531                         "   Reset a mirror rule.\n\n"
532
533                         "set flush_rx (on|off)\n"
534                         "   Flush (default) or don't flush RX streams before"
535                         " forwarding. Mainly used with PCAP drivers.\n\n"
536
537                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
538                         "   Set the bypass mode for the lowest port on bypass enabled"
539                         " NIC.\n\n"
540
541                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
542                         "mode (normal|bypass|isolate) (port_id)\n"
543                         "   Set the event required to initiate specified bypass mode for"
544                         " the lowest port on a bypass enabled NIC where:\n"
545                         "       timeout   = enable bypass after watchdog timeout.\n"
546                         "       os_on     = enable bypass when OS/board is powered on.\n"
547                         "       os_off    = enable bypass when OS/board is powered off.\n"
548                         "       power_on  = enable bypass when power supply is turned on.\n"
549                         "       power_off = enable bypass when power supply is turned off."
550                         "\n\n"
551
552                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
553                         "   Set the bypass watchdog timeout to 'n' seconds"
554                         " where 0 = instant.\n\n"
555
556                         "show bypass config (port_id)\n"
557                         "   Show the bypass configuration for a bypass enabled NIC"
558                         " using the lowest port on the NIC.\n\n"
559
560 #ifdef RTE_LIBRTE_PMD_BOND
561                         "create bonded device (mode) (socket)\n"
562                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
563
564                         "add bonding slave (slave_id) (port_id)\n"
565                         "       Add a slave device to a bonded device.\n\n"
566
567                         "remove bonding slave (slave_id) (port_id)\n"
568                         "       Remove a slave device from a bonded device.\n\n"
569
570                         "set bonding mode (value) (port_id)\n"
571                         "       Set the bonding mode on a bonded device.\n\n"
572
573                         "set bonding primary (slave_id) (port_id)\n"
574                         "       Set the primary slave for a bonded device.\n\n"
575
576                         "show bonding config (port_id)\n"
577                         "       Show the bonding config for port_id.\n\n"
578
579                         "set bonding mac_addr (port_id) (address)\n"
580                         "       Set the MAC address of a bonded device.\n\n"
581
582                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
583                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
584
585                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
586                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
587
588                         "set bonding mon_period (port_id) (value)\n"
589                         "       Set the bonding link status monitoring polling period in ms.\n\n"
590
591                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
592                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
593
594 #endif
595                         "set link-up port (port_id)\n"
596                         "       Set link up for a port.\n\n"
597
598                         "set link-down port (port_id)\n"
599                         "       Set link down for a port.\n\n"
600
601                         "E-tag set insertion on port-tag-id (value)"
602                         " port (port_id) vf (vf_id)\n"
603                         "    Enable E-tag insertion for a VF on a port\n\n"
604
605                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
606                         "    Disable E-tag insertion for a VF on a port\n\n"
607
608                         "E-tag set stripping (on|off) port (port_id)\n"
609                         "    Enable/disable E-tag stripping on a port\n\n"
610
611                         "E-tag set forwarding (on|off) port (port_id)\n"
612                         "    Enable/disable E-tag based forwarding"
613                         " on a port\n\n"
614
615                         "E-tag set filter add e-tag-id (value) dst-pool"
616                         " (pool_id) port (port_id)\n"
617                         "    Add an E-tag forwarding filter on a port\n\n"
618
619                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
620                         "    Delete an E-tag forwarding filter on a port\n\n"
621
622                         "ddp add (port_id) (profile_path[,output_path])\n"
623                         "    Load a profile package on a port\n\n"
624
625                         "ddp del (port_id) (profile_path)\n"
626                         "    Delete a profile package from a port\n\n"
627
628                         "ptype mapping get (port_id) (valid_only)\n"
629                         "    Get ptype mapping on a port\n\n"
630
631                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
632                         "    Replace target with the pkt_type in ptype mapping\n\n"
633
634                         "ptype mapping reset (port_id)\n"
635                         "    Reset ptype mapping on a port\n\n"
636
637                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
638                         "    Update a ptype mapping item on a port\n\n"
639
640                         , list_pkt_forwarding_modes()
641                 );
642         }
643
644         if (show_all || !strcmp(res->section, "ports")) {
645
646                 cmdline_printf(
647                         cl,
648                         "\n"
649                         "Port Operations:\n"
650                         "----------------\n\n"
651
652                         "port start (port_id|all)\n"
653                         "    Start all ports or port_id.\n\n"
654
655                         "port stop (port_id|all)\n"
656                         "    Stop all ports or port_id.\n\n"
657
658                         "port close (port_id|all)\n"
659                         "    Close all ports or port_id.\n\n"
660
661                         "port attach (ident)\n"
662                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
663
664                         "port detach (port_id)\n"
665                         "    Detach physical or virtual dev by port_id\n\n"
666
667                         "port config (port_id|all)"
668                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
669                         " duplex (half|full|auto)\n"
670                         "    Set speed and duplex for all ports or port_id\n\n"
671
672                         "port config all (rxq|txq|rxd|txd) (value)\n"
673                         "    Set number for rxq/txq/rxd/txd.\n\n"
674
675                         "port config all max-pkt-len (value)\n"
676                         "    Set the max packet length.\n\n"
677
678                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
679                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
680                         " (on|off)\n"
681                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
682                         " for ports.\n\n"
683
684                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n"
685                         "    Set the RSS mode.\n\n"
686
687                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
688                         "    Set the RSS redirection table.\n\n"
689
690                         "port config (port_id) dcb vt (on|off) (traffic_class)"
691                         " pfc (on|off)\n"
692                         "    Set the DCB mode.\n\n"
693
694                         "port config all burst (value)\n"
695                         "    Set the number of packets per burst.\n\n"
696
697                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
698                         " (value)\n"
699                         "    Set the ring prefetch/host/writeback threshold"
700                         " for tx/rx queue.\n\n"
701
702                         "port config all (txfreet|txrst|rxfreet) (value)\n"
703                         "    Set free threshold for rx/tx, or set"
704                         " tx rs bit threshold.\n\n"
705                         "port config mtu X value\n"
706                         "    Set the MTU of port X to a given value\n\n"
707
708                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
709                         "    Start/stop a rx/tx queue of port X. Only take effect"
710                         " when port X is started\n\n"
711
712                         "port config (port_id|all) l2-tunnel E-tag ether-type"
713                         " (value)\n"
714                         "    Set the value of E-tag ether-type.\n\n"
715
716                         "port config (port_id|all) l2-tunnel E-tag"
717                         " (enable|disable)\n"
718                         "    Enable/disable the E-tag support.\n\n"
719                 );
720         }
721
722         if (show_all || !strcmp(res->section, "registers")) {
723
724                 cmdline_printf(
725                         cl,
726                         "\n"
727                         "Registers:\n"
728                         "----------\n\n"
729
730                         "read reg (port_id) (address)\n"
731                         "    Display value of a port register.\n\n"
732
733                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
734                         "    Display a port register bit field.\n\n"
735
736                         "read regbit (port_id) (address) (bit_x)\n"
737                         "    Display a single port register bit.\n\n"
738
739                         "write reg (port_id) (address) (value)\n"
740                         "    Set value of a port register.\n\n"
741
742                         "write regfield (port_id) (address) (bit_x) (bit_y)"
743                         " (value)\n"
744                         "    Set bit field of a port register.\n\n"
745
746                         "write regbit (port_id) (address) (bit_x) (value)\n"
747                         "    Set single bit value of a port register.\n\n"
748                 );
749         }
750         if (show_all || !strcmp(res->section, "filters")) {
751
752                 cmdline_printf(
753                         cl,
754                         "\n"
755                         "filters:\n"
756                         "--------\n\n"
757
758                         "ethertype_filter (port_id) (add|del)"
759                         " (mac_addr|mac_ignr) (mac_address) ethertype"
760                         " (ether_type) (drop|fwd) queue (queue_id)\n"
761                         "    Add/Del an ethertype filter.\n\n"
762
763                         "2tuple_filter (port_id) (add|del)"
764                         " dst_port (dst_port_value) protocol (protocol_value)"
765                         " mask (mask_value) tcp_flags (tcp_flags_value)"
766                         " priority (prio_value) queue (queue_id)\n"
767                         "    Add/Del a 2tuple filter.\n\n"
768
769                         "5tuple_filter (port_id) (add|del)"
770                         " dst_ip (dst_address) src_ip (src_address)"
771                         " dst_port (dst_port_value) src_port (src_port_value)"
772                         " protocol (protocol_value)"
773                         " mask (mask_value) tcp_flags (tcp_flags_value)"
774                         " priority (prio_value) queue (queue_id)\n"
775                         "    Add/Del a 5tuple filter.\n\n"
776
777                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
778                         "    Add/Del syn filter.\n\n"
779
780                         "flex_filter (port_id) (add|del) len (len_value)"
781                         " bytes (bytes_value) mask (mask_value)"
782                         " priority (prio_value) queue (queue_id)\n"
783                         "    Add/Del a flex filter.\n\n"
784
785                         "flow_director_filter (port_id) mode IP (add|del|update)"
786                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
787                         " src (src_ip_address) dst (dst_ip_address)"
788                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
789                         " vlan (vlan_value) flexbytes (flexbytes_value)"
790                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
791                         " fd_id (fd_id_value)\n"
792                         "    Add/Del an IP type flow director filter.\n\n"
793
794                         "flow_director_filter (port_id) mode IP (add|del|update)"
795                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
796                         " src (src_ip_address) (src_port)"
797                         " dst (dst_ip_address) (dst_port)"
798                         " tos (tos_value) ttl (ttl_value)"
799                         " vlan (vlan_value) flexbytes (flexbytes_value)"
800                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
801                         " fd_id (fd_id_value)\n"
802                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
803
804                         "flow_director_filter (port_id) mode IP (add|del|update)"
805                         " flow (ipv4-sctp|ipv6-sctp)"
806                         " src (src_ip_address) (src_port)"
807                         " dst (dst_ip_address) (dst_port)"
808                         " tag (verification_tag) "
809                         " tos (tos_value) ttl (ttl_value)"
810                         " vlan (vlan_value)"
811                         " flexbytes (flexbytes_value) (drop|fwd)"
812                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
813                         "    Add/Del a SCTP type flow director filter.\n\n"
814
815                         "flow_director_filter (port_id) mode IP (add|del|update)"
816                         " flow l2_payload ether (ethertype)"
817                         " flexbytes (flexbytes_value) (drop|fwd)"
818                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
819                         "    Add/Del a l2 payload type flow director filter.\n\n"
820
821                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
822                         " mac (mac_address) vlan (vlan_value)"
823                         " flexbytes (flexbytes_value) (drop|fwd)"
824                         " queue (queue_id) fd_id (fd_id_value)\n"
825                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
826
827                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
828                         " mac (mac_address) vlan (vlan_value)"
829                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
830                         " flexbytes (flexbytes_value) (drop|fwd)"
831                         " queue (queue_id) fd_id (fd_id_value)\n"
832                         "    Add/Del a Tunnel flow director filter.\n\n"
833
834                         "flush_flow_director (port_id)\n"
835                         "    Flush all flow director entries of a device.\n\n"
836
837                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
838                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
839                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
840                         "    Set flow director IP mask.\n\n"
841
842                         "flow_director_mask (port_id) mode MAC-VLAN"
843                         " vlan (vlan_value)\n"
844                         "    Set flow director MAC-VLAN mask.\n\n"
845
846                         "flow_director_mask (port_id) mode Tunnel"
847                         " vlan (vlan_value) mac (mac_value)"
848                         " tunnel-type (tunnel_type_value)"
849                         " tunnel-id (tunnel_id_value)\n"
850                         "    Set flow director Tunnel mask.\n\n"
851
852                         "flow_director_flex_mask (port_id)"
853                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
854                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
855                         " (mask)\n"
856                         "    Configure mask of flex payload.\n\n"
857
858                         "flow_director_flex_payload (port_id)"
859                         " (raw|l2|l3|l4) (config)\n"
860                         "    Configure flex payload selection.\n\n"
861
862                         "get_sym_hash_ena_per_port (port_id)\n"
863                         "    get symmetric hash enable configuration per port.\n\n"
864
865                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
866                         "    set symmetric hash enable configuration per port"
867                         " to enable or disable.\n\n"
868
869                         "get_hash_global_config (port_id)\n"
870                         "    Get the global configurations of hash filters.\n\n"
871
872                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
873                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
874                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
875                         " (enable|disable)\n"
876                         "    Set the global configurations of hash filters.\n\n"
877
878                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
879                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
880                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
881                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
882                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
883                         "ipv6-next-header|udp-src-port|udp-dst-port|"
884                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
885                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
886                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
887                         "fld-8th|none) (select|add)\n"
888                         "    Set the input set for hash.\n\n"
889
890                         "set_fdir_input_set (port_id) "
891                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
892                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
893                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
894                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
895                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
896                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
897                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
898                         " (select|add)\n"
899                         "    Set the input set for FDir.\n\n"
900
901                         "flow validate {port_id}"
902                         " [group {group_id}] [priority {level}]"
903                         " [ingress] [egress]"
904                         " pattern {item} [/ {item} [...]] / end"
905                         " actions {action} [/ {action} [...]] / end\n"
906                         "    Check whether a flow rule can be created.\n\n"
907
908                         "flow create {port_id}"
909                         " [group {group_id}] [priority {level}]"
910                         " [ingress] [egress]"
911                         " pattern {item} [/ {item} [...]] / end"
912                         " actions {action} [/ {action} [...]] / end\n"
913                         "    Create a flow rule.\n\n"
914
915                         "flow destroy {port_id} rule {rule_id} [...]\n"
916                         "    Destroy specific flow rules.\n\n"
917
918                         "flow flush {port_id}\n"
919                         "    Destroy all flow rules.\n\n"
920
921                         "flow query {port_id} {rule_id} {action}\n"
922                         "    Query an existing flow rule.\n\n"
923
924                         "flow list {port_id} [group {group_id}] [...]\n"
925                         "    List existing flow rules sorted by priority,"
926                         " filtered by group identifiers.\n\n"
927
928                         "flow isolate {port_id} {boolean}\n"
929                         "    Restrict ingress traffic to the defined"
930                         " flow rules\n\n"
931                 );
932         }
933 }
934
935 cmdline_parse_token_string_t cmd_help_long_help =
936         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
937
938 cmdline_parse_token_string_t cmd_help_long_section =
939         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
940                         "all#control#display#config#"
941                         "ports#registers#filters");
942
943 cmdline_parse_inst_t cmd_help_long = {
944         .f = cmd_help_long_parsed,
945         .data = NULL,
946         .help_str = "help all|control|display|config|ports|register|filters: "
947                 "Show help",
948         .tokens = {
949                 (void *)&cmd_help_long_help,
950                 (void *)&cmd_help_long_section,
951                 NULL,
952         },
953 };
954
955
956 /* *** start/stop/close all ports *** */
957 struct cmd_operate_port_result {
958         cmdline_fixed_string_t keyword;
959         cmdline_fixed_string_t name;
960         cmdline_fixed_string_t value;
961 };
962
963 static void cmd_operate_port_parsed(void *parsed_result,
964                                 __attribute__((unused)) struct cmdline *cl,
965                                 __attribute__((unused)) void *data)
966 {
967         struct cmd_operate_port_result *res = parsed_result;
968
969         if (!strcmp(res->name, "start"))
970                 start_port(RTE_PORT_ALL);
971         else if (!strcmp(res->name, "stop"))
972                 stop_port(RTE_PORT_ALL);
973         else if (!strcmp(res->name, "close"))
974                 close_port(RTE_PORT_ALL);
975         else if (!strcmp(res->name, "reset"))
976                 reset_port(RTE_PORT_ALL);
977         else
978                 printf("Unknown parameter\n");
979 }
980
981 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
982         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
983                                                                 "port");
984 cmdline_parse_token_string_t cmd_operate_port_all_port =
985         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
986                                                 "start#stop#close#reset");
987 cmdline_parse_token_string_t cmd_operate_port_all_all =
988         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
989
990 cmdline_parse_inst_t cmd_operate_port = {
991         .f = cmd_operate_port_parsed,
992         .data = NULL,
993         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
994         .tokens = {
995                 (void *)&cmd_operate_port_all_cmd,
996                 (void *)&cmd_operate_port_all_port,
997                 (void *)&cmd_operate_port_all_all,
998                 NULL,
999         },
1000 };
1001
1002 /* *** start/stop/close specific port *** */
1003 struct cmd_operate_specific_port_result {
1004         cmdline_fixed_string_t keyword;
1005         cmdline_fixed_string_t name;
1006         uint8_t value;
1007 };
1008
1009 static void cmd_operate_specific_port_parsed(void *parsed_result,
1010                         __attribute__((unused)) struct cmdline *cl,
1011                                 __attribute__((unused)) void *data)
1012 {
1013         struct cmd_operate_specific_port_result *res = parsed_result;
1014
1015         if (!strcmp(res->name, "start"))
1016                 start_port(res->value);
1017         else if (!strcmp(res->name, "stop"))
1018                 stop_port(res->value);
1019         else if (!strcmp(res->name, "close"))
1020                 close_port(res->value);
1021         else if (!strcmp(res->name, "reset"))
1022                 reset_port(res->value);
1023         else
1024                 printf("Unknown parameter\n");
1025 }
1026
1027 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1028         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1029                                                         keyword, "port");
1030 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1031         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1032                                                 name, "start#stop#close#reset");
1033 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1034         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1035                                                         value, UINT8);
1036
1037 cmdline_parse_inst_t cmd_operate_specific_port = {
1038         .f = cmd_operate_specific_port_parsed,
1039         .data = NULL,
1040         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1041         .tokens = {
1042                 (void *)&cmd_operate_specific_port_cmd,
1043                 (void *)&cmd_operate_specific_port_port,
1044                 (void *)&cmd_operate_specific_port_id,
1045                 NULL,
1046         },
1047 };
1048
1049 /* *** attach a specified port *** */
1050 struct cmd_operate_attach_port_result {
1051         cmdline_fixed_string_t port;
1052         cmdline_fixed_string_t keyword;
1053         cmdline_fixed_string_t identifier;
1054 };
1055
1056 static void cmd_operate_attach_port_parsed(void *parsed_result,
1057                                 __attribute__((unused)) struct cmdline *cl,
1058                                 __attribute__((unused)) void *data)
1059 {
1060         struct cmd_operate_attach_port_result *res = parsed_result;
1061
1062         if (!strcmp(res->keyword, "attach"))
1063                 attach_port(res->identifier);
1064         else
1065                 printf("Unknown parameter\n");
1066 }
1067
1068 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1069         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1070                         port, "port");
1071 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1072         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1073                         keyword, "attach");
1074 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1075         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1076                         identifier, NULL);
1077
1078 cmdline_parse_inst_t cmd_operate_attach_port = {
1079         .f = cmd_operate_attach_port_parsed,
1080         .data = NULL,
1081         .help_str = "port attach <identifier>: "
1082                 "(identifier: pci address or virtual dev name)",
1083         .tokens = {
1084                 (void *)&cmd_operate_attach_port_port,
1085                 (void *)&cmd_operate_attach_port_keyword,
1086                 (void *)&cmd_operate_attach_port_identifier,
1087                 NULL,
1088         },
1089 };
1090
1091 /* *** detach a specified port *** */
1092 struct cmd_operate_detach_port_result {
1093         cmdline_fixed_string_t port;
1094         cmdline_fixed_string_t keyword;
1095         uint8_t port_id;
1096 };
1097
1098 static void cmd_operate_detach_port_parsed(void *parsed_result,
1099                                 __attribute__((unused)) struct cmdline *cl,
1100                                 __attribute__((unused)) void *data)
1101 {
1102         struct cmd_operate_detach_port_result *res = parsed_result;
1103
1104         if (!strcmp(res->keyword, "detach"))
1105                 detach_port(res->port_id);
1106         else
1107                 printf("Unknown parameter\n");
1108 }
1109
1110 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1111         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1112                         port, "port");
1113 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1114         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1115                         keyword, "detach");
1116 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1117         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1118                         port_id, UINT8);
1119
1120 cmdline_parse_inst_t cmd_operate_detach_port = {
1121         .f = cmd_operate_detach_port_parsed,
1122         .data = NULL,
1123         .help_str = "port detach <port_id>",
1124         .tokens = {
1125                 (void *)&cmd_operate_detach_port_port,
1126                 (void *)&cmd_operate_detach_port_keyword,
1127                 (void *)&cmd_operate_detach_port_port_id,
1128                 NULL,
1129         },
1130 };
1131
1132 /* *** configure speed for all ports *** */
1133 struct cmd_config_speed_all {
1134         cmdline_fixed_string_t port;
1135         cmdline_fixed_string_t keyword;
1136         cmdline_fixed_string_t all;
1137         cmdline_fixed_string_t item1;
1138         cmdline_fixed_string_t item2;
1139         cmdline_fixed_string_t value1;
1140         cmdline_fixed_string_t value2;
1141 };
1142
1143 static int
1144 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1145 {
1146
1147         int duplex;
1148
1149         if (!strcmp(duplexstr, "half")) {
1150                 duplex = ETH_LINK_HALF_DUPLEX;
1151         } else if (!strcmp(duplexstr, "full")) {
1152                 duplex = ETH_LINK_FULL_DUPLEX;
1153         } else if (!strcmp(duplexstr, "auto")) {
1154                 duplex = ETH_LINK_FULL_DUPLEX;
1155         } else {
1156                 printf("Unknown duplex parameter\n");
1157                 return -1;
1158         }
1159
1160         if (!strcmp(speedstr, "10")) {
1161                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1162                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1163         } else if (!strcmp(speedstr, "100")) {
1164                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1165                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1166         } else {
1167                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1168                         printf("Invalid speed/duplex parameters\n");
1169                         return -1;
1170                 }
1171                 if (!strcmp(speedstr, "1000")) {
1172                         *speed = ETH_LINK_SPEED_1G;
1173                 } else if (!strcmp(speedstr, "10000")) {
1174                         *speed = ETH_LINK_SPEED_10G;
1175                 } else if (!strcmp(speedstr, "25000")) {
1176                         *speed = ETH_LINK_SPEED_25G;
1177                 } else if (!strcmp(speedstr, "40000")) {
1178                         *speed = ETH_LINK_SPEED_40G;
1179                 } else if (!strcmp(speedstr, "50000")) {
1180                         *speed = ETH_LINK_SPEED_50G;
1181                 } else if (!strcmp(speedstr, "100000")) {
1182                         *speed = ETH_LINK_SPEED_100G;
1183                 } else if (!strcmp(speedstr, "auto")) {
1184                         *speed = ETH_LINK_SPEED_AUTONEG;
1185                 } else {
1186                         printf("Unknown speed parameter\n");
1187                         return -1;
1188                 }
1189         }
1190
1191         return 0;
1192 }
1193
1194 static void
1195 cmd_config_speed_all_parsed(void *parsed_result,
1196                         __attribute__((unused)) struct cmdline *cl,
1197                         __attribute__((unused)) void *data)
1198 {
1199         struct cmd_config_speed_all *res = parsed_result;
1200         uint32_t link_speed;
1201         portid_t pid;
1202
1203         if (!all_ports_stopped()) {
1204                 printf("Please stop all ports first\n");
1205                 return;
1206         }
1207
1208         if (parse_and_check_speed_duplex(res->value1, res->value2,
1209                         &link_speed) < 0)
1210                 return;
1211
1212         RTE_ETH_FOREACH_DEV(pid) {
1213                 ports[pid].dev_conf.link_speeds = link_speed;
1214         }
1215
1216         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1217 }
1218
1219 cmdline_parse_token_string_t cmd_config_speed_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1221 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1222         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1223                                                         "config");
1224 cmdline_parse_token_string_t cmd_config_speed_all_all =
1225         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1226 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1227         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1228 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1229         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1230                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1231 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1232         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1233 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1234         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1235                                                 "half#full#auto");
1236
1237 cmdline_parse_inst_t cmd_config_speed_all = {
1238         .f = cmd_config_speed_all_parsed,
1239         .data = NULL,
1240         .help_str = "port config all speed "
1241                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1242                                                         "half|full|auto",
1243         .tokens = {
1244                 (void *)&cmd_config_speed_all_port,
1245                 (void *)&cmd_config_speed_all_keyword,
1246                 (void *)&cmd_config_speed_all_all,
1247                 (void *)&cmd_config_speed_all_item1,
1248                 (void *)&cmd_config_speed_all_value1,
1249                 (void *)&cmd_config_speed_all_item2,
1250                 (void *)&cmd_config_speed_all_value2,
1251                 NULL,
1252         },
1253 };
1254
1255 /* *** configure speed for specific port *** */
1256 struct cmd_config_speed_specific {
1257         cmdline_fixed_string_t port;
1258         cmdline_fixed_string_t keyword;
1259         uint8_t id;
1260         cmdline_fixed_string_t item1;
1261         cmdline_fixed_string_t item2;
1262         cmdline_fixed_string_t value1;
1263         cmdline_fixed_string_t value2;
1264 };
1265
1266 static void
1267 cmd_config_speed_specific_parsed(void *parsed_result,
1268                                 __attribute__((unused)) struct cmdline *cl,
1269                                 __attribute__((unused)) void *data)
1270 {
1271         struct cmd_config_speed_specific *res = parsed_result;
1272         uint32_t link_speed;
1273
1274         if (!all_ports_stopped()) {
1275                 printf("Please stop all ports first\n");
1276                 return;
1277         }
1278
1279         if (port_id_is_invalid(res->id, ENABLED_WARN))
1280                 return;
1281
1282         if (parse_and_check_speed_duplex(res->value1, res->value2,
1283                         &link_speed) < 0)
1284                 return;
1285
1286         ports[res->id].dev_conf.link_speeds = link_speed;
1287
1288         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1289 }
1290
1291
1292 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1293         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1294                                                                 "port");
1295 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1296         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1297                                                                 "config");
1298 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1299         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1300 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1301         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1302                                                                 "speed");
1303 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1304         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1305                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1306 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1307         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1308                                                                 "duplex");
1309 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1310         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1311                                                         "half#full#auto");
1312
1313 cmdline_parse_inst_t cmd_config_speed_specific = {
1314         .f = cmd_config_speed_specific_parsed,
1315         .data = NULL,
1316         .help_str = "port config <port_id> speed "
1317                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1318                                                         "half|full|auto",
1319         .tokens = {
1320                 (void *)&cmd_config_speed_specific_port,
1321                 (void *)&cmd_config_speed_specific_keyword,
1322                 (void *)&cmd_config_speed_specific_id,
1323                 (void *)&cmd_config_speed_specific_item1,
1324                 (void *)&cmd_config_speed_specific_value1,
1325                 (void *)&cmd_config_speed_specific_item2,
1326                 (void *)&cmd_config_speed_specific_value2,
1327                 NULL,
1328         },
1329 };
1330
1331 /* *** configure txq/rxq, txd/rxd *** */
1332 struct cmd_config_rx_tx {
1333         cmdline_fixed_string_t port;
1334         cmdline_fixed_string_t keyword;
1335         cmdline_fixed_string_t all;
1336         cmdline_fixed_string_t name;
1337         uint16_t value;
1338 };
1339
1340 static void
1341 cmd_config_rx_tx_parsed(void *parsed_result,
1342                         __attribute__((unused)) struct cmdline *cl,
1343                         __attribute__((unused)) void *data)
1344 {
1345         struct cmd_config_rx_tx *res = parsed_result;
1346
1347         if (!all_ports_stopped()) {
1348                 printf("Please stop all ports first\n");
1349                 return;
1350         }
1351         if (!strcmp(res->name, "rxq")) {
1352                 if (!res->value && !nb_txq) {
1353                         printf("Warning: Either rx or tx queues should be non zero\n");
1354                         return;
1355                 }
1356                 nb_rxq = res->value;
1357         }
1358         else if (!strcmp(res->name, "txq")) {
1359                 if (!res->value && !nb_rxq) {
1360                         printf("Warning: Either rx or tx queues should be non zero\n");
1361                         return;
1362                 }
1363                 nb_txq = res->value;
1364         }
1365         else if (!strcmp(res->name, "rxd")) {
1366                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1367                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1368                                         res->value, RTE_TEST_RX_DESC_MAX);
1369                         return;
1370                 }
1371                 nb_rxd = res->value;
1372         } else if (!strcmp(res->name, "txd")) {
1373                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1374                         printf("txd %d invalid - must be > 0 && <= %d\n",
1375                                         res->value, RTE_TEST_TX_DESC_MAX);
1376                         return;
1377                 }
1378                 nb_txd = res->value;
1379         } else {
1380                 printf("Unknown parameter\n");
1381                 return;
1382         }
1383
1384         fwd_config_setup();
1385
1386         init_port_config();
1387
1388         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1389 }
1390
1391 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1393 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1395 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1397 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1399                                                 "rxq#txq#rxd#txd");
1400 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1401         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1402
1403 cmdline_parse_inst_t cmd_config_rx_tx = {
1404         .f = cmd_config_rx_tx_parsed,
1405         .data = NULL,
1406         .help_str = "port config all rxq|txq|rxd|txd <value>",
1407         .tokens = {
1408                 (void *)&cmd_config_rx_tx_port,
1409                 (void *)&cmd_config_rx_tx_keyword,
1410                 (void *)&cmd_config_rx_tx_all,
1411                 (void *)&cmd_config_rx_tx_name,
1412                 (void *)&cmd_config_rx_tx_value,
1413                 NULL,
1414         },
1415 };
1416
1417 /* *** config max packet length *** */
1418 struct cmd_config_max_pkt_len_result {
1419         cmdline_fixed_string_t port;
1420         cmdline_fixed_string_t keyword;
1421         cmdline_fixed_string_t all;
1422         cmdline_fixed_string_t name;
1423         uint32_t value;
1424 };
1425
1426 static void
1427 cmd_config_max_pkt_len_parsed(void *parsed_result,
1428                                 __attribute__((unused)) struct cmdline *cl,
1429                                 __attribute__((unused)) void *data)
1430 {
1431         struct cmd_config_max_pkt_len_result *res = parsed_result;
1432
1433         if (!all_ports_stopped()) {
1434                 printf("Please stop all ports first\n");
1435                 return;
1436         }
1437
1438         if (!strcmp(res->name, "max-pkt-len")) {
1439                 if (res->value < ETHER_MIN_LEN) {
1440                         printf("max-pkt-len can not be less than %d\n",
1441                                                         ETHER_MIN_LEN);
1442                         return;
1443                 }
1444                 if (res->value == rx_mode.max_rx_pkt_len)
1445                         return;
1446
1447                 rx_mode.max_rx_pkt_len = res->value;
1448                 if (res->value > ETHER_MAX_LEN)
1449                         rx_mode.jumbo_frame = 1;
1450                 else
1451                         rx_mode.jumbo_frame = 0;
1452         } else {
1453                 printf("Unknown parameter\n");
1454                 return;
1455         }
1456
1457         init_port_config();
1458
1459         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1460 }
1461
1462 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1464                                                                 "port");
1465 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1467                                                                 "config");
1468 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1470                                                                 "all");
1471 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1473                                                                 "max-pkt-len");
1474 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1475         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1476                                                                 UINT32);
1477
1478 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1479         .f = cmd_config_max_pkt_len_parsed,
1480         .data = NULL,
1481         .help_str = "port config all max-pkt-len <value>",
1482         .tokens = {
1483                 (void *)&cmd_config_max_pkt_len_port,
1484                 (void *)&cmd_config_max_pkt_len_keyword,
1485                 (void *)&cmd_config_max_pkt_len_all,
1486                 (void *)&cmd_config_max_pkt_len_name,
1487                 (void *)&cmd_config_max_pkt_len_value,
1488                 NULL,
1489         },
1490 };
1491
1492 /* *** configure port MTU *** */
1493 struct cmd_config_mtu_result {
1494         cmdline_fixed_string_t port;
1495         cmdline_fixed_string_t keyword;
1496         cmdline_fixed_string_t mtu;
1497         uint8_t port_id;
1498         uint16_t value;
1499 };
1500
1501 static void
1502 cmd_config_mtu_parsed(void *parsed_result,
1503                       __attribute__((unused)) struct cmdline *cl,
1504                       __attribute__((unused)) void *data)
1505 {
1506         struct cmd_config_mtu_result *res = parsed_result;
1507
1508         if (res->value < ETHER_MIN_LEN) {
1509                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1510                 return;
1511         }
1512         port_mtu_set(res->port_id, res->value);
1513 }
1514
1515 cmdline_parse_token_string_t cmd_config_mtu_port =
1516         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1517                                  "port");
1518 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1519         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1520                                  "config");
1521 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1522         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1523                                  "mtu");
1524 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1525         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1526 cmdline_parse_token_num_t cmd_config_mtu_value =
1527         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1528
1529 cmdline_parse_inst_t cmd_config_mtu = {
1530         .f = cmd_config_mtu_parsed,
1531         .data = NULL,
1532         .help_str = "port config mtu <port_id> <value>",
1533         .tokens = {
1534                 (void *)&cmd_config_mtu_port,
1535                 (void *)&cmd_config_mtu_keyword,
1536                 (void *)&cmd_config_mtu_mtu,
1537                 (void *)&cmd_config_mtu_port_id,
1538                 (void *)&cmd_config_mtu_value,
1539                 NULL,
1540         },
1541 };
1542
1543 /* *** configure rx mode *** */
1544 struct cmd_config_rx_mode_flag {
1545         cmdline_fixed_string_t port;
1546         cmdline_fixed_string_t keyword;
1547         cmdline_fixed_string_t all;
1548         cmdline_fixed_string_t name;
1549         cmdline_fixed_string_t value;
1550 };
1551
1552 static void
1553 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1554                                 __attribute__((unused)) struct cmdline *cl,
1555                                 __attribute__((unused)) void *data)
1556 {
1557         struct cmd_config_rx_mode_flag *res = parsed_result;
1558
1559         if (!all_ports_stopped()) {
1560                 printf("Please stop all ports first\n");
1561                 return;
1562         }
1563
1564         if (!strcmp(res->name, "crc-strip")) {
1565                 if (!strcmp(res->value, "on"))
1566                         rx_mode.hw_strip_crc = 1;
1567                 else if (!strcmp(res->value, "off"))
1568                         rx_mode.hw_strip_crc = 0;
1569                 else {
1570                         printf("Unknown parameter\n");
1571                         return;
1572                 }
1573         } else if (!strcmp(res->name, "scatter")) {
1574                 if (!strcmp(res->value, "on"))
1575                         rx_mode.enable_scatter = 1;
1576                 else if (!strcmp(res->value, "off"))
1577                         rx_mode.enable_scatter = 0;
1578                 else {
1579                         printf("Unknown parameter\n");
1580                         return;
1581                 }
1582         } else if (!strcmp(res->name, "rx-cksum")) {
1583                 if (!strcmp(res->value, "on"))
1584                         rx_mode.hw_ip_checksum = 1;
1585                 else if (!strcmp(res->value, "off"))
1586                         rx_mode.hw_ip_checksum = 0;
1587                 else {
1588                         printf("Unknown parameter\n");
1589                         return;
1590                 }
1591         } else if (!strcmp(res->name, "hw-vlan")) {
1592                 if (!strcmp(res->value, "on")) {
1593                         rx_mode.hw_vlan_filter = 1;
1594                         rx_mode.hw_vlan_strip  = 1;
1595                 }
1596                 else if (!strcmp(res->value, "off")) {
1597                         rx_mode.hw_vlan_filter = 0;
1598                         rx_mode.hw_vlan_strip  = 0;
1599                 }
1600                 else {
1601                         printf("Unknown parameter\n");
1602                         return;
1603                 }
1604         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1605                 if (!strcmp(res->value, "on"))
1606                         rx_mode.hw_vlan_filter = 1;
1607                 else if (!strcmp(res->value, "off"))
1608                         rx_mode.hw_vlan_filter = 0;
1609                 else {
1610                         printf("Unknown parameter\n");
1611                         return;
1612                 }
1613         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1614                 if (!strcmp(res->value, "on"))
1615                         rx_mode.hw_vlan_strip  = 1;
1616                 else if (!strcmp(res->value, "off"))
1617                         rx_mode.hw_vlan_strip  = 0;
1618                 else {
1619                         printf("Unknown parameter\n");
1620                         return;
1621                 }
1622         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1623                 if (!strcmp(res->value, "on"))
1624                         rx_mode.hw_vlan_extend = 1;
1625                 else if (!strcmp(res->value, "off"))
1626                         rx_mode.hw_vlan_extend = 0;
1627                 else {
1628                         printf("Unknown parameter\n");
1629                         return;
1630                 }
1631         } else if (!strcmp(res->name, "drop-en")) {
1632                 if (!strcmp(res->value, "on"))
1633                         rx_drop_en = 1;
1634                 else if (!strcmp(res->value, "off"))
1635                         rx_drop_en = 0;
1636                 else {
1637                         printf("Unknown parameter\n");
1638                         return;
1639                 }
1640         } else {
1641                 printf("Unknown parameter\n");
1642                 return;
1643         }
1644
1645         init_port_config();
1646
1647         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1648 }
1649
1650 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1652 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1654                                                                 "config");
1655 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1657 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1659                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1660                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1661 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1663                                                         "on#off");
1664
1665 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1666         .f = cmd_config_rx_mode_flag_parsed,
1667         .data = NULL,
1668         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1669                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1670         .tokens = {
1671                 (void *)&cmd_config_rx_mode_flag_port,
1672                 (void *)&cmd_config_rx_mode_flag_keyword,
1673                 (void *)&cmd_config_rx_mode_flag_all,
1674                 (void *)&cmd_config_rx_mode_flag_name,
1675                 (void *)&cmd_config_rx_mode_flag_value,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure rss *** */
1681 struct cmd_config_rss {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         cmdline_fixed_string_t all;
1685         cmdline_fixed_string_t name;
1686         cmdline_fixed_string_t value;
1687 };
1688
1689 static void
1690 cmd_config_rss_parsed(void *parsed_result,
1691                         __attribute__((unused)) struct cmdline *cl,
1692                         __attribute__((unused)) void *data)
1693 {
1694         struct cmd_config_rss *res = parsed_result;
1695         struct rte_eth_rss_conf rss_conf;
1696         int diag;
1697         uint8_t i;
1698
1699         if (!strcmp(res->value, "all"))
1700                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1701                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1702                                         ETH_RSS_L2_PAYLOAD;
1703         else if (!strcmp(res->value, "ip"))
1704                 rss_conf.rss_hf = ETH_RSS_IP;
1705         else if (!strcmp(res->value, "udp"))
1706                 rss_conf.rss_hf = ETH_RSS_UDP;
1707         else if (!strcmp(res->value, "tcp"))
1708                 rss_conf.rss_hf = ETH_RSS_TCP;
1709         else if (!strcmp(res->value, "sctp"))
1710                 rss_conf.rss_hf = ETH_RSS_SCTP;
1711         else if (!strcmp(res->value, "ether"))
1712                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1713         else if (!strcmp(res->value, "port"))
1714                 rss_conf.rss_hf = ETH_RSS_PORT;
1715         else if (!strcmp(res->value, "vxlan"))
1716                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1717         else if (!strcmp(res->value, "geneve"))
1718                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1719         else if (!strcmp(res->value, "nvgre"))
1720                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1721         else if (!strcmp(res->value, "none"))
1722                 rss_conf.rss_hf = 0;
1723         else {
1724                 printf("Unknown parameter\n");
1725                 return;
1726         }
1727         rss_conf.rss_key = NULL;
1728         for (i = 0; i < rte_eth_dev_count(); i++) {
1729                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1730                 if (diag < 0)
1731                         printf("Configuration of RSS hash at ethernet port %d "
1732                                 "failed with error (%d): %s.\n",
1733                                 i, -diag, strerror(-diag));
1734         }
1735 }
1736
1737 cmdline_parse_token_string_t cmd_config_rss_port =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1739 cmdline_parse_token_string_t cmd_config_rss_keyword =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1741 cmdline_parse_token_string_t cmd_config_rss_all =
1742         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1743 cmdline_parse_token_string_t cmd_config_rss_name =
1744         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1745 cmdline_parse_token_string_t cmd_config_rss_value =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1747                 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none");
1748
1749 cmdline_parse_inst_t cmd_config_rss = {
1750         .f = cmd_config_rss_parsed,
1751         .data = NULL,
1752         .help_str = "port config all rss "
1753                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none",
1754         .tokens = {
1755                 (void *)&cmd_config_rss_port,
1756                 (void *)&cmd_config_rss_keyword,
1757                 (void *)&cmd_config_rss_all,
1758                 (void *)&cmd_config_rss_name,
1759                 (void *)&cmd_config_rss_value,
1760                 NULL,
1761         },
1762 };
1763
1764 /* *** configure rss hash key *** */
1765 struct cmd_config_rss_hash_key {
1766         cmdline_fixed_string_t port;
1767         cmdline_fixed_string_t config;
1768         uint8_t port_id;
1769         cmdline_fixed_string_t rss_hash_key;
1770         cmdline_fixed_string_t rss_type;
1771         cmdline_fixed_string_t key;
1772 };
1773
1774 static uint8_t
1775 hexa_digit_to_value(char hexa_digit)
1776 {
1777         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1778                 return (uint8_t) (hexa_digit - '0');
1779         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1780                 return (uint8_t) ((hexa_digit - 'a') + 10);
1781         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1782                 return (uint8_t) ((hexa_digit - 'A') + 10);
1783         /* Invalid hexa digit */
1784         return 0xFF;
1785 }
1786
1787 static uint8_t
1788 parse_and_check_key_hexa_digit(char *key, int idx)
1789 {
1790         uint8_t hexa_v;
1791
1792         hexa_v = hexa_digit_to_value(key[idx]);
1793         if (hexa_v == 0xFF)
1794                 printf("invalid key: character %c at position %d is not a "
1795                        "valid hexa digit\n", key[idx], idx);
1796         return hexa_v;
1797 }
1798
1799 static void
1800 cmd_config_rss_hash_key_parsed(void *parsed_result,
1801                                __attribute__((unused)) struct cmdline *cl,
1802                                __attribute__((unused)) void *data)
1803 {
1804         struct cmd_config_rss_hash_key *res = parsed_result;
1805         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1806         uint8_t xdgt0;
1807         uint8_t xdgt1;
1808         int i;
1809         struct rte_eth_dev_info dev_info;
1810         uint8_t hash_key_size;
1811         uint32_t key_len;
1812
1813         memset(&dev_info, 0, sizeof(dev_info));
1814         rte_eth_dev_info_get(res->port_id, &dev_info);
1815         if (dev_info.hash_key_size > 0 &&
1816                         dev_info.hash_key_size <= sizeof(hash_key))
1817                 hash_key_size = dev_info.hash_key_size;
1818         else {
1819                 printf("dev_info did not provide a valid hash key size\n");
1820                 return;
1821         }
1822         /* Check the length of the RSS hash key */
1823         key_len = strlen(res->key);
1824         if (key_len != (hash_key_size * 2)) {
1825                 printf("key length: %d invalid - key must be a string of %d"
1826                            " hexa-decimal numbers\n",
1827                            (int) key_len, hash_key_size * 2);
1828                 return;
1829         }
1830         /* Translate RSS hash key into binary representation */
1831         for (i = 0; i < hash_key_size; i++) {
1832                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1833                 if (xdgt0 == 0xFF)
1834                         return;
1835                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1836                 if (xdgt1 == 0xFF)
1837                         return;
1838                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1839         }
1840         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1841                         hash_key_size);
1842 }
1843
1844 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1846 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1848                                  "config");
1849 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1850         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1851 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1853                                  rss_hash_key, "rss-hash-key");
1854 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1856                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1857                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1858                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1859                                  "ipv6-tcp-ex#ipv6-udp-ex");
1860 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1862
1863 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1864         .f = cmd_config_rss_hash_key_parsed,
1865         .data = NULL,
1866         .help_str = "port config <port_id> rss-hash-key "
1867                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1868                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1869                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1870                 "<string of hex digits (variable length, NIC dependent)>",
1871         .tokens = {
1872                 (void *)&cmd_config_rss_hash_key_port,
1873                 (void *)&cmd_config_rss_hash_key_config,
1874                 (void *)&cmd_config_rss_hash_key_port_id,
1875                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1876                 (void *)&cmd_config_rss_hash_key_rss_type,
1877                 (void *)&cmd_config_rss_hash_key_value,
1878                 NULL,
1879         },
1880 };
1881
1882 /* *** configure port rxq/txq start/stop *** */
1883 struct cmd_config_rxtx_queue {
1884         cmdline_fixed_string_t port;
1885         uint8_t portid;
1886         cmdline_fixed_string_t rxtxq;
1887         uint16_t qid;
1888         cmdline_fixed_string_t opname;
1889 };
1890
1891 static void
1892 cmd_config_rxtx_queue_parsed(void *parsed_result,
1893                         __attribute__((unused)) struct cmdline *cl,
1894                         __attribute__((unused)) void *data)
1895 {
1896         struct cmd_config_rxtx_queue *res = parsed_result;
1897         uint8_t isrx;
1898         uint8_t isstart;
1899         int ret = 0;
1900
1901         if (test_done == 0) {
1902                 printf("Please stop forwarding first\n");
1903                 return;
1904         }
1905
1906         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1907                 return;
1908
1909         if (port_is_started(res->portid) != 1) {
1910                 printf("Please start port %u first\n", res->portid);
1911                 return;
1912         }
1913
1914         if (!strcmp(res->rxtxq, "rxq"))
1915                 isrx = 1;
1916         else if (!strcmp(res->rxtxq, "txq"))
1917                 isrx = 0;
1918         else {
1919                 printf("Unknown parameter\n");
1920                 return;
1921         }
1922
1923         if (isrx && rx_queue_id_is_invalid(res->qid))
1924                 return;
1925         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1926                 return;
1927
1928         if (!strcmp(res->opname, "start"))
1929                 isstart = 1;
1930         else if (!strcmp(res->opname, "stop"))
1931                 isstart = 0;
1932         else {
1933                 printf("Unknown parameter\n");
1934                 return;
1935         }
1936
1937         if (isstart && isrx)
1938                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1939         else if (!isstart && isrx)
1940                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1941         else if (isstart && !isrx)
1942                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1943         else
1944                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1945
1946         if (ret == -ENOTSUP)
1947                 printf("Function not supported in PMD driver\n");
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1952 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1953         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1954 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1956 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1957         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1958 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1960                                                 "start#stop");
1961
1962 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1963         .f = cmd_config_rxtx_queue_parsed,
1964         .data = NULL,
1965         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1966         .tokens = {
1967                 (void *)&cmd_config_speed_all_port,
1968                 (void *)&cmd_config_rxtx_queue_portid,
1969                 (void *)&cmd_config_rxtx_queue_rxtxq,
1970                 (void *)&cmd_config_rxtx_queue_qid,
1971                 (void *)&cmd_config_rxtx_queue_opname,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** Configure RSS RETA *** */
1977 struct cmd_config_rss_reta {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t keyword;
1980         uint8_t port_id;
1981         cmdline_fixed_string_t name;
1982         cmdline_fixed_string_t list_name;
1983         cmdline_fixed_string_t list_of_items;
1984 };
1985
1986 static int
1987 parse_reta_config(const char *str,
1988                   struct rte_eth_rss_reta_entry64 *reta_conf,
1989                   uint16_t nb_entries)
1990 {
1991         int i;
1992         unsigned size;
1993         uint16_t hash_index, idx, shift;
1994         uint16_t nb_queue;
1995         char s[256];
1996         const char *p, *p0 = str;
1997         char *end;
1998         enum fieldnames {
1999                 FLD_HASH_INDEX = 0,
2000                 FLD_QUEUE,
2001                 _NUM_FLD
2002         };
2003         unsigned long int_fld[_NUM_FLD];
2004         char *str_fld[_NUM_FLD];
2005
2006         while ((p = strchr(p0,'(')) != NULL) {
2007                 ++p;
2008                 if((p0 = strchr(p,')')) == NULL)
2009                         return -1;
2010
2011                 size = p0 - p;
2012                 if(size >= sizeof(s))
2013                         return -1;
2014
2015                 snprintf(s, sizeof(s), "%.*s", size, p);
2016                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2017                         return -1;
2018                 for (i = 0; i < _NUM_FLD; i++) {
2019                         errno = 0;
2020                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2021                         if (errno != 0 || end == str_fld[i] ||
2022                                         int_fld[i] > 65535)
2023                                 return -1;
2024                 }
2025
2026                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2027                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2028
2029                 if (hash_index >= nb_entries) {
2030                         printf("Invalid RETA hash index=%d\n", hash_index);
2031                         return -1;
2032                 }
2033
2034                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2035                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2036                 reta_conf[idx].mask |= (1ULL << shift);
2037                 reta_conf[idx].reta[shift] = nb_queue;
2038         }
2039
2040         return 0;
2041 }
2042
2043 static void
2044 cmd_set_rss_reta_parsed(void *parsed_result,
2045                         __attribute__((unused)) struct cmdline *cl,
2046                         __attribute__((unused)) void *data)
2047 {
2048         int ret;
2049         struct rte_eth_dev_info dev_info;
2050         struct rte_eth_rss_reta_entry64 reta_conf[8];
2051         struct cmd_config_rss_reta *res = parsed_result;
2052
2053         memset(&dev_info, 0, sizeof(dev_info));
2054         rte_eth_dev_info_get(res->port_id, &dev_info);
2055         if (dev_info.reta_size == 0) {
2056                 printf("Redirection table size is 0 which is "
2057                                         "invalid for RSS\n");
2058                 return;
2059         } else
2060                 printf("The reta size of port %d is %u\n",
2061                         res->port_id, dev_info.reta_size);
2062         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2063                 printf("Currently do not support more than %u entries of "
2064                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2065                 return;
2066         }
2067
2068         memset(reta_conf, 0, sizeof(reta_conf));
2069         if (!strcmp(res->list_name, "reta")) {
2070                 if (parse_reta_config(res->list_of_items, reta_conf,
2071                                                 dev_info.reta_size)) {
2072                         printf("Invalid RSS Redirection Table "
2073                                         "config entered\n");
2074                         return;
2075                 }
2076                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2077                                 reta_conf, dev_info.reta_size);
2078                 if (ret != 0)
2079                         printf("Bad redirection table parameter, "
2080                                         "return code = %d \n", ret);
2081         }
2082 }
2083
2084 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2086 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2088 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2089         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2090 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2091         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2092 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2094 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2095         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2096                                  NULL);
2097 cmdline_parse_inst_t cmd_config_rss_reta = {
2098         .f = cmd_set_rss_reta_parsed,
2099         .data = NULL,
2100         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2101         .tokens = {
2102                 (void *)&cmd_config_rss_reta_port,
2103                 (void *)&cmd_config_rss_reta_keyword,
2104                 (void *)&cmd_config_rss_reta_port_id,
2105                 (void *)&cmd_config_rss_reta_name,
2106                 (void *)&cmd_config_rss_reta_list_name,
2107                 (void *)&cmd_config_rss_reta_list_of_items,
2108                 NULL,
2109         },
2110 };
2111
2112 /* *** SHOW PORT RETA INFO *** */
2113 struct cmd_showport_reta {
2114         cmdline_fixed_string_t show;
2115         cmdline_fixed_string_t port;
2116         uint8_t port_id;
2117         cmdline_fixed_string_t rss;
2118         cmdline_fixed_string_t reta;
2119         uint16_t size;
2120         cmdline_fixed_string_t list_of_items;
2121 };
2122
2123 static int
2124 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2125                            uint16_t nb_entries,
2126                            char *str)
2127 {
2128         uint32_t size;
2129         const char *p, *p0 = str;
2130         char s[256];
2131         char *end;
2132         char *str_fld[8];
2133         uint16_t i;
2134         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2135                         RTE_RETA_GROUP_SIZE;
2136         int ret;
2137
2138         p = strchr(p0, '(');
2139         if (p == NULL)
2140                 return -1;
2141         p++;
2142         p0 = strchr(p, ')');
2143         if (p0 == NULL)
2144                 return -1;
2145         size = p0 - p;
2146         if (size >= sizeof(s)) {
2147                 printf("The string size exceeds the internal buffer size\n");
2148                 return -1;
2149         }
2150         snprintf(s, sizeof(s), "%.*s", size, p);
2151         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2152         if (ret <= 0 || ret != num) {
2153                 printf("The bits of masks do not match the number of "
2154                                         "reta entries: %u\n", num);
2155                 return -1;
2156         }
2157         for (i = 0; i < ret; i++)
2158                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2159
2160         return 0;
2161 }
2162
2163 static void
2164 cmd_showport_reta_parsed(void *parsed_result,
2165                          __attribute__((unused)) struct cmdline *cl,
2166                          __attribute__((unused)) void *data)
2167 {
2168         struct cmd_showport_reta *res = parsed_result;
2169         struct rte_eth_rss_reta_entry64 reta_conf[8];
2170         struct rte_eth_dev_info dev_info;
2171
2172         memset(&dev_info, 0, sizeof(dev_info));
2173         rte_eth_dev_info_get(res->port_id, &dev_info);
2174         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2175                                 res->size > ETH_RSS_RETA_SIZE_512) {
2176                 printf("Invalid redirection table size: %u\n", res->size);
2177                 return;
2178         }
2179
2180         memset(reta_conf, 0, sizeof(reta_conf));
2181         if (showport_parse_reta_config(reta_conf, res->size,
2182                                 res->list_of_items) < 0) {
2183                 printf("Invalid string: %s for reta masks\n",
2184                                         res->list_of_items);
2185                 return;
2186         }
2187         port_rss_reta_info(res->port_id, reta_conf, res->size);
2188 }
2189
2190 cmdline_parse_token_string_t cmd_showport_reta_show =
2191         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2192 cmdline_parse_token_string_t cmd_showport_reta_port =
2193         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2194 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2195         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2196 cmdline_parse_token_string_t cmd_showport_reta_rss =
2197         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2198 cmdline_parse_token_string_t cmd_showport_reta_reta =
2199         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2200 cmdline_parse_token_num_t cmd_showport_reta_size =
2201         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2202 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2203         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2204                                         list_of_items, NULL);
2205
2206 cmdline_parse_inst_t cmd_showport_reta = {
2207         .f = cmd_showport_reta_parsed,
2208         .data = NULL,
2209         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2210         .tokens = {
2211                 (void *)&cmd_showport_reta_show,
2212                 (void *)&cmd_showport_reta_port,
2213                 (void *)&cmd_showport_reta_port_id,
2214                 (void *)&cmd_showport_reta_rss,
2215                 (void *)&cmd_showport_reta_reta,
2216                 (void *)&cmd_showport_reta_size,
2217                 (void *)&cmd_showport_reta_list_of_items,
2218                 NULL,
2219         },
2220 };
2221
2222 /* *** Show RSS hash configuration *** */
2223 struct cmd_showport_rss_hash {
2224         cmdline_fixed_string_t show;
2225         cmdline_fixed_string_t port;
2226         uint8_t port_id;
2227         cmdline_fixed_string_t rss_hash;
2228         cmdline_fixed_string_t rss_type;
2229         cmdline_fixed_string_t key; /* optional argument */
2230 };
2231
2232 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2233                                 __attribute__((unused)) struct cmdline *cl,
2234                                 void *show_rss_key)
2235 {
2236         struct cmd_showport_rss_hash *res = parsed_result;
2237
2238         port_rss_hash_conf_show(res->port_id, res->rss_type,
2239                                 show_rss_key != NULL);
2240 }
2241
2242 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2243         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2244 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2245         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2246 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2247         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2248 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2249         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2250                                  "rss-hash");
2251 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2252         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2253                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2254                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2255                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2256                                  "ipv6-tcp-ex#ipv6-udp-ex");
2257 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2258         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2259
2260 cmdline_parse_inst_t cmd_showport_rss_hash = {
2261         .f = cmd_showport_rss_hash_parsed,
2262         .data = NULL,
2263         .help_str = "show port <port_id> rss-hash "
2264                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2265                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2266                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2267         .tokens = {
2268                 (void *)&cmd_showport_rss_hash_show,
2269                 (void *)&cmd_showport_rss_hash_port,
2270                 (void *)&cmd_showport_rss_hash_port_id,
2271                 (void *)&cmd_showport_rss_hash_rss_hash,
2272                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2273                 NULL,
2274         },
2275 };
2276
2277 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2278         .f = cmd_showport_rss_hash_parsed,
2279         .data = (void *)1,
2280         .help_str = "show port <port_id> rss-hash "
2281                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2282                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2283                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2284         .tokens = {
2285                 (void *)&cmd_showport_rss_hash_show,
2286                 (void *)&cmd_showport_rss_hash_port,
2287                 (void *)&cmd_showport_rss_hash_port_id,
2288                 (void *)&cmd_showport_rss_hash_rss_hash,
2289                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2290                 (void *)&cmd_showport_rss_hash_rss_key,
2291                 NULL,
2292         },
2293 };
2294
2295 /* *** Configure DCB *** */
2296 struct cmd_config_dcb {
2297         cmdline_fixed_string_t port;
2298         cmdline_fixed_string_t config;
2299         uint8_t port_id;
2300         cmdline_fixed_string_t dcb;
2301         cmdline_fixed_string_t vt;
2302         cmdline_fixed_string_t vt_en;
2303         uint8_t num_tcs;
2304         cmdline_fixed_string_t pfc;
2305         cmdline_fixed_string_t pfc_en;
2306 };
2307
2308 static void
2309 cmd_config_dcb_parsed(void *parsed_result,
2310                         __attribute__((unused)) struct cmdline *cl,
2311                         __attribute__((unused)) void *data)
2312 {
2313         struct cmd_config_dcb *res = parsed_result;
2314         portid_t port_id = res->port_id;
2315         struct rte_port *port;
2316         uint8_t pfc_en;
2317         int ret;
2318
2319         port = &ports[port_id];
2320         /** Check if the port is not started **/
2321         if (port->port_status != RTE_PORT_STOPPED) {
2322                 printf("Please stop port %d first\n", port_id);
2323                 return;
2324         }
2325
2326         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2327                 printf("The invalid number of traffic class,"
2328                         " only 4 or 8 allowed.\n");
2329                 return;
2330         }
2331
2332         if (nb_fwd_lcores < res->num_tcs) {
2333                 printf("nb_cores shouldn't be less than number of TCs.\n");
2334                 return;
2335         }
2336         if (!strncmp(res->pfc_en, "on", 2))
2337                 pfc_en = 1;
2338         else
2339                 pfc_en = 0;
2340
2341         /* DCB in VT mode */
2342         if (!strncmp(res->vt_en, "on", 2))
2343                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2344                                 (enum rte_eth_nb_tcs)res->num_tcs,
2345                                 pfc_en);
2346         else
2347                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2348                                 (enum rte_eth_nb_tcs)res->num_tcs,
2349                                 pfc_en);
2350
2351
2352         if (ret != 0) {
2353                 printf("Cannot initialize network ports.\n");
2354                 return;
2355         }
2356
2357         cmd_reconfig_device_queue(port_id, 1, 1);
2358 }
2359
2360 cmdline_parse_token_string_t cmd_config_dcb_port =
2361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2362 cmdline_parse_token_string_t cmd_config_dcb_config =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2364 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2365         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2366 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2368 cmdline_parse_token_string_t cmd_config_dcb_vt =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2370 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2372 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2373         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2374 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2376 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2378
2379 cmdline_parse_inst_t cmd_config_dcb = {
2380         .f = cmd_config_dcb_parsed,
2381         .data = NULL,
2382         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2383         .tokens = {
2384                 (void *)&cmd_config_dcb_port,
2385                 (void *)&cmd_config_dcb_config,
2386                 (void *)&cmd_config_dcb_port_id,
2387                 (void *)&cmd_config_dcb_dcb,
2388                 (void *)&cmd_config_dcb_vt,
2389                 (void *)&cmd_config_dcb_vt_en,
2390                 (void *)&cmd_config_dcb_num_tcs,
2391                 (void *)&cmd_config_dcb_pfc,
2392                 (void *)&cmd_config_dcb_pfc_en,
2393                 NULL,
2394         },
2395 };
2396
2397 /* *** configure number of packets per burst *** */
2398 struct cmd_config_burst {
2399         cmdline_fixed_string_t port;
2400         cmdline_fixed_string_t keyword;
2401         cmdline_fixed_string_t all;
2402         cmdline_fixed_string_t name;
2403         uint16_t value;
2404 };
2405
2406 static void
2407 cmd_config_burst_parsed(void *parsed_result,
2408                         __attribute__((unused)) struct cmdline *cl,
2409                         __attribute__((unused)) void *data)
2410 {
2411         struct cmd_config_burst *res = parsed_result;
2412
2413         if (!all_ports_stopped()) {
2414                 printf("Please stop all ports first\n");
2415                 return;
2416         }
2417
2418         if (!strcmp(res->name, "burst")) {
2419                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2420                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2421                         return;
2422                 }
2423                 nb_pkt_per_burst = res->value;
2424         } else {
2425                 printf("Unknown parameter\n");
2426                 return;
2427         }
2428
2429         init_port_config();
2430
2431         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2432 }
2433
2434 cmdline_parse_token_string_t cmd_config_burst_port =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2436 cmdline_parse_token_string_t cmd_config_burst_keyword =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2438 cmdline_parse_token_string_t cmd_config_burst_all =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2440 cmdline_parse_token_string_t cmd_config_burst_name =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2442 cmdline_parse_token_num_t cmd_config_burst_value =
2443         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2444
2445 cmdline_parse_inst_t cmd_config_burst = {
2446         .f = cmd_config_burst_parsed,
2447         .data = NULL,
2448         .help_str = "port config all burst <value>",
2449         .tokens = {
2450                 (void *)&cmd_config_burst_port,
2451                 (void *)&cmd_config_burst_keyword,
2452                 (void *)&cmd_config_burst_all,
2453                 (void *)&cmd_config_burst_name,
2454                 (void *)&cmd_config_burst_value,
2455                 NULL,
2456         },
2457 };
2458
2459 /* *** configure rx/tx queues *** */
2460 struct cmd_config_thresh {
2461         cmdline_fixed_string_t port;
2462         cmdline_fixed_string_t keyword;
2463         cmdline_fixed_string_t all;
2464         cmdline_fixed_string_t name;
2465         uint8_t value;
2466 };
2467
2468 static void
2469 cmd_config_thresh_parsed(void *parsed_result,
2470                         __attribute__((unused)) struct cmdline *cl,
2471                         __attribute__((unused)) void *data)
2472 {
2473         struct cmd_config_thresh *res = parsed_result;
2474
2475         if (!all_ports_stopped()) {
2476                 printf("Please stop all ports first\n");
2477                 return;
2478         }
2479
2480         if (!strcmp(res->name, "txpt"))
2481                 tx_pthresh = res->value;
2482         else if(!strcmp(res->name, "txht"))
2483                 tx_hthresh = res->value;
2484         else if(!strcmp(res->name, "txwt"))
2485                 tx_wthresh = res->value;
2486         else if(!strcmp(res->name, "rxpt"))
2487                 rx_pthresh = res->value;
2488         else if(!strcmp(res->name, "rxht"))
2489                 rx_hthresh = res->value;
2490         else if(!strcmp(res->name, "rxwt"))
2491                 rx_wthresh = res->value;
2492         else {
2493                 printf("Unknown parameter\n");
2494                 return;
2495         }
2496
2497         init_port_config();
2498
2499         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2500 }
2501
2502 cmdline_parse_token_string_t cmd_config_thresh_port =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2504 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2505         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2506 cmdline_parse_token_string_t cmd_config_thresh_all =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2508 cmdline_parse_token_string_t cmd_config_thresh_name =
2509         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2510                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2511 cmdline_parse_token_num_t cmd_config_thresh_value =
2512         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2513
2514 cmdline_parse_inst_t cmd_config_thresh = {
2515         .f = cmd_config_thresh_parsed,
2516         .data = NULL,
2517         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2518         .tokens = {
2519                 (void *)&cmd_config_thresh_port,
2520                 (void *)&cmd_config_thresh_keyword,
2521                 (void *)&cmd_config_thresh_all,
2522                 (void *)&cmd_config_thresh_name,
2523                 (void *)&cmd_config_thresh_value,
2524                 NULL,
2525         },
2526 };
2527
2528 /* *** configure free/rs threshold *** */
2529 struct cmd_config_threshold {
2530         cmdline_fixed_string_t port;
2531         cmdline_fixed_string_t keyword;
2532         cmdline_fixed_string_t all;
2533         cmdline_fixed_string_t name;
2534         uint16_t value;
2535 };
2536
2537 static void
2538 cmd_config_threshold_parsed(void *parsed_result,
2539                         __attribute__((unused)) struct cmdline *cl,
2540                         __attribute__((unused)) void *data)
2541 {
2542         struct cmd_config_threshold *res = parsed_result;
2543
2544         if (!all_ports_stopped()) {
2545                 printf("Please stop all ports first\n");
2546                 return;
2547         }
2548
2549         if (!strcmp(res->name, "txfreet"))
2550                 tx_free_thresh = res->value;
2551         else if (!strcmp(res->name, "txrst"))
2552                 tx_rs_thresh = res->value;
2553         else if (!strcmp(res->name, "rxfreet"))
2554                 rx_free_thresh = res->value;
2555         else {
2556                 printf("Unknown parameter\n");
2557                 return;
2558         }
2559
2560         init_port_config();
2561
2562         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2563 }
2564
2565 cmdline_parse_token_string_t cmd_config_threshold_port =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2567 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2568         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2569                                                                 "config");
2570 cmdline_parse_token_string_t cmd_config_threshold_all =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2572 cmdline_parse_token_string_t cmd_config_threshold_name =
2573         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2574                                                 "txfreet#txrst#rxfreet");
2575 cmdline_parse_token_num_t cmd_config_threshold_value =
2576         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2577
2578 cmdline_parse_inst_t cmd_config_threshold = {
2579         .f = cmd_config_threshold_parsed,
2580         .data = NULL,
2581         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2582         .tokens = {
2583                 (void *)&cmd_config_threshold_port,
2584                 (void *)&cmd_config_threshold_keyword,
2585                 (void *)&cmd_config_threshold_all,
2586                 (void *)&cmd_config_threshold_name,
2587                 (void *)&cmd_config_threshold_value,
2588                 NULL,
2589         },
2590 };
2591
2592 /* *** stop *** */
2593 struct cmd_stop_result {
2594         cmdline_fixed_string_t stop;
2595 };
2596
2597 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2598                             __attribute__((unused)) struct cmdline *cl,
2599                             __attribute__((unused)) void *data)
2600 {
2601         stop_packet_forwarding();
2602 }
2603
2604 cmdline_parse_token_string_t cmd_stop_stop =
2605         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2606
2607 cmdline_parse_inst_t cmd_stop = {
2608         .f = cmd_stop_parsed,
2609         .data = NULL,
2610         .help_str = "stop: Stop packet forwarding",
2611         .tokens = {
2612                 (void *)&cmd_stop_stop,
2613                 NULL,
2614         },
2615 };
2616
2617 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2618
2619 unsigned int
2620 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2621                 unsigned int *parsed_items, int check_unique_values)
2622 {
2623         unsigned int nb_item;
2624         unsigned int value;
2625         unsigned int i;
2626         unsigned int j;
2627         int value_ok;
2628         char c;
2629
2630         /*
2631          * First parse all items in the list and store their value.
2632          */
2633         value = 0;
2634         nb_item = 0;
2635         value_ok = 0;
2636         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2637                 c = str[i];
2638                 if ((c >= '0') && (c <= '9')) {
2639                         value = (unsigned int) (value * 10 + (c - '0'));
2640                         value_ok = 1;
2641                         continue;
2642                 }
2643                 if (c != ',') {
2644                         printf("character %c is not a decimal digit\n", c);
2645                         return 0;
2646                 }
2647                 if (! value_ok) {
2648                         printf("No valid value before comma\n");
2649                         return 0;
2650                 }
2651                 if (nb_item < max_items) {
2652                         parsed_items[nb_item] = value;
2653                         value_ok = 0;
2654                         value = 0;
2655                 }
2656                 nb_item++;
2657         }
2658         if (nb_item >= max_items) {
2659                 printf("Number of %s = %u > %u (maximum items)\n",
2660                        item_name, nb_item + 1, max_items);
2661                 return 0;
2662         }
2663         parsed_items[nb_item++] = value;
2664         if (! check_unique_values)
2665                 return nb_item;
2666
2667         /*
2668          * Then, check that all values in the list are differents.
2669          * No optimization here...
2670          */
2671         for (i = 0; i < nb_item; i++) {
2672                 for (j = i + 1; j < nb_item; j++) {
2673                         if (parsed_items[j] == parsed_items[i]) {
2674                                 printf("duplicated %s %u at index %u and %u\n",
2675                                        item_name, parsed_items[i], i, j);
2676                                 return 0;
2677                         }
2678                 }
2679         }
2680         return nb_item;
2681 }
2682
2683 struct cmd_set_list_result {
2684         cmdline_fixed_string_t cmd_keyword;
2685         cmdline_fixed_string_t list_name;
2686         cmdline_fixed_string_t list_of_items;
2687 };
2688
2689 static void cmd_set_list_parsed(void *parsed_result,
2690                                 __attribute__((unused)) struct cmdline *cl,
2691                                 __attribute__((unused)) void *data)
2692 {
2693         struct cmd_set_list_result *res;
2694         union {
2695                 unsigned int lcorelist[RTE_MAX_LCORE];
2696                 unsigned int portlist[RTE_MAX_ETHPORTS];
2697         } parsed_items;
2698         unsigned int nb_item;
2699
2700         if (test_done == 0) {
2701                 printf("Please stop forwarding first\n");
2702                 return;
2703         }
2704
2705         res = parsed_result;
2706         if (!strcmp(res->list_name, "corelist")) {
2707                 nb_item = parse_item_list(res->list_of_items, "core",
2708                                           RTE_MAX_LCORE,
2709                                           parsed_items.lcorelist, 1);
2710                 if (nb_item > 0) {
2711                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2712                         fwd_config_setup();
2713                 }
2714                 return;
2715         }
2716         if (!strcmp(res->list_name, "portlist")) {
2717                 nb_item = parse_item_list(res->list_of_items, "port",
2718                                           RTE_MAX_ETHPORTS,
2719                                           parsed_items.portlist, 1);
2720                 if (nb_item > 0) {
2721                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2722                         fwd_config_setup();
2723                 }
2724         }
2725 }
2726
2727 cmdline_parse_token_string_t cmd_set_list_keyword =
2728         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2729                                  "set");
2730 cmdline_parse_token_string_t cmd_set_list_name =
2731         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2732                                  "corelist#portlist");
2733 cmdline_parse_token_string_t cmd_set_list_of_items =
2734         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2735                                  NULL);
2736
2737 cmdline_parse_inst_t cmd_set_fwd_list = {
2738         .f = cmd_set_list_parsed,
2739         .data = NULL,
2740         .help_str = "set corelist|portlist <list0[,list1]*>",
2741         .tokens = {
2742                 (void *)&cmd_set_list_keyword,
2743                 (void *)&cmd_set_list_name,
2744                 (void *)&cmd_set_list_of_items,
2745                 NULL,
2746         },
2747 };
2748
2749 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2750
2751 struct cmd_setmask_result {
2752         cmdline_fixed_string_t set;
2753         cmdline_fixed_string_t mask;
2754         uint64_t hexavalue;
2755 };
2756
2757 static void cmd_set_mask_parsed(void *parsed_result,
2758                                 __attribute__((unused)) struct cmdline *cl,
2759                                 __attribute__((unused)) void *data)
2760 {
2761         struct cmd_setmask_result *res = parsed_result;
2762
2763         if (test_done == 0) {
2764                 printf("Please stop forwarding first\n");
2765                 return;
2766         }
2767         if (!strcmp(res->mask, "coremask")) {
2768                 set_fwd_lcores_mask(res->hexavalue);
2769                 fwd_config_setup();
2770         } else if (!strcmp(res->mask, "portmask")) {
2771                 set_fwd_ports_mask(res->hexavalue);
2772                 fwd_config_setup();
2773         }
2774 }
2775
2776 cmdline_parse_token_string_t cmd_setmask_set =
2777         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2778 cmdline_parse_token_string_t cmd_setmask_mask =
2779         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2780                                  "coremask#portmask");
2781 cmdline_parse_token_num_t cmd_setmask_value =
2782         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2783
2784 cmdline_parse_inst_t cmd_set_fwd_mask = {
2785         .f = cmd_set_mask_parsed,
2786         .data = NULL,
2787         .help_str = "set coremask|portmask <hexadecimal value>",
2788         .tokens = {
2789                 (void *)&cmd_setmask_set,
2790                 (void *)&cmd_setmask_mask,
2791                 (void *)&cmd_setmask_value,
2792                 NULL,
2793         },
2794 };
2795
2796 /*
2797  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2798  */
2799 struct cmd_set_result {
2800         cmdline_fixed_string_t set;
2801         cmdline_fixed_string_t what;
2802         uint16_t value;
2803 };
2804
2805 static void cmd_set_parsed(void *parsed_result,
2806                            __attribute__((unused)) struct cmdline *cl,
2807                            __attribute__((unused)) void *data)
2808 {
2809         struct cmd_set_result *res = parsed_result;
2810         if (!strcmp(res->what, "nbport")) {
2811                 set_fwd_ports_number(res->value);
2812                 fwd_config_setup();
2813         } else if (!strcmp(res->what, "nbcore")) {
2814                 set_fwd_lcores_number(res->value);
2815                 fwd_config_setup();
2816         } else if (!strcmp(res->what, "burst"))
2817                 set_nb_pkt_per_burst(res->value);
2818         else if (!strcmp(res->what, "verbose"))
2819                 set_verbose_level(res->value);
2820 }
2821
2822 cmdline_parse_token_string_t cmd_set_set =
2823         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2824 cmdline_parse_token_string_t cmd_set_what =
2825         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2826                                  "nbport#nbcore#burst#verbose");
2827 cmdline_parse_token_num_t cmd_set_value =
2828         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2829
2830 cmdline_parse_inst_t cmd_set_numbers = {
2831         .f = cmd_set_parsed,
2832         .data = NULL,
2833         .help_str = "set nbport|nbcore|burst|verbose <value>",
2834         .tokens = {
2835                 (void *)&cmd_set_set,
2836                 (void *)&cmd_set_what,
2837                 (void *)&cmd_set_value,
2838                 NULL,
2839         },
2840 };
2841
2842 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2843
2844 struct cmd_set_txpkts_result {
2845         cmdline_fixed_string_t cmd_keyword;
2846         cmdline_fixed_string_t txpkts;
2847         cmdline_fixed_string_t seg_lengths;
2848 };
2849
2850 static void
2851 cmd_set_txpkts_parsed(void *parsed_result,
2852                       __attribute__((unused)) struct cmdline *cl,
2853                       __attribute__((unused)) void *data)
2854 {
2855         struct cmd_set_txpkts_result *res;
2856         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2857         unsigned int nb_segs;
2858
2859         res = parsed_result;
2860         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2861                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2862         if (nb_segs > 0)
2863                 set_tx_pkt_segments(seg_lengths, nb_segs);
2864 }
2865
2866 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2867         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2868                                  cmd_keyword, "set");
2869 cmdline_parse_token_string_t cmd_set_txpkts_name =
2870         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2871                                  txpkts, "txpkts");
2872 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2873         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2874                                  seg_lengths, NULL);
2875
2876 cmdline_parse_inst_t cmd_set_txpkts = {
2877         .f = cmd_set_txpkts_parsed,
2878         .data = NULL,
2879         .help_str = "set txpkts <len0[,len1]*>",
2880         .tokens = {
2881                 (void *)&cmd_set_txpkts_keyword,
2882                 (void *)&cmd_set_txpkts_name,
2883                 (void *)&cmd_set_txpkts_lengths,
2884                 NULL,
2885         },
2886 };
2887
2888 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2889
2890 struct cmd_set_txsplit_result {
2891         cmdline_fixed_string_t cmd_keyword;
2892         cmdline_fixed_string_t txsplit;
2893         cmdline_fixed_string_t mode;
2894 };
2895
2896 static void
2897 cmd_set_txsplit_parsed(void *parsed_result,
2898                       __attribute__((unused)) struct cmdline *cl,
2899                       __attribute__((unused)) void *data)
2900 {
2901         struct cmd_set_txsplit_result *res;
2902
2903         res = parsed_result;
2904         set_tx_pkt_split(res->mode);
2905 }
2906
2907 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2908         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2909                                  cmd_keyword, "set");
2910 cmdline_parse_token_string_t cmd_set_txsplit_name =
2911         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2912                                  txsplit, "txsplit");
2913 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2914         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2915                                  mode, NULL);
2916
2917 cmdline_parse_inst_t cmd_set_txsplit = {
2918         .f = cmd_set_txsplit_parsed,
2919         .data = NULL,
2920         .help_str = "set txsplit on|off|rand",
2921         .tokens = {
2922                 (void *)&cmd_set_txsplit_keyword,
2923                 (void *)&cmd_set_txsplit_name,
2924                 (void *)&cmd_set_txsplit_mode,
2925                 NULL,
2926         },
2927 };
2928
2929 /* *** CONFIG TX QUEUE FLAGS *** */
2930
2931 struct cmd_config_txqflags_result {
2932         cmdline_fixed_string_t port;
2933         cmdline_fixed_string_t config;
2934         cmdline_fixed_string_t all;
2935         cmdline_fixed_string_t what;
2936         int32_t hexvalue;
2937 };
2938
2939 static void cmd_config_txqflags_parsed(void *parsed_result,
2940                                 __attribute__((unused)) struct cmdline *cl,
2941                                 __attribute__((unused)) void *data)
2942 {
2943         struct cmd_config_txqflags_result *res = parsed_result;
2944
2945         if (!all_ports_stopped()) {
2946                 printf("Please stop all ports first\n");
2947                 return;
2948         }
2949
2950         if (strcmp(res->what, "txqflags")) {
2951                 printf("Unknown parameter\n");
2952                 return;
2953         }
2954
2955         if (res->hexvalue >= 0) {
2956                 txq_flags = res->hexvalue;
2957         } else {
2958                 printf("txqflags must be >= 0\n");
2959                 return;
2960         }
2961
2962         init_port_config();
2963
2964         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2965 }
2966
2967 cmdline_parse_token_string_t cmd_config_txqflags_port =
2968         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2969                                  "port");
2970 cmdline_parse_token_string_t cmd_config_txqflags_config =
2971         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2972                                  "config");
2973 cmdline_parse_token_string_t cmd_config_txqflags_all =
2974         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2975                                  "all");
2976 cmdline_parse_token_string_t cmd_config_txqflags_what =
2977         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2978                                  "txqflags");
2979 cmdline_parse_token_num_t cmd_config_txqflags_value =
2980         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2981                                 hexvalue, INT32);
2982
2983 cmdline_parse_inst_t cmd_config_txqflags = {
2984         .f = cmd_config_txqflags_parsed,
2985         .data = NULL,
2986         .help_str = "port config all txqflags <value>",
2987         .tokens = {
2988                 (void *)&cmd_config_txqflags_port,
2989                 (void *)&cmd_config_txqflags_config,
2990                 (void *)&cmd_config_txqflags_all,
2991                 (void *)&cmd_config_txqflags_what,
2992                 (void *)&cmd_config_txqflags_value,
2993                 NULL,
2994         },
2995 };
2996
2997 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2998 struct cmd_rx_vlan_filter_all_result {
2999         cmdline_fixed_string_t rx_vlan;
3000         cmdline_fixed_string_t what;
3001         cmdline_fixed_string_t all;
3002         uint8_t port_id;
3003 };
3004
3005 static void
3006 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3007                               __attribute__((unused)) struct cmdline *cl,
3008                               __attribute__((unused)) void *data)
3009 {
3010         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3011
3012         if (!strcmp(res->what, "add"))
3013                 rx_vlan_all_filter_set(res->port_id, 1);
3014         else
3015                 rx_vlan_all_filter_set(res->port_id, 0);
3016 }
3017
3018 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3019         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3020                                  rx_vlan, "rx_vlan");
3021 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3022         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3023                                  what, "add#rm");
3024 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3025         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3026                                  all, "all");
3027 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3028         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3029                               port_id, UINT8);
3030
3031 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3032         .f = cmd_rx_vlan_filter_all_parsed,
3033         .data = NULL,
3034         .help_str = "rx_vlan add|rm all <port_id>: "
3035                 "Add/Remove all identifiers to/from the set of VLAN "
3036                 "identifiers filtered by a port",
3037         .tokens = {
3038                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3039                 (void *)&cmd_rx_vlan_filter_all_what,
3040                 (void *)&cmd_rx_vlan_filter_all_all,
3041                 (void *)&cmd_rx_vlan_filter_all_portid,
3042                 NULL,
3043         },
3044 };
3045
3046 /* *** VLAN OFFLOAD SET ON A PORT *** */
3047 struct cmd_vlan_offload_result {
3048         cmdline_fixed_string_t vlan;
3049         cmdline_fixed_string_t set;
3050         cmdline_fixed_string_t vlan_type;
3051         cmdline_fixed_string_t what;
3052         cmdline_fixed_string_t on;
3053         cmdline_fixed_string_t port_id;
3054 };
3055
3056 static void
3057 cmd_vlan_offload_parsed(void *parsed_result,
3058                           __attribute__((unused)) struct cmdline *cl,
3059                           __attribute__((unused)) void *data)
3060 {
3061         int on;
3062         struct cmd_vlan_offload_result *res = parsed_result;
3063         char *str;
3064         int i, len = 0;
3065         portid_t port_id = 0;
3066         unsigned int tmp;
3067
3068         str = res->port_id;
3069         len = strnlen(str, STR_TOKEN_SIZE);
3070         i = 0;
3071         /* Get port_id first */
3072         while(i < len){
3073                 if(str[i] == ',')
3074                         break;
3075
3076                 i++;
3077         }
3078         str[i]='\0';
3079         tmp = strtoul(str, NULL, 0);
3080         /* If port_id greater that what portid_t can represent, return */
3081         if(tmp >= RTE_MAX_ETHPORTS)
3082                 return;
3083         port_id = (portid_t)tmp;
3084
3085         if (!strcmp(res->on, "on"))
3086                 on = 1;
3087         else
3088                 on = 0;
3089
3090         if (!strcmp(res->what, "strip"))
3091                 rx_vlan_strip_set(port_id,  on);
3092         else if(!strcmp(res->what, "stripq")){
3093                 uint16_t queue_id = 0;
3094
3095                 /* No queue_id, return */
3096                 if(i + 1 >= len) {
3097                         printf("must specify (port,queue_id)\n");
3098                         return;
3099                 }
3100                 tmp = strtoul(str + i + 1, NULL, 0);
3101                 /* If queue_id greater that what 16-bits can represent, return */
3102                 if(tmp > 0xffff)
3103                         return;
3104
3105                 queue_id = (uint16_t)tmp;
3106                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3107         }
3108         else if (!strcmp(res->what, "filter"))
3109                 rx_vlan_filter_set(port_id, on);
3110         else
3111                 vlan_extend_set(port_id, on);
3112
3113         return;
3114 }
3115
3116 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3117         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3118                                  vlan, "vlan");
3119 cmdline_parse_token_string_t cmd_vlan_offload_set =
3120         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3121                                  set, "set");
3122 cmdline_parse_token_string_t cmd_vlan_offload_what =
3123         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3124                                  what, "strip#filter#qinq#stripq");
3125 cmdline_parse_token_string_t cmd_vlan_offload_on =
3126         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3127                               on, "on#off");
3128 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3129         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3130                               port_id, NULL);
3131
3132 cmdline_parse_inst_t cmd_vlan_offload = {
3133         .f = cmd_vlan_offload_parsed,
3134         .data = NULL,
3135         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3136                 "<port_id[,queue_id]>: "
3137                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3138         .tokens = {
3139                 (void *)&cmd_vlan_offload_vlan,
3140                 (void *)&cmd_vlan_offload_set,
3141                 (void *)&cmd_vlan_offload_what,
3142                 (void *)&cmd_vlan_offload_on,
3143                 (void *)&cmd_vlan_offload_portid,
3144                 NULL,
3145         },
3146 };
3147
3148 /* *** VLAN TPID SET ON A PORT *** */
3149 struct cmd_vlan_tpid_result {
3150         cmdline_fixed_string_t vlan;
3151         cmdline_fixed_string_t set;
3152         cmdline_fixed_string_t vlan_type;
3153         cmdline_fixed_string_t what;
3154         uint16_t tp_id;
3155         uint8_t port_id;
3156 };
3157
3158 static void
3159 cmd_vlan_tpid_parsed(void *parsed_result,
3160                           __attribute__((unused)) struct cmdline *cl,
3161                           __attribute__((unused)) void *data)
3162 {
3163         struct cmd_vlan_tpid_result *res = parsed_result;
3164         enum rte_vlan_type vlan_type;
3165
3166         if (!strcmp(res->vlan_type, "inner"))
3167                 vlan_type = ETH_VLAN_TYPE_INNER;
3168         else if (!strcmp(res->vlan_type, "outer"))
3169                 vlan_type = ETH_VLAN_TYPE_OUTER;
3170         else {
3171                 printf("Unknown vlan type\n");
3172                 return;
3173         }
3174         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3175 }
3176
3177 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3178         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3179                                  vlan, "vlan");
3180 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3181         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3182                                  set, "set");
3183 cmdline_parse_token_string_t cmd_vlan_type =
3184         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3185                                  vlan_type, "inner#outer");
3186 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3187         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3188                                  what, "tpid");
3189 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3190         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3191                               tp_id, UINT16);
3192 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3193         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3194                               port_id, UINT8);
3195
3196 cmdline_parse_inst_t cmd_vlan_tpid = {
3197         .f = cmd_vlan_tpid_parsed,
3198         .data = NULL,
3199         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3200                 "Set the VLAN Ether type",
3201         .tokens = {
3202                 (void *)&cmd_vlan_tpid_vlan,
3203                 (void *)&cmd_vlan_tpid_set,
3204                 (void *)&cmd_vlan_type,
3205                 (void *)&cmd_vlan_tpid_what,
3206                 (void *)&cmd_vlan_tpid_tpid,
3207                 (void *)&cmd_vlan_tpid_portid,
3208                 NULL,
3209         },
3210 };
3211
3212 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3213 struct cmd_rx_vlan_filter_result {
3214         cmdline_fixed_string_t rx_vlan;
3215         cmdline_fixed_string_t what;
3216         uint16_t vlan_id;
3217         uint8_t port_id;
3218 };
3219
3220 static void
3221 cmd_rx_vlan_filter_parsed(void *parsed_result,
3222                           __attribute__((unused)) struct cmdline *cl,
3223                           __attribute__((unused)) void *data)
3224 {
3225         struct cmd_rx_vlan_filter_result *res = parsed_result;
3226
3227         if (!strcmp(res->what, "add"))
3228                 rx_vft_set(res->port_id, res->vlan_id, 1);
3229         else
3230                 rx_vft_set(res->port_id, res->vlan_id, 0);
3231 }
3232
3233 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3234         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3235                                  rx_vlan, "rx_vlan");
3236 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3237         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3238                                  what, "add#rm");
3239 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3240         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3241                               vlan_id, UINT16);
3242 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3243         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3244                               port_id, UINT8);
3245
3246 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3247         .f = cmd_rx_vlan_filter_parsed,
3248         .data = NULL,
3249         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3250                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3251                 "identifiers filtered by a port",
3252         .tokens = {
3253                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3254                 (void *)&cmd_rx_vlan_filter_what,
3255                 (void *)&cmd_rx_vlan_filter_vlanid,
3256                 (void *)&cmd_rx_vlan_filter_portid,
3257                 NULL,
3258         },
3259 };
3260
3261 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3262 struct cmd_tx_vlan_set_result {
3263         cmdline_fixed_string_t tx_vlan;
3264         cmdline_fixed_string_t set;
3265         uint8_t port_id;
3266         uint16_t vlan_id;
3267 };
3268
3269 static void
3270 cmd_tx_vlan_set_parsed(void *parsed_result,
3271                        __attribute__((unused)) struct cmdline *cl,
3272                        __attribute__((unused)) void *data)
3273 {
3274         struct cmd_tx_vlan_set_result *res = parsed_result;
3275
3276         tx_vlan_set(res->port_id, res->vlan_id);
3277 }
3278
3279 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3280         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3281                                  tx_vlan, "tx_vlan");
3282 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3283         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3284                                  set, "set");
3285 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3286         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3287                               port_id, UINT8);
3288 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3290                               vlan_id, UINT16);
3291
3292 cmdline_parse_inst_t cmd_tx_vlan_set = {
3293         .f = cmd_tx_vlan_set_parsed,
3294         .data = NULL,
3295         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3296                 "Enable hardware insertion of a single VLAN header "
3297                 "with a given TAG Identifier in packets sent on a port",
3298         .tokens = {
3299                 (void *)&cmd_tx_vlan_set_tx_vlan,
3300                 (void *)&cmd_tx_vlan_set_set,
3301                 (void *)&cmd_tx_vlan_set_portid,
3302                 (void *)&cmd_tx_vlan_set_vlanid,
3303                 NULL,
3304         },
3305 };
3306
3307 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3308 struct cmd_tx_vlan_set_qinq_result {
3309         cmdline_fixed_string_t tx_vlan;
3310         cmdline_fixed_string_t set;
3311         uint8_t port_id;
3312         uint16_t vlan_id;
3313         uint16_t vlan_id_outer;
3314 };
3315
3316 static void
3317 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3318                             __attribute__((unused)) struct cmdline *cl,
3319                             __attribute__((unused)) void *data)
3320 {
3321         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3322
3323         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3324 }
3325
3326 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3327         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3328                 tx_vlan, "tx_vlan");
3329 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3330         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3331                 set, "set");
3332 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3333         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3334                 port_id, UINT8);
3335 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3336         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3337                 vlan_id, UINT16);
3338 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3339         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3340                 vlan_id_outer, UINT16);
3341
3342 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3343         .f = cmd_tx_vlan_set_qinq_parsed,
3344         .data = NULL,
3345         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3346                 "Enable hardware insertion of double VLAN header "
3347                 "with given TAG Identifiers in packets sent on a port",
3348         .tokens = {
3349                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3350                 (void *)&cmd_tx_vlan_set_qinq_set,
3351                 (void *)&cmd_tx_vlan_set_qinq_portid,
3352                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3353                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3354                 NULL,
3355         },
3356 };
3357
3358 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3359 struct cmd_tx_vlan_set_pvid_result {
3360         cmdline_fixed_string_t tx_vlan;
3361         cmdline_fixed_string_t set;
3362         cmdline_fixed_string_t pvid;
3363         uint8_t port_id;
3364         uint16_t vlan_id;
3365         cmdline_fixed_string_t mode;
3366 };
3367
3368 static void
3369 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3370                             __attribute__((unused)) struct cmdline *cl,
3371                             __attribute__((unused)) void *data)
3372 {
3373         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3374
3375         if (strcmp(res->mode, "on") == 0)
3376                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3377         else
3378                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3379 }
3380
3381 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3382         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3383                                  tx_vlan, "tx_vlan");
3384 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3385         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3386                                  set, "set");
3387 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3388         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3389                                  pvid, "pvid");
3390 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3391         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3392                              port_id, UINT8);
3393 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3394         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3395                               vlan_id, UINT16);
3396 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3397         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3398                                  mode, "on#off");
3399
3400 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3401         .f = cmd_tx_vlan_set_pvid_parsed,
3402         .data = NULL,
3403         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3404         .tokens = {
3405                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3406                 (void *)&cmd_tx_vlan_set_pvid_set,
3407                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3408                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3409                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3410                 (void *)&cmd_tx_vlan_set_pvid_mode,
3411                 NULL,
3412         },
3413 };
3414
3415 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3416 struct cmd_tx_vlan_reset_result {
3417         cmdline_fixed_string_t tx_vlan;
3418         cmdline_fixed_string_t reset;
3419         uint8_t port_id;
3420 };
3421
3422 static void
3423 cmd_tx_vlan_reset_parsed(void *parsed_result,
3424                          __attribute__((unused)) struct cmdline *cl,
3425                          __attribute__((unused)) void *data)
3426 {
3427         struct cmd_tx_vlan_reset_result *res = parsed_result;
3428
3429         tx_vlan_reset(res->port_id);
3430 }
3431
3432 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3433         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3434                                  tx_vlan, "tx_vlan");
3435 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3436         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3437                                  reset, "reset");
3438 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3439         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3440                               port_id, UINT8);
3441
3442 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3443         .f = cmd_tx_vlan_reset_parsed,
3444         .data = NULL,
3445         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3446                 "VLAN header in packets sent on a port",
3447         .tokens = {
3448                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3449                 (void *)&cmd_tx_vlan_reset_reset,
3450                 (void *)&cmd_tx_vlan_reset_portid,
3451                 NULL,
3452         },
3453 };
3454
3455
3456 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3457 struct cmd_csum_result {
3458         cmdline_fixed_string_t csum;
3459         cmdline_fixed_string_t mode;
3460         cmdline_fixed_string_t proto;
3461         cmdline_fixed_string_t hwsw;
3462         uint8_t port_id;
3463 };
3464
3465 static void
3466 csum_show(int port_id)
3467 {
3468         struct rte_eth_dev_info dev_info;
3469         uint16_t ol_flags;
3470
3471         ol_flags = ports[port_id].tx_ol_flags;
3472         printf("Parse tunnel is %s\n",
3473                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3474         printf("IP checksum offload is %s\n",
3475                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3476         printf("UDP checksum offload is %s\n",
3477                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3478         printf("TCP checksum offload is %s\n",
3479                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3480         printf("SCTP checksum offload is %s\n",
3481                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3482         printf("Outer-Ip checksum offload is %s\n",
3483                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3484
3485         /* display warnings if configuration is not supported by the NIC */
3486         rte_eth_dev_info_get(port_id, &dev_info);
3487         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3488                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3489                 printf("Warning: hardware IP checksum enabled but not "
3490                         "supported by port %d\n", port_id);
3491         }
3492         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3493                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3494                 printf("Warning: hardware UDP checksum enabled but not "
3495                         "supported by port %d\n", port_id);
3496         }
3497         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3498                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3499                 printf("Warning: hardware TCP checksum enabled but not "
3500                         "supported by port %d\n", port_id);
3501         }
3502         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3503                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3504                 printf("Warning: hardware SCTP checksum enabled but not "
3505                         "supported by port %d\n", port_id);
3506         }
3507         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3508                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3509                 printf("Warning: hardware outer IP checksum enabled but not "
3510                         "supported by port %d\n", port_id);
3511         }
3512 }
3513
3514 static void
3515 cmd_csum_parsed(void *parsed_result,
3516                        __attribute__((unused)) struct cmdline *cl,
3517                        __attribute__((unused)) void *data)
3518 {
3519         struct cmd_csum_result *res = parsed_result;
3520         int hw = 0;
3521         uint16_t mask = 0;
3522
3523         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3524                 printf("invalid port %d\n", res->port_id);
3525                 return;
3526         }
3527
3528         if (!strcmp(res->mode, "set")) {
3529
3530                 if (!strcmp(res->hwsw, "hw"))
3531                         hw = 1;
3532
3533                 if (!strcmp(res->proto, "ip")) {
3534                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3535                 } else if (!strcmp(res->proto, "udp")) {
3536                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3537                 } else if (!strcmp(res->proto, "tcp")) {
3538                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3539                 } else if (!strcmp(res->proto, "sctp")) {
3540                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3541                 } else if (!strcmp(res->proto, "outer-ip")) {
3542                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3543                 }
3544
3545                 if (hw)
3546                         ports[res->port_id].tx_ol_flags |= mask;
3547                 else
3548                         ports[res->port_id].tx_ol_flags &= (~mask);
3549         }
3550         csum_show(res->port_id);
3551 }
3552
3553 cmdline_parse_token_string_t cmd_csum_csum =
3554         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3555                                 csum, "csum");
3556 cmdline_parse_token_string_t cmd_csum_mode =
3557         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3558                                 mode, "set");
3559 cmdline_parse_token_string_t cmd_csum_proto =
3560         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3561                                 proto, "ip#tcp#udp#sctp#outer-ip");
3562 cmdline_parse_token_string_t cmd_csum_hwsw =
3563         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3564                                 hwsw, "hw#sw");
3565 cmdline_parse_token_num_t cmd_csum_portid =
3566         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3567                                 port_id, UINT8);
3568
3569 cmdline_parse_inst_t cmd_csum_set = {
3570         .f = cmd_csum_parsed,
3571         .data = NULL,
3572         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3573                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3574                 "using csum forward engine",
3575         .tokens = {
3576                 (void *)&cmd_csum_csum,
3577                 (void *)&cmd_csum_mode,
3578                 (void *)&cmd_csum_proto,
3579                 (void *)&cmd_csum_hwsw,
3580                 (void *)&cmd_csum_portid,
3581                 NULL,
3582         },
3583 };
3584
3585 cmdline_parse_token_string_t cmd_csum_mode_show =
3586         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3587                                 mode, "show");
3588
3589 cmdline_parse_inst_t cmd_csum_show = {
3590         .f = cmd_csum_parsed,
3591         .data = NULL,
3592         .help_str = "csum show <port_id>: Show checksum offload configuration",
3593         .tokens = {
3594                 (void *)&cmd_csum_csum,
3595                 (void *)&cmd_csum_mode_show,
3596                 (void *)&cmd_csum_portid,
3597                 NULL,
3598         },
3599 };
3600
3601 /* Enable/disable tunnel parsing */
3602 struct cmd_csum_tunnel_result {
3603         cmdline_fixed_string_t csum;
3604         cmdline_fixed_string_t parse;
3605         cmdline_fixed_string_t onoff;
3606         uint8_t port_id;
3607 };
3608
3609 static void
3610 cmd_csum_tunnel_parsed(void *parsed_result,
3611                        __attribute__((unused)) struct cmdline *cl,
3612                        __attribute__((unused)) void *data)
3613 {
3614         struct cmd_csum_tunnel_result *res = parsed_result;
3615
3616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3617                 return;
3618
3619         if (!strcmp(res->onoff, "on"))
3620                 ports[res->port_id].tx_ol_flags |=
3621                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3622         else
3623                 ports[res->port_id].tx_ol_flags &=
3624                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3625
3626         csum_show(res->port_id);
3627 }
3628
3629 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3630         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3631                                 csum, "csum");
3632 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3633         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3634                                 parse, "parse_tunnel");
3635 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3636         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3637                                 onoff, "on#off");
3638 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3639         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3640                                 port_id, UINT8);
3641
3642 cmdline_parse_inst_t cmd_csum_tunnel = {
3643         .f = cmd_csum_tunnel_parsed,
3644         .data = NULL,
3645         .help_str = "csum parse_tunnel on|off <port_id>: "
3646                 "Enable/Disable parsing of tunnels for csum engine",
3647         .tokens = {
3648                 (void *)&cmd_csum_tunnel_csum,
3649                 (void *)&cmd_csum_tunnel_parse,
3650                 (void *)&cmd_csum_tunnel_onoff,
3651                 (void *)&cmd_csum_tunnel_portid,
3652                 NULL,
3653         },
3654 };
3655
3656 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3657 struct cmd_tso_set_result {
3658         cmdline_fixed_string_t tso;
3659         cmdline_fixed_string_t mode;
3660         uint16_t tso_segsz;
3661         uint8_t port_id;
3662 };
3663
3664 static void
3665 cmd_tso_set_parsed(void *parsed_result,
3666                        __attribute__((unused)) struct cmdline *cl,
3667                        __attribute__((unused)) void *data)
3668 {
3669         struct cmd_tso_set_result *res = parsed_result;
3670         struct rte_eth_dev_info dev_info;
3671
3672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3673                 return;
3674
3675         if (!strcmp(res->mode, "set"))
3676                 ports[res->port_id].tso_segsz = res->tso_segsz;
3677
3678         if (ports[res->port_id].tso_segsz == 0)
3679                 printf("TSO for non-tunneled packets is disabled\n");
3680         else
3681                 printf("TSO segment size for non-tunneled packets is %d\n",
3682                         ports[res->port_id].tso_segsz);
3683
3684         /* display warnings if configuration is not supported by the NIC */
3685         rte_eth_dev_info_get(res->port_id, &dev_info);
3686         if ((ports[res->port_id].tso_segsz != 0) &&
3687                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3688                 printf("Warning: TSO enabled but not "
3689                         "supported by port %d\n", res->port_id);
3690         }
3691 }
3692
3693 cmdline_parse_token_string_t cmd_tso_set_tso =
3694         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3695                                 tso, "tso");
3696 cmdline_parse_token_string_t cmd_tso_set_mode =
3697         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3698                                 mode, "set");
3699 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3700         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3701                                 tso_segsz, UINT16);
3702 cmdline_parse_token_num_t cmd_tso_set_portid =
3703         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3704                                 port_id, UINT8);
3705
3706 cmdline_parse_inst_t cmd_tso_set = {
3707         .f = cmd_tso_set_parsed,
3708         .data = NULL,
3709         .help_str = "tso set <tso_segsz> <port_id>: "
3710                 "Set TSO segment size of non-tunneled packets for csum engine "
3711                 "(0 to disable)",
3712         .tokens = {
3713                 (void *)&cmd_tso_set_tso,
3714                 (void *)&cmd_tso_set_mode,
3715                 (void *)&cmd_tso_set_tso_segsz,
3716                 (void *)&cmd_tso_set_portid,
3717                 NULL,
3718         },
3719 };
3720
3721 cmdline_parse_token_string_t cmd_tso_show_mode =
3722         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3723                                 mode, "show");
3724
3725
3726 cmdline_parse_inst_t cmd_tso_show = {
3727         .f = cmd_tso_set_parsed,
3728         .data = NULL,
3729         .help_str = "tso show <port_id>: "
3730                 "Show TSO segment size of non-tunneled packets for csum engine",
3731         .tokens = {
3732                 (void *)&cmd_tso_set_tso,
3733                 (void *)&cmd_tso_show_mode,
3734                 (void *)&cmd_tso_set_portid,
3735                 NULL,
3736         },
3737 };
3738
3739 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3740 struct cmd_tunnel_tso_set_result {
3741         cmdline_fixed_string_t tso;
3742         cmdline_fixed_string_t mode;
3743         uint16_t tso_segsz;
3744         uint8_t port_id;
3745 };
3746
3747 static void
3748 check_tunnel_tso_nic_support(uint8_t port_id)
3749 {
3750         struct rte_eth_dev_info dev_info;
3751
3752         rte_eth_dev_info_get(port_id, &dev_info);
3753         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3754                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3755                        "supported by port %d\n", port_id);
3756         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3757                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3758                         "supported by port %d\n", port_id);
3759         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3760                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3761                        "supported by port %d\n", port_id);
3762         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3763                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3764                        "supported by port %d\n", port_id);
3765 }
3766
3767 static void
3768 cmd_tunnel_tso_set_parsed(void *parsed_result,
3769                           __attribute__((unused)) struct cmdline *cl,
3770                           __attribute__((unused)) void *data)
3771 {
3772         struct cmd_tunnel_tso_set_result *res = parsed_result;
3773
3774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3775                 return;
3776
3777         if (!strcmp(res->mode, "set"))
3778                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3779
3780         if (ports[res->port_id].tunnel_tso_segsz == 0)
3781                 printf("TSO for tunneled packets is disabled\n");
3782         else {
3783                 printf("TSO segment size for tunneled packets is %d\n",
3784                         ports[res->port_id].tunnel_tso_segsz);
3785
3786                 /* Below conditions are needed to make it work:
3787                  * (1) tunnel TSO is supported by the NIC;
3788                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3789                  * are recognized;
3790                  * (3) for tunneled pkts with outer L3 of IPv4,
3791                  * "csum set outer-ip" must be set to hw, because after tso,
3792                  * total_len of outer IP header is changed, and the checksum
3793                  * of outer IP header calculated by sw should be wrong; that
3794                  * is not necessary for IPv6 tunneled pkts because there's no
3795                  * checksum in IP header anymore.
3796                  */
3797                 check_tunnel_tso_nic_support(res->port_id);
3798
3799                 if (!(ports[res->port_id].tx_ol_flags &
3800                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3801                         printf("Warning: csum parse_tunnel must be set "
3802                                 "so that tunneled packets are recognized\n");
3803                 if (!(ports[res->port_id].tx_ol_flags &
3804                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3805                         printf("Warning: csum set outer-ip must be set to hw "
3806                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3807         }
3808 }
3809
3810 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3811         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3812                                 tso, "tunnel_tso");
3813 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3814         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3815                                 mode, "set");
3816 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3817         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3818                                 tso_segsz, UINT16);
3819 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3820         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3821                                 port_id, UINT8);
3822
3823 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3824         .f = cmd_tunnel_tso_set_parsed,
3825         .data = NULL,
3826         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3827                 "Set TSO segment size of tunneled packets for csum engine "
3828                 "(0 to disable)",
3829         .tokens = {
3830                 (void *)&cmd_tunnel_tso_set_tso,
3831                 (void *)&cmd_tunnel_tso_set_mode,
3832                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3833                 (void *)&cmd_tunnel_tso_set_portid,
3834                 NULL,
3835         },
3836 };
3837
3838 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3839         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3840                                 mode, "show");
3841
3842
3843 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3844         .f = cmd_tunnel_tso_set_parsed,
3845         .data = NULL,
3846         .help_str = "tunnel_tso show <port_id> "
3847                 "Show TSO segment size of tunneled packets for csum engine",
3848         .tokens = {
3849                 (void *)&cmd_tunnel_tso_set_tso,
3850                 (void *)&cmd_tunnel_tso_show_mode,
3851                 (void *)&cmd_tunnel_tso_set_portid,
3852                 NULL,
3853         },
3854 };
3855
3856 /* *** SET GRO FOR A PORT *** */
3857 struct cmd_gro_result {
3858         cmdline_fixed_string_t cmd_keyword;
3859         cmdline_fixed_string_t mode;
3860         uint8_t port_id;
3861 };
3862
3863 static void
3864 cmd_enable_gro_parsed(void *parsed_result,
3865                 __attribute__((unused)) struct cmdline *cl,
3866                 __attribute__((unused)) void *data)
3867 {
3868         struct cmd_gro_result *res;
3869
3870         res = parsed_result;
3871         setup_gro(res->mode, res->port_id);
3872 }
3873
3874 cmdline_parse_token_string_t cmd_gro_keyword =
3875         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3876                         cmd_keyword, "gro");
3877 cmdline_parse_token_string_t cmd_gro_mode =
3878         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3879                         mode, "on#off");
3880 cmdline_parse_token_num_t cmd_gro_pid =
3881         TOKEN_NUM_INITIALIZER(struct cmd_gro_result,
3882                         port_id, UINT8);
3883
3884 cmdline_parse_inst_t cmd_enable_gro = {
3885         .f = cmd_enable_gro_parsed,
3886         .data = NULL,
3887         .help_str = "gro (on|off) (port_id)",
3888         .tokens = {
3889                 (void *)&cmd_gro_keyword,
3890                 (void *)&cmd_gro_mode,
3891                 (void *)&cmd_gro_pid,
3892                 NULL,
3893         },
3894 };
3895
3896 /* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */
3897 struct cmd_gro_set_result {
3898         cmdline_fixed_string_t gro;
3899         cmdline_fixed_string_t mode;
3900         uint16_t flow_num;
3901         uint16_t item_num_per_flow;
3902         uint8_t port_id;
3903 };
3904
3905 static void
3906 cmd_gro_set_parsed(void *parsed_result,
3907                        __attribute__((unused)) struct cmdline *cl,
3908                        __attribute__((unused)) void *data)
3909 {
3910         struct cmd_gro_set_result *res = parsed_result;
3911
3912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3913                 return;
3914         if (test_done == 0) {
3915                 printf("Before set GRO flow_num and item_num_per_flow,"
3916                                 " please stop forwarding first\n");
3917                 return;
3918         }
3919
3920         if (!strcmp(res->mode, "set")) {
3921                 if (res->flow_num == 0)
3922                         printf("Invalid flow number. Revert to default value:"
3923                                         " %u.\n", GRO_DEFAULT_FLOW_NUM);
3924                 else
3925                         gro_ports[res->port_id].param.max_flow_num =
3926                                 res->flow_num;
3927
3928                 if (res->item_num_per_flow == 0)
3929                         printf("Invalid item number per-flow. Revert"
3930                                         " to default value:%u.\n",
3931                                         GRO_DEFAULT_ITEM_NUM_PER_FLOW);
3932                 else
3933                         gro_ports[res->port_id].param.max_item_per_flow =
3934                                 res->item_num_per_flow;
3935         }
3936 }
3937
3938 cmdline_parse_token_string_t cmd_gro_set_gro =
3939         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3940                                 gro, "gro");
3941 cmdline_parse_token_string_t cmd_gro_set_mode =
3942         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3943                                 mode, "set");
3944 cmdline_parse_token_num_t cmd_gro_set_flow_num =
3945         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3946                                 flow_num, UINT16);
3947 cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow =
3948         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3949                                 item_num_per_flow, UINT16);
3950 cmdline_parse_token_num_t cmd_gro_set_portid =
3951         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3952                                 port_id, UINT8);
3953
3954 cmdline_parse_inst_t cmd_gro_set = {
3955         .f = cmd_gro_set_parsed,
3956         .data = NULL,
3957         .help_str = "gro set <max_flow_num> <max_item_num_per_flow> "
3958                 "<port_id>: set max flow number and max packet number per-flow "
3959                 "for GRO",
3960         .tokens = {
3961                 (void *)&cmd_gro_set_gro,
3962                 (void *)&cmd_gro_set_mode,
3963                 (void *)&cmd_gro_set_flow_num,
3964                 (void *)&cmd_gro_set_item_num_per_flow,
3965                 (void *)&cmd_gro_set_portid,
3966                 NULL,
3967         },
3968 };
3969
3970 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3971 struct cmd_set_flush_rx {
3972         cmdline_fixed_string_t set;
3973         cmdline_fixed_string_t flush_rx;
3974         cmdline_fixed_string_t mode;
3975 };
3976
3977 static void
3978 cmd_set_flush_rx_parsed(void *parsed_result,
3979                 __attribute__((unused)) struct cmdline *cl,
3980                 __attribute__((unused)) void *data)
3981 {
3982         struct cmd_set_flush_rx *res = parsed_result;
3983         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3984 }
3985
3986 cmdline_parse_token_string_t cmd_setflushrx_set =
3987         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3988                         set, "set");
3989 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3990         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3991                         flush_rx, "flush_rx");
3992 cmdline_parse_token_string_t cmd_setflushrx_mode =
3993         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3994                         mode, "on#off");
3995
3996
3997 cmdline_parse_inst_t cmd_set_flush_rx = {
3998         .f = cmd_set_flush_rx_parsed,
3999         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4000         .data = NULL,
4001         .tokens = {
4002                 (void *)&cmd_setflushrx_set,
4003                 (void *)&cmd_setflushrx_flush_rx,
4004                 (void *)&cmd_setflushrx_mode,
4005                 NULL,
4006         },
4007 };
4008
4009 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4010 struct cmd_set_link_check {
4011         cmdline_fixed_string_t set;
4012         cmdline_fixed_string_t link_check;
4013         cmdline_fixed_string_t mode;
4014 };
4015
4016 static void
4017 cmd_set_link_check_parsed(void *parsed_result,
4018                 __attribute__((unused)) struct cmdline *cl,
4019                 __attribute__((unused)) void *data)
4020 {
4021         struct cmd_set_link_check *res = parsed_result;
4022         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4023 }
4024
4025 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4026         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4027                         set, "set");
4028 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4029         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4030                         link_check, "link_check");
4031 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4032         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4033                         mode, "on#off");
4034
4035
4036 cmdline_parse_inst_t cmd_set_link_check = {
4037         .f = cmd_set_link_check_parsed,
4038         .help_str = "set link_check on|off: Enable/Disable link status check "
4039                     "when starting/stopping a port",
4040         .data = NULL,
4041         .tokens = {
4042                 (void *)&cmd_setlinkcheck_set,
4043                 (void *)&cmd_setlinkcheck_link_check,
4044                 (void *)&cmd_setlinkcheck_mode,
4045                 NULL,
4046         },
4047 };
4048
4049 /* *** SET NIC BYPASS MODE *** */
4050 struct cmd_set_bypass_mode_result {
4051         cmdline_fixed_string_t set;
4052         cmdline_fixed_string_t bypass;
4053         cmdline_fixed_string_t mode;
4054         cmdline_fixed_string_t value;
4055         uint8_t port_id;
4056 };
4057
4058 static void
4059 cmd_set_bypass_mode_parsed(void *parsed_result,
4060                 __attribute__((unused)) struct cmdline *cl,
4061                 __attribute__((unused)) void *data)
4062 {
4063         struct cmd_set_bypass_mode_result *res = parsed_result;
4064         portid_t port_id = res->port_id;
4065         int32_t rc = -EINVAL;
4066
4067 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4068         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4069
4070         if (!strcmp(res->value, "bypass"))
4071                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4072         else if (!strcmp(res->value, "isolate"))
4073                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4074         else
4075                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4076
4077         /* Set the bypass mode for the relevant port. */
4078         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4079 #endif
4080         if (rc != 0)
4081                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4082 }
4083
4084 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4086                         set, "set");
4087 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4089                         bypass, "bypass");
4090 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4091         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4092                         mode, "mode");
4093 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4094         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4095                         value, "normal#bypass#isolate");
4096 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4097         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4098                                 port_id, UINT8);
4099
4100 cmdline_parse_inst_t cmd_set_bypass_mode = {
4101         .f = cmd_set_bypass_mode_parsed,
4102         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4103                     "Set the NIC bypass mode for port_id",
4104         .data = NULL,
4105         .tokens = {
4106                 (void *)&cmd_setbypass_mode_set,
4107                 (void *)&cmd_setbypass_mode_bypass,
4108                 (void *)&cmd_setbypass_mode_mode,
4109                 (void *)&cmd_setbypass_mode_value,
4110                 (void *)&cmd_setbypass_mode_port,
4111                 NULL,
4112         },
4113 };
4114
4115 /* *** SET NIC BYPASS EVENT *** */
4116 struct cmd_set_bypass_event_result {
4117         cmdline_fixed_string_t set;
4118         cmdline_fixed_string_t bypass;
4119         cmdline_fixed_string_t event;
4120         cmdline_fixed_string_t event_value;
4121         cmdline_fixed_string_t mode;
4122         cmdline_fixed_string_t mode_value;
4123         uint8_t port_id;
4124 };
4125
4126 static void
4127 cmd_set_bypass_event_parsed(void *parsed_result,
4128                 __attribute__((unused)) struct cmdline *cl,
4129                 __attribute__((unused)) void *data)
4130 {
4131         int32_t rc = -EINVAL;
4132         struct cmd_set_bypass_event_result *res = parsed_result;
4133         portid_t port_id = res->port_id;
4134
4135 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4136         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4137         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4138
4139         if (!strcmp(res->event_value, "timeout"))
4140                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4141         else if (!strcmp(res->event_value, "os_on"))
4142                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4143         else if (!strcmp(res->event_value, "os_off"))
4144                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4145         else if (!strcmp(res->event_value, "power_on"))
4146                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4147         else if (!strcmp(res->event_value, "power_off"))
4148                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4149         else
4150                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4151
4152         if (!strcmp(res->mode_value, "bypass"))
4153                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4154         else if (!strcmp(res->mode_value, "isolate"))
4155                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4156         else
4157                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4158
4159         /* Set the watchdog timeout. */
4160         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4161
4162                 rc = -EINVAL;
4163                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4164                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4165                                                            bypass_timeout);
4166                 }
4167                 if (rc != 0) {
4168                         printf("Failed to set timeout value %u "
4169                         "for port %d, errto code: %d.\n",
4170                         bypass_timeout, port_id, rc);
4171                 }
4172         }
4173
4174         /* Set the bypass event to transition to bypass mode. */
4175         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4176                                               bypass_mode);
4177 #endif
4178
4179         if (rc != 0)
4180                 printf("\t Failed to set bypass event for port = %d.\n",
4181                        port_id);
4182 }
4183
4184 cmdline_parse_token_string_t cmd_setbypass_event_set =
4185         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4186                         set, "set");
4187 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4188         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4189                         bypass, "bypass");
4190 cmdline_parse_token_string_t cmd_setbypass_event_event =
4191         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4192                         event, "event");
4193 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4194         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4195                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4196 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4197         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4198                         mode, "mode");
4199 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4200         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4201                         mode_value, "normal#bypass#isolate");
4202 cmdline_parse_token_num_t cmd_setbypass_event_port =
4203         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4204                                 port_id, UINT8);
4205
4206 cmdline_parse_inst_t cmd_set_bypass_event = {
4207         .f = cmd_set_bypass_event_parsed,
4208         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4209                 "power_off mode normal|bypass|isolate <port_id>: "
4210                 "Set the NIC bypass event mode for port_id",
4211         .data = NULL,
4212         .tokens = {
4213                 (void *)&cmd_setbypass_event_set,
4214                 (void *)&cmd_setbypass_event_bypass,
4215                 (void *)&cmd_setbypass_event_event,
4216                 (void *)&cmd_setbypass_event_event_value,
4217                 (void *)&cmd_setbypass_event_mode,
4218                 (void *)&cmd_setbypass_event_mode_value,
4219                 (void *)&cmd_setbypass_event_port,
4220                 NULL,
4221         },
4222 };
4223
4224
4225 /* *** SET NIC BYPASS TIMEOUT *** */
4226 struct cmd_set_bypass_timeout_result {
4227         cmdline_fixed_string_t set;
4228         cmdline_fixed_string_t bypass;
4229         cmdline_fixed_string_t timeout;
4230         cmdline_fixed_string_t value;
4231 };
4232
4233 static void
4234 cmd_set_bypass_timeout_parsed(void *parsed_result,
4235                 __attribute__((unused)) struct cmdline *cl,
4236                 __attribute__((unused)) void *data)
4237 {
4238         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4239
4240 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4241         if (!strcmp(res->value, "1.5"))
4242                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4243         else if (!strcmp(res->value, "2"))
4244                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4245         else if (!strcmp(res->value, "3"))
4246                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4247         else if (!strcmp(res->value, "4"))
4248                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4249         else if (!strcmp(res->value, "8"))
4250                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4251         else if (!strcmp(res->value, "16"))
4252                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4253         else if (!strcmp(res->value, "32"))
4254                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4255         else
4256                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4257 #endif
4258 }
4259
4260 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4261         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4262                         set, "set");
4263 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4265                         bypass, "bypass");
4266 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4267         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4268                         timeout, "timeout");
4269 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4270         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4271                         value, "0#1.5#2#3#4#8#16#32");
4272
4273 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4274         .f = cmd_set_bypass_timeout_parsed,
4275         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4276                 "Set the NIC bypass watchdog timeout in seconds",
4277         .data = NULL,
4278         .tokens = {
4279                 (void *)&cmd_setbypass_timeout_set,
4280                 (void *)&cmd_setbypass_timeout_bypass,
4281                 (void *)&cmd_setbypass_timeout_timeout,
4282                 (void *)&cmd_setbypass_timeout_value,
4283                 NULL,
4284         },
4285 };
4286
4287 /* *** SHOW NIC BYPASS MODE *** */
4288 struct cmd_show_bypass_config_result {
4289         cmdline_fixed_string_t show;
4290         cmdline_fixed_string_t bypass;
4291         cmdline_fixed_string_t config;
4292         uint8_t port_id;
4293 };
4294
4295 static void
4296 cmd_show_bypass_config_parsed(void *parsed_result,
4297                 __attribute__((unused)) struct cmdline *cl,
4298                 __attribute__((unused)) void *data)
4299 {
4300         struct cmd_show_bypass_config_result *res = parsed_result;
4301         portid_t port_id = res->port_id;
4302         int rc = -EINVAL;
4303 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4304         uint32_t event_mode;
4305         uint32_t bypass_mode;
4306         uint32_t timeout = bypass_timeout;
4307         int i;
4308
4309         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4310                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4311         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4312                 {"UNKNOWN", "normal", "bypass", "isolate"};
4313         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4314                 "NONE",
4315                 "OS/board on",
4316                 "power supply on",
4317                 "OS/board off",
4318                 "power supply off",
4319                 "timeout"};
4320         int num_events = (sizeof events) / (sizeof events[0]);
4321
4322         /* Display the bypass mode.*/
4323         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4324                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4325                 return;
4326         }
4327         else {
4328                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4329                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4330
4331                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4332         }
4333
4334         /* Display the bypass timeout.*/
4335         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4336                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4337
4338         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4339
4340         /* Display the bypass events and associated modes. */
4341         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4342
4343                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4344                         printf("\tFailed to get bypass mode for event = %s\n",
4345                                 events[i]);
4346                 } else {
4347                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4348                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4349
4350                         printf("\tbypass event: %-16s = %s\n", events[i],
4351                                 modes[event_mode]);
4352                 }
4353         }
4354 #endif
4355         if (rc != 0)
4356                 printf("\tFailed to get bypass configuration for port = %d\n",
4357                        port_id);
4358 }
4359
4360 cmdline_parse_token_string_t cmd_showbypass_config_show =
4361         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4362                         show, "show");
4363 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4364         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4365                         bypass, "bypass");
4366 cmdline_parse_token_string_t cmd_showbypass_config_config =
4367         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4368                         config, "config");
4369 cmdline_parse_token_num_t cmd_showbypass_config_port =
4370         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4371                                 port_id, UINT8);
4372
4373 cmdline_parse_inst_t cmd_show_bypass_config = {
4374         .f = cmd_show_bypass_config_parsed,
4375         .help_str = "show bypass config <port_id>: "
4376                     "Show the NIC bypass config for port_id",
4377         .data = NULL,
4378         .tokens = {
4379                 (void *)&cmd_showbypass_config_show,
4380                 (void *)&cmd_showbypass_config_bypass,
4381                 (void *)&cmd_showbypass_config_config,
4382                 (void *)&cmd_showbypass_config_port,
4383                 NULL,
4384         },
4385 };
4386
4387 #ifdef RTE_LIBRTE_PMD_BOND
4388 /* *** SET BONDING MODE *** */
4389 struct cmd_set_bonding_mode_result {
4390         cmdline_fixed_string_t set;
4391         cmdline_fixed_string_t bonding;
4392         cmdline_fixed_string_t mode;
4393         uint8_t value;
4394         uint8_t port_id;
4395 };
4396
4397 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4398                 __attribute__((unused))  struct cmdline *cl,
4399                 __attribute__((unused)) void *data)
4400 {
4401         struct cmd_set_bonding_mode_result *res = parsed_result;
4402         portid_t port_id = res->port_id;
4403
4404         /* Set the bonding mode for the relevant port. */
4405         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4406                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4407 }
4408
4409 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4410 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4411                 set, "set");
4412 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4413 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4414                 bonding, "bonding");
4415 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4416 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4417                 mode, "mode");
4418 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4419 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4420                 value, UINT8);
4421 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4422 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4423                 port_id, UINT8);
4424
4425 cmdline_parse_inst_t cmd_set_bonding_mode = {
4426                 .f = cmd_set_bonding_mode_parsed,
4427                 .help_str = "set bonding mode <mode_value> <port_id>: "
4428                         "Set the bonding mode for port_id",
4429                 .data = NULL,
4430                 .tokens = {
4431                                 (void *) &cmd_setbonding_mode_set,
4432                                 (void *) &cmd_setbonding_mode_bonding,
4433                                 (void *) &cmd_setbonding_mode_mode,
4434                                 (void *) &cmd_setbonding_mode_value,
4435                                 (void *) &cmd_setbonding_mode_port,
4436                                 NULL
4437                 }
4438 };
4439
4440 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4441 struct cmd_set_bonding_lacp_dedicated_queues_result {
4442         cmdline_fixed_string_t set;
4443         cmdline_fixed_string_t bonding;
4444         cmdline_fixed_string_t lacp;
4445         cmdline_fixed_string_t dedicated_queues;
4446         uint8_t port_id;
4447         cmdline_fixed_string_t mode;
4448 };
4449
4450 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4451                 __attribute__((unused))  struct cmdline *cl,
4452                 __attribute__((unused)) void *data)
4453 {
4454         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4455         portid_t port_id = res->port_id;
4456         struct rte_port *port;
4457
4458         port = &ports[port_id];
4459
4460         /** Check if the port is not started **/
4461         if (port->port_status != RTE_PORT_STOPPED) {
4462                 printf("Please stop port %d first\n", port_id);
4463                 return;
4464         }
4465
4466         if (!strcmp(res->mode, "enable")) {
4467                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4468                         printf("Dedicate queues for LACP control packets"
4469                                         " enabled\n");
4470                 else
4471                         printf("Enabling dedicate queues for LACP control "
4472                                         "packets on port %d failed\n", port_id);
4473         } else if (!strcmp(res->mode, "disable")) {
4474                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4475                         printf("Dedicated queues for LACP control packets "
4476                                         "disabled\n");
4477                 else
4478                         printf("Disabling dedicated queues for LACP control "
4479                                         "traffic on port %d failed\n", port_id);
4480         }
4481 }
4482
4483 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4484 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4485                 set, "set");
4486 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4487 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4488                 bonding, "bonding");
4489 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4490 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4491                 lacp, "lacp");
4492 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4493 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4494                 dedicated_queues, "dedicated_queues");
4495 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4496 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4497                 port_id, UINT8);
4498 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4499 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4500                 mode, "enable#disable");
4501
4502 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4503                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4504                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4505                         "enable|disable: "
4506                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4507                 .data = NULL,
4508                 .tokens = {
4509                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4510                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4511                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4512                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4513                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4514                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4515                         NULL
4516                 }
4517 };
4518
4519 /* *** SET BALANCE XMIT POLICY *** */
4520 struct cmd_set_bonding_balance_xmit_policy_result {
4521         cmdline_fixed_string_t set;
4522         cmdline_fixed_string_t bonding;
4523         cmdline_fixed_string_t balance_xmit_policy;
4524         uint8_t port_id;
4525         cmdline_fixed_string_t policy;
4526 };
4527
4528 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4529                 __attribute__((unused))  struct cmdline *cl,
4530                 __attribute__((unused)) void *data)
4531 {
4532         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4533         portid_t port_id = res->port_id;
4534         uint8_t policy;
4535
4536         if (!strcmp(res->policy, "l2")) {
4537                 policy = BALANCE_XMIT_POLICY_LAYER2;
4538         } else if (!strcmp(res->policy, "l23")) {
4539                 policy = BALANCE_XMIT_POLICY_LAYER23;
4540         } else if (!strcmp(res->policy, "l34")) {
4541                 policy = BALANCE_XMIT_POLICY_LAYER34;
4542         } else {
4543                 printf("\t Invalid xmit policy selection");
4544                 return;
4545         }
4546
4547         /* Set the bonding mode for the relevant port. */
4548         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4549                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4550                                 port_id);
4551         }
4552 }
4553
4554 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4555 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4556                 set, "set");
4557 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4558 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4559                 bonding, "bonding");
4560 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4561 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4562                 balance_xmit_policy, "balance_xmit_policy");
4563 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4564 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4565                 port_id, UINT8);
4566 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4567 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4568                 policy, "l2#l23#l34");
4569
4570 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4571                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4572                 .help_str = "set bonding balance_xmit_policy <port_id> "
4573                         "l2|l23|l34: "
4574                         "Set the bonding balance_xmit_policy for port_id",
4575                 .data = NULL,
4576                 .tokens = {
4577                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4578                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4579                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4580                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4581                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4582                                 NULL
4583                 }
4584 };
4585
4586 /* *** SHOW NIC BONDING CONFIGURATION *** */
4587 struct cmd_show_bonding_config_result {
4588         cmdline_fixed_string_t show;
4589         cmdline_fixed_string_t bonding;
4590         cmdline_fixed_string_t config;
4591         uint8_t port_id;
4592 };
4593
4594 static void cmd_show_bonding_config_parsed(void *parsed_result,
4595                 __attribute__((unused))  struct cmdline *cl,
4596                 __attribute__((unused)) void *data)
4597 {
4598         struct cmd_show_bonding_config_result *res = parsed_result;
4599         int bonding_mode, agg_mode;
4600         uint8_t slaves[RTE_MAX_ETHPORTS];
4601         int num_slaves, num_active_slaves;
4602         int primary_id;
4603         int i;
4604         portid_t port_id = res->port_id;
4605
4606         /* Display the bonding mode.*/
4607         bonding_mode = rte_eth_bond_mode_get(port_id);
4608         if (bonding_mode < 0) {
4609                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4610                 return;
4611         } else
4612                 printf("\tBonding mode: %d\n", bonding_mode);
4613
4614         if (bonding_mode == BONDING_MODE_BALANCE) {
4615                 int balance_xmit_policy;
4616
4617                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4618                 if (balance_xmit_policy < 0) {
4619                         printf("\tFailed to get balance xmit policy for port = %d\n",
4620                                         port_id);
4621                         return;
4622                 } else {
4623                         printf("\tBalance Xmit Policy: ");
4624
4625                         switch (balance_xmit_policy) {
4626                         case BALANCE_XMIT_POLICY_LAYER2:
4627                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4628                                 break;
4629                         case BALANCE_XMIT_POLICY_LAYER23:
4630                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4631                                 break;
4632                         case BALANCE_XMIT_POLICY_LAYER34:
4633                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4634                                 break;
4635                         }
4636                         printf("\n");
4637                 }
4638         }
4639
4640         if (bonding_mode == BONDING_MODE_8023AD) {
4641                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4642                 printf("\tIEEE802.3AD Aggregator Mode: ");
4643                 switch (agg_mode) {
4644                 case AGG_BANDWIDTH:
4645                         printf("bandwidth");
4646                         break;
4647                 case AGG_STABLE:
4648                         printf("stable");
4649                         break;
4650                 case AGG_COUNT:
4651                         printf("count");
4652                         break;
4653                 }
4654                 printf("\n");
4655         }
4656
4657         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4658
4659         if (num_slaves < 0) {
4660                 printf("\tFailed to get slave list for port = %d\n", port_id);
4661                 return;
4662         }
4663         if (num_slaves > 0) {
4664                 printf("\tSlaves (%d): [", num_slaves);
4665                 for (i = 0; i < num_slaves - 1; i++)
4666                         printf("%d ", slaves[i]);
4667
4668                 printf("%d]\n", slaves[num_slaves - 1]);
4669         } else {
4670                 printf("\tSlaves: []\n");
4671
4672         }
4673
4674         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4675                         RTE_MAX_ETHPORTS);
4676
4677         if (num_active_slaves < 0) {
4678                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4679                 return;
4680         }
4681         if (num_active_slaves > 0) {
4682                 printf("\tActive Slaves (%d): [", num_active_slaves);
4683                 for (i = 0; i < num_active_slaves - 1; i++)
4684                         printf("%d ", slaves[i]);
4685
4686                 printf("%d]\n", slaves[num_active_slaves - 1]);
4687
4688         } else {
4689                 printf("\tActive Slaves: []\n");
4690
4691         }
4692
4693         primary_id = rte_eth_bond_primary_get(port_id);
4694         if (primary_id < 0) {
4695                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4696                 return;
4697         } else
4698                 printf("\tPrimary: [%d]\n", primary_id);
4699
4700 }
4701
4702 cmdline_parse_token_string_t cmd_showbonding_config_show =
4703 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4704                 show, "show");
4705 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4706 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4707                 bonding, "bonding");
4708 cmdline_parse_token_string_t cmd_showbonding_config_config =
4709 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4710                 config, "config");
4711 cmdline_parse_token_num_t cmd_showbonding_config_port =
4712 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4713                 port_id, UINT8);
4714
4715 cmdline_parse_inst_t cmd_show_bonding_config = {
4716                 .f = cmd_show_bonding_config_parsed,
4717                 .help_str = "show bonding config <port_id>: "
4718                         "Show the bonding config for port_id",
4719                 .data = NULL,
4720                 .tokens = {
4721                                 (void *)&cmd_showbonding_config_show,
4722                                 (void *)&cmd_showbonding_config_bonding,
4723                                 (void *)&cmd_showbonding_config_config,
4724                                 (void *)&cmd_showbonding_config_port,
4725                                 NULL
4726                 }
4727 };
4728
4729 /* *** SET BONDING PRIMARY *** */
4730 struct cmd_set_bonding_primary_result {
4731         cmdline_fixed_string_t set;
4732         cmdline_fixed_string_t bonding;
4733         cmdline_fixed_string_t primary;
4734         uint8_t slave_id;
4735         uint8_t port_id;
4736 };
4737
4738 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4739                 __attribute__((unused))  struct cmdline *cl,
4740                 __attribute__((unused)) void *data)
4741 {
4742         struct cmd_set_bonding_primary_result *res = parsed_result;
4743         portid_t master_port_id = res->port_id;
4744         portid_t slave_port_id = res->slave_id;
4745
4746         /* Set the primary slave for a bonded device. */
4747         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4748                 printf("\t Failed to set primary slave for port = %d.\n",
4749                                 master_port_id);
4750                 return;
4751         }
4752         init_port_config();
4753 }
4754
4755 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4756 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4757                 set, "set");
4758 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4759 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4760                 bonding, "bonding");
4761 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4762 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4763                 primary, "primary");
4764 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4765 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4766                 slave_id, UINT8);
4767 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4768 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4769                 port_id, UINT8);
4770
4771 cmdline_parse_inst_t cmd_set_bonding_primary = {
4772                 .f = cmd_set_bonding_primary_parsed,
4773                 .help_str = "set bonding primary <slave_id> <port_id>: "
4774                         "Set the primary slave for port_id",
4775                 .data = NULL,
4776                 .tokens = {
4777                                 (void *)&cmd_setbonding_primary_set,
4778                                 (void *)&cmd_setbonding_primary_bonding,
4779                                 (void *)&cmd_setbonding_primary_primary,
4780                                 (void *)&cmd_setbonding_primary_slave,
4781                                 (void *)&cmd_setbonding_primary_port,
4782                                 NULL
4783                 }
4784 };
4785
4786 /* *** ADD SLAVE *** */
4787 struct cmd_add_bonding_slave_result {
4788         cmdline_fixed_string_t add;
4789         cmdline_fixed_string_t bonding;
4790         cmdline_fixed_string_t slave;
4791         uint8_t slave_id;
4792         uint8_t port_id;
4793 };
4794
4795 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4796                 __attribute__((unused))  struct cmdline *cl,
4797                 __attribute__((unused)) void *data)
4798 {
4799         struct cmd_add_bonding_slave_result *res = parsed_result;
4800         portid_t master_port_id = res->port_id;
4801         portid_t slave_port_id = res->slave_id;
4802
4803         /* add the slave for a bonded device. */
4804         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4805                 printf("\t Failed to add slave %d to master port = %d.\n",
4806                                 slave_port_id, master_port_id);
4807                 return;
4808         }
4809         init_port_config();
4810         set_port_slave_flag(slave_port_id);
4811 }
4812
4813 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4814 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4815                 add, "add");
4816 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4817 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4818                 bonding, "bonding");
4819 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4820 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4821                 slave, "slave");
4822 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4823 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4824                 slave_id, UINT8);
4825 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4826 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4827                 port_id, UINT8);
4828
4829 cmdline_parse_inst_t cmd_add_bonding_slave = {
4830                 .f = cmd_add_bonding_slave_parsed,
4831                 .help_str = "add bonding slave <slave_id> <port_id>: "
4832                         "Add a slave device to a bonded device",
4833                 .data = NULL,
4834                 .tokens = {
4835                                 (void *)&cmd_addbonding_slave_add,
4836                                 (void *)&cmd_addbonding_slave_bonding,
4837                                 (void *)&cmd_addbonding_slave_slave,
4838                                 (void *)&cmd_addbonding_slave_slaveid,
4839                                 (void *)&cmd_addbonding_slave_port,
4840                                 NULL
4841                 }
4842 };
4843
4844 /* *** REMOVE SLAVE *** */
4845 struct cmd_remove_bonding_slave_result {
4846         cmdline_fixed_string_t remove;
4847         cmdline_fixed_string_t bonding;
4848         cmdline_fixed_string_t slave;
4849         uint8_t slave_id;
4850         uint8_t port_id;
4851 };
4852
4853 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4854                 __attribute__((unused))  struct cmdline *cl,
4855                 __attribute__((unused)) void *data)
4856 {
4857         struct cmd_remove_bonding_slave_result *res = parsed_result;
4858         portid_t master_port_id = res->port_id;
4859         portid_t slave_port_id = res->slave_id;
4860
4861         /* remove the slave from a bonded device. */
4862         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4863                 printf("\t Failed to remove slave %d from master port = %d.\n",
4864                                 slave_port_id, master_port_id);
4865                 return;
4866         }
4867         init_port_config();
4868         clear_port_slave_flag(slave_port_id);
4869 }
4870
4871 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4872                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4873                                 remove, "remove");
4874 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4875                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4876                                 bonding, "bonding");
4877 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4878                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4879                                 slave, "slave");
4880 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4881                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4882                                 slave_id, UINT8);
4883 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4884                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4885                                 port_id, UINT8);
4886
4887 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4888                 .f = cmd_remove_bonding_slave_parsed,
4889                 .help_str = "remove bonding slave <slave_id> <port_id>: "
4890                         "Remove a slave device from a bonded device",
4891                 .data = NULL,
4892                 .tokens = {
4893                                 (void *)&cmd_removebonding_slave_remove,
4894                                 (void *)&cmd_removebonding_slave_bonding,
4895                                 (void *)&cmd_removebonding_slave_slave,
4896                                 (void *)&cmd_removebonding_slave_slaveid,
4897                                 (void *)&cmd_removebonding_slave_port,
4898                                 NULL
4899                 }
4900 };
4901
4902 /* *** CREATE BONDED DEVICE *** */
4903 struct cmd_create_bonded_device_result {
4904         cmdline_fixed_string_t create;
4905         cmdline_fixed_string_t bonded;
4906         cmdline_fixed_string_t device;
4907         uint8_t mode;
4908         uint8_t socket;
4909 };
4910
4911 static int bond_dev_num = 0;
4912
4913 static void cmd_create_bonded_device_parsed(void *parsed_result,
4914                 __attribute__((unused))  struct cmdline *cl,
4915                 __attribute__((unused)) void *data)
4916 {
4917         struct cmd_create_bonded_device_result *res = parsed_result;
4918         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4919         int port_id;
4920
4921         if (test_done == 0) {
4922                 printf("Please stop forwarding first\n");
4923                 return;
4924         }
4925
4926         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
4927                         bond_dev_num++);
4928
4929         /* Create a new bonded device. */
4930         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4931         if (port_id < 0) {
4932                 printf("\t Failed to create bonded device.\n");
4933                 return;
4934         } else {
4935                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4936                                 port_id);
4937
4938                 /* Update number of ports */
4939                 nb_ports = rte_eth_dev_count();
4940                 reconfig(port_id, res->socket);
4941                 rte_eth_promiscuous_enable(port_id);
4942         }
4943
4944 }
4945
4946 cmdline_parse_token_string_t cmd_createbonded_device_create =
4947                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4948                                 create, "create");
4949 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4950                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4951                                 bonded, "bonded");
4952 cmdline_parse_token_string_t cmd_createbonded_device_device =
4953                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4954                                 device, "device");
4955 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4956                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4957                                 mode, UINT8);
4958 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4959                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4960                                 socket, UINT8);
4961
4962 cmdline_parse_inst_t cmd_create_bonded_device = {
4963                 .f = cmd_create_bonded_device_parsed,
4964                 .help_str = "create bonded device <mode> <socket>: "
4965                         "Create a new bonded device with specific bonding mode and socket",
4966                 .data = NULL,
4967                 .tokens = {
4968                                 (void *)&cmd_createbonded_device_create,
4969                                 (void *)&cmd_createbonded_device_bonded,
4970                                 (void *)&cmd_createbonded_device_device,
4971                                 (void *)&cmd_createbonded_device_mode,
4972                                 (void *)&cmd_createbonded_device_socket,
4973                                 NULL
4974                 }
4975 };
4976
4977 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4978 struct cmd_set_bond_mac_addr_result {
4979         cmdline_fixed_string_t set;
4980         cmdline_fixed_string_t bonding;
4981         cmdline_fixed_string_t mac_addr;
4982         uint8_t port_num;
4983         struct ether_addr address;
4984 };
4985
4986 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4987                 __attribute__((unused))  struct cmdline *cl,
4988                 __attribute__((unused)) void *data)
4989 {
4990         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4991         int ret;
4992
4993         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4994                 return;
4995
4996         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4997
4998         /* check the return value and print it if is < 0 */
4999         if (ret < 0)
5000                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5001 }
5002
5003 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5004                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5005 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5006                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5007                                 "bonding");
5008 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5009                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5010                                 "mac_addr");
5011 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5012                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5013 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5014                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5015
5016 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5017                 .f = cmd_set_bond_mac_addr_parsed,
5018                 .data = (void *) 0,
5019                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5020                 .tokens = {
5021                                 (void *)&cmd_set_bond_mac_addr_set,
5022                                 (void *)&cmd_set_bond_mac_addr_bonding,
5023                                 (void *)&cmd_set_bond_mac_addr_mac,
5024                                 (void *)&cmd_set_bond_mac_addr_portnum,
5025                                 (void *)&cmd_set_bond_mac_addr_addr,
5026                                 NULL
5027                 }
5028 };
5029
5030
5031 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5032 struct cmd_set_bond_mon_period_result {
5033         cmdline_fixed_string_t set;
5034         cmdline_fixed_string_t bonding;
5035         cmdline_fixed_string_t mon_period;
5036         uint8_t port_num;
5037         uint32_t period_ms;
5038 };
5039
5040 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5041                 __attribute__((unused))  struct cmdline *cl,
5042                 __attribute__((unused)) void *data)
5043 {
5044         struct cmd_set_bond_mon_period_result *res = parsed_result;
5045         int ret;
5046
5047         if (res->port_num >= nb_ports) {
5048                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5049                 return;
5050         }
5051
5052         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5053
5054         /* check the return value and print it if is < 0 */
5055         if (ret < 0)
5056                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5057 }
5058
5059 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5060                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5061                                 set, "set");
5062 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5063                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5064                                 bonding, "bonding");
5065 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5066                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5067                                 mon_period,     "mon_period");
5068 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5069                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5070                                 port_num, UINT8);
5071 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5072                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5073                                 period_ms, UINT32);
5074
5075 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5076                 .f = cmd_set_bond_mon_period_parsed,
5077                 .data = (void *) 0,
5078                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5079                 .tokens = {
5080                                 (void *)&cmd_set_bond_mon_period_set,
5081                                 (void *)&cmd_set_bond_mon_period_bonding,
5082                                 (void *)&cmd_set_bond_mon_period_mon_period,
5083                                 (void *)&cmd_set_bond_mon_period_portnum,
5084                                 (void *)&cmd_set_bond_mon_period_period_ms,
5085                                 NULL
5086                 }
5087 };
5088
5089
5090
5091 struct cmd_set_bonding_agg_mode_policy_result {
5092         cmdline_fixed_string_t set;
5093         cmdline_fixed_string_t bonding;
5094         cmdline_fixed_string_t agg_mode;
5095         uint8_t port_num;
5096         cmdline_fixed_string_t policy;
5097 };
5098
5099
5100 static void
5101 cmd_set_bonding_agg_mode(void *parsed_result,
5102                 __attribute__((unused)) struct cmdline *cl,
5103                 __attribute__((unused)) void *data)
5104 {
5105         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5106         uint8_t policy = AGG_BANDWIDTH;
5107
5108         if (res->port_num >= nb_ports) {
5109                 printf("Port id %d must be less than %d\n",
5110                                 res->port_num, nb_ports);
5111                 return;
5112         }
5113
5114         if (!strcmp(res->policy, "bandwidth"))
5115                 policy = AGG_BANDWIDTH;
5116         else if (!strcmp(res->policy, "stable"))
5117                 policy = AGG_STABLE;
5118         else if (!strcmp(res->policy, "count"))
5119                 policy = AGG_COUNT;
5120
5121         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5122 }
5123
5124
5125 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5126         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5127                                 set, "set");
5128 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5130                                 bonding, "bonding");
5131
5132 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5133         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5134                                 agg_mode, "agg_mode");
5135
5136 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5137         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5138                                 port_num, UINT8);
5139
5140 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5141         TOKEN_STRING_INITIALIZER(
5142                         struct cmd_set_bonding_balance_xmit_policy_result,
5143                 policy, "stable#bandwidth#count");
5144
5145 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5146         .f = cmd_set_bonding_agg_mode,
5147         .data = (void *) 0,
5148         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5149         .tokens = {
5150                         (void *)&cmd_set_bonding_agg_mode_set,
5151                         (void *)&cmd_set_bonding_agg_mode_bonding,
5152                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5153                         (void *)&cmd_set_bonding_agg_mode_portnum,
5154                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5155                         NULL
5156                 }
5157 };
5158
5159
5160 #endif /* RTE_LIBRTE_PMD_BOND */
5161
5162 /* *** SET FORWARDING MODE *** */
5163 struct cmd_set_fwd_mode_result {
5164         cmdline_fixed_string_t set;
5165         cmdline_fixed_string_t fwd;
5166         cmdline_fixed_string_t mode;
5167 };
5168
5169 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5170                                     __attribute__((unused)) struct cmdline *cl,
5171                                     __attribute__((unused)) void *data)
5172 {
5173         struct cmd_set_fwd_mode_result *res = parsed_result;
5174
5175         retry_enabled = 0;
5176         set_pkt_forwarding_mode(res->mode);
5177 }
5178
5179 cmdline_parse_token_string_t cmd_setfwd_set =
5180         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5181 cmdline_parse_token_string_t cmd_setfwd_fwd =
5182         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5183 cmdline_parse_token_string_t cmd_setfwd_mode =
5184         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5185                 "" /* defined at init */);
5186
5187 cmdline_parse_inst_t cmd_set_fwd_mode = {
5188         .f = cmd_set_fwd_mode_parsed,
5189         .data = NULL,
5190         .help_str = NULL, /* defined at init */
5191         .tokens = {
5192                 (void *)&cmd_setfwd_set,
5193                 (void *)&cmd_setfwd_fwd,
5194                 (void *)&cmd_setfwd_mode,
5195                 NULL,
5196         },
5197 };
5198
5199 static void cmd_set_fwd_mode_init(void)
5200 {
5201         char *modes, *c;
5202         static char token[128];
5203         static char help[256];
5204         cmdline_parse_token_string_t *token_struct;
5205
5206         modes = list_pkt_forwarding_modes();
5207         snprintf(help, sizeof(help), "set fwd %s: "
5208                 "Set packet forwarding mode", modes);
5209         cmd_set_fwd_mode.help_str = help;
5210
5211         /* string token separator is # */
5212         for (c = token; *modes != '\0'; modes++)
5213                 if (*modes == '|')
5214                         *c++ = '#';
5215                 else
5216                         *c++ = *modes;
5217         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5218         token_struct->string_data.str = token;
5219 }
5220
5221 /* *** SET RETRY FORWARDING MODE *** */
5222 struct cmd_set_fwd_retry_mode_result {
5223         cmdline_fixed_string_t set;
5224         cmdline_fixed_string_t fwd;
5225         cmdline_fixed_string_t mode;
5226         cmdline_fixed_string_t retry;
5227 };
5228
5229 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5230                             __attribute__((unused)) struct cmdline *cl,
5231                             __attribute__((unused)) void *data)
5232 {
5233         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5234
5235         retry_enabled = 1;
5236         set_pkt_forwarding_mode(res->mode);
5237 }
5238
5239 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5240         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5241                         set, "set");
5242 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5243         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5244                         fwd, "fwd");
5245 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5246         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5247                         mode,
5248                 "" /* defined at init */);
5249 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5251                         retry, "retry");
5252
5253 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5254         .f = cmd_set_fwd_retry_mode_parsed,
5255         .data = NULL,
5256         .help_str = NULL, /* defined at init */
5257         .tokens = {
5258                 (void *)&cmd_setfwd_retry_set,
5259                 (void *)&cmd_setfwd_retry_fwd,
5260                 (void *)&cmd_setfwd_retry_mode,
5261                 (void *)&cmd_setfwd_retry_retry,
5262                 NULL,
5263         },
5264 };
5265
5266 static void cmd_set_fwd_retry_mode_init(void)
5267 {
5268         char *modes, *c;
5269         static char token[128];
5270         static char help[256];
5271         cmdline_parse_token_string_t *token_struct;
5272
5273         modes = list_pkt_forwarding_retry_modes();
5274         snprintf(help, sizeof(help), "set fwd %s retry: "
5275                 "Set packet forwarding mode with retry", modes);
5276         cmd_set_fwd_retry_mode.help_str = help;
5277
5278         /* string token separator is # */
5279         for (c = token; *modes != '\0'; modes++)
5280                 if (*modes == '|')
5281                         *c++ = '#';
5282                 else
5283                         *c++ = *modes;
5284         token_struct = (cmdline_parse_token_string_t *)
5285                 cmd_set_fwd_retry_mode.tokens[2];
5286         token_struct->string_data.str = token;
5287 }
5288
5289 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5290 struct cmd_set_burst_tx_retry_result {
5291         cmdline_fixed_string_t set;
5292         cmdline_fixed_string_t burst;
5293         cmdline_fixed_string_t tx;
5294         cmdline_fixed_string_t delay;
5295         uint32_t time;
5296         cmdline_fixed_string_t retry;
5297         uint32_t retry_num;
5298 };
5299
5300 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5301                                         __attribute__((unused)) struct cmdline *cl,
5302                                         __attribute__((unused)) void *data)
5303 {
5304         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5305
5306         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5307                 && !strcmp(res->tx, "tx")) {
5308                 if (!strcmp(res->delay, "delay"))
5309                         burst_tx_delay_time = res->time;
5310                 if (!strcmp(res->retry, "retry"))
5311                         burst_tx_retry_num = res->retry_num;
5312         }
5313
5314 }
5315
5316 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5317         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5318 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5319         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5320                                  "burst");
5321 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5322         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5323 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5324         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5325 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5326         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5327 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5328         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5329 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5330         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5331
5332 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5333         .f = cmd_set_burst_tx_retry_parsed,
5334         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5335         .tokens = {
5336                 (void *)&cmd_set_burst_tx_retry_set,
5337                 (void *)&cmd_set_burst_tx_retry_burst,
5338                 (void *)&cmd_set_burst_tx_retry_tx,
5339                 (void *)&cmd_set_burst_tx_retry_delay,
5340                 (void *)&cmd_set_burst_tx_retry_time,
5341                 (void *)&cmd_set_burst_tx_retry_retry,
5342                 (void *)&cmd_set_burst_tx_retry_retry_num,
5343                 NULL,
5344         },
5345 };
5346
5347 /* *** SET PROMISC MODE *** */
5348 struct cmd_set_promisc_mode_result {
5349         cmdline_fixed_string_t set;
5350         cmdline_fixed_string_t promisc;
5351         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5352         uint8_t port_num;                /* valid if "allports" argument == 0 */
5353         cmdline_fixed_string_t mode;
5354 };
5355
5356 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5357                                         __attribute__((unused)) struct cmdline *cl,
5358                                         void *allports)
5359 {
5360         struct cmd_set_promisc_mode_result *res = parsed_result;
5361         int enable;
5362         portid_t i;
5363
5364         if (!strcmp(res->mode, "on"))
5365                 enable = 1;
5366         else
5367                 enable = 0;
5368
5369         /* all ports */
5370         if (allports) {
5371                 RTE_ETH_FOREACH_DEV(i) {
5372                         if (enable)
5373                                 rte_eth_promiscuous_enable(i);
5374                         else
5375                                 rte_eth_promiscuous_disable(i);
5376                 }
5377         }
5378         else {
5379                 if (enable)
5380                         rte_eth_promiscuous_enable(res->port_num);
5381                 else
5382                         rte_eth_promiscuous_disable(res->port_num);
5383         }
5384 }
5385
5386 cmdline_parse_token_string_t cmd_setpromisc_set =
5387         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5388 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5389         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5390                                  "promisc");
5391 cmdline_parse_token_string_t cmd_setpromisc_portall =
5392         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5393                                  "all");
5394 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5395         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5396                               UINT8);
5397 cmdline_parse_token_string_t cmd_setpromisc_mode =
5398         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5399                                  "on#off");
5400
5401 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5402         .f = cmd_set_promisc_mode_parsed,
5403         .data = (void *)1,
5404         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5405         .tokens = {
5406                 (void *)&cmd_setpromisc_set,
5407                 (void *)&cmd_setpromisc_promisc,
5408                 (void *)&cmd_setpromisc_portall,
5409                 (void *)&cmd_setpromisc_mode,
5410                 NULL,
5411         },
5412 };
5413
5414 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5415         .f = cmd_set_promisc_mode_parsed,
5416         .data = (void *)0,
5417         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5418         .tokens = {
5419                 (void *)&cmd_setpromisc_set,
5420                 (void *)&cmd_setpromisc_promisc,
5421                 (void *)&cmd_setpromisc_portnum,
5422                 (void *)&cmd_setpromisc_mode,
5423                 NULL,
5424         },
5425 };
5426
5427 /* *** SET ALLMULTI MODE *** */
5428 struct cmd_set_allmulti_mode_result {
5429         cmdline_fixed_string_t set;
5430         cmdline_fixed_string_t allmulti;
5431         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5432         uint8_t port_num;                /* valid if "allports" argument == 0 */
5433         cmdline_fixed_string_t mode;
5434 };
5435
5436 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5437                                         __attribute__((unused)) struct cmdline *cl,
5438                                         void *allports)
5439 {
5440         struct cmd_set_allmulti_mode_result *res = parsed_result;
5441         int enable;
5442         portid_t i;
5443
5444         if (!strcmp(res->mode, "on"))
5445                 enable = 1;
5446         else
5447                 enable = 0;
5448
5449         /* all ports */
5450         if (allports) {
5451                 RTE_ETH_FOREACH_DEV(i) {
5452                         if (enable)
5453                                 rte_eth_allmulticast_enable(i);
5454                         else
5455                                 rte_eth_allmulticast_disable(i);
5456                 }
5457         }
5458         else {
5459                 if (enable)
5460                         rte_eth_allmulticast_enable(res->port_num);
5461                 else
5462                         rte_eth_allmulticast_disable(res->port_num);
5463         }
5464 }
5465
5466 cmdline_parse_token_string_t cmd_setallmulti_set =
5467         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5468 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5469         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5470                                  "allmulti");
5471 cmdline_parse_token_string_t cmd_setallmulti_portall =
5472         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5473                                  "all");
5474 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5475         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5476                               UINT8);
5477 cmdline_parse_token_string_t cmd_setallmulti_mode =
5478         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5479                                  "on#off");
5480
5481 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5482         .f = cmd_set_allmulti_mode_parsed,
5483         .data = (void *)1,
5484         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5485         .tokens = {
5486                 (void *)&cmd_setallmulti_set,
5487                 (void *)&cmd_setallmulti_allmulti,
5488                 (void *)&cmd_setallmulti_portall,
5489                 (void *)&cmd_setallmulti_mode,
5490                 NULL,
5491         },
5492 };
5493
5494 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5495         .f = cmd_set_allmulti_mode_parsed,
5496         .data = (void *)0,
5497         .help_str = "set allmulti <port_id> on|off: "
5498                 "Set allmulti mode on port_id",
5499         .tokens = {
5500                 (void *)&cmd_setallmulti_set,
5501                 (void *)&cmd_setallmulti_allmulti,
5502                 (void *)&cmd_setallmulti_portnum,
5503                 (void *)&cmd_setallmulti_mode,
5504                 NULL,
5505         },
5506 };
5507
5508 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5509 struct cmd_link_flow_ctrl_set_result {
5510         cmdline_fixed_string_t set;
5511         cmdline_fixed_string_t flow_ctrl;
5512         cmdline_fixed_string_t rx;
5513         cmdline_fixed_string_t rx_lfc_mode;
5514         cmdline_fixed_string_t tx;
5515         cmdline_fixed_string_t tx_lfc_mode;
5516         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5517         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5518         cmdline_fixed_string_t autoneg_str;
5519         cmdline_fixed_string_t autoneg;
5520         cmdline_fixed_string_t hw_str;
5521         uint32_t high_water;
5522         cmdline_fixed_string_t lw_str;
5523         uint32_t low_water;
5524         cmdline_fixed_string_t pt_str;
5525         uint16_t pause_time;
5526         cmdline_fixed_string_t xon_str;
5527         uint16_t send_xon;
5528         uint8_t  port_id;
5529 };
5530
5531 cmdline_parse_token_string_t cmd_lfc_set_set =
5532         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5533                                 set, "set");
5534 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5535         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5536                                 flow_ctrl, "flow_ctrl");
5537 cmdline_parse_token_string_t cmd_lfc_set_rx =
5538         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5539                                 rx, "rx");
5540 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5541         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5542                                 rx_lfc_mode, "on#off");
5543 cmdline_parse_token_string_t cmd_lfc_set_tx =
5544         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5545                                 tx, "tx");
5546 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5547         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5548                                 tx_lfc_mode, "on#off");
5549 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5550         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5551                                 hw_str, "high_water");
5552 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5553         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5554                                 high_water, UINT32);
5555 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5556         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5557                                 lw_str, "low_water");
5558 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5559         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5560                                 low_water, UINT32);
5561 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5562         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5563                                 pt_str, "pause_time");
5564 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5565         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5566                                 pause_time, UINT16);
5567 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5568         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5569                                 xon_str, "send_xon");
5570 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5571         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5572                                 send_xon, UINT16);
5573 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5574         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5575                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5576 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5577         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5578                                 mac_ctrl_frame_fwd_mode, "on#off");
5579 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5580         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5581                                 autoneg_str, "autoneg");
5582 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5583         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5584                                 autoneg, "on#off");
5585 cmdline_parse_token_num_t cmd_lfc_set_portid =
5586         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5587                                 port_id, UINT8);
5588
5589 /* forward declaration */
5590 static void
5591 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5592                               void *data);
5593
5594 cmdline_parse_inst_t cmd_link_flow_control_set = {
5595         .f = cmd_link_flow_ctrl_set_parsed,
5596         .data = NULL,
5597         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5598                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5599                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5600         .tokens = {
5601                 (void *)&cmd_lfc_set_set,
5602                 (void *)&cmd_lfc_set_flow_ctrl,
5603                 (void *)&cmd_lfc_set_rx,
5604                 (void *)&cmd_lfc_set_rx_mode,
5605                 (void *)&cmd_lfc_set_tx,
5606                 (void *)&cmd_lfc_set_tx_mode,
5607                 (void *)&cmd_lfc_set_high_water,
5608                 (void *)&cmd_lfc_set_low_water,
5609                 (void *)&cmd_lfc_set_pause_time,
5610                 (void *)&cmd_lfc_set_send_xon,
5611                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5612                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5613                 (void *)&cmd_lfc_set_autoneg_str,
5614                 (void *)&cmd_lfc_set_autoneg,
5615                 (void *)&cmd_lfc_set_portid,
5616                 NULL,
5617         },
5618 };
5619
5620 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5621         .f = cmd_link_flow_ctrl_set_parsed,
5622         .data = (void *)&cmd_link_flow_control_set_rx,
5623         .help_str = "set flow_ctrl rx on|off <port_id>: "
5624                 "Change rx flow control parameter",
5625         .tokens = {
5626                 (void *)&cmd_lfc_set_set,
5627                 (void *)&cmd_lfc_set_flow_ctrl,
5628                 (void *)&cmd_lfc_set_rx,
5629                 (void *)&cmd_lfc_set_rx_mode,
5630                 (void *)&cmd_lfc_set_portid,
5631                 NULL,
5632         },
5633 };
5634
5635 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5636         .f = cmd_link_flow_ctrl_set_parsed,
5637         .data = (void *)&cmd_link_flow_control_set_tx,
5638         .help_str = "set flow_ctrl tx on|off <port_id>: "
5639                 "Change tx flow control parameter",
5640         .tokens = {
5641                 (void *)&cmd_lfc_set_set,
5642                 (void *)&cmd_lfc_set_flow_ctrl,
5643                 (void *)&cmd_lfc_set_tx,
5644                 (void *)&cmd_lfc_set_tx_mode,
5645                 (void *)&cmd_lfc_set_portid,
5646                 NULL,
5647         },
5648 };
5649
5650 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5651         .f = cmd_link_flow_ctrl_set_parsed,
5652         .data = (void *)&cmd_link_flow_control_set_hw,
5653         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5654                 "Change high water flow control parameter",
5655         .tokens = {
5656                 (void *)&cmd_lfc_set_set,
5657                 (void *)&cmd_lfc_set_flow_ctrl,
5658                 (void *)&cmd_lfc_set_high_water_str,
5659                 (void *)&cmd_lfc_set_high_water,
5660                 (void *)&cmd_lfc_set_portid,
5661                 NULL,
5662         },
5663 };
5664
5665 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5666         .f = cmd_link_flow_ctrl_set_parsed,
5667         .data = (void *)&cmd_link_flow_control_set_lw,
5668         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5669                 "Change low water flow control parameter",
5670         .tokens = {
5671                 (void *)&cmd_lfc_set_set,
5672                 (void *)&cmd_lfc_set_flow_ctrl,
5673                 (void *)&cmd_lfc_set_low_water_str,
5674                 (void *)&cmd_lfc_set_low_water,
5675                 (void *)&cmd_lfc_set_portid,
5676                 NULL,
5677         },
5678 };
5679
5680 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5681         .f = cmd_link_flow_ctrl_set_parsed,
5682         .data = (void *)&cmd_link_flow_control_set_pt,
5683         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5684                 "Change pause time flow control parameter",
5685         .tokens = {
5686                 (void *)&cmd_lfc_set_set,
5687                 (void *)&cmd_lfc_set_flow_ctrl,
5688                 (void *)&cmd_lfc_set_pause_time_str,
5689                 (void *)&cmd_lfc_set_pause_time,
5690                 (void *)&cmd_lfc_set_portid,
5691                 NULL,
5692         },
5693 };
5694
5695 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5696         .f = cmd_link_flow_ctrl_set_parsed,
5697         .data = (void *)&cmd_link_flow_control_set_xon,
5698         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5699                 "Change send_xon flow control parameter",
5700         .tokens = {
5701                 (void *)&cmd_lfc_set_set,
5702                 (void *)&cmd_lfc_set_flow_ctrl,
5703                 (void *)&cmd_lfc_set_send_xon_str,
5704                 (void *)&cmd_lfc_set_send_xon,
5705                 (void *)&cmd_lfc_set_portid,
5706                 NULL,
5707         },
5708 };
5709
5710 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5711         .f = cmd_link_flow_ctrl_set_parsed,
5712         .data = (void *)&cmd_link_flow_control_set_macfwd,
5713         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5714                 "Change mac ctrl fwd flow control parameter",
5715         .tokens = {
5716                 (void *)&cmd_lfc_set_set,
5717                 (void *)&cmd_lfc_set_flow_ctrl,
5718                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5719                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5720                 (void *)&cmd_lfc_set_portid,
5721                 NULL,
5722         },
5723 };
5724
5725 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5726         .f = cmd_link_flow_ctrl_set_parsed,
5727         .data = (void *)&cmd_link_flow_control_set_autoneg,
5728         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5729                 "Change autoneg flow control parameter",
5730         .tokens = {
5731                 (void *)&cmd_lfc_set_set,
5732                 (void *)&cmd_lfc_set_flow_ctrl,
5733                 (void *)&cmd_lfc_set_autoneg_str,
5734                 (void *)&cmd_lfc_set_autoneg,
5735                 (void *)&cmd_lfc_set_portid,
5736                 NULL,
5737         },
5738 };
5739
5740 static void
5741 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5742                               __attribute__((unused)) struct cmdline *cl,
5743                               void *data)
5744 {
5745         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5746         cmdline_parse_inst_t *cmd = data;
5747         struct rte_eth_fc_conf fc_conf;
5748         int rx_fc_en = 0;
5749         int tx_fc_en = 0;
5750         int ret;
5751
5752         /*
5753          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5754          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5755          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5756          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5757          */
5758         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5759                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5760         };
5761
5762         /* Partial command line, retrieve current configuration */
5763         if (cmd) {
5764                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5765                 if (ret != 0) {
5766                         printf("cannot get current flow ctrl parameters, return"
5767                                "code = %d\n", ret);
5768                         return;
5769                 }
5770
5771                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5772                     (fc_conf.mode == RTE_FC_FULL))
5773                         rx_fc_en = 1;
5774                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5775                     (fc_conf.mode == RTE_FC_FULL))
5776                         tx_fc_en = 1;
5777         }
5778
5779         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5780                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5781
5782         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5783                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5784
5785         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5786
5787         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5788                 fc_conf.high_water = res->high_water;
5789
5790         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5791                 fc_conf.low_water = res->low_water;
5792
5793         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5794                 fc_conf.pause_time = res->pause_time;
5795
5796         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5797                 fc_conf.send_xon = res->send_xon;
5798
5799         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5800                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5801                         fc_conf.mac_ctrl_frame_fwd = 1;
5802                 else
5803                         fc_conf.mac_ctrl_frame_fwd = 0;
5804         }
5805
5806         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5807                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5808
5809         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5810         if (ret != 0)
5811                 printf("bad flow contrl parameter, return code = %d \n", ret);
5812 }
5813
5814 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5815 struct cmd_priority_flow_ctrl_set_result {
5816         cmdline_fixed_string_t set;
5817         cmdline_fixed_string_t pfc_ctrl;
5818         cmdline_fixed_string_t rx;
5819         cmdline_fixed_string_t rx_pfc_mode;
5820         cmdline_fixed_string_t tx;
5821         cmdline_fixed_string_t tx_pfc_mode;
5822         uint32_t high_water;
5823         uint32_t low_water;
5824         uint16_t pause_time;
5825         uint8_t  priority;
5826         uint8_t  port_id;
5827 };
5828
5829 static void
5830 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5831                        __attribute__((unused)) struct cmdline *cl,
5832                        __attribute__((unused)) void *data)
5833 {
5834         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5835         struct rte_eth_pfc_conf pfc_conf;
5836         int rx_fc_enable, tx_fc_enable;
5837         int ret;
5838
5839         /*
5840          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5841          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5842          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5843          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5844          */
5845         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5846                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5847         };
5848
5849         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5850         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5851         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5852         pfc_conf.fc.high_water = res->high_water;
5853         pfc_conf.fc.low_water  = res->low_water;
5854         pfc_conf.fc.pause_time = res->pause_time;
5855         pfc_conf.priority      = res->priority;
5856
5857         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5858         if (ret != 0)
5859                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5860 }
5861
5862 cmdline_parse_token_string_t cmd_pfc_set_set =
5863         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5864                                 set, "set");
5865 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5866         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5867                                 pfc_ctrl, "pfc_ctrl");
5868 cmdline_parse_token_string_t cmd_pfc_set_rx =
5869         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5870                                 rx, "rx");
5871 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5872         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5873                                 rx_pfc_mode, "on#off");
5874 cmdline_parse_token_string_t cmd_pfc_set_tx =
5875         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5876                                 tx, "tx");
5877 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5878         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5879                                 tx_pfc_mode, "on#off");
5880 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5881         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5882                                 high_water, UINT32);
5883 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5884         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5885                                 low_water, UINT32);
5886 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5887         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5888                                 pause_time, UINT16);
5889 cmdline_parse_token_num_t cmd_pfc_set_priority =
5890         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5891                                 priority, UINT8);
5892 cmdline_parse_token_num_t cmd_pfc_set_portid =
5893         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5894                                 port_id, UINT8);
5895
5896 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5897         .f = cmd_priority_flow_ctrl_set_parsed,
5898         .data = NULL,
5899         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5900                 "<pause_time> <priority> <port_id>: "
5901                 "Configure the Ethernet priority flow control",
5902         .tokens = {
5903                 (void *)&cmd_pfc_set_set,
5904                 (void *)&cmd_pfc_set_flow_ctrl,
5905                 (void *)&cmd_pfc_set_rx,
5906                 (void *)&cmd_pfc_set_rx_mode,
5907                 (void *)&cmd_pfc_set_tx,
5908                 (void *)&cmd_pfc_set_tx_mode,
5909                 (void *)&cmd_pfc_set_high_water,
5910                 (void *)&cmd_pfc_set_low_water,
5911                 (void *)&cmd_pfc_set_pause_time,
5912                 (void *)&cmd_pfc_set_priority,
5913                 (void *)&cmd_pfc_set_portid,
5914                 NULL,
5915         },
5916 };
5917
5918 /* *** RESET CONFIGURATION *** */
5919 struct cmd_reset_result {
5920         cmdline_fixed_string_t reset;
5921         cmdline_fixed_string_t def;
5922 };
5923
5924 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5925                              struct cmdline *cl,
5926                              __attribute__((unused)) void *data)
5927 {
5928         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5929         set_def_fwd_config();
5930 }
5931
5932 cmdline_parse_token_string_t cmd_reset_set =
5933         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5934 cmdline_parse_token_string_t cmd_reset_def =
5935         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5936                                  "default");
5937
5938 cmdline_parse_inst_t cmd_reset = {
5939         .f = cmd_reset_parsed,
5940         .data = NULL,
5941         .help_str = "set default: Reset default forwarding configuration",
5942         .tokens = {
5943                 (void *)&cmd_reset_set,
5944                 (void *)&cmd_reset_def,
5945                 NULL,
5946         },
5947 };
5948
5949 /* *** START FORWARDING *** */
5950 struct cmd_start_result {
5951         cmdline_fixed_string_t start;
5952 };
5953
5954 cmdline_parse_token_string_t cmd_start_start =
5955         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5956
5957 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5958                              __attribute__((unused)) struct cmdline *cl,
5959                              __attribute__((unused)) void *data)
5960 {
5961         start_packet_forwarding(0);
5962 }
5963
5964 cmdline_parse_inst_t cmd_start = {
5965         .f = cmd_start_parsed,
5966         .data = NULL,
5967         .help_str = "start: Start packet forwarding",
5968         .tokens = {
5969                 (void *)&cmd_start_start,
5970                 NULL,
5971         },
5972 };
5973
5974 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5975 struct cmd_start_tx_first_result {
5976         cmdline_fixed_string_t start;
5977         cmdline_fixed_string_t tx_first;
5978 };
5979
5980 static void
5981 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5982                           __attribute__((unused)) struct cmdline *cl,
5983                           __attribute__((unused)) void *data)
5984 {
5985         start_packet_forwarding(1);
5986 }
5987
5988 cmdline_parse_token_string_t cmd_start_tx_first_start =
5989         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5990                                  "start");
5991 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5992         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5993                                  tx_first, "tx_first");
5994
5995 cmdline_parse_inst_t cmd_start_tx_first = {
5996         .f = cmd_start_tx_first_parsed,
5997         .data = NULL,
5998         .help_str = "start tx_first: Start packet forwarding, "
5999                 "after sending 1 burst of packets",
6000         .tokens = {
6001                 (void *)&cmd_start_tx_first_start,
6002                 (void *)&cmd_start_tx_first_tx_first,
6003                 NULL,
6004         },
6005 };
6006
6007 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6008 struct cmd_start_tx_first_n_result {
6009         cmdline_fixed_string_t start;
6010         cmdline_fixed_string_t tx_first;
6011         uint32_t tx_num;
6012 };
6013
6014 static void
6015 cmd_start_tx_first_n_parsed(void *parsed_result,
6016                           __attribute__((unused)) struct cmdline *cl,
6017                           __attribute__((unused)) void *data)
6018 {
6019         struct cmd_start_tx_first_n_result *res = parsed_result;
6020
6021         start_packet_forwarding(res->tx_num);
6022 }
6023
6024 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6025         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6026                         start, "start");
6027 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6028         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6029                         tx_first, "tx_first");
6030 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6031         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6032                         tx_num, UINT32);
6033
6034 cmdline_parse_inst_t cmd_start_tx_first_n = {
6035         .f = cmd_start_tx_first_n_parsed,
6036         .data = NULL,
6037         .help_str = "start tx_first <num>: "
6038                 "packet forwarding, after sending <num> bursts of packets",
6039         .tokens = {
6040                 (void *)&cmd_start_tx_first_n_start,
6041                 (void *)&cmd_start_tx_first_n_tx_first,
6042                 (void *)&cmd_start_tx_first_n_tx_num,
6043                 NULL,
6044         },
6045 };
6046
6047 /* *** SET LINK UP *** */
6048 struct cmd_set_link_up_result {
6049         cmdline_fixed_string_t set;
6050         cmdline_fixed_string_t link_up;
6051         cmdline_fixed_string_t port;
6052         uint8_t port_id;
6053 };
6054
6055 cmdline_parse_token_string_t cmd_set_link_up_set =
6056         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6057 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6058         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6059                                 "link-up");
6060 cmdline_parse_token_string_t cmd_set_link_up_port =
6061         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6062 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6063         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6064
6065 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6066                              __attribute__((unused)) struct cmdline *cl,
6067                              __attribute__((unused)) void *data)
6068 {
6069         struct cmd_set_link_up_result *res = parsed_result;
6070         dev_set_link_up(res->port_id);
6071 }
6072
6073 cmdline_parse_inst_t cmd_set_link_up = {
6074         .f = cmd_set_link_up_parsed,
6075         .data = NULL,
6076         .help_str = "set link-up port <port id>",
6077         .tokens = {
6078                 (void *)&cmd_set_link_up_set,
6079                 (void *)&cmd_set_link_up_link_up,
6080                 (void *)&cmd_set_link_up_port,
6081                 (void *)&cmd_set_link_up_port_id,
6082                 NULL,
6083         },
6084 };
6085
6086 /* *** SET LINK DOWN *** */
6087 struct cmd_set_link_down_result {
6088         cmdline_fixed_string_t set;
6089         cmdline_fixed_string_t link_down;
6090         cmdline_fixed_string_t port;
6091         uint8_t port_id;
6092 };
6093
6094 cmdline_parse_token_string_t cmd_set_link_down_set =
6095         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6096 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6097         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6098                                 "link-down");
6099 cmdline_parse_token_string_t cmd_set_link_down_port =
6100         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6101 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6102         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6103
6104 static void cmd_set_link_down_parsed(
6105                                 __attribute__((unused)) void *parsed_result,
6106                                 __attribute__((unused)) struct cmdline *cl,
6107                                 __attribute__((unused)) void *data)
6108 {
6109         struct cmd_set_link_down_result *res = parsed_result;
6110         dev_set_link_down(res->port_id);
6111 }
6112
6113 cmdline_parse_inst_t cmd_set_link_down = {
6114         .f = cmd_set_link_down_parsed,
6115         .data = NULL,
6116         .help_str = "set link-down port <port id>",
6117         .tokens = {
6118                 (void *)&cmd_set_link_down_set,
6119                 (void *)&cmd_set_link_down_link_down,
6120                 (void *)&cmd_set_link_down_port,
6121                 (void *)&cmd_set_link_down_port_id,
6122                 NULL,
6123         },
6124 };
6125
6126 /* *** SHOW CFG *** */
6127 struct cmd_showcfg_result {
6128         cmdline_fixed_string_t show;
6129         cmdline_fixed_string_t cfg;
6130         cmdline_fixed_string_t what;
6131 };
6132
6133 static void cmd_showcfg_parsed(void *parsed_result,
6134                                __attribute__((unused)) struct cmdline *cl,
6135                                __attribute__((unused)) void *data)
6136 {
6137         struct cmd_showcfg_result *res = parsed_result;
6138         if (!strcmp(res->what, "rxtx"))
6139                 rxtx_config_display();
6140         else if (!strcmp(res->what, "cores"))
6141                 fwd_lcores_config_display();
6142         else if (!strcmp(res->what, "fwd"))
6143                 pkt_fwd_config_display(&cur_fwd_config);
6144         else if (!strcmp(res->what, "txpkts"))
6145                 show_tx_pkt_segments();
6146 }
6147
6148 cmdline_parse_token_string_t cmd_showcfg_show =
6149         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6150 cmdline_parse_token_string_t cmd_showcfg_port =
6151         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6152 cmdline_parse_token_string_t cmd_showcfg_what =
6153         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6154                                  "rxtx#cores#fwd#txpkts");
6155
6156 cmdline_parse_inst_t cmd_showcfg = {
6157         .f = cmd_showcfg_parsed,
6158         .data = NULL,
6159         .help_str = "show config rxtx|cores|fwd|txpkts",
6160         .tokens = {
6161                 (void *)&cmd_showcfg_show,
6162                 (void *)&cmd_showcfg_port,
6163                 (void *)&cmd_showcfg_what,
6164                 NULL,
6165         },
6166 };
6167
6168 /* *** SHOW ALL PORT INFO *** */
6169 struct cmd_showportall_result {
6170         cmdline_fixed_string_t show;
6171         cmdline_fixed_string_t port;
6172         cmdline_fixed_string_t what;
6173         cmdline_fixed_string_t all;
6174 };
6175
6176 static void cmd_showportall_parsed(void *parsed_result,
6177                                 __attribute__((unused)) struct cmdline *cl,
6178                                 __attribute__((unused)) void *data)
6179 {
6180         portid_t i;
6181
6182         struct cmd_showportall_result *res = parsed_result;
6183         if (!strcmp(res->show, "clear")) {
6184                 if (!strcmp(res->what, "stats"))
6185                         RTE_ETH_FOREACH_DEV(i)
6186                                 nic_stats_clear(i);
6187                 else if (!strcmp(res->what, "xstats"))
6188                         RTE_ETH_FOREACH_DEV(i)
6189                                 nic_xstats_clear(i);
6190         } else if (!strcmp(res->what, "info"))
6191                 RTE_ETH_FOREACH_DEV(i)
6192                         port_infos_display(i);
6193         else if (!strcmp(res->what, "stats"))
6194                 RTE_ETH_FOREACH_DEV(i)
6195                         nic_stats_display(i);
6196         else if (!strcmp(res->what, "xstats"))
6197                 RTE_ETH_FOREACH_DEV(i)
6198                         nic_xstats_display(i);
6199         else if (!strcmp(res->what, "fdir"))
6200                 RTE_ETH_FOREACH_DEV(i)
6201                         fdir_get_infos(i);
6202         else if (!strcmp(res->what, "stat_qmap"))
6203                 RTE_ETH_FOREACH_DEV(i)
6204                         nic_stats_mapping_display(i);
6205         else if (!strcmp(res->what, "dcb_tc"))
6206                 RTE_ETH_FOREACH_DEV(i)
6207                         port_dcb_info_display(i);
6208         else if (!strcmp(res->what, "cap"))
6209                 RTE_ETH_FOREACH_DEV(i)
6210                         port_offload_cap_display(i);
6211 }
6212
6213 cmdline_parse_token_string_t cmd_showportall_show =
6214         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6215                                  "show#clear");
6216 cmdline_parse_token_string_t cmd_showportall_port =
6217         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6218 cmdline_parse_token_string_t cmd_showportall_what =
6219         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6220                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6221 cmdline_parse_token_string_t cmd_showportall_all =
6222         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6223 cmdline_parse_inst_t cmd_showportall = {
6224         .f = cmd_showportall_parsed,
6225         .data = NULL,
6226         .help_str = "show|clear port "
6227                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6228         .tokens = {
6229                 (void *)&cmd_showportall_show,
6230                 (void *)&cmd_showportall_port,
6231                 (void *)&cmd_showportall_what,
6232                 (void *)&cmd_showportall_all,
6233                 NULL,
6234         },
6235 };
6236
6237 /* *** SHOW PORT INFO *** */
6238 struct cmd_showport_result {
6239         cmdline_fixed_string_t show;
6240         cmdline_fixed_string_t port;
6241         cmdline_fixed_string_t what;
6242         uint8_t portnum;
6243 };
6244
6245 static void cmd_showport_parsed(void *parsed_result,
6246                                 __attribute__((unused)) struct cmdline *cl,
6247                                 __attribute__((unused)) void *data)
6248 {
6249         struct cmd_showport_result *res = parsed_result;
6250         if (!strcmp(res->show, "clear")) {
6251                 if (!strcmp(res->what, "stats"))
6252                         nic_stats_clear(res->portnum);
6253                 else if (!strcmp(res->what, "xstats"))
6254                         nic_xstats_clear(res->portnum);
6255         } else if (!strcmp(res->what, "info"))
6256                 port_infos_display(res->portnum);
6257         else if (!strcmp(res->what, "stats"))
6258                 nic_stats_display(res->portnum);
6259         else if (!strcmp(res->what, "xstats"))
6260                 nic_xstats_display(res->portnum);
6261         else if (!strcmp(res->what, "fdir"))
6262                  fdir_get_infos(res->portnum);
6263         else if (!strcmp(res->what, "stat_qmap"))
6264                 nic_stats_mapping_display(res->portnum);
6265         else if (!strcmp(res->what, "dcb_tc"))
6266                 port_dcb_info_display(res->portnum);
6267         else if (!strcmp(res->what, "cap"))
6268                 port_offload_cap_display(res->portnum);
6269 }
6270
6271 cmdline_parse_token_string_t cmd_showport_show =
6272         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6273                                  "show#clear");
6274 cmdline_parse_token_string_t cmd_showport_port =
6275         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6276 cmdline_parse_token_string_t cmd_showport_what =
6277         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6278                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6279 cmdline_parse_token_num_t cmd_showport_portnum =
6280         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6281
6282 cmdline_parse_inst_t cmd_showport = {
6283         .f = cmd_showport_parsed,
6284         .data = NULL,
6285         .help_str = "show|clear port "
6286                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6287                 "<port_id>",
6288         .tokens = {
6289                 (void *)&cmd_showport_show,
6290                 (void *)&cmd_showport_port,
6291                 (void *)&cmd_showport_what,
6292                 (void *)&cmd_showport_portnum,
6293                 NULL,
6294         },
6295 };
6296
6297 /* *** SHOW QUEUE INFO *** */
6298 struct cmd_showqueue_result {
6299         cmdline_fixed_string_t show;
6300         cmdline_fixed_string_t type;
6301         cmdline_fixed_string_t what;
6302         uint8_t portnum;
6303         uint16_t queuenum;
6304 };
6305
6306 static void
6307 cmd_showqueue_parsed(void *parsed_result,
6308         __attribute__((unused)) struct cmdline *cl,
6309         __attribute__((unused)) void *data)
6310 {
6311         struct cmd_showqueue_result *res = parsed_result;
6312
6313         if (!strcmp(res->type, "rxq"))
6314                 rx_queue_infos_display(res->portnum, res->queuenum);
6315         else if (!strcmp(res->type, "txq"))
6316                 tx_queue_infos_display(res->portnum, res->queuenum);
6317 }
6318
6319 cmdline_parse_token_string_t cmd_showqueue_show =
6320         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6321 cmdline_parse_token_string_t cmd_showqueue_type =
6322         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6323 cmdline_parse_token_string_t cmd_showqueue_what =
6324         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6325 cmdline_parse_token_num_t cmd_showqueue_portnum =
6326         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6327 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6328         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6329
6330 cmdline_parse_inst_t cmd_showqueue = {
6331         .f = cmd_showqueue_parsed,
6332         .data = NULL,
6333         .help_str = "show rxq|txq info <port_id> <queue_id>",
6334         .tokens = {
6335                 (void *)&cmd_showqueue_show,
6336                 (void *)&cmd_showqueue_type,
6337                 (void *)&cmd_showqueue_what,
6338                 (void *)&cmd_showqueue_portnum,
6339                 (void *)&cmd_showqueue_queuenum,
6340                 NULL,
6341         },
6342 };
6343
6344 /* *** READ PORT REGISTER *** */
6345 struct cmd_read_reg_result {
6346         cmdline_fixed_string_t read;
6347         cmdline_fixed_string_t reg;
6348         uint8_t port_id;
6349         uint32_t reg_off;
6350 };
6351
6352 static void
6353 cmd_read_reg_parsed(void *parsed_result,
6354                     __attribute__((unused)) struct cmdline *cl,
6355                     __attribute__((unused)) void *data)
6356 {
6357         struct cmd_read_reg_result *res = parsed_result;
6358         port_reg_display(res->port_id, res->reg_off);
6359 }
6360
6361 cmdline_parse_token_string_t cmd_read_reg_read =
6362         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6363 cmdline_parse_token_string_t cmd_read_reg_reg =
6364         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6365 cmdline_parse_token_num_t cmd_read_reg_port_id =
6366         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6367 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6368         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6369
6370 cmdline_parse_inst_t cmd_read_reg = {
6371         .f = cmd_read_reg_parsed,
6372         .data = NULL,
6373         .help_str = "read reg <port_id> <reg_off>",
6374         .tokens = {
6375                 (void *)&cmd_read_reg_read,
6376                 (void *)&cmd_read_reg_reg,
6377                 (void *)&cmd_read_reg_port_id,
6378                 (void *)&cmd_read_reg_reg_off,
6379                 NULL,
6380         },
6381 };
6382
6383 /* *** READ PORT REGISTER BIT FIELD *** */
6384 struct cmd_read_reg_bit_field_result {
6385         cmdline_fixed_string_t read;
6386         cmdline_fixed_string_t regfield;
6387         uint8_t port_id;
6388         uint32_t reg_off;
6389         uint8_t bit1_pos;
6390         uint8_t bit2_pos;
6391 };
6392
6393 static void
6394 cmd_read_reg_bit_field_parsed(void *parsed_result,
6395                               __attribute__((unused)) struct cmdline *cl,
6396                               __attribute__((unused)) void *data)
6397 {
6398         struct cmd_read_reg_bit_field_result *res = parsed_result;
6399         port_reg_bit_field_display(res->port_id, res->reg_off,
6400                                    res->bit1_pos, res->bit2_pos);
6401 }
6402
6403 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6404         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6405                                  "read");
6406 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6407         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6408                                  regfield, "regfield");
6409 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6410         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6411                               UINT8);
6412 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6413         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6414                               UINT32);
6415 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6416         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6417                               UINT8);
6418 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6419         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6420                               UINT8);
6421
6422 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6423         .f = cmd_read_reg_bit_field_parsed,
6424         .data = NULL,
6425         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6426         "Read register bit field between bit_x and bit_y included",
6427         .tokens = {
6428                 (void *)&cmd_read_reg_bit_field_read,
6429                 (void *)&cmd_read_reg_bit_field_regfield,
6430                 (void *)&cmd_read_reg_bit_field_port_id,
6431                 (void *)&cmd_read_reg_bit_field_reg_off,
6432                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6433                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6434                 NULL,
6435         },
6436 };
6437
6438 /* *** READ PORT REGISTER BIT *** */
6439 struct cmd_read_reg_bit_result {
6440         cmdline_fixed_string_t read;
6441         cmdline_fixed_string_t regbit;
6442         uint8_t port_id;
6443         uint32_t reg_off;
6444         uint8_t bit_pos;
6445 };
6446
6447 static void
6448 cmd_read_reg_bit_parsed(void *parsed_result,
6449                         __attribute__((unused)) struct cmdline *cl,
6450                         __attribute__((unused)) void *data)
6451 {
6452         struct cmd_read_reg_bit_result *res = parsed_result;
6453         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6454 }
6455
6456 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6457         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6458 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6459         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6460                                  regbit, "regbit");
6461 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6462         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6463 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6464         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6465 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6466         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6467
6468 cmdline_parse_inst_t cmd_read_reg_bit = {
6469         .f = cmd_read_reg_bit_parsed,
6470         .data = NULL,
6471         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6472         .tokens = {
6473                 (void *)&cmd_read_reg_bit_read,
6474                 (void *)&cmd_read_reg_bit_regbit,
6475                 (void *)&cmd_read_reg_bit_port_id,
6476                 (void *)&cmd_read_reg_bit_reg_off,
6477                 (void *)&cmd_read_reg_bit_bit_pos,
6478                 NULL,
6479         },
6480 };
6481
6482 /* *** WRITE PORT REGISTER *** */
6483 struct cmd_write_reg_result {
6484         cmdline_fixed_string_t write;
6485         cmdline_fixed_string_t reg;
6486         uint8_t port_id;
6487         uint32_t reg_off;
6488         uint32_t value;
6489 };
6490
6491 static void
6492 cmd_write_reg_parsed(void *parsed_result,
6493                      __attribute__((unused)) struct cmdline *cl,
6494                      __attribute__((unused)) void *data)
6495 {
6496         struct cmd_write_reg_result *res = parsed_result;
6497         port_reg_set(res->port_id, res->reg_off, res->value);
6498 }
6499
6500 cmdline_parse_token_string_t cmd_write_reg_write =
6501         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6502 cmdline_parse_token_string_t cmd_write_reg_reg =
6503         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6504 cmdline_parse_token_num_t cmd_write_reg_port_id =
6505         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6506 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6507         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6508 cmdline_parse_token_num_t cmd_write_reg_value =
6509         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6510
6511 cmdline_parse_inst_t cmd_write_reg = {
6512         .f = cmd_write_reg_parsed,
6513         .data = NULL,
6514         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6515         .tokens = {
6516                 (void *)&cmd_write_reg_write,
6517                 (void *)&cmd_write_reg_reg,
6518                 (void *)&cmd_write_reg_port_id,
6519                 (void *)&cmd_write_reg_reg_off,
6520                 (void *)&cmd_write_reg_value,
6521                 NULL,
6522         },
6523 };
6524
6525 /* *** WRITE PORT REGISTER BIT FIELD *** */
6526 struct cmd_write_reg_bit_field_result {
6527         cmdline_fixed_string_t write;
6528         cmdline_fixed_string_t regfield;
6529         uint8_t port_id;
6530         uint32_t reg_off;
6531         uint8_t bit1_pos;
6532         uint8_t bit2_pos;
6533         uint32_t value;
6534 };
6535
6536 static void
6537 cmd_write_reg_bit_field_parsed(void *parsed_result,
6538                                __attribute__((unused)) struct cmdline *cl,
6539                                __attribute__((unused)) void *data)
6540 {
6541         struct cmd_write_reg_bit_field_result *res = parsed_result;
6542         port_reg_bit_field_set(res->port_id, res->reg_off,
6543                           res->bit1_pos, res->bit2_pos, res->value);
6544 }
6545
6546 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6547         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6548                                  "write");
6549 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6550         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6551                                  regfield, "regfield");
6552 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6553         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6554                               UINT8);
6555 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6556         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6557                               UINT32);
6558 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6559         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6560                               UINT8);
6561 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6562         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6563                               UINT8);
6564 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6565         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6566                               UINT32);
6567
6568 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6569         .f = cmd_write_reg_bit_field_parsed,
6570         .data = NULL,
6571         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6572                 "<reg_value>: "
6573                 "Set register bit field between bit_x and bit_y included",
6574         .tokens = {
6575                 (void *)&cmd_write_reg_bit_field_write,
6576                 (void *)&cmd_write_reg_bit_field_regfield,
6577                 (void *)&cmd_write_reg_bit_field_port_id,
6578                 (void *)&cmd_write_reg_bit_field_reg_off,
6579                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6580                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6581                 (void *)&cmd_write_reg_bit_field_value,
6582                 NULL,
6583         },
6584 };
6585
6586 /* *** WRITE PORT REGISTER BIT *** */
6587 struct cmd_write_reg_bit_result {
6588         cmdline_fixed_string_t write;
6589         cmdline_fixed_string_t regbit;
6590         uint8_t port_id;
6591         uint32_t reg_off;
6592         uint8_t bit_pos;
6593         uint8_t value;
6594 };
6595
6596 static void
6597 cmd_write_reg_bit_parsed(void *parsed_result,
6598                          __attribute__((unused)) struct cmdline *cl,
6599                          __attribute__((unused)) void *data)
6600 {
6601         struct cmd_write_reg_bit_result *res = parsed_result;
6602         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6603 }
6604
6605 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6606         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6607                                  "write");
6608 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6609         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6610                                  regbit, "regbit");
6611 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6612         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6613 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6614         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6615 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6616         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6617 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6618         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6619
6620 cmdline_parse_inst_t cmd_write_reg_bit = {
6621         .f = cmd_write_reg_bit_parsed,
6622         .data = NULL,
6623         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6624                 "0 <= bit_x <= 31",
6625         .tokens = {
6626                 (void *)&cmd_write_reg_bit_write,
6627                 (void *)&cmd_write_reg_bit_regbit,
6628                 (void *)&cmd_write_reg_bit_port_id,
6629                 (void *)&cmd_write_reg_bit_reg_off,
6630                 (void *)&cmd_write_reg_bit_bit_pos,
6631                 (void *)&cmd_write_reg_bit_value,
6632                 NULL,
6633         },
6634 };
6635
6636 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6637 struct cmd_read_rxd_txd_result {
6638         cmdline_fixed_string_t read;
6639         cmdline_fixed_string_t rxd_txd;
6640         uint8_t port_id;
6641         uint16_t queue_id;
6642         uint16_t desc_id;
6643 };
6644
6645 static void
6646 cmd_read_rxd_txd_parsed(void *parsed_result,
6647                         __attribute__((unused)) struct cmdline *cl,
6648                         __attribute__((unused)) void *data)
6649 {
6650         struct cmd_read_rxd_txd_result *res = parsed_result;
6651
6652         if (!strcmp(res->rxd_txd, "rxd"))
6653                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6654         else if (!strcmp(res->rxd_txd, "txd"))
6655                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6656 }
6657
6658 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6659         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6660 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6661         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6662                                  "rxd#txd");
6663 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6664         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6665 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6666         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6667 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6668         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6669
6670 cmdline_parse_inst_t cmd_read_rxd_txd = {
6671         .f = cmd_read_rxd_txd_parsed,
6672         .data = NULL,
6673         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6674         .tokens = {
6675                 (void *)&cmd_read_rxd_txd_read,
6676                 (void *)&cmd_read_rxd_txd_rxd_txd,
6677                 (void *)&cmd_read_rxd_txd_port_id,
6678                 (void *)&cmd_read_rxd_txd_queue_id,
6679                 (void *)&cmd_read_rxd_txd_desc_id,
6680                 NULL,
6681         },
6682 };
6683
6684 /* *** QUIT *** */
6685 struct cmd_quit_result {
6686         cmdline_fixed_string_t quit;
6687 };
6688
6689 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6690                             struct cmdline *cl,
6691                             __attribute__((unused)) void *data)
6692 {
6693         pmd_test_exit();
6694         cmdline_quit(cl);
6695 }
6696
6697 cmdline_parse_token_string_t cmd_quit_quit =
6698         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6699
6700 cmdline_parse_inst_t cmd_quit = {
6701         .f = cmd_quit_parsed,
6702         .data = NULL,
6703         .help_str = "quit: Exit application",
6704         .tokens = {
6705                 (void *)&cmd_quit_quit,
6706                 NULL,
6707         },
6708 };
6709
6710 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6711 struct cmd_mac_addr_result {
6712         cmdline_fixed_string_t mac_addr_cmd;
6713         cmdline_fixed_string_t what;
6714         uint8_t port_num;
6715         struct ether_addr address;
6716 };
6717
6718 static void cmd_mac_addr_parsed(void *parsed_result,
6719                 __attribute__((unused)) struct cmdline *cl,
6720                 __attribute__((unused)) void *data)
6721 {
6722         struct cmd_mac_addr_result *res = parsed_result;
6723         int ret;
6724
6725         if (strcmp(res->what, "add") == 0)
6726                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6727         else if (strcmp(res->what, "set") == 0)
6728                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6729                                                        &res->address);
6730         else
6731                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6732
6733         /* check the return value and print it if is < 0 */
6734         if(ret < 0)
6735                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6736
6737 }
6738
6739 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6740         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6741                                 "mac_addr");
6742 cmdline_parse_token_string_t cmd_mac_addr_what =
6743         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6744                                 "add#remove#set");
6745 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6746                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6747 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6748                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6749
6750 cmdline_parse_inst_t cmd_mac_addr = {
6751         .f = cmd_mac_addr_parsed,
6752         .data = (void *)0,
6753         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6754                         "Add/Remove/Set MAC address on port_id",
6755         .tokens = {
6756                 (void *)&cmd_mac_addr_cmd,
6757                 (void *)&cmd_mac_addr_what,
6758                 (void *)&cmd_mac_addr_portnum,
6759                 (void *)&cmd_mac_addr_addr,
6760                 NULL,
6761         },
6762 };
6763
6764
6765 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6766 struct cmd_set_qmap_result {
6767         cmdline_fixed_string_t set;
6768         cmdline_fixed_string_t qmap;
6769         cmdline_fixed_string_t what;
6770         uint8_t port_id;
6771         uint16_t queue_id;
6772         uint8_t map_value;
6773 };
6774
6775 static void
6776 cmd_set_qmap_parsed(void *parsed_result,
6777                        __attribute__((unused)) struct cmdline *cl,
6778                        __attribute__((unused)) void *data)
6779 {
6780         struct cmd_set_qmap_result *res = parsed_result;
6781         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6782
6783         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6784 }
6785
6786 cmdline_parse_token_string_t cmd_setqmap_set =
6787         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6788                                  set, "set");
6789 cmdline_parse_token_string_t cmd_setqmap_qmap =
6790         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6791                                  qmap, "stat_qmap");
6792 cmdline_parse_token_string_t cmd_setqmap_what =
6793         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6794                                  what, "tx#rx");
6795 cmdline_parse_token_num_t cmd_setqmap_portid =
6796         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6797                               port_id, UINT8);
6798 cmdline_parse_token_num_t cmd_setqmap_queueid =
6799         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6800                               queue_id, UINT16);
6801 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6802         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6803                               map_value, UINT8);
6804
6805 cmdline_parse_inst_t cmd_set_qmap = {
6806         .f = cmd_set_qmap_parsed,
6807         .data = NULL,
6808         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6809                 "Set statistics mapping value on tx|rx queue_id of port_id",
6810         .tokens = {
6811                 (void *)&cmd_setqmap_set,
6812                 (void *)&cmd_setqmap_qmap,
6813                 (void *)&cmd_setqmap_what,
6814                 (void *)&cmd_setqmap_portid,
6815                 (void *)&cmd_setqmap_queueid,
6816                 (void *)&cmd_setqmap_mapvalue,
6817                 NULL,
6818         },
6819 };
6820
6821 /* *** CONFIGURE UNICAST HASH TABLE *** */
6822 struct cmd_set_uc_hash_table {
6823         cmdline_fixed_string_t set;
6824         cmdline_fixed_string_t port;
6825         uint8_t port_id;
6826         cmdline_fixed_string_t what;
6827         struct ether_addr address;
6828         cmdline_fixed_string_t mode;
6829 };
6830
6831 static void
6832 cmd_set_uc_hash_parsed(void *parsed_result,
6833                        __attribute__((unused)) struct cmdline *cl,
6834                        __attribute__((unused)) void *data)
6835 {
6836         int ret=0;
6837         struct cmd_set_uc_hash_table *res = parsed_result;
6838
6839         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6840
6841         if (strcmp(res->what, "uta") == 0)
6842                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6843                                                 &res->address,(uint8_t)is_on);
6844         if (ret < 0)
6845                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6846
6847 }
6848
6849 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6850         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6851                                  set, "set");
6852 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6853         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6854                                  port, "port");
6855 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6856         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6857                               port_id, UINT8);
6858 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6859         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6860                                  what, "uta");
6861 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6862         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6863                                 address);
6864 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6865         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6866                                  mode, "on#off");
6867
6868 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6869         .f = cmd_set_uc_hash_parsed,
6870         .data = NULL,
6871         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6872         .tokens = {
6873                 (void *)&cmd_set_uc_hash_set,
6874                 (void *)&cmd_set_uc_hash_port,
6875                 (void *)&cmd_set_uc_hash_portid,
6876                 (void *)&cmd_set_uc_hash_what,
6877                 (void *)&cmd_set_uc_hash_mac,
6878                 (void *)&cmd_set_uc_hash_mode,
6879                 NULL,
6880         },
6881 };
6882
6883 struct cmd_set_uc_all_hash_table {
6884         cmdline_fixed_string_t set;
6885         cmdline_fixed_string_t port;
6886         uint8_t port_id;
6887         cmdline_fixed_string_t what;
6888         cmdline_fixed_string_t value;
6889         cmdline_fixed_string_t mode;
6890 };
6891
6892 static void
6893 cmd_set_uc_all_hash_parsed(void *parsed_result,
6894                        __attribute__((unused)) struct cmdline *cl,
6895                        __attribute__((unused)) void *data)
6896 {
6897         int ret=0;
6898         struct cmd_set_uc_all_hash_table *res = parsed_result;
6899
6900         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6901
6902         if ((strcmp(res->what, "uta") == 0) &&
6903                 (strcmp(res->value, "all") == 0))
6904                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6905         if (ret < 0)
6906                 printf("bad unicast hash table parameter,"
6907                         "return code = %d \n", ret);
6908 }
6909
6910 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6911         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6912                                  set, "set");
6913 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6914         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6915                                  port, "port");
6916 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6917         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6918                               port_id, UINT8);
6919 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6920         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6921                                  what, "uta");
6922 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6923         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6924                                 value,"all");
6925 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6926         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6927                                  mode, "on#off");
6928
6929 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6930         .f = cmd_set_uc_all_hash_parsed,
6931         .data = NULL,
6932         .help_str = "set port <port_id> uta all on|off",
6933         .tokens = {
6934                 (void *)&cmd_set_uc_all_hash_set,
6935                 (void *)&cmd_set_uc_all_hash_port,
6936                 (void *)&cmd_set_uc_all_hash_portid,
6937                 (void *)&cmd_set_uc_all_hash_what,
6938                 (void *)&cmd_set_uc_all_hash_value,
6939                 (void *)&cmd_set_uc_all_hash_mode,
6940                 NULL,
6941         },
6942 };
6943
6944 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6945 struct cmd_set_vf_macvlan_filter {
6946         cmdline_fixed_string_t set;
6947         cmdline_fixed_string_t port;
6948         uint8_t port_id;
6949         cmdline_fixed_string_t vf;
6950         uint8_t vf_id;
6951         struct ether_addr address;
6952         cmdline_fixed_string_t filter_type;
6953         cmdline_fixed_string_t mode;
6954 };
6955
6956 static void
6957 cmd_set_vf_macvlan_parsed(void *parsed_result,
6958                        __attribute__((unused)) struct cmdline *cl,
6959                        __attribute__((unused)) void *data)
6960 {
6961         int is_on, ret = 0;
6962         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6963         struct rte_eth_mac_filter filter;
6964
6965         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6966
6967         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6968
6969         /* set VF MAC filter */
6970         filter.is_vf = 1;
6971
6972         /* set VF ID */
6973         filter.dst_id = res->vf_id;
6974
6975         if (!strcmp(res->filter_type, "exact-mac"))
6976                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6977         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6978                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6979         else if (!strcmp(res->filter_type, "hashmac"))
6980                 filter.filter_type = RTE_MAC_HASH_MATCH;
6981         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6982                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6983
6984         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6985
6986         if (is_on)
6987                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6988                                         RTE_ETH_FILTER_MACVLAN,
6989                                         RTE_ETH_FILTER_ADD,
6990                                          &filter);
6991         else
6992                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6993                                         RTE_ETH_FILTER_MACVLAN,
6994                                         RTE_ETH_FILTER_DELETE,
6995                                         &filter);
6996
6997         if (ret < 0)
6998                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6999
7000 }
7001
7002 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7003         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7004                                  set, "set");
7005 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7006         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7007                                  port, "port");
7008 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7009         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7010                               port_id, UINT8);
7011 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7012         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7013                                  vf, "vf");
7014 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7015         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7016                                 vf_id, UINT8);
7017 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7018         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7019                                 address);
7020 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7021         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7022                                 filter_type, "exact-mac#exact-mac-vlan"
7023                                 "#hashmac#hashmac-vlan");
7024 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7025         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7026                                  mode, "on#off");
7027
7028 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7029         .f = cmd_set_vf_macvlan_parsed,
7030         .data = NULL,
7031         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7032                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7033                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7034                 "hash match rule: hash match of MAC and exact match of VLAN",
7035         .tokens = {
7036                 (void *)&cmd_set_vf_macvlan_set,
7037                 (void *)&cmd_set_vf_macvlan_port,
7038                 (void *)&cmd_set_vf_macvlan_portid,
7039                 (void *)&cmd_set_vf_macvlan_vf,
7040                 (void *)&cmd_set_vf_macvlan_vf_id,
7041                 (void *)&cmd_set_vf_macvlan_mac,
7042                 (void *)&cmd_set_vf_macvlan_filter_type,
7043                 (void *)&cmd_set_vf_macvlan_mode,
7044                 NULL,
7045         },
7046 };
7047
7048 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7049 struct cmd_set_vf_traffic {
7050         cmdline_fixed_string_t set;
7051         cmdline_fixed_string_t port;
7052         uint8_t port_id;
7053         cmdline_fixed_string_t vf;
7054         uint8_t vf_id;
7055         cmdline_fixed_string_t what;
7056         cmdline_fixed_string_t mode;
7057 };
7058
7059 static void
7060 cmd_set_vf_traffic_parsed(void *parsed_result,
7061                        __attribute__((unused)) struct cmdline *cl,
7062                        __attribute__((unused)) void *data)
7063 {
7064         struct cmd_set_vf_traffic *res = parsed_result;
7065         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7066         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7067
7068         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7069 }
7070
7071 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7072         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7073                                  set, "set");
7074 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7075         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7076                                  port, "port");
7077 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7078         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7079                               port_id, UINT8);
7080 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7081         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7082                                  vf, "vf");
7083 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7084         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7085                               vf_id, UINT8);
7086 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7087         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7088                                  what, "tx#rx");
7089 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7090         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7091                                  mode, "on#off");
7092
7093 cmdline_parse_inst_t cmd_set_vf_traffic = {
7094         .f = cmd_set_vf_traffic_parsed,
7095         .data = NULL,
7096         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7097         .tokens = {
7098                 (void *)&cmd_setvf_traffic_set,
7099                 (void *)&cmd_setvf_traffic_port,
7100                 (void *)&cmd_setvf_traffic_portid,
7101                 (void *)&cmd_setvf_traffic_vf,
7102                 (void *)&cmd_setvf_traffic_vfid,
7103                 (void *)&cmd_setvf_traffic_what,
7104                 (void *)&cmd_setvf_traffic_mode,
7105                 NULL,
7106         },
7107 };
7108
7109 /* *** CONFIGURE VF RECEIVE MODE *** */
7110 struct cmd_set_vf_rxmode {
7111         cmdline_fixed_string_t set;
7112         cmdline_fixed_string_t port;
7113         uint8_t port_id;
7114         cmdline_fixed_string_t vf;
7115         uint8_t vf_id;
7116         cmdline_fixed_string_t what;
7117         cmdline_fixed_string_t mode;
7118         cmdline_fixed_string_t on;
7119 };
7120
7121 static void
7122 cmd_set_vf_rxmode_parsed(void *parsed_result,
7123                        __attribute__((unused)) struct cmdline *cl,
7124                        __attribute__((unused)) void *data)
7125 {
7126         int ret = -ENOTSUP;
7127         uint16_t rx_mode = 0;
7128         struct cmd_set_vf_rxmode *res = parsed_result;
7129
7130         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7131         if (!strcmp(res->what,"rxmode")) {
7132                 if (!strcmp(res->mode, "AUPE"))
7133                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7134                 else if (!strcmp(res->mode, "ROPE"))
7135                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7136                 else if (!strcmp(res->mode, "BAM"))
7137                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7138                 else if (!strncmp(res->mode, "MPE",3))
7139                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7140         }
7141
7142 #ifdef RTE_LIBRTE_IXGBE_PMD
7143         if (ret == -ENOTSUP)
7144                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7145                                                   rx_mode, (uint8_t)is_on);
7146 #endif
7147 #ifdef RTE_LIBRTE_BNXT_PMD
7148         if (ret == -ENOTSUP)
7149                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7150                                                  rx_mode, (uint8_t)is_on);
7151 #endif
7152         if (ret < 0)
7153                 printf("bad VF receive mode parameter, return code = %d \n",
7154                 ret);
7155 }
7156
7157 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7158         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7159                                  set, "set");
7160 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7161         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7162                                  port, "port");
7163 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7164         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7165                               port_id, UINT8);
7166 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7167         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7168                                  vf, "vf");
7169 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7170         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7171                               vf_id, UINT8);
7172 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7173         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7174                                  what, "rxmode");
7175 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7176         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7177                                  mode, "AUPE#ROPE#BAM#MPE");
7178 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7179         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7180                                  on, "on#off");
7181
7182 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7183         .f = cmd_set_vf_rxmode_parsed,
7184         .data = NULL,
7185         .help_str = "set port <port_id> vf <vf_id> rxmode "
7186                 "AUPE|ROPE|BAM|MPE on|off",
7187         .tokens = {
7188                 (void *)&cmd_set_vf_rxmode_set,
7189                 (void *)&cmd_set_vf_rxmode_port,
7190                 (void *)&cmd_set_vf_rxmode_portid,
7191                 (void *)&cmd_set_vf_rxmode_vf,
7192                 (void *)&cmd_set_vf_rxmode_vfid,
7193                 (void *)&cmd_set_vf_rxmode_what,
7194                 (void *)&cmd_set_vf_rxmode_mode,
7195                 (void *)&cmd_set_vf_rxmode_on,
7196                 NULL,
7197         },
7198 };
7199
7200 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7201 struct cmd_vf_mac_addr_result {
7202         cmdline_fixed_string_t mac_addr_cmd;
7203         cmdline_fixed_string_t what;
7204         cmdline_fixed_string_t port;
7205         uint8_t port_num;
7206         cmdline_fixed_string_t vf;
7207         uint8_t vf_num;
7208         struct ether_addr address;
7209 };
7210
7211 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7212                 __attribute__((unused)) struct cmdline *cl,
7213                 __attribute__((unused)) void *data)
7214 {
7215         struct cmd_vf_mac_addr_result *res = parsed_result;
7216         int ret = -ENOTSUP;
7217
7218         if (strcmp(res->what, "add") != 0)
7219                 return;
7220
7221 #ifdef RTE_LIBRTE_I40E_PMD
7222         if (ret == -ENOTSUP)
7223                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7224                                                    &res->address);
7225 #endif
7226 #ifdef RTE_LIBRTE_BNXT_PMD
7227         if (ret == -ENOTSUP)
7228                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7229                                                 res->vf_num);
7230 #endif
7231
7232         if(ret < 0)
7233                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7234
7235 }
7236
7237 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7238         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7239                                 mac_addr_cmd,"mac_addr");
7240 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7241         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7242                                 what,"add");
7243 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7244         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7245                                 port,"port");
7246 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7247         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7248                                 port_num, UINT8);
7249 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7250         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7251                                 vf,"vf");
7252 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7253         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7254                                 vf_num, UINT8);
7255 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7256         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7257                                 address);
7258
7259 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7260         .f = cmd_vf_mac_addr_parsed,
7261         .data = (void *)0,
7262         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7263                 "Add MAC address filtering for a VF on port_id",
7264         .tokens = {
7265                 (void *)&cmd_vf_mac_addr_cmd,
7266                 (void *)&cmd_vf_mac_addr_what,
7267                 (void *)&cmd_vf_mac_addr_port,
7268                 (void *)&cmd_vf_mac_addr_portnum,
7269                 (void *)&cmd_vf_mac_addr_vf,
7270                 (void *)&cmd_vf_mac_addr_vfnum,
7271                 (void *)&cmd_vf_mac_addr_addr,
7272                 NULL,
7273         },
7274 };
7275
7276 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7277 struct cmd_vf_rx_vlan_filter {
7278         cmdline_fixed_string_t rx_vlan;
7279         cmdline_fixed_string_t what;
7280         uint16_t vlan_id;
7281         cmdline_fixed_string_t port;
7282         uint8_t port_id;
7283         cmdline_fixed_string_t vf;
7284         uint64_t vf_mask;
7285 };
7286
7287 static void
7288 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7289                           __attribute__((unused)) struct cmdline *cl,
7290                           __attribute__((unused)) void *data)
7291 {
7292         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7293         int ret = -ENOTSUP;
7294
7295         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7296
7297 #ifdef RTE_LIBRTE_IXGBE_PMD
7298         if (ret == -ENOTSUP)
7299                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7300                                 res->vlan_id, res->vf_mask, is_add);
7301 #endif
7302 #ifdef RTE_LIBRTE_I40E_PMD
7303         if (ret == -ENOTSUP)
7304                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7305                                 res->vlan_id, res->vf_mask, is_add);
7306 #endif
7307 #ifdef RTE_LIBRTE_BNXT_PMD
7308         if (ret == -ENOTSUP)
7309                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7310                                 res->vlan_id, res->vf_mask, is_add);
7311 #endif
7312
7313         switch (ret) {
7314         case 0:
7315                 break;
7316         case -EINVAL:
7317                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7318                                 res->vlan_id, res->vf_mask);
7319                 break;
7320         case -ENODEV:
7321                 printf("invalid port_id %d\n", res->port_id);
7322                 break;
7323         case -ENOTSUP:
7324                 printf("function not implemented or supported\n");
7325                 break;
7326         default:
7327                 printf("programming error: (%s)\n", strerror(-ret));
7328         }
7329 }
7330
7331 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7332         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7333                                  rx_vlan, "rx_vlan");
7334 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7335         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7336                                  what, "add#rm");
7337 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7338         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7339                               vlan_id, UINT16);
7340 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7341         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7342                                  port, "port");
7343 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7344         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7345                               port_id, UINT8);
7346 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7347         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7348                                  vf, "vf");
7349 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7350         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7351                               vf_mask, UINT64);
7352
7353 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7354         .f = cmd_vf_rx_vlan_filter_parsed,
7355         .data = NULL,
7356         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7357                 "(vf_mask = hexadecimal VF mask)",
7358         .tokens = {
7359                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7360                 (void *)&cmd_vf_rx_vlan_filter_what,
7361                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7362                 (void *)&cmd_vf_rx_vlan_filter_port,
7363                 (void *)&cmd_vf_rx_vlan_filter_portid,
7364                 (void *)&cmd_vf_rx_vlan_filter_vf,
7365                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7366                 NULL,
7367         },
7368 };
7369
7370 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7371 struct cmd_queue_rate_limit_result {
7372         cmdline_fixed_string_t set;
7373         cmdline_fixed_string_t port;
7374         uint8_t port_num;
7375         cmdline_fixed_string_t queue;
7376         uint8_t queue_num;
7377         cmdline_fixed_string_t rate;
7378         uint16_t rate_num;
7379 };
7380
7381 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7382                 __attribute__((unused)) struct cmdline *cl,
7383                 __attribute__((unused)) void *data)
7384 {
7385         struct cmd_queue_rate_limit_result *res = parsed_result;
7386         int ret = 0;
7387
7388         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7389                 && (strcmp(res->queue, "queue") == 0)
7390                 && (strcmp(res->rate, "rate") == 0))
7391                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7392                                         res->rate_num);
7393         if (ret < 0)
7394                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7395
7396 }
7397
7398 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7399         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7400                                 set, "set");
7401 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7402         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7403                                 port, "port");
7404 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7405         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7406                                 port_num, UINT8);
7407 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7408         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7409                                 queue, "queue");
7410 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7411         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7412                                 queue_num, UINT8);
7413 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7414         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7415                                 rate, "rate");
7416 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7417         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7418                                 rate_num, UINT16);
7419
7420 cmdline_parse_inst_t cmd_queue_rate_limit = {
7421         .f = cmd_queue_rate_limit_parsed,
7422         .data = (void *)0,
7423         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7424                 "Set rate limit for a queue on port_id",
7425         .tokens = {
7426                 (void *)&cmd_queue_rate_limit_set,
7427                 (void *)&cmd_queue_rate_limit_port,
7428                 (void *)&cmd_queue_rate_limit_portnum,
7429                 (void *)&cmd_queue_rate_limit_queue,
7430                 (void *)&cmd_queue_rate_limit_queuenum,
7431                 (void *)&cmd_queue_rate_limit_rate,
7432                 (void *)&cmd_queue_rate_limit_ratenum,
7433                 NULL,
7434         },
7435 };
7436
7437 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7438 struct cmd_vf_rate_limit_result {
7439         cmdline_fixed_string_t set;
7440         cmdline_fixed_string_t port;
7441         uint8_t port_num;
7442         cmdline_fixed_string_t vf;
7443         uint8_t vf_num;
7444         cmdline_fixed_string_t rate;
7445         uint16_t rate_num;
7446         cmdline_fixed_string_t q_msk;
7447         uint64_t q_msk_val;
7448 };
7449
7450 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7451                 __attribute__((unused)) struct cmdline *cl,
7452                 __attribute__((unused)) void *data)
7453 {
7454         struct cmd_vf_rate_limit_result *res = parsed_result;
7455         int ret = 0;
7456
7457         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7458                 && (strcmp(res->vf, "vf") == 0)
7459                 && (strcmp(res->rate, "rate") == 0)
7460                 && (strcmp(res->q_msk, "queue_mask") == 0))
7461                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7462                                         res->rate_num, res->q_msk_val);
7463         if (ret < 0)
7464                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7465
7466 }
7467
7468 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7469         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7470                                 set, "set");
7471 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7472         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7473                                 port, "port");
7474 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7475         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7476                                 port_num, UINT8);
7477 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7478         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7479                                 vf, "vf");
7480 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7481         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7482                                 vf_num, UINT8);
7483 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7484         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7485                                 rate, "rate");
7486 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7487         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7488                                 rate_num, UINT16);
7489 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7490         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7491                                 q_msk, "queue_mask");
7492 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7493         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7494                                 q_msk_val, UINT64);
7495
7496 cmdline_parse_inst_t cmd_vf_rate_limit = {
7497         .f = cmd_vf_rate_limit_parsed,
7498         .data = (void *)0,
7499         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7500                 "queue_mask <queue_mask_value>: "
7501                 "Set rate limit for queues of VF on port_id",
7502         .tokens = {
7503                 (void *)&cmd_vf_rate_limit_set,
7504                 (void *)&cmd_vf_rate_limit_port,
7505                 (void *)&cmd_vf_rate_limit_portnum,
7506                 (void *)&cmd_vf_rate_limit_vf,
7507                 (void *)&cmd_vf_rate_limit_vfnum,
7508                 (void *)&cmd_vf_rate_limit_rate,
7509                 (void *)&cmd_vf_rate_limit_ratenum,
7510                 (void *)&cmd_vf_rate_limit_q_msk,
7511                 (void *)&cmd_vf_rate_limit_q_msk_val,
7512                 NULL,
7513         },
7514 };
7515
7516 /* *** ADD TUNNEL FILTER OF A PORT *** */
7517 struct cmd_tunnel_filter_result {
7518         cmdline_fixed_string_t cmd;
7519         cmdline_fixed_string_t what;
7520         uint8_t port_id;
7521         struct ether_addr outer_mac;
7522         struct ether_addr inner_mac;
7523         cmdline_ipaddr_t ip_value;
7524         uint16_t inner_vlan;
7525         cmdline_fixed_string_t tunnel_type;
7526         cmdline_fixed_string_t filter_type;
7527         uint32_t tenant_id;
7528         uint16_t queue_num;
7529 };
7530
7531 static void
7532 cmd_tunnel_filter_parsed(void *parsed_result,
7533                           __attribute__((unused)) struct cmdline *cl,
7534                           __attribute__((unused)) void *data)
7535 {
7536         struct cmd_tunnel_filter_result *res = parsed_result;
7537         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7538         int ret = 0;
7539
7540         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7541
7542         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7543         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7544         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7545
7546         if (res->ip_value.family == AF_INET) {
7547                 tunnel_filter_conf.ip_addr.ipv4_addr =
7548                         res->ip_value.addr.ipv4.s_addr;
7549                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7550         } else {
7551                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7552                         &(res->ip_value.addr.ipv6),
7553                         sizeof(struct in6_addr));
7554                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7555         }
7556
7557         if (!strcmp(res->filter_type, "imac-ivlan"))
7558                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7559         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7560                 tunnel_filter_conf.filter_type =
7561                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7562         else if (!strcmp(res->filter_type, "imac-tenid"))
7563                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7564         else if (!strcmp(res->filter_type, "imac"))
7565                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7566         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7567                 tunnel_filter_conf.filter_type =
7568                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7569         else if (!strcmp(res->filter_type, "oip"))
7570                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7571         else if (!strcmp(res->filter_type, "iip"))
7572                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7573         else {
7574                 printf("The filter type is not supported");
7575                 return;
7576         }
7577
7578         if (!strcmp(res->tunnel_type, "vxlan"))
7579                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7580         else if (!strcmp(res->tunnel_type, "nvgre"))
7581                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7582         else if (!strcmp(res->tunnel_type, "ipingre"))
7583                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7584         else {
7585                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7586                 return;
7587         }
7588
7589         tunnel_filter_conf.tenant_id = res->tenant_id;
7590         tunnel_filter_conf.queue_id = res->queue_num;
7591         if (!strcmp(res->what, "add"))
7592                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7593                                         RTE_ETH_FILTER_TUNNEL,
7594                                         RTE_ETH_FILTER_ADD,
7595                                         &tunnel_filter_conf);
7596         else
7597                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7598                                         RTE_ETH_FILTER_TUNNEL,
7599                                         RTE_ETH_FILTER_DELETE,
7600                                         &tunnel_filter_conf);
7601         if (ret < 0)
7602                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7603                                 strerror(-ret));
7604
7605 }
7606 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7607         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7608         cmd, "tunnel_filter");
7609 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7610         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7611         what, "add#rm");
7612 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7613         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7614         port_id, UINT8);
7615 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7616         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7617         outer_mac);
7618 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7619         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7620         inner_mac);
7621 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7622         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7623         inner_vlan, UINT16);
7624 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7625         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7626         ip_value);
7627 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7628         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7629         tunnel_type, "vxlan#nvgre#ipingre");
7630
7631 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7632         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7633         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7634                 "imac#omac-imac-tenid");
7635 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7636         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7637         tenant_id, UINT32);
7638 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7639         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7640         queue_num, UINT16);
7641
7642 cmdline_parse_inst_t cmd_tunnel_filter = {
7643         .f = cmd_tunnel_filter_parsed,
7644         .data = (void *)0,
7645         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7646                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7647                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7648                 "<queue_id>: Add/Rm tunnel filter of a port",
7649         .tokens = {
7650                 (void *)&cmd_tunnel_filter_cmd,
7651                 (void *)&cmd_tunnel_filter_what,
7652                 (void *)&cmd_tunnel_filter_port_id,
7653                 (void *)&cmd_tunnel_filter_outer_mac,
7654                 (void *)&cmd_tunnel_filter_inner_mac,
7655                 (void *)&cmd_tunnel_filter_ip_value,
7656                 (void *)&cmd_tunnel_filter_innner_vlan,
7657                 (void *)&cmd_tunnel_filter_tunnel_type,
7658                 (void *)&cmd_tunnel_filter_filter_type,
7659                 (void *)&cmd_tunnel_filter_tenant_id,
7660                 (void *)&cmd_tunnel_filter_queue_num,
7661                 NULL,
7662         },
7663 };
7664
7665 /* *** CONFIGURE TUNNEL UDP PORT *** */
7666 struct cmd_tunnel_udp_config {
7667         cmdline_fixed_string_t cmd;
7668         cmdline_fixed_string_t what;
7669         uint16_t udp_port;
7670         uint8_t port_id;
7671 };
7672
7673 static void
7674 cmd_tunnel_udp_config_parsed(void *parsed_result,
7675                           __attribute__((unused)) struct cmdline *cl,
7676                           __attribute__((unused)) void *data)
7677 {
7678         struct cmd_tunnel_udp_config *res = parsed_result;
7679         struct rte_eth_udp_tunnel tunnel_udp;
7680         int ret;
7681
7682         tunnel_udp.udp_port = res->udp_port;
7683
7684         if (!strcmp(res->cmd, "rx_vxlan_port"))
7685                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7686
7687         if (!strcmp(res->what, "add"))
7688                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7689                                                       &tunnel_udp);
7690         else
7691                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7692                                                          &tunnel_udp);
7693
7694         if (ret < 0)
7695                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7696 }
7697
7698 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7699         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7700                                 cmd, "rx_vxlan_port");
7701 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7702         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7703                                 what, "add#rm");
7704 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7705         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7706                                 udp_port, UINT16);
7707 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7708         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7709                                 port_id, UINT8);
7710
7711 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7712         .f = cmd_tunnel_udp_config_parsed,
7713         .data = (void *)0,
7714         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7715                 "Add/Remove a tunneling UDP port filter",
7716         .tokens = {
7717                 (void *)&cmd_tunnel_udp_config_cmd,
7718                 (void *)&cmd_tunnel_udp_config_what,
7719                 (void *)&cmd_tunnel_udp_config_udp_port,
7720                 (void *)&cmd_tunnel_udp_config_port_id,
7721                 NULL,
7722         },
7723 };
7724
7725 /* *** GLOBAL CONFIG *** */
7726 struct cmd_global_config_result {
7727         cmdline_fixed_string_t cmd;
7728         uint8_t port_id;
7729         cmdline_fixed_string_t cfg_type;
7730         uint8_t len;
7731 };
7732
7733 static void
7734 cmd_global_config_parsed(void *parsed_result,
7735                          __attribute__((unused)) struct cmdline *cl,
7736                          __attribute__((unused)) void *data)
7737 {
7738         struct cmd_global_config_result *res = parsed_result;
7739         struct rte_eth_global_cfg conf;
7740         int ret;
7741
7742         memset(&conf, 0, sizeof(conf));
7743         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7744         conf.cfg.gre_key_len = res->len;
7745         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7746                                       RTE_ETH_FILTER_SET, &conf);
7747         if (ret != 0)
7748                 printf("Global config error\n");
7749 }
7750
7751 cmdline_parse_token_string_t cmd_global_config_cmd =
7752         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7753                 "global_config");
7754 cmdline_parse_token_num_t cmd_global_config_port_id =
7755         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7756 cmdline_parse_token_string_t cmd_global_config_type =
7757         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7758                 cfg_type, "gre-key-len");
7759 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7760         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7761                 len, UINT8);
7762
7763 cmdline_parse_inst_t cmd_global_config = {
7764         .f = cmd_global_config_parsed,
7765         .data = (void *)NULL,
7766         .help_str = "global_config <port_id> gre-key-len <key_len>",
7767         .tokens = {
7768                 (void *)&cmd_global_config_cmd,
7769                 (void *)&cmd_global_config_port_id,
7770                 (void *)&cmd_global_config_type,
7771                 (void *)&cmd_global_config_gre_key_len,
7772                 NULL,
7773         },
7774 };
7775
7776 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7777 struct cmd_set_mirror_mask_result {
7778         cmdline_fixed_string_t set;
7779         cmdline_fixed_string_t port;
7780         uint8_t port_id;
7781         cmdline_fixed_string_t mirror;
7782         uint8_t rule_id;
7783         cmdline_fixed_string_t what;
7784         cmdline_fixed_string_t value;
7785         cmdline_fixed_string_t dstpool;
7786         uint8_t dstpool_id;
7787         cmdline_fixed_string_t on;
7788 };
7789
7790 cmdline_parse_token_string_t cmd_mirror_mask_set =
7791         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7792                                 set, "set");
7793 cmdline_parse_token_string_t cmd_mirror_mask_port =
7794         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7795                                 port, "port");
7796 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7797         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7798                                 port_id, UINT8);
7799 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7800         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7801                                 mirror, "mirror-rule");
7802 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7803         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7804                                 rule_id, UINT8);
7805 cmdline_parse_token_string_t cmd_mirror_mask_what =
7806         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7807                                 what, "pool-mirror-up#pool-mirror-down"
7808                                       "#vlan-mirror");
7809 cmdline_parse_token_string_t cmd_mirror_mask_value =
7810         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7811                                 value, NULL);
7812 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7813         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7814                                 dstpool, "dst-pool");
7815 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7816         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7817                                 dstpool_id, UINT8);
7818 cmdline_parse_token_string_t cmd_mirror_mask_on =
7819         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7820                                 on, "on#off");
7821
7822 static void
7823 cmd_set_mirror_mask_parsed(void *parsed_result,
7824                        __attribute__((unused)) struct cmdline *cl,
7825                        __attribute__((unused)) void *data)
7826 {
7827         int ret,nb_item,i;
7828         struct cmd_set_mirror_mask_result *res = parsed_result;
7829         struct rte_eth_mirror_conf mr_conf;
7830
7831         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7832
7833         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7834
7835         mr_conf.dst_pool = res->dstpool_id;
7836
7837         if (!strcmp(res->what, "pool-mirror-up")) {
7838                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7839                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7840         } else if (!strcmp(res->what, "pool-mirror-down")) {
7841                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7842                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7843         } else if (!strcmp(res->what, "vlan-mirror")) {
7844                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7845                 nb_item = parse_item_list(res->value, "vlan",
7846                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7847                 if (nb_item <= 0)
7848                         return;
7849
7850                 for (i = 0; i < nb_item; i++) {
7851                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7852                                 printf("Invalid vlan_id: must be < 4096\n");
7853                                 return;
7854                         }
7855
7856                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7857                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7858                 }
7859         }
7860
7861         if (!strcmp(res->on, "on"))
7862                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7863                                                 res->rule_id, 1);
7864         else
7865                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7866                                                 res->rule_id, 0);
7867         if (ret < 0)
7868                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7869 }
7870
7871 cmdline_parse_inst_t cmd_set_mirror_mask = {
7872                 .f = cmd_set_mirror_mask_parsed,
7873                 .data = NULL,
7874                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7875                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7876                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7877                 .tokens = {
7878                         (void *)&cmd_mirror_mask_set,
7879                         (void *)&cmd_mirror_mask_port,
7880                         (void *)&cmd_mirror_mask_portid,
7881                         (void *)&cmd_mirror_mask_mirror,
7882                         (void *)&cmd_mirror_mask_ruleid,
7883                         (void *)&cmd_mirror_mask_what,
7884                         (void *)&cmd_mirror_mask_value,
7885                         (void *)&cmd_mirror_mask_dstpool,
7886                         (void *)&cmd_mirror_mask_poolid,
7887                         (void *)&cmd_mirror_mask_on,
7888                         NULL,
7889                 },
7890 };
7891
7892 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7893 struct cmd_set_mirror_link_result {
7894         cmdline_fixed_string_t set;
7895         cmdline_fixed_string_t port;
7896         uint8_t port_id;
7897         cmdline_fixed_string_t mirror;
7898         uint8_t rule_id;
7899         cmdline_fixed_string_t what;
7900         cmdline_fixed_string_t dstpool;
7901         uint8_t dstpool_id;
7902         cmdline_fixed_string_t on;
7903 };
7904
7905 cmdline_parse_token_string_t cmd_mirror_link_set =
7906         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7907                                  set, "set");
7908 cmdline_parse_token_string_t cmd_mirror_link_port =
7909         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7910                                 port, "port");
7911 cmdline_parse_token_num_t cmd_mirror_link_portid =
7912         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7913                                 port_id, UINT8);
7914 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7915         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7916                                 mirror, "mirror-rule");
7917 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7918         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7919                             rule_id, UINT8);
7920 cmdline_parse_token_string_t cmd_mirror_link_what =
7921         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7922                                 what, "uplink-mirror#downlink-mirror");
7923 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7924         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7925                                 dstpool, "dst-pool");
7926 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7927         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7928                                 dstpool_id, UINT8);
7929 cmdline_parse_token_string_t cmd_mirror_link_on =
7930         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7931                                 on, "on#off");
7932
7933 static void
7934 cmd_set_mirror_link_parsed(void *parsed_result,
7935                        __attribute__((unused)) struct cmdline *cl,
7936                        __attribute__((unused)) void *data)
7937 {
7938         int ret;
7939         struct cmd_set_mirror_link_result *res = parsed_result;
7940         struct rte_eth_mirror_conf mr_conf;
7941
7942         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7943         if (!strcmp(res->what, "uplink-mirror"))
7944                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7945         else
7946                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7947
7948         mr_conf.dst_pool = res->dstpool_id;
7949
7950         if (!strcmp(res->on, "on"))
7951                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7952                                                 res->rule_id, 1);
7953         else
7954                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7955                                                 res->rule_id, 0);
7956
7957         /* check the return value and print it if is < 0 */
7958         if (ret < 0)
7959                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7960
7961 }
7962
7963 cmdline_parse_inst_t cmd_set_mirror_link = {
7964                 .f = cmd_set_mirror_link_parsed,
7965                 .data = NULL,
7966                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7967                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7968                 .tokens = {
7969                         (void *)&cmd_mirror_link_set,
7970                         (void *)&cmd_mirror_link_port,
7971                         (void *)&cmd_mirror_link_portid,
7972                         (void *)&cmd_mirror_link_mirror,
7973                         (void *)&cmd_mirror_link_ruleid,
7974                         (void *)&cmd_mirror_link_what,
7975                         (void *)&cmd_mirror_link_dstpool,
7976                         (void *)&cmd_mirror_link_poolid,
7977                         (void *)&cmd_mirror_link_on,
7978                         NULL,
7979                 },
7980 };
7981
7982 /* *** RESET VM MIRROR RULE *** */
7983 struct cmd_rm_mirror_rule_result {
7984         cmdline_fixed_string_t reset;
7985         cmdline_fixed_string_t port;
7986         uint8_t port_id;
7987         cmdline_fixed_string_t mirror;
7988         uint8_t rule_id;
7989 };
7990
7991 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7992         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7993                                  reset, "reset");
7994 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7995         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7996                                 port, "port");
7997 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7998         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7999                                 port_id, UINT8);
8000 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8001         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8002                                 mirror, "mirror-rule");
8003 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8004         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8005                                 rule_id, UINT8);
8006
8007 static void
8008 cmd_reset_mirror_rule_parsed(void *parsed_result,
8009                        __attribute__((unused)) struct cmdline *cl,
8010                        __attribute__((unused)) void *data)
8011 {
8012         int ret;
8013         struct cmd_set_mirror_link_result *res = parsed_result;
8014         /* check rule_id */
8015         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8016         if(ret < 0)
8017                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8018 }
8019
8020 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8021                 .f = cmd_reset_mirror_rule_parsed,
8022                 .data = NULL,
8023                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8024                 .tokens = {
8025                         (void *)&cmd_rm_mirror_rule_reset,
8026                         (void *)&cmd_rm_mirror_rule_port,
8027                         (void *)&cmd_rm_mirror_rule_portid,
8028                         (void *)&cmd_rm_mirror_rule_mirror,
8029                         (void *)&cmd_rm_mirror_rule_ruleid,
8030                         NULL,
8031                 },
8032 };
8033
8034 /* ******************************************************************************** */
8035
8036 struct cmd_dump_result {
8037         cmdline_fixed_string_t dump;
8038 };
8039
8040 static void
8041 dump_struct_sizes(void)
8042 {
8043 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8044         DUMP_SIZE(struct rte_mbuf);
8045         DUMP_SIZE(struct rte_mempool);
8046         DUMP_SIZE(struct rte_ring);
8047 #undef DUMP_SIZE
8048 }
8049
8050 static void cmd_dump_parsed(void *parsed_result,
8051                             __attribute__((unused)) struct cmdline *cl,
8052                             __attribute__((unused)) void *data)
8053 {
8054         struct cmd_dump_result *res = parsed_result;
8055
8056         if (!strcmp(res->dump, "dump_physmem"))
8057                 rte_dump_physmem_layout(stdout);
8058         else if (!strcmp(res->dump, "dump_memzone"))
8059                 rte_memzone_dump(stdout);
8060         else if (!strcmp(res->dump, "dump_struct_sizes"))
8061                 dump_struct_sizes();
8062         else if (!strcmp(res->dump, "dump_ring"))
8063                 rte_ring_list_dump(stdout);
8064         else if (!strcmp(res->dump, "dump_mempool"))
8065                 rte_mempool_list_dump(stdout);
8066         else if (!strcmp(res->dump, "dump_devargs"))
8067                 rte_eal_devargs_dump(stdout);
8068         else if (!strcmp(res->dump, "dump_log_types"))
8069                 rte_log_dump(stdout);
8070 }
8071
8072 cmdline_parse_token_string_t cmd_dump_dump =
8073         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8074                 "dump_physmem#"
8075                 "dump_memzone#"
8076                 "dump_struct_sizes#"
8077                 "dump_ring#"
8078                 "dump_mempool#"
8079                 "dump_devargs#"
8080                 "dump_log_types");
8081
8082 cmdline_parse_inst_t cmd_dump = {
8083         .f = cmd_dump_parsed,  /* function to call */
8084         .data = NULL,      /* 2nd arg of func */
8085         .help_str = "Dump status",
8086         .tokens = {        /* token list, NULL terminated */
8087                 (void *)&cmd_dump_dump,
8088                 NULL,
8089         },
8090 };
8091
8092 /* ******************************************************************************** */
8093
8094 struct cmd_dump_one_result {
8095         cmdline_fixed_string_t dump;
8096         cmdline_fixed_string_t name;
8097 };
8098
8099 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8100                                 __attribute__((unused)) void *data)
8101 {
8102         struct cmd_dump_one_result *res = parsed_result;
8103
8104         if (!strcmp(res->dump, "dump_ring")) {
8105                 struct rte_ring *r;
8106                 r = rte_ring_lookup(res->name);
8107                 if (r == NULL) {
8108                         cmdline_printf(cl, "Cannot find ring\n");
8109                         return;
8110                 }
8111                 rte_ring_dump(stdout, r);
8112         } else if (!strcmp(res->dump, "dump_mempool")) {
8113                 struct rte_mempool *mp;
8114                 mp = rte_mempool_lookup(res->name);
8115                 if (mp == NULL) {
8116                         cmdline_printf(cl, "Cannot find mempool\n");
8117                         return;
8118                 }
8119                 rte_mempool_dump(stdout, mp);
8120         }
8121 }
8122
8123 cmdline_parse_token_string_t cmd_dump_one_dump =
8124         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8125                                  "dump_ring#dump_mempool");
8126
8127 cmdline_parse_token_string_t cmd_dump_one_name =
8128         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8129
8130 cmdline_parse_inst_t cmd_dump_one = {
8131         .f = cmd_dump_one_parsed,  /* function to call */
8132         .data = NULL,      /* 2nd arg of func */
8133         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8134         .tokens = {        /* token list, NULL terminated */
8135                 (void *)&cmd_dump_one_dump,
8136                 (void *)&cmd_dump_one_name,
8137                 NULL,
8138         },
8139 };
8140
8141 /* *** Add/Del syn filter *** */
8142 struct cmd_syn_filter_result {
8143         cmdline_fixed_string_t filter;
8144         uint8_t port_id;
8145         cmdline_fixed_string_t ops;
8146         cmdline_fixed_string_t priority;
8147         cmdline_fixed_string_t high;
8148         cmdline_fixed_string_t queue;
8149         uint16_t queue_id;
8150 };
8151
8152 static void
8153 cmd_syn_filter_parsed(void *parsed_result,
8154                         __attribute__((unused)) struct cmdline *cl,
8155                         __attribute__((unused)) void *data)
8156 {
8157         struct cmd_syn_filter_result *res = parsed_result;
8158         struct rte_eth_syn_filter syn_filter;
8159         int ret = 0;
8160
8161         ret = rte_eth_dev_filter_supported(res->port_id,
8162                                         RTE_ETH_FILTER_SYN);
8163         if (ret < 0) {
8164                 printf("syn filter is not supported on port %u.\n",
8165                                 res->port_id);
8166                 return;
8167         }
8168
8169         memset(&syn_filter, 0, sizeof(syn_filter));
8170
8171         if (!strcmp(res->ops, "add")) {
8172                 if (!strcmp(res->high, "high"))
8173                         syn_filter.hig_pri = 1;
8174                 else
8175                         syn_filter.hig_pri = 0;
8176
8177                 syn_filter.queue = res->queue_id;
8178                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8179                                                 RTE_ETH_FILTER_SYN,
8180                                                 RTE_ETH_FILTER_ADD,
8181                                                 &syn_filter);
8182         } else
8183                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8184                                                 RTE_ETH_FILTER_SYN,
8185                                                 RTE_ETH_FILTER_DELETE,
8186                                                 &syn_filter);
8187
8188         if (ret < 0)
8189                 printf("syn filter programming error: (%s)\n",
8190                                 strerror(-ret));
8191 }
8192
8193 cmdline_parse_token_string_t cmd_syn_filter_filter =
8194         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8195         filter, "syn_filter");
8196 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8197         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8198         port_id, UINT8);
8199 cmdline_parse_token_string_t cmd_syn_filter_ops =
8200         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8201         ops, "add#del");
8202 cmdline_parse_token_string_t cmd_syn_filter_priority =
8203         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8204                                 priority, "priority");
8205 cmdline_parse_token_string_t cmd_syn_filter_high =
8206         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8207                                 high, "high#low");
8208 cmdline_parse_token_string_t cmd_syn_filter_queue =
8209         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8210                                 queue, "queue");
8211 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8212         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8213                                 queue_id, UINT16);
8214
8215 cmdline_parse_inst_t cmd_syn_filter = {
8216         .f = cmd_syn_filter_parsed,
8217         .data = NULL,
8218         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8219                 "<queue_id>: Add/Delete syn filter",
8220         .tokens = {
8221                 (void *)&cmd_syn_filter_filter,
8222                 (void *)&cmd_syn_filter_port_id,
8223                 (void *)&cmd_syn_filter_ops,
8224                 (void *)&cmd_syn_filter_priority,
8225                 (void *)&cmd_syn_filter_high,
8226                 (void *)&cmd_syn_filter_queue,
8227                 (void *)&cmd_syn_filter_queue_id,
8228                 NULL,
8229         },
8230 };
8231
8232 /* *** ADD/REMOVE A 2tuple FILTER *** */
8233 struct cmd_2tuple_filter_result {
8234         cmdline_fixed_string_t filter;
8235         uint8_t  port_id;
8236         cmdline_fixed_string_t ops;
8237         cmdline_fixed_string_t dst_port;
8238         uint16_t dst_port_value;
8239         cmdline_fixed_string_t protocol;
8240         uint8_t protocol_value;
8241         cmdline_fixed_string_t mask;
8242         uint8_t  mask_value;
8243         cmdline_fixed_string_t tcp_flags;
8244         uint8_t tcp_flags_value;
8245         cmdline_fixed_string_t priority;
8246         uint8_t  priority_value;
8247         cmdline_fixed_string_t queue;
8248         uint16_t  queue_id;
8249 };
8250
8251 static void
8252 cmd_2tuple_filter_parsed(void *parsed_result,
8253                         __attribute__((unused)) struct cmdline *cl,
8254                         __attribute__((unused)) void *data)
8255 {
8256         struct rte_eth_ntuple_filter filter;
8257         struct cmd_2tuple_filter_result *res = parsed_result;
8258         int ret = 0;
8259
8260         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8261         if (ret < 0) {
8262                 printf("ntuple filter is not supported on port %u.\n",
8263                         res->port_id);
8264                 return;
8265         }
8266
8267         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8268
8269         filter.flags = RTE_2TUPLE_FLAGS;
8270         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8271         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8272         filter.proto = res->protocol_value;
8273         filter.priority = res->priority_value;
8274         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8275                 printf("nonzero tcp_flags is only meaningful"
8276                         " when protocol is TCP.\n");
8277                 return;
8278         }
8279         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8280                 printf("invalid TCP flags.\n");
8281                 return;
8282         }
8283
8284         if (res->tcp_flags_value != 0) {
8285                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8286                 filter.tcp_flags = res->tcp_flags_value;
8287         }
8288
8289         /* need convert to big endian. */
8290         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8291         filter.queue = res->queue_id;
8292
8293         if (!strcmp(res->ops, "add"))
8294                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8295                                 RTE_ETH_FILTER_NTUPLE,
8296                                 RTE_ETH_FILTER_ADD,
8297                                 &filter);
8298         else
8299                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8300                                 RTE_ETH_FILTER_NTUPLE,
8301                                 RTE_ETH_FILTER_DELETE,
8302                                 &filter);
8303         if (ret < 0)
8304                 printf("2tuple filter programming error: (%s)\n",
8305                         strerror(-ret));
8306
8307 }
8308
8309 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8310         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8311                                  filter, "2tuple_filter");
8312 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8313         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8314                                 port_id, UINT8);
8315 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8316         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8317                                  ops, "add#del");
8318 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8319         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8320                                 dst_port, "dst_port");
8321 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8322         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8323                                 dst_port_value, UINT16);
8324 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8325         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8326                                 protocol, "protocol");
8327 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8328         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8329                                 protocol_value, UINT8);
8330 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8331         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8332                                 mask, "mask");
8333 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8334         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8335                                 mask_value, INT8);
8336 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8337         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8338                                 tcp_flags, "tcp_flags");
8339 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8340         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8341                                 tcp_flags_value, UINT8);
8342 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8343         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8344                                 priority, "priority");
8345 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8346         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8347                                 priority_value, UINT8);
8348 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8349         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8350                                 queue, "queue");
8351 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8352         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8353                                 queue_id, UINT16);
8354
8355 cmdline_parse_inst_t cmd_2tuple_filter = {
8356         .f = cmd_2tuple_filter_parsed,
8357         .data = NULL,
8358         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8359                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8360                 "<queue_id>: Add a 2tuple filter",
8361         .tokens = {
8362                 (void *)&cmd_2tuple_filter_filter,
8363                 (void *)&cmd_2tuple_filter_port_id,
8364                 (void *)&cmd_2tuple_filter_ops,
8365                 (void *)&cmd_2tuple_filter_dst_port,
8366                 (void *)&cmd_2tuple_filter_dst_port_value,
8367                 (void *)&cmd_2tuple_filter_protocol,
8368                 (void *)&cmd_2tuple_filter_protocol_value,
8369                 (void *)&cmd_2tuple_filter_mask,
8370                 (void *)&cmd_2tuple_filter_mask_value,
8371                 (void *)&cmd_2tuple_filter_tcp_flags,
8372                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8373                 (void *)&cmd_2tuple_filter_priority,
8374                 (void *)&cmd_2tuple_filter_priority_value,
8375                 (void *)&cmd_2tuple_filter_queue,
8376                 (void *)&cmd_2tuple_filter_queue_id,
8377                 NULL,
8378         },
8379 };
8380
8381 /* *** ADD/REMOVE A 5tuple FILTER *** */
8382 struct cmd_5tuple_filter_result {
8383         cmdline_fixed_string_t filter;
8384         uint8_t  port_id;
8385         cmdline_fixed_string_t ops;
8386         cmdline_fixed_string_t dst_ip;
8387         cmdline_ipaddr_t dst_ip_value;
8388         cmdline_fixed_string_t src_ip;
8389         cmdline_ipaddr_t src_ip_value;
8390         cmdline_fixed_string_t dst_port;
8391         uint16_t dst_port_value;
8392         cmdline_fixed_string_t src_port;
8393         uint16_t src_port_value;
8394         cmdline_fixed_string_t protocol;
8395         uint8_t protocol_value;
8396         cmdline_fixed_string_t mask;
8397         uint8_t  mask_value;
8398         cmdline_fixed_string_t tcp_flags;
8399         uint8_t tcp_flags_value;
8400         cmdline_fixed_string_t priority;
8401         uint8_t  priority_value;
8402         cmdline_fixed_string_t queue;
8403         uint16_t  queue_id;
8404 };
8405
8406 static void
8407 cmd_5tuple_filter_parsed(void *parsed_result,
8408                         __attribute__((unused)) struct cmdline *cl,
8409                         __attribute__((unused)) void *data)
8410 {
8411         struct rte_eth_ntuple_filter filter;
8412         struct cmd_5tuple_filter_result *res = parsed_result;
8413         int ret = 0;
8414
8415         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8416         if (ret < 0) {
8417                 printf("ntuple filter is not supported on port %u.\n",
8418                         res->port_id);
8419                 return;
8420         }
8421
8422         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8423
8424         filter.flags = RTE_5TUPLE_FLAGS;
8425         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8426         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8427         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8428         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8429         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8430         filter.proto = res->protocol_value;
8431         filter.priority = res->priority_value;
8432         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8433                 printf("nonzero tcp_flags is only meaningful"
8434                         " when protocol is TCP.\n");
8435                 return;
8436         }
8437         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8438                 printf("invalid TCP flags.\n");
8439                 return;
8440         }
8441
8442         if (res->tcp_flags_value != 0) {
8443                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8444                 filter.tcp_flags = res->tcp_flags_value;
8445         }
8446
8447         if (res->dst_ip_value.family == AF_INET)
8448                 /* no need to convert, already big endian. */
8449                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8450         else {
8451                 if (filter.dst_ip_mask == 0) {
8452                         printf("can not support ipv6 involved compare.\n");
8453                         return;
8454                 }
8455                 filter.dst_ip = 0;
8456         }
8457
8458         if (res->src_ip_value.family == AF_INET)
8459                 /* no need to convert, already big endian. */
8460                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8461         else {
8462                 if (filter.src_ip_mask == 0) {
8463                         printf("can not support ipv6 involved compare.\n");
8464                         return;
8465                 }
8466                 filter.src_ip = 0;
8467         }
8468         /* need convert to big endian. */
8469         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8470         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8471         filter.queue = res->queue_id;
8472
8473         if (!strcmp(res->ops, "add"))
8474                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8475                                 RTE_ETH_FILTER_NTUPLE,
8476                                 RTE_ETH_FILTER_ADD,
8477                                 &filter);
8478         else
8479                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8480                                 RTE_ETH_FILTER_NTUPLE,
8481                                 RTE_ETH_FILTER_DELETE,
8482                                 &filter);
8483         if (ret < 0)
8484                 printf("5tuple filter programming error: (%s)\n",
8485                         strerror(-ret));
8486 }
8487
8488 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8489         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8490                                  filter, "5tuple_filter");
8491 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8492         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8493                                 port_id, UINT8);
8494 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8495         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8496                                  ops, "add#del");
8497 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8498         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8499                                 dst_ip, "dst_ip");
8500 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8501         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8502                                 dst_ip_value);
8503 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8504         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8505                                 src_ip, "src_ip");
8506 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8507         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8508                                 src_ip_value);
8509 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8510         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8511                                 dst_port, "dst_port");
8512 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8513         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8514                                 dst_port_value, UINT16);
8515 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8516         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8517                                 src_port, "src_port");
8518 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8519         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8520                                 src_port_value, UINT16);
8521 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8522         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8523                                 protocol, "protocol");
8524 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8525         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8526                                 protocol_value, UINT8);
8527 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8528         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8529                                 mask, "mask");
8530 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8531         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8532                                 mask_value, INT8);
8533 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8534         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8535                                 tcp_flags, "tcp_flags");
8536 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8537         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8538                                 tcp_flags_value, UINT8);
8539 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8540         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8541                                 priority, "priority");
8542 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8543         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8544                                 priority_value, UINT8);
8545 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8546         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8547                                 queue, "queue");
8548 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8549         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8550                                 queue_id, UINT16);
8551
8552 cmdline_parse_inst_t cmd_5tuple_filter = {
8553         .f = cmd_5tuple_filter_parsed,
8554         .data = NULL,
8555         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8556                 "src_ip <value> dst_port <value> src_port <value> "
8557                 "protocol <value>  mask <value> tcp_flags <value> "
8558                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8559         .tokens = {
8560                 (void *)&cmd_5tuple_filter_filter,
8561                 (void *)&cmd_5tuple_filter_port_id,
8562                 (void *)&cmd_5tuple_filter_ops,
8563                 (void *)&cmd_5tuple_filter_dst_ip,
8564                 (void *)&cmd_5tuple_filter_dst_ip_value,
8565                 (void *)&cmd_5tuple_filter_src_ip,
8566                 (void *)&cmd_5tuple_filter_src_ip_value,
8567                 (void *)&cmd_5tuple_filter_dst_port,
8568                 (void *)&cmd_5tuple_filter_dst_port_value,
8569                 (void *)&cmd_5tuple_filter_src_port,
8570                 (void *)&cmd_5tuple_filter_src_port_value,
8571                 (void *)&cmd_5tuple_filter_protocol,
8572                 (void *)&cmd_5tuple_filter_protocol_value,
8573                 (void *)&cmd_5tuple_filter_mask,
8574                 (void *)&cmd_5tuple_filter_mask_value,
8575                 (void *)&cmd_5tuple_filter_tcp_flags,
8576                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8577                 (void *)&cmd_5tuple_filter_priority,
8578                 (void *)&cmd_5tuple_filter_priority_value,
8579                 (void *)&cmd_5tuple_filter_queue,
8580                 (void *)&cmd_5tuple_filter_queue_id,
8581                 NULL,
8582         },
8583 };
8584
8585 /* *** ADD/REMOVE A flex FILTER *** */
8586 struct cmd_flex_filter_result {
8587         cmdline_fixed_string_t filter;
8588         cmdline_fixed_string_t ops;
8589         uint8_t port_id;
8590         cmdline_fixed_string_t len;
8591         uint8_t len_value;
8592         cmdline_fixed_string_t bytes;
8593         cmdline_fixed_string_t bytes_value;
8594         cmdline_fixed_string_t mask;
8595         cmdline_fixed_string_t mask_value;
8596         cmdline_fixed_string_t priority;
8597         uint8_t priority_value;
8598         cmdline_fixed_string_t queue;
8599         uint16_t queue_id;
8600 };
8601
8602 static int xdigit2val(unsigned char c)
8603 {
8604         int val;
8605         if (isdigit(c))
8606                 val = c - '0';
8607         else if (isupper(c))
8608                 val = c - 'A' + 10;
8609         else
8610                 val = c - 'a' + 10;
8611         return val;
8612 }
8613
8614 static void
8615 cmd_flex_filter_parsed(void *parsed_result,
8616                           __attribute__((unused)) struct cmdline *cl,
8617                           __attribute__((unused)) void *data)
8618 {
8619         int ret = 0;
8620         struct rte_eth_flex_filter filter;
8621         struct cmd_flex_filter_result *res = parsed_result;
8622         char *bytes_ptr, *mask_ptr;
8623         uint16_t len, i, j = 0;
8624         char c;
8625         int val;
8626         uint8_t byte = 0;
8627
8628         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8629                 printf("the len exceed the max length 128\n");
8630                 return;
8631         }
8632         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8633         filter.len = res->len_value;
8634         filter.priority = res->priority_value;
8635         filter.queue = res->queue_id;
8636         bytes_ptr = res->bytes_value;
8637         mask_ptr = res->mask_value;
8638
8639          /* translate bytes string to array. */
8640         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8641                 (bytes_ptr[1] == 'X')))
8642                 bytes_ptr += 2;
8643         len = strnlen(bytes_ptr, res->len_value * 2);
8644         if (len == 0 || (len % 8 != 0)) {
8645                 printf("please check len and bytes input\n");
8646                 return;
8647         }
8648         for (i = 0; i < len; i++) {
8649                 c = bytes_ptr[i];
8650                 if (isxdigit(c) == 0) {
8651                         /* invalid characters. */
8652                         printf("invalid input\n");
8653                         return;
8654                 }
8655                 val = xdigit2val(c);
8656                 if (i % 2) {
8657                         byte |= val;
8658                         filter.bytes[j] = byte;
8659                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8660                         j++;
8661                         byte = 0;
8662                 } else
8663                         byte |= val << 4;
8664         }
8665         printf("\n");
8666          /* translate mask string to uint8_t array. */
8667         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8668                 (mask_ptr[1] == 'X')))
8669                 mask_ptr += 2;
8670         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8671         if (len == 0) {
8672                 printf("invalid input\n");
8673                 return;
8674         }
8675         j = 0;
8676         byte = 0;
8677         for (i = 0; i < len; i++) {
8678                 c = mask_ptr[i];
8679                 if (isxdigit(c) == 0) {
8680                         /* invalid characters. */
8681                         printf("invalid input\n");
8682                         return;
8683                 }
8684                 val = xdigit2val(c);
8685                 if (i % 2) {
8686                         byte |= val;
8687                         filter.mask[j] = byte;
8688                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8689                         j++;
8690                         byte = 0;
8691                 } else
8692                         byte |= val << 4;
8693         }
8694         printf("\n");
8695
8696         if (!strcmp(res->ops, "add"))
8697                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8698                                 RTE_ETH_FILTER_FLEXIBLE,
8699                                 RTE_ETH_FILTER_ADD,
8700                                 &filter);
8701         else
8702                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8703                                 RTE_ETH_FILTER_FLEXIBLE,
8704                                 RTE_ETH_FILTER_DELETE,
8705                                 &filter);
8706
8707         if (ret < 0)
8708                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8709 }
8710
8711 cmdline_parse_token_string_t cmd_flex_filter_filter =
8712         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8713                                 filter, "flex_filter");
8714 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8715         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8716                                 port_id, UINT8);
8717 cmdline_parse_token_string_t cmd_flex_filter_ops =
8718         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8719                                 ops, "add#del");
8720 cmdline_parse_token_string_t cmd_flex_filter_len =
8721         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8722                                 len, "len");
8723 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8724         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8725                                 len_value, UINT8);
8726 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8727         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8728                                 bytes, "bytes");
8729 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8730         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8731                                 bytes_value, NULL);
8732 cmdline_parse_token_string_t cmd_flex_filter_mask =
8733         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8734                                 mask, "mask");
8735 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8736         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8737                                 mask_value, NULL);
8738 cmdline_parse_token_string_t cmd_flex_filter_priority =
8739         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8740                                 priority, "priority");
8741 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8742         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8743                                 priority_value, UINT8);
8744 cmdline_parse_token_string_t cmd_flex_filter_queue =
8745         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8746                                 queue, "queue");
8747 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8748         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8749                                 queue_id, UINT16);
8750 cmdline_parse_inst_t cmd_flex_filter = {
8751         .f = cmd_flex_filter_parsed,
8752         .data = NULL,
8753         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8754                 "<value> mask <value> priority <value> queue <queue_id>: "
8755                 "Add/Del a flex filter",
8756         .tokens = {
8757                 (void *)&cmd_flex_filter_filter,
8758                 (void *)&cmd_flex_filter_port_id,
8759                 (void *)&cmd_flex_filter_ops,
8760                 (void *)&cmd_flex_filter_len,
8761                 (void *)&cmd_flex_filter_len_value,
8762                 (void *)&cmd_flex_filter_bytes,
8763                 (void *)&cmd_flex_filter_bytes_value,
8764                 (void *)&cmd_flex_filter_mask,
8765                 (void *)&cmd_flex_filter_mask_value,
8766                 (void *)&cmd_flex_filter_priority,
8767                 (void *)&cmd_flex_filter_priority_value,
8768                 (void *)&cmd_flex_filter_queue,
8769                 (void *)&cmd_flex_filter_queue_id,
8770                 NULL,
8771         },
8772 };
8773
8774 /* *** Filters Control *** */
8775
8776 /* *** deal with ethertype filter *** */
8777 struct cmd_ethertype_filter_result {
8778         cmdline_fixed_string_t filter;
8779         uint8_t port_id;
8780         cmdline_fixed_string_t ops;
8781         cmdline_fixed_string_t mac;
8782         struct ether_addr mac_addr;
8783         cmdline_fixed_string_t ethertype;
8784         uint16_t ethertype_value;
8785         cmdline_fixed_string_t drop;
8786         cmdline_fixed_string_t queue;
8787         uint16_t  queue_id;
8788 };
8789
8790 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8791         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8792                                  filter, "ethertype_filter");
8793 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8794         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8795                               port_id, UINT8);
8796 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8797         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8798                                  ops, "add#del");
8799 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8800         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8801                                  mac, "mac_addr#mac_ignr");
8802 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8803         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8804                                      mac_addr);
8805 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8806         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8807                                  ethertype, "ethertype");
8808 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8809         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8810                               ethertype_value, UINT16);
8811 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8812         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8813                                  drop, "drop#fwd");
8814 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8815         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8816                                  queue, "queue");
8817 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8818         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8819                               queue_id, UINT16);
8820
8821 static void
8822 cmd_ethertype_filter_parsed(void *parsed_result,
8823                           __attribute__((unused)) struct cmdline *cl,
8824                           __attribute__((unused)) void *data)
8825 {
8826         struct cmd_ethertype_filter_result *res = parsed_result;
8827         struct rte_eth_ethertype_filter filter;
8828         int ret = 0;
8829
8830         ret = rte_eth_dev_filter_supported(res->port_id,
8831                         RTE_ETH_FILTER_ETHERTYPE);
8832         if (ret < 0) {
8833                 printf("ethertype filter is not supported on port %u.\n",
8834                         res->port_id);
8835                 return;
8836         }
8837
8838         memset(&filter, 0, sizeof(filter));
8839         if (!strcmp(res->mac, "mac_addr")) {
8840                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8841                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
8842                         sizeof(struct ether_addr));
8843         }
8844         if (!strcmp(res->drop, "drop"))
8845                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8846         filter.ether_type = res->ethertype_value;
8847         filter.queue = res->queue_id;
8848
8849         if (!strcmp(res->ops, "add"))
8850                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8851                                 RTE_ETH_FILTER_ETHERTYPE,
8852                                 RTE_ETH_FILTER_ADD,
8853                                 &filter);
8854         else
8855                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8856                                 RTE_ETH_FILTER_ETHERTYPE,
8857                                 RTE_ETH_FILTER_DELETE,
8858                                 &filter);
8859         if (ret < 0)
8860                 printf("ethertype filter programming error: (%s)\n",
8861                         strerror(-ret));
8862 }
8863
8864 cmdline_parse_inst_t cmd_ethertype_filter = {
8865         .f = cmd_ethertype_filter_parsed,
8866         .data = NULL,
8867         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8868                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8869                 "Add or delete an ethertype filter entry",
8870         .tokens = {
8871                 (void *)&cmd_ethertype_filter_filter,
8872                 (void *)&cmd_ethertype_filter_port_id,
8873                 (void *)&cmd_ethertype_filter_ops,
8874                 (void *)&cmd_ethertype_filter_mac,
8875                 (void *)&cmd_ethertype_filter_mac_addr,
8876                 (void *)&cmd_ethertype_filter_ethertype,
8877                 (void *)&cmd_ethertype_filter_ethertype_value,
8878                 (void *)&cmd_ethertype_filter_drop,
8879                 (void *)&cmd_ethertype_filter_queue,
8880                 (void *)&cmd_ethertype_filter_queue_id,
8881                 NULL,
8882         },
8883 };
8884
8885 /* *** deal with flow director filter *** */
8886 struct cmd_flow_director_result {
8887         cmdline_fixed_string_t flow_director_filter;
8888         uint8_t port_id;
8889         cmdline_fixed_string_t mode;
8890         cmdline_fixed_string_t mode_value;
8891         cmdline_fixed_string_t ops;
8892         cmdline_fixed_string_t flow;
8893         cmdline_fixed_string_t flow_type;
8894         cmdline_fixed_string_t ether;
8895         uint16_t ether_type;
8896         cmdline_fixed_string_t src;
8897         cmdline_ipaddr_t ip_src;
8898         uint16_t port_src;
8899         cmdline_fixed_string_t dst;
8900         cmdline_ipaddr_t ip_dst;
8901         uint16_t port_dst;
8902         cmdline_fixed_string_t verify_tag;
8903         uint32_t verify_tag_value;
8904         cmdline_ipaddr_t tos;
8905         uint8_t tos_value;
8906         cmdline_ipaddr_t proto;
8907         uint8_t proto_value;
8908         cmdline_ipaddr_t ttl;
8909         uint8_t ttl_value;
8910         cmdline_fixed_string_t vlan;
8911         uint16_t vlan_value;
8912         cmdline_fixed_string_t flexbytes;
8913         cmdline_fixed_string_t flexbytes_value;
8914         cmdline_fixed_string_t pf_vf;
8915         cmdline_fixed_string_t drop;
8916         cmdline_fixed_string_t queue;
8917         uint16_t  queue_id;
8918         cmdline_fixed_string_t fd_id;
8919         uint32_t  fd_id_value;
8920         cmdline_fixed_string_t mac;
8921         struct ether_addr mac_addr;
8922         cmdline_fixed_string_t tunnel;
8923         cmdline_fixed_string_t tunnel_type;
8924         cmdline_fixed_string_t tunnel_id;
8925         uint32_t tunnel_id_value;
8926 };
8927
8928 static inline int
8929 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8930 {
8931         char s[256];
8932         const char *p, *p0 = q_arg;
8933         char *end;
8934         unsigned long int_fld;
8935         char *str_fld[max_num];
8936         int i;
8937         unsigned size;
8938         int ret = -1;
8939
8940         p = strchr(p0, '(');
8941         if (p == NULL)
8942                 return -1;
8943         ++p;
8944         p0 = strchr(p, ')');
8945         if (p0 == NULL)
8946                 return -1;
8947
8948         size = p0 - p;
8949         if (size >= sizeof(s))
8950                 return -1;
8951
8952         snprintf(s, sizeof(s), "%.*s", size, p);
8953         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8954         if (ret < 0 || ret > max_num)
8955                 return -1;
8956         for (i = 0; i < ret; i++) {
8957                 errno = 0;
8958                 int_fld = strtoul(str_fld[i], &end, 0);
8959                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8960                         return -1;
8961                 flexbytes[i] = (uint8_t)int_fld;
8962         }
8963         return ret;
8964 }
8965
8966 static uint16_t
8967 str2flowtype(char *string)
8968 {
8969         uint8_t i = 0;
8970         static const struct {
8971                 char str[32];
8972                 uint16_t type;
8973         } flowtype_str[] = {
8974                 {"raw", RTE_ETH_FLOW_RAW},
8975                 {"ipv4", RTE_ETH_FLOW_IPV4},
8976                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8977                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8978                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8979                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8980                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8981                 {"ipv6", RTE_ETH_FLOW_IPV6},
8982                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8983                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8984                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8985                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8986                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8987                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8988         };
8989
8990         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8991                 if (!strcmp(flowtype_str[i].str, string))
8992                         return flowtype_str[i].type;
8993         }
8994         return RTE_ETH_FLOW_UNKNOWN;
8995 }
8996
8997 static enum rte_eth_fdir_tunnel_type
8998 str2fdir_tunneltype(char *string)
8999 {
9000         uint8_t i = 0;
9001
9002         static const struct {
9003                 char str[32];
9004                 enum rte_eth_fdir_tunnel_type type;
9005         } tunneltype_str[] = {
9006                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9007                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9008         };
9009
9010         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9011                 if (!strcmp(tunneltype_str[i].str, string))
9012                         return tunneltype_str[i].type;
9013         }
9014         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9015 }
9016
9017 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9018 do { \
9019         if ((ip_addr).family == AF_INET) \
9020                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9021         else { \
9022                 printf("invalid parameter.\n"); \
9023                 return; \
9024         } \
9025 } while (0)
9026
9027 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9028 do { \
9029         if ((ip_addr).family == AF_INET6) \
9030                 rte_memcpy(&(ip), \
9031                                  &((ip_addr).addr.ipv6), \
9032                                  sizeof(struct in6_addr)); \
9033         else { \
9034                 printf("invalid parameter.\n"); \
9035                 return; \
9036         } \
9037 } while (0)
9038
9039 static void
9040 cmd_flow_director_filter_parsed(void *parsed_result,
9041                           __attribute__((unused)) struct cmdline *cl,
9042                           __attribute__((unused)) void *data)
9043 {
9044         struct cmd_flow_director_result *res = parsed_result;
9045         struct rte_eth_fdir_filter entry;
9046         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9047         char *end;
9048         unsigned long vf_id;
9049         int ret = 0;
9050
9051         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9052         if (ret < 0) {
9053                 printf("flow director is not supported on port %u.\n",
9054                         res->port_id);
9055                 return;
9056         }
9057         memset(flexbytes, 0, sizeof(flexbytes));
9058         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9059
9060         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9061                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9062                         printf("Please set mode to MAC-VLAN.\n");
9063                         return;
9064                 }
9065         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9066                 if (strcmp(res->mode_value, "Tunnel")) {
9067                         printf("Please set mode to Tunnel.\n");
9068                         return;
9069                 }
9070         } else {
9071                 if (strcmp(res->mode_value, "IP")) {
9072                         printf("Please set mode to IP.\n");
9073                         return;
9074                 }
9075                 entry.input.flow_type = str2flowtype(res->flow_type);
9076         }
9077
9078         ret = parse_flexbytes(res->flexbytes_value,
9079                                         flexbytes,
9080                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9081         if (ret < 0) {
9082                 printf("error: Cannot parse flexbytes input.\n");
9083                 return;
9084         }
9085
9086         switch (entry.input.flow_type) {
9087         case RTE_ETH_FLOW_FRAG_IPV4:
9088         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9089                 entry.input.flow.ip4_flow.proto = res->proto_value;
9090                 /* fall-through */
9091         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9092         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9093                 IPV4_ADDR_TO_UINT(res->ip_dst,
9094                         entry.input.flow.ip4_flow.dst_ip);
9095                 IPV4_ADDR_TO_UINT(res->ip_src,
9096                         entry.input.flow.ip4_flow.src_ip);
9097                 entry.input.flow.ip4_flow.tos = res->tos_value;
9098                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9099                 /* need convert to big endian. */
9100                 entry.input.flow.udp4_flow.dst_port =
9101                                 rte_cpu_to_be_16(res->port_dst);
9102                 entry.input.flow.udp4_flow.src_port =
9103                                 rte_cpu_to_be_16(res->port_src);
9104                 break;
9105         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9106                 IPV4_ADDR_TO_UINT(res->ip_dst,
9107                         entry.input.flow.sctp4_flow.ip.dst_ip);
9108                 IPV4_ADDR_TO_UINT(res->ip_src,
9109                         entry.input.flow.sctp4_flow.ip.src_ip);
9110                 entry.input.flow.ip4_flow.tos = res->tos_value;
9111                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9112                 /* need convert to big endian. */
9113                 entry.input.flow.sctp4_flow.dst_port =
9114                                 rte_cpu_to_be_16(res->port_dst);
9115                 entry.input.flow.sctp4_flow.src_port =
9116                                 rte_cpu_to_be_16(res->port_src);
9117                 entry.input.flow.sctp4_flow.verify_tag =
9118                                 rte_cpu_to_be_32(res->verify_tag_value);
9119                 break;
9120         case RTE_ETH_FLOW_FRAG_IPV6:
9121         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9122                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9123                 /* fall-through */
9124         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9125         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9126                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9127                         entry.input.flow.ipv6_flow.dst_ip);
9128                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9129                         entry.input.flow.ipv6_flow.src_ip);
9130                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9131                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9132                 /* need convert to big endian. */
9133                 entry.input.flow.udp6_flow.dst_port =
9134                                 rte_cpu_to_be_16(res->port_dst);
9135                 entry.input.flow.udp6_flow.src_port =
9136                                 rte_cpu_to_be_16(res->port_src);
9137                 break;
9138         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9139                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9140                         entry.input.flow.sctp6_flow.ip.dst_ip);
9141                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9142                         entry.input.flow.sctp6_flow.ip.src_ip);
9143                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9144                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9145                 /* need convert to big endian. */
9146                 entry.input.flow.sctp6_flow.dst_port =
9147                                 rte_cpu_to_be_16(res->port_dst);
9148                 entry.input.flow.sctp6_flow.src_port =
9149                                 rte_cpu_to_be_16(res->port_src);
9150                 entry.input.flow.sctp6_flow.verify_tag =
9151                                 rte_cpu_to_be_32(res->verify_tag_value);
9152                 break;
9153         case RTE_ETH_FLOW_L2_PAYLOAD:
9154                 entry.input.flow.l2_flow.ether_type =
9155                         rte_cpu_to_be_16(res->ether_type);
9156                 break;
9157         default:
9158                 break;
9159         }
9160
9161         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9162                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9163                                  &res->mac_addr,
9164                                  sizeof(struct ether_addr));
9165
9166         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9167                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9168                                  &res->mac_addr,
9169                                  sizeof(struct ether_addr));
9170                 entry.input.flow.tunnel_flow.tunnel_type =
9171                         str2fdir_tunneltype(res->tunnel_type);
9172                 entry.input.flow.tunnel_flow.tunnel_id =
9173                         rte_cpu_to_be_32(res->tunnel_id_value);
9174         }
9175
9176         rte_memcpy(entry.input.flow_ext.flexbytes,
9177                    flexbytes,
9178                    RTE_ETH_FDIR_MAX_FLEXLEN);
9179
9180         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9181
9182         entry.action.flex_off = 0;  /*use 0 by default */
9183         if (!strcmp(res->drop, "drop"))
9184                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9185         else
9186                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9187
9188         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9189             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9190                 if (!strcmp(res->pf_vf, "pf"))
9191                         entry.input.flow_ext.is_vf = 0;
9192                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9193                         struct rte_eth_dev_info dev_info;
9194
9195                         memset(&dev_info, 0, sizeof(dev_info));
9196                         rte_eth_dev_info_get(res->port_id, &dev_info);
9197                         errno = 0;
9198                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9199                         if (errno != 0 || *end != '\0' ||
9200                             vf_id >= dev_info.max_vfs) {
9201                                 printf("invalid parameter %s.\n", res->pf_vf);
9202                                 return;
9203                         }
9204                         entry.input.flow_ext.is_vf = 1;
9205                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9206                 } else {
9207                         printf("invalid parameter %s.\n", res->pf_vf);
9208                         return;
9209                 }
9210         }
9211
9212         /* set to report FD ID by default */
9213         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9214         entry.action.rx_queue = res->queue_id;
9215         entry.soft_id = res->fd_id_value;
9216         if (!strcmp(res->ops, "add"))
9217                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9218                                              RTE_ETH_FILTER_ADD, &entry);
9219         else if (!strcmp(res->ops, "del"))
9220                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9221                                              RTE_ETH_FILTER_DELETE, &entry);
9222         else
9223                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9224                                              RTE_ETH_FILTER_UPDATE, &entry);
9225         if (ret < 0)
9226                 printf("flow director programming error: (%s)\n",
9227                         strerror(-ret));
9228 }
9229
9230 cmdline_parse_token_string_t cmd_flow_director_filter =
9231         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9232                                  flow_director_filter, "flow_director_filter");
9233 cmdline_parse_token_num_t cmd_flow_director_port_id =
9234         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9235                               port_id, UINT8);
9236 cmdline_parse_token_string_t cmd_flow_director_ops =
9237         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9238                                  ops, "add#del#update");
9239 cmdline_parse_token_string_t cmd_flow_director_flow =
9240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9241                                  flow, "flow");
9242 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9244                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9245                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9246 cmdline_parse_token_string_t cmd_flow_director_ether =
9247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9248                                  ether, "ether");
9249 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9250         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9251                               ether_type, UINT16);
9252 cmdline_parse_token_string_t cmd_flow_director_src =
9253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9254                                  src, "src");
9255 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9256         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9257                                  ip_src);
9258 cmdline_parse_token_num_t cmd_flow_director_port_src =
9259         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9260                               port_src, UINT16);
9261 cmdline_parse_token_string_t cmd_flow_director_dst =
9262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9263                                  dst, "dst");
9264 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9265         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9266                                  ip_dst);
9267 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9268         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9269                               port_dst, UINT16);
9270 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9272                                   verify_tag, "verify_tag");
9273 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9274         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9275                               verify_tag_value, UINT32);
9276 cmdline_parse_token_string_t cmd_flow_director_tos =
9277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9278                                  tos, "tos");
9279 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9280         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9281                               tos_value, UINT8);
9282 cmdline_parse_token_string_t cmd_flow_director_proto =
9283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9284                                  proto, "proto");
9285 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9286         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9287                               proto_value, UINT8);
9288 cmdline_parse_token_string_t cmd_flow_director_ttl =
9289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9290                                  ttl, "ttl");
9291 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9292         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9293                               ttl_value, UINT8);
9294 cmdline_parse_token_string_t cmd_flow_director_vlan =
9295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9296                                  vlan, "vlan");
9297 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9298         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9299                               vlan_value, UINT16);
9300 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9302                                  flexbytes, "flexbytes");
9303 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9304         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9305                               flexbytes_value, NULL);
9306 cmdline_parse_token_string_t cmd_flow_director_drop =
9307         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9308                                  drop, "drop#fwd");
9309 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9311                               pf_vf, NULL);
9312 cmdline_parse_token_string_t cmd_flow_director_queue =
9313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9314                                  queue, "queue");
9315 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9316         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9317                               queue_id, UINT16);
9318 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9320                                  fd_id, "fd_id");
9321 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9322         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9323                               fd_id_value, UINT32);
9324
9325 cmdline_parse_token_string_t cmd_flow_director_mode =
9326         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9327                                  mode, "mode");
9328 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9330                                  mode_value, "IP");
9331 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9333                                  mode_value, "MAC-VLAN");
9334 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9335         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9336                                  mode_value, "Tunnel");
9337 cmdline_parse_token_string_t cmd_flow_director_mac =
9338         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9339                                  mac, "mac");
9340 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9341         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9342                                     mac_addr);
9343 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9345                                  tunnel, "tunnel");
9346 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9348                                  tunnel_type, "NVGRE#VxLAN");
9349 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9351                                  tunnel_id, "tunnel-id");
9352 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9353         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9354                               tunnel_id_value, UINT32);
9355
9356 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9357         .f = cmd_flow_director_filter_parsed,
9358         .data = NULL,
9359         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9360                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9361                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9362                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9363                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9364                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9365                 "fd_id <fd_id_value>: "
9366                 "Add or delete an ip flow director entry on NIC",
9367         .tokens = {
9368                 (void *)&cmd_flow_director_filter,
9369                 (void *)&cmd_flow_director_port_id,
9370                 (void *)&cmd_flow_director_mode,
9371                 (void *)&cmd_flow_director_mode_ip,
9372                 (void *)&cmd_flow_director_ops,
9373                 (void *)&cmd_flow_director_flow,
9374                 (void *)&cmd_flow_director_flow_type,
9375                 (void *)&cmd_flow_director_src,
9376                 (void *)&cmd_flow_director_ip_src,
9377                 (void *)&cmd_flow_director_dst,
9378                 (void *)&cmd_flow_director_ip_dst,
9379                 (void *)&cmd_flow_director_tos,
9380                 (void *)&cmd_flow_director_tos_value,
9381                 (void *)&cmd_flow_director_proto,
9382                 (void *)&cmd_flow_director_proto_value,
9383                 (void *)&cmd_flow_director_ttl,
9384                 (void *)&cmd_flow_director_ttl_value,
9385                 (void *)&cmd_flow_director_vlan,
9386                 (void *)&cmd_flow_director_vlan_value,
9387                 (void *)&cmd_flow_director_flexbytes,
9388                 (void *)&cmd_flow_director_flexbytes_value,
9389                 (void *)&cmd_flow_director_drop,
9390                 (void *)&cmd_flow_director_pf_vf,
9391                 (void *)&cmd_flow_director_queue,
9392                 (void *)&cmd_flow_director_queue_id,
9393                 (void *)&cmd_flow_director_fd_id,
9394                 (void *)&cmd_flow_director_fd_id_value,
9395                 NULL,
9396         },
9397 };
9398
9399 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9400         .f = cmd_flow_director_filter_parsed,
9401         .data = NULL,
9402         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9403                 "director entry on NIC",
9404         .tokens = {
9405                 (void *)&cmd_flow_director_filter,
9406                 (void *)&cmd_flow_director_port_id,
9407                 (void *)&cmd_flow_director_mode,
9408                 (void *)&cmd_flow_director_mode_ip,
9409                 (void *)&cmd_flow_director_ops,
9410                 (void *)&cmd_flow_director_flow,
9411                 (void *)&cmd_flow_director_flow_type,
9412                 (void *)&cmd_flow_director_src,
9413                 (void *)&cmd_flow_director_ip_src,
9414                 (void *)&cmd_flow_director_port_src,
9415                 (void *)&cmd_flow_director_dst,
9416                 (void *)&cmd_flow_director_ip_dst,
9417                 (void *)&cmd_flow_director_port_dst,
9418                 (void *)&cmd_flow_director_tos,
9419                 (void *)&cmd_flow_director_tos_value,
9420                 (void *)&cmd_flow_director_ttl,
9421                 (void *)&cmd_flow_director_ttl_value,
9422                 (void *)&cmd_flow_director_vlan,
9423                 (void *)&cmd_flow_director_vlan_value,
9424                 (void *)&cmd_flow_director_flexbytes,
9425                 (void *)&cmd_flow_director_flexbytes_value,
9426                 (void *)&cmd_flow_director_drop,
9427                 (void *)&cmd_flow_director_pf_vf,
9428                 (void *)&cmd_flow_director_queue,
9429                 (void *)&cmd_flow_director_queue_id,
9430                 (void *)&cmd_flow_director_fd_id,
9431                 (void *)&cmd_flow_director_fd_id_value,
9432                 NULL,
9433         },
9434 };
9435
9436 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9437         .f = cmd_flow_director_filter_parsed,
9438         .data = NULL,
9439         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9440                 "director entry on NIC",
9441         .tokens = {
9442                 (void *)&cmd_flow_director_filter,
9443                 (void *)&cmd_flow_director_port_id,
9444                 (void *)&cmd_flow_director_mode,
9445                 (void *)&cmd_flow_director_mode_ip,
9446                 (void *)&cmd_flow_director_ops,
9447                 (void *)&cmd_flow_director_flow,
9448                 (void *)&cmd_flow_director_flow_type,
9449                 (void *)&cmd_flow_director_src,
9450                 (void *)&cmd_flow_director_ip_src,
9451                 (void *)&cmd_flow_director_port_dst,
9452                 (void *)&cmd_flow_director_dst,
9453                 (void *)&cmd_flow_director_ip_dst,
9454                 (void *)&cmd_flow_director_port_dst,
9455                 (void *)&cmd_flow_director_verify_tag,
9456                 (void *)&cmd_flow_director_verify_tag_value,
9457                 (void *)&cmd_flow_director_tos,
9458                 (void *)&cmd_flow_director_tos_value,
9459                 (void *)&cmd_flow_director_ttl,
9460                 (void *)&cmd_flow_director_ttl_value,
9461                 (void *)&cmd_flow_director_vlan,
9462                 (void *)&cmd_flow_director_vlan_value,
9463                 (void *)&cmd_flow_director_flexbytes,
9464                 (void *)&cmd_flow_director_flexbytes_value,
9465                 (void *)&cmd_flow_director_drop,
9466                 (void *)&cmd_flow_director_pf_vf,
9467                 (void *)&cmd_flow_director_queue,
9468                 (void *)&cmd_flow_director_queue_id,
9469                 (void *)&cmd_flow_director_fd_id,
9470                 (void *)&cmd_flow_director_fd_id_value,
9471                 NULL,
9472         },
9473 };
9474
9475 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9476         .f = cmd_flow_director_filter_parsed,
9477         .data = NULL,
9478         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9479                 "director entry on NIC",
9480         .tokens = {
9481                 (void *)&cmd_flow_director_filter,
9482                 (void *)&cmd_flow_director_port_id,
9483                 (void *)&cmd_flow_director_mode,
9484                 (void *)&cmd_flow_director_mode_ip,
9485                 (void *)&cmd_flow_director_ops,
9486                 (void *)&cmd_flow_director_flow,
9487                 (void *)&cmd_flow_director_flow_type,
9488                 (void *)&cmd_flow_director_ether,
9489                 (void *)&cmd_flow_director_ether_type,
9490                 (void *)&cmd_flow_director_flexbytes,
9491                 (void *)&cmd_flow_director_flexbytes_value,
9492                 (void *)&cmd_flow_director_drop,
9493                 (void *)&cmd_flow_director_pf_vf,
9494                 (void *)&cmd_flow_director_queue,
9495                 (void *)&cmd_flow_director_queue_id,
9496                 (void *)&cmd_flow_director_fd_id,
9497                 (void *)&cmd_flow_director_fd_id_value,
9498                 NULL,
9499         },
9500 };
9501
9502 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9503         .f = cmd_flow_director_filter_parsed,
9504         .data = NULL,
9505         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9506                 "director entry on NIC",
9507         .tokens = {
9508                 (void *)&cmd_flow_director_filter,
9509                 (void *)&cmd_flow_director_port_id,
9510                 (void *)&cmd_flow_director_mode,
9511                 (void *)&cmd_flow_director_mode_mac_vlan,
9512                 (void *)&cmd_flow_director_ops,
9513                 (void *)&cmd_flow_director_mac,
9514                 (void *)&cmd_flow_director_mac_addr,
9515                 (void *)&cmd_flow_director_vlan,
9516                 (void *)&cmd_flow_director_vlan_value,
9517                 (void *)&cmd_flow_director_flexbytes,
9518                 (void *)&cmd_flow_director_flexbytes_value,
9519                 (void *)&cmd_flow_director_drop,
9520                 (void *)&cmd_flow_director_queue,
9521                 (void *)&cmd_flow_director_queue_id,
9522                 (void *)&cmd_flow_director_fd_id,
9523                 (void *)&cmd_flow_director_fd_id_value,
9524                 NULL,
9525         },
9526 };
9527
9528 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9529         .f = cmd_flow_director_filter_parsed,
9530         .data = NULL,
9531         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9532                 "director entry on NIC",
9533         .tokens = {
9534                 (void *)&cmd_flow_director_filter,
9535                 (void *)&cmd_flow_director_port_id,
9536                 (void *)&cmd_flow_director_mode,
9537                 (void *)&cmd_flow_director_mode_tunnel,
9538                 (void *)&cmd_flow_director_ops,
9539                 (void *)&cmd_flow_director_mac,
9540                 (void *)&cmd_flow_director_mac_addr,
9541                 (void *)&cmd_flow_director_vlan,
9542                 (void *)&cmd_flow_director_vlan_value,
9543                 (void *)&cmd_flow_director_tunnel,
9544                 (void *)&cmd_flow_director_tunnel_type,
9545                 (void *)&cmd_flow_director_tunnel_id,
9546                 (void *)&cmd_flow_director_tunnel_id_value,
9547                 (void *)&cmd_flow_director_flexbytes,
9548                 (void *)&cmd_flow_director_flexbytes_value,
9549                 (void *)&cmd_flow_director_drop,
9550                 (void *)&cmd_flow_director_queue,
9551                 (void *)&cmd_flow_director_queue_id,
9552                 (void *)&cmd_flow_director_fd_id,
9553                 (void *)&cmd_flow_director_fd_id_value,
9554                 NULL,
9555         },
9556 };
9557
9558 struct cmd_flush_flow_director_result {
9559         cmdline_fixed_string_t flush_flow_director;
9560         uint8_t port_id;
9561 };
9562
9563 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9564         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9565                                  flush_flow_director, "flush_flow_director");
9566 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9567         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9568                               port_id, UINT8);
9569
9570 static void
9571 cmd_flush_flow_director_parsed(void *parsed_result,
9572                           __attribute__((unused)) struct cmdline *cl,
9573                           __attribute__((unused)) void *data)
9574 {
9575         struct cmd_flow_director_result *res = parsed_result;
9576         int ret = 0;
9577
9578         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9579         if (ret < 0) {
9580                 printf("flow director is not supported on port %u.\n",
9581                         res->port_id);
9582                 return;
9583         }
9584
9585         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9586                         RTE_ETH_FILTER_FLUSH, NULL);
9587         if (ret < 0)
9588                 printf("flow director table flushing error: (%s)\n",
9589                         strerror(-ret));
9590 }
9591
9592 cmdline_parse_inst_t cmd_flush_flow_director = {
9593         .f = cmd_flush_flow_director_parsed,
9594         .data = NULL,
9595         .help_str = "flush_flow_director <port_id>: "
9596                 "Flush all flow director entries of a device on NIC",
9597         .tokens = {
9598                 (void *)&cmd_flush_flow_director_flush,
9599                 (void *)&cmd_flush_flow_director_port_id,
9600                 NULL,
9601         },
9602 };
9603
9604 /* *** deal with flow director mask *** */
9605 struct cmd_flow_director_mask_result {
9606         cmdline_fixed_string_t flow_director_mask;
9607         uint8_t port_id;
9608         cmdline_fixed_string_t mode;
9609         cmdline_fixed_string_t mode_value;
9610         cmdline_fixed_string_t vlan;
9611         uint16_t vlan_mask;
9612         cmdline_fixed_string_t src_mask;
9613         cmdline_ipaddr_t ipv4_src;
9614         cmdline_ipaddr_t ipv6_src;
9615         uint16_t port_src;
9616         cmdline_fixed_string_t dst_mask;
9617         cmdline_ipaddr_t ipv4_dst;
9618         cmdline_ipaddr_t ipv6_dst;
9619         uint16_t port_dst;
9620         cmdline_fixed_string_t mac;
9621         uint8_t mac_addr_byte_mask;
9622         cmdline_fixed_string_t tunnel_id;
9623         uint32_t tunnel_id_mask;
9624         cmdline_fixed_string_t tunnel_type;
9625         uint8_t tunnel_type_mask;
9626 };
9627
9628 static void
9629 cmd_flow_director_mask_parsed(void *parsed_result,
9630                           __attribute__((unused)) struct cmdline *cl,
9631                           __attribute__((unused)) void *data)
9632 {
9633         struct cmd_flow_director_mask_result *res = parsed_result;
9634         struct rte_eth_fdir_masks *mask;
9635         struct rte_port *port;
9636
9637         if (res->port_id > nb_ports) {
9638                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9639                 return;
9640         }
9641
9642         port = &ports[res->port_id];
9643         /** Check if the port is not started **/
9644         if (port->port_status != RTE_PORT_STOPPED) {
9645                 printf("Please stop port %d first\n", res->port_id);
9646                 return;
9647         }
9648
9649         mask = &port->dev_conf.fdir_conf.mask;
9650
9651         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9652                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9653                         printf("Please set mode to MAC-VLAN.\n");
9654                         return;
9655                 }
9656
9657                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9658         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9659                 if (strcmp(res->mode_value, "Tunnel")) {
9660                         printf("Please set mode to Tunnel.\n");
9661                         return;
9662                 }
9663
9664                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9665                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9666                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9667                 mask->tunnel_type_mask = res->tunnel_type_mask;
9668         } else {
9669                 if (strcmp(res->mode_value, "IP")) {
9670                         printf("Please set mode to IP.\n");
9671                         return;
9672                 }
9673
9674                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9675                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9676                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9677                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9678                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9679                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9680                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9681         }
9682
9683         cmd_reconfig_device_queue(res->port_id, 1, 1);
9684 }
9685
9686 cmdline_parse_token_string_t cmd_flow_director_mask =
9687         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9688                                  flow_director_mask, "flow_director_mask");
9689 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9690         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9691                               port_id, UINT8);
9692 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9694                                  vlan, "vlan");
9695 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9696         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9697                               vlan_mask, UINT16);
9698 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9700                                  src_mask, "src_mask");
9701 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9702         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9703                                  ipv4_src);
9704 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9705         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9706                                  ipv6_src);
9707 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9708         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9709                               port_src, UINT16);
9710 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9712                                  dst_mask, "dst_mask");
9713 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9714         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9715                                  ipv4_dst);
9716 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9717         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9718                                  ipv6_dst);
9719 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9720         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9721                               port_dst, UINT16);
9722
9723 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9724         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9725                                  mode, "mode");
9726 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9727         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9728                                  mode_value, "IP");
9729 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9731                                  mode_value, "MAC-VLAN");
9732 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9734                                  mode_value, "Tunnel");
9735 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9737                                  mac, "mac");
9738 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9739         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9740                               mac_addr_byte_mask, UINT8);
9741 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9743                                  tunnel_type, "tunnel-type");
9744 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9746                               tunnel_type_mask, UINT8);
9747 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9749                                  tunnel_id, "tunnel-id");
9750 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9752                               tunnel_id_mask, UINT32);
9753
9754 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9755         .f = cmd_flow_director_mask_parsed,
9756         .data = NULL,
9757         .help_str = "flow_director_mask ... : "
9758                 "Set IP mode flow director's mask on NIC",
9759         .tokens = {
9760                 (void *)&cmd_flow_director_mask,
9761                 (void *)&cmd_flow_director_mask_port_id,
9762                 (void *)&cmd_flow_director_mask_mode,
9763                 (void *)&cmd_flow_director_mask_mode_ip,
9764                 (void *)&cmd_flow_director_mask_vlan,
9765                 (void *)&cmd_flow_director_mask_vlan_value,
9766                 (void *)&cmd_flow_director_mask_src,
9767                 (void *)&cmd_flow_director_mask_ipv4_src,
9768                 (void *)&cmd_flow_director_mask_ipv6_src,
9769                 (void *)&cmd_flow_director_mask_port_src,
9770                 (void *)&cmd_flow_director_mask_dst,
9771                 (void *)&cmd_flow_director_mask_ipv4_dst,
9772                 (void *)&cmd_flow_director_mask_ipv6_dst,
9773                 (void *)&cmd_flow_director_mask_port_dst,
9774                 NULL,
9775         },
9776 };
9777
9778 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9779         .f = cmd_flow_director_mask_parsed,
9780         .data = NULL,
9781         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9782                 "flow director's mask on NIC",
9783         .tokens = {
9784                 (void *)&cmd_flow_director_mask,
9785                 (void *)&cmd_flow_director_mask_port_id,
9786                 (void *)&cmd_flow_director_mask_mode,
9787                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9788                 (void *)&cmd_flow_director_mask_vlan,
9789                 (void *)&cmd_flow_director_mask_vlan_value,
9790                 NULL,
9791         },
9792 };
9793
9794 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9795         .f = cmd_flow_director_mask_parsed,
9796         .data = NULL,
9797         .help_str = "flow_director_mask ... : Set tunnel mode "
9798                 "flow director's mask on NIC",
9799         .tokens = {
9800                 (void *)&cmd_flow_director_mask,
9801                 (void *)&cmd_flow_director_mask_port_id,
9802                 (void *)&cmd_flow_director_mask_mode,
9803                 (void *)&cmd_flow_director_mask_mode_tunnel,
9804                 (void *)&cmd_flow_director_mask_vlan,
9805                 (void *)&cmd_flow_director_mask_vlan_value,
9806                 (void *)&cmd_flow_director_mask_mac,
9807                 (void *)&cmd_flow_director_mask_mac_value,
9808                 (void *)&cmd_flow_director_mask_tunnel_type,
9809                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9810                 (void *)&cmd_flow_director_mask_tunnel_id,
9811                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9812                 NULL,
9813         },
9814 };
9815
9816 /* *** deal with flow director mask on flexible payload *** */
9817 struct cmd_flow_director_flex_mask_result {
9818         cmdline_fixed_string_t flow_director_flexmask;
9819         uint8_t port_id;
9820         cmdline_fixed_string_t flow;
9821         cmdline_fixed_string_t flow_type;
9822         cmdline_fixed_string_t mask;
9823 };
9824
9825 static void
9826 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9827                           __attribute__((unused)) struct cmdline *cl,
9828                           __attribute__((unused)) void *data)
9829 {
9830         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9831         struct rte_eth_fdir_info fdir_info;
9832         struct rte_eth_fdir_flex_mask flex_mask;
9833         struct rte_port *port;
9834         uint32_t flow_type_mask;
9835         uint16_t i;
9836         int ret;
9837
9838         if (res->port_id > nb_ports) {
9839                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9840                 return;
9841         }
9842
9843         port = &ports[res->port_id];
9844         /** Check if the port is not started **/
9845         if (port->port_status != RTE_PORT_STOPPED) {
9846                 printf("Please stop port %d first\n", res->port_id);
9847                 return;
9848         }
9849
9850         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9851         ret = parse_flexbytes(res->mask,
9852                         flex_mask.mask,
9853                         RTE_ETH_FDIR_MAX_FLEXLEN);
9854         if (ret < 0) {
9855                 printf("error: Cannot parse mask input.\n");
9856                 return;
9857         }
9858
9859         memset(&fdir_info, 0, sizeof(fdir_info));
9860         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9861                                 RTE_ETH_FILTER_INFO, &fdir_info);
9862         if (ret < 0) {
9863                 printf("Cannot get FDir filter info\n");
9864                 return;
9865         }
9866
9867         if (!strcmp(res->flow_type, "none")) {
9868                 /* means don't specify the flow type */
9869                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9870                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9871                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9872                                0, sizeof(struct rte_eth_fdir_flex_mask));
9873                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9874                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9875                                  &flex_mask,
9876                                  sizeof(struct rte_eth_fdir_flex_mask));
9877                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9878                 return;
9879         }
9880         flow_type_mask = fdir_info.flow_types_mask[0];
9881         if (!strcmp(res->flow_type, "all")) {
9882                 if (!flow_type_mask) {
9883                         printf("No flow type supported\n");
9884                         return;
9885                 }
9886                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9887                         if (flow_type_mask & (1 << i)) {
9888                                 flex_mask.flow_type = i;
9889                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9890                         }
9891                 }
9892                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9893                 return;
9894         }
9895         flex_mask.flow_type = str2flowtype(res->flow_type);
9896         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9897                 printf("Flow type %s not supported on port %d\n",
9898                                 res->flow_type, res->port_id);
9899                 return;
9900         }
9901         fdir_set_flex_mask(res->port_id, &flex_mask);
9902         cmd_reconfig_device_queue(res->port_id, 1, 1);
9903 }
9904
9905 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9906         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9907                                  flow_director_flexmask,
9908                                  "flow_director_flex_mask");
9909 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9910         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9911                               port_id, UINT8);
9912 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9913         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9914                                  flow, "flow");
9915 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9916         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9917                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9918                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9919 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9920         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9921                                  mask, NULL);
9922
9923 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9924         .f = cmd_flow_director_flex_mask_parsed,
9925         .data = NULL,
9926         .help_str = "flow_director_flex_mask ... : "
9927                 "Set flow director's flex mask on NIC",
9928         .tokens = {
9929                 (void *)&cmd_flow_director_flexmask,
9930                 (void *)&cmd_flow_director_flexmask_port_id,
9931                 (void *)&cmd_flow_director_flexmask_flow,
9932                 (void *)&cmd_flow_director_flexmask_flow_type,
9933                 (void *)&cmd_flow_director_flexmask_mask,
9934                 NULL,
9935         },
9936 };
9937
9938 /* *** deal with flow director flexible payload configuration *** */
9939 struct cmd_flow_director_flexpayload_result {
9940         cmdline_fixed_string_t flow_director_flexpayload;
9941         uint8_t port_id;
9942         cmdline_fixed_string_t payload_layer;
9943         cmdline_fixed_string_t payload_cfg;
9944 };
9945
9946 static inline int
9947 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9948 {
9949         char s[256];
9950         const char *p, *p0 = q_arg;
9951         char *end;
9952         unsigned long int_fld;
9953         char *str_fld[max_num];
9954         int i;
9955         unsigned size;
9956         int ret = -1;
9957
9958         p = strchr(p0, '(');
9959         if (p == NULL)
9960                 return -1;
9961         ++p;
9962         p0 = strchr(p, ')');
9963         if (p0 == NULL)
9964                 return -1;
9965
9966         size = p0 - p;
9967         if (size >= sizeof(s))
9968                 return -1;
9969
9970         snprintf(s, sizeof(s), "%.*s", size, p);
9971         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9972         if (ret < 0 || ret > max_num)
9973                 return -1;
9974         for (i = 0; i < ret; i++) {
9975                 errno = 0;
9976                 int_fld = strtoul(str_fld[i], &end, 0);
9977                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9978                         return -1;
9979                 offsets[i] = (uint16_t)int_fld;
9980         }
9981         return ret;
9982 }
9983
9984 static void
9985 cmd_flow_director_flxpld_parsed(void *parsed_result,
9986                           __attribute__((unused)) struct cmdline *cl,
9987                           __attribute__((unused)) void *data)
9988 {
9989         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9990         struct rte_eth_flex_payload_cfg flex_cfg;
9991         struct rte_port *port;
9992         int ret = 0;
9993
9994         if (res->port_id > nb_ports) {
9995                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9996                 return;
9997         }
9998
9999         port = &ports[res->port_id];
10000         /** Check if the port is not started **/
10001         if (port->port_status != RTE_PORT_STOPPED) {
10002                 printf("Please stop port %d first\n", res->port_id);
10003                 return;
10004         }
10005
10006         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10007
10008         if (!strcmp(res->payload_layer, "raw"))
10009                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10010         else if (!strcmp(res->payload_layer, "l2"))
10011                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10012         else if (!strcmp(res->payload_layer, "l3"))
10013                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10014         else if (!strcmp(res->payload_layer, "l4"))
10015                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10016
10017         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10018                             RTE_ETH_FDIR_MAX_FLEXLEN);
10019         if (ret < 0) {
10020                 printf("error: Cannot parse flex payload input.\n");
10021                 return;
10022         }
10023
10024         fdir_set_flex_payload(res->port_id, &flex_cfg);
10025         cmd_reconfig_device_queue(res->port_id, 1, 1);
10026 }
10027
10028 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10029         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10030                                  flow_director_flexpayload,
10031                                  "flow_director_flex_payload");
10032 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10033         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10034                               port_id, UINT8);
10035 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10037                                  payload_layer, "raw#l2#l3#l4");
10038 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10040                                  payload_cfg, NULL);
10041
10042 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10043         .f = cmd_flow_director_flxpld_parsed,
10044         .data = NULL,
10045         .help_str = "flow_director_flexpayload ... : "
10046                 "Set flow director's flex payload on NIC",
10047         .tokens = {
10048                 (void *)&cmd_flow_director_flexpayload,
10049                 (void *)&cmd_flow_director_flexpayload_port_id,
10050                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10051                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10052                 NULL,
10053         },
10054 };
10055
10056 /* Generic flow interface command. */
10057 extern cmdline_parse_inst_t cmd_flow;
10058
10059 /* *** Classification Filters Control *** */
10060 /* *** Get symmetric hash enable per port *** */
10061 struct cmd_get_sym_hash_ena_per_port_result {
10062         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10063         uint8_t port_id;
10064 };
10065
10066 static void
10067 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10068                                  __rte_unused struct cmdline *cl,
10069                                  __rte_unused void *data)
10070 {
10071         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10072         struct rte_eth_hash_filter_info info;
10073         int ret;
10074
10075         if (rte_eth_dev_filter_supported(res->port_id,
10076                                 RTE_ETH_FILTER_HASH) < 0) {
10077                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10078                                                         res->port_id);
10079                 return;
10080         }
10081
10082         memset(&info, 0, sizeof(info));
10083         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10084         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10085                                                 RTE_ETH_FILTER_GET, &info);
10086
10087         if (ret < 0) {
10088                 printf("Cannot get symmetric hash enable per port "
10089                                         "on port %u\n", res->port_id);
10090                 return;
10091         }
10092
10093         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10094                                 "enabled" : "disabled", res->port_id);
10095 }
10096
10097 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10098         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10099                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10100 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10101         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10102                 port_id, UINT8);
10103
10104 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10105         .f = cmd_get_sym_hash_per_port_parsed,
10106         .data = NULL,
10107         .help_str = "get_sym_hash_ena_per_port <port_id>",
10108         .tokens = {
10109                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10110                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10111                 NULL,
10112         },
10113 };
10114
10115 /* *** Set symmetric hash enable per port *** */
10116 struct cmd_set_sym_hash_ena_per_port_result {
10117         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10118         cmdline_fixed_string_t enable;
10119         uint8_t port_id;
10120 };
10121
10122 static void
10123 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10124                                  __rte_unused struct cmdline *cl,
10125                                  __rte_unused void *data)
10126 {
10127         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10128         struct rte_eth_hash_filter_info info;
10129         int ret;
10130
10131         if (rte_eth_dev_filter_supported(res->port_id,
10132                                 RTE_ETH_FILTER_HASH) < 0) {
10133                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10134                                                         res->port_id);
10135                 return;
10136         }
10137
10138         memset(&info, 0, sizeof(info));
10139         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10140         if (!strcmp(res->enable, "enable"))
10141                 info.info.enable = 1;
10142         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10143                                         RTE_ETH_FILTER_SET, &info);
10144         if (ret < 0) {
10145                 printf("Cannot set symmetric hash enable per port on "
10146                                         "port %u\n", res->port_id);
10147                 return;
10148         }
10149         printf("Symmetric hash has been set to %s on port %u\n",
10150                                         res->enable, res->port_id);
10151 }
10152
10153 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10154         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10155                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10156 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10157         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10158                 port_id, UINT8);
10159 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10160         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10161                 enable, "enable#disable");
10162
10163 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10164         .f = cmd_set_sym_hash_per_port_parsed,
10165         .data = NULL,
10166         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10167         .tokens = {
10168                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10169                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10170                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10171                 NULL,
10172         },
10173 };
10174
10175 /* Get global config of hash function */
10176 struct cmd_get_hash_global_config_result {
10177         cmdline_fixed_string_t get_hash_global_config;
10178         uint8_t port_id;
10179 };
10180
10181 static char *
10182 flowtype_to_str(uint16_t ftype)
10183 {
10184         uint16_t i;
10185         static struct {
10186                 char str[16];
10187                 uint16_t ftype;
10188         } ftype_table[] = {
10189                 {"ipv4", RTE_ETH_FLOW_IPV4},
10190                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10191                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10192                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10193                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10194                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10195                 {"ipv6", RTE_ETH_FLOW_IPV6},
10196                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10197                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10198                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10199                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10200                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10201                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10202                 {"port", RTE_ETH_FLOW_PORT},
10203                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10204                 {"geneve", RTE_ETH_FLOW_GENEVE},
10205                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10206         };
10207
10208         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10209                 if (ftype_table[i].ftype == ftype)
10210                         return ftype_table[i].str;
10211         }
10212
10213         return NULL;
10214 }
10215
10216 static void
10217 cmd_get_hash_global_config_parsed(void *parsed_result,
10218                                   __rte_unused struct cmdline *cl,
10219                                   __rte_unused void *data)
10220 {
10221         struct cmd_get_hash_global_config_result *res = parsed_result;
10222         struct rte_eth_hash_filter_info info;
10223         uint32_t idx, offset;
10224         uint16_t i;
10225         char *str;
10226         int ret;
10227
10228         if (rte_eth_dev_filter_supported(res->port_id,
10229                         RTE_ETH_FILTER_HASH) < 0) {
10230                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10231                                                         res->port_id);
10232                 return;
10233         }
10234
10235         memset(&info, 0, sizeof(info));
10236         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10237         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10238                                         RTE_ETH_FILTER_GET, &info);
10239         if (ret < 0) {
10240                 printf("Cannot get hash global configurations by port %d\n",
10241                                                         res->port_id);
10242                 return;
10243         }
10244
10245         switch (info.info.global_conf.hash_func) {
10246         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10247                 printf("Hash function is Toeplitz\n");
10248                 break;
10249         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10250                 printf("Hash function is Simple XOR\n");
10251                 break;
10252         default:
10253                 printf("Unknown hash function\n");
10254                 break;
10255         }
10256
10257         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10258                 idx = i / UINT32_BIT;
10259                 offset = i % UINT32_BIT;
10260                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10261                                                 (1UL << offset)))
10262                         continue;
10263                 str = flowtype_to_str(i);
10264                 if (!str)
10265                         continue;
10266                 printf("Symmetric hash is %s globally for flow type %s "
10267                                                         "by port %d\n",
10268                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10269                         (1UL << offset)) ? "enabled" : "disabled"), str,
10270                                                         res->port_id);
10271         }
10272 }
10273
10274 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10275         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10276                 get_hash_global_config, "get_hash_global_config");
10277 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10278         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10279                 port_id, UINT8);
10280
10281 cmdline_parse_inst_t cmd_get_hash_global_config = {
10282         .f = cmd_get_hash_global_config_parsed,
10283         .data = NULL,
10284         .help_str = "get_hash_global_config <port_id>",
10285         .tokens = {
10286                 (void *)&cmd_get_hash_global_config_all,
10287                 (void *)&cmd_get_hash_global_config_port_id,
10288                 NULL,
10289         },
10290 };
10291
10292 /* Set global config of hash function */
10293 struct cmd_set_hash_global_config_result {
10294         cmdline_fixed_string_t set_hash_global_config;
10295         uint8_t port_id;
10296         cmdline_fixed_string_t hash_func;
10297         cmdline_fixed_string_t flow_type;
10298         cmdline_fixed_string_t enable;
10299 };
10300
10301 static void
10302 cmd_set_hash_global_config_parsed(void *parsed_result,
10303                                   __rte_unused struct cmdline *cl,
10304                                   __rte_unused void *data)
10305 {
10306         struct cmd_set_hash_global_config_result *res = parsed_result;
10307         struct rte_eth_hash_filter_info info;
10308         uint32_t ftype, idx, offset;
10309         int ret;
10310
10311         if (rte_eth_dev_filter_supported(res->port_id,
10312                                 RTE_ETH_FILTER_HASH) < 0) {
10313                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10314                                                         res->port_id);
10315                 return;
10316         }
10317         memset(&info, 0, sizeof(info));
10318         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10319         if (!strcmp(res->hash_func, "toeplitz"))
10320                 info.info.global_conf.hash_func =
10321                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10322         else if (!strcmp(res->hash_func, "simple_xor"))
10323                 info.info.global_conf.hash_func =
10324                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10325         else if (!strcmp(res->hash_func, "default"))
10326                 info.info.global_conf.hash_func =
10327                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10328
10329         ftype = str2flowtype(res->flow_type);
10330         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10331         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10332         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10333         if (!strcmp(res->enable, "enable"))
10334                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10335                                                 (1UL << offset);
10336         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10337                                         RTE_ETH_FILTER_SET, &info);
10338         if (ret < 0)
10339                 printf("Cannot set global hash configurations by port %d\n",
10340                                                         res->port_id);
10341         else
10342                 printf("Global hash configurations have been set "
10343                         "succcessfully by port %d\n", res->port_id);
10344 }
10345
10346 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10347         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10348                 set_hash_global_config, "set_hash_global_config");
10349 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10350         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10351                 port_id, UINT8);
10352 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10353         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10354                 hash_func, "toeplitz#simple_xor#default");
10355 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10356         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10357                 flow_type,
10358                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10359                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10360 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10361         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10362                 enable, "enable#disable");
10363
10364 cmdline_parse_inst_t cmd_set_hash_global_config = {
10365         .f = cmd_set_hash_global_config_parsed,
10366         .data = NULL,
10367         .help_str = "set_hash_global_config <port_id> "
10368                 "toeplitz|simple_xor|default "
10369                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10370                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10371                 "l2_payload enable|disable",
10372         .tokens = {
10373                 (void *)&cmd_set_hash_global_config_all,
10374                 (void *)&cmd_set_hash_global_config_port_id,
10375                 (void *)&cmd_set_hash_global_config_hash_func,
10376                 (void *)&cmd_set_hash_global_config_flow_type,
10377                 (void *)&cmd_set_hash_global_config_enable,
10378                 NULL,
10379         },
10380 };
10381
10382 /* Set hash input set */
10383 struct cmd_set_hash_input_set_result {
10384         cmdline_fixed_string_t set_hash_input_set;
10385         uint8_t port_id;
10386         cmdline_fixed_string_t flow_type;
10387         cmdline_fixed_string_t inset_field;
10388         cmdline_fixed_string_t select;
10389 };
10390
10391 static enum rte_eth_input_set_field
10392 str2inset(char *string)
10393 {
10394         uint16_t i;
10395
10396         static const struct {
10397                 char str[32];
10398                 enum rte_eth_input_set_field inset;
10399         } inset_table[] = {
10400                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10401                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10402                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10403                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10404                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10405                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10406                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10407                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10408                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10409                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10410                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10411                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10412                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10413                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10414                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10415                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10416                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10417                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10418                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10419                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10420                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10421                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10422                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10423                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10424                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10425                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10426                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10427                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10428                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10429                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10430                 {"none", RTE_ETH_INPUT_SET_NONE},
10431         };
10432
10433         for (i = 0; i < RTE_DIM(inset_table); i++) {
10434                 if (!strcmp(string, inset_table[i].str))
10435                         return inset_table[i].inset;
10436         }
10437
10438         return RTE_ETH_INPUT_SET_UNKNOWN;
10439 }
10440
10441 static void
10442 cmd_set_hash_input_set_parsed(void *parsed_result,
10443                               __rte_unused struct cmdline *cl,
10444                               __rte_unused void *data)
10445 {
10446         struct cmd_set_hash_input_set_result *res = parsed_result;
10447         struct rte_eth_hash_filter_info info;
10448
10449         memset(&info, 0, sizeof(info));
10450         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10451         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10452         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10453         info.info.input_set_conf.inset_size = 1;
10454         if (!strcmp(res->select, "select"))
10455                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10456         else if (!strcmp(res->select, "add"))
10457                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10458         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10459                                 RTE_ETH_FILTER_SET, &info);
10460 }
10461
10462 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10463         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10464                 set_hash_input_set, "set_hash_input_set");
10465 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10466         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10467                 port_id, UINT8);
10468 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10469         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10470                 flow_type,
10471                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10472                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10473 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10474         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10475                 inset_field,
10476                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10477                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10478                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10479                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10480                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10481                 "fld-8th#none");
10482 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10483         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10484                 select, "select#add");
10485
10486 cmdline_parse_inst_t cmd_set_hash_input_set = {
10487         .f = cmd_set_hash_input_set_parsed,
10488         .data = NULL,
10489         .help_str = "set_hash_input_set <port_id> "
10490         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10491         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10492         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10493         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10494         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10495         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10496         "fld-7th|fld-8th|none select|add",
10497         .tokens = {
10498                 (void *)&cmd_set_hash_input_set_cmd,
10499                 (void *)&cmd_set_hash_input_set_port_id,
10500                 (void *)&cmd_set_hash_input_set_flow_type,
10501                 (void *)&cmd_set_hash_input_set_field,
10502                 (void *)&cmd_set_hash_input_set_select,
10503                 NULL,
10504         },
10505 };
10506
10507 /* Set flow director input set */
10508 struct cmd_set_fdir_input_set_result {
10509         cmdline_fixed_string_t set_fdir_input_set;
10510         uint8_t port_id;
10511         cmdline_fixed_string_t flow_type;
10512         cmdline_fixed_string_t inset_field;
10513         cmdline_fixed_string_t select;
10514 };
10515
10516 static void
10517 cmd_set_fdir_input_set_parsed(void *parsed_result,
10518         __rte_unused struct cmdline *cl,
10519         __rte_unused void *data)
10520 {
10521         struct cmd_set_fdir_input_set_result *res = parsed_result;
10522         struct rte_eth_fdir_filter_info info;
10523
10524         memset(&info, 0, sizeof(info));
10525         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10526         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10527         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10528         info.info.input_set_conf.inset_size = 1;
10529         if (!strcmp(res->select, "select"))
10530                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10531         else if (!strcmp(res->select, "add"))
10532                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10533         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10534                 RTE_ETH_FILTER_SET, &info);
10535 }
10536
10537 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10538         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10539         set_fdir_input_set, "set_fdir_input_set");
10540 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10541         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10542         port_id, UINT8);
10543 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10544         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10545         flow_type,
10546         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10547         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10548 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10549         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10550         inset_field,
10551         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10552         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10553         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10554         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10555         "sctp-veri-tag#none");
10556 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10557         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10558         select, "select#add");
10559
10560 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10561         .f = cmd_set_fdir_input_set_parsed,
10562         .data = NULL,
10563         .help_str = "set_fdir_input_set <port_id> "
10564         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10565         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10566         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10567         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10568         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10569         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10570         "sctp-veri-tag|none select|add",
10571         .tokens = {
10572                 (void *)&cmd_set_fdir_input_set_cmd,
10573                 (void *)&cmd_set_fdir_input_set_port_id,
10574                 (void *)&cmd_set_fdir_input_set_flow_type,
10575                 (void *)&cmd_set_fdir_input_set_field,
10576                 (void *)&cmd_set_fdir_input_set_select,
10577                 NULL,
10578         },
10579 };
10580
10581 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10582 struct cmd_mcast_addr_result {
10583         cmdline_fixed_string_t mcast_addr_cmd;
10584         cmdline_fixed_string_t what;
10585         uint8_t port_num;
10586         struct ether_addr mc_addr;
10587 };
10588
10589 static void cmd_mcast_addr_parsed(void *parsed_result,
10590                 __attribute__((unused)) struct cmdline *cl,
10591                 __attribute__((unused)) void *data)
10592 {
10593         struct cmd_mcast_addr_result *res = parsed_result;
10594
10595         if (!is_multicast_ether_addr(&res->mc_addr)) {
10596                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10597                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10598                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10599                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10600                 return;
10601         }
10602         if (strcmp(res->what, "add") == 0)
10603                 mcast_addr_add(res->port_num, &res->mc_addr);
10604         else
10605                 mcast_addr_remove(res->port_num, &res->mc_addr);
10606 }
10607
10608 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10609         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10610                                  mcast_addr_cmd, "mcast_addr");
10611 cmdline_parse_token_string_t cmd_mcast_addr_what =
10612         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10613                                  "add#remove");
10614 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10615         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10616 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10617         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10618
10619 cmdline_parse_inst_t cmd_mcast_addr = {
10620         .f = cmd_mcast_addr_parsed,
10621         .data = (void *)0,
10622         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10623                 "Add/Remove multicast MAC address on port_id",
10624         .tokens = {
10625                 (void *)&cmd_mcast_addr_cmd,
10626                 (void *)&cmd_mcast_addr_what,
10627                 (void *)&cmd_mcast_addr_portnum,
10628                 (void *)&cmd_mcast_addr_addr,
10629                 NULL,
10630         },
10631 };
10632
10633 /* l2 tunnel config
10634  * only support E-tag now.
10635  */
10636
10637 /* Ether type config */
10638 struct cmd_config_l2_tunnel_eth_type_result {
10639         cmdline_fixed_string_t port;
10640         cmdline_fixed_string_t config;
10641         cmdline_fixed_string_t all;
10642         uint8_t id;
10643         cmdline_fixed_string_t l2_tunnel;
10644         cmdline_fixed_string_t l2_tunnel_type;
10645         cmdline_fixed_string_t eth_type;
10646         uint16_t eth_type_val;
10647 };
10648
10649 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10650         TOKEN_STRING_INITIALIZER
10651                 (struct cmd_config_l2_tunnel_eth_type_result,
10652                  port, "port");
10653 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10654         TOKEN_STRING_INITIALIZER
10655                 (struct cmd_config_l2_tunnel_eth_type_result,
10656                  config, "config");
10657 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10658         TOKEN_STRING_INITIALIZER
10659                 (struct cmd_config_l2_tunnel_eth_type_result,
10660                  all, "all");
10661 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10662         TOKEN_NUM_INITIALIZER
10663                 (struct cmd_config_l2_tunnel_eth_type_result,
10664                  id, UINT8);
10665 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10666         TOKEN_STRING_INITIALIZER
10667                 (struct cmd_config_l2_tunnel_eth_type_result,
10668                  l2_tunnel, "l2-tunnel");
10669 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10670         TOKEN_STRING_INITIALIZER
10671                 (struct cmd_config_l2_tunnel_eth_type_result,
10672                  l2_tunnel_type, "E-tag");
10673 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10674         TOKEN_STRING_INITIALIZER
10675                 (struct cmd_config_l2_tunnel_eth_type_result,
10676                  eth_type, "ether-type");
10677 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10678         TOKEN_NUM_INITIALIZER
10679                 (struct cmd_config_l2_tunnel_eth_type_result,
10680                  eth_type_val, UINT16);
10681
10682 static enum rte_eth_tunnel_type
10683 str2fdir_l2_tunnel_type(char *string)
10684 {
10685         uint32_t i = 0;
10686
10687         static const struct {
10688                 char str[32];
10689                 enum rte_eth_tunnel_type type;
10690         } l2_tunnel_type_str[] = {
10691                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10692         };
10693
10694         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10695                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10696                         return l2_tunnel_type_str[i].type;
10697         }
10698         return RTE_TUNNEL_TYPE_NONE;
10699 }
10700
10701 /* ether type config for all ports */
10702 static void
10703 cmd_config_l2_tunnel_eth_type_all_parsed
10704         (void *parsed_result,
10705          __attribute__((unused)) struct cmdline *cl,
10706          __attribute__((unused)) void *data)
10707 {
10708         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10709         struct rte_eth_l2_tunnel_conf entry;
10710         portid_t pid;
10711
10712         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10713         entry.ether_type = res->eth_type_val;
10714
10715         RTE_ETH_FOREACH_DEV(pid) {
10716                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10717         }
10718 }
10719
10720 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10721         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10722         .data = NULL,
10723         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10724         .tokens = {
10725                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10726                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10727                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10728                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10729                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10730                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10731                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10732                 NULL,
10733         },
10734 };
10735
10736 /* ether type config for a specific port */
10737 static void
10738 cmd_config_l2_tunnel_eth_type_specific_parsed(
10739         void *parsed_result,
10740         __attribute__((unused)) struct cmdline *cl,
10741         __attribute__((unused)) void *data)
10742 {
10743         struct cmd_config_l2_tunnel_eth_type_result *res =
10744                  parsed_result;
10745         struct rte_eth_l2_tunnel_conf entry;
10746
10747         if (port_id_is_invalid(res->id, ENABLED_WARN))
10748                 return;
10749
10750         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10751         entry.ether_type = res->eth_type_val;
10752
10753         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10754 }
10755
10756 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10757         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10758         .data = NULL,
10759         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10760         .tokens = {
10761                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10762                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10763                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10764                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10765                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10766                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10767                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10768                 NULL,
10769         },
10770 };
10771
10772 /* Enable/disable l2 tunnel */
10773 struct cmd_config_l2_tunnel_en_dis_result {
10774         cmdline_fixed_string_t port;
10775         cmdline_fixed_string_t config;
10776         cmdline_fixed_string_t all;
10777         uint8_t id;
10778         cmdline_fixed_string_t l2_tunnel;
10779         cmdline_fixed_string_t l2_tunnel_type;
10780         cmdline_fixed_string_t en_dis;
10781 };
10782
10783 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10784         TOKEN_STRING_INITIALIZER
10785                 (struct cmd_config_l2_tunnel_en_dis_result,
10786                  port, "port");
10787 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10788         TOKEN_STRING_INITIALIZER
10789                 (struct cmd_config_l2_tunnel_en_dis_result,
10790                  config, "config");
10791 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10792         TOKEN_STRING_INITIALIZER
10793                 (struct cmd_config_l2_tunnel_en_dis_result,
10794                  all, "all");
10795 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10796         TOKEN_NUM_INITIALIZER
10797                 (struct cmd_config_l2_tunnel_en_dis_result,
10798                  id, UINT8);
10799 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10800         TOKEN_STRING_INITIALIZER
10801                 (struct cmd_config_l2_tunnel_en_dis_result,
10802                  l2_tunnel, "l2-tunnel");
10803 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10804         TOKEN_STRING_INITIALIZER
10805                 (struct cmd_config_l2_tunnel_en_dis_result,
10806                  l2_tunnel_type, "E-tag");
10807 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10808         TOKEN_STRING_INITIALIZER
10809                 (struct cmd_config_l2_tunnel_en_dis_result,
10810                  en_dis, "enable#disable");
10811
10812 /* enable/disable l2 tunnel for all ports */
10813 static void
10814 cmd_config_l2_tunnel_en_dis_all_parsed(
10815         void *parsed_result,
10816         __attribute__((unused)) struct cmdline *cl,
10817         __attribute__((unused)) void *data)
10818 {
10819         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10820         struct rte_eth_l2_tunnel_conf entry;
10821         portid_t pid;
10822         uint8_t en;
10823
10824         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10825
10826         if (!strcmp("enable", res->en_dis))
10827                 en = 1;
10828         else
10829                 en = 0;
10830
10831         RTE_ETH_FOREACH_DEV(pid) {
10832                 rte_eth_dev_l2_tunnel_offload_set(pid,
10833                                                   &entry,
10834                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10835                                                   en);
10836         }
10837 }
10838
10839 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10840         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10841         .data = NULL,
10842         .help_str = "port config all l2-tunnel E-tag enable|disable",
10843         .tokens = {
10844                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10845                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10846                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10847                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10848                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10849                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10850                 NULL,
10851         },
10852 };
10853
10854 /* enable/disable l2 tunnel for a port */
10855 static void
10856 cmd_config_l2_tunnel_en_dis_specific_parsed(
10857         void *parsed_result,
10858         __attribute__((unused)) struct cmdline *cl,
10859         __attribute__((unused)) void *data)
10860 {
10861         struct cmd_config_l2_tunnel_en_dis_result *res =
10862                 parsed_result;
10863         struct rte_eth_l2_tunnel_conf entry;
10864
10865         if (port_id_is_invalid(res->id, ENABLED_WARN))
10866                 return;
10867
10868         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10869
10870         if (!strcmp("enable", res->en_dis))
10871                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10872                                                   &entry,
10873                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10874                                                   1);
10875         else
10876                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10877                                                   &entry,
10878                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10879                                                   0);
10880 }
10881
10882 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10883         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10884         .data = NULL,
10885         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10886         .tokens = {
10887                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10888                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10889                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10890                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10891                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10892                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10893                 NULL,
10894         },
10895 };
10896
10897 /* E-tag configuration */
10898
10899 /* Common result structure for all E-tag configuration */
10900 struct cmd_config_e_tag_result {
10901         cmdline_fixed_string_t e_tag;
10902         cmdline_fixed_string_t set;
10903         cmdline_fixed_string_t insertion;
10904         cmdline_fixed_string_t stripping;
10905         cmdline_fixed_string_t forwarding;
10906         cmdline_fixed_string_t filter;
10907         cmdline_fixed_string_t add;
10908         cmdline_fixed_string_t del;
10909         cmdline_fixed_string_t on;
10910         cmdline_fixed_string_t off;
10911         cmdline_fixed_string_t on_off;
10912         cmdline_fixed_string_t port_tag_id;
10913         uint32_t port_tag_id_val;
10914         cmdline_fixed_string_t e_tag_id;
10915         uint16_t e_tag_id_val;
10916         cmdline_fixed_string_t dst_pool;
10917         uint8_t dst_pool_val;
10918         cmdline_fixed_string_t port;
10919         uint8_t port_id;
10920         cmdline_fixed_string_t vf;
10921         uint8_t vf_id;
10922 };
10923
10924 /* Common CLI fields for all E-tag configuration */
10925 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10926         TOKEN_STRING_INITIALIZER
10927                 (struct cmd_config_e_tag_result,
10928                  e_tag, "E-tag");
10929 cmdline_parse_token_string_t cmd_config_e_tag_set =
10930         TOKEN_STRING_INITIALIZER
10931                 (struct cmd_config_e_tag_result,
10932                  set, "set");
10933 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10934         TOKEN_STRING_INITIALIZER
10935                 (struct cmd_config_e_tag_result,
10936                  insertion, "insertion");
10937 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10938         TOKEN_STRING_INITIALIZER
10939                 (struct cmd_config_e_tag_result,
10940                  stripping, "stripping");
10941 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10942         TOKEN_STRING_INITIALIZER
10943                 (struct cmd_config_e_tag_result,
10944                  forwarding, "forwarding");
10945 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10946         TOKEN_STRING_INITIALIZER
10947                 (struct cmd_config_e_tag_result,
10948                  filter, "filter");
10949 cmdline_parse_token_string_t cmd_config_e_tag_add =
10950         TOKEN_STRING_INITIALIZER
10951                 (struct cmd_config_e_tag_result,
10952                  add, "add");
10953 cmdline_parse_token_string_t cmd_config_e_tag_del =
10954         TOKEN_STRING_INITIALIZER
10955                 (struct cmd_config_e_tag_result,
10956                  del, "del");
10957 cmdline_parse_token_string_t cmd_config_e_tag_on =
10958         TOKEN_STRING_INITIALIZER
10959                 (struct cmd_config_e_tag_result,
10960                  on, "on");
10961 cmdline_parse_token_string_t cmd_config_e_tag_off =
10962         TOKEN_STRING_INITIALIZER
10963                 (struct cmd_config_e_tag_result,
10964                  off, "off");
10965 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10966         TOKEN_STRING_INITIALIZER
10967                 (struct cmd_config_e_tag_result,
10968                  on_off, "on#off");
10969 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10970         TOKEN_STRING_INITIALIZER
10971                 (struct cmd_config_e_tag_result,
10972                  port_tag_id, "port-tag-id");
10973 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10974         TOKEN_NUM_INITIALIZER
10975                 (struct cmd_config_e_tag_result,
10976                  port_tag_id_val, UINT32);
10977 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10978         TOKEN_STRING_INITIALIZER
10979                 (struct cmd_config_e_tag_result,
10980                  e_tag_id, "e-tag-id");
10981 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10982         TOKEN_NUM_INITIALIZER
10983                 (struct cmd_config_e_tag_result,
10984                  e_tag_id_val, UINT16);
10985 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10986         TOKEN_STRING_INITIALIZER
10987                 (struct cmd_config_e_tag_result,
10988                  dst_pool, "dst-pool");
10989 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10990         TOKEN_NUM_INITIALIZER
10991                 (struct cmd_config_e_tag_result,
10992                  dst_pool_val, UINT8);
10993 cmdline_parse_token_string_t cmd_config_e_tag_port =
10994         TOKEN_STRING_INITIALIZER
10995                 (struct cmd_config_e_tag_result,
10996                  port, "port");
10997 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10998         TOKEN_NUM_INITIALIZER
10999                 (struct cmd_config_e_tag_result,
11000                  port_id, UINT8);
11001 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11002         TOKEN_STRING_INITIALIZER
11003                 (struct cmd_config_e_tag_result,
11004                  vf, "vf");
11005 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11006         TOKEN_NUM_INITIALIZER
11007                 (struct cmd_config_e_tag_result,
11008                  vf_id, UINT8);
11009
11010 /* E-tag insertion configuration */
11011 static void
11012 cmd_config_e_tag_insertion_en_parsed(
11013         void *parsed_result,
11014         __attribute__((unused)) struct cmdline *cl,
11015         __attribute__((unused)) void *data)
11016 {
11017         struct cmd_config_e_tag_result *res =
11018                 parsed_result;
11019         struct rte_eth_l2_tunnel_conf entry;
11020
11021         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11022                 return;
11023
11024         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11025         entry.tunnel_id = res->port_tag_id_val;
11026         entry.vf_id = res->vf_id;
11027         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11028                                           &entry,
11029                                           ETH_L2_TUNNEL_INSERTION_MASK,
11030                                           1);
11031 }
11032
11033 static void
11034 cmd_config_e_tag_insertion_dis_parsed(
11035         void *parsed_result,
11036         __attribute__((unused)) struct cmdline *cl,
11037         __attribute__((unused)) void *data)
11038 {
11039         struct cmd_config_e_tag_result *res =
11040                 parsed_result;
11041         struct rte_eth_l2_tunnel_conf entry;
11042
11043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11044                 return;
11045
11046         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11047         entry.vf_id = res->vf_id;
11048
11049         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11050                                           &entry,
11051                                           ETH_L2_TUNNEL_INSERTION_MASK,
11052                                           0);
11053 }
11054
11055 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11056         .f = cmd_config_e_tag_insertion_en_parsed,
11057         .data = NULL,
11058         .help_str = "E-tag ... : E-tag insertion enable",
11059         .tokens = {
11060                 (void *)&cmd_config_e_tag_e_tag,
11061                 (void *)&cmd_config_e_tag_set,
11062                 (void *)&cmd_config_e_tag_insertion,
11063                 (void *)&cmd_config_e_tag_on,
11064                 (void *)&cmd_config_e_tag_port_tag_id,
11065                 (void *)&cmd_config_e_tag_port_tag_id_val,
11066                 (void *)&cmd_config_e_tag_port,
11067                 (void *)&cmd_config_e_tag_port_id,
11068                 (void *)&cmd_config_e_tag_vf,
11069                 (void *)&cmd_config_e_tag_vf_id,
11070                 NULL,
11071         },
11072 };
11073
11074 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11075         .f = cmd_config_e_tag_insertion_dis_parsed,
11076         .data = NULL,
11077         .help_str = "E-tag ... : E-tag insertion disable",
11078         .tokens = {
11079                 (void *)&cmd_config_e_tag_e_tag,
11080                 (void *)&cmd_config_e_tag_set,
11081                 (void *)&cmd_config_e_tag_insertion,
11082                 (void *)&cmd_config_e_tag_off,
11083                 (void *)&cmd_config_e_tag_port,
11084                 (void *)&cmd_config_e_tag_port_id,
11085                 (void *)&cmd_config_e_tag_vf,
11086                 (void *)&cmd_config_e_tag_vf_id,
11087                 NULL,
11088         },
11089 };
11090
11091 /* E-tag stripping configuration */
11092 static void
11093 cmd_config_e_tag_stripping_parsed(
11094         void *parsed_result,
11095         __attribute__((unused)) struct cmdline *cl,
11096         __attribute__((unused)) void *data)
11097 {
11098         struct cmd_config_e_tag_result *res =
11099                 parsed_result;
11100         struct rte_eth_l2_tunnel_conf entry;
11101
11102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11103                 return;
11104
11105         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11106
11107         if (!strcmp(res->on_off, "on"))
11108                 rte_eth_dev_l2_tunnel_offload_set
11109                         (res->port_id,
11110                          &entry,
11111                          ETH_L2_TUNNEL_STRIPPING_MASK,
11112                          1);
11113         else
11114                 rte_eth_dev_l2_tunnel_offload_set
11115                         (res->port_id,
11116                          &entry,
11117                          ETH_L2_TUNNEL_STRIPPING_MASK,
11118                          0);
11119 }
11120
11121 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11122         .f = cmd_config_e_tag_stripping_parsed,
11123         .data = NULL,
11124         .help_str = "E-tag ... : E-tag stripping enable/disable",
11125         .tokens = {
11126                 (void *)&cmd_config_e_tag_e_tag,
11127                 (void *)&cmd_config_e_tag_set,
11128                 (void *)&cmd_config_e_tag_stripping,
11129                 (void *)&cmd_config_e_tag_on_off,
11130                 (void *)&cmd_config_e_tag_port,
11131                 (void *)&cmd_config_e_tag_port_id,
11132                 NULL,
11133         },
11134 };
11135
11136 /* E-tag forwarding configuration */
11137 static void
11138 cmd_config_e_tag_forwarding_parsed(
11139         void *parsed_result,
11140         __attribute__((unused)) struct cmdline *cl,
11141         __attribute__((unused)) void *data)
11142 {
11143         struct cmd_config_e_tag_result *res = parsed_result;
11144         struct rte_eth_l2_tunnel_conf entry;
11145
11146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11147                 return;
11148
11149         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11150
11151         if (!strcmp(res->on_off, "on"))
11152                 rte_eth_dev_l2_tunnel_offload_set
11153                         (res->port_id,
11154                          &entry,
11155                          ETH_L2_TUNNEL_FORWARDING_MASK,
11156                          1);
11157         else
11158                 rte_eth_dev_l2_tunnel_offload_set
11159                         (res->port_id,
11160                          &entry,
11161                          ETH_L2_TUNNEL_FORWARDING_MASK,
11162                          0);
11163 }
11164
11165 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11166         .f = cmd_config_e_tag_forwarding_parsed,
11167         .data = NULL,
11168         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11169         .tokens = {
11170                 (void *)&cmd_config_e_tag_e_tag,
11171                 (void *)&cmd_config_e_tag_set,
11172                 (void *)&cmd_config_e_tag_forwarding,
11173                 (void *)&cmd_config_e_tag_on_off,
11174                 (void *)&cmd_config_e_tag_port,
11175                 (void *)&cmd_config_e_tag_port_id,
11176                 NULL,
11177         },
11178 };
11179
11180 /* E-tag filter configuration */
11181 static void
11182 cmd_config_e_tag_filter_add_parsed(
11183         void *parsed_result,
11184         __attribute__((unused)) struct cmdline *cl,
11185         __attribute__((unused)) void *data)
11186 {
11187         struct cmd_config_e_tag_result *res = parsed_result;
11188         struct rte_eth_l2_tunnel_conf entry;
11189         int ret = 0;
11190
11191         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11192                 return;
11193
11194         if (res->e_tag_id_val > 0x3fff) {
11195                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11196                 return;
11197         }
11198
11199         ret = rte_eth_dev_filter_supported(res->port_id,
11200                                            RTE_ETH_FILTER_L2_TUNNEL);
11201         if (ret < 0) {
11202                 printf("E-tag filter is not supported on port %u.\n",
11203                        res->port_id);
11204                 return;
11205         }
11206
11207         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11208         entry.tunnel_id = res->e_tag_id_val;
11209         entry.pool = res->dst_pool_val;
11210
11211         ret = rte_eth_dev_filter_ctrl(res->port_id,
11212                                       RTE_ETH_FILTER_L2_TUNNEL,
11213                                       RTE_ETH_FILTER_ADD,
11214                                       &entry);
11215         if (ret < 0)
11216                 printf("E-tag filter programming error: (%s)\n",
11217                        strerror(-ret));
11218 }
11219
11220 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11221         .f = cmd_config_e_tag_filter_add_parsed,
11222         .data = NULL,
11223         .help_str = "E-tag ... : E-tag filter add",
11224         .tokens = {
11225                 (void *)&cmd_config_e_tag_e_tag,
11226                 (void *)&cmd_config_e_tag_set,
11227                 (void *)&cmd_config_e_tag_filter,
11228                 (void *)&cmd_config_e_tag_add,
11229                 (void *)&cmd_config_e_tag_e_tag_id,
11230                 (void *)&cmd_config_e_tag_e_tag_id_val,
11231                 (void *)&cmd_config_e_tag_dst_pool,
11232                 (void *)&cmd_config_e_tag_dst_pool_val,
11233                 (void *)&cmd_config_e_tag_port,
11234                 (void *)&cmd_config_e_tag_port_id,
11235                 NULL,
11236         },
11237 };
11238
11239 static void
11240 cmd_config_e_tag_filter_del_parsed(
11241         void *parsed_result,
11242         __attribute__((unused)) struct cmdline *cl,
11243         __attribute__((unused)) void *data)
11244 {
11245         struct cmd_config_e_tag_result *res = parsed_result;
11246         struct rte_eth_l2_tunnel_conf entry;
11247         int ret = 0;
11248
11249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11250                 return;
11251
11252         if (res->e_tag_id_val > 0x3fff) {
11253                 printf("e-tag-id must be less than 0x3fff.\n");
11254                 return;
11255         }
11256
11257         ret = rte_eth_dev_filter_supported(res->port_id,
11258                                            RTE_ETH_FILTER_L2_TUNNEL);
11259         if (ret < 0) {
11260                 printf("E-tag filter is not supported on port %u.\n",
11261                        res->port_id);
11262                 return;
11263         }
11264
11265         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11266         entry.tunnel_id = res->e_tag_id_val;
11267
11268         ret = rte_eth_dev_filter_ctrl(res->port_id,
11269                                       RTE_ETH_FILTER_L2_TUNNEL,
11270                                       RTE_ETH_FILTER_DELETE,
11271                                       &entry);
11272         if (ret < 0)
11273                 printf("E-tag filter programming error: (%s)\n",
11274                        strerror(-ret));
11275 }
11276
11277 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11278         .f = cmd_config_e_tag_filter_del_parsed,
11279         .data = NULL,
11280         .help_str = "E-tag ... : E-tag filter delete",
11281         .tokens = {
11282                 (void *)&cmd_config_e_tag_e_tag,
11283                 (void *)&cmd_config_e_tag_set,
11284                 (void *)&cmd_config_e_tag_filter,
11285                 (void *)&cmd_config_e_tag_del,
11286                 (void *)&cmd_config_e_tag_e_tag_id,
11287                 (void *)&cmd_config_e_tag_e_tag_id_val,
11288                 (void *)&cmd_config_e_tag_port,
11289                 (void *)&cmd_config_e_tag_port_id,
11290                 NULL,
11291         },
11292 };
11293
11294 /* vf vlan anti spoof configuration */
11295
11296 /* Common result structure for vf vlan anti spoof */
11297 struct cmd_vf_vlan_anti_spoof_result {
11298         cmdline_fixed_string_t set;
11299         cmdline_fixed_string_t vf;
11300         cmdline_fixed_string_t vlan;
11301         cmdline_fixed_string_t antispoof;
11302         uint8_t port_id;
11303         uint32_t vf_id;
11304         cmdline_fixed_string_t on_off;
11305 };
11306
11307 /* Common CLI fields for vf vlan anti spoof enable disable */
11308 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11309         TOKEN_STRING_INITIALIZER
11310                 (struct cmd_vf_vlan_anti_spoof_result,
11311                  set, "set");
11312 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11313         TOKEN_STRING_INITIALIZER
11314                 (struct cmd_vf_vlan_anti_spoof_result,
11315                  vf, "vf");
11316 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11317         TOKEN_STRING_INITIALIZER
11318                 (struct cmd_vf_vlan_anti_spoof_result,
11319                  vlan, "vlan");
11320 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11321         TOKEN_STRING_INITIALIZER
11322                 (struct cmd_vf_vlan_anti_spoof_result,
11323                  antispoof, "antispoof");
11324 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11325         TOKEN_NUM_INITIALIZER
11326                 (struct cmd_vf_vlan_anti_spoof_result,
11327                  port_id, UINT8);
11328 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11329         TOKEN_NUM_INITIALIZER
11330                 (struct cmd_vf_vlan_anti_spoof_result,
11331                  vf_id, UINT32);
11332 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11333         TOKEN_STRING_INITIALIZER
11334                 (struct cmd_vf_vlan_anti_spoof_result,
11335                  on_off, "on#off");
11336
11337 static void
11338 cmd_set_vf_vlan_anti_spoof_parsed(
11339         void *parsed_result,
11340         __attribute__((unused)) struct cmdline *cl,
11341         __attribute__((unused)) void *data)
11342 {
11343         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11344         int ret = -ENOTSUP;
11345
11346         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11347
11348         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11349                 return;
11350
11351 #ifdef RTE_LIBRTE_IXGBE_PMD
11352         if (ret == -ENOTSUP)
11353                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11354                                 res->vf_id, is_on);
11355 #endif
11356 #ifdef RTE_LIBRTE_I40E_PMD
11357         if (ret == -ENOTSUP)
11358                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11359                                 res->vf_id, is_on);
11360 #endif
11361 #ifdef RTE_LIBRTE_BNXT_PMD
11362         if (ret == -ENOTSUP)
11363                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11364                                 res->vf_id, is_on);
11365 #endif
11366
11367         switch (ret) {
11368         case 0:
11369                 break;
11370         case -EINVAL:
11371                 printf("invalid vf_id %d\n", res->vf_id);
11372                 break;
11373         case -ENODEV:
11374                 printf("invalid port_id %d\n", res->port_id);
11375                 break;
11376         case -ENOTSUP:
11377                 printf("function not implemented\n");
11378                 break;
11379         default:
11380                 printf("programming error: (%s)\n", strerror(-ret));
11381         }
11382 }
11383
11384 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11385         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11386         .data = NULL,
11387         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11388         .tokens = {
11389                 (void *)&cmd_vf_vlan_anti_spoof_set,
11390                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11391                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11392                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11393                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11394                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11395                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11396                 NULL,
11397         },
11398 };
11399
11400 /* vf mac anti spoof configuration */
11401
11402 /* Common result structure for vf mac anti spoof */
11403 struct cmd_vf_mac_anti_spoof_result {
11404         cmdline_fixed_string_t set;
11405         cmdline_fixed_string_t vf;
11406         cmdline_fixed_string_t mac;
11407         cmdline_fixed_string_t antispoof;
11408         uint8_t port_id;
11409         uint32_t vf_id;
11410         cmdline_fixed_string_t on_off;
11411 };
11412
11413 /* Common CLI fields for vf mac anti spoof enable disable */
11414 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11415         TOKEN_STRING_INITIALIZER
11416                 (struct cmd_vf_mac_anti_spoof_result,
11417                  set, "set");
11418 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11419         TOKEN_STRING_INITIALIZER
11420                 (struct cmd_vf_mac_anti_spoof_result,
11421                  vf, "vf");
11422 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11423         TOKEN_STRING_INITIALIZER
11424                 (struct cmd_vf_mac_anti_spoof_result,
11425                  mac, "mac");
11426 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11427         TOKEN_STRING_INITIALIZER
11428                 (struct cmd_vf_mac_anti_spoof_result,
11429                  antispoof, "antispoof");
11430 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11431         TOKEN_NUM_INITIALIZER
11432                 (struct cmd_vf_mac_anti_spoof_result,
11433                  port_id, UINT8);
11434 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11435         TOKEN_NUM_INITIALIZER
11436                 (struct cmd_vf_mac_anti_spoof_result,
11437                  vf_id, UINT32);
11438 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11439         TOKEN_STRING_INITIALIZER
11440                 (struct cmd_vf_mac_anti_spoof_result,
11441                  on_off, "on#off");
11442
11443 static void
11444 cmd_set_vf_mac_anti_spoof_parsed(
11445         void *parsed_result,
11446         __attribute__((unused)) struct cmdline *cl,
11447         __attribute__((unused)) void *data)
11448 {
11449         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11450         int ret = -ENOTSUP;
11451
11452         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11453
11454         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11455                 return;
11456
11457 #ifdef RTE_LIBRTE_IXGBE_PMD
11458         if (ret == -ENOTSUP)
11459                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11460                         res->vf_id, is_on);
11461 #endif
11462 #ifdef RTE_LIBRTE_I40E_PMD
11463         if (ret == -ENOTSUP)
11464                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11465                         res->vf_id, is_on);
11466 #endif
11467 #ifdef RTE_LIBRTE_BNXT_PMD
11468         if (ret == -ENOTSUP)
11469                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11470                         res->vf_id, is_on);
11471 #endif
11472
11473         switch (ret) {
11474         case 0:
11475                 break;
11476         case -EINVAL:
11477                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11478                 break;
11479         case -ENODEV:
11480                 printf("invalid port_id %d\n", res->port_id);
11481                 break;
11482         case -ENOTSUP:
11483                 printf("function not implemented\n");
11484                 break;
11485         default:
11486                 printf("programming error: (%s)\n", strerror(-ret));
11487         }
11488 }
11489
11490 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11491         .f = cmd_set_vf_mac_anti_spoof_parsed,
11492         .data = NULL,
11493         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11494         .tokens = {
11495                 (void *)&cmd_vf_mac_anti_spoof_set,
11496                 (void *)&cmd_vf_mac_anti_spoof_vf,
11497                 (void *)&cmd_vf_mac_anti_spoof_mac,
11498                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11499                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11500                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11501                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11502                 NULL,
11503         },
11504 };
11505
11506 /* vf vlan strip queue configuration */
11507
11508 /* Common result structure for vf mac anti spoof */
11509 struct cmd_vf_vlan_stripq_result {
11510         cmdline_fixed_string_t set;
11511         cmdline_fixed_string_t vf;
11512         cmdline_fixed_string_t vlan;
11513         cmdline_fixed_string_t stripq;
11514         uint8_t port_id;
11515         uint16_t vf_id;
11516         cmdline_fixed_string_t on_off;
11517 };
11518
11519 /* Common CLI fields for vf vlan strip enable disable */
11520 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11521         TOKEN_STRING_INITIALIZER
11522                 (struct cmd_vf_vlan_stripq_result,
11523                  set, "set");
11524 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11525         TOKEN_STRING_INITIALIZER
11526                 (struct cmd_vf_vlan_stripq_result,
11527                  vf, "vf");
11528 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11529         TOKEN_STRING_INITIALIZER
11530                 (struct cmd_vf_vlan_stripq_result,
11531                  vlan, "vlan");
11532 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11533         TOKEN_STRING_INITIALIZER
11534                 (struct cmd_vf_vlan_stripq_result,
11535                  stripq, "stripq");
11536 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11537         TOKEN_NUM_INITIALIZER
11538                 (struct cmd_vf_vlan_stripq_result,
11539                  port_id, UINT8);
11540 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11541         TOKEN_NUM_INITIALIZER
11542                 (struct cmd_vf_vlan_stripq_result,
11543                  vf_id, UINT16);
11544 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11545         TOKEN_STRING_INITIALIZER
11546                 (struct cmd_vf_vlan_stripq_result,
11547                  on_off, "on#off");
11548
11549 static void
11550 cmd_set_vf_vlan_stripq_parsed(
11551         void *parsed_result,
11552         __attribute__((unused)) struct cmdline *cl,
11553         __attribute__((unused)) void *data)
11554 {
11555         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11556         int ret = -ENOTSUP;
11557
11558         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11559
11560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11561                 return;
11562
11563 #ifdef RTE_LIBRTE_IXGBE_PMD
11564         if (ret == -ENOTSUP)
11565                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11566                         res->vf_id, is_on);
11567 #endif
11568 #ifdef RTE_LIBRTE_I40E_PMD
11569         if (ret == -ENOTSUP)
11570                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11571                         res->vf_id, is_on);
11572 #endif
11573 #ifdef RTE_LIBRTE_BNXT_PMD
11574         if (ret == -ENOTSUP)
11575                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11576                         res->vf_id, is_on);
11577 #endif
11578
11579         switch (ret) {
11580         case 0:
11581                 break;
11582         case -EINVAL:
11583                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11584                 break;
11585         case -ENODEV:
11586                 printf("invalid port_id %d\n", res->port_id);
11587                 break;
11588         case -ENOTSUP:
11589                 printf("function not implemented\n");
11590                 break;
11591         default:
11592                 printf("programming error: (%s)\n", strerror(-ret));
11593         }
11594 }
11595
11596 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11597         .f = cmd_set_vf_vlan_stripq_parsed,
11598         .data = NULL,
11599         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11600         .tokens = {
11601                 (void *)&cmd_vf_vlan_stripq_set,
11602                 (void *)&cmd_vf_vlan_stripq_vf,
11603                 (void *)&cmd_vf_vlan_stripq_vlan,
11604                 (void *)&cmd_vf_vlan_stripq_stripq,
11605                 (void *)&cmd_vf_vlan_stripq_port_id,
11606                 (void *)&cmd_vf_vlan_stripq_vf_id,
11607                 (void *)&cmd_vf_vlan_stripq_on_off,
11608                 NULL,
11609         },
11610 };
11611
11612 /* vf vlan insert configuration */
11613
11614 /* Common result structure for vf vlan insert */
11615 struct cmd_vf_vlan_insert_result {
11616         cmdline_fixed_string_t set;
11617         cmdline_fixed_string_t vf;
11618         cmdline_fixed_string_t vlan;
11619         cmdline_fixed_string_t insert;
11620         uint8_t port_id;
11621         uint16_t vf_id;
11622         uint16_t vlan_id;
11623 };
11624
11625 /* Common CLI fields for vf vlan insert enable disable */
11626 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11627         TOKEN_STRING_INITIALIZER
11628                 (struct cmd_vf_vlan_insert_result,
11629                  set, "set");
11630 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11631         TOKEN_STRING_INITIALIZER
11632                 (struct cmd_vf_vlan_insert_result,
11633                  vf, "vf");
11634 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11635         TOKEN_STRING_INITIALIZER
11636                 (struct cmd_vf_vlan_insert_result,
11637                  vlan, "vlan");
11638 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11639         TOKEN_STRING_INITIALIZER
11640                 (struct cmd_vf_vlan_insert_result,
11641                  insert, "insert");
11642 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11643         TOKEN_NUM_INITIALIZER
11644                 (struct cmd_vf_vlan_insert_result,
11645                  port_id, UINT8);
11646 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11647         TOKEN_NUM_INITIALIZER
11648                 (struct cmd_vf_vlan_insert_result,
11649                  vf_id, UINT16);
11650 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11651         TOKEN_NUM_INITIALIZER
11652                 (struct cmd_vf_vlan_insert_result,
11653                  vlan_id, UINT16);
11654
11655 static void
11656 cmd_set_vf_vlan_insert_parsed(
11657         void *parsed_result,
11658         __attribute__((unused)) struct cmdline *cl,
11659         __attribute__((unused)) void *data)
11660 {
11661         struct cmd_vf_vlan_insert_result *res = parsed_result;
11662         int ret = -ENOTSUP;
11663
11664         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11665                 return;
11666
11667 #ifdef RTE_LIBRTE_IXGBE_PMD
11668         if (ret == -ENOTSUP)
11669                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11670                         res->vlan_id);
11671 #endif
11672 #ifdef RTE_LIBRTE_I40E_PMD
11673         if (ret == -ENOTSUP)
11674                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11675                         res->vlan_id);
11676 #endif
11677 #ifdef RTE_LIBRTE_BNXT_PMD
11678         if (ret == -ENOTSUP)
11679                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11680                         res->vlan_id);
11681 #endif
11682
11683         switch (ret) {
11684         case 0:
11685                 break;
11686         case -EINVAL:
11687                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11688                 break;
11689         case -ENODEV:
11690                 printf("invalid port_id %d\n", res->port_id);
11691                 break;
11692         case -ENOTSUP:
11693                 printf("function not implemented\n");
11694                 break;
11695         default:
11696                 printf("programming error: (%s)\n", strerror(-ret));
11697         }
11698 }
11699
11700 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11701         .f = cmd_set_vf_vlan_insert_parsed,
11702         .data = NULL,
11703         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11704         .tokens = {
11705                 (void *)&cmd_vf_vlan_insert_set,
11706                 (void *)&cmd_vf_vlan_insert_vf,
11707                 (void *)&cmd_vf_vlan_insert_vlan,
11708                 (void *)&cmd_vf_vlan_insert_insert,
11709                 (void *)&cmd_vf_vlan_insert_port_id,
11710                 (void *)&cmd_vf_vlan_insert_vf_id,
11711                 (void *)&cmd_vf_vlan_insert_vlan_id,
11712                 NULL,
11713         },
11714 };
11715
11716 /* tx loopback configuration */
11717
11718 /* Common result structure for tx loopback */
11719 struct cmd_tx_loopback_result {
11720         cmdline_fixed_string_t set;
11721         cmdline_fixed_string_t tx;
11722         cmdline_fixed_string_t loopback;
11723         uint8_t port_id;
11724         cmdline_fixed_string_t on_off;
11725 };
11726
11727 /* Common CLI fields for tx loopback enable disable */
11728 cmdline_parse_token_string_t cmd_tx_loopback_set =
11729         TOKEN_STRING_INITIALIZER
11730                 (struct cmd_tx_loopback_result,
11731                  set, "set");
11732 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11733         TOKEN_STRING_INITIALIZER
11734                 (struct cmd_tx_loopback_result,
11735                  tx, "tx");
11736 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11737         TOKEN_STRING_INITIALIZER
11738                 (struct cmd_tx_loopback_result,
11739                  loopback, "loopback");
11740 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11741         TOKEN_NUM_INITIALIZER
11742                 (struct cmd_tx_loopback_result,
11743                  port_id, UINT8);
11744 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11745         TOKEN_STRING_INITIALIZER
11746                 (struct cmd_tx_loopback_result,
11747                  on_off, "on#off");
11748
11749 static void
11750 cmd_set_tx_loopback_parsed(
11751         void *parsed_result,
11752         __attribute__((unused)) struct cmdline *cl,
11753         __attribute__((unused)) void *data)
11754 {
11755         struct cmd_tx_loopback_result *res = parsed_result;
11756         int ret = -ENOTSUP;
11757
11758         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11759
11760         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11761                 return;
11762
11763 #ifdef RTE_LIBRTE_IXGBE_PMD
11764         if (ret == -ENOTSUP)
11765                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11766 #endif
11767 #ifdef RTE_LIBRTE_I40E_PMD
11768         if (ret == -ENOTSUP)
11769                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11770 #endif
11771 #ifdef RTE_LIBRTE_BNXT_PMD
11772         if (ret == -ENOTSUP)
11773                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11774 #endif
11775
11776         switch (ret) {
11777         case 0:
11778                 break;
11779         case -EINVAL:
11780                 printf("invalid is_on %d\n", is_on);
11781                 break;
11782         case -ENODEV:
11783                 printf("invalid port_id %d\n", res->port_id);
11784                 break;
11785         case -ENOTSUP:
11786                 printf("function not implemented\n");
11787                 break;
11788         default:
11789                 printf("programming error: (%s)\n", strerror(-ret));
11790         }
11791 }
11792
11793 cmdline_parse_inst_t cmd_set_tx_loopback = {
11794         .f = cmd_set_tx_loopback_parsed,
11795         .data = NULL,
11796         .help_str = "set tx loopback <port_id> on|off",
11797         .tokens = {
11798                 (void *)&cmd_tx_loopback_set,
11799                 (void *)&cmd_tx_loopback_tx,
11800                 (void *)&cmd_tx_loopback_loopback,
11801                 (void *)&cmd_tx_loopback_port_id,
11802                 (void *)&cmd_tx_loopback_on_off,
11803                 NULL,
11804         },
11805 };
11806
11807 /* all queues drop enable configuration */
11808
11809 /* Common result structure for all queues drop enable */
11810 struct cmd_all_queues_drop_en_result {
11811         cmdline_fixed_string_t set;
11812         cmdline_fixed_string_t all;
11813         cmdline_fixed_string_t queues;
11814         cmdline_fixed_string_t drop;
11815         uint8_t port_id;
11816         cmdline_fixed_string_t on_off;
11817 };
11818
11819 /* Common CLI fields for tx loopback enable disable */
11820 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11821         TOKEN_STRING_INITIALIZER
11822                 (struct cmd_all_queues_drop_en_result,
11823                  set, "set");
11824 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11825         TOKEN_STRING_INITIALIZER
11826                 (struct cmd_all_queues_drop_en_result,
11827                  all, "all");
11828 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11829         TOKEN_STRING_INITIALIZER
11830                 (struct cmd_all_queues_drop_en_result,
11831                  queues, "queues");
11832 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11833         TOKEN_STRING_INITIALIZER
11834                 (struct cmd_all_queues_drop_en_result,
11835                  drop, "drop");
11836 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11837         TOKEN_NUM_INITIALIZER
11838                 (struct cmd_all_queues_drop_en_result,
11839                  port_id, UINT8);
11840 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11841         TOKEN_STRING_INITIALIZER
11842                 (struct cmd_all_queues_drop_en_result,
11843                  on_off, "on#off");
11844
11845 static void
11846 cmd_set_all_queues_drop_en_parsed(
11847         void *parsed_result,
11848         __attribute__((unused)) struct cmdline *cl,
11849         __attribute__((unused)) void *data)
11850 {
11851         struct cmd_all_queues_drop_en_result *res = parsed_result;
11852         int ret = -ENOTSUP;
11853         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11854
11855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11856                 return;
11857
11858 #ifdef RTE_LIBRTE_IXGBE_PMD
11859         if (ret == -ENOTSUP)
11860                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11861 #endif
11862 #ifdef RTE_LIBRTE_BNXT_PMD
11863         if (ret == -ENOTSUP)
11864                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11865 #endif
11866         switch (ret) {
11867         case 0:
11868                 break;
11869         case -EINVAL:
11870                 printf("invalid is_on %d\n", is_on);
11871                 break;
11872         case -ENODEV:
11873                 printf("invalid port_id %d\n", res->port_id);
11874                 break;
11875         case -ENOTSUP:
11876                 printf("function not implemented\n");
11877                 break;
11878         default:
11879                 printf("programming error: (%s)\n", strerror(-ret));
11880         }
11881 }
11882
11883 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11884         .f = cmd_set_all_queues_drop_en_parsed,
11885         .data = NULL,
11886         .help_str = "set all queues drop <port_id> on|off",
11887         .tokens = {
11888                 (void *)&cmd_all_queues_drop_en_set,
11889                 (void *)&cmd_all_queues_drop_en_all,
11890                 (void *)&cmd_all_queues_drop_en_queues,
11891                 (void *)&cmd_all_queues_drop_en_drop,
11892                 (void *)&cmd_all_queues_drop_en_port_id,
11893                 (void *)&cmd_all_queues_drop_en_on_off,
11894                 NULL,
11895         },
11896 };
11897
11898 /* vf split drop enable configuration */
11899
11900 /* Common result structure for vf split drop enable */
11901 struct cmd_vf_split_drop_en_result {
11902         cmdline_fixed_string_t set;
11903         cmdline_fixed_string_t vf;
11904         cmdline_fixed_string_t split;
11905         cmdline_fixed_string_t drop;
11906         uint8_t port_id;
11907         uint16_t vf_id;
11908         cmdline_fixed_string_t on_off;
11909 };
11910
11911 /* Common CLI fields for vf split drop enable disable */
11912 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11913         TOKEN_STRING_INITIALIZER
11914                 (struct cmd_vf_split_drop_en_result,
11915                  set, "set");
11916 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11917         TOKEN_STRING_INITIALIZER
11918                 (struct cmd_vf_split_drop_en_result,
11919                  vf, "vf");
11920 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11921         TOKEN_STRING_INITIALIZER
11922                 (struct cmd_vf_split_drop_en_result,
11923                  split, "split");
11924 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11925         TOKEN_STRING_INITIALIZER
11926                 (struct cmd_vf_split_drop_en_result,
11927                  drop, "drop");
11928 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11929         TOKEN_NUM_INITIALIZER
11930                 (struct cmd_vf_split_drop_en_result,
11931                  port_id, UINT8);
11932 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11933         TOKEN_NUM_INITIALIZER
11934                 (struct cmd_vf_split_drop_en_result,
11935                  vf_id, UINT16);
11936 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11937         TOKEN_STRING_INITIALIZER
11938                 (struct cmd_vf_split_drop_en_result,
11939                  on_off, "on#off");
11940
11941 static void
11942 cmd_set_vf_split_drop_en_parsed(
11943         void *parsed_result,
11944         __attribute__((unused)) struct cmdline *cl,
11945         __attribute__((unused)) void *data)
11946 {
11947         struct cmd_vf_split_drop_en_result *res = parsed_result;
11948         int ret = -ENOTSUP;
11949         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11950
11951         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11952                 return;
11953
11954 #ifdef RTE_LIBRTE_IXGBE_PMD
11955         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11956                         is_on);
11957 #endif
11958         switch (ret) {
11959         case 0:
11960                 break;
11961         case -EINVAL:
11962                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11963                 break;
11964         case -ENODEV:
11965                 printf("invalid port_id %d\n", res->port_id);
11966                 break;
11967         case -ENOTSUP:
11968                 printf("not supported on port %d\n", res->port_id);
11969                 break;
11970         default:
11971                 printf("programming error: (%s)\n", strerror(-ret));
11972         }
11973 }
11974
11975 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11976         .f = cmd_set_vf_split_drop_en_parsed,
11977         .data = NULL,
11978         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11979         .tokens = {
11980                 (void *)&cmd_vf_split_drop_en_set,
11981                 (void *)&cmd_vf_split_drop_en_vf,
11982                 (void *)&cmd_vf_split_drop_en_split,
11983                 (void *)&cmd_vf_split_drop_en_drop,
11984                 (void *)&cmd_vf_split_drop_en_port_id,
11985                 (void *)&cmd_vf_split_drop_en_vf_id,
11986                 (void *)&cmd_vf_split_drop_en_on_off,
11987                 NULL,
11988         },
11989 };
11990
11991 /* vf mac address configuration */
11992
11993 /* Common result structure for vf mac address */
11994 struct cmd_set_vf_mac_addr_result {
11995         cmdline_fixed_string_t set;
11996         cmdline_fixed_string_t vf;
11997         cmdline_fixed_string_t mac;
11998         cmdline_fixed_string_t addr;
11999         uint8_t port_id;
12000         uint16_t vf_id;
12001         struct ether_addr mac_addr;
12002
12003 };
12004
12005 /* Common CLI fields for vf split drop enable disable */
12006 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12007         TOKEN_STRING_INITIALIZER
12008                 (struct cmd_set_vf_mac_addr_result,
12009                  set, "set");
12010 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12011         TOKEN_STRING_INITIALIZER
12012                 (struct cmd_set_vf_mac_addr_result,
12013                  vf, "vf");
12014 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12015         TOKEN_STRING_INITIALIZER
12016                 (struct cmd_set_vf_mac_addr_result,
12017                  mac, "mac");
12018 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12019         TOKEN_STRING_INITIALIZER
12020                 (struct cmd_set_vf_mac_addr_result,
12021                  addr, "addr");
12022 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12023         TOKEN_NUM_INITIALIZER
12024                 (struct cmd_set_vf_mac_addr_result,
12025                  port_id, UINT8);
12026 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12027         TOKEN_NUM_INITIALIZER
12028                 (struct cmd_set_vf_mac_addr_result,
12029                  vf_id, UINT16);
12030 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12031         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12032                  mac_addr);
12033
12034 static void
12035 cmd_set_vf_mac_addr_parsed(
12036         void *parsed_result,
12037         __attribute__((unused)) struct cmdline *cl,
12038         __attribute__((unused)) void *data)
12039 {
12040         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12041         int ret = -ENOTSUP;
12042
12043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12044                 return;
12045
12046 #ifdef RTE_LIBRTE_IXGBE_PMD
12047         if (ret == -ENOTSUP)
12048                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12049                                 &res->mac_addr);
12050 #endif
12051 #ifdef RTE_LIBRTE_I40E_PMD
12052         if (ret == -ENOTSUP)
12053                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12054                                 &res->mac_addr);
12055 #endif
12056 #ifdef RTE_LIBRTE_BNXT_PMD
12057         if (ret == -ENOTSUP)
12058                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12059                                 &res->mac_addr);
12060 #endif
12061
12062         switch (ret) {
12063         case 0:
12064                 break;
12065         case -EINVAL:
12066                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12067                 break;
12068         case -ENODEV:
12069                 printf("invalid port_id %d\n", res->port_id);
12070                 break;
12071         case -ENOTSUP:
12072                 printf("function not implemented\n");
12073                 break;
12074         default:
12075                 printf("programming error: (%s)\n", strerror(-ret));
12076         }
12077 }
12078
12079 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12080         .f = cmd_set_vf_mac_addr_parsed,
12081         .data = NULL,
12082         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12083         .tokens = {
12084                 (void *)&cmd_set_vf_mac_addr_set,
12085                 (void *)&cmd_set_vf_mac_addr_vf,
12086                 (void *)&cmd_set_vf_mac_addr_mac,
12087                 (void *)&cmd_set_vf_mac_addr_addr,
12088                 (void *)&cmd_set_vf_mac_addr_port_id,
12089                 (void *)&cmd_set_vf_mac_addr_vf_id,
12090                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12091                 NULL,
12092         },
12093 };
12094
12095 /* MACsec configuration */
12096
12097 /* Common result structure for MACsec offload enable */
12098 struct cmd_macsec_offload_on_result {
12099         cmdline_fixed_string_t set;
12100         cmdline_fixed_string_t macsec;
12101         cmdline_fixed_string_t offload;
12102         uint8_t port_id;
12103         cmdline_fixed_string_t on;
12104         cmdline_fixed_string_t encrypt;
12105         cmdline_fixed_string_t en_on_off;
12106         cmdline_fixed_string_t replay_protect;
12107         cmdline_fixed_string_t rp_on_off;
12108 };
12109
12110 /* Common CLI fields for MACsec offload disable */
12111 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_macsec_offload_on_result,
12114                  set, "set");
12115 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12116         TOKEN_STRING_INITIALIZER
12117                 (struct cmd_macsec_offload_on_result,
12118                  macsec, "macsec");
12119 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12120         TOKEN_STRING_INITIALIZER
12121                 (struct cmd_macsec_offload_on_result,
12122                  offload, "offload");
12123 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12124         TOKEN_NUM_INITIALIZER
12125                 (struct cmd_macsec_offload_on_result,
12126                  port_id, UINT8);
12127 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12128         TOKEN_STRING_INITIALIZER
12129                 (struct cmd_macsec_offload_on_result,
12130                  on, "on");
12131 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12132         TOKEN_STRING_INITIALIZER
12133                 (struct cmd_macsec_offload_on_result,
12134                  encrypt, "encrypt");
12135 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12136         TOKEN_STRING_INITIALIZER
12137                 (struct cmd_macsec_offload_on_result,
12138                  en_on_off, "on#off");
12139 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12140         TOKEN_STRING_INITIALIZER
12141                 (struct cmd_macsec_offload_on_result,
12142                  replay_protect, "replay-protect");
12143 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12144         TOKEN_STRING_INITIALIZER
12145                 (struct cmd_macsec_offload_on_result,
12146                  rp_on_off, "on#off");
12147
12148 static void
12149 cmd_set_macsec_offload_on_parsed(
12150         void *parsed_result,
12151         __attribute__((unused)) struct cmdline *cl,
12152         __attribute__((unused)) void *data)
12153 {
12154         struct cmd_macsec_offload_on_result *res = parsed_result;
12155         int ret = -ENOTSUP;
12156         portid_t port_id = res->port_id;
12157         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12158         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12159
12160         if (port_id_is_invalid(port_id, ENABLED_WARN))
12161                 return;
12162
12163         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12164 #ifdef RTE_LIBRTE_IXGBE_PMD
12165         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12166 #endif
12167         RTE_SET_USED(en);
12168         RTE_SET_USED(rp);
12169
12170         switch (ret) {
12171         case 0:
12172                 break;
12173         case -ENODEV:
12174                 printf("invalid port_id %d\n", port_id);
12175                 break;
12176         case -ENOTSUP:
12177                 printf("not supported on port %d\n", port_id);
12178                 break;
12179         default:
12180                 printf("programming error: (%s)\n", strerror(-ret));
12181         }
12182 }
12183
12184 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12185         .f = cmd_set_macsec_offload_on_parsed,
12186         .data = NULL,
12187         .help_str = "set macsec offload <port_id> on "
12188                 "encrypt on|off replay-protect on|off",
12189         .tokens = {
12190                 (void *)&cmd_macsec_offload_on_set,
12191                 (void *)&cmd_macsec_offload_on_macsec,
12192                 (void *)&cmd_macsec_offload_on_offload,
12193                 (void *)&cmd_macsec_offload_on_port_id,
12194                 (void *)&cmd_macsec_offload_on_on,
12195                 (void *)&cmd_macsec_offload_on_encrypt,
12196                 (void *)&cmd_macsec_offload_on_en_on_off,
12197                 (void *)&cmd_macsec_offload_on_replay_protect,
12198                 (void *)&cmd_macsec_offload_on_rp_on_off,
12199                 NULL,
12200         },
12201 };
12202
12203 /* Common result structure for MACsec offload disable */
12204 struct cmd_macsec_offload_off_result {
12205         cmdline_fixed_string_t set;
12206         cmdline_fixed_string_t macsec;
12207         cmdline_fixed_string_t offload;
12208         uint8_t port_id;
12209         cmdline_fixed_string_t off;
12210 };
12211
12212 /* Common CLI fields for MACsec offload disable */
12213 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12214         TOKEN_STRING_INITIALIZER
12215                 (struct cmd_macsec_offload_off_result,
12216                  set, "set");
12217 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_macsec_offload_off_result,
12220                  macsec, "macsec");
12221 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12222         TOKEN_STRING_INITIALIZER
12223                 (struct cmd_macsec_offload_off_result,
12224                  offload, "offload");
12225 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12226         TOKEN_NUM_INITIALIZER
12227                 (struct cmd_macsec_offload_off_result,
12228                  port_id, UINT8);
12229 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12230         TOKEN_STRING_INITIALIZER
12231                 (struct cmd_macsec_offload_off_result,
12232                  off, "off");
12233
12234 static void
12235 cmd_set_macsec_offload_off_parsed(
12236         void *parsed_result,
12237         __attribute__((unused)) struct cmdline *cl,
12238         __attribute__((unused)) void *data)
12239 {
12240         struct cmd_macsec_offload_off_result *res = parsed_result;
12241         int ret = -ENOTSUP;
12242         portid_t port_id = res->port_id;
12243
12244         if (port_id_is_invalid(port_id, ENABLED_WARN))
12245                 return;
12246
12247         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12248 #ifdef RTE_LIBRTE_IXGBE_PMD
12249         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12250 #endif
12251
12252         switch (ret) {
12253         case 0:
12254                 break;
12255         case -ENODEV:
12256                 printf("invalid port_id %d\n", port_id);
12257                 break;
12258         case -ENOTSUP:
12259                 printf("not supported on port %d\n", port_id);
12260                 break;
12261         default:
12262                 printf("programming error: (%s)\n", strerror(-ret));
12263         }
12264 }
12265
12266 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12267         .f = cmd_set_macsec_offload_off_parsed,
12268         .data = NULL,
12269         .help_str = "set macsec offload <port_id> off",
12270         .tokens = {
12271                 (void *)&cmd_macsec_offload_off_set,
12272                 (void *)&cmd_macsec_offload_off_macsec,
12273                 (void *)&cmd_macsec_offload_off_offload,
12274                 (void *)&cmd_macsec_offload_off_port_id,
12275                 (void *)&cmd_macsec_offload_off_off,
12276                 NULL,
12277         },
12278 };
12279
12280 /* Common result structure for MACsec secure connection configure */
12281 struct cmd_macsec_sc_result {
12282         cmdline_fixed_string_t set;
12283         cmdline_fixed_string_t macsec;
12284         cmdline_fixed_string_t sc;
12285         cmdline_fixed_string_t tx_rx;
12286         uint8_t port_id;
12287         struct ether_addr mac;
12288         uint16_t pi;
12289 };
12290
12291 /* Common CLI fields for MACsec secure connection configure */
12292 cmdline_parse_token_string_t cmd_macsec_sc_set =
12293         TOKEN_STRING_INITIALIZER
12294                 (struct cmd_macsec_sc_result,
12295                  set, "set");
12296 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12297         TOKEN_STRING_INITIALIZER
12298                 (struct cmd_macsec_sc_result,
12299                  macsec, "macsec");
12300 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12301         TOKEN_STRING_INITIALIZER
12302                 (struct cmd_macsec_sc_result,
12303                  sc, "sc");
12304 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12305         TOKEN_STRING_INITIALIZER
12306                 (struct cmd_macsec_sc_result,
12307                  tx_rx, "tx#rx");
12308 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12309         TOKEN_NUM_INITIALIZER
12310                 (struct cmd_macsec_sc_result,
12311                  port_id, UINT8);
12312 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12313         TOKEN_ETHERADDR_INITIALIZER
12314                 (struct cmd_macsec_sc_result,
12315                  mac);
12316 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12317         TOKEN_NUM_INITIALIZER
12318                 (struct cmd_macsec_sc_result,
12319                  pi, UINT16);
12320
12321 static void
12322 cmd_set_macsec_sc_parsed(
12323         void *parsed_result,
12324         __attribute__((unused)) struct cmdline *cl,
12325         __attribute__((unused)) void *data)
12326 {
12327         struct cmd_macsec_sc_result *res = parsed_result;
12328         int ret = -ENOTSUP;
12329         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12330
12331 #ifdef RTE_LIBRTE_IXGBE_PMD
12332         ret = is_tx ?
12333                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12334                                 res->mac.addr_bytes) :
12335                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12336                                 res->mac.addr_bytes, res->pi);
12337 #endif
12338         RTE_SET_USED(is_tx);
12339
12340         switch (ret) {
12341         case 0:
12342                 break;
12343         case -ENODEV:
12344                 printf("invalid port_id %d\n", res->port_id);
12345                 break;
12346         case -ENOTSUP:
12347                 printf("not supported on port %d\n", res->port_id);
12348                 break;
12349         default:
12350                 printf("programming error: (%s)\n", strerror(-ret));
12351         }
12352 }
12353
12354 cmdline_parse_inst_t cmd_set_macsec_sc = {
12355         .f = cmd_set_macsec_sc_parsed,
12356         .data = NULL,
12357         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12358         .tokens = {
12359                 (void *)&cmd_macsec_sc_set,
12360                 (void *)&cmd_macsec_sc_macsec,
12361                 (void *)&cmd_macsec_sc_sc,
12362                 (void *)&cmd_macsec_sc_tx_rx,
12363                 (void *)&cmd_macsec_sc_port_id,
12364                 (void *)&cmd_macsec_sc_mac,
12365                 (void *)&cmd_macsec_sc_pi,
12366                 NULL,
12367         },
12368 };
12369
12370 /* Common result structure for MACsec secure connection configure */
12371 struct cmd_macsec_sa_result {
12372         cmdline_fixed_string_t set;
12373         cmdline_fixed_string_t macsec;
12374         cmdline_fixed_string_t sa;
12375         cmdline_fixed_string_t tx_rx;
12376         uint8_t port_id;
12377         uint8_t idx;
12378         uint8_t an;
12379         uint32_t pn;
12380         cmdline_fixed_string_t key;
12381 };
12382
12383 /* Common CLI fields for MACsec secure connection configure */
12384 cmdline_parse_token_string_t cmd_macsec_sa_set =
12385         TOKEN_STRING_INITIALIZER
12386                 (struct cmd_macsec_sa_result,
12387                  set, "set");
12388 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12389         TOKEN_STRING_INITIALIZER
12390                 (struct cmd_macsec_sa_result,
12391                  macsec, "macsec");
12392 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12393         TOKEN_STRING_INITIALIZER
12394                 (struct cmd_macsec_sa_result,
12395                  sa, "sa");
12396 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12397         TOKEN_STRING_INITIALIZER
12398                 (struct cmd_macsec_sa_result,
12399                  tx_rx, "tx#rx");
12400 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12401         TOKEN_NUM_INITIALIZER
12402                 (struct cmd_macsec_sa_result,
12403                  port_id, UINT8);
12404 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12405         TOKEN_NUM_INITIALIZER
12406                 (struct cmd_macsec_sa_result,
12407                  idx, UINT8);
12408 cmdline_parse_token_num_t cmd_macsec_sa_an =
12409         TOKEN_NUM_INITIALIZER
12410                 (struct cmd_macsec_sa_result,
12411                  an, UINT8);
12412 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12413         TOKEN_NUM_INITIALIZER
12414                 (struct cmd_macsec_sa_result,
12415                  pn, UINT32);
12416 cmdline_parse_token_string_t cmd_macsec_sa_key =
12417         TOKEN_STRING_INITIALIZER
12418                 (struct cmd_macsec_sa_result,
12419                  key, NULL);
12420
12421 static void
12422 cmd_set_macsec_sa_parsed(
12423         void *parsed_result,
12424         __attribute__((unused)) struct cmdline *cl,
12425         __attribute__((unused)) void *data)
12426 {
12427         struct cmd_macsec_sa_result *res = parsed_result;
12428         int ret = -ENOTSUP;
12429         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12430         uint8_t key[16] = { 0 };
12431         uint8_t xdgt0;
12432         uint8_t xdgt1;
12433         int key_len;
12434         int i;
12435
12436         key_len = strlen(res->key) / 2;
12437         if (key_len > 16)
12438                 key_len = 16;
12439
12440         for (i = 0; i < key_len; i++) {
12441                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12442                 if (xdgt0 == 0xFF)
12443                         return;
12444                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12445                 if (xdgt1 == 0xFF)
12446                         return;
12447                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12448         }
12449
12450 #ifdef RTE_LIBRTE_IXGBE_PMD
12451         ret = is_tx ?
12452                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12453                         res->idx, res->an, res->pn, key) :
12454                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12455                         res->idx, res->an, res->pn, key);
12456 #endif
12457         RTE_SET_USED(is_tx);
12458         RTE_SET_USED(key);
12459
12460         switch (ret) {
12461         case 0:
12462                 break;
12463         case -EINVAL:
12464                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12465                 break;
12466         case -ENODEV:
12467                 printf("invalid port_id %d\n", res->port_id);
12468                 break;
12469         case -ENOTSUP:
12470                 printf("not supported on port %d\n", res->port_id);
12471                 break;
12472         default:
12473                 printf("programming error: (%s)\n", strerror(-ret));
12474         }
12475 }
12476
12477 cmdline_parse_inst_t cmd_set_macsec_sa = {
12478         .f = cmd_set_macsec_sa_parsed,
12479         .data = NULL,
12480         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12481         .tokens = {
12482                 (void *)&cmd_macsec_sa_set,
12483                 (void *)&cmd_macsec_sa_macsec,
12484                 (void *)&cmd_macsec_sa_sa,
12485                 (void *)&cmd_macsec_sa_tx_rx,
12486                 (void *)&cmd_macsec_sa_port_id,
12487                 (void *)&cmd_macsec_sa_idx,
12488                 (void *)&cmd_macsec_sa_an,
12489                 (void *)&cmd_macsec_sa_pn,
12490                 (void *)&cmd_macsec_sa_key,
12491                 NULL,
12492         },
12493 };
12494
12495 /* VF unicast promiscuous mode configuration */
12496
12497 /* Common result structure for VF unicast promiscuous mode */
12498 struct cmd_vf_promisc_result {
12499         cmdline_fixed_string_t set;
12500         cmdline_fixed_string_t vf;
12501         cmdline_fixed_string_t promisc;
12502         uint8_t port_id;
12503         uint32_t vf_id;
12504         cmdline_fixed_string_t on_off;
12505 };
12506
12507 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12508 cmdline_parse_token_string_t cmd_vf_promisc_set =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_vf_promisc_result,
12511                  set, "set");
12512 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_vf_promisc_result,
12515                  vf, "vf");
12516 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_vf_promisc_result,
12519                  promisc, "promisc");
12520 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12521         TOKEN_NUM_INITIALIZER
12522                 (struct cmd_vf_promisc_result,
12523                  port_id, UINT8);
12524 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12525         TOKEN_NUM_INITIALIZER
12526                 (struct cmd_vf_promisc_result,
12527                  vf_id, UINT32);
12528 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_vf_promisc_result,
12531                  on_off, "on#off");
12532
12533 static void
12534 cmd_set_vf_promisc_parsed(
12535         void *parsed_result,
12536         __attribute__((unused)) struct cmdline *cl,
12537         __attribute__((unused)) void *data)
12538 {
12539         struct cmd_vf_promisc_result *res = parsed_result;
12540         int ret = -ENOTSUP;
12541
12542         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12543
12544         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12545                 return;
12546
12547 #ifdef RTE_LIBRTE_I40E_PMD
12548         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12549                                                   res->vf_id, is_on);
12550 #endif
12551
12552         switch (ret) {
12553         case 0:
12554                 break;
12555         case -EINVAL:
12556                 printf("invalid vf_id %d\n", res->vf_id);
12557                 break;
12558         case -ENODEV:
12559                 printf("invalid port_id %d\n", res->port_id);
12560                 break;
12561         case -ENOTSUP:
12562                 printf("function not implemented\n");
12563                 break;
12564         default:
12565                 printf("programming error: (%s)\n", strerror(-ret));
12566         }
12567 }
12568
12569 cmdline_parse_inst_t cmd_set_vf_promisc = {
12570         .f = cmd_set_vf_promisc_parsed,
12571         .data = NULL,
12572         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12573                 "Set unicast promiscuous mode for a VF from the PF",
12574         .tokens = {
12575                 (void *)&cmd_vf_promisc_set,
12576                 (void *)&cmd_vf_promisc_vf,
12577                 (void *)&cmd_vf_promisc_promisc,
12578                 (void *)&cmd_vf_promisc_port_id,
12579                 (void *)&cmd_vf_promisc_vf_id,
12580                 (void *)&cmd_vf_promisc_on_off,
12581                 NULL,
12582         },
12583 };
12584
12585 /* VF multicast promiscuous mode configuration */
12586
12587 /* Common result structure for VF multicast promiscuous mode */
12588 struct cmd_vf_allmulti_result {
12589         cmdline_fixed_string_t set;
12590         cmdline_fixed_string_t vf;
12591         cmdline_fixed_string_t allmulti;
12592         uint8_t port_id;
12593         uint32_t vf_id;
12594         cmdline_fixed_string_t on_off;
12595 };
12596
12597 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12598 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12599         TOKEN_STRING_INITIALIZER
12600                 (struct cmd_vf_allmulti_result,
12601                  set, "set");
12602 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12603         TOKEN_STRING_INITIALIZER
12604                 (struct cmd_vf_allmulti_result,
12605                  vf, "vf");
12606 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12607         TOKEN_STRING_INITIALIZER
12608                 (struct cmd_vf_allmulti_result,
12609                  allmulti, "allmulti");
12610 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12611         TOKEN_NUM_INITIALIZER
12612                 (struct cmd_vf_allmulti_result,
12613                  port_id, UINT8);
12614 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12615         TOKEN_NUM_INITIALIZER
12616                 (struct cmd_vf_allmulti_result,
12617                  vf_id, UINT32);
12618 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12619         TOKEN_STRING_INITIALIZER
12620                 (struct cmd_vf_allmulti_result,
12621                  on_off, "on#off");
12622
12623 static void
12624 cmd_set_vf_allmulti_parsed(
12625         void *parsed_result,
12626         __attribute__((unused)) struct cmdline *cl,
12627         __attribute__((unused)) void *data)
12628 {
12629         struct cmd_vf_allmulti_result *res = parsed_result;
12630         int ret = -ENOTSUP;
12631
12632         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12633
12634         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12635                 return;
12636
12637 #ifdef RTE_LIBRTE_I40E_PMD
12638         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12639                                                     res->vf_id, is_on);
12640 #endif
12641
12642         switch (ret) {
12643         case 0:
12644                 break;
12645         case -EINVAL:
12646                 printf("invalid vf_id %d\n", res->vf_id);
12647                 break;
12648         case -ENODEV:
12649                 printf("invalid port_id %d\n", res->port_id);
12650                 break;
12651         case -ENOTSUP:
12652                 printf("function not implemented\n");
12653                 break;
12654         default:
12655                 printf("programming error: (%s)\n", strerror(-ret));
12656         }
12657 }
12658
12659 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12660         .f = cmd_set_vf_allmulti_parsed,
12661         .data = NULL,
12662         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12663                 "Set multicast promiscuous mode for a VF from the PF",
12664         .tokens = {
12665                 (void *)&cmd_vf_allmulti_set,
12666                 (void *)&cmd_vf_allmulti_vf,
12667                 (void *)&cmd_vf_allmulti_allmulti,
12668                 (void *)&cmd_vf_allmulti_port_id,
12669                 (void *)&cmd_vf_allmulti_vf_id,
12670                 (void *)&cmd_vf_allmulti_on_off,
12671                 NULL,
12672         },
12673 };
12674
12675 /* vf broadcast mode configuration */
12676
12677 /* Common result structure for vf broadcast */
12678 struct cmd_set_vf_broadcast_result {
12679         cmdline_fixed_string_t set;
12680         cmdline_fixed_string_t vf;
12681         cmdline_fixed_string_t broadcast;
12682         uint8_t port_id;
12683         uint16_t vf_id;
12684         cmdline_fixed_string_t on_off;
12685 };
12686
12687 /* Common CLI fields for vf broadcast enable disable */
12688 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12689         TOKEN_STRING_INITIALIZER
12690                 (struct cmd_set_vf_broadcast_result,
12691                  set, "set");
12692 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12693         TOKEN_STRING_INITIALIZER
12694                 (struct cmd_set_vf_broadcast_result,
12695                  vf, "vf");
12696 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12697         TOKEN_STRING_INITIALIZER
12698                 (struct cmd_set_vf_broadcast_result,
12699                  broadcast, "broadcast");
12700 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12701         TOKEN_NUM_INITIALIZER
12702                 (struct cmd_set_vf_broadcast_result,
12703                  port_id, UINT8);
12704 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12705         TOKEN_NUM_INITIALIZER
12706                 (struct cmd_set_vf_broadcast_result,
12707                  vf_id, UINT16);
12708 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12709         TOKEN_STRING_INITIALIZER
12710                 (struct cmd_set_vf_broadcast_result,
12711                  on_off, "on#off");
12712
12713 static void
12714 cmd_set_vf_broadcast_parsed(
12715         void *parsed_result,
12716         __attribute__((unused)) struct cmdline *cl,
12717         __attribute__((unused)) void *data)
12718 {
12719         struct cmd_set_vf_broadcast_result *res = parsed_result;
12720         int ret = -ENOTSUP;
12721
12722         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12723
12724         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12725                 return;
12726
12727 #ifdef RTE_LIBRTE_I40E_PMD
12728         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12729                                             res->vf_id, is_on);
12730 #endif
12731
12732         switch (ret) {
12733         case 0:
12734                 break;
12735         case -EINVAL:
12736                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12737                 break;
12738         case -ENODEV:
12739                 printf("invalid port_id %d\n", res->port_id);
12740                 break;
12741         case -ENOTSUP:
12742                 printf("function not implemented\n");
12743                 break;
12744         default:
12745                 printf("programming error: (%s)\n", strerror(-ret));
12746         }
12747 }
12748
12749 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12750         .f = cmd_set_vf_broadcast_parsed,
12751         .data = NULL,
12752         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12753         .tokens = {
12754                 (void *)&cmd_set_vf_broadcast_set,
12755                 (void *)&cmd_set_vf_broadcast_vf,
12756                 (void *)&cmd_set_vf_broadcast_broadcast,
12757                 (void *)&cmd_set_vf_broadcast_port_id,
12758                 (void *)&cmd_set_vf_broadcast_vf_id,
12759                 (void *)&cmd_set_vf_broadcast_on_off,
12760                 NULL,
12761         },
12762 };
12763
12764 /* vf vlan tag configuration */
12765
12766 /* Common result structure for vf vlan tag */
12767 struct cmd_set_vf_vlan_tag_result {
12768         cmdline_fixed_string_t set;
12769         cmdline_fixed_string_t vf;
12770         cmdline_fixed_string_t vlan;
12771         cmdline_fixed_string_t tag;
12772         uint8_t port_id;
12773         uint16_t vf_id;
12774         cmdline_fixed_string_t on_off;
12775 };
12776
12777 /* Common CLI fields for vf vlan tag enable disable */
12778 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12779         TOKEN_STRING_INITIALIZER
12780                 (struct cmd_set_vf_vlan_tag_result,
12781                  set, "set");
12782 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12783         TOKEN_STRING_INITIALIZER
12784                 (struct cmd_set_vf_vlan_tag_result,
12785                  vf, "vf");
12786 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12787         TOKEN_STRING_INITIALIZER
12788                 (struct cmd_set_vf_vlan_tag_result,
12789                  vlan, "vlan");
12790 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12791         TOKEN_STRING_INITIALIZER
12792                 (struct cmd_set_vf_vlan_tag_result,
12793                  tag, "tag");
12794 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12795         TOKEN_NUM_INITIALIZER
12796                 (struct cmd_set_vf_vlan_tag_result,
12797                  port_id, UINT8);
12798 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12799         TOKEN_NUM_INITIALIZER
12800                 (struct cmd_set_vf_vlan_tag_result,
12801                  vf_id, UINT16);
12802 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12803         TOKEN_STRING_INITIALIZER
12804                 (struct cmd_set_vf_vlan_tag_result,
12805                  on_off, "on#off");
12806
12807 static void
12808 cmd_set_vf_vlan_tag_parsed(
12809         void *parsed_result,
12810         __attribute__((unused)) struct cmdline *cl,
12811         __attribute__((unused)) void *data)
12812 {
12813         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12814         int ret = -ENOTSUP;
12815
12816         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12817
12818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12819                 return;
12820
12821 #ifdef RTE_LIBRTE_I40E_PMD
12822         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12823                                            res->vf_id, is_on);
12824 #endif
12825
12826         switch (ret) {
12827         case 0:
12828                 break;
12829         case -EINVAL:
12830                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12831                 break;
12832         case -ENODEV:
12833                 printf("invalid port_id %d\n", res->port_id);
12834                 break;
12835         case -ENOTSUP:
12836                 printf("function not implemented\n");
12837                 break;
12838         default:
12839                 printf("programming error: (%s)\n", strerror(-ret));
12840         }
12841 }
12842
12843 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12844         .f = cmd_set_vf_vlan_tag_parsed,
12845         .data = NULL,
12846         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12847         .tokens = {
12848                 (void *)&cmd_set_vf_vlan_tag_set,
12849                 (void *)&cmd_set_vf_vlan_tag_vf,
12850                 (void *)&cmd_set_vf_vlan_tag_vlan,
12851                 (void *)&cmd_set_vf_vlan_tag_tag,
12852                 (void *)&cmd_set_vf_vlan_tag_port_id,
12853                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12854                 (void *)&cmd_set_vf_vlan_tag_on_off,
12855                 NULL,
12856         },
12857 };
12858
12859 /* Common definition of VF and TC TX bandwidth configuration */
12860 struct cmd_vf_tc_bw_result {
12861         cmdline_fixed_string_t set;
12862         cmdline_fixed_string_t vf;
12863         cmdline_fixed_string_t tc;
12864         cmdline_fixed_string_t tx;
12865         cmdline_fixed_string_t min_bw;
12866         cmdline_fixed_string_t max_bw;
12867         cmdline_fixed_string_t strict_link_prio;
12868         uint8_t port_id;
12869         uint16_t vf_id;
12870         uint8_t tc_no;
12871         uint32_t bw;
12872         cmdline_fixed_string_t bw_list;
12873         uint8_t tc_map;
12874 };
12875
12876 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_vf_tc_bw_result,
12879                  set, "set");
12880 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_vf_tc_bw_result,
12883                  vf, "vf");
12884 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_vf_tc_bw_result,
12887                  tc, "tc");
12888 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_vf_tc_bw_result,
12891                  tx, "tx");
12892 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12893         TOKEN_STRING_INITIALIZER
12894                 (struct cmd_vf_tc_bw_result,
12895                  strict_link_prio, "strict-link-priority");
12896 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12897         TOKEN_STRING_INITIALIZER
12898                 (struct cmd_vf_tc_bw_result,
12899                  min_bw, "min-bandwidth");
12900 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12901         TOKEN_STRING_INITIALIZER
12902                 (struct cmd_vf_tc_bw_result,
12903                  max_bw, "max-bandwidth");
12904 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12905         TOKEN_NUM_INITIALIZER
12906                 (struct cmd_vf_tc_bw_result,
12907                  port_id, UINT8);
12908 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12909         TOKEN_NUM_INITIALIZER
12910                 (struct cmd_vf_tc_bw_result,
12911                  vf_id, UINT16);
12912 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12913         TOKEN_NUM_INITIALIZER
12914                 (struct cmd_vf_tc_bw_result,
12915                  tc_no, UINT8);
12916 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12917         TOKEN_NUM_INITIALIZER
12918                 (struct cmd_vf_tc_bw_result,
12919                  bw, UINT32);
12920 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_vf_tc_bw_result,
12923                  bw_list, NULL);
12924 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12925         TOKEN_NUM_INITIALIZER
12926                 (struct cmd_vf_tc_bw_result,
12927                  tc_map, UINT8);
12928
12929 /* VF max bandwidth setting */
12930 static void
12931 cmd_vf_max_bw_parsed(
12932         void *parsed_result,
12933         __attribute__((unused)) struct cmdline *cl,
12934         __attribute__((unused)) void *data)
12935 {
12936         struct cmd_vf_tc_bw_result *res = parsed_result;
12937         int ret = -ENOTSUP;
12938
12939         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12940                 return;
12941
12942 #ifdef RTE_LIBRTE_I40E_PMD
12943         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12944                                          res->vf_id, res->bw);
12945 #endif
12946
12947         switch (ret) {
12948         case 0:
12949                 break;
12950         case -EINVAL:
12951                 printf("invalid vf_id %d or bandwidth %d\n",
12952                        res->vf_id, res->bw);
12953                 break;
12954         case -ENODEV:
12955                 printf("invalid port_id %d\n", res->port_id);
12956                 break;
12957         case -ENOTSUP:
12958                 printf("function not implemented\n");
12959                 break;
12960         default:
12961                 printf("programming error: (%s)\n", strerror(-ret));
12962         }
12963 }
12964
12965 cmdline_parse_inst_t cmd_vf_max_bw = {
12966         .f = cmd_vf_max_bw_parsed,
12967         .data = NULL,
12968         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12969         .tokens = {
12970                 (void *)&cmd_vf_tc_bw_set,
12971                 (void *)&cmd_vf_tc_bw_vf,
12972                 (void *)&cmd_vf_tc_bw_tx,
12973                 (void *)&cmd_vf_tc_bw_max_bw,
12974                 (void *)&cmd_vf_tc_bw_port_id,
12975                 (void *)&cmd_vf_tc_bw_vf_id,
12976                 (void *)&cmd_vf_tc_bw_bw,
12977                 NULL,
12978         },
12979 };
12980
12981 static int
12982 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12983                            uint8_t *tc_num,
12984                            char *str)
12985 {
12986         uint32_t size;
12987         const char *p, *p0 = str;
12988         char s[256];
12989         char *end;
12990         char *str_fld[16];
12991         uint16_t i;
12992         int ret;
12993
12994         p = strchr(p0, '(');
12995         if (p == NULL) {
12996                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12997                 return -1;
12998         }
12999         p++;
13000         p0 = strchr(p, ')');
13001         if (p0 == NULL) {
13002                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13003                 return -1;
13004         }
13005         size = p0 - p;
13006         if (size >= sizeof(s)) {
13007                 printf("The string size exceeds the internal buffer size\n");
13008                 return -1;
13009         }
13010         snprintf(s, sizeof(s), "%.*s", size, p);
13011         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13012         if (ret <= 0) {
13013                 printf("Failed to get the bandwidth list. ");
13014                 return -1;
13015         }
13016         *tc_num = ret;
13017         for (i = 0; i < ret; i++)
13018                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13019
13020         return 0;
13021 }
13022
13023 /* TC min bandwidth setting */
13024 static void
13025 cmd_vf_tc_min_bw_parsed(
13026         void *parsed_result,
13027         __attribute__((unused)) struct cmdline *cl,
13028         __attribute__((unused)) void *data)
13029 {
13030         struct cmd_vf_tc_bw_result *res = parsed_result;
13031         uint8_t tc_num;
13032         uint8_t bw[16];
13033         int ret = -ENOTSUP;
13034
13035         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13036                 return;
13037
13038         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13039         if (ret)
13040                 return;
13041
13042 #ifdef RTE_LIBRTE_I40E_PMD
13043         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13044                                               tc_num, bw);
13045 #endif
13046
13047         switch (ret) {
13048         case 0:
13049                 break;
13050         case -EINVAL:
13051                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13052                 break;
13053         case -ENODEV:
13054                 printf("invalid port_id %d\n", res->port_id);
13055                 break;
13056         case -ENOTSUP:
13057                 printf("function not implemented\n");
13058                 break;
13059         default:
13060                 printf("programming error: (%s)\n", strerror(-ret));
13061         }
13062 }
13063
13064 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13065         .f = cmd_vf_tc_min_bw_parsed,
13066         .data = NULL,
13067         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13068                     " <bw1, bw2, ...>",
13069         .tokens = {
13070                 (void *)&cmd_vf_tc_bw_set,
13071                 (void *)&cmd_vf_tc_bw_vf,
13072                 (void *)&cmd_vf_tc_bw_tc,
13073                 (void *)&cmd_vf_tc_bw_tx,
13074                 (void *)&cmd_vf_tc_bw_min_bw,
13075                 (void *)&cmd_vf_tc_bw_port_id,
13076                 (void *)&cmd_vf_tc_bw_vf_id,
13077                 (void *)&cmd_vf_tc_bw_bw_list,
13078                 NULL,
13079         },
13080 };
13081
13082 static void
13083 cmd_tc_min_bw_parsed(
13084         void *parsed_result,
13085         __attribute__((unused)) struct cmdline *cl,
13086         __attribute__((unused)) void *data)
13087 {
13088         struct cmd_vf_tc_bw_result *res = parsed_result;
13089         struct rte_port *port;
13090         uint8_t tc_num;
13091         uint8_t bw[16];
13092         int ret = -ENOTSUP;
13093
13094         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13095                 return;
13096
13097         port = &ports[res->port_id];
13098         /** Check if the port is not started **/
13099         if (port->port_status != RTE_PORT_STOPPED) {
13100                 printf("Please stop port %d first\n", res->port_id);
13101                 return;
13102         }
13103
13104         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13105         if (ret)
13106                 return;
13107
13108 #ifdef RTE_LIBRTE_IXGBE_PMD
13109         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13110 #endif
13111
13112         switch (ret) {
13113         case 0:
13114                 break;
13115         case -EINVAL:
13116                 printf("invalid bandwidth\n");
13117                 break;
13118         case -ENODEV:
13119                 printf("invalid port_id %d\n", res->port_id);
13120                 break;
13121         case -ENOTSUP:
13122                 printf("function not implemented\n");
13123                 break;
13124         default:
13125                 printf("programming error: (%s)\n", strerror(-ret));
13126         }
13127 }
13128
13129 cmdline_parse_inst_t cmd_tc_min_bw = {
13130         .f = cmd_tc_min_bw_parsed,
13131         .data = NULL,
13132         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13133         .tokens = {
13134                 (void *)&cmd_vf_tc_bw_set,
13135                 (void *)&cmd_vf_tc_bw_tc,
13136                 (void *)&cmd_vf_tc_bw_tx,
13137                 (void *)&cmd_vf_tc_bw_min_bw,
13138                 (void *)&cmd_vf_tc_bw_port_id,
13139                 (void *)&cmd_vf_tc_bw_bw_list,
13140                 NULL,
13141         },
13142 };
13143
13144 /* TC max bandwidth setting */
13145 static void
13146 cmd_vf_tc_max_bw_parsed(
13147         void *parsed_result,
13148         __attribute__((unused)) struct cmdline *cl,
13149         __attribute__((unused)) void *data)
13150 {
13151         struct cmd_vf_tc_bw_result *res = parsed_result;
13152         int ret = -ENOTSUP;
13153
13154         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13155                 return;
13156
13157 #ifdef RTE_LIBRTE_I40E_PMD
13158         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13159                                             res->tc_no, res->bw);
13160 #endif
13161
13162         switch (ret) {
13163         case 0:
13164                 break;
13165         case -EINVAL:
13166                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13167                        res->vf_id, res->tc_no, res->bw);
13168                 break;
13169         case -ENODEV:
13170                 printf("invalid port_id %d\n", res->port_id);
13171                 break;
13172         case -ENOTSUP:
13173                 printf("function not implemented\n");
13174                 break;
13175         default:
13176                 printf("programming error: (%s)\n", strerror(-ret));
13177         }
13178 }
13179
13180 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13181         .f = cmd_vf_tc_max_bw_parsed,
13182         .data = NULL,
13183         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13184                     " <bandwidth>",
13185         .tokens = {
13186                 (void *)&cmd_vf_tc_bw_set,
13187                 (void *)&cmd_vf_tc_bw_vf,
13188                 (void *)&cmd_vf_tc_bw_tc,
13189                 (void *)&cmd_vf_tc_bw_tx,
13190                 (void *)&cmd_vf_tc_bw_max_bw,
13191                 (void *)&cmd_vf_tc_bw_port_id,
13192                 (void *)&cmd_vf_tc_bw_vf_id,
13193                 (void *)&cmd_vf_tc_bw_tc_no,
13194                 (void *)&cmd_vf_tc_bw_bw,
13195                 NULL,
13196         },
13197 };
13198
13199 /* Strict link priority scheduling mode setting */
13200 static void
13201 cmd_strict_link_prio_parsed(
13202         void *parsed_result,
13203         __attribute__((unused)) struct cmdline *cl,
13204         __attribute__((unused)) void *data)
13205 {
13206         struct cmd_vf_tc_bw_result *res = parsed_result;
13207         int ret = -ENOTSUP;
13208
13209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13210                 return;
13211
13212 #ifdef RTE_LIBRTE_I40E_PMD
13213         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13214 #endif
13215
13216         switch (ret) {
13217         case 0:
13218                 break;
13219         case -EINVAL:
13220                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13221                 break;
13222         case -ENODEV:
13223                 printf("invalid port_id %d\n", res->port_id);
13224                 break;
13225         case -ENOTSUP:
13226                 printf("function not implemented\n");
13227                 break;
13228         default:
13229                 printf("programming error: (%s)\n", strerror(-ret));
13230         }
13231 }
13232
13233 cmdline_parse_inst_t cmd_strict_link_prio = {
13234         .f = cmd_strict_link_prio_parsed,
13235         .data = NULL,
13236         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13237         .tokens = {
13238                 (void *)&cmd_vf_tc_bw_set,
13239                 (void *)&cmd_vf_tc_bw_tx,
13240                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13241                 (void *)&cmd_vf_tc_bw_port_id,
13242                 (void *)&cmd_vf_tc_bw_tc_map,
13243                 NULL,
13244         },
13245 };
13246
13247 /* Load dynamic device personalization*/
13248 struct cmd_ddp_add_result {
13249         cmdline_fixed_string_t ddp;
13250         cmdline_fixed_string_t add;
13251         uint8_t port_id;
13252         char filepath[];
13253 };
13254
13255 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13256         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13257 cmdline_parse_token_string_t cmd_ddp_add_add =
13258         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13259 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13260         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13261 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13262         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13263
13264 static void
13265 cmd_ddp_add_parsed(
13266         void *parsed_result,
13267         __attribute__((unused)) struct cmdline *cl,
13268         __attribute__((unused)) void *data)
13269 {
13270         struct cmd_ddp_add_result *res = parsed_result;
13271         uint8_t *buff;
13272         uint32_t size;
13273         char *filepath;
13274         char *file_fld[2];
13275         int file_num;
13276         int ret = -ENOTSUP;
13277
13278         if (res->port_id > nb_ports) {
13279                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13280                 return;
13281         }
13282
13283         if (!all_ports_stopped()) {
13284                 printf("Please stop all ports first\n");
13285                 return;
13286         }
13287
13288         filepath = strdup(res->filepath);
13289         if (filepath == NULL) {
13290                 printf("Failed to allocate memory\n");
13291                 return;
13292         }
13293         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13294
13295         buff = open_ddp_package_file(file_fld[0], &size);
13296         if (!buff) {
13297                 free((void *)filepath);
13298                 return;
13299         }
13300
13301 #ifdef RTE_LIBRTE_I40E_PMD
13302         if (ret == -ENOTSUP)
13303                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13304                                                buff, size,
13305                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13306 #endif
13307
13308         if (ret == -EEXIST)
13309                 printf("Profile has already existed.\n");
13310         else if (ret < 0)
13311                 printf("Failed to load profile.\n");
13312         else if (file_num == 2)
13313                 save_ddp_package_file(file_fld[1], buff, size);
13314
13315         close_ddp_package_file(buff);
13316         free((void *)filepath);
13317 }
13318
13319 cmdline_parse_inst_t cmd_ddp_add = {
13320         .f = cmd_ddp_add_parsed,
13321         .data = NULL,
13322         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13323         .tokens = {
13324                 (void *)&cmd_ddp_add_ddp,
13325                 (void *)&cmd_ddp_add_add,
13326                 (void *)&cmd_ddp_add_port_id,
13327                 (void *)&cmd_ddp_add_filepath,
13328                 NULL,
13329         },
13330 };
13331
13332 /* Delete dynamic device personalization*/
13333 struct cmd_ddp_del_result {
13334         cmdline_fixed_string_t ddp;
13335         cmdline_fixed_string_t del;
13336         uint8_t port_id;
13337         char filepath[];
13338 };
13339
13340 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13341         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13342 cmdline_parse_token_string_t cmd_ddp_del_del =
13343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13344 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13345         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13346 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13347         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13348
13349 static void
13350 cmd_ddp_del_parsed(
13351         void *parsed_result,
13352         __attribute__((unused)) struct cmdline *cl,
13353         __attribute__((unused)) void *data)
13354 {
13355         struct cmd_ddp_del_result *res = parsed_result;
13356         uint8_t *buff;
13357         uint32_t size;
13358         int ret = -ENOTSUP;
13359
13360         if (res->port_id > nb_ports) {
13361                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13362                 return;
13363         }
13364
13365         if (!all_ports_stopped()) {
13366                 printf("Please stop all ports first\n");
13367                 return;
13368         }
13369
13370         buff = open_ddp_package_file(res->filepath, &size);
13371         if (!buff)
13372                 return;
13373
13374 #ifdef RTE_LIBRTE_I40E_PMD
13375         if (ret == -ENOTSUP)
13376                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13377                                                buff, size,
13378                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13379 #endif
13380
13381         if (ret == -EACCES)
13382                 printf("Profile does not exist.\n");
13383         else if (ret < 0)
13384                 printf("Failed to delete profile.\n");
13385
13386         close_ddp_package_file(buff);
13387 }
13388
13389 cmdline_parse_inst_t cmd_ddp_del = {
13390         .f = cmd_ddp_del_parsed,
13391         .data = NULL,
13392         .help_str = "ddp del <port_id> <profile_path>",
13393         .tokens = {
13394                 (void *)&cmd_ddp_del_ddp,
13395                 (void *)&cmd_ddp_del_del,
13396                 (void *)&cmd_ddp_del_port_id,
13397                 (void *)&cmd_ddp_del_filepath,
13398                 NULL,
13399         },
13400 };
13401
13402 /* Get dynamic device personalization profile info */
13403 struct cmd_ddp_info_result {
13404         cmdline_fixed_string_t ddp;
13405         cmdline_fixed_string_t get;
13406         cmdline_fixed_string_t info;
13407         char filepath[];
13408 };
13409
13410 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13411         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13412 cmdline_parse_token_string_t cmd_ddp_info_get =
13413         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13414 cmdline_parse_token_string_t cmd_ddp_info_info =
13415         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13416 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13417         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13418
13419 static void
13420 cmd_ddp_info_parsed(
13421         void *parsed_result,
13422         __attribute__((unused)) struct cmdline *cl,
13423         __attribute__((unused)) void *data)
13424 {
13425         struct cmd_ddp_info_result *res = parsed_result;
13426         uint8_t *pkg;
13427         uint32_t pkg_size;
13428         int ret = -ENOTSUP;
13429 #ifdef RTE_LIBRTE_I40E_PMD
13430         uint32_t i;
13431         uint8_t *buff;
13432         uint32_t buff_size;
13433         struct rte_pmd_i40e_profile_info info;
13434         uint32_t dev_num;
13435         struct rte_pmd_i40e_ddp_device_id *devs;
13436 #endif
13437
13438         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13439         if (!pkg)
13440                 return;
13441
13442 #ifdef RTE_LIBRTE_I40E_PMD
13443         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13444                                 (uint8_t *)&info, sizeof(info),
13445                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13446         if (!ret) {
13447                 printf("Global Track id:       0x%x\n", info.track_id);
13448                 printf("Global Version:        %d.%d.%d.%d\n",
13449                         info.version.major,
13450                         info.version.minor,
13451                         info.version.update,
13452                         info.version.draft);
13453                 printf("Global Package name:   %s\n\n", info.name);
13454         }
13455
13456         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13457                                 (uint8_t *)&info, sizeof(info),
13458                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13459         if (!ret) {
13460                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13461                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13462                         info.version.major,
13463                         info.version.minor,
13464                         info.version.update,
13465                         info.version.draft);
13466                 printf("i40e Profile name:     %s\n\n", info.name);
13467         }
13468
13469         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13470                                 (uint8_t *)&buff_size, sizeof(buff_size),
13471                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13472         if (!ret && buff_size) {
13473                 buff = (uint8_t *)malloc(buff_size);
13474                 if (buff) {
13475                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13476                                                 buff, buff_size,
13477                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13478                         if (!ret)
13479                                 printf("Package Notes:\n%s\n\n", buff);
13480                         free(buff);
13481                 }
13482         }
13483
13484         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13485                                 (uint8_t *)&dev_num, sizeof(dev_num),
13486                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13487         if (!ret && dev_num) {
13488                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(dev_num *
13489                         sizeof(struct rte_pmd_i40e_ddp_device_id));
13490                 if (devs) {
13491                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13492                                                 (uint8_t *)devs, dev_num *
13493                                                 sizeof(struct rte_pmd_i40e_ddp_device_id),
13494                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13495                         if (!ret) {
13496                                 printf("List of supported devices:\n");
13497                                 for (i = 0; i < dev_num; i++) {
13498                                         printf("  %04X:%04X %04X:%04X\n",
13499                                                 devs[i].vendor_dev_id >> 16,
13500                                                 devs[i].vendor_dev_id & 0xFFFF,
13501                                                 devs[i].sub_vendor_dev_id >> 16,
13502                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13503                                 }
13504                                 printf("\n");
13505                         }
13506                         free(devs);
13507                 }
13508         }
13509         ret = 0;
13510 #endif
13511         if (ret == -ENOTSUP)
13512                 printf("Function not supported in PMD driver\n");
13513         close_ddp_package_file(pkg);
13514 }
13515
13516 cmdline_parse_inst_t cmd_ddp_get_info = {
13517         .f = cmd_ddp_info_parsed,
13518         .data = NULL,
13519         .help_str = "ddp get info <profile_path>",
13520         .tokens = {
13521                 (void *)&cmd_ddp_info_ddp,
13522                 (void *)&cmd_ddp_info_get,
13523                 (void *)&cmd_ddp_info_info,
13524                 (void *)&cmd_ddp_info_filepath,
13525                 NULL,
13526         },
13527 };
13528
13529 /* Get dynamic device personalization profile info list*/
13530 #define PROFILE_INFO_SIZE 48
13531 #define MAX_PROFILE_NUM 16
13532
13533 struct cmd_ddp_get_list_result {
13534         cmdline_fixed_string_t ddp;
13535         cmdline_fixed_string_t get;
13536         cmdline_fixed_string_t list;
13537         uint8_t port_id;
13538 };
13539
13540 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13541         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13542 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13543         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13544 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13545         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13546 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13547         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13548
13549 static void
13550 cmd_ddp_get_list_parsed(
13551         void *parsed_result,
13552         __attribute__((unused)) struct cmdline *cl,
13553         __attribute__((unused)) void *data)
13554 {
13555         struct cmd_ddp_get_list_result *res = parsed_result;
13556 #ifdef RTE_LIBRTE_I40E_PMD
13557         struct rte_pmd_i40e_profile_list *p_list;
13558         struct rte_pmd_i40e_profile_info *p_info;
13559         uint32_t p_num;
13560         uint32_t size;
13561         uint32_t i;
13562 #endif
13563         int ret = -ENOTSUP;
13564
13565         if (res->port_id > nb_ports) {
13566                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13567                 return;
13568         }
13569
13570 #ifdef RTE_LIBRTE_I40E_PMD
13571         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13572         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13573         if (!p_list)
13574                 printf("%s: Failed to malloc buffer\n", __func__);
13575
13576         if (ret == -ENOTSUP)
13577                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13578                                                 (uint8_t *)p_list, size);
13579
13580         if (!ret) {
13581                 p_num = p_list->p_count;
13582                 printf("Profile number is: %d\n\n", p_num);
13583
13584                 for (i = 0; i < p_num; i++) {
13585                         p_info = &p_list->p_info[i];
13586                         printf("Profile %d:\n", i);
13587                         printf("Track id:     0x%x\n", p_info->track_id);
13588                         printf("Version:      %d.%d.%d.%d\n",
13589                                p_info->version.major,
13590                                p_info->version.minor,
13591                                p_info->version.update,
13592                                p_info->version.draft);
13593                         printf("Profile name: %s\n\n", p_info->name);
13594                 }
13595         }
13596
13597         free(p_list);
13598 #endif
13599
13600         if (ret < 0)
13601                 printf("Failed to get ddp list\n");
13602 }
13603
13604 cmdline_parse_inst_t cmd_ddp_get_list = {
13605         .f = cmd_ddp_get_list_parsed,
13606         .data = NULL,
13607         .help_str = "ddp get list <port_id>",
13608         .tokens = {
13609                 (void *)&cmd_ddp_get_list_ddp,
13610                 (void *)&cmd_ddp_get_list_get,
13611                 (void *)&cmd_ddp_get_list_list,
13612                 (void *)&cmd_ddp_get_list_port_id,
13613                 NULL,
13614         },
13615 };
13616
13617 /* show vf stats */
13618
13619 /* Common result structure for show vf stats */
13620 struct cmd_show_vf_stats_result {
13621         cmdline_fixed_string_t show;
13622         cmdline_fixed_string_t vf;
13623         cmdline_fixed_string_t stats;
13624         uint8_t port_id;
13625         uint16_t vf_id;
13626 };
13627
13628 /* Common CLI fields show vf stats*/
13629 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13630         TOKEN_STRING_INITIALIZER
13631                 (struct cmd_show_vf_stats_result,
13632                  show, "show");
13633 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13634         TOKEN_STRING_INITIALIZER
13635                 (struct cmd_show_vf_stats_result,
13636                  vf, "vf");
13637 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13638         TOKEN_STRING_INITIALIZER
13639                 (struct cmd_show_vf_stats_result,
13640                  stats, "stats");
13641 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13642         TOKEN_NUM_INITIALIZER
13643                 (struct cmd_show_vf_stats_result,
13644                  port_id, UINT8);
13645 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13646         TOKEN_NUM_INITIALIZER
13647                 (struct cmd_show_vf_stats_result,
13648                  vf_id, UINT16);
13649
13650 static void
13651 cmd_show_vf_stats_parsed(
13652         void *parsed_result,
13653         __attribute__((unused)) struct cmdline *cl,
13654         __attribute__((unused)) void *data)
13655 {
13656         struct cmd_show_vf_stats_result *res = parsed_result;
13657         struct rte_eth_stats stats;
13658         int ret = -ENOTSUP;
13659         static const char *nic_stats_border = "########################";
13660
13661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13662                 return;
13663
13664         memset(&stats, 0, sizeof(stats));
13665
13666 #ifdef RTE_LIBRTE_I40E_PMD
13667         if (ret == -ENOTSUP)
13668                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13669                                                 res->vf_id,
13670                                                 &stats);
13671 #endif
13672 #ifdef RTE_LIBRTE_BNXT_PMD
13673         if (ret == -ENOTSUP)
13674                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
13675                                                 res->vf_id,
13676                                                 &stats);
13677 #endif
13678
13679         switch (ret) {
13680         case 0:
13681                 break;
13682         case -EINVAL:
13683                 printf("invalid vf_id %d\n", res->vf_id);
13684                 break;
13685         case -ENODEV:
13686                 printf("invalid port_id %d\n", res->port_id);
13687                 break;
13688         case -ENOTSUP:
13689                 printf("function not implemented\n");
13690                 break;
13691         default:
13692                 printf("programming error: (%s)\n", strerror(-ret));
13693         }
13694
13695         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13696                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13697
13698         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13699                "%-"PRIu64"\n",
13700                stats.ipackets, stats.imissed, stats.ibytes);
13701         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13702         printf("  RX-nombuf:  %-10"PRIu64"\n",
13703                stats.rx_nombuf);
13704         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13705                "%-"PRIu64"\n",
13706                stats.opackets, stats.oerrors, stats.obytes);
13707
13708         printf("  %s############################%s\n",
13709                                nic_stats_border, nic_stats_border);
13710 }
13711
13712 cmdline_parse_inst_t cmd_show_vf_stats = {
13713         .f = cmd_show_vf_stats_parsed,
13714         .data = NULL,
13715         .help_str = "show vf stats <port_id> <vf_id>",
13716         .tokens = {
13717                 (void *)&cmd_show_vf_stats_show,
13718                 (void *)&cmd_show_vf_stats_vf,
13719                 (void *)&cmd_show_vf_stats_stats,
13720                 (void *)&cmd_show_vf_stats_port_id,
13721                 (void *)&cmd_show_vf_stats_vf_id,
13722                 NULL,
13723         },
13724 };
13725
13726 /* clear vf stats */
13727
13728 /* Common result structure for clear vf stats */
13729 struct cmd_clear_vf_stats_result {
13730         cmdline_fixed_string_t clear;
13731         cmdline_fixed_string_t vf;
13732         cmdline_fixed_string_t stats;
13733         uint8_t port_id;
13734         uint16_t vf_id;
13735 };
13736
13737 /* Common CLI fields clear vf stats*/
13738 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13739         TOKEN_STRING_INITIALIZER
13740                 (struct cmd_clear_vf_stats_result,
13741                  clear, "clear");
13742 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13743         TOKEN_STRING_INITIALIZER
13744                 (struct cmd_clear_vf_stats_result,
13745                  vf, "vf");
13746 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13747         TOKEN_STRING_INITIALIZER
13748                 (struct cmd_clear_vf_stats_result,
13749                  stats, "stats");
13750 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13751         TOKEN_NUM_INITIALIZER
13752                 (struct cmd_clear_vf_stats_result,
13753                  port_id, UINT8);
13754 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13755         TOKEN_NUM_INITIALIZER
13756                 (struct cmd_clear_vf_stats_result,
13757                  vf_id, UINT16);
13758
13759 static void
13760 cmd_clear_vf_stats_parsed(
13761         void *parsed_result,
13762         __attribute__((unused)) struct cmdline *cl,
13763         __attribute__((unused)) void *data)
13764 {
13765         struct cmd_clear_vf_stats_result *res = parsed_result;
13766         int ret = -ENOTSUP;
13767
13768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13769                 return;
13770
13771 #ifdef RTE_LIBRTE_I40E_PMD
13772         if (ret == -ENOTSUP)
13773                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13774                                                   res->vf_id);
13775 #endif
13776 #ifdef RTE_LIBRTE_BNXT_PMD
13777         if (ret == -ENOTSUP)
13778                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
13779                                                   res->vf_id);
13780 #endif
13781
13782         switch (ret) {
13783         case 0:
13784                 break;
13785         case -EINVAL:
13786                 printf("invalid vf_id %d\n", res->vf_id);
13787                 break;
13788         case -ENODEV:
13789                 printf("invalid port_id %d\n", res->port_id);
13790                 break;
13791         case -ENOTSUP:
13792                 printf("function not implemented\n");
13793                 break;
13794         default:
13795                 printf("programming error: (%s)\n", strerror(-ret));
13796         }
13797 }
13798
13799 cmdline_parse_inst_t cmd_clear_vf_stats = {
13800         .f = cmd_clear_vf_stats_parsed,
13801         .data = NULL,
13802         .help_str = "clear vf stats <port_id> <vf_id>",
13803         .tokens = {
13804                 (void *)&cmd_clear_vf_stats_clear,
13805                 (void *)&cmd_clear_vf_stats_vf,
13806                 (void *)&cmd_clear_vf_stats_stats,
13807                 (void *)&cmd_clear_vf_stats_port_id,
13808                 (void *)&cmd_clear_vf_stats_vf_id,
13809                 NULL,
13810         },
13811 };
13812
13813 /* ptype mapping get */
13814
13815 /* Common result structure for ptype mapping get */
13816 struct cmd_ptype_mapping_get_result {
13817         cmdline_fixed_string_t ptype;
13818         cmdline_fixed_string_t mapping;
13819         cmdline_fixed_string_t get;
13820         uint8_t port_id;
13821         uint8_t valid_only;
13822 };
13823
13824 /* Common CLI fields for ptype mapping get */
13825 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
13826         TOKEN_STRING_INITIALIZER
13827                 (struct cmd_ptype_mapping_get_result,
13828                  ptype, "ptype");
13829 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_ptype_mapping_get_result,
13832                  mapping, "mapping");
13833 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
13834         TOKEN_STRING_INITIALIZER
13835                 (struct cmd_ptype_mapping_get_result,
13836                  get, "get");
13837 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
13838         TOKEN_NUM_INITIALIZER
13839                 (struct cmd_ptype_mapping_get_result,
13840                  port_id, UINT8);
13841 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_ptype_mapping_get_result,
13844                  valid_only, UINT8);
13845
13846 static void
13847 cmd_ptype_mapping_get_parsed(
13848         void *parsed_result,
13849         __attribute__((unused)) struct cmdline *cl,
13850         __attribute__((unused)) void *data)
13851 {
13852         struct cmd_ptype_mapping_get_result *res = parsed_result;
13853         int ret = -ENOTSUP;
13854 #ifdef RTE_LIBRTE_I40E_PMD
13855         int max_ptype_num = 256;
13856         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
13857         uint16_t count;
13858         int i;
13859 #endif
13860
13861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13862                 return;
13863
13864 #ifdef RTE_LIBRTE_I40E_PMD
13865         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
13866                                         mapping,
13867                                         max_ptype_num,
13868                                         &count,
13869                                         res->valid_only);
13870 #endif
13871
13872         switch (ret) {
13873         case 0:
13874                 break;
13875         case -ENODEV:
13876                 printf("invalid port_id %d\n", res->port_id);
13877                 break;
13878         case -ENOTSUP:
13879                 printf("function not implemented\n");
13880                 break;
13881         default:
13882                 printf("programming error: (%s)\n", strerror(-ret));
13883         }
13884
13885 #ifdef RTE_LIBRTE_I40E_PMD
13886         if (!ret) {
13887                 for (i = 0; i < count; i++)
13888                         printf("%3d\t0x%08x\n",
13889                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
13890         }
13891 #endif
13892 }
13893
13894 cmdline_parse_inst_t cmd_ptype_mapping_get = {
13895         .f = cmd_ptype_mapping_get_parsed,
13896         .data = NULL,
13897         .help_str = "ptype mapping get <port_id> <valid_only>",
13898         .tokens = {
13899                 (void *)&cmd_ptype_mapping_get_ptype,
13900                 (void *)&cmd_ptype_mapping_get_mapping,
13901                 (void *)&cmd_ptype_mapping_get_get,
13902                 (void *)&cmd_ptype_mapping_get_port_id,
13903                 (void *)&cmd_ptype_mapping_get_valid_only,
13904                 NULL,
13905         },
13906 };
13907
13908 /* ptype mapping replace */
13909
13910 /* Common result structure for ptype mapping replace */
13911 struct cmd_ptype_mapping_replace_result {
13912         cmdline_fixed_string_t ptype;
13913         cmdline_fixed_string_t mapping;
13914         cmdline_fixed_string_t replace;
13915         uint8_t port_id;
13916         uint32_t target;
13917         uint8_t mask;
13918         uint32_t pkt_type;
13919 };
13920
13921 /* Common CLI fields for ptype mapping replace */
13922 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
13923         TOKEN_STRING_INITIALIZER
13924                 (struct cmd_ptype_mapping_replace_result,
13925                  ptype, "ptype");
13926 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
13927         TOKEN_STRING_INITIALIZER
13928                 (struct cmd_ptype_mapping_replace_result,
13929                  mapping, "mapping");
13930 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
13931         TOKEN_STRING_INITIALIZER
13932                 (struct cmd_ptype_mapping_replace_result,
13933                  replace, "replace");
13934 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
13935         TOKEN_NUM_INITIALIZER
13936                 (struct cmd_ptype_mapping_replace_result,
13937                  port_id, UINT8);
13938 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
13939         TOKEN_NUM_INITIALIZER
13940                 (struct cmd_ptype_mapping_replace_result,
13941                  target, UINT32);
13942 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
13943         TOKEN_NUM_INITIALIZER
13944                 (struct cmd_ptype_mapping_replace_result,
13945                  mask, UINT8);
13946 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
13947         TOKEN_NUM_INITIALIZER
13948                 (struct cmd_ptype_mapping_replace_result,
13949                  pkt_type, UINT32);
13950
13951 static void
13952 cmd_ptype_mapping_replace_parsed(
13953         void *parsed_result,
13954         __attribute__((unused)) struct cmdline *cl,
13955         __attribute__((unused)) void *data)
13956 {
13957         struct cmd_ptype_mapping_replace_result *res = parsed_result;
13958         int ret = -ENOTSUP;
13959
13960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13961                 return;
13962
13963 #ifdef RTE_LIBRTE_I40E_PMD
13964         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
13965                                         res->target,
13966                                         res->mask,
13967                                         res->pkt_type);
13968 #endif
13969
13970         switch (ret) {
13971         case 0:
13972                 break;
13973         case -EINVAL:
13974                 printf("invalid ptype 0x%8x or 0x%8x\n",
13975                                 res->target, res->pkt_type);
13976                 break;
13977         case -ENODEV:
13978                 printf("invalid port_id %d\n", res->port_id);
13979                 break;
13980         case -ENOTSUP:
13981                 printf("function not implemented\n");
13982                 break;
13983         default:
13984                 printf("programming error: (%s)\n", strerror(-ret));
13985         }
13986 }
13987
13988 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
13989         .f = cmd_ptype_mapping_replace_parsed,
13990         .data = NULL,
13991         .help_str =
13992                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
13993         .tokens = {
13994                 (void *)&cmd_ptype_mapping_replace_ptype,
13995                 (void *)&cmd_ptype_mapping_replace_mapping,
13996                 (void *)&cmd_ptype_mapping_replace_replace,
13997                 (void *)&cmd_ptype_mapping_replace_port_id,
13998                 (void *)&cmd_ptype_mapping_replace_target,
13999                 (void *)&cmd_ptype_mapping_replace_mask,
14000                 (void *)&cmd_ptype_mapping_replace_pkt_type,
14001                 NULL,
14002         },
14003 };
14004
14005 /* ptype mapping reset */
14006
14007 /* Common result structure for ptype mapping reset */
14008 struct cmd_ptype_mapping_reset_result {
14009         cmdline_fixed_string_t ptype;
14010         cmdline_fixed_string_t mapping;
14011         cmdline_fixed_string_t reset;
14012         uint8_t port_id;
14013 };
14014
14015 /* Common CLI fields for ptype mapping reset*/
14016 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14017         TOKEN_STRING_INITIALIZER
14018                 (struct cmd_ptype_mapping_reset_result,
14019                  ptype, "ptype");
14020 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14021         TOKEN_STRING_INITIALIZER
14022                 (struct cmd_ptype_mapping_reset_result,
14023                  mapping, "mapping");
14024 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14025         TOKEN_STRING_INITIALIZER
14026                 (struct cmd_ptype_mapping_reset_result,
14027                  reset, "reset");
14028 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14029         TOKEN_NUM_INITIALIZER
14030                 (struct cmd_ptype_mapping_reset_result,
14031                  port_id, UINT8);
14032
14033 static void
14034 cmd_ptype_mapping_reset_parsed(
14035         void *parsed_result,
14036         __attribute__((unused)) struct cmdline *cl,
14037         __attribute__((unused)) void *data)
14038 {
14039         struct cmd_ptype_mapping_reset_result *res = parsed_result;
14040         int ret = -ENOTSUP;
14041
14042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14043                 return;
14044
14045 #ifdef RTE_LIBRTE_I40E_PMD
14046         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14047 #endif
14048
14049         switch (ret) {
14050         case 0:
14051                 break;
14052         case -ENODEV:
14053                 printf("invalid port_id %d\n", res->port_id);
14054                 break;
14055         case -ENOTSUP:
14056                 printf("function not implemented\n");
14057                 break;
14058         default:
14059                 printf("programming error: (%s)\n", strerror(-ret));
14060         }
14061 }
14062
14063 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14064         .f = cmd_ptype_mapping_reset_parsed,
14065         .data = NULL,
14066         .help_str = "ptype mapping reset <port_id>",
14067         .tokens = {
14068                 (void *)&cmd_ptype_mapping_reset_ptype,
14069                 (void *)&cmd_ptype_mapping_reset_mapping,
14070                 (void *)&cmd_ptype_mapping_reset_reset,
14071                 (void *)&cmd_ptype_mapping_reset_port_id,
14072                 NULL,
14073         },
14074 };
14075
14076 /* ptype mapping update */
14077
14078 /* Common result structure for ptype mapping update */
14079 struct cmd_ptype_mapping_update_result {
14080         cmdline_fixed_string_t ptype;
14081         cmdline_fixed_string_t mapping;
14082         cmdline_fixed_string_t reset;
14083         uint8_t port_id;
14084         uint8_t hw_ptype;
14085         uint32_t sw_ptype;
14086 };
14087
14088 /* Common CLI fields for ptype mapping update*/
14089 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14090         TOKEN_STRING_INITIALIZER
14091                 (struct cmd_ptype_mapping_update_result,
14092                  ptype, "ptype");
14093 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14094         TOKEN_STRING_INITIALIZER
14095                 (struct cmd_ptype_mapping_update_result,
14096                  mapping, "mapping");
14097 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14098         TOKEN_STRING_INITIALIZER
14099                 (struct cmd_ptype_mapping_update_result,
14100                  reset, "update");
14101 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14102         TOKEN_NUM_INITIALIZER
14103                 (struct cmd_ptype_mapping_update_result,
14104                  port_id, UINT8);
14105 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14106         TOKEN_NUM_INITIALIZER
14107                 (struct cmd_ptype_mapping_update_result,
14108                  hw_ptype, UINT8);
14109 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14110         TOKEN_NUM_INITIALIZER
14111                 (struct cmd_ptype_mapping_update_result,
14112                  sw_ptype, UINT32);
14113
14114 static void
14115 cmd_ptype_mapping_update_parsed(
14116         void *parsed_result,
14117         __attribute__((unused)) struct cmdline *cl,
14118         __attribute__((unused)) void *data)
14119 {
14120         struct cmd_ptype_mapping_update_result *res = parsed_result;
14121         int ret = -ENOTSUP;
14122 #ifdef RTE_LIBRTE_I40E_PMD
14123         struct rte_pmd_i40e_ptype_mapping mapping;
14124 #endif
14125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14126                 return;
14127
14128 #ifdef RTE_LIBRTE_I40E_PMD
14129         mapping.hw_ptype = res->hw_ptype;
14130         mapping.sw_ptype = res->sw_ptype;
14131         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14132                                                 &mapping,
14133                                                 1,
14134                                                 0);
14135 #endif
14136
14137         switch (ret) {
14138         case 0:
14139                 break;
14140         case -EINVAL:
14141                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
14142                 break;
14143         case -ENODEV:
14144                 printf("invalid port_id %d\n", res->port_id);
14145                 break;
14146         case -ENOTSUP:
14147                 printf("function not implemented\n");
14148                 break;
14149         default:
14150                 printf("programming error: (%s)\n", strerror(-ret));
14151         }
14152 }
14153
14154 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14155         .f = cmd_ptype_mapping_update_parsed,
14156         .data = NULL,
14157         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14158         .tokens = {
14159                 (void *)&cmd_ptype_mapping_update_ptype,
14160                 (void *)&cmd_ptype_mapping_update_mapping,
14161                 (void *)&cmd_ptype_mapping_update_update,
14162                 (void *)&cmd_ptype_mapping_update_port_id,
14163                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14164                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14165                 NULL,
14166         },
14167 };
14168
14169 /* Common result structure for file commands */
14170 struct cmd_cmdfile_result {
14171         cmdline_fixed_string_t load;
14172         cmdline_fixed_string_t filename;
14173 };
14174
14175 /* Common CLI fields for file commands */
14176 cmdline_parse_token_string_t cmd_load_cmdfile =
14177         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14178 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14179         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14180
14181 static void
14182 cmd_load_from_file_parsed(
14183         void *parsed_result,
14184         __attribute__((unused)) struct cmdline *cl,
14185         __attribute__((unused)) void *data)
14186 {
14187         struct cmd_cmdfile_result *res = parsed_result;
14188
14189         cmdline_read_from_file(res->filename);
14190 }
14191
14192 cmdline_parse_inst_t cmd_load_from_file = {
14193         .f = cmd_load_from_file_parsed,
14194         .data = NULL,
14195         .help_str = "load <filename>",
14196         .tokens = {
14197                 (void *)&cmd_load_cmdfile,
14198                 (void *)&cmd_load_cmdfile_filename,
14199                 NULL,
14200         },
14201 };
14202
14203 /* ******************************************************************************** */
14204
14205 /* list of instructions */
14206 cmdline_parse_ctx_t main_ctx[] = {
14207         (cmdline_parse_inst_t *)&cmd_help_brief,
14208         (cmdline_parse_inst_t *)&cmd_help_long,
14209         (cmdline_parse_inst_t *)&cmd_quit,
14210         (cmdline_parse_inst_t *)&cmd_load_from_file,
14211         (cmdline_parse_inst_t *)&cmd_showport,
14212         (cmdline_parse_inst_t *)&cmd_showqueue,
14213         (cmdline_parse_inst_t *)&cmd_showportall,
14214         (cmdline_parse_inst_t *)&cmd_showcfg,
14215         (cmdline_parse_inst_t *)&cmd_start,
14216         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14217         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14218         (cmdline_parse_inst_t *)&cmd_set_link_up,
14219         (cmdline_parse_inst_t *)&cmd_set_link_down,
14220         (cmdline_parse_inst_t *)&cmd_reset,
14221         (cmdline_parse_inst_t *)&cmd_set_numbers,
14222         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14223         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14224         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14225         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14226         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14227         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14228         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14229         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14230         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14231         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14232         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14233         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14234         (cmdline_parse_inst_t *)&cmd_set_link_check,
14235         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14236         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14237         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14238         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14239 #ifdef RTE_LIBRTE_PMD_BOND
14240         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14241         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14242         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14243         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14244         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14245         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14246         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14247         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14248         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14249         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14250         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14251 #endif
14252         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14253         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14254         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14255         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14256         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14257         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14258         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14259         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14260         (cmdline_parse_inst_t *)&cmd_csum_set,
14261         (cmdline_parse_inst_t *)&cmd_csum_show,
14262         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14263         (cmdline_parse_inst_t *)&cmd_tso_set,
14264         (cmdline_parse_inst_t *)&cmd_tso_show,
14265         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14266         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14267         (cmdline_parse_inst_t *)&cmd_enable_gro,
14268         (cmdline_parse_inst_t *)&cmd_gro_set,
14269         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14270         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14271         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14272         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14273         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14274         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14275         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14276         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14277         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14278         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14279         (cmdline_parse_inst_t *)&cmd_config_dcb,
14280         (cmdline_parse_inst_t *)&cmd_read_reg,
14281         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14282         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
14283         (cmdline_parse_inst_t *)&cmd_write_reg,
14284         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14285         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
14286         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14287         (cmdline_parse_inst_t *)&cmd_stop,
14288         (cmdline_parse_inst_t *)&cmd_mac_addr,
14289         (cmdline_parse_inst_t *)&cmd_set_qmap,
14290         (cmdline_parse_inst_t *)&cmd_operate_port,
14291         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
14292         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
14293         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
14294         (cmdline_parse_inst_t *)&cmd_config_speed_all,
14295         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
14296         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
14297         (cmdline_parse_inst_t *)&cmd_config_mtu,
14298         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14299         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14300         (cmdline_parse_inst_t *)&cmd_config_rss,
14301         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14302         (cmdline_parse_inst_t *)&cmd_config_txqflags,
14303         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
14304         (cmdline_parse_inst_t *)&cmd_showport_reta,
14305         (cmdline_parse_inst_t *)&cmd_config_burst,
14306         (cmdline_parse_inst_t *)&cmd_config_thresh,
14307         (cmdline_parse_inst_t *)&cmd_config_threshold,
14308         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14309         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14310         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14311         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14312         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14313         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
14314         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14315         (cmdline_parse_inst_t *)&cmd_global_config,
14316         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14317         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
14318         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14319         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14320         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14321         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14322         (cmdline_parse_inst_t *)&cmd_dump,
14323         (cmdline_parse_inst_t *)&cmd_dump_one,
14324         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
14325         (cmdline_parse_inst_t *)&cmd_syn_filter,
14326         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
14327         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
14328         (cmdline_parse_inst_t *)&cmd_flex_filter,
14329         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14330         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14331         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14332         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14333         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14334         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14335         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
14336         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14337         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14338         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14339         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14340         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14341         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14342         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14343         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14344         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14345         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14346         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14347         (cmdline_parse_inst_t *)&cmd_flow,
14348         (cmdline_parse_inst_t *)&cmd_mcast_addr,
14349         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14350         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14351         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14352         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14353         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14354         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14355         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14356         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14357         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14358         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14359         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14360         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14361         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14362         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
14363         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
14364         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
14365         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
14366         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
14367         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
14368         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
14369         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
14370         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
14371         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
14372         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
14373         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
14374         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
14375         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
14376         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
14377         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
14378         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
14379         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
14380         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
14381         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
14382         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
14383         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
14384         (cmdline_parse_inst_t *)&cmd_ddp_add,
14385         (cmdline_parse_inst_t *)&cmd_ddp_del,
14386         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
14387         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
14388         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
14389         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
14390         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
14391         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
14392         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
14393         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
14394         NULL,
14395 };
14396
14397 /* read cmdline commands from file */
14398 void
14399 cmdline_read_from_file(const char *filename)
14400 {
14401         struct cmdline *cl;
14402
14403         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
14404         if (cl == NULL) {
14405                 printf("Failed to create file based cmdline context: %s\n",
14406                        filename);
14407                 return;
14408         }
14409
14410         cmdline_interact(cl);
14411         cmdline_quit(cl);
14412
14413         cmdline_free(cl);
14414
14415         printf("Read CLI commands from %s\n", filename);
14416 }
14417
14418 /* prompt function, called from main on MASTER lcore */
14419 void
14420 prompt(void)
14421 {
14422         /* initialize non-constant commands */
14423         cmd_set_fwd_mode_init();
14424         cmd_set_fwd_retry_mode_init();
14425
14426         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
14427         if (testpmd_cl == NULL)
14428                 return;
14429         cmdline_interact(testpmd_cl);
14430         cmdline_stdin_exit(testpmd_cl);
14431 }
14432
14433 void
14434 prompt_exit(void)
14435 {
14436         if (testpmd_cl != NULL)
14437                 cmdline_quit(testpmd_cl);
14438 }
14439
14440 static void
14441 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
14442 {
14443         if (id == (portid_t)RTE_PORT_ALL) {
14444                 portid_t pid;
14445
14446                 RTE_ETH_FOREACH_DEV(pid) {
14447                         /* check if need_reconfig has been set to 1 */
14448                         if (ports[pid].need_reconfig == 0)
14449                                 ports[pid].need_reconfig = dev;
14450                         /* check if need_reconfig_queues has been set to 1 */
14451                         if (ports[pid].need_reconfig_queues == 0)
14452                                 ports[pid].need_reconfig_queues = queue;
14453                 }
14454         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
14455                 /* check if need_reconfig has been set to 1 */
14456                 if (ports[id].need_reconfig == 0)
14457                         ports[id].need_reconfig = dev;
14458                 /* check if need_reconfig_queues has been set to 1 */
14459                 if (ports[id].need_reconfig_queues == 0)
14460                         ports[id].need_reconfig_queues = queue;
14461         }
14462 }