app/testpmd: add traffic management forwarding mode
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102
103 static struct cmdline *testpmd_cl;
104
105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
106
107 /* *** Help command with introduction. *** */
108 struct cmd_help_brief_result {
109         cmdline_fixed_string_t help;
110 };
111
112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
113                                   struct cmdline *cl,
114                                   __attribute__((unused)) void *data)
115 {
116         cmdline_printf(
117                 cl,
118                 "\n"
119                 "Help is available for the following sections:\n\n"
120                 "    help control    : Start and stop forwarding.\n"
121                 "    help display    : Displaying port, stats and config "
122                 "information.\n"
123                 "    help config     : Configuration information.\n"
124                 "    help ports      : Configuring ports.\n"
125                 "    help registers  : Reading and setting port registers.\n"
126                 "    help filters    : Filters configuration help.\n"
127                 "    help all        : All of the above sections.\n\n"
128         );
129
130 }
131
132 cmdline_parse_token_string_t cmd_help_brief_help =
133         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
134
135 cmdline_parse_inst_t cmd_help_brief = {
136         .f = cmd_help_brief_parsed,
137         .data = NULL,
138         .help_str = "help: Show help",
139         .tokens = {
140                 (void *)&cmd_help_brief_help,
141                 NULL,
142         },
143 };
144
145 /* *** Help command with help sections. *** */
146 struct cmd_help_long_result {
147         cmdline_fixed_string_t help;
148         cmdline_fixed_string_t section;
149 };
150
151 static void cmd_help_long_parsed(void *parsed_result,
152                                  struct cmdline *cl,
153                                  __attribute__((unused)) void *data)
154 {
155         int show_all = 0;
156         struct cmd_help_long_result *res = parsed_result;
157
158         if (!strcmp(res->section, "all"))
159                 show_all = 1;
160
161         if (show_all || !strcmp(res->section, "control")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Control forwarding:\n"
167                         "-------------------\n\n"
168
169                         "start\n"
170                         "    Start packet forwarding with current configuration.\n\n"
171
172                         "start tx_first\n"
173                         "    Start packet forwarding with current config"
174                         " after sending one burst of packets.\n\n"
175
176                         "stop\n"
177                         "    Stop packet forwarding, and display accumulated"
178                         " statistics.\n\n"
179
180                         "quit\n"
181                         "    Quit to prompt.\n\n"
182                 );
183         }
184
185         if (show_all || !strcmp(res->section, "display")) {
186
187                 cmdline_printf(
188                         cl,
189                         "\n"
190                         "Display:\n"
191                         "--------\n\n"
192
193                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
194                         "    Display information for port_id, or all.\n\n"
195
196                         "show port X rss reta (size) (mask0,mask1,...)\n"
197                         "    Display the rss redirection table entry indicated"
198                         " by masks on port X. size is used to indicate the"
199                         " hardware supported reta size\n\n"
200
201                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
202                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
203                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
204                         "    Display the RSS hash functions and RSS hash key"
205                         " of port X\n\n"
206
207                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
208                         "    Clear information for port_id, or all.\n\n"
209
210                         "show (rxq|txq) info (port_id) (queue_id)\n"
211                         "    Display information for configured RX/TX queue.\n\n"
212
213                         "show config (rxtx|cores|fwd|txpkts)\n"
214                         "    Display the given configuration.\n\n"
215
216                         "read rxd (port_id) (queue_id) (rxd_id)\n"
217                         "    Display an RX descriptor of a port RX queue.\n\n"
218
219                         "read txd (port_id) (queue_id) (txd_id)\n"
220                         "    Display a TX descriptor of a port TX queue.\n\n"
221
222                         "ddp get list (port_id)\n"
223                         "    Get ddp profile info list\n\n"
224
225                         "ddp get info (profile_path)\n"
226                         "    Get ddp profile information.\n\n"
227
228                         "show vf stats (port_id) (vf_id)\n"
229                         "    Display a VF's statistics.\n\n"
230
231                         "clear vf stats (port_id) (vf_id)\n"
232                         "    Reset a VF's statistics.\n\n"
233
234                         "show port (port_id) pctype mapping\n"
235                         "    Get flow ptype to pctype mapping on a port\n\n"
236
237                 );
238         }
239
240         if (show_all || !strcmp(res->section, "config")) {
241                 cmdline_printf(
242                         cl,
243                         "\n"
244                         "Configuration:\n"
245                         "--------------\n"
246                         "Configuration changes only become active when"
247                         " forwarding is started/restarted.\n\n"
248
249                         "set default\n"
250                         "    Reset forwarding to the default configuration.\n\n"
251
252                         "set verbose (level)\n"
253                         "    Set the debug verbosity level X.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set port (port_id) gso (on|off)"
442                         "    Enable or disable Generic Segmentation Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "set gso segsz (length)\n"
446                         "    Set max packet length for output GSO segments,"
447                         " including packet header and payload.\n\n"
448
449                         "show port (port_id) gso\n"
450                         "    Show GSO configuration.\n\n"
451
452                         "set fwd (%s)\n"
453                         "    Set packet forwarding mode.\n\n"
454
455                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Add a MAC address on port_id.\n\n"
457
458                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Remove a MAC address from port_id.\n\n"
460
461                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Set the default MAC address for port_id.\n\n"
463
464                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465                         "    Add a MAC address for a VF on the port.\n\n"
466
467                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the MAC address for a VF from the PF.\n\n"
469
470                         "set port (port_id) uta (mac_address|all) (on|off)\n"
471                         "    Add/Remove a or all unicast hash filter(s)"
472                         "from port X.\n\n"
473
474                         "set promisc (port_id|all) (on|off)\n"
475                         "    Set the promiscuous mode on port_id, or all.\n\n"
476
477                         "set allmulti (port_id|all) (on|off)\n"
478                         "    Set the allmulti mode on port_id, or all.\n\n"
479
480                         "set vf promisc (port_id) (vf_id) (on|off)\n"
481                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
482
483                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
484                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488                         " (on|off) autoneg (on|off) (port_id)\n"
489                         "set flow_ctrl rx (on|off) (portid)\n"
490                         "set flow_ctrl tx (on|off) (portid)\n"
491                         "set flow_ctrl high_water (high_water) (portid)\n"
492                         "set flow_ctrl low_water (low_water) (portid)\n"
493                         "set flow_ctrl pause_time (pause_time) (portid)\n"
494                         "set flow_ctrl send_xon (send_xon) (portid)\n"
495                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496                         "set flow_ctrl autoneg (on|off) (port_id)\n"
497                         "    Set the link flow control parameter on a port.\n\n"
498
499                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500                         " (low_water) (pause_time) (priority) (port_id)\n"
501                         "    Set the priority flow control parameter on a"
502                         " port.\n\n"
503
504                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
506                         " queue on port.\n"
507                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508                         " on port 0 to mapping 5.\n\n"
509
510                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
511                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
512
513                         "set port (port_id) vf (vf_id) (mac_addr)"
514                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
515                         "   Add/Remove unicast or multicast MAC addr filter"
516                         " for a VF.\n\n"
517
518                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
519                         "|MPE) (on|off)\n"
520                         "    AUPE:accepts untagged VLAN;"
521                         "ROPE:accept unicast hash\n\n"
522                         "    BAM:accepts broadcast packets;"
523                         "MPE:accepts all multicast packets\n\n"
524                         "    Enable/Disable a VF receive mode of a port\n\n"
525
526                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
527                         "    Set rate limit for a queue of a port\n\n"
528
529                         "set port (port_id) vf (vf_id) rate (rate_num) "
530                         "queue_mask (queue_mask_value)\n"
531                         "    Set rate limit for queues in VF of a port\n\n"
532
533                         "set port (port_id) mirror-rule (rule_id)"
534                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
535                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
536                         "   Set pool or vlan type mirror rule on a port.\n"
537                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
538                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
539                         " to pool 0.\n\n"
540
541                         "set port (port_id) mirror-rule (rule_id)"
542                         " (uplink-mirror|downlink-mirror) dst-pool"
543                         " (pool_id) (on|off)\n"
544                         "   Set uplink or downlink type mirror rule on a port.\n"
545                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
546                         " 0 on' enable mirror income traffic to pool 0.\n\n"
547
548                         "reset port (port_id) mirror-rule (rule_id)\n"
549                         "   Reset a mirror rule.\n\n"
550
551                         "set flush_rx (on|off)\n"
552                         "   Flush (default) or don't flush RX streams before"
553                         " forwarding. Mainly used with PCAP drivers.\n\n"
554
555                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
556                         "   Set the bypass mode for the lowest port on bypass enabled"
557                         " NIC.\n\n"
558
559                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
560                         "mode (normal|bypass|isolate) (port_id)\n"
561                         "   Set the event required to initiate specified bypass mode for"
562                         " the lowest port on a bypass enabled NIC where:\n"
563                         "       timeout   = enable bypass after watchdog timeout.\n"
564                         "       os_on     = enable bypass when OS/board is powered on.\n"
565                         "       os_off    = enable bypass when OS/board is powered off.\n"
566                         "       power_on  = enable bypass when power supply is turned on.\n"
567                         "       power_off = enable bypass when power supply is turned off."
568                         "\n\n"
569
570                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
571                         "   Set the bypass watchdog timeout to 'n' seconds"
572                         " where 0 = instant.\n\n"
573
574                         "show bypass config (port_id)\n"
575                         "   Show the bypass configuration for a bypass enabled NIC"
576                         " using the lowest port on the NIC.\n\n"
577
578 #ifdef RTE_LIBRTE_PMD_BOND
579                         "create bonded device (mode) (socket)\n"
580                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
581
582                         "add bonding slave (slave_id) (port_id)\n"
583                         "       Add a slave device to a bonded device.\n\n"
584
585                         "remove bonding slave (slave_id) (port_id)\n"
586                         "       Remove a slave device from a bonded device.\n\n"
587
588                         "set bonding mode (value) (port_id)\n"
589                         "       Set the bonding mode on a bonded device.\n\n"
590
591                         "set bonding primary (slave_id) (port_id)\n"
592                         "       Set the primary slave for a bonded device.\n\n"
593
594                         "show bonding config (port_id)\n"
595                         "       Show the bonding config for port_id.\n\n"
596
597                         "set bonding mac_addr (port_id) (address)\n"
598                         "       Set the MAC address of a bonded device.\n\n"
599
600                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
601                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
602
603                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
604                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
605
606                         "set bonding mon_period (port_id) (value)\n"
607                         "       Set the bonding link status monitoring polling period in ms.\n\n"
608
609                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
610                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
611
612 #endif
613                         "set link-up port (port_id)\n"
614                         "       Set link up for a port.\n\n"
615
616                         "set link-down port (port_id)\n"
617                         "       Set link down for a port.\n\n"
618
619                         "E-tag set insertion on port-tag-id (value)"
620                         " port (port_id) vf (vf_id)\n"
621                         "    Enable E-tag insertion for a VF on a port\n\n"
622
623                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
624                         "    Disable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set stripping (on|off) port (port_id)\n"
627                         "    Enable/disable E-tag stripping on a port\n\n"
628
629                         "E-tag set forwarding (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag based forwarding"
631                         " on a port\n\n"
632
633                         "E-tag set filter add e-tag-id (value) dst-pool"
634                         " (pool_id) port (port_id)\n"
635                         "    Add an E-tag forwarding filter on a port\n\n"
636
637                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
638                         "    Delete an E-tag forwarding filter on a port\n\n"
639
640 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
641                         "set port tm hierarchy default (port_id)\n"
642                         "       Set default traffic Management hierarchy on a port\n\n"
643
644 #endif
645                         "ddp add (port_id) (profile_path[,output_path])\n"
646                         "    Load a profile package on a port\n\n"
647
648                         "ddp del (port_id) (profile_path)\n"
649                         "    Delete a profile package from a port\n\n"
650
651                         "ptype mapping get (port_id) (valid_only)\n"
652                         "    Get ptype mapping on a port\n\n"
653
654                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
655                         "    Replace target with the pkt_type in ptype mapping\n\n"
656
657                         "ptype mapping reset (port_id)\n"
658                         "    Reset ptype mapping on a port\n\n"
659
660                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
661                         "    Update a ptype mapping item on a port\n\n"
662
663                         , list_pkt_forwarding_modes()
664                 );
665         }
666
667         if (show_all || !strcmp(res->section, "ports")) {
668
669                 cmdline_printf(
670                         cl,
671                         "\n"
672                         "Port Operations:\n"
673                         "----------------\n\n"
674
675                         "port start (port_id|all)\n"
676                         "    Start all ports or port_id.\n\n"
677
678                         "port stop (port_id|all)\n"
679                         "    Stop all ports or port_id.\n\n"
680
681                         "port close (port_id|all)\n"
682                         "    Close all ports or port_id.\n\n"
683
684                         "port attach (ident)\n"
685                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
686
687                         "port detach (port_id)\n"
688                         "    Detach physical or virtual dev by port_id\n\n"
689
690                         "port config (port_id|all)"
691                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
692                         " duplex (half|full|auto)\n"
693                         "    Set speed and duplex for all ports or port_id\n\n"
694
695                         "port config all (rxq|txq|rxd|txd) (value)\n"
696                         "    Set number for rxq/txq/rxd/txd.\n\n"
697
698                         "port config all max-pkt-len (value)\n"
699                         "    Set the max packet length.\n\n"
700
701                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
702                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
703                         " (on|off)\n"
704                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
705                         " for ports.\n\n"
706
707                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
708                         "geneve|nvgre|none|<flowtype_id>)\n"
709                         "    Set the RSS mode.\n\n"
710
711                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
712                         "    Set the RSS redirection table.\n\n"
713
714                         "port config (port_id) dcb vt (on|off) (traffic_class)"
715                         " pfc (on|off)\n"
716                         "    Set the DCB mode.\n\n"
717
718                         "port config all burst (value)\n"
719                         "    Set the number of packets per burst.\n\n"
720
721                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
722                         " (value)\n"
723                         "    Set the ring prefetch/host/writeback threshold"
724                         " for tx/rx queue.\n\n"
725
726                         "port config all (txfreet|txrst|rxfreet) (value)\n"
727                         "    Set free threshold for rx/tx, or set"
728                         " tx rs bit threshold.\n\n"
729                         "port config mtu X value\n"
730                         "    Set the MTU of port X to a given value\n\n"
731
732                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
733                         "    Start/stop a rx/tx queue of port X. Only take effect"
734                         " when port X is started\n\n"
735
736                         "port config (port_id|all) l2-tunnel E-tag ether-type"
737                         " (value)\n"
738                         "    Set the value of E-tag ether-type.\n\n"
739
740                         "port config (port_id|all) l2-tunnel E-tag"
741                         " (enable|disable)\n"
742                         "    Enable/disable the E-tag support.\n\n"
743
744                         "port config (port_id) pctype mapping reset\n"
745                         "    Reset flow type to pctype mapping on a port\n\n"
746
747                         "port config (port_id) pctype mapping update"
748                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
749                         "    Update a flow type to pctype mapping item on a port\n\n"
750                 );
751         }
752
753         if (show_all || !strcmp(res->section, "registers")) {
754
755                 cmdline_printf(
756                         cl,
757                         "\n"
758                         "Registers:\n"
759                         "----------\n\n"
760
761                         "read reg (port_id) (address)\n"
762                         "    Display value of a port register.\n\n"
763
764                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
765                         "    Display a port register bit field.\n\n"
766
767                         "read regbit (port_id) (address) (bit_x)\n"
768                         "    Display a single port register bit.\n\n"
769
770                         "write reg (port_id) (address) (value)\n"
771                         "    Set value of a port register.\n\n"
772
773                         "write regfield (port_id) (address) (bit_x) (bit_y)"
774                         " (value)\n"
775                         "    Set bit field of a port register.\n\n"
776
777                         "write regbit (port_id) (address) (bit_x) (value)\n"
778                         "    Set single bit value of a port register.\n\n"
779                 );
780         }
781         if (show_all || !strcmp(res->section, "filters")) {
782
783                 cmdline_printf(
784                         cl,
785                         "\n"
786                         "filters:\n"
787                         "--------\n\n"
788
789                         "ethertype_filter (port_id) (add|del)"
790                         " (mac_addr|mac_ignr) (mac_address) ethertype"
791                         " (ether_type) (drop|fwd) queue (queue_id)\n"
792                         "    Add/Del an ethertype filter.\n\n"
793
794                         "2tuple_filter (port_id) (add|del)"
795                         " dst_port (dst_port_value) protocol (protocol_value)"
796                         " mask (mask_value) tcp_flags (tcp_flags_value)"
797                         " priority (prio_value) queue (queue_id)\n"
798                         "    Add/Del a 2tuple filter.\n\n"
799
800                         "5tuple_filter (port_id) (add|del)"
801                         " dst_ip (dst_address) src_ip (src_address)"
802                         " dst_port (dst_port_value) src_port (src_port_value)"
803                         " protocol (protocol_value)"
804                         " mask (mask_value) tcp_flags (tcp_flags_value)"
805                         " priority (prio_value) queue (queue_id)\n"
806                         "    Add/Del a 5tuple filter.\n\n"
807
808                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
809                         "    Add/Del syn filter.\n\n"
810
811                         "flex_filter (port_id) (add|del) len (len_value)"
812                         " bytes (bytes_value) mask (mask_value)"
813                         " priority (prio_value) queue (queue_id)\n"
814                         "    Add/Del a flex filter.\n\n"
815
816                         "flow_director_filter (port_id) mode IP (add|del|update)"
817                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
818                         " src (src_ip_address) dst (dst_ip_address)"
819                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
820                         " vlan (vlan_value) flexbytes (flexbytes_value)"
821                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
822                         " fd_id (fd_id_value)\n"
823                         "    Add/Del an IP type flow director filter.\n\n"
824
825                         "flow_director_filter (port_id) mode IP (add|del|update)"
826                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
827                         " src (src_ip_address) (src_port)"
828                         " dst (dst_ip_address) (dst_port)"
829                         " tos (tos_value) ttl (ttl_value)"
830                         " vlan (vlan_value) flexbytes (flexbytes_value)"
831                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
832                         " fd_id (fd_id_value)\n"
833                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
834
835                         "flow_director_filter (port_id) mode IP (add|del|update)"
836                         " flow (ipv4-sctp|ipv6-sctp)"
837                         " src (src_ip_address) (src_port)"
838                         " dst (dst_ip_address) (dst_port)"
839                         " tag (verification_tag) "
840                         " tos (tos_value) ttl (ttl_value)"
841                         " vlan (vlan_value)"
842                         " flexbytes (flexbytes_value) (drop|fwd)"
843                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
844                         "    Add/Del a SCTP type flow director filter.\n\n"
845
846                         "flow_director_filter (port_id) mode IP (add|del|update)"
847                         " flow l2_payload ether (ethertype)"
848                         " flexbytes (flexbytes_value) (drop|fwd)"
849                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
850                         "    Add/Del a l2 payload type flow director filter.\n\n"
851
852                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
853                         " mac (mac_address) vlan (vlan_value)"
854                         " flexbytes (flexbytes_value) (drop|fwd)"
855                         " queue (queue_id) fd_id (fd_id_value)\n"
856                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
857
858                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
859                         " mac (mac_address) vlan (vlan_value)"
860                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
861                         " flexbytes (flexbytes_value) (drop|fwd)"
862                         " queue (queue_id) fd_id (fd_id_value)\n"
863                         "    Add/Del a Tunnel flow director filter.\n\n"
864
865                         "flush_flow_director (port_id)\n"
866                         "    Flush all flow director entries of a device.\n\n"
867
868                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
869                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
870                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
871                         "    Set flow director IP mask.\n\n"
872
873                         "flow_director_mask (port_id) mode MAC-VLAN"
874                         " vlan (vlan_value)\n"
875                         "    Set flow director MAC-VLAN mask.\n\n"
876
877                         "flow_director_mask (port_id) mode Tunnel"
878                         " vlan (vlan_value) mac (mac_value)"
879                         " tunnel-type (tunnel_type_value)"
880                         " tunnel-id (tunnel_id_value)\n"
881                         "    Set flow director Tunnel mask.\n\n"
882
883                         "flow_director_flex_mask (port_id)"
884                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
885                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
886                         " (mask)\n"
887                         "    Configure mask of flex payload.\n\n"
888
889                         "flow_director_flex_payload (port_id)"
890                         " (raw|l2|l3|l4) (config)\n"
891                         "    Configure flex payload selection.\n\n"
892
893                         "get_sym_hash_ena_per_port (port_id)\n"
894                         "    get symmetric hash enable configuration per port.\n\n"
895
896                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
897                         "    set symmetric hash enable configuration per port"
898                         " to enable or disable.\n\n"
899
900                         "get_hash_global_config (port_id)\n"
901                         "    Get the global configurations of hash filters.\n\n"
902
903                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
904                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
905                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
906                         " (enable|disable)\n"
907                         "    Set the global configurations of hash filters.\n\n"
908
909                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
910                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
911                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
912                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
913                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
914                         "ipv6-next-header|udp-src-port|udp-dst-port|"
915                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
916                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
917                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
918                         "fld-8th|none) (select|add)\n"
919                         "    Set the input set for hash.\n\n"
920
921                         "set_fdir_input_set (port_id) "
922                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
923                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
924                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
925                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
926                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
927                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
928                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
929                         " (select|add)\n"
930                         "    Set the input set for FDir.\n\n"
931
932                         "flow validate {port_id}"
933                         " [group {group_id}] [priority {level}]"
934                         " [ingress] [egress]"
935                         " pattern {item} [/ {item} [...]] / end"
936                         " actions {action} [/ {action} [...]] / end\n"
937                         "    Check whether a flow rule can be created.\n\n"
938
939                         "flow create {port_id}"
940                         " [group {group_id}] [priority {level}]"
941                         " [ingress] [egress]"
942                         " pattern {item} [/ {item} [...]] / end"
943                         " actions {action} [/ {action} [...]] / end\n"
944                         "    Create a flow rule.\n\n"
945
946                         "flow destroy {port_id} rule {rule_id} [...]\n"
947                         "    Destroy specific flow rules.\n\n"
948
949                         "flow flush {port_id}\n"
950                         "    Destroy all flow rules.\n\n"
951
952                         "flow query {port_id} {rule_id} {action}\n"
953                         "    Query an existing flow rule.\n\n"
954
955                         "flow list {port_id} [group {group_id}] [...]\n"
956                         "    List existing flow rules sorted by priority,"
957                         " filtered by group identifiers.\n\n"
958
959                         "flow isolate {port_id} {boolean}\n"
960                         "    Restrict ingress traffic to the defined"
961                         " flow rules\n\n"
962                 );
963         }
964 }
965
966 cmdline_parse_token_string_t cmd_help_long_help =
967         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
968
969 cmdline_parse_token_string_t cmd_help_long_section =
970         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
971                         "all#control#display#config#"
972                         "ports#registers#filters");
973
974 cmdline_parse_inst_t cmd_help_long = {
975         .f = cmd_help_long_parsed,
976         .data = NULL,
977         .help_str = "help all|control|display|config|ports|register|filters: "
978                 "Show help",
979         .tokens = {
980                 (void *)&cmd_help_long_help,
981                 (void *)&cmd_help_long_section,
982                 NULL,
983         },
984 };
985
986
987 /* *** start/stop/close all ports *** */
988 struct cmd_operate_port_result {
989         cmdline_fixed_string_t keyword;
990         cmdline_fixed_string_t name;
991         cmdline_fixed_string_t value;
992 };
993
994 static void cmd_operate_port_parsed(void *parsed_result,
995                                 __attribute__((unused)) struct cmdline *cl,
996                                 __attribute__((unused)) void *data)
997 {
998         struct cmd_operate_port_result *res = parsed_result;
999
1000         if (!strcmp(res->name, "start"))
1001                 start_port(RTE_PORT_ALL);
1002         else if (!strcmp(res->name, "stop"))
1003                 stop_port(RTE_PORT_ALL);
1004         else if (!strcmp(res->name, "close"))
1005                 close_port(RTE_PORT_ALL);
1006         else if (!strcmp(res->name, "reset"))
1007                 reset_port(RTE_PORT_ALL);
1008         else
1009                 printf("Unknown parameter\n");
1010 }
1011
1012 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1013         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1014                                                                 "port");
1015 cmdline_parse_token_string_t cmd_operate_port_all_port =
1016         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1017                                                 "start#stop#close#reset");
1018 cmdline_parse_token_string_t cmd_operate_port_all_all =
1019         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1020
1021 cmdline_parse_inst_t cmd_operate_port = {
1022         .f = cmd_operate_port_parsed,
1023         .data = NULL,
1024         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1025         .tokens = {
1026                 (void *)&cmd_operate_port_all_cmd,
1027                 (void *)&cmd_operate_port_all_port,
1028                 (void *)&cmd_operate_port_all_all,
1029                 NULL,
1030         },
1031 };
1032
1033 /* *** start/stop/close specific port *** */
1034 struct cmd_operate_specific_port_result {
1035         cmdline_fixed_string_t keyword;
1036         cmdline_fixed_string_t name;
1037         uint8_t value;
1038 };
1039
1040 static void cmd_operate_specific_port_parsed(void *parsed_result,
1041                         __attribute__((unused)) struct cmdline *cl,
1042                                 __attribute__((unused)) void *data)
1043 {
1044         struct cmd_operate_specific_port_result *res = parsed_result;
1045
1046         if (!strcmp(res->name, "start"))
1047                 start_port(res->value);
1048         else if (!strcmp(res->name, "stop"))
1049                 stop_port(res->value);
1050         else if (!strcmp(res->name, "close"))
1051                 close_port(res->value);
1052         else if (!strcmp(res->name, "reset"))
1053                 reset_port(res->value);
1054         else
1055                 printf("Unknown parameter\n");
1056 }
1057
1058 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1059         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1060                                                         keyword, "port");
1061 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1062         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1063                                                 name, "start#stop#close#reset");
1064 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1065         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1066                                                         value, UINT8);
1067
1068 cmdline_parse_inst_t cmd_operate_specific_port = {
1069         .f = cmd_operate_specific_port_parsed,
1070         .data = NULL,
1071         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1072         .tokens = {
1073                 (void *)&cmd_operate_specific_port_cmd,
1074                 (void *)&cmd_operate_specific_port_port,
1075                 (void *)&cmd_operate_specific_port_id,
1076                 NULL,
1077         },
1078 };
1079
1080 /* *** attach a specified port *** */
1081 struct cmd_operate_attach_port_result {
1082         cmdline_fixed_string_t port;
1083         cmdline_fixed_string_t keyword;
1084         cmdline_fixed_string_t identifier;
1085 };
1086
1087 static void cmd_operate_attach_port_parsed(void *parsed_result,
1088                                 __attribute__((unused)) struct cmdline *cl,
1089                                 __attribute__((unused)) void *data)
1090 {
1091         struct cmd_operate_attach_port_result *res = parsed_result;
1092
1093         if (!strcmp(res->keyword, "attach"))
1094                 attach_port(res->identifier);
1095         else
1096                 printf("Unknown parameter\n");
1097 }
1098
1099 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1100         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1101                         port, "port");
1102 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1103         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1104                         keyword, "attach");
1105 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1106         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1107                         identifier, NULL);
1108
1109 cmdline_parse_inst_t cmd_operate_attach_port = {
1110         .f = cmd_operate_attach_port_parsed,
1111         .data = NULL,
1112         .help_str = "port attach <identifier>: "
1113                 "(identifier: pci address or virtual dev name)",
1114         .tokens = {
1115                 (void *)&cmd_operate_attach_port_port,
1116                 (void *)&cmd_operate_attach_port_keyword,
1117                 (void *)&cmd_operate_attach_port_identifier,
1118                 NULL,
1119         },
1120 };
1121
1122 /* *** detach a specified port *** */
1123 struct cmd_operate_detach_port_result {
1124         cmdline_fixed_string_t port;
1125         cmdline_fixed_string_t keyword;
1126         uint8_t port_id;
1127 };
1128
1129 static void cmd_operate_detach_port_parsed(void *parsed_result,
1130                                 __attribute__((unused)) struct cmdline *cl,
1131                                 __attribute__((unused)) void *data)
1132 {
1133         struct cmd_operate_detach_port_result *res = parsed_result;
1134
1135         if (!strcmp(res->keyword, "detach"))
1136                 detach_port(res->port_id);
1137         else
1138                 printf("Unknown parameter\n");
1139 }
1140
1141 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1142         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1143                         port, "port");
1144 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1145         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1146                         keyword, "detach");
1147 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1148         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1149                         port_id, UINT8);
1150
1151 cmdline_parse_inst_t cmd_operate_detach_port = {
1152         .f = cmd_operate_detach_port_parsed,
1153         .data = NULL,
1154         .help_str = "port detach <port_id>",
1155         .tokens = {
1156                 (void *)&cmd_operate_detach_port_port,
1157                 (void *)&cmd_operate_detach_port_keyword,
1158                 (void *)&cmd_operate_detach_port_port_id,
1159                 NULL,
1160         },
1161 };
1162
1163 /* *** configure speed for all ports *** */
1164 struct cmd_config_speed_all {
1165         cmdline_fixed_string_t port;
1166         cmdline_fixed_string_t keyword;
1167         cmdline_fixed_string_t all;
1168         cmdline_fixed_string_t item1;
1169         cmdline_fixed_string_t item2;
1170         cmdline_fixed_string_t value1;
1171         cmdline_fixed_string_t value2;
1172 };
1173
1174 static int
1175 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1176 {
1177
1178         int duplex;
1179
1180         if (!strcmp(duplexstr, "half")) {
1181                 duplex = ETH_LINK_HALF_DUPLEX;
1182         } else if (!strcmp(duplexstr, "full")) {
1183                 duplex = ETH_LINK_FULL_DUPLEX;
1184         } else if (!strcmp(duplexstr, "auto")) {
1185                 duplex = ETH_LINK_FULL_DUPLEX;
1186         } else {
1187                 printf("Unknown duplex parameter\n");
1188                 return -1;
1189         }
1190
1191         if (!strcmp(speedstr, "10")) {
1192                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1193                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1194         } else if (!strcmp(speedstr, "100")) {
1195                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1196                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1197         } else {
1198                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1199                         printf("Invalid speed/duplex parameters\n");
1200                         return -1;
1201                 }
1202                 if (!strcmp(speedstr, "1000")) {
1203                         *speed = ETH_LINK_SPEED_1G;
1204                 } else if (!strcmp(speedstr, "10000")) {
1205                         *speed = ETH_LINK_SPEED_10G;
1206                 } else if (!strcmp(speedstr, "25000")) {
1207                         *speed = ETH_LINK_SPEED_25G;
1208                 } else if (!strcmp(speedstr, "40000")) {
1209                         *speed = ETH_LINK_SPEED_40G;
1210                 } else if (!strcmp(speedstr, "50000")) {
1211                         *speed = ETH_LINK_SPEED_50G;
1212                 } else if (!strcmp(speedstr, "100000")) {
1213                         *speed = ETH_LINK_SPEED_100G;
1214                 } else if (!strcmp(speedstr, "auto")) {
1215                         *speed = ETH_LINK_SPEED_AUTONEG;
1216                 } else {
1217                         printf("Unknown speed parameter\n");
1218                         return -1;
1219                 }
1220         }
1221
1222         return 0;
1223 }
1224
1225 static void
1226 cmd_config_speed_all_parsed(void *parsed_result,
1227                         __attribute__((unused)) struct cmdline *cl,
1228                         __attribute__((unused)) void *data)
1229 {
1230         struct cmd_config_speed_all *res = parsed_result;
1231         uint32_t link_speed;
1232         portid_t pid;
1233
1234         if (!all_ports_stopped()) {
1235                 printf("Please stop all ports first\n");
1236                 return;
1237         }
1238
1239         if (parse_and_check_speed_duplex(res->value1, res->value2,
1240                         &link_speed) < 0)
1241                 return;
1242
1243         RTE_ETH_FOREACH_DEV(pid) {
1244                 ports[pid].dev_conf.link_speeds = link_speed;
1245         }
1246
1247         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1248 }
1249
1250 cmdline_parse_token_string_t cmd_config_speed_all_port =
1251         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1252 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1253         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1254                                                         "config");
1255 cmdline_parse_token_string_t cmd_config_speed_all_all =
1256         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1257 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1258         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1259 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1260         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1261                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1262 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1263         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1264 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1265         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1266                                                 "half#full#auto");
1267
1268 cmdline_parse_inst_t cmd_config_speed_all = {
1269         .f = cmd_config_speed_all_parsed,
1270         .data = NULL,
1271         .help_str = "port config all speed "
1272                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1273                                                         "half|full|auto",
1274         .tokens = {
1275                 (void *)&cmd_config_speed_all_port,
1276                 (void *)&cmd_config_speed_all_keyword,
1277                 (void *)&cmd_config_speed_all_all,
1278                 (void *)&cmd_config_speed_all_item1,
1279                 (void *)&cmd_config_speed_all_value1,
1280                 (void *)&cmd_config_speed_all_item2,
1281                 (void *)&cmd_config_speed_all_value2,
1282                 NULL,
1283         },
1284 };
1285
1286 /* *** configure speed for specific port *** */
1287 struct cmd_config_speed_specific {
1288         cmdline_fixed_string_t port;
1289         cmdline_fixed_string_t keyword;
1290         uint8_t id;
1291         cmdline_fixed_string_t item1;
1292         cmdline_fixed_string_t item2;
1293         cmdline_fixed_string_t value1;
1294         cmdline_fixed_string_t value2;
1295 };
1296
1297 static void
1298 cmd_config_speed_specific_parsed(void *parsed_result,
1299                                 __attribute__((unused)) struct cmdline *cl,
1300                                 __attribute__((unused)) void *data)
1301 {
1302         struct cmd_config_speed_specific *res = parsed_result;
1303         uint32_t link_speed;
1304
1305         if (!all_ports_stopped()) {
1306                 printf("Please stop all ports first\n");
1307                 return;
1308         }
1309
1310         if (port_id_is_invalid(res->id, ENABLED_WARN))
1311                 return;
1312
1313         if (parse_and_check_speed_duplex(res->value1, res->value2,
1314                         &link_speed) < 0)
1315                 return;
1316
1317         ports[res->id].dev_conf.link_speeds = link_speed;
1318
1319         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1320 }
1321
1322
1323 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1324         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1325                                                                 "port");
1326 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1327         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1328                                                                 "config");
1329 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1330         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1331 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1332         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1333                                                                 "speed");
1334 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1335         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1336                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1337 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1338         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1339                                                                 "duplex");
1340 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1341         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1342                                                         "half#full#auto");
1343
1344 cmdline_parse_inst_t cmd_config_speed_specific = {
1345         .f = cmd_config_speed_specific_parsed,
1346         .data = NULL,
1347         .help_str = "port config <port_id> speed "
1348                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1349                                                         "half|full|auto",
1350         .tokens = {
1351                 (void *)&cmd_config_speed_specific_port,
1352                 (void *)&cmd_config_speed_specific_keyword,
1353                 (void *)&cmd_config_speed_specific_id,
1354                 (void *)&cmd_config_speed_specific_item1,
1355                 (void *)&cmd_config_speed_specific_value1,
1356                 (void *)&cmd_config_speed_specific_item2,
1357                 (void *)&cmd_config_speed_specific_value2,
1358                 NULL,
1359         },
1360 };
1361
1362 /* *** configure txq/rxq, txd/rxd *** */
1363 struct cmd_config_rx_tx {
1364         cmdline_fixed_string_t port;
1365         cmdline_fixed_string_t keyword;
1366         cmdline_fixed_string_t all;
1367         cmdline_fixed_string_t name;
1368         uint16_t value;
1369 };
1370
1371 static void
1372 cmd_config_rx_tx_parsed(void *parsed_result,
1373                         __attribute__((unused)) struct cmdline *cl,
1374                         __attribute__((unused)) void *data)
1375 {
1376         struct cmd_config_rx_tx *res = parsed_result;
1377
1378         if (!all_ports_stopped()) {
1379                 printf("Please stop all ports first\n");
1380                 return;
1381         }
1382         if (!strcmp(res->name, "rxq")) {
1383                 if (!res->value && !nb_txq) {
1384                         printf("Warning: Either rx or tx queues should be non zero\n");
1385                         return;
1386                 }
1387                 nb_rxq = res->value;
1388         }
1389         else if (!strcmp(res->name, "txq")) {
1390                 if (!res->value && !nb_rxq) {
1391                         printf("Warning: Either rx or tx queues should be non zero\n");
1392                         return;
1393                 }
1394                 nb_txq = res->value;
1395         }
1396         else if (!strcmp(res->name, "rxd")) {
1397                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1398                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1399                                         res->value, RTE_TEST_RX_DESC_MAX);
1400                         return;
1401                 }
1402                 nb_rxd = res->value;
1403         } else if (!strcmp(res->name, "txd")) {
1404                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1405                         printf("txd %d invalid - must be > 0 && <= %d\n",
1406                                         res->value, RTE_TEST_TX_DESC_MAX);
1407                         return;
1408                 }
1409                 nb_txd = res->value;
1410         } else {
1411                 printf("Unknown parameter\n");
1412                 return;
1413         }
1414
1415         fwd_config_setup();
1416
1417         init_port_config();
1418
1419         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1420 }
1421
1422 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1424 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1425         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1426 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1427         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1428 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1429         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1430                                                 "rxq#txq#rxd#txd");
1431 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1432         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1433
1434 cmdline_parse_inst_t cmd_config_rx_tx = {
1435         .f = cmd_config_rx_tx_parsed,
1436         .data = NULL,
1437         .help_str = "port config all rxq|txq|rxd|txd <value>",
1438         .tokens = {
1439                 (void *)&cmd_config_rx_tx_port,
1440                 (void *)&cmd_config_rx_tx_keyword,
1441                 (void *)&cmd_config_rx_tx_all,
1442                 (void *)&cmd_config_rx_tx_name,
1443                 (void *)&cmd_config_rx_tx_value,
1444                 NULL,
1445         },
1446 };
1447
1448 /* *** config max packet length *** */
1449 struct cmd_config_max_pkt_len_result {
1450         cmdline_fixed_string_t port;
1451         cmdline_fixed_string_t keyword;
1452         cmdline_fixed_string_t all;
1453         cmdline_fixed_string_t name;
1454         uint32_t value;
1455 };
1456
1457 static void
1458 cmd_config_max_pkt_len_parsed(void *parsed_result,
1459                                 __attribute__((unused)) struct cmdline *cl,
1460                                 __attribute__((unused)) void *data)
1461 {
1462         struct cmd_config_max_pkt_len_result *res = parsed_result;
1463
1464         if (!all_ports_stopped()) {
1465                 printf("Please stop all ports first\n");
1466                 return;
1467         }
1468
1469         if (!strcmp(res->name, "max-pkt-len")) {
1470                 if (res->value < ETHER_MIN_LEN) {
1471                         printf("max-pkt-len can not be less than %d\n",
1472                                                         ETHER_MIN_LEN);
1473                         return;
1474                 }
1475                 if (res->value == rx_mode.max_rx_pkt_len)
1476                         return;
1477
1478                 rx_mode.max_rx_pkt_len = res->value;
1479                 if (res->value > ETHER_MAX_LEN)
1480                         rx_mode.jumbo_frame = 1;
1481                 else
1482                         rx_mode.jumbo_frame = 0;
1483         } else {
1484                 printf("Unknown parameter\n");
1485                 return;
1486         }
1487
1488         init_port_config();
1489
1490         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1491 }
1492
1493 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1494         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1495                                                                 "port");
1496 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1497         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1498                                                                 "config");
1499 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1500         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1501                                                                 "all");
1502 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1503         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1504                                                                 "max-pkt-len");
1505 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1506         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1507                                                                 UINT32);
1508
1509 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1510         .f = cmd_config_max_pkt_len_parsed,
1511         .data = NULL,
1512         .help_str = "port config all max-pkt-len <value>",
1513         .tokens = {
1514                 (void *)&cmd_config_max_pkt_len_port,
1515                 (void *)&cmd_config_max_pkt_len_keyword,
1516                 (void *)&cmd_config_max_pkt_len_all,
1517                 (void *)&cmd_config_max_pkt_len_name,
1518                 (void *)&cmd_config_max_pkt_len_value,
1519                 NULL,
1520         },
1521 };
1522
1523 /* *** configure port MTU *** */
1524 struct cmd_config_mtu_result {
1525         cmdline_fixed_string_t port;
1526         cmdline_fixed_string_t keyword;
1527         cmdline_fixed_string_t mtu;
1528         uint8_t port_id;
1529         uint16_t value;
1530 };
1531
1532 static void
1533 cmd_config_mtu_parsed(void *parsed_result,
1534                       __attribute__((unused)) struct cmdline *cl,
1535                       __attribute__((unused)) void *data)
1536 {
1537         struct cmd_config_mtu_result *res = parsed_result;
1538
1539         if (res->value < ETHER_MIN_LEN) {
1540                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1541                 return;
1542         }
1543         port_mtu_set(res->port_id, res->value);
1544 }
1545
1546 cmdline_parse_token_string_t cmd_config_mtu_port =
1547         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1548                                  "port");
1549 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1550         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1551                                  "config");
1552 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1554                                  "mtu");
1555 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1556         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1557 cmdline_parse_token_num_t cmd_config_mtu_value =
1558         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1559
1560 cmdline_parse_inst_t cmd_config_mtu = {
1561         .f = cmd_config_mtu_parsed,
1562         .data = NULL,
1563         .help_str = "port config mtu <port_id> <value>",
1564         .tokens = {
1565                 (void *)&cmd_config_mtu_port,
1566                 (void *)&cmd_config_mtu_keyword,
1567                 (void *)&cmd_config_mtu_mtu,
1568                 (void *)&cmd_config_mtu_port_id,
1569                 (void *)&cmd_config_mtu_value,
1570                 NULL,
1571         },
1572 };
1573
1574 /* *** configure rx mode *** */
1575 struct cmd_config_rx_mode_flag {
1576         cmdline_fixed_string_t port;
1577         cmdline_fixed_string_t keyword;
1578         cmdline_fixed_string_t all;
1579         cmdline_fixed_string_t name;
1580         cmdline_fixed_string_t value;
1581 };
1582
1583 static void
1584 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1585                                 __attribute__((unused)) struct cmdline *cl,
1586                                 __attribute__((unused)) void *data)
1587 {
1588         struct cmd_config_rx_mode_flag *res = parsed_result;
1589
1590         if (!all_ports_stopped()) {
1591                 printf("Please stop all ports first\n");
1592                 return;
1593         }
1594
1595         if (!strcmp(res->name, "crc-strip")) {
1596                 if (!strcmp(res->value, "on"))
1597                         rx_mode.hw_strip_crc = 1;
1598                 else if (!strcmp(res->value, "off"))
1599                         rx_mode.hw_strip_crc = 0;
1600                 else {
1601                         printf("Unknown parameter\n");
1602                         return;
1603                 }
1604         } else if (!strcmp(res->name, "scatter")) {
1605                 if (!strcmp(res->value, "on"))
1606                         rx_mode.enable_scatter = 1;
1607                 else if (!strcmp(res->value, "off"))
1608                         rx_mode.enable_scatter = 0;
1609                 else {
1610                         printf("Unknown parameter\n");
1611                         return;
1612                 }
1613         } else if (!strcmp(res->name, "rx-cksum")) {
1614                 if (!strcmp(res->value, "on"))
1615                         rx_mode.hw_ip_checksum = 1;
1616                 else if (!strcmp(res->value, "off"))
1617                         rx_mode.hw_ip_checksum = 0;
1618                 else {
1619                         printf("Unknown parameter\n");
1620                         return;
1621                 }
1622         } else if (!strcmp(res->name, "hw-vlan")) {
1623                 if (!strcmp(res->value, "on")) {
1624                         rx_mode.hw_vlan_filter = 1;
1625                         rx_mode.hw_vlan_strip  = 1;
1626                 }
1627                 else if (!strcmp(res->value, "off")) {
1628                         rx_mode.hw_vlan_filter = 0;
1629                         rx_mode.hw_vlan_strip  = 0;
1630                 }
1631                 else {
1632                         printf("Unknown parameter\n");
1633                         return;
1634                 }
1635         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1636                 if (!strcmp(res->value, "on"))
1637                         rx_mode.hw_vlan_filter = 1;
1638                 else if (!strcmp(res->value, "off"))
1639                         rx_mode.hw_vlan_filter = 0;
1640                 else {
1641                         printf("Unknown parameter\n");
1642                         return;
1643                 }
1644         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1645                 if (!strcmp(res->value, "on"))
1646                         rx_mode.hw_vlan_strip  = 1;
1647                 else if (!strcmp(res->value, "off"))
1648                         rx_mode.hw_vlan_strip  = 0;
1649                 else {
1650                         printf("Unknown parameter\n");
1651                         return;
1652                 }
1653         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1654                 if (!strcmp(res->value, "on"))
1655                         rx_mode.hw_vlan_extend = 1;
1656                 else if (!strcmp(res->value, "off"))
1657                         rx_mode.hw_vlan_extend = 0;
1658                 else {
1659                         printf("Unknown parameter\n");
1660                         return;
1661                 }
1662         } else if (!strcmp(res->name, "drop-en")) {
1663                 if (!strcmp(res->value, "on"))
1664                         rx_drop_en = 1;
1665                 else if (!strcmp(res->value, "off"))
1666                         rx_drop_en = 0;
1667                 else {
1668                         printf("Unknown parameter\n");
1669                         return;
1670                 }
1671         } else {
1672                 printf("Unknown parameter\n");
1673                 return;
1674         }
1675
1676         init_port_config();
1677
1678         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1679 }
1680
1681 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1683 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1685                                                                 "config");
1686 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1688 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1689         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1690                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1691                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1692 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1693         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1694                                                         "on#off");
1695
1696 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1697         .f = cmd_config_rx_mode_flag_parsed,
1698         .data = NULL,
1699         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1700                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1701         .tokens = {
1702                 (void *)&cmd_config_rx_mode_flag_port,
1703                 (void *)&cmd_config_rx_mode_flag_keyword,
1704                 (void *)&cmd_config_rx_mode_flag_all,
1705                 (void *)&cmd_config_rx_mode_flag_name,
1706                 (void *)&cmd_config_rx_mode_flag_value,
1707                 NULL,
1708         },
1709 };
1710
1711 /* *** configure rss *** */
1712 struct cmd_config_rss {
1713         cmdline_fixed_string_t port;
1714         cmdline_fixed_string_t keyword;
1715         cmdline_fixed_string_t all;
1716         cmdline_fixed_string_t name;
1717         cmdline_fixed_string_t value;
1718 };
1719
1720 static void
1721 cmd_config_rss_parsed(void *parsed_result,
1722                         __attribute__((unused)) struct cmdline *cl,
1723                         __attribute__((unused)) void *data)
1724 {
1725         struct cmd_config_rss *res = parsed_result;
1726         struct rte_eth_rss_conf rss_conf;
1727         int diag;
1728         uint8_t i;
1729
1730         if (!strcmp(res->value, "all"))
1731                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1732                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1733                                         ETH_RSS_L2_PAYLOAD;
1734         else if (!strcmp(res->value, "ip"))
1735                 rss_conf.rss_hf = ETH_RSS_IP;
1736         else if (!strcmp(res->value, "udp"))
1737                 rss_conf.rss_hf = ETH_RSS_UDP;
1738         else if (!strcmp(res->value, "tcp"))
1739                 rss_conf.rss_hf = ETH_RSS_TCP;
1740         else if (!strcmp(res->value, "sctp"))
1741                 rss_conf.rss_hf = ETH_RSS_SCTP;
1742         else if (!strcmp(res->value, "ether"))
1743                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1744         else if (!strcmp(res->value, "port"))
1745                 rss_conf.rss_hf = ETH_RSS_PORT;
1746         else if (!strcmp(res->value, "vxlan"))
1747                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1748         else if (!strcmp(res->value, "geneve"))
1749                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1750         else if (!strcmp(res->value, "nvgre"))
1751                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1752         else if (!strcmp(res->value, "none"))
1753                 rss_conf.rss_hf = 0;
1754         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1755                                                 atoi(res->value) < 64)
1756                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1757         else {
1758                 printf("Unknown parameter\n");
1759                 return;
1760         }
1761         rss_conf.rss_key = NULL;
1762         for (i = 0; i < rte_eth_dev_count(); i++) {
1763                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1764                 if (diag < 0)
1765                         printf("Configuration of RSS hash at ethernet port %d "
1766                                 "failed with error (%d): %s.\n",
1767                                 i, -diag, strerror(-diag));
1768         }
1769 }
1770
1771 cmdline_parse_token_string_t cmd_config_rss_port =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1773 cmdline_parse_token_string_t cmd_config_rss_keyword =
1774         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1775 cmdline_parse_token_string_t cmd_config_rss_all =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1777 cmdline_parse_token_string_t cmd_config_rss_name =
1778         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1779 cmdline_parse_token_string_t cmd_config_rss_value =
1780         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1781
1782 cmdline_parse_inst_t cmd_config_rss = {
1783         .f = cmd_config_rss_parsed,
1784         .data = NULL,
1785         .help_str = "port config all rss "
1786                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1787         .tokens = {
1788                 (void *)&cmd_config_rss_port,
1789                 (void *)&cmd_config_rss_keyword,
1790                 (void *)&cmd_config_rss_all,
1791                 (void *)&cmd_config_rss_name,
1792                 (void *)&cmd_config_rss_value,
1793                 NULL,
1794         },
1795 };
1796
1797 /* *** configure rss hash key *** */
1798 struct cmd_config_rss_hash_key {
1799         cmdline_fixed_string_t port;
1800         cmdline_fixed_string_t config;
1801         uint8_t port_id;
1802         cmdline_fixed_string_t rss_hash_key;
1803         cmdline_fixed_string_t rss_type;
1804         cmdline_fixed_string_t key;
1805 };
1806
1807 static uint8_t
1808 hexa_digit_to_value(char hexa_digit)
1809 {
1810         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1811                 return (uint8_t) (hexa_digit - '0');
1812         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1813                 return (uint8_t) ((hexa_digit - 'a') + 10);
1814         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1815                 return (uint8_t) ((hexa_digit - 'A') + 10);
1816         /* Invalid hexa digit */
1817         return 0xFF;
1818 }
1819
1820 static uint8_t
1821 parse_and_check_key_hexa_digit(char *key, int idx)
1822 {
1823         uint8_t hexa_v;
1824
1825         hexa_v = hexa_digit_to_value(key[idx]);
1826         if (hexa_v == 0xFF)
1827                 printf("invalid key: character %c at position %d is not a "
1828                        "valid hexa digit\n", key[idx], idx);
1829         return hexa_v;
1830 }
1831
1832 static void
1833 cmd_config_rss_hash_key_parsed(void *parsed_result,
1834                                __attribute__((unused)) struct cmdline *cl,
1835                                __attribute__((unused)) void *data)
1836 {
1837         struct cmd_config_rss_hash_key *res = parsed_result;
1838         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1839         uint8_t xdgt0;
1840         uint8_t xdgt1;
1841         int i;
1842         struct rte_eth_dev_info dev_info;
1843         uint8_t hash_key_size;
1844         uint32_t key_len;
1845
1846         memset(&dev_info, 0, sizeof(dev_info));
1847         rte_eth_dev_info_get(res->port_id, &dev_info);
1848         if (dev_info.hash_key_size > 0 &&
1849                         dev_info.hash_key_size <= sizeof(hash_key))
1850                 hash_key_size = dev_info.hash_key_size;
1851         else {
1852                 printf("dev_info did not provide a valid hash key size\n");
1853                 return;
1854         }
1855         /* Check the length of the RSS hash key */
1856         key_len = strlen(res->key);
1857         if (key_len != (hash_key_size * 2)) {
1858                 printf("key length: %d invalid - key must be a string of %d"
1859                            " hexa-decimal numbers\n",
1860                            (int) key_len, hash_key_size * 2);
1861                 return;
1862         }
1863         /* Translate RSS hash key into binary representation */
1864         for (i = 0; i < hash_key_size; i++) {
1865                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1866                 if (xdgt0 == 0xFF)
1867                         return;
1868                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1869                 if (xdgt1 == 0xFF)
1870                         return;
1871                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1872         }
1873         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1874                         hash_key_size);
1875 }
1876
1877 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1879 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1881                                  "config");
1882 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1883         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1884 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1885         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1886                                  rss_hash_key, "rss-hash-key");
1887 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1888         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1889                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1890                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1891                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1892                                  "ipv6-tcp-ex#ipv6-udp-ex");
1893 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1894         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1895
1896 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1897         .f = cmd_config_rss_hash_key_parsed,
1898         .data = NULL,
1899         .help_str = "port config <port_id> rss-hash-key "
1900                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1901                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1902                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1903                 "<string of hex digits (variable length, NIC dependent)>",
1904         .tokens = {
1905                 (void *)&cmd_config_rss_hash_key_port,
1906                 (void *)&cmd_config_rss_hash_key_config,
1907                 (void *)&cmd_config_rss_hash_key_port_id,
1908                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1909                 (void *)&cmd_config_rss_hash_key_rss_type,
1910                 (void *)&cmd_config_rss_hash_key_value,
1911                 NULL,
1912         },
1913 };
1914
1915 /* *** configure port rxq/txq start/stop *** */
1916 struct cmd_config_rxtx_queue {
1917         cmdline_fixed_string_t port;
1918         uint8_t portid;
1919         cmdline_fixed_string_t rxtxq;
1920         uint16_t qid;
1921         cmdline_fixed_string_t opname;
1922 };
1923
1924 static void
1925 cmd_config_rxtx_queue_parsed(void *parsed_result,
1926                         __attribute__((unused)) struct cmdline *cl,
1927                         __attribute__((unused)) void *data)
1928 {
1929         struct cmd_config_rxtx_queue *res = parsed_result;
1930         uint8_t isrx;
1931         uint8_t isstart;
1932         int ret = 0;
1933
1934         if (test_done == 0) {
1935                 printf("Please stop forwarding first\n");
1936                 return;
1937         }
1938
1939         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1940                 return;
1941
1942         if (port_is_started(res->portid) != 1) {
1943                 printf("Please start port %u first\n", res->portid);
1944                 return;
1945         }
1946
1947         if (!strcmp(res->rxtxq, "rxq"))
1948                 isrx = 1;
1949         else if (!strcmp(res->rxtxq, "txq"))
1950                 isrx = 0;
1951         else {
1952                 printf("Unknown parameter\n");
1953                 return;
1954         }
1955
1956         if (isrx && rx_queue_id_is_invalid(res->qid))
1957                 return;
1958         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1959                 return;
1960
1961         if (!strcmp(res->opname, "start"))
1962                 isstart = 1;
1963         else if (!strcmp(res->opname, "stop"))
1964                 isstart = 0;
1965         else {
1966                 printf("Unknown parameter\n");
1967                 return;
1968         }
1969
1970         if (isstart && isrx)
1971                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1972         else if (!isstart && isrx)
1973                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1974         else if (isstart && !isrx)
1975                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1976         else
1977                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1978
1979         if (ret == -ENOTSUP)
1980                 printf("Function not supported in PMD driver\n");
1981 }
1982
1983 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1984         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1985 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1986         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1987 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1988         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1989 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1990         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1991 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1992         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1993                                                 "start#stop");
1994
1995 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1996         .f = cmd_config_rxtx_queue_parsed,
1997         .data = NULL,
1998         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1999         .tokens = {
2000                 (void *)&cmd_config_speed_all_port,
2001                 (void *)&cmd_config_rxtx_queue_portid,
2002                 (void *)&cmd_config_rxtx_queue_rxtxq,
2003                 (void *)&cmd_config_rxtx_queue_qid,
2004                 (void *)&cmd_config_rxtx_queue_opname,
2005                 NULL,
2006         },
2007 };
2008
2009 /* *** Configure RSS RETA *** */
2010 struct cmd_config_rss_reta {
2011         cmdline_fixed_string_t port;
2012         cmdline_fixed_string_t keyword;
2013         uint8_t port_id;
2014         cmdline_fixed_string_t name;
2015         cmdline_fixed_string_t list_name;
2016         cmdline_fixed_string_t list_of_items;
2017 };
2018
2019 static int
2020 parse_reta_config(const char *str,
2021                   struct rte_eth_rss_reta_entry64 *reta_conf,
2022                   uint16_t nb_entries)
2023 {
2024         int i;
2025         unsigned size;
2026         uint16_t hash_index, idx, shift;
2027         uint16_t nb_queue;
2028         char s[256];
2029         const char *p, *p0 = str;
2030         char *end;
2031         enum fieldnames {
2032                 FLD_HASH_INDEX = 0,
2033                 FLD_QUEUE,
2034                 _NUM_FLD
2035         };
2036         unsigned long int_fld[_NUM_FLD];
2037         char *str_fld[_NUM_FLD];
2038
2039         while ((p = strchr(p0,'(')) != NULL) {
2040                 ++p;
2041                 if((p0 = strchr(p,')')) == NULL)
2042                         return -1;
2043
2044                 size = p0 - p;
2045                 if(size >= sizeof(s))
2046                         return -1;
2047
2048                 snprintf(s, sizeof(s), "%.*s", size, p);
2049                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2050                         return -1;
2051                 for (i = 0; i < _NUM_FLD; i++) {
2052                         errno = 0;
2053                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2054                         if (errno != 0 || end == str_fld[i] ||
2055                                         int_fld[i] > 65535)
2056                                 return -1;
2057                 }
2058
2059                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2060                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2061
2062                 if (hash_index >= nb_entries) {
2063                         printf("Invalid RETA hash index=%d\n", hash_index);
2064                         return -1;
2065                 }
2066
2067                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2068                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2069                 reta_conf[idx].mask |= (1ULL << shift);
2070                 reta_conf[idx].reta[shift] = nb_queue;
2071         }
2072
2073         return 0;
2074 }
2075
2076 static void
2077 cmd_set_rss_reta_parsed(void *parsed_result,
2078                         __attribute__((unused)) struct cmdline *cl,
2079                         __attribute__((unused)) void *data)
2080 {
2081         int ret;
2082         struct rte_eth_dev_info dev_info;
2083         struct rte_eth_rss_reta_entry64 reta_conf[8];
2084         struct cmd_config_rss_reta *res = parsed_result;
2085
2086         memset(&dev_info, 0, sizeof(dev_info));
2087         rte_eth_dev_info_get(res->port_id, &dev_info);
2088         if (dev_info.reta_size == 0) {
2089                 printf("Redirection table size is 0 which is "
2090                                         "invalid for RSS\n");
2091                 return;
2092         } else
2093                 printf("The reta size of port %d is %u\n",
2094                         res->port_id, dev_info.reta_size);
2095         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2096                 printf("Currently do not support more than %u entries of "
2097                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2098                 return;
2099         }
2100
2101         memset(reta_conf, 0, sizeof(reta_conf));
2102         if (!strcmp(res->list_name, "reta")) {
2103                 if (parse_reta_config(res->list_of_items, reta_conf,
2104                                                 dev_info.reta_size)) {
2105                         printf("Invalid RSS Redirection Table "
2106                                         "config entered\n");
2107                         return;
2108                 }
2109                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2110                                 reta_conf, dev_info.reta_size);
2111                 if (ret != 0)
2112                         printf("Bad redirection table parameter, "
2113                                         "return code = %d \n", ret);
2114         }
2115 }
2116
2117 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2119 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2121 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2122         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2123 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2124         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2125 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2126         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2127 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2128         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2129                                  NULL);
2130 cmdline_parse_inst_t cmd_config_rss_reta = {
2131         .f = cmd_set_rss_reta_parsed,
2132         .data = NULL,
2133         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2134         .tokens = {
2135                 (void *)&cmd_config_rss_reta_port,
2136                 (void *)&cmd_config_rss_reta_keyword,
2137                 (void *)&cmd_config_rss_reta_port_id,
2138                 (void *)&cmd_config_rss_reta_name,
2139                 (void *)&cmd_config_rss_reta_list_name,
2140                 (void *)&cmd_config_rss_reta_list_of_items,
2141                 NULL,
2142         },
2143 };
2144
2145 /* *** SHOW PORT RETA INFO *** */
2146 struct cmd_showport_reta {
2147         cmdline_fixed_string_t show;
2148         cmdline_fixed_string_t port;
2149         uint8_t port_id;
2150         cmdline_fixed_string_t rss;
2151         cmdline_fixed_string_t reta;
2152         uint16_t size;
2153         cmdline_fixed_string_t list_of_items;
2154 };
2155
2156 static int
2157 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2158                            uint16_t nb_entries,
2159                            char *str)
2160 {
2161         uint32_t size;
2162         const char *p, *p0 = str;
2163         char s[256];
2164         char *end;
2165         char *str_fld[8];
2166         uint16_t i;
2167         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2168                         RTE_RETA_GROUP_SIZE;
2169         int ret;
2170
2171         p = strchr(p0, '(');
2172         if (p == NULL)
2173                 return -1;
2174         p++;
2175         p0 = strchr(p, ')');
2176         if (p0 == NULL)
2177                 return -1;
2178         size = p0 - p;
2179         if (size >= sizeof(s)) {
2180                 printf("The string size exceeds the internal buffer size\n");
2181                 return -1;
2182         }
2183         snprintf(s, sizeof(s), "%.*s", size, p);
2184         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2185         if (ret <= 0 || ret != num) {
2186                 printf("The bits of masks do not match the number of "
2187                                         "reta entries: %u\n", num);
2188                 return -1;
2189         }
2190         for (i = 0; i < ret; i++)
2191                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2192
2193         return 0;
2194 }
2195
2196 static void
2197 cmd_showport_reta_parsed(void *parsed_result,
2198                          __attribute__((unused)) struct cmdline *cl,
2199                          __attribute__((unused)) void *data)
2200 {
2201         struct cmd_showport_reta *res = parsed_result;
2202         struct rte_eth_rss_reta_entry64 reta_conf[8];
2203         struct rte_eth_dev_info dev_info;
2204         uint16_t max_reta_size;
2205
2206         memset(&dev_info, 0, sizeof(dev_info));
2207         rte_eth_dev_info_get(res->port_id, &dev_info);
2208         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2209         if (res->size == 0 || res->size > max_reta_size) {
2210                 printf("Invalid redirection table size: %u (1-%u)\n",
2211                         res->size, max_reta_size);
2212                 return;
2213         }
2214
2215         memset(reta_conf, 0, sizeof(reta_conf));
2216         if (showport_parse_reta_config(reta_conf, res->size,
2217                                 res->list_of_items) < 0) {
2218                 printf("Invalid string: %s for reta masks\n",
2219                                         res->list_of_items);
2220                 return;
2221         }
2222         port_rss_reta_info(res->port_id, reta_conf, res->size);
2223 }
2224
2225 cmdline_parse_token_string_t cmd_showport_reta_show =
2226         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2227 cmdline_parse_token_string_t cmd_showport_reta_port =
2228         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2229 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2230         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2231 cmdline_parse_token_string_t cmd_showport_reta_rss =
2232         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2233 cmdline_parse_token_string_t cmd_showport_reta_reta =
2234         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2235 cmdline_parse_token_num_t cmd_showport_reta_size =
2236         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2237 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2238         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2239                                         list_of_items, NULL);
2240
2241 cmdline_parse_inst_t cmd_showport_reta = {
2242         .f = cmd_showport_reta_parsed,
2243         .data = NULL,
2244         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2245         .tokens = {
2246                 (void *)&cmd_showport_reta_show,
2247                 (void *)&cmd_showport_reta_port,
2248                 (void *)&cmd_showport_reta_port_id,
2249                 (void *)&cmd_showport_reta_rss,
2250                 (void *)&cmd_showport_reta_reta,
2251                 (void *)&cmd_showport_reta_size,
2252                 (void *)&cmd_showport_reta_list_of_items,
2253                 NULL,
2254         },
2255 };
2256
2257 /* *** Show RSS hash configuration *** */
2258 struct cmd_showport_rss_hash {
2259         cmdline_fixed_string_t show;
2260         cmdline_fixed_string_t port;
2261         uint8_t port_id;
2262         cmdline_fixed_string_t rss_hash;
2263         cmdline_fixed_string_t rss_type;
2264         cmdline_fixed_string_t key; /* optional argument */
2265 };
2266
2267 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2268                                 __attribute__((unused)) struct cmdline *cl,
2269                                 void *show_rss_key)
2270 {
2271         struct cmd_showport_rss_hash *res = parsed_result;
2272
2273         port_rss_hash_conf_show(res->port_id, res->rss_type,
2274                                 show_rss_key != NULL);
2275 }
2276
2277 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2278         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2279 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2280         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2281 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2282         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2283 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2284         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2285                                  "rss-hash");
2286 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2287         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2288                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2289                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2290                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2291                                  "ipv6-tcp-ex#ipv6-udp-ex");
2292 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2293         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2294
2295 cmdline_parse_inst_t cmd_showport_rss_hash = {
2296         .f = cmd_showport_rss_hash_parsed,
2297         .data = NULL,
2298         .help_str = "show port <port_id> rss-hash "
2299                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2300                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2301                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2302         .tokens = {
2303                 (void *)&cmd_showport_rss_hash_show,
2304                 (void *)&cmd_showport_rss_hash_port,
2305                 (void *)&cmd_showport_rss_hash_port_id,
2306                 (void *)&cmd_showport_rss_hash_rss_hash,
2307                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2308                 NULL,
2309         },
2310 };
2311
2312 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2313         .f = cmd_showport_rss_hash_parsed,
2314         .data = (void *)1,
2315         .help_str = "show port <port_id> rss-hash "
2316                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2317                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2318                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2319         .tokens = {
2320                 (void *)&cmd_showport_rss_hash_show,
2321                 (void *)&cmd_showport_rss_hash_port,
2322                 (void *)&cmd_showport_rss_hash_port_id,
2323                 (void *)&cmd_showport_rss_hash_rss_hash,
2324                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2325                 (void *)&cmd_showport_rss_hash_rss_key,
2326                 NULL,
2327         },
2328 };
2329
2330 /* *** Configure DCB *** */
2331 struct cmd_config_dcb {
2332         cmdline_fixed_string_t port;
2333         cmdline_fixed_string_t config;
2334         uint8_t port_id;
2335         cmdline_fixed_string_t dcb;
2336         cmdline_fixed_string_t vt;
2337         cmdline_fixed_string_t vt_en;
2338         uint8_t num_tcs;
2339         cmdline_fixed_string_t pfc;
2340         cmdline_fixed_string_t pfc_en;
2341 };
2342
2343 static void
2344 cmd_config_dcb_parsed(void *parsed_result,
2345                         __attribute__((unused)) struct cmdline *cl,
2346                         __attribute__((unused)) void *data)
2347 {
2348         struct cmd_config_dcb *res = parsed_result;
2349         portid_t port_id = res->port_id;
2350         struct rte_port *port;
2351         uint8_t pfc_en;
2352         int ret;
2353
2354         port = &ports[port_id];
2355         /** Check if the port is not started **/
2356         if (port->port_status != RTE_PORT_STOPPED) {
2357                 printf("Please stop port %d first\n", port_id);
2358                 return;
2359         }
2360
2361         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2362                 printf("The invalid number of traffic class,"
2363                         " only 4 or 8 allowed.\n");
2364                 return;
2365         }
2366
2367         if (nb_fwd_lcores < res->num_tcs) {
2368                 printf("nb_cores shouldn't be less than number of TCs.\n");
2369                 return;
2370         }
2371         if (!strncmp(res->pfc_en, "on", 2))
2372                 pfc_en = 1;
2373         else
2374                 pfc_en = 0;
2375
2376         /* DCB in VT mode */
2377         if (!strncmp(res->vt_en, "on", 2))
2378                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2379                                 (enum rte_eth_nb_tcs)res->num_tcs,
2380                                 pfc_en);
2381         else
2382                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2383                                 (enum rte_eth_nb_tcs)res->num_tcs,
2384                                 pfc_en);
2385
2386
2387         if (ret != 0) {
2388                 printf("Cannot initialize network ports.\n");
2389                 return;
2390         }
2391
2392         cmd_reconfig_device_queue(port_id, 1, 1);
2393 }
2394
2395 cmdline_parse_token_string_t cmd_config_dcb_port =
2396         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2397 cmdline_parse_token_string_t cmd_config_dcb_config =
2398         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2399 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2400         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2401 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2402         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2403 cmdline_parse_token_string_t cmd_config_dcb_vt =
2404         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2405 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2407 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2408         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2409 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2411 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2413
2414 cmdline_parse_inst_t cmd_config_dcb = {
2415         .f = cmd_config_dcb_parsed,
2416         .data = NULL,
2417         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2418         .tokens = {
2419                 (void *)&cmd_config_dcb_port,
2420                 (void *)&cmd_config_dcb_config,
2421                 (void *)&cmd_config_dcb_port_id,
2422                 (void *)&cmd_config_dcb_dcb,
2423                 (void *)&cmd_config_dcb_vt,
2424                 (void *)&cmd_config_dcb_vt_en,
2425                 (void *)&cmd_config_dcb_num_tcs,
2426                 (void *)&cmd_config_dcb_pfc,
2427                 (void *)&cmd_config_dcb_pfc_en,
2428                 NULL,
2429         },
2430 };
2431
2432 /* *** configure number of packets per burst *** */
2433 struct cmd_config_burst {
2434         cmdline_fixed_string_t port;
2435         cmdline_fixed_string_t keyword;
2436         cmdline_fixed_string_t all;
2437         cmdline_fixed_string_t name;
2438         uint16_t value;
2439 };
2440
2441 static void
2442 cmd_config_burst_parsed(void *parsed_result,
2443                         __attribute__((unused)) struct cmdline *cl,
2444                         __attribute__((unused)) void *data)
2445 {
2446         struct cmd_config_burst *res = parsed_result;
2447
2448         if (!all_ports_stopped()) {
2449                 printf("Please stop all ports first\n");
2450                 return;
2451         }
2452
2453         if (!strcmp(res->name, "burst")) {
2454                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2455                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2456                         return;
2457                 }
2458                 nb_pkt_per_burst = res->value;
2459         } else {
2460                 printf("Unknown parameter\n");
2461                 return;
2462         }
2463
2464         init_port_config();
2465
2466         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2467 }
2468
2469 cmdline_parse_token_string_t cmd_config_burst_port =
2470         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2471 cmdline_parse_token_string_t cmd_config_burst_keyword =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2473 cmdline_parse_token_string_t cmd_config_burst_all =
2474         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2475 cmdline_parse_token_string_t cmd_config_burst_name =
2476         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2477 cmdline_parse_token_num_t cmd_config_burst_value =
2478         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2479
2480 cmdline_parse_inst_t cmd_config_burst = {
2481         .f = cmd_config_burst_parsed,
2482         .data = NULL,
2483         .help_str = "port config all burst <value>",
2484         .tokens = {
2485                 (void *)&cmd_config_burst_port,
2486                 (void *)&cmd_config_burst_keyword,
2487                 (void *)&cmd_config_burst_all,
2488                 (void *)&cmd_config_burst_name,
2489                 (void *)&cmd_config_burst_value,
2490                 NULL,
2491         },
2492 };
2493
2494 /* *** configure rx/tx queues *** */
2495 struct cmd_config_thresh {
2496         cmdline_fixed_string_t port;
2497         cmdline_fixed_string_t keyword;
2498         cmdline_fixed_string_t all;
2499         cmdline_fixed_string_t name;
2500         uint8_t value;
2501 };
2502
2503 static void
2504 cmd_config_thresh_parsed(void *parsed_result,
2505                         __attribute__((unused)) struct cmdline *cl,
2506                         __attribute__((unused)) void *data)
2507 {
2508         struct cmd_config_thresh *res = parsed_result;
2509
2510         if (!all_ports_stopped()) {
2511                 printf("Please stop all ports first\n");
2512                 return;
2513         }
2514
2515         if (!strcmp(res->name, "txpt"))
2516                 tx_pthresh = res->value;
2517         else if(!strcmp(res->name, "txht"))
2518                 tx_hthresh = res->value;
2519         else if(!strcmp(res->name, "txwt"))
2520                 tx_wthresh = res->value;
2521         else if(!strcmp(res->name, "rxpt"))
2522                 rx_pthresh = res->value;
2523         else if(!strcmp(res->name, "rxht"))
2524                 rx_hthresh = res->value;
2525         else if(!strcmp(res->name, "rxwt"))
2526                 rx_wthresh = res->value;
2527         else {
2528                 printf("Unknown parameter\n");
2529                 return;
2530         }
2531
2532         init_port_config();
2533
2534         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2535 }
2536
2537 cmdline_parse_token_string_t cmd_config_thresh_port =
2538         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2539 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2540         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2541 cmdline_parse_token_string_t cmd_config_thresh_all =
2542         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2543 cmdline_parse_token_string_t cmd_config_thresh_name =
2544         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2545                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2546 cmdline_parse_token_num_t cmd_config_thresh_value =
2547         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2548
2549 cmdline_parse_inst_t cmd_config_thresh = {
2550         .f = cmd_config_thresh_parsed,
2551         .data = NULL,
2552         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2553         .tokens = {
2554                 (void *)&cmd_config_thresh_port,
2555                 (void *)&cmd_config_thresh_keyword,
2556                 (void *)&cmd_config_thresh_all,
2557                 (void *)&cmd_config_thresh_name,
2558                 (void *)&cmd_config_thresh_value,
2559                 NULL,
2560         },
2561 };
2562
2563 /* *** configure free/rs threshold *** */
2564 struct cmd_config_threshold {
2565         cmdline_fixed_string_t port;
2566         cmdline_fixed_string_t keyword;
2567         cmdline_fixed_string_t all;
2568         cmdline_fixed_string_t name;
2569         uint16_t value;
2570 };
2571
2572 static void
2573 cmd_config_threshold_parsed(void *parsed_result,
2574                         __attribute__((unused)) struct cmdline *cl,
2575                         __attribute__((unused)) void *data)
2576 {
2577         struct cmd_config_threshold *res = parsed_result;
2578
2579         if (!all_ports_stopped()) {
2580                 printf("Please stop all ports first\n");
2581                 return;
2582         }
2583
2584         if (!strcmp(res->name, "txfreet"))
2585                 tx_free_thresh = res->value;
2586         else if (!strcmp(res->name, "txrst"))
2587                 tx_rs_thresh = res->value;
2588         else if (!strcmp(res->name, "rxfreet"))
2589                 rx_free_thresh = res->value;
2590         else {
2591                 printf("Unknown parameter\n");
2592                 return;
2593         }
2594
2595         init_port_config();
2596
2597         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2598 }
2599
2600 cmdline_parse_token_string_t cmd_config_threshold_port =
2601         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2602 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2603         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2604                                                                 "config");
2605 cmdline_parse_token_string_t cmd_config_threshold_all =
2606         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2607 cmdline_parse_token_string_t cmd_config_threshold_name =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2609                                                 "txfreet#txrst#rxfreet");
2610 cmdline_parse_token_num_t cmd_config_threshold_value =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2612
2613 cmdline_parse_inst_t cmd_config_threshold = {
2614         .f = cmd_config_threshold_parsed,
2615         .data = NULL,
2616         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2617         .tokens = {
2618                 (void *)&cmd_config_threshold_port,
2619                 (void *)&cmd_config_threshold_keyword,
2620                 (void *)&cmd_config_threshold_all,
2621                 (void *)&cmd_config_threshold_name,
2622                 (void *)&cmd_config_threshold_value,
2623                 NULL,
2624         },
2625 };
2626
2627 /* *** stop *** */
2628 struct cmd_stop_result {
2629         cmdline_fixed_string_t stop;
2630 };
2631
2632 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2633                             __attribute__((unused)) struct cmdline *cl,
2634                             __attribute__((unused)) void *data)
2635 {
2636         stop_packet_forwarding();
2637 }
2638
2639 cmdline_parse_token_string_t cmd_stop_stop =
2640         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2641
2642 cmdline_parse_inst_t cmd_stop = {
2643         .f = cmd_stop_parsed,
2644         .data = NULL,
2645         .help_str = "stop: Stop packet forwarding",
2646         .tokens = {
2647                 (void *)&cmd_stop_stop,
2648                 NULL,
2649         },
2650 };
2651
2652 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2653
2654 unsigned int
2655 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2656                 unsigned int *parsed_items, int check_unique_values)
2657 {
2658         unsigned int nb_item;
2659         unsigned int value;
2660         unsigned int i;
2661         unsigned int j;
2662         int value_ok;
2663         char c;
2664
2665         /*
2666          * First parse all items in the list and store their value.
2667          */
2668         value = 0;
2669         nb_item = 0;
2670         value_ok = 0;
2671         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2672                 c = str[i];
2673                 if ((c >= '0') && (c <= '9')) {
2674                         value = (unsigned int) (value * 10 + (c - '0'));
2675                         value_ok = 1;
2676                         continue;
2677                 }
2678                 if (c != ',') {
2679                         printf("character %c is not a decimal digit\n", c);
2680                         return 0;
2681                 }
2682                 if (! value_ok) {
2683                         printf("No valid value before comma\n");
2684                         return 0;
2685                 }
2686                 if (nb_item < max_items) {
2687                         parsed_items[nb_item] = value;
2688                         value_ok = 0;
2689                         value = 0;
2690                 }
2691                 nb_item++;
2692         }
2693         if (nb_item >= max_items) {
2694                 printf("Number of %s = %u > %u (maximum items)\n",
2695                        item_name, nb_item + 1, max_items);
2696                 return 0;
2697         }
2698         parsed_items[nb_item++] = value;
2699         if (! check_unique_values)
2700                 return nb_item;
2701
2702         /*
2703          * Then, check that all values in the list are differents.
2704          * No optimization here...
2705          */
2706         for (i = 0; i < nb_item; i++) {
2707                 for (j = i + 1; j < nb_item; j++) {
2708                         if (parsed_items[j] == parsed_items[i]) {
2709                                 printf("duplicated %s %u at index %u and %u\n",
2710                                        item_name, parsed_items[i], i, j);
2711                                 return 0;
2712                         }
2713                 }
2714         }
2715         return nb_item;
2716 }
2717
2718 struct cmd_set_list_result {
2719         cmdline_fixed_string_t cmd_keyword;
2720         cmdline_fixed_string_t list_name;
2721         cmdline_fixed_string_t list_of_items;
2722 };
2723
2724 static void cmd_set_list_parsed(void *parsed_result,
2725                                 __attribute__((unused)) struct cmdline *cl,
2726                                 __attribute__((unused)) void *data)
2727 {
2728         struct cmd_set_list_result *res;
2729         union {
2730                 unsigned int lcorelist[RTE_MAX_LCORE];
2731                 unsigned int portlist[RTE_MAX_ETHPORTS];
2732         } parsed_items;
2733         unsigned int nb_item;
2734
2735         if (test_done == 0) {
2736                 printf("Please stop forwarding first\n");
2737                 return;
2738         }
2739
2740         res = parsed_result;
2741         if (!strcmp(res->list_name, "corelist")) {
2742                 nb_item = parse_item_list(res->list_of_items, "core",
2743                                           RTE_MAX_LCORE,
2744                                           parsed_items.lcorelist, 1);
2745                 if (nb_item > 0) {
2746                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2747                         fwd_config_setup();
2748                 }
2749                 return;
2750         }
2751         if (!strcmp(res->list_name, "portlist")) {
2752                 nb_item = parse_item_list(res->list_of_items, "port",
2753                                           RTE_MAX_ETHPORTS,
2754                                           parsed_items.portlist, 1);
2755                 if (nb_item > 0) {
2756                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2757                         fwd_config_setup();
2758                 }
2759         }
2760 }
2761
2762 cmdline_parse_token_string_t cmd_set_list_keyword =
2763         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2764                                  "set");
2765 cmdline_parse_token_string_t cmd_set_list_name =
2766         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2767                                  "corelist#portlist");
2768 cmdline_parse_token_string_t cmd_set_list_of_items =
2769         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2770                                  NULL);
2771
2772 cmdline_parse_inst_t cmd_set_fwd_list = {
2773         .f = cmd_set_list_parsed,
2774         .data = NULL,
2775         .help_str = "set corelist|portlist <list0[,list1]*>",
2776         .tokens = {
2777                 (void *)&cmd_set_list_keyword,
2778                 (void *)&cmd_set_list_name,
2779                 (void *)&cmd_set_list_of_items,
2780                 NULL,
2781         },
2782 };
2783
2784 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2785
2786 struct cmd_setmask_result {
2787         cmdline_fixed_string_t set;
2788         cmdline_fixed_string_t mask;
2789         uint64_t hexavalue;
2790 };
2791
2792 static void cmd_set_mask_parsed(void *parsed_result,
2793                                 __attribute__((unused)) struct cmdline *cl,
2794                                 __attribute__((unused)) void *data)
2795 {
2796         struct cmd_setmask_result *res = parsed_result;
2797
2798         if (test_done == 0) {
2799                 printf("Please stop forwarding first\n");
2800                 return;
2801         }
2802         if (!strcmp(res->mask, "coremask")) {
2803                 set_fwd_lcores_mask(res->hexavalue);
2804                 fwd_config_setup();
2805         } else if (!strcmp(res->mask, "portmask")) {
2806                 set_fwd_ports_mask(res->hexavalue);
2807                 fwd_config_setup();
2808         }
2809 }
2810
2811 cmdline_parse_token_string_t cmd_setmask_set =
2812         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2813 cmdline_parse_token_string_t cmd_setmask_mask =
2814         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2815                                  "coremask#portmask");
2816 cmdline_parse_token_num_t cmd_setmask_value =
2817         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2818
2819 cmdline_parse_inst_t cmd_set_fwd_mask = {
2820         .f = cmd_set_mask_parsed,
2821         .data = NULL,
2822         .help_str = "set coremask|portmask <hexadecimal value>",
2823         .tokens = {
2824                 (void *)&cmd_setmask_set,
2825                 (void *)&cmd_setmask_mask,
2826                 (void *)&cmd_setmask_value,
2827                 NULL,
2828         },
2829 };
2830
2831 /*
2832  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2833  */
2834 struct cmd_set_result {
2835         cmdline_fixed_string_t set;
2836         cmdline_fixed_string_t what;
2837         uint16_t value;
2838 };
2839
2840 static void cmd_set_parsed(void *parsed_result,
2841                            __attribute__((unused)) struct cmdline *cl,
2842                            __attribute__((unused)) void *data)
2843 {
2844         struct cmd_set_result *res = parsed_result;
2845         if (!strcmp(res->what, "nbport")) {
2846                 set_fwd_ports_number(res->value);
2847                 fwd_config_setup();
2848         } else if (!strcmp(res->what, "nbcore")) {
2849                 set_fwd_lcores_number(res->value);
2850                 fwd_config_setup();
2851         } else if (!strcmp(res->what, "burst"))
2852                 set_nb_pkt_per_burst(res->value);
2853         else if (!strcmp(res->what, "verbose"))
2854                 set_verbose_level(res->value);
2855 }
2856
2857 cmdline_parse_token_string_t cmd_set_set =
2858         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2859 cmdline_parse_token_string_t cmd_set_what =
2860         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2861                                  "nbport#nbcore#burst#verbose");
2862 cmdline_parse_token_num_t cmd_set_value =
2863         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2864
2865 cmdline_parse_inst_t cmd_set_numbers = {
2866         .f = cmd_set_parsed,
2867         .data = NULL,
2868         .help_str = "set nbport|nbcore|burst|verbose <value>",
2869         .tokens = {
2870                 (void *)&cmd_set_set,
2871                 (void *)&cmd_set_what,
2872                 (void *)&cmd_set_value,
2873                 NULL,
2874         },
2875 };
2876
2877 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2878
2879 struct cmd_set_txpkts_result {
2880         cmdline_fixed_string_t cmd_keyword;
2881         cmdline_fixed_string_t txpkts;
2882         cmdline_fixed_string_t seg_lengths;
2883 };
2884
2885 static void
2886 cmd_set_txpkts_parsed(void *parsed_result,
2887                       __attribute__((unused)) struct cmdline *cl,
2888                       __attribute__((unused)) void *data)
2889 {
2890         struct cmd_set_txpkts_result *res;
2891         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2892         unsigned int nb_segs;
2893
2894         res = parsed_result;
2895         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2896                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2897         if (nb_segs > 0)
2898                 set_tx_pkt_segments(seg_lengths, nb_segs);
2899 }
2900
2901 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2902         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2903                                  cmd_keyword, "set");
2904 cmdline_parse_token_string_t cmd_set_txpkts_name =
2905         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2906                                  txpkts, "txpkts");
2907 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2908         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2909                                  seg_lengths, NULL);
2910
2911 cmdline_parse_inst_t cmd_set_txpkts = {
2912         .f = cmd_set_txpkts_parsed,
2913         .data = NULL,
2914         .help_str = "set txpkts <len0[,len1]*>",
2915         .tokens = {
2916                 (void *)&cmd_set_txpkts_keyword,
2917                 (void *)&cmd_set_txpkts_name,
2918                 (void *)&cmd_set_txpkts_lengths,
2919                 NULL,
2920         },
2921 };
2922
2923 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2924
2925 struct cmd_set_txsplit_result {
2926         cmdline_fixed_string_t cmd_keyword;
2927         cmdline_fixed_string_t txsplit;
2928         cmdline_fixed_string_t mode;
2929 };
2930
2931 static void
2932 cmd_set_txsplit_parsed(void *parsed_result,
2933                       __attribute__((unused)) struct cmdline *cl,
2934                       __attribute__((unused)) void *data)
2935 {
2936         struct cmd_set_txsplit_result *res;
2937
2938         res = parsed_result;
2939         set_tx_pkt_split(res->mode);
2940 }
2941
2942 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2943         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2944                                  cmd_keyword, "set");
2945 cmdline_parse_token_string_t cmd_set_txsplit_name =
2946         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2947                                  txsplit, "txsplit");
2948 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2949         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2950                                  mode, NULL);
2951
2952 cmdline_parse_inst_t cmd_set_txsplit = {
2953         .f = cmd_set_txsplit_parsed,
2954         .data = NULL,
2955         .help_str = "set txsplit on|off|rand",
2956         .tokens = {
2957                 (void *)&cmd_set_txsplit_keyword,
2958                 (void *)&cmd_set_txsplit_name,
2959                 (void *)&cmd_set_txsplit_mode,
2960                 NULL,
2961         },
2962 };
2963
2964 /* *** CONFIG TX QUEUE FLAGS *** */
2965
2966 struct cmd_config_txqflags_result {
2967         cmdline_fixed_string_t port;
2968         cmdline_fixed_string_t config;
2969         cmdline_fixed_string_t all;
2970         cmdline_fixed_string_t what;
2971         int32_t hexvalue;
2972 };
2973
2974 static void cmd_config_txqflags_parsed(void *parsed_result,
2975                                 __attribute__((unused)) struct cmdline *cl,
2976                                 __attribute__((unused)) void *data)
2977 {
2978         struct cmd_config_txqflags_result *res = parsed_result;
2979
2980         if (!all_ports_stopped()) {
2981                 printf("Please stop all ports first\n");
2982                 return;
2983         }
2984
2985         if (strcmp(res->what, "txqflags")) {
2986                 printf("Unknown parameter\n");
2987                 return;
2988         }
2989
2990         if (res->hexvalue >= 0) {
2991                 txq_flags = res->hexvalue;
2992         } else {
2993                 printf("txqflags must be >= 0\n");
2994                 return;
2995         }
2996
2997         init_port_config();
2998
2999         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3000 }
3001
3002 cmdline_parse_token_string_t cmd_config_txqflags_port =
3003         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3004                                  "port");
3005 cmdline_parse_token_string_t cmd_config_txqflags_config =
3006         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3007                                  "config");
3008 cmdline_parse_token_string_t cmd_config_txqflags_all =
3009         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3010                                  "all");
3011 cmdline_parse_token_string_t cmd_config_txqflags_what =
3012         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3013                                  "txqflags");
3014 cmdline_parse_token_num_t cmd_config_txqflags_value =
3015         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3016                                 hexvalue, INT32);
3017
3018 cmdline_parse_inst_t cmd_config_txqflags = {
3019         .f = cmd_config_txqflags_parsed,
3020         .data = NULL,
3021         .help_str = "port config all txqflags <value>",
3022         .tokens = {
3023                 (void *)&cmd_config_txqflags_port,
3024                 (void *)&cmd_config_txqflags_config,
3025                 (void *)&cmd_config_txqflags_all,
3026                 (void *)&cmd_config_txqflags_what,
3027                 (void *)&cmd_config_txqflags_value,
3028                 NULL,
3029         },
3030 };
3031
3032 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3033 struct cmd_rx_vlan_filter_all_result {
3034         cmdline_fixed_string_t rx_vlan;
3035         cmdline_fixed_string_t what;
3036         cmdline_fixed_string_t all;
3037         uint8_t port_id;
3038 };
3039
3040 static void
3041 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3042                               __attribute__((unused)) struct cmdline *cl,
3043                               __attribute__((unused)) void *data)
3044 {
3045         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3046
3047         if (!strcmp(res->what, "add"))
3048                 rx_vlan_all_filter_set(res->port_id, 1);
3049         else
3050                 rx_vlan_all_filter_set(res->port_id, 0);
3051 }
3052
3053 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3054         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3055                                  rx_vlan, "rx_vlan");
3056 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3057         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3058                                  what, "add#rm");
3059 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3060         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3061                                  all, "all");
3062 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3063         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3064                               port_id, UINT8);
3065
3066 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3067         .f = cmd_rx_vlan_filter_all_parsed,
3068         .data = NULL,
3069         .help_str = "rx_vlan add|rm all <port_id>: "
3070                 "Add/Remove all identifiers to/from the set of VLAN "
3071                 "identifiers filtered by a port",
3072         .tokens = {
3073                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3074                 (void *)&cmd_rx_vlan_filter_all_what,
3075                 (void *)&cmd_rx_vlan_filter_all_all,
3076                 (void *)&cmd_rx_vlan_filter_all_portid,
3077                 NULL,
3078         },
3079 };
3080
3081 /* *** VLAN OFFLOAD SET ON A PORT *** */
3082 struct cmd_vlan_offload_result {
3083         cmdline_fixed_string_t vlan;
3084         cmdline_fixed_string_t set;
3085         cmdline_fixed_string_t vlan_type;
3086         cmdline_fixed_string_t what;
3087         cmdline_fixed_string_t on;
3088         cmdline_fixed_string_t port_id;
3089 };
3090
3091 static void
3092 cmd_vlan_offload_parsed(void *parsed_result,
3093                           __attribute__((unused)) struct cmdline *cl,
3094                           __attribute__((unused)) void *data)
3095 {
3096         int on;
3097         struct cmd_vlan_offload_result *res = parsed_result;
3098         char *str;
3099         int i, len = 0;
3100         portid_t port_id = 0;
3101         unsigned int tmp;
3102
3103         str = res->port_id;
3104         len = strnlen(str, STR_TOKEN_SIZE);
3105         i = 0;
3106         /* Get port_id first */
3107         while(i < len){
3108                 if(str[i] == ',')
3109                         break;
3110
3111                 i++;
3112         }
3113         str[i]='\0';
3114         tmp = strtoul(str, NULL, 0);
3115         /* If port_id greater that what portid_t can represent, return */
3116         if(tmp >= RTE_MAX_ETHPORTS)
3117                 return;
3118         port_id = (portid_t)tmp;
3119
3120         if (!strcmp(res->on, "on"))
3121                 on = 1;
3122         else
3123                 on = 0;
3124
3125         if (!strcmp(res->what, "strip"))
3126                 rx_vlan_strip_set(port_id,  on);
3127         else if(!strcmp(res->what, "stripq")){
3128                 uint16_t queue_id = 0;
3129
3130                 /* No queue_id, return */
3131                 if(i + 1 >= len) {
3132                         printf("must specify (port,queue_id)\n");
3133                         return;
3134                 }
3135                 tmp = strtoul(str + i + 1, NULL, 0);
3136                 /* If queue_id greater that what 16-bits can represent, return */
3137                 if(tmp > 0xffff)
3138                         return;
3139
3140                 queue_id = (uint16_t)tmp;
3141                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3142         }
3143         else if (!strcmp(res->what, "filter"))
3144                 rx_vlan_filter_set(port_id, on);
3145         else
3146                 vlan_extend_set(port_id, on);
3147
3148         return;
3149 }
3150
3151 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3152         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3153                                  vlan, "vlan");
3154 cmdline_parse_token_string_t cmd_vlan_offload_set =
3155         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3156                                  set, "set");
3157 cmdline_parse_token_string_t cmd_vlan_offload_what =
3158         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3159                                  what, "strip#filter#qinq#stripq");
3160 cmdline_parse_token_string_t cmd_vlan_offload_on =
3161         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3162                               on, "on#off");
3163 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3164         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3165                               port_id, NULL);
3166
3167 cmdline_parse_inst_t cmd_vlan_offload = {
3168         .f = cmd_vlan_offload_parsed,
3169         .data = NULL,
3170         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3171                 "<port_id[,queue_id]>: "
3172                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3173         .tokens = {
3174                 (void *)&cmd_vlan_offload_vlan,
3175                 (void *)&cmd_vlan_offload_set,
3176                 (void *)&cmd_vlan_offload_what,
3177                 (void *)&cmd_vlan_offload_on,
3178                 (void *)&cmd_vlan_offload_portid,
3179                 NULL,
3180         },
3181 };
3182
3183 /* *** VLAN TPID SET ON A PORT *** */
3184 struct cmd_vlan_tpid_result {
3185         cmdline_fixed_string_t vlan;
3186         cmdline_fixed_string_t set;
3187         cmdline_fixed_string_t vlan_type;
3188         cmdline_fixed_string_t what;
3189         uint16_t tp_id;
3190         uint8_t port_id;
3191 };
3192
3193 static void
3194 cmd_vlan_tpid_parsed(void *parsed_result,
3195                           __attribute__((unused)) struct cmdline *cl,
3196                           __attribute__((unused)) void *data)
3197 {
3198         struct cmd_vlan_tpid_result *res = parsed_result;
3199         enum rte_vlan_type vlan_type;
3200
3201         if (!strcmp(res->vlan_type, "inner"))
3202                 vlan_type = ETH_VLAN_TYPE_INNER;
3203         else if (!strcmp(res->vlan_type, "outer"))
3204                 vlan_type = ETH_VLAN_TYPE_OUTER;
3205         else {
3206                 printf("Unknown vlan type\n");
3207                 return;
3208         }
3209         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3210 }
3211
3212 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3213         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3214                                  vlan, "vlan");
3215 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3216         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3217                                  set, "set");
3218 cmdline_parse_token_string_t cmd_vlan_type =
3219         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3220                                  vlan_type, "inner#outer");
3221 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3222         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3223                                  what, "tpid");
3224 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3225         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3226                               tp_id, UINT16);
3227 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3228         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3229                               port_id, UINT8);
3230
3231 cmdline_parse_inst_t cmd_vlan_tpid = {
3232         .f = cmd_vlan_tpid_parsed,
3233         .data = NULL,
3234         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3235                 "Set the VLAN Ether type",
3236         .tokens = {
3237                 (void *)&cmd_vlan_tpid_vlan,
3238                 (void *)&cmd_vlan_tpid_set,
3239                 (void *)&cmd_vlan_type,
3240                 (void *)&cmd_vlan_tpid_what,
3241                 (void *)&cmd_vlan_tpid_tpid,
3242                 (void *)&cmd_vlan_tpid_portid,
3243                 NULL,
3244         },
3245 };
3246
3247 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3248 struct cmd_rx_vlan_filter_result {
3249         cmdline_fixed_string_t rx_vlan;
3250         cmdline_fixed_string_t what;
3251         uint16_t vlan_id;
3252         uint8_t port_id;
3253 };
3254
3255 static void
3256 cmd_rx_vlan_filter_parsed(void *parsed_result,
3257                           __attribute__((unused)) struct cmdline *cl,
3258                           __attribute__((unused)) void *data)
3259 {
3260         struct cmd_rx_vlan_filter_result *res = parsed_result;
3261
3262         if (!strcmp(res->what, "add"))
3263                 rx_vft_set(res->port_id, res->vlan_id, 1);
3264         else
3265                 rx_vft_set(res->port_id, res->vlan_id, 0);
3266 }
3267
3268 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3269         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3270                                  rx_vlan, "rx_vlan");
3271 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3272         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3273                                  what, "add#rm");
3274 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3275         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3276                               vlan_id, UINT16);
3277 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3278         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3279                               port_id, UINT8);
3280
3281 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3282         .f = cmd_rx_vlan_filter_parsed,
3283         .data = NULL,
3284         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3285                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3286                 "identifiers filtered by a port",
3287         .tokens = {
3288                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3289                 (void *)&cmd_rx_vlan_filter_what,
3290                 (void *)&cmd_rx_vlan_filter_vlanid,
3291                 (void *)&cmd_rx_vlan_filter_portid,
3292                 NULL,
3293         },
3294 };
3295
3296 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3297 struct cmd_tx_vlan_set_result {
3298         cmdline_fixed_string_t tx_vlan;
3299         cmdline_fixed_string_t set;
3300         uint8_t port_id;
3301         uint16_t vlan_id;
3302 };
3303
3304 static void
3305 cmd_tx_vlan_set_parsed(void *parsed_result,
3306                        __attribute__((unused)) struct cmdline *cl,
3307                        __attribute__((unused)) void *data)
3308 {
3309         struct cmd_tx_vlan_set_result *res = parsed_result;
3310
3311         tx_vlan_set(res->port_id, res->vlan_id);
3312 }
3313
3314 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3315         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3316                                  tx_vlan, "tx_vlan");
3317 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3318         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3319                                  set, "set");
3320 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3321         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3322                               port_id, UINT8);
3323 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3324         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3325                               vlan_id, UINT16);
3326
3327 cmdline_parse_inst_t cmd_tx_vlan_set = {
3328         .f = cmd_tx_vlan_set_parsed,
3329         .data = NULL,
3330         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3331                 "Enable hardware insertion of a single VLAN header "
3332                 "with a given TAG Identifier in packets sent on a port",
3333         .tokens = {
3334                 (void *)&cmd_tx_vlan_set_tx_vlan,
3335                 (void *)&cmd_tx_vlan_set_set,
3336                 (void *)&cmd_tx_vlan_set_portid,
3337                 (void *)&cmd_tx_vlan_set_vlanid,
3338                 NULL,
3339         },
3340 };
3341
3342 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3343 struct cmd_tx_vlan_set_qinq_result {
3344         cmdline_fixed_string_t tx_vlan;
3345         cmdline_fixed_string_t set;
3346         uint8_t port_id;
3347         uint16_t vlan_id;
3348         uint16_t vlan_id_outer;
3349 };
3350
3351 static void
3352 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3353                             __attribute__((unused)) struct cmdline *cl,
3354                             __attribute__((unused)) void *data)
3355 {
3356         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3357
3358         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3359 }
3360
3361 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3362         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3363                 tx_vlan, "tx_vlan");
3364 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3365         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3366                 set, "set");
3367 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3368         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3369                 port_id, UINT8);
3370 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3371         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3372                 vlan_id, UINT16);
3373 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3374         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3375                 vlan_id_outer, UINT16);
3376
3377 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3378         .f = cmd_tx_vlan_set_qinq_parsed,
3379         .data = NULL,
3380         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3381                 "Enable hardware insertion of double VLAN header "
3382                 "with given TAG Identifiers in packets sent on a port",
3383         .tokens = {
3384                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3385                 (void *)&cmd_tx_vlan_set_qinq_set,
3386                 (void *)&cmd_tx_vlan_set_qinq_portid,
3387                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3388                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3389                 NULL,
3390         },
3391 };
3392
3393 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3394 struct cmd_tx_vlan_set_pvid_result {
3395         cmdline_fixed_string_t tx_vlan;
3396         cmdline_fixed_string_t set;
3397         cmdline_fixed_string_t pvid;
3398         uint8_t port_id;
3399         uint16_t vlan_id;
3400         cmdline_fixed_string_t mode;
3401 };
3402
3403 static void
3404 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3405                             __attribute__((unused)) struct cmdline *cl,
3406                             __attribute__((unused)) void *data)
3407 {
3408         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3409
3410         if (strcmp(res->mode, "on") == 0)
3411                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3412         else
3413                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3414 }
3415
3416 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3417         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3418                                  tx_vlan, "tx_vlan");
3419 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3420         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3421                                  set, "set");
3422 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3423         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3424                                  pvid, "pvid");
3425 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3426         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3427                              port_id, UINT8);
3428 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3429         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3430                               vlan_id, UINT16);
3431 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3432         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3433                                  mode, "on#off");
3434
3435 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3436         .f = cmd_tx_vlan_set_pvid_parsed,
3437         .data = NULL,
3438         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3439         .tokens = {
3440                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3441                 (void *)&cmd_tx_vlan_set_pvid_set,
3442                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3443                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3444                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3445                 (void *)&cmd_tx_vlan_set_pvid_mode,
3446                 NULL,
3447         },
3448 };
3449
3450 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3451 struct cmd_tx_vlan_reset_result {
3452         cmdline_fixed_string_t tx_vlan;
3453         cmdline_fixed_string_t reset;
3454         uint8_t port_id;
3455 };
3456
3457 static void
3458 cmd_tx_vlan_reset_parsed(void *parsed_result,
3459                          __attribute__((unused)) struct cmdline *cl,
3460                          __attribute__((unused)) void *data)
3461 {
3462         struct cmd_tx_vlan_reset_result *res = parsed_result;
3463
3464         tx_vlan_reset(res->port_id);
3465 }
3466
3467 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3468         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3469                                  tx_vlan, "tx_vlan");
3470 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3471         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3472                                  reset, "reset");
3473 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3474         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3475                               port_id, UINT8);
3476
3477 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3478         .f = cmd_tx_vlan_reset_parsed,
3479         .data = NULL,
3480         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3481                 "VLAN header in packets sent on a port",
3482         .tokens = {
3483                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3484                 (void *)&cmd_tx_vlan_reset_reset,
3485                 (void *)&cmd_tx_vlan_reset_portid,
3486                 NULL,
3487         },
3488 };
3489
3490
3491 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3492 struct cmd_csum_result {
3493         cmdline_fixed_string_t csum;
3494         cmdline_fixed_string_t mode;
3495         cmdline_fixed_string_t proto;
3496         cmdline_fixed_string_t hwsw;
3497         uint8_t port_id;
3498 };
3499
3500 static void
3501 csum_show(int port_id)
3502 {
3503         struct rte_eth_dev_info dev_info;
3504         uint16_t ol_flags;
3505
3506         ol_flags = ports[port_id].tx_ol_flags;
3507         printf("Parse tunnel is %s\n",
3508                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3509         printf("IP checksum offload is %s\n",
3510                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3511         printf("UDP checksum offload is %s\n",
3512                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3513         printf("TCP checksum offload is %s\n",
3514                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3515         printf("SCTP checksum offload is %s\n",
3516                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3517         printf("Outer-Ip checksum offload is %s\n",
3518                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3519
3520         /* display warnings if configuration is not supported by the NIC */
3521         rte_eth_dev_info_get(port_id, &dev_info);
3522         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3523                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3524                 printf("Warning: hardware IP checksum enabled but not "
3525                         "supported by port %d\n", port_id);
3526         }
3527         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3528                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3529                 printf("Warning: hardware UDP checksum enabled but not "
3530                         "supported by port %d\n", port_id);
3531         }
3532         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3533                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3534                 printf("Warning: hardware TCP checksum enabled but not "
3535                         "supported by port %d\n", port_id);
3536         }
3537         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3538                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3539                 printf("Warning: hardware SCTP checksum enabled but not "
3540                         "supported by port %d\n", port_id);
3541         }
3542         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3543                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3544                 printf("Warning: hardware outer IP checksum enabled but not "
3545                         "supported by port %d\n", port_id);
3546         }
3547 }
3548
3549 static void
3550 cmd_csum_parsed(void *parsed_result,
3551                        __attribute__((unused)) struct cmdline *cl,
3552                        __attribute__((unused)) void *data)
3553 {
3554         struct cmd_csum_result *res = parsed_result;
3555         int hw = 0;
3556         uint16_t mask = 0;
3557
3558         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3559                 printf("invalid port %d\n", res->port_id);
3560                 return;
3561         }
3562
3563         if (!strcmp(res->mode, "set")) {
3564
3565                 if (!strcmp(res->hwsw, "hw"))
3566                         hw = 1;
3567
3568                 if (!strcmp(res->proto, "ip")) {
3569                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3570                 } else if (!strcmp(res->proto, "udp")) {
3571                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3572                 } else if (!strcmp(res->proto, "tcp")) {
3573                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3574                 } else if (!strcmp(res->proto, "sctp")) {
3575                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3576                 } else if (!strcmp(res->proto, "outer-ip")) {
3577                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3578                 }
3579
3580                 if (hw)
3581                         ports[res->port_id].tx_ol_flags |= mask;
3582                 else
3583                         ports[res->port_id].tx_ol_flags &= (~mask);
3584         }
3585         csum_show(res->port_id);
3586 }
3587
3588 cmdline_parse_token_string_t cmd_csum_csum =
3589         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3590                                 csum, "csum");
3591 cmdline_parse_token_string_t cmd_csum_mode =
3592         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3593                                 mode, "set");
3594 cmdline_parse_token_string_t cmd_csum_proto =
3595         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3596                                 proto, "ip#tcp#udp#sctp#outer-ip");
3597 cmdline_parse_token_string_t cmd_csum_hwsw =
3598         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3599                                 hwsw, "hw#sw");
3600 cmdline_parse_token_num_t cmd_csum_portid =
3601         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3602                                 port_id, UINT8);
3603
3604 cmdline_parse_inst_t cmd_csum_set = {
3605         .f = cmd_csum_parsed,
3606         .data = NULL,
3607         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3608                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3609                 "using csum forward engine",
3610         .tokens = {
3611                 (void *)&cmd_csum_csum,
3612                 (void *)&cmd_csum_mode,
3613                 (void *)&cmd_csum_proto,
3614                 (void *)&cmd_csum_hwsw,
3615                 (void *)&cmd_csum_portid,
3616                 NULL,
3617         },
3618 };
3619
3620 cmdline_parse_token_string_t cmd_csum_mode_show =
3621         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3622                                 mode, "show");
3623
3624 cmdline_parse_inst_t cmd_csum_show = {
3625         .f = cmd_csum_parsed,
3626         .data = NULL,
3627         .help_str = "csum show <port_id>: Show checksum offload configuration",
3628         .tokens = {
3629                 (void *)&cmd_csum_csum,
3630                 (void *)&cmd_csum_mode_show,
3631                 (void *)&cmd_csum_portid,
3632                 NULL,
3633         },
3634 };
3635
3636 /* Enable/disable tunnel parsing */
3637 struct cmd_csum_tunnel_result {
3638         cmdline_fixed_string_t csum;
3639         cmdline_fixed_string_t parse;
3640         cmdline_fixed_string_t onoff;
3641         uint8_t port_id;
3642 };
3643
3644 static void
3645 cmd_csum_tunnel_parsed(void *parsed_result,
3646                        __attribute__((unused)) struct cmdline *cl,
3647                        __attribute__((unused)) void *data)
3648 {
3649         struct cmd_csum_tunnel_result *res = parsed_result;
3650
3651         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3652                 return;
3653
3654         if (!strcmp(res->onoff, "on"))
3655                 ports[res->port_id].tx_ol_flags |=
3656                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3657         else
3658                 ports[res->port_id].tx_ol_flags &=
3659                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3660
3661         csum_show(res->port_id);
3662 }
3663
3664 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3665         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3666                                 csum, "csum");
3667 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3668         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3669                                 parse, "parse_tunnel");
3670 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3671         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3672                                 onoff, "on#off");
3673 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3674         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3675                                 port_id, UINT8);
3676
3677 cmdline_parse_inst_t cmd_csum_tunnel = {
3678         .f = cmd_csum_tunnel_parsed,
3679         .data = NULL,
3680         .help_str = "csum parse_tunnel on|off <port_id>: "
3681                 "Enable/Disable parsing of tunnels for csum engine",
3682         .tokens = {
3683                 (void *)&cmd_csum_tunnel_csum,
3684                 (void *)&cmd_csum_tunnel_parse,
3685                 (void *)&cmd_csum_tunnel_onoff,
3686                 (void *)&cmd_csum_tunnel_portid,
3687                 NULL,
3688         },
3689 };
3690
3691 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3692 struct cmd_tso_set_result {
3693         cmdline_fixed_string_t tso;
3694         cmdline_fixed_string_t mode;
3695         uint16_t tso_segsz;
3696         uint8_t port_id;
3697 };
3698
3699 static void
3700 cmd_tso_set_parsed(void *parsed_result,
3701                        __attribute__((unused)) struct cmdline *cl,
3702                        __attribute__((unused)) void *data)
3703 {
3704         struct cmd_tso_set_result *res = parsed_result;
3705         struct rte_eth_dev_info dev_info;
3706
3707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3708                 return;
3709
3710         if (!strcmp(res->mode, "set"))
3711                 ports[res->port_id].tso_segsz = res->tso_segsz;
3712
3713         if (ports[res->port_id].tso_segsz == 0)
3714                 printf("TSO for non-tunneled packets is disabled\n");
3715         else
3716                 printf("TSO segment size for non-tunneled packets is %d\n",
3717                         ports[res->port_id].tso_segsz);
3718
3719         /* display warnings if configuration is not supported by the NIC */
3720         rte_eth_dev_info_get(res->port_id, &dev_info);
3721         if ((ports[res->port_id].tso_segsz != 0) &&
3722                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3723                 printf("Warning: TSO enabled but not "
3724                         "supported by port %d\n", res->port_id);
3725         }
3726 }
3727
3728 cmdline_parse_token_string_t cmd_tso_set_tso =
3729         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3730                                 tso, "tso");
3731 cmdline_parse_token_string_t cmd_tso_set_mode =
3732         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3733                                 mode, "set");
3734 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3735         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3736                                 tso_segsz, UINT16);
3737 cmdline_parse_token_num_t cmd_tso_set_portid =
3738         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3739                                 port_id, UINT8);
3740
3741 cmdline_parse_inst_t cmd_tso_set = {
3742         .f = cmd_tso_set_parsed,
3743         .data = NULL,
3744         .help_str = "tso set <tso_segsz> <port_id>: "
3745                 "Set TSO segment size of non-tunneled packets for csum engine "
3746                 "(0 to disable)",
3747         .tokens = {
3748                 (void *)&cmd_tso_set_tso,
3749                 (void *)&cmd_tso_set_mode,
3750                 (void *)&cmd_tso_set_tso_segsz,
3751                 (void *)&cmd_tso_set_portid,
3752                 NULL,
3753         },
3754 };
3755
3756 cmdline_parse_token_string_t cmd_tso_show_mode =
3757         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3758                                 mode, "show");
3759
3760
3761 cmdline_parse_inst_t cmd_tso_show = {
3762         .f = cmd_tso_set_parsed,
3763         .data = NULL,
3764         .help_str = "tso show <port_id>: "
3765                 "Show TSO segment size of non-tunneled packets for csum engine",
3766         .tokens = {
3767                 (void *)&cmd_tso_set_tso,
3768                 (void *)&cmd_tso_show_mode,
3769                 (void *)&cmd_tso_set_portid,
3770                 NULL,
3771         },
3772 };
3773
3774 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3775 struct cmd_tunnel_tso_set_result {
3776         cmdline_fixed_string_t tso;
3777         cmdline_fixed_string_t mode;
3778         uint16_t tso_segsz;
3779         uint8_t port_id;
3780 };
3781
3782 static void
3783 check_tunnel_tso_nic_support(uint8_t port_id)
3784 {
3785         struct rte_eth_dev_info dev_info;
3786
3787         rte_eth_dev_info_get(port_id, &dev_info);
3788         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3789                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3790                        "supported by port %d\n", port_id);
3791         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3792                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3793                         "supported by port %d\n", port_id);
3794         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3795                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3796                        "supported by port %d\n", port_id);
3797         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3798                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3799                        "supported by port %d\n", port_id);
3800 }
3801
3802 static void
3803 cmd_tunnel_tso_set_parsed(void *parsed_result,
3804                           __attribute__((unused)) struct cmdline *cl,
3805                           __attribute__((unused)) void *data)
3806 {
3807         struct cmd_tunnel_tso_set_result *res = parsed_result;
3808
3809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3810                 return;
3811
3812         if (!strcmp(res->mode, "set"))
3813                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3814
3815         if (ports[res->port_id].tunnel_tso_segsz == 0)
3816                 printf("TSO for tunneled packets is disabled\n");
3817         else {
3818                 printf("TSO segment size for tunneled packets is %d\n",
3819                         ports[res->port_id].tunnel_tso_segsz);
3820
3821                 /* Below conditions are needed to make it work:
3822                  * (1) tunnel TSO is supported by the NIC;
3823                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3824                  * are recognized;
3825                  * (3) for tunneled pkts with outer L3 of IPv4,
3826                  * "csum set outer-ip" must be set to hw, because after tso,
3827                  * total_len of outer IP header is changed, and the checksum
3828                  * of outer IP header calculated by sw should be wrong; that
3829                  * is not necessary for IPv6 tunneled pkts because there's no
3830                  * checksum in IP header anymore.
3831                  */
3832                 check_tunnel_tso_nic_support(res->port_id);
3833
3834                 if (!(ports[res->port_id].tx_ol_flags &
3835                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3836                         printf("Warning: csum parse_tunnel must be set "
3837                                 "so that tunneled packets are recognized\n");
3838                 if (!(ports[res->port_id].tx_ol_flags &
3839                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3840                         printf("Warning: csum set outer-ip must be set to hw "
3841                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3842         }
3843 }
3844
3845 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3846         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3847                                 tso, "tunnel_tso");
3848 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3849         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3850                                 mode, "set");
3851 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3852         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3853                                 tso_segsz, UINT16);
3854 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3855         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3856                                 port_id, UINT8);
3857
3858 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3859         .f = cmd_tunnel_tso_set_parsed,
3860         .data = NULL,
3861         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3862                 "Set TSO segment size of tunneled packets for csum engine "
3863                 "(0 to disable)",
3864         .tokens = {
3865                 (void *)&cmd_tunnel_tso_set_tso,
3866                 (void *)&cmd_tunnel_tso_set_mode,
3867                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3868                 (void *)&cmd_tunnel_tso_set_portid,
3869                 NULL,
3870         },
3871 };
3872
3873 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3874         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3875                                 mode, "show");
3876
3877
3878 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3879         .f = cmd_tunnel_tso_set_parsed,
3880         .data = NULL,
3881         .help_str = "tunnel_tso show <port_id> "
3882                 "Show TSO segment size of tunneled packets for csum engine",
3883         .tokens = {
3884                 (void *)&cmd_tunnel_tso_set_tso,
3885                 (void *)&cmd_tunnel_tso_show_mode,
3886                 (void *)&cmd_tunnel_tso_set_portid,
3887                 NULL,
3888         },
3889 };
3890
3891 /* *** SET GRO FOR A PORT *** */
3892 struct cmd_gro_enable_result {
3893         cmdline_fixed_string_t cmd_set;
3894         cmdline_fixed_string_t cmd_port;
3895         cmdline_fixed_string_t cmd_keyword;
3896         cmdline_fixed_string_t cmd_onoff;
3897         portid_t cmd_pid;
3898 };
3899
3900 static void
3901 cmd_gro_enable_parsed(void *parsed_result,
3902                 __attribute__((unused)) struct cmdline *cl,
3903                 __attribute__((unused)) void *data)
3904 {
3905         struct cmd_gro_enable_result *res;
3906
3907         res = parsed_result;
3908         if (!strcmp(res->cmd_keyword, "gro"))
3909                 setup_gro(res->cmd_onoff, res->cmd_pid);
3910 }
3911
3912 cmdline_parse_token_string_t cmd_gro_enable_set =
3913         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3914                         cmd_set, "set");
3915 cmdline_parse_token_string_t cmd_gro_enable_port =
3916         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3917                         cmd_keyword, "port");
3918 cmdline_parse_token_num_t cmd_gro_enable_pid =
3919         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3920                         cmd_pid, UINT16);
3921 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3922         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3923                         cmd_keyword, "gro");
3924 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3925         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3926                         cmd_onoff, "on#off");
3927
3928 cmdline_parse_inst_t cmd_gro_enable = {
3929         .f = cmd_gro_enable_parsed,
3930         .data = NULL,
3931         .help_str = "set port <port_id> gro on|off",
3932         .tokens = {
3933                 (void *)&cmd_gro_enable_set,
3934                 (void *)&cmd_gro_enable_port,
3935                 (void *)&cmd_gro_enable_pid,
3936                 (void *)&cmd_gro_enable_keyword,
3937                 (void *)&cmd_gro_enable_onoff,
3938                 NULL,
3939         },
3940 };
3941
3942 /* *** DISPLAY GRO CONFIGURATION *** */
3943 struct cmd_gro_show_result {
3944         cmdline_fixed_string_t cmd_show;
3945         cmdline_fixed_string_t cmd_port;
3946         cmdline_fixed_string_t cmd_keyword;
3947         portid_t cmd_pid;
3948 };
3949
3950 static void
3951 cmd_gro_show_parsed(void *parsed_result,
3952                 __attribute__((unused)) struct cmdline *cl,
3953                 __attribute__((unused)) void *data)
3954 {
3955         struct cmd_gro_show_result *res;
3956
3957         res = parsed_result;
3958         if (!strcmp(res->cmd_keyword, "gro"))
3959                 show_gro(res->cmd_pid);
3960 }
3961
3962 cmdline_parse_token_string_t cmd_gro_show_show =
3963         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3964                         cmd_show, "show");
3965 cmdline_parse_token_string_t cmd_gro_show_port =
3966         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3967                         cmd_port, "port");
3968 cmdline_parse_token_num_t cmd_gro_show_pid =
3969         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3970                         cmd_pid, UINT16);
3971 cmdline_parse_token_string_t cmd_gro_show_keyword =
3972         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3973                         cmd_keyword, "gro");
3974
3975 cmdline_parse_inst_t cmd_gro_show = {
3976         .f = cmd_gro_show_parsed,
3977         .data = NULL,
3978         .help_str = "show port <port_id> gro",
3979         .tokens = {
3980                 (void *)&cmd_gro_show_show,
3981                 (void *)&cmd_gro_show_port,
3982                 (void *)&cmd_gro_show_pid,
3983                 (void *)&cmd_gro_show_keyword,
3984                 NULL,
3985         },
3986 };
3987
3988 /* *** SET FLUSH CYCLES FOR GRO *** */
3989 struct cmd_gro_flush_result {
3990         cmdline_fixed_string_t cmd_set;
3991         cmdline_fixed_string_t cmd_keyword;
3992         cmdline_fixed_string_t cmd_flush;
3993         uint8_t cmd_cycles;
3994 };
3995
3996 static void
3997 cmd_gro_flush_parsed(void *parsed_result,
3998                 __attribute__((unused)) struct cmdline *cl,
3999                 __attribute__((unused)) void *data)
4000 {
4001         struct cmd_gro_flush_result *res;
4002
4003         res = parsed_result;
4004         if ((!strcmp(res->cmd_keyword, "gro")) &&
4005                         (!strcmp(res->cmd_flush, "flush")))
4006                 setup_gro_flush_cycles(res->cmd_cycles);
4007 }
4008
4009 cmdline_parse_token_string_t cmd_gro_flush_set =
4010         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4011                         cmd_set, "set");
4012 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4013         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4014                         cmd_keyword, "gro");
4015 cmdline_parse_token_string_t cmd_gro_flush_flush =
4016         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4017                         cmd_flush, "flush");
4018 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4019         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4020                         cmd_cycles, UINT8);
4021
4022 cmdline_parse_inst_t cmd_gro_flush = {
4023         .f = cmd_gro_flush_parsed,
4024         .data = NULL,
4025         .help_str = "set gro flush <cycles>",
4026         .tokens = {
4027                 (void *)&cmd_gro_flush_set,
4028                 (void *)&cmd_gro_flush_keyword,
4029                 (void *)&cmd_gro_flush_flush,
4030                 (void *)&cmd_gro_flush_cycles,
4031                 NULL,
4032         },
4033 };
4034
4035 /* *** ENABLE/DISABLE GSO *** */
4036 struct cmd_gso_enable_result {
4037         cmdline_fixed_string_t cmd_set;
4038         cmdline_fixed_string_t cmd_port;
4039         cmdline_fixed_string_t cmd_keyword;
4040         cmdline_fixed_string_t cmd_mode;
4041         portid_t cmd_pid;
4042 };
4043
4044 static void
4045 cmd_gso_enable_parsed(void *parsed_result,
4046                 __attribute__((unused)) struct cmdline *cl,
4047                 __attribute__((unused)) void *data)
4048 {
4049         struct cmd_gso_enable_result *res;
4050
4051         res = parsed_result;
4052         if (!strcmp(res->cmd_keyword, "gso"))
4053                 setup_gso(res->cmd_mode, res->cmd_pid);
4054 }
4055
4056 cmdline_parse_token_string_t cmd_gso_enable_set =
4057         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4058                         cmd_set, "set");
4059 cmdline_parse_token_string_t cmd_gso_enable_port =
4060         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4061                         cmd_port, "port");
4062 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4063         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4064                         cmd_keyword, "gso");
4065 cmdline_parse_token_string_t cmd_gso_enable_mode =
4066         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4067                         cmd_mode, "on#off");
4068 cmdline_parse_token_num_t cmd_gso_enable_pid =
4069         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4070                         cmd_pid, UINT16);
4071
4072 cmdline_parse_inst_t cmd_gso_enable = {
4073         .f = cmd_gso_enable_parsed,
4074         .data = NULL,
4075         .help_str = "set port <port_id> gso on|off",
4076         .tokens = {
4077                 (void *)&cmd_gso_enable_set,
4078                 (void *)&cmd_gso_enable_port,
4079                 (void *)&cmd_gso_enable_pid,
4080                 (void *)&cmd_gso_enable_keyword,
4081                 (void *)&cmd_gso_enable_mode,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4087 struct cmd_gso_size_result {
4088         cmdline_fixed_string_t cmd_set;
4089         cmdline_fixed_string_t cmd_keyword;
4090         cmdline_fixed_string_t cmd_segsz;
4091         uint16_t cmd_size;
4092 };
4093
4094 static void
4095 cmd_gso_size_parsed(void *parsed_result,
4096                        __attribute__((unused)) struct cmdline *cl,
4097                        __attribute__((unused)) void *data)
4098 {
4099         struct cmd_gso_size_result *res = parsed_result;
4100
4101         if (test_done == 0) {
4102                 printf("Before setting GSO segsz, please first"
4103                                 " stop fowarding\n");
4104                 return;
4105         }
4106
4107         if (!strcmp(res->cmd_keyword, "gso") &&
4108                         !strcmp(res->cmd_segsz, "segsz")) {
4109                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4110                         printf("gso_size should be larger than %zu."
4111                                         " Please input a legal value\n",
4112                                         RTE_GSO_SEG_SIZE_MIN);
4113                 else
4114                         gso_max_segment_size = res->cmd_size;
4115         }
4116 }
4117
4118 cmdline_parse_token_string_t cmd_gso_size_set =
4119         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4120                                 cmd_set, "set");
4121 cmdline_parse_token_string_t cmd_gso_size_keyword =
4122         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4123                                 cmd_keyword, "gso");
4124 cmdline_parse_token_string_t cmd_gso_size_segsz =
4125         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4126                                 cmd_segsz, "segsz");
4127 cmdline_parse_token_num_t cmd_gso_size_size =
4128         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4129                                 cmd_size, UINT16);
4130
4131 cmdline_parse_inst_t cmd_gso_size = {
4132         .f = cmd_gso_size_parsed,
4133         .data = NULL,
4134         .help_str = "set gso segsz <length>",
4135         .tokens = {
4136                 (void *)&cmd_gso_size_set,
4137                 (void *)&cmd_gso_size_keyword,
4138                 (void *)&cmd_gso_size_segsz,
4139                 (void *)&cmd_gso_size_size,
4140                 NULL,
4141         },
4142 };
4143
4144 /* *** SHOW GSO CONFIGURATION *** */
4145 struct cmd_gso_show_result {
4146         cmdline_fixed_string_t cmd_show;
4147         cmdline_fixed_string_t cmd_port;
4148         cmdline_fixed_string_t cmd_keyword;
4149         portid_t cmd_pid;
4150 };
4151
4152 static void
4153 cmd_gso_show_parsed(void *parsed_result,
4154                        __attribute__((unused)) struct cmdline *cl,
4155                        __attribute__((unused)) void *data)
4156 {
4157         struct cmd_gso_show_result *res = parsed_result;
4158
4159         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4160                 printf("invalid port id %u\n", res->cmd_pid);
4161                 return;
4162         }
4163         if (!strcmp(res->cmd_keyword, "gso")) {
4164                 if (gso_ports[res->cmd_pid].enable) {
4165                         printf("Max GSO'd packet size: %uB\n"
4166                                         "Supported GSO types: TCP/IPv4, "
4167                                         "VxLAN with inner TCP/IPv4 packet, "
4168                                         "GRE with inner TCP/IPv4  packet\n",
4169                                         gso_max_segment_size);
4170                 } else
4171                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4172         }
4173 }
4174
4175 cmdline_parse_token_string_t cmd_gso_show_show =
4176 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4177                 cmd_show, "show");
4178 cmdline_parse_token_string_t cmd_gso_show_port =
4179 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4180                 cmd_port, "port");
4181 cmdline_parse_token_string_t cmd_gso_show_keyword =
4182         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4183                                 cmd_keyword, "gso");
4184 cmdline_parse_token_num_t cmd_gso_show_pid =
4185         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4186                                 cmd_pid, UINT16);
4187
4188 cmdline_parse_inst_t cmd_gso_show = {
4189         .f = cmd_gso_show_parsed,
4190         .data = NULL,
4191         .help_str = "show port <port_id> gso",
4192         .tokens = {
4193                 (void *)&cmd_gso_show_show,
4194                 (void *)&cmd_gso_show_port,
4195                 (void *)&cmd_gso_show_pid,
4196                 (void *)&cmd_gso_show_keyword,
4197                 NULL,
4198         },
4199 };
4200
4201 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4202 struct cmd_set_flush_rx {
4203         cmdline_fixed_string_t set;
4204         cmdline_fixed_string_t flush_rx;
4205         cmdline_fixed_string_t mode;
4206 };
4207
4208 static void
4209 cmd_set_flush_rx_parsed(void *parsed_result,
4210                 __attribute__((unused)) struct cmdline *cl,
4211                 __attribute__((unused)) void *data)
4212 {
4213         struct cmd_set_flush_rx *res = parsed_result;
4214         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4215 }
4216
4217 cmdline_parse_token_string_t cmd_setflushrx_set =
4218         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4219                         set, "set");
4220 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4221         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4222                         flush_rx, "flush_rx");
4223 cmdline_parse_token_string_t cmd_setflushrx_mode =
4224         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4225                         mode, "on#off");
4226
4227
4228 cmdline_parse_inst_t cmd_set_flush_rx = {
4229         .f = cmd_set_flush_rx_parsed,
4230         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4231         .data = NULL,
4232         .tokens = {
4233                 (void *)&cmd_setflushrx_set,
4234                 (void *)&cmd_setflushrx_flush_rx,
4235                 (void *)&cmd_setflushrx_mode,
4236                 NULL,
4237         },
4238 };
4239
4240 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4241 struct cmd_set_link_check {
4242         cmdline_fixed_string_t set;
4243         cmdline_fixed_string_t link_check;
4244         cmdline_fixed_string_t mode;
4245 };
4246
4247 static void
4248 cmd_set_link_check_parsed(void *parsed_result,
4249                 __attribute__((unused)) struct cmdline *cl,
4250                 __attribute__((unused)) void *data)
4251 {
4252         struct cmd_set_link_check *res = parsed_result;
4253         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4254 }
4255
4256 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4257         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4258                         set, "set");
4259 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4260         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4261                         link_check, "link_check");
4262 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4263         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4264                         mode, "on#off");
4265
4266
4267 cmdline_parse_inst_t cmd_set_link_check = {
4268         .f = cmd_set_link_check_parsed,
4269         .help_str = "set link_check on|off: Enable/Disable link status check "
4270                     "when starting/stopping a port",
4271         .data = NULL,
4272         .tokens = {
4273                 (void *)&cmd_setlinkcheck_set,
4274                 (void *)&cmd_setlinkcheck_link_check,
4275                 (void *)&cmd_setlinkcheck_mode,
4276                 NULL,
4277         },
4278 };
4279
4280 /* *** SET NIC BYPASS MODE *** */
4281 struct cmd_set_bypass_mode_result {
4282         cmdline_fixed_string_t set;
4283         cmdline_fixed_string_t bypass;
4284         cmdline_fixed_string_t mode;
4285         cmdline_fixed_string_t value;
4286         uint8_t port_id;
4287 };
4288
4289 static void
4290 cmd_set_bypass_mode_parsed(void *parsed_result,
4291                 __attribute__((unused)) struct cmdline *cl,
4292                 __attribute__((unused)) void *data)
4293 {
4294         struct cmd_set_bypass_mode_result *res = parsed_result;
4295         portid_t port_id = res->port_id;
4296         int32_t rc = -EINVAL;
4297
4298 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4299         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4300
4301         if (!strcmp(res->value, "bypass"))
4302                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4303         else if (!strcmp(res->value, "isolate"))
4304                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4305         else
4306                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4307
4308         /* Set the bypass mode for the relevant port. */
4309         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4310 #endif
4311         if (rc != 0)
4312                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4313 }
4314
4315 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4316         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4317                         set, "set");
4318 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4319         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4320                         bypass, "bypass");
4321 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4322         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4323                         mode, "mode");
4324 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4325         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4326                         value, "normal#bypass#isolate");
4327 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4328         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4329                                 port_id, UINT8);
4330
4331 cmdline_parse_inst_t cmd_set_bypass_mode = {
4332         .f = cmd_set_bypass_mode_parsed,
4333         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4334                     "Set the NIC bypass mode for port_id",
4335         .data = NULL,
4336         .tokens = {
4337                 (void *)&cmd_setbypass_mode_set,
4338                 (void *)&cmd_setbypass_mode_bypass,
4339                 (void *)&cmd_setbypass_mode_mode,
4340                 (void *)&cmd_setbypass_mode_value,
4341                 (void *)&cmd_setbypass_mode_port,
4342                 NULL,
4343         },
4344 };
4345
4346 /* *** SET NIC BYPASS EVENT *** */
4347 struct cmd_set_bypass_event_result {
4348         cmdline_fixed_string_t set;
4349         cmdline_fixed_string_t bypass;
4350         cmdline_fixed_string_t event;
4351         cmdline_fixed_string_t event_value;
4352         cmdline_fixed_string_t mode;
4353         cmdline_fixed_string_t mode_value;
4354         uint8_t port_id;
4355 };
4356
4357 static void
4358 cmd_set_bypass_event_parsed(void *parsed_result,
4359                 __attribute__((unused)) struct cmdline *cl,
4360                 __attribute__((unused)) void *data)
4361 {
4362         int32_t rc = -EINVAL;
4363         struct cmd_set_bypass_event_result *res = parsed_result;
4364         portid_t port_id = res->port_id;
4365
4366 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4367         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4368         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4369
4370         if (!strcmp(res->event_value, "timeout"))
4371                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4372         else if (!strcmp(res->event_value, "os_on"))
4373                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4374         else if (!strcmp(res->event_value, "os_off"))
4375                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4376         else if (!strcmp(res->event_value, "power_on"))
4377                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4378         else if (!strcmp(res->event_value, "power_off"))
4379                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4380         else
4381                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4382
4383         if (!strcmp(res->mode_value, "bypass"))
4384                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4385         else if (!strcmp(res->mode_value, "isolate"))
4386                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4387         else
4388                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4389
4390         /* Set the watchdog timeout. */
4391         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4392
4393                 rc = -EINVAL;
4394                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4395                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4396                                                            bypass_timeout);
4397                 }
4398                 if (rc != 0) {
4399                         printf("Failed to set timeout value %u "
4400                         "for port %d, errto code: %d.\n",
4401                         bypass_timeout, port_id, rc);
4402                 }
4403         }
4404
4405         /* Set the bypass event to transition to bypass mode. */
4406         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4407                                               bypass_mode);
4408 #endif
4409
4410         if (rc != 0)
4411                 printf("\t Failed to set bypass event for port = %d.\n",
4412                        port_id);
4413 }
4414
4415 cmdline_parse_token_string_t cmd_setbypass_event_set =
4416         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4417                         set, "set");
4418 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4419         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4420                         bypass, "bypass");
4421 cmdline_parse_token_string_t cmd_setbypass_event_event =
4422         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4423                         event, "event");
4424 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4425         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4426                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4427 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4428         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4429                         mode, "mode");
4430 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4431         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4432                         mode_value, "normal#bypass#isolate");
4433 cmdline_parse_token_num_t cmd_setbypass_event_port =
4434         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4435                                 port_id, UINT8);
4436
4437 cmdline_parse_inst_t cmd_set_bypass_event = {
4438         .f = cmd_set_bypass_event_parsed,
4439         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4440                 "power_off mode normal|bypass|isolate <port_id>: "
4441                 "Set the NIC bypass event mode for port_id",
4442         .data = NULL,
4443         .tokens = {
4444                 (void *)&cmd_setbypass_event_set,
4445                 (void *)&cmd_setbypass_event_bypass,
4446                 (void *)&cmd_setbypass_event_event,
4447                 (void *)&cmd_setbypass_event_event_value,
4448                 (void *)&cmd_setbypass_event_mode,
4449                 (void *)&cmd_setbypass_event_mode_value,
4450                 (void *)&cmd_setbypass_event_port,
4451                 NULL,
4452         },
4453 };
4454
4455
4456 /* *** SET NIC BYPASS TIMEOUT *** */
4457 struct cmd_set_bypass_timeout_result {
4458         cmdline_fixed_string_t set;
4459         cmdline_fixed_string_t bypass;
4460         cmdline_fixed_string_t timeout;
4461         cmdline_fixed_string_t value;
4462 };
4463
4464 static void
4465 cmd_set_bypass_timeout_parsed(void *parsed_result,
4466                 __attribute__((unused)) struct cmdline *cl,
4467                 __attribute__((unused)) void *data)
4468 {
4469         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4470
4471 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4472         if (!strcmp(res->value, "1.5"))
4473                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4474         else if (!strcmp(res->value, "2"))
4475                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4476         else if (!strcmp(res->value, "3"))
4477                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4478         else if (!strcmp(res->value, "4"))
4479                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4480         else if (!strcmp(res->value, "8"))
4481                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4482         else if (!strcmp(res->value, "16"))
4483                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4484         else if (!strcmp(res->value, "32"))
4485                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4486         else
4487                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4488 #endif
4489 }
4490
4491 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4492         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4493                         set, "set");
4494 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4495         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4496                         bypass, "bypass");
4497 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4498         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4499                         timeout, "timeout");
4500 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4501         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4502                         value, "0#1.5#2#3#4#8#16#32");
4503
4504 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4505         .f = cmd_set_bypass_timeout_parsed,
4506         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4507                 "Set the NIC bypass watchdog timeout in seconds",
4508         .data = NULL,
4509         .tokens = {
4510                 (void *)&cmd_setbypass_timeout_set,
4511                 (void *)&cmd_setbypass_timeout_bypass,
4512                 (void *)&cmd_setbypass_timeout_timeout,
4513                 (void *)&cmd_setbypass_timeout_value,
4514                 NULL,
4515         },
4516 };
4517
4518 /* *** SHOW NIC BYPASS MODE *** */
4519 struct cmd_show_bypass_config_result {
4520         cmdline_fixed_string_t show;
4521         cmdline_fixed_string_t bypass;
4522         cmdline_fixed_string_t config;
4523         uint8_t port_id;
4524 };
4525
4526 static void
4527 cmd_show_bypass_config_parsed(void *parsed_result,
4528                 __attribute__((unused)) struct cmdline *cl,
4529                 __attribute__((unused)) void *data)
4530 {
4531         struct cmd_show_bypass_config_result *res = parsed_result;
4532         portid_t port_id = res->port_id;
4533         int rc = -EINVAL;
4534 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4535         uint32_t event_mode;
4536         uint32_t bypass_mode;
4537         uint32_t timeout = bypass_timeout;
4538         int i;
4539
4540         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4541                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4542         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4543                 {"UNKNOWN", "normal", "bypass", "isolate"};
4544         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4545                 "NONE",
4546                 "OS/board on",
4547                 "power supply on",
4548                 "OS/board off",
4549                 "power supply off",
4550                 "timeout"};
4551         int num_events = (sizeof events) / (sizeof events[0]);
4552
4553         /* Display the bypass mode.*/
4554         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4555                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4556                 return;
4557         }
4558         else {
4559                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4560                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4561
4562                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4563         }
4564
4565         /* Display the bypass timeout.*/
4566         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4567                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4568
4569         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4570
4571         /* Display the bypass events and associated modes. */
4572         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4573
4574                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4575                         printf("\tFailed to get bypass mode for event = %s\n",
4576                                 events[i]);
4577                 } else {
4578                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4579                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4580
4581                         printf("\tbypass event: %-16s = %s\n", events[i],
4582                                 modes[event_mode]);
4583                 }
4584         }
4585 #endif
4586         if (rc != 0)
4587                 printf("\tFailed to get bypass configuration for port = %d\n",
4588                        port_id);
4589 }
4590
4591 cmdline_parse_token_string_t cmd_showbypass_config_show =
4592         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4593                         show, "show");
4594 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4595         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4596                         bypass, "bypass");
4597 cmdline_parse_token_string_t cmd_showbypass_config_config =
4598         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4599                         config, "config");
4600 cmdline_parse_token_num_t cmd_showbypass_config_port =
4601         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4602                                 port_id, UINT8);
4603
4604 cmdline_parse_inst_t cmd_show_bypass_config = {
4605         .f = cmd_show_bypass_config_parsed,
4606         .help_str = "show bypass config <port_id>: "
4607                     "Show the NIC bypass config for port_id",
4608         .data = NULL,
4609         .tokens = {
4610                 (void *)&cmd_showbypass_config_show,
4611                 (void *)&cmd_showbypass_config_bypass,
4612                 (void *)&cmd_showbypass_config_config,
4613                 (void *)&cmd_showbypass_config_port,
4614                 NULL,
4615         },
4616 };
4617
4618 #ifdef RTE_LIBRTE_PMD_BOND
4619 /* *** SET BONDING MODE *** */
4620 struct cmd_set_bonding_mode_result {
4621         cmdline_fixed_string_t set;
4622         cmdline_fixed_string_t bonding;
4623         cmdline_fixed_string_t mode;
4624         uint8_t value;
4625         uint8_t port_id;
4626 };
4627
4628 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4629                 __attribute__((unused))  struct cmdline *cl,
4630                 __attribute__((unused)) void *data)
4631 {
4632         struct cmd_set_bonding_mode_result *res = parsed_result;
4633         portid_t port_id = res->port_id;
4634
4635         /* Set the bonding mode for the relevant port. */
4636         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4637                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4638 }
4639
4640 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4641 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4642                 set, "set");
4643 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4644 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4645                 bonding, "bonding");
4646 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4647 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4648                 mode, "mode");
4649 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4650 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4651                 value, UINT8);
4652 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4653 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4654                 port_id, UINT8);
4655
4656 cmdline_parse_inst_t cmd_set_bonding_mode = {
4657                 .f = cmd_set_bonding_mode_parsed,
4658                 .help_str = "set bonding mode <mode_value> <port_id>: "
4659                         "Set the bonding mode for port_id",
4660                 .data = NULL,
4661                 .tokens = {
4662                                 (void *) &cmd_setbonding_mode_set,
4663                                 (void *) &cmd_setbonding_mode_bonding,
4664                                 (void *) &cmd_setbonding_mode_mode,
4665                                 (void *) &cmd_setbonding_mode_value,
4666                                 (void *) &cmd_setbonding_mode_port,
4667                                 NULL
4668                 }
4669 };
4670
4671 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4672 struct cmd_set_bonding_lacp_dedicated_queues_result {
4673         cmdline_fixed_string_t set;
4674         cmdline_fixed_string_t bonding;
4675         cmdline_fixed_string_t lacp;
4676         cmdline_fixed_string_t dedicated_queues;
4677         uint8_t port_id;
4678         cmdline_fixed_string_t mode;
4679 };
4680
4681 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4682                 __attribute__((unused))  struct cmdline *cl,
4683                 __attribute__((unused)) void *data)
4684 {
4685         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4686         portid_t port_id = res->port_id;
4687         struct rte_port *port;
4688
4689         port = &ports[port_id];
4690
4691         /** Check if the port is not started **/
4692         if (port->port_status != RTE_PORT_STOPPED) {
4693                 printf("Please stop port %d first\n", port_id);
4694                 return;
4695         }
4696
4697         if (!strcmp(res->mode, "enable")) {
4698                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4699                         printf("Dedicate queues for LACP control packets"
4700                                         " enabled\n");
4701                 else
4702                         printf("Enabling dedicate queues for LACP control "
4703                                         "packets on port %d failed\n", port_id);
4704         } else if (!strcmp(res->mode, "disable")) {
4705                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4706                         printf("Dedicated queues for LACP control packets "
4707                                         "disabled\n");
4708                 else
4709                         printf("Disabling dedicated queues for LACP control "
4710                                         "traffic on port %d failed\n", port_id);
4711         }
4712 }
4713
4714 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4715 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4716                 set, "set");
4717 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4718 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4719                 bonding, "bonding");
4720 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4721 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4722                 lacp, "lacp");
4723 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4724 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4725                 dedicated_queues, "dedicated_queues");
4726 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4727 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4728                 port_id, UINT8);
4729 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4730 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4731                 mode, "enable#disable");
4732
4733 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4734                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4735                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4736                         "enable|disable: "
4737                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4738                 .data = NULL,
4739                 .tokens = {
4740                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4741                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4742                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4743                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4744                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4745                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4746                         NULL
4747                 }
4748 };
4749
4750 /* *** SET BALANCE XMIT POLICY *** */
4751 struct cmd_set_bonding_balance_xmit_policy_result {
4752         cmdline_fixed_string_t set;
4753         cmdline_fixed_string_t bonding;
4754         cmdline_fixed_string_t balance_xmit_policy;
4755         uint8_t port_id;
4756         cmdline_fixed_string_t policy;
4757 };
4758
4759 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4760                 __attribute__((unused))  struct cmdline *cl,
4761                 __attribute__((unused)) void *data)
4762 {
4763         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4764         portid_t port_id = res->port_id;
4765         uint8_t policy;
4766
4767         if (!strcmp(res->policy, "l2")) {
4768                 policy = BALANCE_XMIT_POLICY_LAYER2;
4769         } else if (!strcmp(res->policy, "l23")) {
4770                 policy = BALANCE_XMIT_POLICY_LAYER23;
4771         } else if (!strcmp(res->policy, "l34")) {
4772                 policy = BALANCE_XMIT_POLICY_LAYER34;
4773         } else {
4774                 printf("\t Invalid xmit policy selection");
4775                 return;
4776         }
4777
4778         /* Set the bonding mode for the relevant port. */
4779         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4780                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4781                                 port_id);
4782         }
4783 }
4784
4785 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4786 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4787                 set, "set");
4788 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4789 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4790                 bonding, "bonding");
4791 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4792 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4793                 balance_xmit_policy, "balance_xmit_policy");
4794 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4795 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4796                 port_id, UINT8);
4797 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4798 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4799                 policy, "l2#l23#l34");
4800
4801 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4802                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4803                 .help_str = "set bonding balance_xmit_policy <port_id> "
4804                         "l2|l23|l34: "
4805                         "Set the bonding balance_xmit_policy for port_id",
4806                 .data = NULL,
4807                 .tokens = {
4808                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4809                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4810                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4811                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4812                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4813                                 NULL
4814                 }
4815 };
4816
4817 /* *** SHOW NIC BONDING CONFIGURATION *** */
4818 struct cmd_show_bonding_config_result {
4819         cmdline_fixed_string_t show;
4820         cmdline_fixed_string_t bonding;
4821         cmdline_fixed_string_t config;
4822         portid_t port_id;
4823 };
4824
4825 static void cmd_show_bonding_config_parsed(void *parsed_result,
4826                 __attribute__((unused))  struct cmdline *cl,
4827                 __attribute__((unused)) void *data)
4828 {
4829         struct cmd_show_bonding_config_result *res = parsed_result;
4830         int bonding_mode, agg_mode;
4831         portid_t slaves[RTE_MAX_ETHPORTS];
4832         int num_slaves, num_active_slaves;
4833         int primary_id;
4834         int i;
4835         portid_t port_id = res->port_id;
4836
4837         /* Display the bonding mode.*/
4838         bonding_mode = rte_eth_bond_mode_get(port_id);
4839         if (bonding_mode < 0) {
4840                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4841                 return;
4842         } else
4843                 printf("\tBonding mode: %d\n", bonding_mode);
4844
4845         if (bonding_mode == BONDING_MODE_BALANCE) {
4846                 int balance_xmit_policy;
4847
4848                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4849                 if (balance_xmit_policy < 0) {
4850                         printf("\tFailed to get balance xmit policy for port = %d\n",
4851                                         port_id);
4852                         return;
4853                 } else {
4854                         printf("\tBalance Xmit Policy: ");
4855
4856                         switch (balance_xmit_policy) {
4857                         case BALANCE_XMIT_POLICY_LAYER2:
4858                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4859                                 break;
4860                         case BALANCE_XMIT_POLICY_LAYER23:
4861                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4862                                 break;
4863                         case BALANCE_XMIT_POLICY_LAYER34:
4864                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4865                                 break;
4866                         }
4867                         printf("\n");
4868                 }
4869         }
4870
4871         if (bonding_mode == BONDING_MODE_8023AD) {
4872                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4873                 printf("\tIEEE802.3AD Aggregator Mode: ");
4874                 switch (agg_mode) {
4875                 case AGG_BANDWIDTH:
4876                         printf("bandwidth");
4877                         break;
4878                 case AGG_STABLE:
4879                         printf("stable");
4880                         break;
4881                 case AGG_COUNT:
4882                         printf("count");
4883                         break;
4884                 }
4885                 printf("\n");
4886         }
4887
4888         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4889
4890         if (num_slaves < 0) {
4891                 printf("\tFailed to get slave list for port = %d\n", port_id);
4892                 return;
4893         }
4894         if (num_slaves > 0) {
4895                 printf("\tSlaves (%d): [", num_slaves);
4896                 for (i = 0; i < num_slaves - 1; i++)
4897                         printf("%d ", slaves[i]);
4898
4899                 printf("%d]\n", slaves[num_slaves - 1]);
4900         } else {
4901                 printf("\tSlaves: []\n");
4902
4903         }
4904
4905         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4906                         RTE_MAX_ETHPORTS);
4907
4908         if (num_active_slaves < 0) {
4909                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4910                 return;
4911         }
4912         if (num_active_slaves > 0) {
4913                 printf("\tActive Slaves (%d): [", num_active_slaves);
4914                 for (i = 0; i < num_active_slaves - 1; i++)
4915                         printf("%d ", slaves[i]);
4916
4917                 printf("%d]\n", slaves[num_active_slaves - 1]);
4918
4919         } else {
4920                 printf("\tActive Slaves: []\n");
4921
4922         }
4923
4924         primary_id = rte_eth_bond_primary_get(port_id);
4925         if (primary_id < 0) {
4926                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4927                 return;
4928         } else
4929                 printf("\tPrimary: [%d]\n", primary_id);
4930
4931 }
4932
4933 cmdline_parse_token_string_t cmd_showbonding_config_show =
4934 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4935                 show, "show");
4936 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4937 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4938                 bonding, "bonding");
4939 cmdline_parse_token_string_t cmd_showbonding_config_config =
4940 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4941                 config, "config");
4942 cmdline_parse_token_num_t cmd_showbonding_config_port =
4943 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4944                 port_id, UINT8);
4945
4946 cmdline_parse_inst_t cmd_show_bonding_config = {
4947                 .f = cmd_show_bonding_config_parsed,
4948                 .help_str = "show bonding config <port_id>: "
4949                         "Show the bonding config for port_id",
4950                 .data = NULL,
4951                 .tokens = {
4952                                 (void *)&cmd_showbonding_config_show,
4953                                 (void *)&cmd_showbonding_config_bonding,
4954                                 (void *)&cmd_showbonding_config_config,
4955                                 (void *)&cmd_showbonding_config_port,
4956                                 NULL
4957                 }
4958 };
4959
4960 /* *** SET BONDING PRIMARY *** */
4961 struct cmd_set_bonding_primary_result {
4962         cmdline_fixed_string_t set;
4963         cmdline_fixed_string_t bonding;
4964         cmdline_fixed_string_t primary;
4965         uint8_t slave_id;
4966         uint8_t port_id;
4967 };
4968
4969 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4970                 __attribute__((unused))  struct cmdline *cl,
4971                 __attribute__((unused)) void *data)
4972 {
4973         struct cmd_set_bonding_primary_result *res = parsed_result;
4974         portid_t master_port_id = res->port_id;
4975         portid_t slave_port_id = res->slave_id;
4976
4977         /* Set the primary slave for a bonded device. */
4978         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4979                 printf("\t Failed to set primary slave for port = %d.\n",
4980                                 master_port_id);
4981                 return;
4982         }
4983         init_port_config();
4984 }
4985
4986 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4987 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4988                 set, "set");
4989 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4990 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4991                 bonding, "bonding");
4992 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4993 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4994                 primary, "primary");
4995 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4996 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4997                 slave_id, UINT8);
4998 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4999 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5000                 port_id, UINT8);
5001
5002 cmdline_parse_inst_t cmd_set_bonding_primary = {
5003                 .f = cmd_set_bonding_primary_parsed,
5004                 .help_str = "set bonding primary <slave_id> <port_id>: "
5005                         "Set the primary slave for port_id",
5006                 .data = NULL,
5007                 .tokens = {
5008                                 (void *)&cmd_setbonding_primary_set,
5009                                 (void *)&cmd_setbonding_primary_bonding,
5010                                 (void *)&cmd_setbonding_primary_primary,
5011                                 (void *)&cmd_setbonding_primary_slave,
5012                                 (void *)&cmd_setbonding_primary_port,
5013                                 NULL
5014                 }
5015 };
5016
5017 /* *** ADD SLAVE *** */
5018 struct cmd_add_bonding_slave_result {
5019         cmdline_fixed_string_t add;
5020         cmdline_fixed_string_t bonding;
5021         cmdline_fixed_string_t slave;
5022         uint8_t slave_id;
5023         uint8_t port_id;
5024 };
5025
5026 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5027                 __attribute__((unused))  struct cmdline *cl,
5028                 __attribute__((unused)) void *data)
5029 {
5030         struct cmd_add_bonding_slave_result *res = parsed_result;
5031         portid_t master_port_id = res->port_id;
5032         portid_t slave_port_id = res->slave_id;
5033
5034         /* add the slave for a bonded device. */
5035         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5036                 printf("\t Failed to add slave %d to master port = %d.\n",
5037                                 slave_port_id, master_port_id);
5038                 return;
5039         }
5040         init_port_config();
5041         set_port_slave_flag(slave_port_id);
5042 }
5043
5044 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5045 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5046                 add, "add");
5047 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5048 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5049                 bonding, "bonding");
5050 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5051 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5052                 slave, "slave");
5053 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5054 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5055                 slave_id, UINT8);
5056 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5057 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5058                 port_id, UINT8);
5059
5060 cmdline_parse_inst_t cmd_add_bonding_slave = {
5061                 .f = cmd_add_bonding_slave_parsed,
5062                 .help_str = "add bonding slave <slave_id> <port_id>: "
5063                         "Add a slave device to a bonded device",
5064                 .data = NULL,
5065                 .tokens = {
5066                                 (void *)&cmd_addbonding_slave_add,
5067                                 (void *)&cmd_addbonding_slave_bonding,
5068                                 (void *)&cmd_addbonding_slave_slave,
5069                                 (void *)&cmd_addbonding_slave_slaveid,
5070                                 (void *)&cmd_addbonding_slave_port,
5071                                 NULL
5072                 }
5073 };
5074
5075 /* *** REMOVE SLAVE *** */
5076 struct cmd_remove_bonding_slave_result {
5077         cmdline_fixed_string_t remove;
5078         cmdline_fixed_string_t bonding;
5079         cmdline_fixed_string_t slave;
5080         uint8_t slave_id;
5081         uint8_t port_id;
5082 };
5083
5084 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5085                 __attribute__((unused))  struct cmdline *cl,
5086                 __attribute__((unused)) void *data)
5087 {
5088         struct cmd_remove_bonding_slave_result *res = parsed_result;
5089         portid_t master_port_id = res->port_id;
5090         portid_t slave_port_id = res->slave_id;
5091
5092         /* remove the slave from a bonded device. */
5093         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5094                 printf("\t Failed to remove slave %d from master port = %d.\n",
5095                                 slave_port_id, master_port_id);
5096                 return;
5097         }
5098         init_port_config();
5099         clear_port_slave_flag(slave_port_id);
5100 }
5101
5102 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5103                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5104                                 remove, "remove");
5105 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5106                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5107                                 bonding, "bonding");
5108 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5109                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5110                                 slave, "slave");
5111 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5112                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5113                                 slave_id, UINT8);
5114 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5115                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5116                                 port_id, UINT8);
5117
5118 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5119                 .f = cmd_remove_bonding_slave_parsed,
5120                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5121                         "Remove a slave device from a bonded device",
5122                 .data = NULL,
5123                 .tokens = {
5124                                 (void *)&cmd_removebonding_slave_remove,
5125                                 (void *)&cmd_removebonding_slave_bonding,
5126                                 (void *)&cmd_removebonding_slave_slave,
5127                                 (void *)&cmd_removebonding_slave_slaveid,
5128                                 (void *)&cmd_removebonding_slave_port,
5129                                 NULL
5130                 }
5131 };
5132
5133 /* *** CREATE BONDED DEVICE *** */
5134 struct cmd_create_bonded_device_result {
5135         cmdline_fixed_string_t create;
5136         cmdline_fixed_string_t bonded;
5137         cmdline_fixed_string_t device;
5138         uint8_t mode;
5139         uint8_t socket;
5140 };
5141
5142 static int bond_dev_num = 0;
5143
5144 static void cmd_create_bonded_device_parsed(void *parsed_result,
5145                 __attribute__((unused))  struct cmdline *cl,
5146                 __attribute__((unused)) void *data)
5147 {
5148         struct cmd_create_bonded_device_result *res = parsed_result;
5149         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5150         int port_id;
5151
5152         if (test_done == 0) {
5153                 printf("Please stop forwarding first\n");
5154                 return;
5155         }
5156
5157         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5158                         bond_dev_num++);
5159
5160         /* Create a new bonded device. */
5161         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5162         if (port_id < 0) {
5163                 printf("\t Failed to create bonded device.\n");
5164                 return;
5165         } else {
5166                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5167                                 port_id);
5168
5169                 /* Update number of ports */
5170                 nb_ports = rte_eth_dev_count();
5171                 reconfig(port_id, res->socket);
5172                 rte_eth_promiscuous_enable(port_id);
5173         }
5174
5175 }
5176
5177 cmdline_parse_token_string_t cmd_createbonded_device_create =
5178                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5179                                 create, "create");
5180 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5181                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5182                                 bonded, "bonded");
5183 cmdline_parse_token_string_t cmd_createbonded_device_device =
5184                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5185                                 device, "device");
5186 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5187                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5188                                 mode, UINT8);
5189 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5190                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5191                                 socket, UINT8);
5192
5193 cmdline_parse_inst_t cmd_create_bonded_device = {
5194                 .f = cmd_create_bonded_device_parsed,
5195                 .help_str = "create bonded device <mode> <socket>: "
5196                         "Create a new bonded device with specific bonding mode and socket",
5197                 .data = NULL,
5198                 .tokens = {
5199                                 (void *)&cmd_createbonded_device_create,
5200                                 (void *)&cmd_createbonded_device_bonded,
5201                                 (void *)&cmd_createbonded_device_device,
5202                                 (void *)&cmd_createbonded_device_mode,
5203                                 (void *)&cmd_createbonded_device_socket,
5204                                 NULL
5205                 }
5206 };
5207
5208 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5209 struct cmd_set_bond_mac_addr_result {
5210         cmdline_fixed_string_t set;
5211         cmdline_fixed_string_t bonding;
5212         cmdline_fixed_string_t mac_addr;
5213         uint8_t port_num;
5214         struct ether_addr address;
5215 };
5216
5217 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5218                 __attribute__((unused))  struct cmdline *cl,
5219                 __attribute__((unused)) void *data)
5220 {
5221         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5222         int ret;
5223
5224         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5225                 return;
5226
5227         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5228
5229         /* check the return value and print it if is < 0 */
5230         if (ret < 0)
5231                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5232 }
5233
5234 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5235                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5236 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5237                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5238                                 "bonding");
5239 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5240                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5241                                 "mac_addr");
5242 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5243                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5244 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5245                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5246
5247 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5248                 .f = cmd_set_bond_mac_addr_parsed,
5249                 .data = (void *) 0,
5250                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5251                 .tokens = {
5252                                 (void *)&cmd_set_bond_mac_addr_set,
5253                                 (void *)&cmd_set_bond_mac_addr_bonding,
5254                                 (void *)&cmd_set_bond_mac_addr_mac,
5255                                 (void *)&cmd_set_bond_mac_addr_portnum,
5256                                 (void *)&cmd_set_bond_mac_addr_addr,
5257                                 NULL
5258                 }
5259 };
5260
5261
5262 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5263 struct cmd_set_bond_mon_period_result {
5264         cmdline_fixed_string_t set;
5265         cmdline_fixed_string_t bonding;
5266         cmdline_fixed_string_t mon_period;
5267         uint8_t port_num;
5268         uint32_t period_ms;
5269 };
5270
5271 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5272                 __attribute__((unused))  struct cmdline *cl,
5273                 __attribute__((unused)) void *data)
5274 {
5275         struct cmd_set_bond_mon_period_result *res = parsed_result;
5276         int ret;
5277
5278         if (res->port_num >= nb_ports) {
5279                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5280                 return;
5281         }
5282
5283         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5284
5285         /* check the return value and print it if is < 0 */
5286         if (ret < 0)
5287                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5288 }
5289
5290 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5291                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5292                                 set, "set");
5293 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5294                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5295                                 bonding, "bonding");
5296 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5297                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5298                                 mon_period,     "mon_period");
5299 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5300                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5301                                 port_num, UINT8);
5302 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5303                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5304                                 period_ms, UINT32);
5305
5306 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5307                 .f = cmd_set_bond_mon_period_parsed,
5308                 .data = (void *) 0,
5309                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5310                 .tokens = {
5311                                 (void *)&cmd_set_bond_mon_period_set,
5312                                 (void *)&cmd_set_bond_mon_period_bonding,
5313                                 (void *)&cmd_set_bond_mon_period_mon_period,
5314                                 (void *)&cmd_set_bond_mon_period_portnum,
5315                                 (void *)&cmd_set_bond_mon_period_period_ms,
5316                                 NULL
5317                 }
5318 };
5319
5320
5321
5322 struct cmd_set_bonding_agg_mode_policy_result {
5323         cmdline_fixed_string_t set;
5324         cmdline_fixed_string_t bonding;
5325         cmdline_fixed_string_t agg_mode;
5326         uint8_t port_num;
5327         cmdline_fixed_string_t policy;
5328 };
5329
5330
5331 static void
5332 cmd_set_bonding_agg_mode(void *parsed_result,
5333                 __attribute__((unused)) struct cmdline *cl,
5334                 __attribute__((unused)) void *data)
5335 {
5336         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5337         uint8_t policy = AGG_BANDWIDTH;
5338
5339         if (res->port_num >= nb_ports) {
5340                 printf("Port id %d must be less than %d\n",
5341                                 res->port_num, nb_ports);
5342                 return;
5343         }
5344
5345         if (!strcmp(res->policy, "bandwidth"))
5346                 policy = AGG_BANDWIDTH;
5347         else if (!strcmp(res->policy, "stable"))
5348                 policy = AGG_STABLE;
5349         else if (!strcmp(res->policy, "count"))
5350                 policy = AGG_COUNT;
5351
5352         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5353 }
5354
5355
5356 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5357         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5358                                 set, "set");
5359 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5360         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5361                                 bonding, "bonding");
5362
5363 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5365                                 agg_mode, "agg_mode");
5366
5367 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5368         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5369                                 port_num, UINT8);
5370
5371 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5372         TOKEN_STRING_INITIALIZER(
5373                         struct cmd_set_bonding_balance_xmit_policy_result,
5374                 policy, "stable#bandwidth#count");
5375
5376 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5377         .f = cmd_set_bonding_agg_mode,
5378         .data = (void *) 0,
5379         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5380         .tokens = {
5381                         (void *)&cmd_set_bonding_agg_mode_set,
5382                         (void *)&cmd_set_bonding_agg_mode_bonding,
5383                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5384                         (void *)&cmd_set_bonding_agg_mode_portnum,
5385                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5386                         NULL
5387                 }
5388 };
5389
5390
5391 #endif /* RTE_LIBRTE_PMD_BOND */
5392
5393 /* *** SET FORWARDING MODE *** */
5394 struct cmd_set_fwd_mode_result {
5395         cmdline_fixed_string_t set;
5396         cmdline_fixed_string_t fwd;
5397         cmdline_fixed_string_t mode;
5398 };
5399
5400 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5401                                     __attribute__((unused)) struct cmdline *cl,
5402                                     __attribute__((unused)) void *data)
5403 {
5404         struct cmd_set_fwd_mode_result *res = parsed_result;
5405
5406         retry_enabled = 0;
5407         set_pkt_forwarding_mode(res->mode);
5408 }
5409
5410 cmdline_parse_token_string_t cmd_setfwd_set =
5411         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5412 cmdline_parse_token_string_t cmd_setfwd_fwd =
5413         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5414 cmdline_parse_token_string_t cmd_setfwd_mode =
5415         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5416                 "" /* defined at init */);
5417
5418 cmdline_parse_inst_t cmd_set_fwd_mode = {
5419         .f = cmd_set_fwd_mode_parsed,
5420         .data = NULL,
5421         .help_str = NULL, /* defined at init */
5422         .tokens = {
5423                 (void *)&cmd_setfwd_set,
5424                 (void *)&cmd_setfwd_fwd,
5425                 (void *)&cmd_setfwd_mode,
5426                 NULL,
5427         },
5428 };
5429
5430 static void cmd_set_fwd_mode_init(void)
5431 {
5432         char *modes, *c;
5433         static char token[128];
5434         static char help[256];
5435         cmdline_parse_token_string_t *token_struct;
5436
5437         modes = list_pkt_forwarding_modes();
5438         snprintf(help, sizeof(help), "set fwd %s: "
5439                 "Set packet forwarding mode", modes);
5440         cmd_set_fwd_mode.help_str = help;
5441
5442         /* string token separator is # */
5443         for (c = token; *modes != '\0'; modes++)
5444                 if (*modes == '|')
5445                         *c++ = '#';
5446                 else
5447                         *c++ = *modes;
5448         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5449         token_struct->string_data.str = token;
5450 }
5451
5452 /* *** SET RETRY FORWARDING MODE *** */
5453 struct cmd_set_fwd_retry_mode_result {
5454         cmdline_fixed_string_t set;
5455         cmdline_fixed_string_t fwd;
5456         cmdline_fixed_string_t mode;
5457         cmdline_fixed_string_t retry;
5458 };
5459
5460 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5461                             __attribute__((unused)) struct cmdline *cl,
5462                             __attribute__((unused)) void *data)
5463 {
5464         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5465
5466         retry_enabled = 1;
5467         set_pkt_forwarding_mode(res->mode);
5468 }
5469
5470 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5471         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5472                         set, "set");
5473 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5474         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5475                         fwd, "fwd");
5476 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5477         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5478                         mode,
5479                 "" /* defined at init */);
5480 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5481         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5482                         retry, "retry");
5483
5484 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5485         .f = cmd_set_fwd_retry_mode_parsed,
5486         .data = NULL,
5487         .help_str = NULL, /* defined at init */
5488         .tokens = {
5489                 (void *)&cmd_setfwd_retry_set,
5490                 (void *)&cmd_setfwd_retry_fwd,
5491                 (void *)&cmd_setfwd_retry_mode,
5492                 (void *)&cmd_setfwd_retry_retry,
5493                 NULL,
5494         },
5495 };
5496
5497 static void cmd_set_fwd_retry_mode_init(void)
5498 {
5499         char *modes, *c;
5500         static char token[128];
5501         static char help[256];
5502         cmdline_parse_token_string_t *token_struct;
5503
5504         modes = list_pkt_forwarding_retry_modes();
5505         snprintf(help, sizeof(help), "set fwd %s retry: "
5506                 "Set packet forwarding mode with retry", modes);
5507         cmd_set_fwd_retry_mode.help_str = help;
5508
5509         /* string token separator is # */
5510         for (c = token; *modes != '\0'; modes++)
5511                 if (*modes == '|')
5512                         *c++ = '#';
5513                 else
5514                         *c++ = *modes;
5515         token_struct = (cmdline_parse_token_string_t *)
5516                 cmd_set_fwd_retry_mode.tokens[2];
5517         token_struct->string_data.str = token;
5518 }
5519
5520 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5521 struct cmd_set_burst_tx_retry_result {
5522         cmdline_fixed_string_t set;
5523         cmdline_fixed_string_t burst;
5524         cmdline_fixed_string_t tx;
5525         cmdline_fixed_string_t delay;
5526         uint32_t time;
5527         cmdline_fixed_string_t retry;
5528         uint32_t retry_num;
5529 };
5530
5531 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5532                                         __attribute__((unused)) struct cmdline *cl,
5533                                         __attribute__((unused)) void *data)
5534 {
5535         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5536
5537         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5538                 && !strcmp(res->tx, "tx")) {
5539                 if (!strcmp(res->delay, "delay"))
5540                         burst_tx_delay_time = res->time;
5541                 if (!strcmp(res->retry, "retry"))
5542                         burst_tx_retry_num = res->retry_num;
5543         }
5544
5545 }
5546
5547 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5549 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5551                                  "burst");
5552 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5554 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5556 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5557         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5558 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5560 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5561         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5562
5563 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5564         .f = cmd_set_burst_tx_retry_parsed,
5565         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5566         .tokens = {
5567                 (void *)&cmd_set_burst_tx_retry_set,
5568                 (void *)&cmd_set_burst_tx_retry_burst,
5569                 (void *)&cmd_set_burst_tx_retry_tx,
5570                 (void *)&cmd_set_burst_tx_retry_delay,
5571                 (void *)&cmd_set_burst_tx_retry_time,
5572                 (void *)&cmd_set_burst_tx_retry_retry,
5573                 (void *)&cmd_set_burst_tx_retry_retry_num,
5574                 NULL,
5575         },
5576 };
5577
5578 /* *** SET PROMISC MODE *** */
5579 struct cmd_set_promisc_mode_result {
5580         cmdline_fixed_string_t set;
5581         cmdline_fixed_string_t promisc;
5582         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5583         uint8_t port_num;                /* valid if "allports" argument == 0 */
5584         cmdline_fixed_string_t mode;
5585 };
5586
5587 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5588                                         __attribute__((unused)) struct cmdline *cl,
5589                                         void *allports)
5590 {
5591         struct cmd_set_promisc_mode_result *res = parsed_result;
5592         int enable;
5593         portid_t i;
5594
5595         if (!strcmp(res->mode, "on"))
5596                 enable = 1;
5597         else
5598                 enable = 0;
5599
5600         /* all ports */
5601         if (allports) {
5602                 RTE_ETH_FOREACH_DEV(i) {
5603                         if (enable)
5604                                 rte_eth_promiscuous_enable(i);
5605                         else
5606                                 rte_eth_promiscuous_disable(i);
5607                 }
5608         }
5609         else {
5610                 if (enable)
5611                         rte_eth_promiscuous_enable(res->port_num);
5612                 else
5613                         rte_eth_promiscuous_disable(res->port_num);
5614         }
5615 }
5616
5617 cmdline_parse_token_string_t cmd_setpromisc_set =
5618         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5619 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5621                                  "promisc");
5622 cmdline_parse_token_string_t cmd_setpromisc_portall =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5624                                  "all");
5625 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5626         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5627                               UINT8);
5628 cmdline_parse_token_string_t cmd_setpromisc_mode =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5630                                  "on#off");
5631
5632 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5633         .f = cmd_set_promisc_mode_parsed,
5634         .data = (void *)1,
5635         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5636         .tokens = {
5637                 (void *)&cmd_setpromisc_set,
5638                 (void *)&cmd_setpromisc_promisc,
5639                 (void *)&cmd_setpromisc_portall,
5640                 (void *)&cmd_setpromisc_mode,
5641                 NULL,
5642         },
5643 };
5644
5645 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5646         .f = cmd_set_promisc_mode_parsed,
5647         .data = (void *)0,
5648         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5649         .tokens = {
5650                 (void *)&cmd_setpromisc_set,
5651                 (void *)&cmd_setpromisc_promisc,
5652                 (void *)&cmd_setpromisc_portnum,
5653                 (void *)&cmd_setpromisc_mode,
5654                 NULL,
5655         },
5656 };
5657
5658 /* *** SET ALLMULTI MODE *** */
5659 struct cmd_set_allmulti_mode_result {
5660         cmdline_fixed_string_t set;
5661         cmdline_fixed_string_t allmulti;
5662         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5663         uint8_t port_num;                /* valid if "allports" argument == 0 */
5664         cmdline_fixed_string_t mode;
5665 };
5666
5667 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5668                                         __attribute__((unused)) struct cmdline *cl,
5669                                         void *allports)
5670 {
5671         struct cmd_set_allmulti_mode_result *res = parsed_result;
5672         int enable;
5673         portid_t i;
5674
5675         if (!strcmp(res->mode, "on"))
5676                 enable = 1;
5677         else
5678                 enable = 0;
5679
5680         /* all ports */
5681         if (allports) {
5682                 RTE_ETH_FOREACH_DEV(i) {
5683                         if (enable)
5684                                 rte_eth_allmulticast_enable(i);
5685                         else
5686                                 rte_eth_allmulticast_disable(i);
5687                 }
5688         }
5689         else {
5690                 if (enable)
5691                         rte_eth_allmulticast_enable(res->port_num);
5692                 else
5693                         rte_eth_allmulticast_disable(res->port_num);
5694         }
5695 }
5696
5697 cmdline_parse_token_string_t cmd_setallmulti_set =
5698         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5699 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5700         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5701                                  "allmulti");
5702 cmdline_parse_token_string_t cmd_setallmulti_portall =
5703         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5704                                  "all");
5705 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5706         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5707                               UINT8);
5708 cmdline_parse_token_string_t cmd_setallmulti_mode =
5709         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5710                                  "on#off");
5711
5712 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5713         .f = cmd_set_allmulti_mode_parsed,
5714         .data = (void *)1,
5715         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5716         .tokens = {
5717                 (void *)&cmd_setallmulti_set,
5718                 (void *)&cmd_setallmulti_allmulti,
5719                 (void *)&cmd_setallmulti_portall,
5720                 (void *)&cmd_setallmulti_mode,
5721                 NULL,
5722         },
5723 };
5724
5725 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5726         .f = cmd_set_allmulti_mode_parsed,
5727         .data = (void *)0,
5728         .help_str = "set allmulti <port_id> on|off: "
5729                 "Set allmulti mode on port_id",
5730         .tokens = {
5731                 (void *)&cmd_setallmulti_set,
5732                 (void *)&cmd_setallmulti_allmulti,
5733                 (void *)&cmd_setallmulti_portnum,
5734                 (void *)&cmd_setallmulti_mode,
5735                 NULL,
5736         },
5737 };
5738
5739 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5740 struct cmd_link_flow_ctrl_set_result {
5741         cmdline_fixed_string_t set;
5742         cmdline_fixed_string_t flow_ctrl;
5743         cmdline_fixed_string_t rx;
5744         cmdline_fixed_string_t rx_lfc_mode;
5745         cmdline_fixed_string_t tx;
5746         cmdline_fixed_string_t tx_lfc_mode;
5747         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5748         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5749         cmdline_fixed_string_t autoneg_str;
5750         cmdline_fixed_string_t autoneg;
5751         cmdline_fixed_string_t hw_str;
5752         uint32_t high_water;
5753         cmdline_fixed_string_t lw_str;
5754         uint32_t low_water;
5755         cmdline_fixed_string_t pt_str;
5756         uint16_t pause_time;
5757         cmdline_fixed_string_t xon_str;
5758         uint16_t send_xon;
5759         uint8_t  port_id;
5760 };
5761
5762 cmdline_parse_token_string_t cmd_lfc_set_set =
5763         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5764                                 set, "set");
5765 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5766         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5767                                 flow_ctrl, "flow_ctrl");
5768 cmdline_parse_token_string_t cmd_lfc_set_rx =
5769         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5770                                 rx, "rx");
5771 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5772         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5773                                 rx_lfc_mode, "on#off");
5774 cmdline_parse_token_string_t cmd_lfc_set_tx =
5775         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5776                                 tx, "tx");
5777 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5778         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5779                                 tx_lfc_mode, "on#off");
5780 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5781         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5782                                 hw_str, "high_water");
5783 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5784         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5785                                 high_water, UINT32);
5786 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5787         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5788                                 lw_str, "low_water");
5789 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5790         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5791                                 low_water, UINT32);
5792 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5793         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5794                                 pt_str, "pause_time");
5795 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5796         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5797                                 pause_time, UINT16);
5798 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5799         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5800                                 xon_str, "send_xon");
5801 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5802         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5803                                 send_xon, UINT16);
5804 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5805         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5806                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5807 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5808         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5809                                 mac_ctrl_frame_fwd_mode, "on#off");
5810 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5811         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5812                                 autoneg_str, "autoneg");
5813 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5814         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5815                                 autoneg, "on#off");
5816 cmdline_parse_token_num_t cmd_lfc_set_portid =
5817         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5818                                 port_id, UINT8);
5819
5820 /* forward declaration */
5821 static void
5822 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5823                               void *data);
5824
5825 cmdline_parse_inst_t cmd_link_flow_control_set = {
5826         .f = cmd_link_flow_ctrl_set_parsed,
5827         .data = NULL,
5828         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5829                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5830                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5831         .tokens = {
5832                 (void *)&cmd_lfc_set_set,
5833                 (void *)&cmd_lfc_set_flow_ctrl,
5834                 (void *)&cmd_lfc_set_rx,
5835                 (void *)&cmd_lfc_set_rx_mode,
5836                 (void *)&cmd_lfc_set_tx,
5837                 (void *)&cmd_lfc_set_tx_mode,
5838                 (void *)&cmd_lfc_set_high_water,
5839                 (void *)&cmd_lfc_set_low_water,
5840                 (void *)&cmd_lfc_set_pause_time,
5841                 (void *)&cmd_lfc_set_send_xon,
5842                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5843                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5844                 (void *)&cmd_lfc_set_autoneg_str,
5845                 (void *)&cmd_lfc_set_autoneg,
5846                 (void *)&cmd_lfc_set_portid,
5847                 NULL,
5848         },
5849 };
5850
5851 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5852         .f = cmd_link_flow_ctrl_set_parsed,
5853         .data = (void *)&cmd_link_flow_control_set_rx,
5854         .help_str = "set flow_ctrl rx on|off <port_id>: "
5855                 "Change rx flow control parameter",
5856         .tokens = {
5857                 (void *)&cmd_lfc_set_set,
5858                 (void *)&cmd_lfc_set_flow_ctrl,
5859                 (void *)&cmd_lfc_set_rx,
5860                 (void *)&cmd_lfc_set_rx_mode,
5861                 (void *)&cmd_lfc_set_portid,
5862                 NULL,
5863         },
5864 };
5865
5866 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5867         .f = cmd_link_flow_ctrl_set_parsed,
5868         .data = (void *)&cmd_link_flow_control_set_tx,
5869         .help_str = "set flow_ctrl tx on|off <port_id>: "
5870                 "Change tx flow control parameter",
5871         .tokens = {
5872                 (void *)&cmd_lfc_set_set,
5873                 (void *)&cmd_lfc_set_flow_ctrl,
5874                 (void *)&cmd_lfc_set_tx,
5875                 (void *)&cmd_lfc_set_tx_mode,
5876                 (void *)&cmd_lfc_set_portid,
5877                 NULL,
5878         },
5879 };
5880
5881 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5882         .f = cmd_link_flow_ctrl_set_parsed,
5883         .data = (void *)&cmd_link_flow_control_set_hw,
5884         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5885                 "Change high water flow control parameter",
5886         .tokens = {
5887                 (void *)&cmd_lfc_set_set,
5888                 (void *)&cmd_lfc_set_flow_ctrl,
5889                 (void *)&cmd_lfc_set_high_water_str,
5890                 (void *)&cmd_lfc_set_high_water,
5891                 (void *)&cmd_lfc_set_portid,
5892                 NULL,
5893         },
5894 };
5895
5896 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5897         .f = cmd_link_flow_ctrl_set_parsed,
5898         .data = (void *)&cmd_link_flow_control_set_lw,
5899         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5900                 "Change low water flow control parameter",
5901         .tokens = {
5902                 (void *)&cmd_lfc_set_set,
5903                 (void *)&cmd_lfc_set_flow_ctrl,
5904                 (void *)&cmd_lfc_set_low_water_str,
5905                 (void *)&cmd_lfc_set_low_water,
5906                 (void *)&cmd_lfc_set_portid,
5907                 NULL,
5908         },
5909 };
5910
5911 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5912         .f = cmd_link_flow_ctrl_set_parsed,
5913         .data = (void *)&cmd_link_flow_control_set_pt,
5914         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5915                 "Change pause time flow control parameter",
5916         .tokens = {
5917                 (void *)&cmd_lfc_set_set,
5918                 (void *)&cmd_lfc_set_flow_ctrl,
5919                 (void *)&cmd_lfc_set_pause_time_str,
5920                 (void *)&cmd_lfc_set_pause_time,
5921                 (void *)&cmd_lfc_set_portid,
5922                 NULL,
5923         },
5924 };
5925
5926 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5927         .f = cmd_link_flow_ctrl_set_parsed,
5928         .data = (void *)&cmd_link_flow_control_set_xon,
5929         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5930                 "Change send_xon flow control parameter",
5931         .tokens = {
5932                 (void *)&cmd_lfc_set_set,
5933                 (void *)&cmd_lfc_set_flow_ctrl,
5934                 (void *)&cmd_lfc_set_send_xon_str,
5935                 (void *)&cmd_lfc_set_send_xon,
5936                 (void *)&cmd_lfc_set_portid,
5937                 NULL,
5938         },
5939 };
5940
5941 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5942         .f = cmd_link_flow_ctrl_set_parsed,
5943         .data = (void *)&cmd_link_flow_control_set_macfwd,
5944         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5945                 "Change mac ctrl fwd flow control parameter",
5946         .tokens = {
5947                 (void *)&cmd_lfc_set_set,
5948                 (void *)&cmd_lfc_set_flow_ctrl,
5949                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5950                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5951                 (void *)&cmd_lfc_set_portid,
5952                 NULL,
5953         },
5954 };
5955
5956 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5957         .f = cmd_link_flow_ctrl_set_parsed,
5958         .data = (void *)&cmd_link_flow_control_set_autoneg,
5959         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5960                 "Change autoneg flow control parameter",
5961         .tokens = {
5962                 (void *)&cmd_lfc_set_set,
5963                 (void *)&cmd_lfc_set_flow_ctrl,
5964                 (void *)&cmd_lfc_set_autoneg_str,
5965                 (void *)&cmd_lfc_set_autoneg,
5966                 (void *)&cmd_lfc_set_portid,
5967                 NULL,
5968         },
5969 };
5970
5971 static void
5972 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5973                               __attribute__((unused)) struct cmdline *cl,
5974                               void *data)
5975 {
5976         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5977         cmdline_parse_inst_t *cmd = data;
5978         struct rte_eth_fc_conf fc_conf;
5979         int rx_fc_en = 0;
5980         int tx_fc_en = 0;
5981         int ret;
5982
5983         /*
5984          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5985          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5986          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5987          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5988          */
5989         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5990                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5991         };
5992
5993         /* Partial command line, retrieve current configuration */
5994         if (cmd) {
5995                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5996                 if (ret != 0) {
5997                         printf("cannot get current flow ctrl parameters, return"
5998                                "code = %d\n", ret);
5999                         return;
6000                 }
6001
6002                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6003                     (fc_conf.mode == RTE_FC_FULL))
6004                         rx_fc_en = 1;
6005                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6006                     (fc_conf.mode == RTE_FC_FULL))
6007                         tx_fc_en = 1;
6008         }
6009
6010         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6011                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6012
6013         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6014                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6015
6016         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6017
6018         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6019                 fc_conf.high_water = res->high_water;
6020
6021         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6022                 fc_conf.low_water = res->low_water;
6023
6024         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6025                 fc_conf.pause_time = res->pause_time;
6026
6027         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6028                 fc_conf.send_xon = res->send_xon;
6029
6030         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6031                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6032                         fc_conf.mac_ctrl_frame_fwd = 1;
6033                 else
6034                         fc_conf.mac_ctrl_frame_fwd = 0;
6035         }
6036
6037         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6038                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6039
6040         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6041         if (ret != 0)
6042                 printf("bad flow contrl parameter, return code = %d \n", ret);
6043 }
6044
6045 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6046 struct cmd_priority_flow_ctrl_set_result {
6047         cmdline_fixed_string_t set;
6048         cmdline_fixed_string_t pfc_ctrl;
6049         cmdline_fixed_string_t rx;
6050         cmdline_fixed_string_t rx_pfc_mode;
6051         cmdline_fixed_string_t tx;
6052         cmdline_fixed_string_t tx_pfc_mode;
6053         uint32_t high_water;
6054         uint32_t low_water;
6055         uint16_t pause_time;
6056         uint8_t  priority;
6057         uint8_t  port_id;
6058 };
6059
6060 static void
6061 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6062                        __attribute__((unused)) struct cmdline *cl,
6063                        __attribute__((unused)) void *data)
6064 {
6065         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6066         struct rte_eth_pfc_conf pfc_conf;
6067         int rx_fc_enable, tx_fc_enable;
6068         int ret;
6069
6070         /*
6071          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6072          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6073          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6074          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6075          */
6076         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6077                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6078         };
6079
6080         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6081         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6082         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6083         pfc_conf.fc.high_water = res->high_water;
6084         pfc_conf.fc.low_water  = res->low_water;
6085         pfc_conf.fc.pause_time = res->pause_time;
6086         pfc_conf.priority      = res->priority;
6087
6088         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6089         if (ret != 0)
6090                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6091 }
6092
6093 cmdline_parse_token_string_t cmd_pfc_set_set =
6094         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6095                                 set, "set");
6096 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6097         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6098                                 pfc_ctrl, "pfc_ctrl");
6099 cmdline_parse_token_string_t cmd_pfc_set_rx =
6100         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6101                                 rx, "rx");
6102 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6103         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6104                                 rx_pfc_mode, "on#off");
6105 cmdline_parse_token_string_t cmd_pfc_set_tx =
6106         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6107                                 tx, "tx");
6108 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6109         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6110                                 tx_pfc_mode, "on#off");
6111 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6112         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6113                                 high_water, UINT32);
6114 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6115         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6116                                 low_water, UINT32);
6117 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6118         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6119                                 pause_time, UINT16);
6120 cmdline_parse_token_num_t cmd_pfc_set_priority =
6121         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6122                                 priority, UINT8);
6123 cmdline_parse_token_num_t cmd_pfc_set_portid =
6124         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6125                                 port_id, UINT8);
6126
6127 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6128         .f = cmd_priority_flow_ctrl_set_parsed,
6129         .data = NULL,
6130         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6131                 "<pause_time> <priority> <port_id>: "
6132                 "Configure the Ethernet priority flow control",
6133         .tokens = {
6134                 (void *)&cmd_pfc_set_set,
6135                 (void *)&cmd_pfc_set_flow_ctrl,
6136                 (void *)&cmd_pfc_set_rx,
6137                 (void *)&cmd_pfc_set_rx_mode,
6138                 (void *)&cmd_pfc_set_tx,
6139                 (void *)&cmd_pfc_set_tx_mode,
6140                 (void *)&cmd_pfc_set_high_water,
6141                 (void *)&cmd_pfc_set_low_water,
6142                 (void *)&cmd_pfc_set_pause_time,
6143                 (void *)&cmd_pfc_set_priority,
6144                 (void *)&cmd_pfc_set_portid,
6145                 NULL,
6146         },
6147 };
6148
6149 /* *** RESET CONFIGURATION *** */
6150 struct cmd_reset_result {
6151         cmdline_fixed_string_t reset;
6152         cmdline_fixed_string_t def;
6153 };
6154
6155 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6156                              struct cmdline *cl,
6157                              __attribute__((unused)) void *data)
6158 {
6159         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6160         set_def_fwd_config();
6161 }
6162
6163 cmdline_parse_token_string_t cmd_reset_set =
6164         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6165 cmdline_parse_token_string_t cmd_reset_def =
6166         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6167                                  "default");
6168
6169 cmdline_parse_inst_t cmd_reset = {
6170         .f = cmd_reset_parsed,
6171         .data = NULL,
6172         .help_str = "set default: Reset default forwarding configuration",
6173         .tokens = {
6174                 (void *)&cmd_reset_set,
6175                 (void *)&cmd_reset_def,
6176                 NULL,
6177         },
6178 };
6179
6180 /* *** START FORWARDING *** */
6181 struct cmd_start_result {
6182         cmdline_fixed_string_t start;
6183 };
6184
6185 cmdline_parse_token_string_t cmd_start_start =
6186         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6187
6188 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6189                              __attribute__((unused)) struct cmdline *cl,
6190                              __attribute__((unused)) void *data)
6191 {
6192         start_packet_forwarding(0);
6193 }
6194
6195 cmdline_parse_inst_t cmd_start = {
6196         .f = cmd_start_parsed,
6197         .data = NULL,
6198         .help_str = "start: Start packet forwarding",
6199         .tokens = {
6200                 (void *)&cmd_start_start,
6201                 NULL,
6202         },
6203 };
6204
6205 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6206 struct cmd_start_tx_first_result {
6207         cmdline_fixed_string_t start;
6208         cmdline_fixed_string_t tx_first;
6209 };
6210
6211 static void
6212 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6213                           __attribute__((unused)) struct cmdline *cl,
6214                           __attribute__((unused)) void *data)
6215 {
6216         start_packet_forwarding(1);
6217 }
6218
6219 cmdline_parse_token_string_t cmd_start_tx_first_start =
6220         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6221                                  "start");
6222 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6223         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6224                                  tx_first, "tx_first");
6225
6226 cmdline_parse_inst_t cmd_start_tx_first = {
6227         .f = cmd_start_tx_first_parsed,
6228         .data = NULL,
6229         .help_str = "start tx_first: Start packet forwarding, "
6230                 "after sending 1 burst of packets",
6231         .tokens = {
6232                 (void *)&cmd_start_tx_first_start,
6233                 (void *)&cmd_start_tx_first_tx_first,
6234                 NULL,
6235         },
6236 };
6237
6238 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6239 struct cmd_start_tx_first_n_result {
6240         cmdline_fixed_string_t start;
6241         cmdline_fixed_string_t tx_first;
6242         uint32_t tx_num;
6243 };
6244
6245 static void
6246 cmd_start_tx_first_n_parsed(void *parsed_result,
6247                           __attribute__((unused)) struct cmdline *cl,
6248                           __attribute__((unused)) void *data)
6249 {
6250         struct cmd_start_tx_first_n_result *res = parsed_result;
6251
6252         start_packet_forwarding(res->tx_num);
6253 }
6254
6255 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6256         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6257                         start, "start");
6258 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6259         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6260                         tx_first, "tx_first");
6261 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6262         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6263                         tx_num, UINT32);
6264
6265 cmdline_parse_inst_t cmd_start_tx_first_n = {
6266         .f = cmd_start_tx_first_n_parsed,
6267         .data = NULL,
6268         .help_str = "start tx_first <num>: "
6269                 "packet forwarding, after sending <num> bursts of packets",
6270         .tokens = {
6271                 (void *)&cmd_start_tx_first_n_start,
6272                 (void *)&cmd_start_tx_first_n_tx_first,
6273                 (void *)&cmd_start_tx_first_n_tx_num,
6274                 NULL,
6275         },
6276 };
6277
6278 /* *** SET LINK UP *** */
6279 struct cmd_set_link_up_result {
6280         cmdline_fixed_string_t set;
6281         cmdline_fixed_string_t link_up;
6282         cmdline_fixed_string_t port;
6283         uint8_t port_id;
6284 };
6285
6286 cmdline_parse_token_string_t cmd_set_link_up_set =
6287         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6288 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6289         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6290                                 "link-up");
6291 cmdline_parse_token_string_t cmd_set_link_up_port =
6292         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6293 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6294         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6295
6296 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6297                              __attribute__((unused)) struct cmdline *cl,
6298                              __attribute__((unused)) void *data)
6299 {
6300         struct cmd_set_link_up_result *res = parsed_result;
6301         dev_set_link_up(res->port_id);
6302 }
6303
6304 cmdline_parse_inst_t cmd_set_link_up = {
6305         .f = cmd_set_link_up_parsed,
6306         .data = NULL,
6307         .help_str = "set link-up port <port id>",
6308         .tokens = {
6309                 (void *)&cmd_set_link_up_set,
6310                 (void *)&cmd_set_link_up_link_up,
6311                 (void *)&cmd_set_link_up_port,
6312                 (void *)&cmd_set_link_up_port_id,
6313                 NULL,
6314         },
6315 };
6316
6317 /* *** SET LINK DOWN *** */
6318 struct cmd_set_link_down_result {
6319         cmdline_fixed_string_t set;
6320         cmdline_fixed_string_t link_down;
6321         cmdline_fixed_string_t port;
6322         uint8_t port_id;
6323 };
6324
6325 cmdline_parse_token_string_t cmd_set_link_down_set =
6326         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6327 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6328         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6329                                 "link-down");
6330 cmdline_parse_token_string_t cmd_set_link_down_port =
6331         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6332 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6333         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6334
6335 static void cmd_set_link_down_parsed(
6336                                 __attribute__((unused)) void *parsed_result,
6337                                 __attribute__((unused)) struct cmdline *cl,
6338                                 __attribute__((unused)) void *data)
6339 {
6340         struct cmd_set_link_down_result *res = parsed_result;
6341         dev_set_link_down(res->port_id);
6342 }
6343
6344 cmdline_parse_inst_t cmd_set_link_down = {
6345         .f = cmd_set_link_down_parsed,
6346         .data = NULL,
6347         .help_str = "set link-down port <port id>",
6348         .tokens = {
6349                 (void *)&cmd_set_link_down_set,
6350                 (void *)&cmd_set_link_down_link_down,
6351                 (void *)&cmd_set_link_down_port,
6352                 (void *)&cmd_set_link_down_port_id,
6353                 NULL,
6354         },
6355 };
6356
6357 /* *** SHOW CFG *** */
6358 struct cmd_showcfg_result {
6359         cmdline_fixed_string_t show;
6360         cmdline_fixed_string_t cfg;
6361         cmdline_fixed_string_t what;
6362 };
6363
6364 static void cmd_showcfg_parsed(void *parsed_result,
6365                                __attribute__((unused)) struct cmdline *cl,
6366                                __attribute__((unused)) void *data)
6367 {
6368         struct cmd_showcfg_result *res = parsed_result;
6369         if (!strcmp(res->what, "rxtx"))
6370                 rxtx_config_display();
6371         else if (!strcmp(res->what, "cores"))
6372                 fwd_lcores_config_display();
6373         else if (!strcmp(res->what, "fwd"))
6374                 pkt_fwd_config_display(&cur_fwd_config);
6375         else if (!strcmp(res->what, "txpkts"))
6376                 show_tx_pkt_segments();
6377 }
6378
6379 cmdline_parse_token_string_t cmd_showcfg_show =
6380         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6381 cmdline_parse_token_string_t cmd_showcfg_port =
6382         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6383 cmdline_parse_token_string_t cmd_showcfg_what =
6384         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6385                                  "rxtx#cores#fwd#txpkts");
6386
6387 cmdline_parse_inst_t cmd_showcfg = {
6388         .f = cmd_showcfg_parsed,
6389         .data = NULL,
6390         .help_str = "show config rxtx|cores|fwd|txpkts",
6391         .tokens = {
6392                 (void *)&cmd_showcfg_show,
6393                 (void *)&cmd_showcfg_port,
6394                 (void *)&cmd_showcfg_what,
6395                 NULL,
6396         },
6397 };
6398
6399 /* *** SHOW ALL PORT INFO *** */
6400 struct cmd_showportall_result {
6401         cmdline_fixed_string_t show;
6402         cmdline_fixed_string_t port;
6403         cmdline_fixed_string_t what;
6404         cmdline_fixed_string_t all;
6405 };
6406
6407 static void cmd_showportall_parsed(void *parsed_result,
6408                                 __attribute__((unused)) struct cmdline *cl,
6409                                 __attribute__((unused)) void *data)
6410 {
6411         portid_t i;
6412
6413         struct cmd_showportall_result *res = parsed_result;
6414         if (!strcmp(res->show, "clear")) {
6415                 if (!strcmp(res->what, "stats"))
6416                         RTE_ETH_FOREACH_DEV(i)
6417                                 nic_stats_clear(i);
6418                 else if (!strcmp(res->what, "xstats"))
6419                         RTE_ETH_FOREACH_DEV(i)
6420                                 nic_xstats_clear(i);
6421         } else if (!strcmp(res->what, "info"))
6422                 RTE_ETH_FOREACH_DEV(i)
6423                         port_infos_display(i);
6424         else if (!strcmp(res->what, "stats"))
6425                 RTE_ETH_FOREACH_DEV(i)
6426                         nic_stats_display(i);
6427         else if (!strcmp(res->what, "xstats"))
6428                 RTE_ETH_FOREACH_DEV(i)
6429                         nic_xstats_display(i);
6430         else if (!strcmp(res->what, "fdir"))
6431                 RTE_ETH_FOREACH_DEV(i)
6432                         fdir_get_infos(i);
6433         else if (!strcmp(res->what, "stat_qmap"))
6434                 RTE_ETH_FOREACH_DEV(i)
6435                         nic_stats_mapping_display(i);
6436         else if (!strcmp(res->what, "dcb_tc"))
6437                 RTE_ETH_FOREACH_DEV(i)
6438                         port_dcb_info_display(i);
6439         else if (!strcmp(res->what, "cap"))
6440                 RTE_ETH_FOREACH_DEV(i)
6441                         port_offload_cap_display(i);
6442 }
6443
6444 cmdline_parse_token_string_t cmd_showportall_show =
6445         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6446                                  "show#clear");
6447 cmdline_parse_token_string_t cmd_showportall_port =
6448         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6449 cmdline_parse_token_string_t cmd_showportall_what =
6450         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6451                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6452 cmdline_parse_token_string_t cmd_showportall_all =
6453         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6454 cmdline_parse_inst_t cmd_showportall = {
6455         .f = cmd_showportall_parsed,
6456         .data = NULL,
6457         .help_str = "show|clear port "
6458                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6459         .tokens = {
6460                 (void *)&cmd_showportall_show,
6461                 (void *)&cmd_showportall_port,
6462                 (void *)&cmd_showportall_what,
6463                 (void *)&cmd_showportall_all,
6464                 NULL,
6465         },
6466 };
6467
6468 /* *** SHOW PORT INFO *** */
6469 struct cmd_showport_result {
6470         cmdline_fixed_string_t show;
6471         cmdline_fixed_string_t port;
6472         cmdline_fixed_string_t what;
6473         uint8_t portnum;
6474 };
6475
6476 static void cmd_showport_parsed(void *parsed_result,
6477                                 __attribute__((unused)) struct cmdline *cl,
6478                                 __attribute__((unused)) void *data)
6479 {
6480         struct cmd_showport_result *res = parsed_result;
6481         if (!strcmp(res->show, "clear")) {
6482                 if (!strcmp(res->what, "stats"))
6483                         nic_stats_clear(res->portnum);
6484                 else if (!strcmp(res->what, "xstats"))
6485                         nic_xstats_clear(res->portnum);
6486         } else if (!strcmp(res->what, "info"))
6487                 port_infos_display(res->portnum);
6488         else if (!strcmp(res->what, "stats"))
6489                 nic_stats_display(res->portnum);
6490         else if (!strcmp(res->what, "xstats"))
6491                 nic_xstats_display(res->portnum);
6492         else if (!strcmp(res->what, "fdir"))
6493                  fdir_get_infos(res->portnum);
6494         else if (!strcmp(res->what, "stat_qmap"))
6495                 nic_stats_mapping_display(res->portnum);
6496         else if (!strcmp(res->what, "dcb_tc"))
6497                 port_dcb_info_display(res->portnum);
6498         else if (!strcmp(res->what, "cap"))
6499                 port_offload_cap_display(res->portnum);
6500 }
6501
6502 cmdline_parse_token_string_t cmd_showport_show =
6503         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6504                                  "show#clear");
6505 cmdline_parse_token_string_t cmd_showport_port =
6506         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6507 cmdline_parse_token_string_t cmd_showport_what =
6508         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6509                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6510 cmdline_parse_token_num_t cmd_showport_portnum =
6511         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6512
6513 cmdline_parse_inst_t cmd_showport = {
6514         .f = cmd_showport_parsed,
6515         .data = NULL,
6516         .help_str = "show|clear port "
6517                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6518                 "<port_id>",
6519         .tokens = {
6520                 (void *)&cmd_showport_show,
6521                 (void *)&cmd_showport_port,
6522                 (void *)&cmd_showport_what,
6523                 (void *)&cmd_showport_portnum,
6524                 NULL,
6525         },
6526 };
6527
6528 /* *** SHOW QUEUE INFO *** */
6529 struct cmd_showqueue_result {
6530         cmdline_fixed_string_t show;
6531         cmdline_fixed_string_t type;
6532         cmdline_fixed_string_t what;
6533         uint8_t portnum;
6534         uint16_t queuenum;
6535 };
6536
6537 static void
6538 cmd_showqueue_parsed(void *parsed_result,
6539         __attribute__((unused)) struct cmdline *cl,
6540         __attribute__((unused)) void *data)
6541 {
6542         struct cmd_showqueue_result *res = parsed_result;
6543
6544         if (!strcmp(res->type, "rxq"))
6545                 rx_queue_infos_display(res->portnum, res->queuenum);
6546         else if (!strcmp(res->type, "txq"))
6547                 tx_queue_infos_display(res->portnum, res->queuenum);
6548 }
6549
6550 cmdline_parse_token_string_t cmd_showqueue_show =
6551         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6552 cmdline_parse_token_string_t cmd_showqueue_type =
6553         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6554 cmdline_parse_token_string_t cmd_showqueue_what =
6555         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6556 cmdline_parse_token_num_t cmd_showqueue_portnum =
6557         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6558 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6559         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6560
6561 cmdline_parse_inst_t cmd_showqueue = {
6562         .f = cmd_showqueue_parsed,
6563         .data = NULL,
6564         .help_str = "show rxq|txq info <port_id> <queue_id>",
6565         .tokens = {
6566                 (void *)&cmd_showqueue_show,
6567                 (void *)&cmd_showqueue_type,
6568                 (void *)&cmd_showqueue_what,
6569                 (void *)&cmd_showqueue_portnum,
6570                 (void *)&cmd_showqueue_queuenum,
6571                 NULL,
6572         },
6573 };
6574
6575 /* *** READ PORT REGISTER *** */
6576 struct cmd_read_reg_result {
6577         cmdline_fixed_string_t read;
6578         cmdline_fixed_string_t reg;
6579         uint8_t port_id;
6580         uint32_t reg_off;
6581 };
6582
6583 static void
6584 cmd_read_reg_parsed(void *parsed_result,
6585                     __attribute__((unused)) struct cmdline *cl,
6586                     __attribute__((unused)) void *data)
6587 {
6588         struct cmd_read_reg_result *res = parsed_result;
6589         port_reg_display(res->port_id, res->reg_off);
6590 }
6591
6592 cmdline_parse_token_string_t cmd_read_reg_read =
6593         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6594 cmdline_parse_token_string_t cmd_read_reg_reg =
6595         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6596 cmdline_parse_token_num_t cmd_read_reg_port_id =
6597         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6598 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6599         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6600
6601 cmdline_parse_inst_t cmd_read_reg = {
6602         .f = cmd_read_reg_parsed,
6603         .data = NULL,
6604         .help_str = "read reg <port_id> <reg_off>",
6605         .tokens = {
6606                 (void *)&cmd_read_reg_read,
6607                 (void *)&cmd_read_reg_reg,
6608                 (void *)&cmd_read_reg_port_id,
6609                 (void *)&cmd_read_reg_reg_off,
6610                 NULL,
6611         },
6612 };
6613
6614 /* *** READ PORT REGISTER BIT FIELD *** */
6615 struct cmd_read_reg_bit_field_result {
6616         cmdline_fixed_string_t read;
6617         cmdline_fixed_string_t regfield;
6618         uint8_t port_id;
6619         uint32_t reg_off;
6620         uint8_t bit1_pos;
6621         uint8_t bit2_pos;
6622 };
6623
6624 static void
6625 cmd_read_reg_bit_field_parsed(void *parsed_result,
6626                               __attribute__((unused)) struct cmdline *cl,
6627                               __attribute__((unused)) void *data)
6628 {
6629         struct cmd_read_reg_bit_field_result *res = parsed_result;
6630         port_reg_bit_field_display(res->port_id, res->reg_off,
6631                                    res->bit1_pos, res->bit2_pos);
6632 }
6633
6634 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6635         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6636                                  "read");
6637 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6638         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6639                                  regfield, "regfield");
6640 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6641         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6642                               UINT8);
6643 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6644         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6645                               UINT32);
6646 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6647         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6648                               UINT8);
6649 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6650         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6651                               UINT8);
6652
6653 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6654         .f = cmd_read_reg_bit_field_parsed,
6655         .data = NULL,
6656         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6657         "Read register bit field between bit_x and bit_y included",
6658         .tokens = {
6659                 (void *)&cmd_read_reg_bit_field_read,
6660                 (void *)&cmd_read_reg_bit_field_regfield,
6661                 (void *)&cmd_read_reg_bit_field_port_id,
6662                 (void *)&cmd_read_reg_bit_field_reg_off,
6663                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6664                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6665                 NULL,
6666         },
6667 };
6668
6669 /* *** READ PORT REGISTER BIT *** */
6670 struct cmd_read_reg_bit_result {
6671         cmdline_fixed_string_t read;
6672         cmdline_fixed_string_t regbit;
6673         uint8_t port_id;
6674         uint32_t reg_off;
6675         uint8_t bit_pos;
6676 };
6677
6678 static void
6679 cmd_read_reg_bit_parsed(void *parsed_result,
6680                         __attribute__((unused)) struct cmdline *cl,
6681                         __attribute__((unused)) void *data)
6682 {
6683         struct cmd_read_reg_bit_result *res = parsed_result;
6684         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6685 }
6686
6687 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6688         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6689 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6690         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6691                                  regbit, "regbit");
6692 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6693         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6694 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6695         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6696 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6697         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6698
6699 cmdline_parse_inst_t cmd_read_reg_bit = {
6700         .f = cmd_read_reg_bit_parsed,
6701         .data = NULL,
6702         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6703         .tokens = {
6704                 (void *)&cmd_read_reg_bit_read,
6705                 (void *)&cmd_read_reg_bit_regbit,
6706                 (void *)&cmd_read_reg_bit_port_id,
6707                 (void *)&cmd_read_reg_bit_reg_off,
6708                 (void *)&cmd_read_reg_bit_bit_pos,
6709                 NULL,
6710         },
6711 };
6712
6713 /* *** WRITE PORT REGISTER *** */
6714 struct cmd_write_reg_result {
6715         cmdline_fixed_string_t write;
6716         cmdline_fixed_string_t reg;
6717         uint8_t port_id;
6718         uint32_t reg_off;
6719         uint32_t value;
6720 };
6721
6722 static void
6723 cmd_write_reg_parsed(void *parsed_result,
6724                      __attribute__((unused)) struct cmdline *cl,
6725                      __attribute__((unused)) void *data)
6726 {
6727         struct cmd_write_reg_result *res = parsed_result;
6728         port_reg_set(res->port_id, res->reg_off, res->value);
6729 }
6730
6731 cmdline_parse_token_string_t cmd_write_reg_write =
6732         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6733 cmdline_parse_token_string_t cmd_write_reg_reg =
6734         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6735 cmdline_parse_token_num_t cmd_write_reg_port_id =
6736         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6737 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6738         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6739 cmdline_parse_token_num_t cmd_write_reg_value =
6740         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6741
6742 cmdline_parse_inst_t cmd_write_reg = {
6743         .f = cmd_write_reg_parsed,
6744         .data = NULL,
6745         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6746         .tokens = {
6747                 (void *)&cmd_write_reg_write,
6748                 (void *)&cmd_write_reg_reg,
6749                 (void *)&cmd_write_reg_port_id,
6750                 (void *)&cmd_write_reg_reg_off,
6751                 (void *)&cmd_write_reg_value,
6752                 NULL,
6753         },
6754 };
6755
6756 /* *** WRITE PORT REGISTER BIT FIELD *** */
6757 struct cmd_write_reg_bit_field_result {
6758         cmdline_fixed_string_t write;
6759         cmdline_fixed_string_t regfield;
6760         uint8_t port_id;
6761         uint32_t reg_off;
6762         uint8_t bit1_pos;
6763         uint8_t bit2_pos;
6764         uint32_t value;
6765 };
6766
6767 static void
6768 cmd_write_reg_bit_field_parsed(void *parsed_result,
6769                                __attribute__((unused)) struct cmdline *cl,
6770                                __attribute__((unused)) void *data)
6771 {
6772         struct cmd_write_reg_bit_field_result *res = parsed_result;
6773         port_reg_bit_field_set(res->port_id, res->reg_off,
6774                           res->bit1_pos, res->bit2_pos, res->value);
6775 }
6776
6777 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6778         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6779                                  "write");
6780 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6781         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6782                                  regfield, "regfield");
6783 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6784         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6785                               UINT8);
6786 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6787         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6788                               UINT32);
6789 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6790         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6791                               UINT8);
6792 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6793         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6794                               UINT8);
6795 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6796         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6797                               UINT32);
6798
6799 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6800         .f = cmd_write_reg_bit_field_parsed,
6801         .data = NULL,
6802         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6803                 "<reg_value>: "
6804                 "Set register bit field between bit_x and bit_y included",
6805         .tokens = {
6806                 (void *)&cmd_write_reg_bit_field_write,
6807                 (void *)&cmd_write_reg_bit_field_regfield,
6808                 (void *)&cmd_write_reg_bit_field_port_id,
6809                 (void *)&cmd_write_reg_bit_field_reg_off,
6810                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6811                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6812                 (void *)&cmd_write_reg_bit_field_value,
6813                 NULL,
6814         },
6815 };
6816
6817 /* *** WRITE PORT REGISTER BIT *** */
6818 struct cmd_write_reg_bit_result {
6819         cmdline_fixed_string_t write;
6820         cmdline_fixed_string_t regbit;
6821         uint8_t port_id;
6822         uint32_t reg_off;
6823         uint8_t bit_pos;
6824         uint8_t value;
6825 };
6826
6827 static void
6828 cmd_write_reg_bit_parsed(void *parsed_result,
6829                          __attribute__((unused)) struct cmdline *cl,
6830                          __attribute__((unused)) void *data)
6831 {
6832         struct cmd_write_reg_bit_result *res = parsed_result;
6833         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6834 }
6835
6836 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6837         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6838                                  "write");
6839 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6840         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6841                                  regbit, "regbit");
6842 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6843         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6844 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6845         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6846 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6847         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6848 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6849         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6850
6851 cmdline_parse_inst_t cmd_write_reg_bit = {
6852         .f = cmd_write_reg_bit_parsed,
6853         .data = NULL,
6854         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6855                 "0 <= bit_x <= 31",
6856         .tokens = {
6857                 (void *)&cmd_write_reg_bit_write,
6858                 (void *)&cmd_write_reg_bit_regbit,
6859                 (void *)&cmd_write_reg_bit_port_id,
6860                 (void *)&cmd_write_reg_bit_reg_off,
6861                 (void *)&cmd_write_reg_bit_bit_pos,
6862                 (void *)&cmd_write_reg_bit_value,
6863                 NULL,
6864         },
6865 };
6866
6867 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6868 struct cmd_read_rxd_txd_result {
6869         cmdline_fixed_string_t read;
6870         cmdline_fixed_string_t rxd_txd;
6871         uint8_t port_id;
6872         uint16_t queue_id;
6873         uint16_t desc_id;
6874 };
6875
6876 static void
6877 cmd_read_rxd_txd_parsed(void *parsed_result,
6878                         __attribute__((unused)) struct cmdline *cl,
6879                         __attribute__((unused)) void *data)
6880 {
6881         struct cmd_read_rxd_txd_result *res = parsed_result;
6882
6883         if (!strcmp(res->rxd_txd, "rxd"))
6884                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6885         else if (!strcmp(res->rxd_txd, "txd"))
6886                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6887 }
6888
6889 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6890         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6891 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6892         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6893                                  "rxd#txd");
6894 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6895         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6896 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6897         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6898 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6899         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6900
6901 cmdline_parse_inst_t cmd_read_rxd_txd = {
6902         .f = cmd_read_rxd_txd_parsed,
6903         .data = NULL,
6904         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6905         .tokens = {
6906                 (void *)&cmd_read_rxd_txd_read,
6907                 (void *)&cmd_read_rxd_txd_rxd_txd,
6908                 (void *)&cmd_read_rxd_txd_port_id,
6909                 (void *)&cmd_read_rxd_txd_queue_id,
6910                 (void *)&cmd_read_rxd_txd_desc_id,
6911                 NULL,
6912         },
6913 };
6914
6915 /* *** QUIT *** */
6916 struct cmd_quit_result {
6917         cmdline_fixed_string_t quit;
6918 };
6919
6920 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6921                             struct cmdline *cl,
6922                             __attribute__((unused)) void *data)
6923 {
6924         pmd_test_exit();
6925         cmdline_quit(cl);
6926 }
6927
6928 cmdline_parse_token_string_t cmd_quit_quit =
6929         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6930
6931 cmdline_parse_inst_t cmd_quit = {
6932         .f = cmd_quit_parsed,
6933         .data = NULL,
6934         .help_str = "quit: Exit application",
6935         .tokens = {
6936                 (void *)&cmd_quit_quit,
6937                 NULL,
6938         },
6939 };
6940
6941 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6942 struct cmd_mac_addr_result {
6943         cmdline_fixed_string_t mac_addr_cmd;
6944         cmdline_fixed_string_t what;
6945         uint8_t port_num;
6946         struct ether_addr address;
6947 };
6948
6949 static void cmd_mac_addr_parsed(void *parsed_result,
6950                 __attribute__((unused)) struct cmdline *cl,
6951                 __attribute__((unused)) void *data)
6952 {
6953         struct cmd_mac_addr_result *res = parsed_result;
6954         int ret;
6955
6956         if (strcmp(res->what, "add") == 0)
6957                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6958         else if (strcmp(res->what, "set") == 0)
6959                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6960                                                        &res->address);
6961         else
6962                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6963
6964         /* check the return value and print it if is < 0 */
6965         if(ret < 0)
6966                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6967
6968 }
6969
6970 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6971         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6972                                 "mac_addr");
6973 cmdline_parse_token_string_t cmd_mac_addr_what =
6974         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6975                                 "add#remove#set");
6976 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6977                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6978 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6979                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6980
6981 cmdline_parse_inst_t cmd_mac_addr = {
6982         .f = cmd_mac_addr_parsed,
6983         .data = (void *)0,
6984         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6985                         "Add/Remove/Set MAC address on port_id",
6986         .tokens = {
6987                 (void *)&cmd_mac_addr_cmd,
6988                 (void *)&cmd_mac_addr_what,
6989                 (void *)&cmd_mac_addr_portnum,
6990                 (void *)&cmd_mac_addr_addr,
6991                 NULL,
6992         },
6993 };
6994
6995
6996 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6997 struct cmd_set_qmap_result {
6998         cmdline_fixed_string_t set;
6999         cmdline_fixed_string_t qmap;
7000         cmdline_fixed_string_t what;
7001         uint8_t port_id;
7002         uint16_t queue_id;
7003         uint8_t map_value;
7004 };
7005
7006 static void
7007 cmd_set_qmap_parsed(void *parsed_result,
7008                        __attribute__((unused)) struct cmdline *cl,
7009                        __attribute__((unused)) void *data)
7010 {
7011         struct cmd_set_qmap_result *res = parsed_result;
7012         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7013
7014         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7015 }
7016
7017 cmdline_parse_token_string_t cmd_setqmap_set =
7018         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7019                                  set, "set");
7020 cmdline_parse_token_string_t cmd_setqmap_qmap =
7021         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7022                                  qmap, "stat_qmap");
7023 cmdline_parse_token_string_t cmd_setqmap_what =
7024         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7025                                  what, "tx#rx");
7026 cmdline_parse_token_num_t cmd_setqmap_portid =
7027         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7028                               port_id, UINT8);
7029 cmdline_parse_token_num_t cmd_setqmap_queueid =
7030         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7031                               queue_id, UINT16);
7032 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7033         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7034                               map_value, UINT8);
7035
7036 cmdline_parse_inst_t cmd_set_qmap = {
7037         .f = cmd_set_qmap_parsed,
7038         .data = NULL,
7039         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7040                 "Set statistics mapping value on tx|rx queue_id of port_id",
7041         .tokens = {
7042                 (void *)&cmd_setqmap_set,
7043                 (void *)&cmd_setqmap_qmap,
7044                 (void *)&cmd_setqmap_what,
7045                 (void *)&cmd_setqmap_portid,
7046                 (void *)&cmd_setqmap_queueid,
7047                 (void *)&cmd_setqmap_mapvalue,
7048                 NULL,
7049         },
7050 };
7051
7052 /* *** CONFIGURE UNICAST HASH TABLE *** */
7053 struct cmd_set_uc_hash_table {
7054         cmdline_fixed_string_t set;
7055         cmdline_fixed_string_t port;
7056         uint8_t port_id;
7057         cmdline_fixed_string_t what;
7058         struct ether_addr address;
7059         cmdline_fixed_string_t mode;
7060 };
7061
7062 static void
7063 cmd_set_uc_hash_parsed(void *parsed_result,
7064                        __attribute__((unused)) struct cmdline *cl,
7065                        __attribute__((unused)) void *data)
7066 {
7067         int ret=0;
7068         struct cmd_set_uc_hash_table *res = parsed_result;
7069
7070         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7071
7072         if (strcmp(res->what, "uta") == 0)
7073                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7074                                                 &res->address,(uint8_t)is_on);
7075         if (ret < 0)
7076                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7077
7078 }
7079
7080 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7081         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7082                                  set, "set");
7083 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7084         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7085                                  port, "port");
7086 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7087         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7088                               port_id, UINT8);
7089 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7090         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7091                                  what, "uta");
7092 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7093         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7094                                 address);
7095 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7096         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7097                                  mode, "on#off");
7098
7099 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7100         .f = cmd_set_uc_hash_parsed,
7101         .data = NULL,
7102         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7103         .tokens = {
7104                 (void *)&cmd_set_uc_hash_set,
7105                 (void *)&cmd_set_uc_hash_port,
7106                 (void *)&cmd_set_uc_hash_portid,
7107                 (void *)&cmd_set_uc_hash_what,
7108                 (void *)&cmd_set_uc_hash_mac,
7109                 (void *)&cmd_set_uc_hash_mode,
7110                 NULL,
7111         },
7112 };
7113
7114 struct cmd_set_uc_all_hash_table {
7115         cmdline_fixed_string_t set;
7116         cmdline_fixed_string_t port;
7117         uint8_t port_id;
7118         cmdline_fixed_string_t what;
7119         cmdline_fixed_string_t value;
7120         cmdline_fixed_string_t mode;
7121 };
7122
7123 static void
7124 cmd_set_uc_all_hash_parsed(void *parsed_result,
7125                        __attribute__((unused)) struct cmdline *cl,
7126                        __attribute__((unused)) void *data)
7127 {
7128         int ret=0;
7129         struct cmd_set_uc_all_hash_table *res = parsed_result;
7130
7131         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7132
7133         if ((strcmp(res->what, "uta") == 0) &&
7134                 (strcmp(res->value, "all") == 0))
7135                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7136         if (ret < 0)
7137                 printf("bad unicast hash table parameter,"
7138                         "return code = %d \n", ret);
7139 }
7140
7141 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7142         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7143                                  set, "set");
7144 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7145         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7146                                  port, "port");
7147 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7148         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7149                               port_id, UINT8);
7150 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7151         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7152                                  what, "uta");
7153 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7154         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7155                                 value,"all");
7156 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7157         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7158                                  mode, "on#off");
7159
7160 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7161         .f = cmd_set_uc_all_hash_parsed,
7162         .data = NULL,
7163         .help_str = "set port <port_id> uta all on|off",
7164         .tokens = {
7165                 (void *)&cmd_set_uc_all_hash_set,
7166                 (void *)&cmd_set_uc_all_hash_port,
7167                 (void *)&cmd_set_uc_all_hash_portid,
7168                 (void *)&cmd_set_uc_all_hash_what,
7169                 (void *)&cmd_set_uc_all_hash_value,
7170                 (void *)&cmd_set_uc_all_hash_mode,
7171                 NULL,
7172         },
7173 };
7174
7175 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7176 struct cmd_set_vf_macvlan_filter {
7177         cmdline_fixed_string_t set;
7178         cmdline_fixed_string_t port;
7179         uint8_t port_id;
7180         cmdline_fixed_string_t vf;
7181         uint8_t vf_id;
7182         struct ether_addr address;
7183         cmdline_fixed_string_t filter_type;
7184         cmdline_fixed_string_t mode;
7185 };
7186
7187 static void
7188 cmd_set_vf_macvlan_parsed(void *parsed_result,
7189                        __attribute__((unused)) struct cmdline *cl,
7190                        __attribute__((unused)) void *data)
7191 {
7192         int is_on, ret = 0;
7193         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7194         struct rte_eth_mac_filter filter;
7195
7196         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7197
7198         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7199
7200         /* set VF MAC filter */
7201         filter.is_vf = 1;
7202
7203         /* set VF ID */
7204         filter.dst_id = res->vf_id;
7205
7206         if (!strcmp(res->filter_type, "exact-mac"))
7207                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7208         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7209                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7210         else if (!strcmp(res->filter_type, "hashmac"))
7211                 filter.filter_type = RTE_MAC_HASH_MATCH;
7212         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7213                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7214
7215         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7216
7217         if (is_on)
7218                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7219                                         RTE_ETH_FILTER_MACVLAN,
7220                                         RTE_ETH_FILTER_ADD,
7221                                          &filter);
7222         else
7223                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7224                                         RTE_ETH_FILTER_MACVLAN,
7225                                         RTE_ETH_FILTER_DELETE,
7226                                         &filter);
7227
7228         if (ret < 0)
7229                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7230
7231 }
7232
7233 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7234         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7235                                  set, "set");
7236 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7237         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7238                                  port, "port");
7239 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7240         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7241                               port_id, UINT8);
7242 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7243         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7244                                  vf, "vf");
7245 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7246         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7247                                 vf_id, UINT8);
7248 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7249         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7250                                 address);
7251 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7252         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7253                                 filter_type, "exact-mac#exact-mac-vlan"
7254                                 "#hashmac#hashmac-vlan");
7255 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7256         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7257                                  mode, "on#off");
7258
7259 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7260         .f = cmd_set_vf_macvlan_parsed,
7261         .data = NULL,
7262         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7263                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7264                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7265                 "hash match rule: hash match of MAC and exact match of VLAN",
7266         .tokens = {
7267                 (void *)&cmd_set_vf_macvlan_set,
7268                 (void *)&cmd_set_vf_macvlan_port,
7269                 (void *)&cmd_set_vf_macvlan_portid,
7270                 (void *)&cmd_set_vf_macvlan_vf,
7271                 (void *)&cmd_set_vf_macvlan_vf_id,
7272                 (void *)&cmd_set_vf_macvlan_mac,
7273                 (void *)&cmd_set_vf_macvlan_filter_type,
7274                 (void *)&cmd_set_vf_macvlan_mode,
7275                 NULL,
7276         },
7277 };
7278
7279 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7280 struct cmd_set_vf_traffic {
7281         cmdline_fixed_string_t set;
7282         cmdline_fixed_string_t port;
7283         uint8_t port_id;
7284         cmdline_fixed_string_t vf;
7285         uint8_t vf_id;
7286         cmdline_fixed_string_t what;
7287         cmdline_fixed_string_t mode;
7288 };
7289
7290 static void
7291 cmd_set_vf_traffic_parsed(void *parsed_result,
7292                        __attribute__((unused)) struct cmdline *cl,
7293                        __attribute__((unused)) void *data)
7294 {
7295         struct cmd_set_vf_traffic *res = parsed_result;
7296         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7297         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7298
7299         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7300 }
7301
7302 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7303         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7304                                  set, "set");
7305 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7306         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7307                                  port, "port");
7308 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7309         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7310                               port_id, UINT8);
7311 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7312         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7313                                  vf, "vf");
7314 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7315         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7316                               vf_id, UINT8);
7317 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7318         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7319                                  what, "tx#rx");
7320 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7321         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7322                                  mode, "on#off");
7323
7324 cmdline_parse_inst_t cmd_set_vf_traffic = {
7325         .f = cmd_set_vf_traffic_parsed,
7326         .data = NULL,
7327         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7328         .tokens = {
7329                 (void *)&cmd_setvf_traffic_set,
7330                 (void *)&cmd_setvf_traffic_port,
7331                 (void *)&cmd_setvf_traffic_portid,
7332                 (void *)&cmd_setvf_traffic_vf,
7333                 (void *)&cmd_setvf_traffic_vfid,
7334                 (void *)&cmd_setvf_traffic_what,
7335                 (void *)&cmd_setvf_traffic_mode,
7336                 NULL,
7337         },
7338 };
7339
7340 /* *** CONFIGURE VF RECEIVE MODE *** */
7341 struct cmd_set_vf_rxmode {
7342         cmdline_fixed_string_t set;
7343         cmdline_fixed_string_t port;
7344         uint8_t port_id;
7345         cmdline_fixed_string_t vf;
7346         uint8_t vf_id;
7347         cmdline_fixed_string_t what;
7348         cmdline_fixed_string_t mode;
7349         cmdline_fixed_string_t on;
7350 };
7351
7352 static void
7353 cmd_set_vf_rxmode_parsed(void *parsed_result,
7354                        __attribute__((unused)) struct cmdline *cl,
7355                        __attribute__((unused)) void *data)
7356 {
7357         int ret = -ENOTSUP;
7358         uint16_t rx_mode = 0;
7359         struct cmd_set_vf_rxmode *res = parsed_result;
7360
7361         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7362         if (!strcmp(res->what,"rxmode")) {
7363                 if (!strcmp(res->mode, "AUPE"))
7364                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7365                 else if (!strcmp(res->mode, "ROPE"))
7366                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7367                 else if (!strcmp(res->mode, "BAM"))
7368                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7369                 else if (!strncmp(res->mode, "MPE",3))
7370                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7371         }
7372
7373 #ifdef RTE_LIBRTE_IXGBE_PMD
7374         if (ret == -ENOTSUP)
7375                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7376                                                   rx_mode, (uint8_t)is_on);
7377 #endif
7378 #ifdef RTE_LIBRTE_BNXT_PMD
7379         if (ret == -ENOTSUP)
7380                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7381                                                  rx_mode, (uint8_t)is_on);
7382 #endif
7383         if (ret < 0)
7384                 printf("bad VF receive mode parameter, return code = %d \n",
7385                 ret);
7386 }
7387
7388 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7389         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7390                                  set, "set");
7391 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7392         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7393                                  port, "port");
7394 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7395         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7396                               port_id, UINT8);
7397 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7398         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7399                                  vf, "vf");
7400 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7401         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7402                               vf_id, UINT8);
7403 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7404         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7405                                  what, "rxmode");
7406 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7407         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7408                                  mode, "AUPE#ROPE#BAM#MPE");
7409 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7410         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7411                                  on, "on#off");
7412
7413 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7414         .f = cmd_set_vf_rxmode_parsed,
7415         .data = NULL,
7416         .help_str = "set port <port_id> vf <vf_id> rxmode "
7417                 "AUPE|ROPE|BAM|MPE on|off",
7418         .tokens = {
7419                 (void *)&cmd_set_vf_rxmode_set,
7420                 (void *)&cmd_set_vf_rxmode_port,
7421                 (void *)&cmd_set_vf_rxmode_portid,
7422                 (void *)&cmd_set_vf_rxmode_vf,
7423                 (void *)&cmd_set_vf_rxmode_vfid,
7424                 (void *)&cmd_set_vf_rxmode_what,
7425                 (void *)&cmd_set_vf_rxmode_mode,
7426                 (void *)&cmd_set_vf_rxmode_on,
7427                 NULL,
7428         },
7429 };
7430
7431 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7432 struct cmd_vf_mac_addr_result {
7433         cmdline_fixed_string_t mac_addr_cmd;
7434         cmdline_fixed_string_t what;
7435         cmdline_fixed_string_t port;
7436         uint8_t port_num;
7437         cmdline_fixed_string_t vf;
7438         uint8_t vf_num;
7439         struct ether_addr address;
7440 };
7441
7442 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7443                 __attribute__((unused)) struct cmdline *cl,
7444                 __attribute__((unused)) void *data)
7445 {
7446         struct cmd_vf_mac_addr_result *res = parsed_result;
7447         int ret = -ENOTSUP;
7448
7449         if (strcmp(res->what, "add") != 0)
7450                 return;
7451
7452 #ifdef RTE_LIBRTE_I40E_PMD
7453         if (ret == -ENOTSUP)
7454                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7455                                                    &res->address);
7456 #endif
7457 #ifdef RTE_LIBRTE_BNXT_PMD
7458         if (ret == -ENOTSUP)
7459                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7460                                                 res->vf_num);
7461 #endif
7462
7463         if(ret < 0)
7464                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7465
7466 }
7467
7468 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7469         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7470                                 mac_addr_cmd,"mac_addr");
7471 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7472         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7473                                 what,"add");
7474 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7475         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7476                                 port,"port");
7477 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7478         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7479                                 port_num, UINT8);
7480 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7481         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7482                                 vf,"vf");
7483 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7484         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7485                                 vf_num, UINT8);
7486 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7487         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7488                                 address);
7489
7490 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7491         .f = cmd_vf_mac_addr_parsed,
7492         .data = (void *)0,
7493         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7494                 "Add MAC address filtering for a VF on port_id",
7495         .tokens = {
7496                 (void *)&cmd_vf_mac_addr_cmd,
7497                 (void *)&cmd_vf_mac_addr_what,
7498                 (void *)&cmd_vf_mac_addr_port,
7499                 (void *)&cmd_vf_mac_addr_portnum,
7500                 (void *)&cmd_vf_mac_addr_vf,
7501                 (void *)&cmd_vf_mac_addr_vfnum,
7502                 (void *)&cmd_vf_mac_addr_addr,
7503                 NULL,
7504         },
7505 };
7506
7507 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7508 struct cmd_vf_rx_vlan_filter {
7509         cmdline_fixed_string_t rx_vlan;
7510         cmdline_fixed_string_t what;
7511         uint16_t vlan_id;
7512         cmdline_fixed_string_t port;
7513         uint8_t port_id;
7514         cmdline_fixed_string_t vf;
7515         uint64_t vf_mask;
7516 };
7517
7518 static void
7519 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7520                           __attribute__((unused)) struct cmdline *cl,
7521                           __attribute__((unused)) void *data)
7522 {
7523         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7524         int ret = -ENOTSUP;
7525
7526         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7527
7528 #ifdef RTE_LIBRTE_IXGBE_PMD
7529         if (ret == -ENOTSUP)
7530                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7531                                 res->vlan_id, res->vf_mask, is_add);
7532 #endif
7533 #ifdef RTE_LIBRTE_I40E_PMD
7534         if (ret == -ENOTSUP)
7535                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7536                                 res->vlan_id, res->vf_mask, is_add);
7537 #endif
7538 #ifdef RTE_LIBRTE_BNXT_PMD
7539         if (ret == -ENOTSUP)
7540                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7541                                 res->vlan_id, res->vf_mask, is_add);
7542 #endif
7543
7544         switch (ret) {
7545         case 0:
7546                 break;
7547         case -EINVAL:
7548                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7549                                 res->vlan_id, res->vf_mask);
7550                 break;
7551         case -ENODEV:
7552                 printf("invalid port_id %d\n", res->port_id);
7553                 break;
7554         case -ENOTSUP:
7555                 printf("function not implemented or supported\n");
7556                 break;
7557         default:
7558                 printf("programming error: (%s)\n", strerror(-ret));
7559         }
7560 }
7561
7562 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7563         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7564                                  rx_vlan, "rx_vlan");
7565 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7566         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7567                                  what, "add#rm");
7568 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7569         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7570                               vlan_id, UINT16);
7571 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7572         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7573                                  port, "port");
7574 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7575         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7576                               port_id, UINT8);
7577 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7578         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7579                                  vf, "vf");
7580 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7581         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7582                               vf_mask, UINT64);
7583
7584 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7585         .f = cmd_vf_rx_vlan_filter_parsed,
7586         .data = NULL,
7587         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7588                 "(vf_mask = hexadecimal VF mask)",
7589         .tokens = {
7590                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7591                 (void *)&cmd_vf_rx_vlan_filter_what,
7592                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7593                 (void *)&cmd_vf_rx_vlan_filter_port,
7594                 (void *)&cmd_vf_rx_vlan_filter_portid,
7595                 (void *)&cmd_vf_rx_vlan_filter_vf,
7596                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7597                 NULL,
7598         },
7599 };
7600
7601 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7602 struct cmd_queue_rate_limit_result {
7603         cmdline_fixed_string_t set;
7604         cmdline_fixed_string_t port;
7605         uint8_t port_num;
7606         cmdline_fixed_string_t queue;
7607         uint8_t queue_num;
7608         cmdline_fixed_string_t rate;
7609         uint16_t rate_num;
7610 };
7611
7612 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7613                 __attribute__((unused)) struct cmdline *cl,
7614                 __attribute__((unused)) void *data)
7615 {
7616         struct cmd_queue_rate_limit_result *res = parsed_result;
7617         int ret = 0;
7618
7619         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7620                 && (strcmp(res->queue, "queue") == 0)
7621                 && (strcmp(res->rate, "rate") == 0))
7622                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7623                                         res->rate_num);
7624         if (ret < 0)
7625                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7626
7627 }
7628
7629 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7630         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7631                                 set, "set");
7632 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7633         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7634                                 port, "port");
7635 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7636         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7637                                 port_num, UINT8);
7638 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7639         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7640                                 queue, "queue");
7641 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7642         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7643                                 queue_num, UINT8);
7644 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7645         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7646                                 rate, "rate");
7647 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7648         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7649                                 rate_num, UINT16);
7650
7651 cmdline_parse_inst_t cmd_queue_rate_limit = {
7652         .f = cmd_queue_rate_limit_parsed,
7653         .data = (void *)0,
7654         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7655                 "Set rate limit for a queue on port_id",
7656         .tokens = {
7657                 (void *)&cmd_queue_rate_limit_set,
7658                 (void *)&cmd_queue_rate_limit_port,
7659                 (void *)&cmd_queue_rate_limit_portnum,
7660                 (void *)&cmd_queue_rate_limit_queue,
7661                 (void *)&cmd_queue_rate_limit_queuenum,
7662                 (void *)&cmd_queue_rate_limit_rate,
7663                 (void *)&cmd_queue_rate_limit_ratenum,
7664                 NULL,
7665         },
7666 };
7667
7668 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7669 struct cmd_vf_rate_limit_result {
7670         cmdline_fixed_string_t set;
7671         cmdline_fixed_string_t port;
7672         uint8_t port_num;
7673         cmdline_fixed_string_t vf;
7674         uint8_t vf_num;
7675         cmdline_fixed_string_t rate;
7676         uint16_t rate_num;
7677         cmdline_fixed_string_t q_msk;
7678         uint64_t q_msk_val;
7679 };
7680
7681 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7682                 __attribute__((unused)) struct cmdline *cl,
7683                 __attribute__((unused)) void *data)
7684 {
7685         struct cmd_vf_rate_limit_result *res = parsed_result;
7686         int ret = 0;
7687
7688         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7689                 && (strcmp(res->vf, "vf") == 0)
7690                 && (strcmp(res->rate, "rate") == 0)
7691                 && (strcmp(res->q_msk, "queue_mask") == 0))
7692                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7693                                         res->rate_num, res->q_msk_val);
7694         if (ret < 0)
7695                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7696
7697 }
7698
7699 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7700         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7701                                 set, "set");
7702 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7703         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7704                                 port, "port");
7705 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7706         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7707                                 port_num, UINT8);
7708 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7709         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7710                                 vf, "vf");
7711 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7712         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7713                                 vf_num, UINT8);
7714 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7715         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7716                                 rate, "rate");
7717 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7718         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7719                                 rate_num, UINT16);
7720 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7721         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7722                                 q_msk, "queue_mask");
7723 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7724         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7725                                 q_msk_val, UINT64);
7726
7727 cmdline_parse_inst_t cmd_vf_rate_limit = {
7728         .f = cmd_vf_rate_limit_parsed,
7729         .data = (void *)0,
7730         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7731                 "queue_mask <queue_mask_value>: "
7732                 "Set rate limit for queues of VF on port_id",
7733         .tokens = {
7734                 (void *)&cmd_vf_rate_limit_set,
7735                 (void *)&cmd_vf_rate_limit_port,
7736                 (void *)&cmd_vf_rate_limit_portnum,
7737                 (void *)&cmd_vf_rate_limit_vf,
7738                 (void *)&cmd_vf_rate_limit_vfnum,
7739                 (void *)&cmd_vf_rate_limit_rate,
7740                 (void *)&cmd_vf_rate_limit_ratenum,
7741                 (void *)&cmd_vf_rate_limit_q_msk,
7742                 (void *)&cmd_vf_rate_limit_q_msk_val,
7743                 NULL,
7744         },
7745 };
7746
7747 /* *** ADD TUNNEL FILTER OF A PORT *** */
7748 struct cmd_tunnel_filter_result {
7749         cmdline_fixed_string_t cmd;
7750         cmdline_fixed_string_t what;
7751         uint8_t port_id;
7752         struct ether_addr outer_mac;
7753         struct ether_addr inner_mac;
7754         cmdline_ipaddr_t ip_value;
7755         uint16_t inner_vlan;
7756         cmdline_fixed_string_t tunnel_type;
7757         cmdline_fixed_string_t filter_type;
7758         uint32_t tenant_id;
7759         uint16_t queue_num;
7760 };
7761
7762 static void
7763 cmd_tunnel_filter_parsed(void *parsed_result,
7764                           __attribute__((unused)) struct cmdline *cl,
7765                           __attribute__((unused)) void *data)
7766 {
7767         struct cmd_tunnel_filter_result *res = parsed_result;
7768         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7769         int ret = 0;
7770
7771         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7772
7773         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7774         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7775         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7776
7777         if (res->ip_value.family == AF_INET) {
7778                 tunnel_filter_conf.ip_addr.ipv4_addr =
7779                         res->ip_value.addr.ipv4.s_addr;
7780                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7781         } else {
7782                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7783                         &(res->ip_value.addr.ipv6),
7784                         sizeof(struct in6_addr));
7785                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7786         }
7787
7788         if (!strcmp(res->filter_type, "imac-ivlan"))
7789                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7790         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7791                 tunnel_filter_conf.filter_type =
7792                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7793         else if (!strcmp(res->filter_type, "imac-tenid"))
7794                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7795         else if (!strcmp(res->filter_type, "imac"))
7796                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7797         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7798                 tunnel_filter_conf.filter_type =
7799                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7800         else if (!strcmp(res->filter_type, "oip"))
7801                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7802         else if (!strcmp(res->filter_type, "iip"))
7803                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7804         else {
7805                 printf("The filter type is not supported");
7806                 return;
7807         }
7808
7809         if (!strcmp(res->tunnel_type, "vxlan"))
7810                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7811         else if (!strcmp(res->tunnel_type, "nvgre"))
7812                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7813         else if (!strcmp(res->tunnel_type, "ipingre"))
7814                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7815         else {
7816                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7817                 return;
7818         }
7819
7820         tunnel_filter_conf.tenant_id = res->tenant_id;
7821         tunnel_filter_conf.queue_id = res->queue_num;
7822         if (!strcmp(res->what, "add"))
7823                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7824                                         RTE_ETH_FILTER_TUNNEL,
7825                                         RTE_ETH_FILTER_ADD,
7826                                         &tunnel_filter_conf);
7827         else
7828                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7829                                         RTE_ETH_FILTER_TUNNEL,
7830                                         RTE_ETH_FILTER_DELETE,
7831                                         &tunnel_filter_conf);
7832         if (ret < 0)
7833                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7834                                 strerror(-ret));
7835
7836 }
7837 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7838         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7839         cmd, "tunnel_filter");
7840 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7841         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7842         what, "add#rm");
7843 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7844         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7845         port_id, UINT8);
7846 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7847         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7848         outer_mac);
7849 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7851         inner_mac);
7852 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7853         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7854         inner_vlan, UINT16);
7855 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7856         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7857         ip_value);
7858 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7859         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7860         tunnel_type, "vxlan#nvgre#ipingre");
7861
7862 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7863         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7864         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7865                 "imac#omac-imac-tenid");
7866 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7867         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7868         tenant_id, UINT32);
7869 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7870         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7871         queue_num, UINT16);
7872
7873 cmdline_parse_inst_t cmd_tunnel_filter = {
7874         .f = cmd_tunnel_filter_parsed,
7875         .data = (void *)0,
7876         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7877                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7878                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7879                 "<queue_id>: Add/Rm tunnel filter of a port",
7880         .tokens = {
7881                 (void *)&cmd_tunnel_filter_cmd,
7882                 (void *)&cmd_tunnel_filter_what,
7883                 (void *)&cmd_tunnel_filter_port_id,
7884                 (void *)&cmd_tunnel_filter_outer_mac,
7885                 (void *)&cmd_tunnel_filter_inner_mac,
7886                 (void *)&cmd_tunnel_filter_ip_value,
7887                 (void *)&cmd_tunnel_filter_innner_vlan,
7888                 (void *)&cmd_tunnel_filter_tunnel_type,
7889                 (void *)&cmd_tunnel_filter_filter_type,
7890                 (void *)&cmd_tunnel_filter_tenant_id,
7891                 (void *)&cmd_tunnel_filter_queue_num,
7892                 NULL,
7893         },
7894 };
7895
7896 /* *** CONFIGURE TUNNEL UDP PORT *** */
7897 struct cmd_tunnel_udp_config {
7898         cmdline_fixed_string_t cmd;
7899         cmdline_fixed_string_t what;
7900         uint16_t udp_port;
7901         uint8_t port_id;
7902 };
7903
7904 static void
7905 cmd_tunnel_udp_config_parsed(void *parsed_result,
7906                           __attribute__((unused)) struct cmdline *cl,
7907                           __attribute__((unused)) void *data)
7908 {
7909         struct cmd_tunnel_udp_config *res = parsed_result;
7910         struct rte_eth_udp_tunnel tunnel_udp;
7911         int ret;
7912
7913         tunnel_udp.udp_port = res->udp_port;
7914
7915         if (!strcmp(res->cmd, "rx_vxlan_port"))
7916                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7917
7918         if (!strcmp(res->what, "add"))
7919                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7920                                                       &tunnel_udp);
7921         else
7922                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7923                                                          &tunnel_udp);
7924
7925         if (ret < 0)
7926                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7927 }
7928
7929 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7930         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7931                                 cmd, "rx_vxlan_port");
7932 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7933         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7934                                 what, "add#rm");
7935 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7936         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7937                                 udp_port, UINT16);
7938 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7939         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7940                                 port_id, UINT8);
7941
7942 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7943         .f = cmd_tunnel_udp_config_parsed,
7944         .data = (void *)0,
7945         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7946                 "Add/Remove a tunneling UDP port filter",
7947         .tokens = {
7948                 (void *)&cmd_tunnel_udp_config_cmd,
7949                 (void *)&cmd_tunnel_udp_config_what,
7950                 (void *)&cmd_tunnel_udp_config_udp_port,
7951                 (void *)&cmd_tunnel_udp_config_port_id,
7952                 NULL,
7953         },
7954 };
7955
7956 /* *** GLOBAL CONFIG *** */
7957 struct cmd_global_config_result {
7958         cmdline_fixed_string_t cmd;
7959         uint8_t port_id;
7960         cmdline_fixed_string_t cfg_type;
7961         uint8_t len;
7962 };
7963
7964 static void
7965 cmd_global_config_parsed(void *parsed_result,
7966                          __attribute__((unused)) struct cmdline *cl,
7967                          __attribute__((unused)) void *data)
7968 {
7969         struct cmd_global_config_result *res = parsed_result;
7970         struct rte_eth_global_cfg conf;
7971         int ret;
7972
7973         memset(&conf, 0, sizeof(conf));
7974         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7975         conf.cfg.gre_key_len = res->len;
7976         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7977                                       RTE_ETH_FILTER_SET, &conf);
7978         if (ret != 0)
7979                 printf("Global config error\n");
7980 }
7981
7982 cmdline_parse_token_string_t cmd_global_config_cmd =
7983         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7984                 "global_config");
7985 cmdline_parse_token_num_t cmd_global_config_port_id =
7986         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7987 cmdline_parse_token_string_t cmd_global_config_type =
7988         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7989                 cfg_type, "gre-key-len");
7990 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7991         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7992                 len, UINT8);
7993
7994 cmdline_parse_inst_t cmd_global_config = {
7995         .f = cmd_global_config_parsed,
7996         .data = (void *)NULL,
7997         .help_str = "global_config <port_id> gre-key-len <key_len>",
7998         .tokens = {
7999                 (void *)&cmd_global_config_cmd,
8000                 (void *)&cmd_global_config_port_id,
8001                 (void *)&cmd_global_config_type,
8002                 (void *)&cmd_global_config_gre_key_len,
8003                 NULL,
8004         },
8005 };
8006
8007 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8008 struct cmd_set_mirror_mask_result {
8009         cmdline_fixed_string_t set;
8010         cmdline_fixed_string_t port;
8011         uint8_t port_id;
8012         cmdline_fixed_string_t mirror;
8013         uint8_t rule_id;
8014         cmdline_fixed_string_t what;
8015         cmdline_fixed_string_t value;
8016         cmdline_fixed_string_t dstpool;
8017         uint8_t dstpool_id;
8018         cmdline_fixed_string_t on;
8019 };
8020
8021 cmdline_parse_token_string_t cmd_mirror_mask_set =
8022         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8023                                 set, "set");
8024 cmdline_parse_token_string_t cmd_mirror_mask_port =
8025         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8026                                 port, "port");
8027 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8028         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8029                                 port_id, UINT8);
8030 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8031         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8032                                 mirror, "mirror-rule");
8033 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8034         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8035                                 rule_id, UINT8);
8036 cmdline_parse_token_string_t cmd_mirror_mask_what =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8038                                 what, "pool-mirror-up#pool-mirror-down"
8039                                       "#vlan-mirror");
8040 cmdline_parse_token_string_t cmd_mirror_mask_value =
8041         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8042                                 value, NULL);
8043 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8044         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8045                                 dstpool, "dst-pool");
8046 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8047         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8048                                 dstpool_id, UINT8);
8049 cmdline_parse_token_string_t cmd_mirror_mask_on =
8050         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8051                                 on, "on#off");
8052
8053 static void
8054 cmd_set_mirror_mask_parsed(void *parsed_result,
8055                        __attribute__((unused)) struct cmdline *cl,
8056                        __attribute__((unused)) void *data)
8057 {
8058         int ret,nb_item,i;
8059         struct cmd_set_mirror_mask_result *res = parsed_result;
8060         struct rte_eth_mirror_conf mr_conf;
8061
8062         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8063
8064         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8065
8066         mr_conf.dst_pool = res->dstpool_id;
8067
8068         if (!strcmp(res->what, "pool-mirror-up")) {
8069                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8070                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8071         } else if (!strcmp(res->what, "pool-mirror-down")) {
8072                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8073                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8074         } else if (!strcmp(res->what, "vlan-mirror")) {
8075                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8076                 nb_item = parse_item_list(res->value, "vlan",
8077                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8078                 if (nb_item <= 0)
8079                         return;
8080
8081                 for (i = 0; i < nb_item; i++) {
8082                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8083                                 printf("Invalid vlan_id: must be < 4096\n");
8084                                 return;
8085                         }
8086
8087                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8088                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8089                 }
8090         }
8091
8092         if (!strcmp(res->on, "on"))
8093                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8094                                                 res->rule_id, 1);
8095         else
8096                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8097                                                 res->rule_id, 0);
8098         if (ret < 0)
8099                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8100 }
8101
8102 cmdline_parse_inst_t cmd_set_mirror_mask = {
8103                 .f = cmd_set_mirror_mask_parsed,
8104                 .data = NULL,
8105                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8106                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8107                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8108                 .tokens = {
8109                         (void *)&cmd_mirror_mask_set,
8110                         (void *)&cmd_mirror_mask_port,
8111                         (void *)&cmd_mirror_mask_portid,
8112                         (void *)&cmd_mirror_mask_mirror,
8113                         (void *)&cmd_mirror_mask_ruleid,
8114                         (void *)&cmd_mirror_mask_what,
8115                         (void *)&cmd_mirror_mask_value,
8116                         (void *)&cmd_mirror_mask_dstpool,
8117                         (void *)&cmd_mirror_mask_poolid,
8118                         (void *)&cmd_mirror_mask_on,
8119                         NULL,
8120                 },
8121 };
8122
8123 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8124 struct cmd_set_mirror_link_result {
8125         cmdline_fixed_string_t set;
8126         cmdline_fixed_string_t port;
8127         uint8_t port_id;
8128         cmdline_fixed_string_t mirror;
8129         uint8_t rule_id;
8130         cmdline_fixed_string_t what;
8131         cmdline_fixed_string_t dstpool;
8132         uint8_t dstpool_id;
8133         cmdline_fixed_string_t on;
8134 };
8135
8136 cmdline_parse_token_string_t cmd_mirror_link_set =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8138                                  set, "set");
8139 cmdline_parse_token_string_t cmd_mirror_link_port =
8140         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8141                                 port, "port");
8142 cmdline_parse_token_num_t cmd_mirror_link_portid =
8143         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8144                                 port_id, UINT8);
8145 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8146         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8147                                 mirror, "mirror-rule");
8148 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8149         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8150                             rule_id, UINT8);
8151 cmdline_parse_token_string_t cmd_mirror_link_what =
8152         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8153                                 what, "uplink-mirror#downlink-mirror");
8154 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8155         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8156                                 dstpool, "dst-pool");
8157 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8158         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8159                                 dstpool_id, UINT8);
8160 cmdline_parse_token_string_t cmd_mirror_link_on =
8161         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8162                                 on, "on#off");
8163
8164 static void
8165 cmd_set_mirror_link_parsed(void *parsed_result,
8166                        __attribute__((unused)) struct cmdline *cl,
8167                        __attribute__((unused)) void *data)
8168 {
8169         int ret;
8170         struct cmd_set_mirror_link_result *res = parsed_result;
8171         struct rte_eth_mirror_conf mr_conf;
8172
8173         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8174         if (!strcmp(res->what, "uplink-mirror"))
8175                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8176         else
8177                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8178
8179         mr_conf.dst_pool = res->dstpool_id;
8180
8181         if (!strcmp(res->on, "on"))
8182                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8183                                                 res->rule_id, 1);
8184         else
8185                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8186                                                 res->rule_id, 0);
8187
8188         /* check the return value and print it if is < 0 */
8189         if (ret < 0)
8190                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8191
8192 }
8193
8194 cmdline_parse_inst_t cmd_set_mirror_link = {
8195                 .f = cmd_set_mirror_link_parsed,
8196                 .data = NULL,
8197                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8198                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8199                 .tokens = {
8200                         (void *)&cmd_mirror_link_set,
8201                         (void *)&cmd_mirror_link_port,
8202                         (void *)&cmd_mirror_link_portid,
8203                         (void *)&cmd_mirror_link_mirror,
8204                         (void *)&cmd_mirror_link_ruleid,
8205                         (void *)&cmd_mirror_link_what,
8206                         (void *)&cmd_mirror_link_dstpool,
8207                         (void *)&cmd_mirror_link_poolid,
8208                         (void *)&cmd_mirror_link_on,
8209                         NULL,
8210                 },
8211 };
8212
8213 /* *** RESET VM MIRROR RULE *** */
8214 struct cmd_rm_mirror_rule_result {
8215         cmdline_fixed_string_t reset;
8216         cmdline_fixed_string_t port;
8217         uint8_t port_id;
8218         cmdline_fixed_string_t mirror;
8219         uint8_t rule_id;
8220 };
8221
8222 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8223         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8224                                  reset, "reset");
8225 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8226         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8227                                 port, "port");
8228 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8229         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8230                                 port_id, UINT8);
8231 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8232         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8233                                 mirror, "mirror-rule");
8234 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8235         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8236                                 rule_id, UINT8);
8237
8238 static void
8239 cmd_reset_mirror_rule_parsed(void *parsed_result,
8240                        __attribute__((unused)) struct cmdline *cl,
8241                        __attribute__((unused)) void *data)
8242 {
8243         int ret;
8244         struct cmd_set_mirror_link_result *res = parsed_result;
8245         /* check rule_id */
8246         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8247         if(ret < 0)
8248                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8249 }
8250
8251 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8252                 .f = cmd_reset_mirror_rule_parsed,
8253                 .data = NULL,
8254                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8255                 .tokens = {
8256                         (void *)&cmd_rm_mirror_rule_reset,
8257                         (void *)&cmd_rm_mirror_rule_port,
8258                         (void *)&cmd_rm_mirror_rule_portid,
8259                         (void *)&cmd_rm_mirror_rule_mirror,
8260                         (void *)&cmd_rm_mirror_rule_ruleid,
8261                         NULL,
8262                 },
8263 };
8264
8265 /* ******************************************************************************** */
8266
8267 struct cmd_dump_result {
8268         cmdline_fixed_string_t dump;
8269 };
8270
8271 static void
8272 dump_struct_sizes(void)
8273 {
8274 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8275         DUMP_SIZE(struct rte_mbuf);
8276         DUMP_SIZE(struct rte_mempool);
8277         DUMP_SIZE(struct rte_ring);
8278 #undef DUMP_SIZE
8279 }
8280
8281 static void cmd_dump_parsed(void *parsed_result,
8282                             __attribute__((unused)) struct cmdline *cl,
8283                             __attribute__((unused)) void *data)
8284 {
8285         struct cmd_dump_result *res = parsed_result;
8286
8287         if (!strcmp(res->dump, "dump_physmem"))
8288                 rte_dump_physmem_layout(stdout);
8289         else if (!strcmp(res->dump, "dump_memzone"))
8290                 rte_memzone_dump(stdout);
8291         else if (!strcmp(res->dump, "dump_struct_sizes"))
8292                 dump_struct_sizes();
8293         else if (!strcmp(res->dump, "dump_ring"))
8294                 rte_ring_list_dump(stdout);
8295         else if (!strcmp(res->dump, "dump_mempool"))
8296                 rte_mempool_list_dump(stdout);
8297         else if (!strcmp(res->dump, "dump_devargs"))
8298                 rte_eal_devargs_dump(stdout);
8299         else if (!strcmp(res->dump, "dump_log_types"))
8300                 rte_log_dump(stdout);
8301 }
8302
8303 cmdline_parse_token_string_t cmd_dump_dump =
8304         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8305                 "dump_physmem#"
8306                 "dump_memzone#"
8307                 "dump_struct_sizes#"
8308                 "dump_ring#"
8309                 "dump_mempool#"
8310                 "dump_devargs#"
8311                 "dump_log_types");
8312
8313 cmdline_parse_inst_t cmd_dump = {
8314         .f = cmd_dump_parsed,  /* function to call */
8315         .data = NULL,      /* 2nd arg of func */
8316         .help_str = "Dump status",
8317         .tokens = {        /* token list, NULL terminated */
8318                 (void *)&cmd_dump_dump,
8319                 NULL,
8320         },
8321 };
8322
8323 /* ******************************************************************************** */
8324
8325 struct cmd_dump_one_result {
8326         cmdline_fixed_string_t dump;
8327         cmdline_fixed_string_t name;
8328 };
8329
8330 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8331                                 __attribute__((unused)) void *data)
8332 {
8333         struct cmd_dump_one_result *res = parsed_result;
8334
8335         if (!strcmp(res->dump, "dump_ring")) {
8336                 struct rte_ring *r;
8337                 r = rte_ring_lookup(res->name);
8338                 if (r == NULL) {
8339                         cmdline_printf(cl, "Cannot find ring\n");
8340                         return;
8341                 }
8342                 rte_ring_dump(stdout, r);
8343         } else if (!strcmp(res->dump, "dump_mempool")) {
8344                 struct rte_mempool *mp;
8345                 mp = rte_mempool_lookup(res->name);
8346                 if (mp == NULL) {
8347                         cmdline_printf(cl, "Cannot find mempool\n");
8348                         return;
8349                 }
8350                 rte_mempool_dump(stdout, mp);
8351         }
8352 }
8353
8354 cmdline_parse_token_string_t cmd_dump_one_dump =
8355         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8356                                  "dump_ring#dump_mempool");
8357
8358 cmdline_parse_token_string_t cmd_dump_one_name =
8359         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8360
8361 cmdline_parse_inst_t cmd_dump_one = {
8362         .f = cmd_dump_one_parsed,  /* function to call */
8363         .data = NULL,      /* 2nd arg of func */
8364         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8365         .tokens = {        /* token list, NULL terminated */
8366                 (void *)&cmd_dump_one_dump,
8367                 (void *)&cmd_dump_one_name,
8368                 NULL,
8369         },
8370 };
8371
8372 /* *** Add/Del syn filter *** */
8373 struct cmd_syn_filter_result {
8374         cmdline_fixed_string_t filter;
8375         uint8_t port_id;
8376         cmdline_fixed_string_t ops;
8377         cmdline_fixed_string_t priority;
8378         cmdline_fixed_string_t high;
8379         cmdline_fixed_string_t queue;
8380         uint16_t queue_id;
8381 };
8382
8383 static void
8384 cmd_syn_filter_parsed(void *parsed_result,
8385                         __attribute__((unused)) struct cmdline *cl,
8386                         __attribute__((unused)) void *data)
8387 {
8388         struct cmd_syn_filter_result *res = parsed_result;
8389         struct rte_eth_syn_filter syn_filter;
8390         int ret = 0;
8391
8392         ret = rte_eth_dev_filter_supported(res->port_id,
8393                                         RTE_ETH_FILTER_SYN);
8394         if (ret < 0) {
8395                 printf("syn filter is not supported on port %u.\n",
8396                                 res->port_id);
8397                 return;
8398         }
8399
8400         memset(&syn_filter, 0, sizeof(syn_filter));
8401
8402         if (!strcmp(res->ops, "add")) {
8403                 if (!strcmp(res->high, "high"))
8404                         syn_filter.hig_pri = 1;
8405                 else
8406                         syn_filter.hig_pri = 0;
8407
8408                 syn_filter.queue = res->queue_id;
8409                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8410                                                 RTE_ETH_FILTER_SYN,
8411                                                 RTE_ETH_FILTER_ADD,
8412                                                 &syn_filter);
8413         } else
8414                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8415                                                 RTE_ETH_FILTER_SYN,
8416                                                 RTE_ETH_FILTER_DELETE,
8417                                                 &syn_filter);
8418
8419         if (ret < 0)
8420                 printf("syn filter programming error: (%s)\n",
8421                                 strerror(-ret));
8422 }
8423
8424 cmdline_parse_token_string_t cmd_syn_filter_filter =
8425         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8426         filter, "syn_filter");
8427 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8428         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8429         port_id, UINT8);
8430 cmdline_parse_token_string_t cmd_syn_filter_ops =
8431         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8432         ops, "add#del");
8433 cmdline_parse_token_string_t cmd_syn_filter_priority =
8434         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8435                                 priority, "priority");
8436 cmdline_parse_token_string_t cmd_syn_filter_high =
8437         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8438                                 high, "high#low");
8439 cmdline_parse_token_string_t cmd_syn_filter_queue =
8440         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8441                                 queue, "queue");
8442 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8443         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8444                                 queue_id, UINT16);
8445
8446 cmdline_parse_inst_t cmd_syn_filter = {
8447         .f = cmd_syn_filter_parsed,
8448         .data = NULL,
8449         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8450                 "<queue_id>: Add/Delete syn filter",
8451         .tokens = {
8452                 (void *)&cmd_syn_filter_filter,
8453                 (void *)&cmd_syn_filter_port_id,
8454                 (void *)&cmd_syn_filter_ops,
8455                 (void *)&cmd_syn_filter_priority,
8456                 (void *)&cmd_syn_filter_high,
8457                 (void *)&cmd_syn_filter_queue,
8458                 (void *)&cmd_syn_filter_queue_id,
8459                 NULL,
8460         },
8461 };
8462
8463 /* *** ADD/REMOVE A 2tuple FILTER *** */
8464 struct cmd_2tuple_filter_result {
8465         cmdline_fixed_string_t filter;
8466         uint8_t  port_id;
8467         cmdline_fixed_string_t ops;
8468         cmdline_fixed_string_t dst_port;
8469         uint16_t dst_port_value;
8470         cmdline_fixed_string_t protocol;
8471         uint8_t protocol_value;
8472         cmdline_fixed_string_t mask;
8473         uint8_t  mask_value;
8474         cmdline_fixed_string_t tcp_flags;
8475         uint8_t tcp_flags_value;
8476         cmdline_fixed_string_t priority;
8477         uint8_t  priority_value;
8478         cmdline_fixed_string_t queue;
8479         uint16_t  queue_id;
8480 };
8481
8482 static void
8483 cmd_2tuple_filter_parsed(void *parsed_result,
8484                         __attribute__((unused)) struct cmdline *cl,
8485                         __attribute__((unused)) void *data)
8486 {
8487         struct rte_eth_ntuple_filter filter;
8488         struct cmd_2tuple_filter_result *res = parsed_result;
8489         int ret = 0;
8490
8491         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8492         if (ret < 0) {
8493                 printf("ntuple filter is not supported on port %u.\n",
8494                         res->port_id);
8495                 return;
8496         }
8497
8498         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8499
8500         filter.flags = RTE_2TUPLE_FLAGS;
8501         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8502         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8503         filter.proto = res->protocol_value;
8504         filter.priority = res->priority_value;
8505         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8506                 printf("nonzero tcp_flags is only meaningful"
8507                         " when protocol is TCP.\n");
8508                 return;
8509         }
8510         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8511                 printf("invalid TCP flags.\n");
8512                 return;
8513         }
8514
8515         if (res->tcp_flags_value != 0) {
8516                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8517                 filter.tcp_flags = res->tcp_flags_value;
8518         }
8519
8520         /* need convert to big endian. */
8521         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8522         filter.queue = res->queue_id;
8523
8524         if (!strcmp(res->ops, "add"))
8525                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8526                                 RTE_ETH_FILTER_NTUPLE,
8527                                 RTE_ETH_FILTER_ADD,
8528                                 &filter);
8529         else
8530                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8531                                 RTE_ETH_FILTER_NTUPLE,
8532                                 RTE_ETH_FILTER_DELETE,
8533                                 &filter);
8534         if (ret < 0)
8535                 printf("2tuple filter programming error: (%s)\n",
8536                         strerror(-ret));
8537
8538 }
8539
8540 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8541         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8542                                  filter, "2tuple_filter");
8543 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8544         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8545                                 port_id, UINT8);
8546 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8547         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8548                                  ops, "add#del");
8549 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8550         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8551                                 dst_port, "dst_port");
8552 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8553         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8554                                 dst_port_value, UINT16);
8555 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8556         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8557                                 protocol, "protocol");
8558 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8559         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8560                                 protocol_value, UINT8);
8561 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8562         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8563                                 mask, "mask");
8564 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8565         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8566                                 mask_value, INT8);
8567 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8568         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8569                                 tcp_flags, "tcp_flags");
8570 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8571         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8572                                 tcp_flags_value, UINT8);
8573 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8574         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8575                                 priority, "priority");
8576 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8577         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8578                                 priority_value, UINT8);
8579 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8580         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8581                                 queue, "queue");
8582 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8583         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8584                                 queue_id, UINT16);
8585
8586 cmdline_parse_inst_t cmd_2tuple_filter = {
8587         .f = cmd_2tuple_filter_parsed,
8588         .data = NULL,
8589         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8590                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8591                 "<queue_id>: Add a 2tuple filter",
8592         .tokens = {
8593                 (void *)&cmd_2tuple_filter_filter,
8594                 (void *)&cmd_2tuple_filter_port_id,
8595                 (void *)&cmd_2tuple_filter_ops,
8596                 (void *)&cmd_2tuple_filter_dst_port,
8597                 (void *)&cmd_2tuple_filter_dst_port_value,
8598                 (void *)&cmd_2tuple_filter_protocol,
8599                 (void *)&cmd_2tuple_filter_protocol_value,
8600                 (void *)&cmd_2tuple_filter_mask,
8601                 (void *)&cmd_2tuple_filter_mask_value,
8602                 (void *)&cmd_2tuple_filter_tcp_flags,
8603                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8604                 (void *)&cmd_2tuple_filter_priority,
8605                 (void *)&cmd_2tuple_filter_priority_value,
8606                 (void *)&cmd_2tuple_filter_queue,
8607                 (void *)&cmd_2tuple_filter_queue_id,
8608                 NULL,
8609         },
8610 };
8611
8612 /* *** ADD/REMOVE A 5tuple FILTER *** */
8613 struct cmd_5tuple_filter_result {
8614         cmdline_fixed_string_t filter;
8615         uint8_t  port_id;
8616         cmdline_fixed_string_t ops;
8617         cmdline_fixed_string_t dst_ip;
8618         cmdline_ipaddr_t dst_ip_value;
8619         cmdline_fixed_string_t src_ip;
8620         cmdline_ipaddr_t src_ip_value;
8621         cmdline_fixed_string_t dst_port;
8622         uint16_t dst_port_value;
8623         cmdline_fixed_string_t src_port;
8624         uint16_t src_port_value;
8625         cmdline_fixed_string_t protocol;
8626         uint8_t protocol_value;
8627         cmdline_fixed_string_t mask;
8628         uint8_t  mask_value;
8629         cmdline_fixed_string_t tcp_flags;
8630         uint8_t tcp_flags_value;
8631         cmdline_fixed_string_t priority;
8632         uint8_t  priority_value;
8633         cmdline_fixed_string_t queue;
8634         uint16_t  queue_id;
8635 };
8636
8637 static void
8638 cmd_5tuple_filter_parsed(void *parsed_result,
8639                         __attribute__((unused)) struct cmdline *cl,
8640                         __attribute__((unused)) void *data)
8641 {
8642         struct rte_eth_ntuple_filter filter;
8643         struct cmd_5tuple_filter_result *res = parsed_result;
8644         int ret = 0;
8645
8646         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8647         if (ret < 0) {
8648                 printf("ntuple filter is not supported on port %u.\n",
8649                         res->port_id);
8650                 return;
8651         }
8652
8653         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8654
8655         filter.flags = RTE_5TUPLE_FLAGS;
8656         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8657         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8658         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8659         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8660         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8661         filter.proto = res->protocol_value;
8662         filter.priority = res->priority_value;
8663         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8664                 printf("nonzero tcp_flags is only meaningful"
8665                         " when protocol is TCP.\n");
8666                 return;
8667         }
8668         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8669                 printf("invalid TCP flags.\n");
8670                 return;
8671         }
8672
8673         if (res->tcp_flags_value != 0) {
8674                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8675                 filter.tcp_flags = res->tcp_flags_value;
8676         }
8677
8678         if (res->dst_ip_value.family == AF_INET)
8679                 /* no need to convert, already big endian. */
8680                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8681         else {
8682                 if (filter.dst_ip_mask == 0) {
8683                         printf("can not support ipv6 involved compare.\n");
8684                         return;
8685                 }
8686                 filter.dst_ip = 0;
8687         }
8688
8689         if (res->src_ip_value.family == AF_INET)
8690                 /* no need to convert, already big endian. */
8691                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8692         else {
8693                 if (filter.src_ip_mask == 0) {
8694                         printf("can not support ipv6 involved compare.\n");
8695                         return;
8696                 }
8697                 filter.src_ip = 0;
8698         }
8699         /* need convert to big endian. */
8700         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8701         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8702         filter.queue = res->queue_id;
8703
8704         if (!strcmp(res->ops, "add"))
8705                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8706                                 RTE_ETH_FILTER_NTUPLE,
8707                                 RTE_ETH_FILTER_ADD,
8708                                 &filter);
8709         else
8710                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8711                                 RTE_ETH_FILTER_NTUPLE,
8712                                 RTE_ETH_FILTER_DELETE,
8713                                 &filter);
8714         if (ret < 0)
8715                 printf("5tuple filter programming error: (%s)\n",
8716                         strerror(-ret));
8717 }
8718
8719 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8720         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8721                                  filter, "5tuple_filter");
8722 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8723         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8724                                 port_id, UINT8);
8725 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8726         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8727                                  ops, "add#del");
8728 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8729         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8730                                 dst_ip, "dst_ip");
8731 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8732         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8733                                 dst_ip_value);
8734 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8735         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8736                                 src_ip, "src_ip");
8737 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8738         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8739                                 src_ip_value);
8740 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8741         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8742                                 dst_port, "dst_port");
8743 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8744         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8745                                 dst_port_value, UINT16);
8746 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8747         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8748                                 src_port, "src_port");
8749 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8750         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8751                                 src_port_value, UINT16);
8752 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8753         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8754                                 protocol, "protocol");
8755 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8756         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8757                                 protocol_value, UINT8);
8758 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8759         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8760                                 mask, "mask");
8761 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8762         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8763                                 mask_value, INT8);
8764 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8765         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8766                                 tcp_flags, "tcp_flags");
8767 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8768         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8769                                 tcp_flags_value, UINT8);
8770 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8771         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8772                                 priority, "priority");
8773 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8774         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8775                                 priority_value, UINT8);
8776 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8777         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8778                                 queue, "queue");
8779 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8780         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8781                                 queue_id, UINT16);
8782
8783 cmdline_parse_inst_t cmd_5tuple_filter = {
8784         .f = cmd_5tuple_filter_parsed,
8785         .data = NULL,
8786         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8787                 "src_ip <value> dst_port <value> src_port <value> "
8788                 "protocol <value>  mask <value> tcp_flags <value> "
8789                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8790         .tokens = {
8791                 (void *)&cmd_5tuple_filter_filter,
8792                 (void *)&cmd_5tuple_filter_port_id,
8793                 (void *)&cmd_5tuple_filter_ops,
8794                 (void *)&cmd_5tuple_filter_dst_ip,
8795                 (void *)&cmd_5tuple_filter_dst_ip_value,
8796                 (void *)&cmd_5tuple_filter_src_ip,
8797                 (void *)&cmd_5tuple_filter_src_ip_value,
8798                 (void *)&cmd_5tuple_filter_dst_port,
8799                 (void *)&cmd_5tuple_filter_dst_port_value,
8800                 (void *)&cmd_5tuple_filter_src_port,
8801                 (void *)&cmd_5tuple_filter_src_port_value,
8802                 (void *)&cmd_5tuple_filter_protocol,
8803                 (void *)&cmd_5tuple_filter_protocol_value,
8804                 (void *)&cmd_5tuple_filter_mask,
8805                 (void *)&cmd_5tuple_filter_mask_value,
8806                 (void *)&cmd_5tuple_filter_tcp_flags,
8807                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8808                 (void *)&cmd_5tuple_filter_priority,
8809                 (void *)&cmd_5tuple_filter_priority_value,
8810                 (void *)&cmd_5tuple_filter_queue,
8811                 (void *)&cmd_5tuple_filter_queue_id,
8812                 NULL,
8813         },
8814 };
8815
8816 /* *** ADD/REMOVE A flex FILTER *** */
8817 struct cmd_flex_filter_result {
8818         cmdline_fixed_string_t filter;
8819         cmdline_fixed_string_t ops;
8820         uint8_t port_id;
8821         cmdline_fixed_string_t len;
8822         uint8_t len_value;
8823         cmdline_fixed_string_t bytes;
8824         cmdline_fixed_string_t bytes_value;
8825         cmdline_fixed_string_t mask;
8826         cmdline_fixed_string_t mask_value;
8827         cmdline_fixed_string_t priority;
8828         uint8_t priority_value;
8829         cmdline_fixed_string_t queue;
8830         uint16_t queue_id;
8831 };
8832
8833 static int xdigit2val(unsigned char c)
8834 {
8835         int val;
8836         if (isdigit(c))
8837                 val = c - '0';
8838         else if (isupper(c))
8839                 val = c - 'A' + 10;
8840         else
8841                 val = c - 'a' + 10;
8842         return val;
8843 }
8844
8845 static void
8846 cmd_flex_filter_parsed(void *parsed_result,
8847                           __attribute__((unused)) struct cmdline *cl,
8848                           __attribute__((unused)) void *data)
8849 {
8850         int ret = 0;
8851         struct rte_eth_flex_filter filter;
8852         struct cmd_flex_filter_result *res = parsed_result;
8853         char *bytes_ptr, *mask_ptr;
8854         uint16_t len, i, j = 0;
8855         char c;
8856         int val;
8857         uint8_t byte = 0;
8858
8859         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8860                 printf("the len exceed the max length 128\n");
8861                 return;
8862         }
8863         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8864         filter.len = res->len_value;
8865         filter.priority = res->priority_value;
8866         filter.queue = res->queue_id;
8867         bytes_ptr = res->bytes_value;
8868         mask_ptr = res->mask_value;
8869
8870          /* translate bytes string to array. */
8871         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8872                 (bytes_ptr[1] == 'X')))
8873                 bytes_ptr += 2;
8874         len = strnlen(bytes_ptr, res->len_value * 2);
8875         if (len == 0 || (len % 8 != 0)) {
8876                 printf("please check len and bytes input\n");
8877                 return;
8878         }
8879         for (i = 0; i < len; i++) {
8880                 c = bytes_ptr[i];
8881                 if (isxdigit(c) == 0) {
8882                         /* invalid characters. */
8883                         printf("invalid input\n");
8884                         return;
8885                 }
8886                 val = xdigit2val(c);
8887                 if (i % 2) {
8888                         byte |= val;
8889                         filter.bytes[j] = byte;
8890                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8891                         j++;
8892                         byte = 0;
8893                 } else
8894                         byte |= val << 4;
8895         }
8896         printf("\n");
8897          /* translate mask string to uint8_t array. */
8898         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8899                 (mask_ptr[1] == 'X')))
8900                 mask_ptr += 2;
8901         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8902         if (len == 0) {
8903                 printf("invalid input\n");
8904                 return;
8905         }
8906         j = 0;
8907         byte = 0;
8908         for (i = 0; i < len; i++) {
8909                 c = mask_ptr[i];
8910                 if (isxdigit(c) == 0) {
8911                         /* invalid characters. */
8912                         printf("invalid input\n");
8913                         return;
8914                 }
8915                 val = xdigit2val(c);
8916                 if (i % 2) {
8917                         byte |= val;
8918                         filter.mask[j] = byte;
8919                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8920                         j++;
8921                         byte = 0;
8922                 } else
8923                         byte |= val << 4;
8924         }
8925         printf("\n");
8926
8927         if (!strcmp(res->ops, "add"))
8928                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8929                                 RTE_ETH_FILTER_FLEXIBLE,
8930                                 RTE_ETH_FILTER_ADD,
8931                                 &filter);
8932         else
8933                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8934                                 RTE_ETH_FILTER_FLEXIBLE,
8935                                 RTE_ETH_FILTER_DELETE,
8936                                 &filter);
8937
8938         if (ret < 0)
8939                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8940 }
8941
8942 cmdline_parse_token_string_t cmd_flex_filter_filter =
8943         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8944                                 filter, "flex_filter");
8945 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8946         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8947                                 port_id, UINT8);
8948 cmdline_parse_token_string_t cmd_flex_filter_ops =
8949         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8950                                 ops, "add#del");
8951 cmdline_parse_token_string_t cmd_flex_filter_len =
8952         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8953                                 len, "len");
8954 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8955         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8956                                 len_value, UINT8);
8957 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8958         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8959                                 bytes, "bytes");
8960 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8961         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8962                                 bytes_value, NULL);
8963 cmdline_parse_token_string_t cmd_flex_filter_mask =
8964         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8965                                 mask, "mask");
8966 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8967         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8968                                 mask_value, NULL);
8969 cmdline_parse_token_string_t cmd_flex_filter_priority =
8970         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8971                                 priority, "priority");
8972 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8973         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8974                                 priority_value, UINT8);
8975 cmdline_parse_token_string_t cmd_flex_filter_queue =
8976         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8977                                 queue, "queue");
8978 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8979         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8980                                 queue_id, UINT16);
8981 cmdline_parse_inst_t cmd_flex_filter = {
8982         .f = cmd_flex_filter_parsed,
8983         .data = NULL,
8984         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8985                 "<value> mask <value> priority <value> queue <queue_id>: "
8986                 "Add/Del a flex filter",
8987         .tokens = {
8988                 (void *)&cmd_flex_filter_filter,
8989                 (void *)&cmd_flex_filter_port_id,
8990                 (void *)&cmd_flex_filter_ops,
8991                 (void *)&cmd_flex_filter_len,
8992                 (void *)&cmd_flex_filter_len_value,
8993                 (void *)&cmd_flex_filter_bytes,
8994                 (void *)&cmd_flex_filter_bytes_value,
8995                 (void *)&cmd_flex_filter_mask,
8996                 (void *)&cmd_flex_filter_mask_value,
8997                 (void *)&cmd_flex_filter_priority,
8998                 (void *)&cmd_flex_filter_priority_value,
8999                 (void *)&cmd_flex_filter_queue,
9000                 (void *)&cmd_flex_filter_queue_id,
9001                 NULL,
9002         },
9003 };
9004
9005 /* *** Filters Control *** */
9006
9007 /* *** deal with ethertype filter *** */
9008 struct cmd_ethertype_filter_result {
9009         cmdline_fixed_string_t filter;
9010         uint8_t port_id;
9011         cmdline_fixed_string_t ops;
9012         cmdline_fixed_string_t mac;
9013         struct ether_addr mac_addr;
9014         cmdline_fixed_string_t ethertype;
9015         uint16_t ethertype_value;
9016         cmdline_fixed_string_t drop;
9017         cmdline_fixed_string_t queue;
9018         uint16_t  queue_id;
9019 };
9020
9021 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9022         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9023                                  filter, "ethertype_filter");
9024 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9025         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9026                               port_id, UINT8);
9027 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9028         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9029                                  ops, "add#del");
9030 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9031         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9032                                  mac, "mac_addr#mac_ignr");
9033 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9034         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9035                                      mac_addr);
9036 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9037         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9038                                  ethertype, "ethertype");
9039 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9040         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9041                               ethertype_value, UINT16);
9042 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9043         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9044                                  drop, "drop#fwd");
9045 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9046         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9047                                  queue, "queue");
9048 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9049         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9050                               queue_id, UINT16);
9051
9052 static void
9053 cmd_ethertype_filter_parsed(void *parsed_result,
9054                           __attribute__((unused)) struct cmdline *cl,
9055                           __attribute__((unused)) void *data)
9056 {
9057         struct cmd_ethertype_filter_result *res = parsed_result;
9058         struct rte_eth_ethertype_filter filter;
9059         int ret = 0;
9060
9061         ret = rte_eth_dev_filter_supported(res->port_id,
9062                         RTE_ETH_FILTER_ETHERTYPE);
9063         if (ret < 0) {
9064                 printf("ethertype filter is not supported on port %u.\n",
9065                         res->port_id);
9066                 return;
9067         }
9068
9069         memset(&filter, 0, sizeof(filter));
9070         if (!strcmp(res->mac, "mac_addr")) {
9071                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9072                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9073                         sizeof(struct ether_addr));
9074         }
9075         if (!strcmp(res->drop, "drop"))
9076                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9077         filter.ether_type = res->ethertype_value;
9078         filter.queue = res->queue_id;
9079
9080         if (!strcmp(res->ops, "add"))
9081                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9082                                 RTE_ETH_FILTER_ETHERTYPE,
9083                                 RTE_ETH_FILTER_ADD,
9084                                 &filter);
9085         else
9086                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9087                                 RTE_ETH_FILTER_ETHERTYPE,
9088                                 RTE_ETH_FILTER_DELETE,
9089                                 &filter);
9090         if (ret < 0)
9091                 printf("ethertype filter programming error: (%s)\n",
9092                         strerror(-ret));
9093 }
9094
9095 cmdline_parse_inst_t cmd_ethertype_filter = {
9096         .f = cmd_ethertype_filter_parsed,
9097         .data = NULL,
9098         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9099                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9100                 "Add or delete an ethertype filter entry",
9101         .tokens = {
9102                 (void *)&cmd_ethertype_filter_filter,
9103                 (void *)&cmd_ethertype_filter_port_id,
9104                 (void *)&cmd_ethertype_filter_ops,
9105                 (void *)&cmd_ethertype_filter_mac,
9106                 (void *)&cmd_ethertype_filter_mac_addr,
9107                 (void *)&cmd_ethertype_filter_ethertype,
9108                 (void *)&cmd_ethertype_filter_ethertype_value,
9109                 (void *)&cmd_ethertype_filter_drop,
9110                 (void *)&cmd_ethertype_filter_queue,
9111                 (void *)&cmd_ethertype_filter_queue_id,
9112                 NULL,
9113         },
9114 };
9115
9116 /* *** deal with flow director filter *** */
9117 struct cmd_flow_director_result {
9118         cmdline_fixed_string_t flow_director_filter;
9119         uint8_t port_id;
9120         cmdline_fixed_string_t mode;
9121         cmdline_fixed_string_t mode_value;
9122         cmdline_fixed_string_t ops;
9123         cmdline_fixed_string_t flow;
9124         cmdline_fixed_string_t flow_type;
9125         cmdline_fixed_string_t ether;
9126         uint16_t ether_type;
9127         cmdline_fixed_string_t src;
9128         cmdline_ipaddr_t ip_src;
9129         uint16_t port_src;
9130         cmdline_fixed_string_t dst;
9131         cmdline_ipaddr_t ip_dst;
9132         uint16_t port_dst;
9133         cmdline_fixed_string_t verify_tag;
9134         uint32_t verify_tag_value;
9135         cmdline_ipaddr_t tos;
9136         uint8_t tos_value;
9137         cmdline_ipaddr_t proto;
9138         uint8_t proto_value;
9139         cmdline_ipaddr_t ttl;
9140         uint8_t ttl_value;
9141         cmdline_fixed_string_t vlan;
9142         uint16_t vlan_value;
9143         cmdline_fixed_string_t flexbytes;
9144         cmdline_fixed_string_t flexbytes_value;
9145         cmdline_fixed_string_t pf_vf;
9146         cmdline_fixed_string_t drop;
9147         cmdline_fixed_string_t queue;
9148         uint16_t  queue_id;
9149         cmdline_fixed_string_t fd_id;
9150         uint32_t  fd_id_value;
9151         cmdline_fixed_string_t mac;
9152         struct ether_addr mac_addr;
9153         cmdline_fixed_string_t tunnel;
9154         cmdline_fixed_string_t tunnel_type;
9155         cmdline_fixed_string_t tunnel_id;
9156         uint32_t tunnel_id_value;
9157 };
9158
9159 static inline int
9160 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9161 {
9162         char s[256];
9163         const char *p, *p0 = q_arg;
9164         char *end;
9165         unsigned long int_fld;
9166         char *str_fld[max_num];
9167         int i;
9168         unsigned size;
9169         int ret = -1;
9170
9171         p = strchr(p0, '(');
9172         if (p == NULL)
9173                 return -1;
9174         ++p;
9175         p0 = strchr(p, ')');
9176         if (p0 == NULL)
9177                 return -1;
9178
9179         size = p0 - p;
9180         if (size >= sizeof(s))
9181                 return -1;
9182
9183         snprintf(s, sizeof(s), "%.*s", size, p);
9184         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9185         if (ret < 0 || ret > max_num)
9186                 return -1;
9187         for (i = 0; i < ret; i++) {
9188                 errno = 0;
9189                 int_fld = strtoul(str_fld[i], &end, 0);
9190                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9191                         return -1;
9192                 flexbytes[i] = (uint8_t)int_fld;
9193         }
9194         return ret;
9195 }
9196
9197 static uint16_t
9198 str2flowtype(char *string)
9199 {
9200         uint8_t i = 0;
9201         static const struct {
9202                 char str[32];
9203                 uint16_t type;
9204         } flowtype_str[] = {
9205                 {"raw", RTE_ETH_FLOW_RAW},
9206                 {"ipv4", RTE_ETH_FLOW_IPV4},
9207                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9208                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9209                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9210                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9211                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9212                 {"ipv6", RTE_ETH_FLOW_IPV6},
9213                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9214                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9215                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9216                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9217                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9218                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9219         };
9220
9221         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9222                 if (!strcmp(flowtype_str[i].str, string))
9223                         return flowtype_str[i].type;
9224         }
9225
9226         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9227                 return (uint16_t)atoi(string);
9228
9229         return RTE_ETH_FLOW_UNKNOWN;
9230 }
9231
9232 static enum rte_eth_fdir_tunnel_type
9233 str2fdir_tunneltype(char *string)
9234 {
9235         uint8_t i = 0;
9236
9237         static const struct {
9238                 char str[32];
9239                 enum rte_eth_fdir_tunnel_type type;
9240         } tunneltype_str[] = {
9241                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9242                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9243         };
9244
9245         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9246                 if (!strcmp(tunneltype_str[i].str, string))
9247                         return tunneltype_str[i].type;
9248         }
9249         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9250 }
9251
9252 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9253 do { \
9254         if ((ip_addr).family == AF_INET) \
9255                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9256         else { \
9257                 printf("invalid parameter.\n"); \
9258                 return; \
9259         } \
9260 } while (0)
9261
9262 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9263 do { \
9264         if ((ip_addr).family == AF_INET6) \
9265                 rte_memcpy(&(ip), \
9266                                  &((ip_addr).addr.ipv6), \
9267                                  sizeof(struct in6_addr)); \
9268         else { \
9269                 printf("invalid parameter.\n"); \
9270                 return; \
9271         } \
9272 } while (0)
9273
9274 static void
9275 cmd_flow_director_filter_parsed(void *parsed_result,
9276                           __attribute__((unused)) struct cmdline *cl,
9277                           __attribute__((unused)) void *data)
9278 {
9279         struct cmd_flow_director_result *res = parsed_result;
9280         struct rte_eth_fdir_filter entry;
9281         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9282         char *end;
9283         unsigned long vf_id;
9284         int ret = 0;
9285
9286         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9287         if (ret < 0) {
9288                 printf("flow director is not supported on port %u.\n",
9289                         res->port_id);
9290                 return;
9291         }
9292         memset(flexbytes, 0, sizeof(flexbytes));
9293         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9294
9295         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9296                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9297                         printf("Please set mode to MAC-VLAN.\n");
9298                         return;
9299                 }
9300         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9301                 if (strcmp(res->mode_value, "Tunnel")) {
9302                         printf("Please set mode to Tunnel.\n");
9303                         return;
9304                 }
9305         } else {
9306                 if (strcmp(res->mode_value, "IP")) {
9307                         printf("Please set mode to IP.\n");
9308                         return;
9309                 }
9310                 entry.input.flow_type = str2flowtype(res->flow_type);
9311         }
9312
9313         ret = parse_flexbytes(res->flexbytes_value,
9314                                         flexbytes,
9315                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9316         if (ret < 0) {
9317                 printf("error: Cannot parse flexbytes input.\n");
9318                 return;
9319         }
9320
9321         switch (entry.input.flow_type) {
9322         case RTE_ETH_FLOW_FRAG_IPV4:
9323         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9324                 entry.input.flow.ip4_flow.proto = res->proto_value;
9325                 /* fall-through */
9326         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9327         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9328                 IPV4_ADDR_TO_UINT(res->ip_dst,
9329                         entry.input.flow.ip4_flow.dst_ip);
9330                 IPV4_ADDR_TO_UINT(res->ip_src,
9331                         entry.input.flow.ip4_flow.src_ip);
9332                 entry.input.flow.ip4_flow.tos = res->tos_value;
9333                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9334                 /* need convert to big endian. */
9335                 entry.input.flow.udp4_flow.dst_port =
9336                                 rte_cpu_to_be_16(res->port_dst);
9337                 entry.input.flow.udp4_flow.src_port =
9338                                 rte_cpu_to_be_16(res->port_src);
9339                 break;
9340         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9341                 IPV4_ADDR_TO_UINT(res->ip_dst,
9342                         entry.input.flow.sctp4_flow.ip.dst_ip);
9343                 IPV4_ADDR_TO_UINT(res->ip_src,
9344                         entry.input.flow.sctp4_flow.ip.src_ip);
9345                 entry.input.flow.ip4_flow.tos = res->tos_value;
9346                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9347                 /* need convert to big endian. */
9348                 entry.input.flow.sctp4_flow.dst_port =
9349                                 rte_cpu_to_be_16(res->port_dst);
9350                 entry.input.flow.sctp4_flow.src_port =
9351                                 rte_cpu_to_be_16(res->port_src);
9352                 entry.input.flow.sctp4_flow.verify_tag =
9353                                 rte_cpu_to_be_32(res->verify_tag_value);
9354                 break;
9355         case RTE_ETH_FLOW_FRAG_IPV6:
9356         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9357                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9358                 /* fall-through */
9359         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9360         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9361                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9362                         entry.input.flow.ipv6_flow.dst_ip);
9363                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9364                         entry.input.flow.ipv6_flow.src_ip);
9365                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9366                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9367                 /* need convert to big endian. */
9368                 entry.input.flow.udp6_flow.dst_port =
9369                                 rte_cpu_to_be_16(res->port_dst);
9370                 entry.input.flow.udp6_flow.src_port =
9371                                 rte_cpu_to_be_16(res->port_src);
9372                 break;
9373         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9374                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9375                         entry.input.flow.sctp6_flow.ip.dst_ip);
9376                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9377                         entry.input.flow.sctp6_flow.ip.src_ip);
9378                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9379                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9380                 /* need convert to big endian. */
9381                 entry.input.flow.sctp6_flow.dst_port =
9382                                 rte_cpu_to_be_16(res->port_dst);
9383                 entry.input.flow.sctp6_flow.src_port =
9384                                 rte_cpu_to_be_16(res->port_src);
9385                 entry.input.flow.sctp6_flow.verify_tag =
9386                                 rte_cpu_to_be_32(res->verify_tag_value);
9387                 break;
9388         case RTE_ETH_FLOW_L2_PAYLOAD:
9389                 entry.input.flow.l2_flow.ether_type =
9390                         rte_cpu_to_be_16(res->ether_type);
9391                 break;
9392         default:
9393                 break;
9394         }
9395
9396         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9397                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9398                                  &res->mac_addr,
9399                                  sizeof(struct ether_addr));
9400
9401         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9402                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9403                                  &res->mac_addr,
9404                                  sizeof(struct ether_addr));
9405                 entry.input.flow.tunnel_flow.tunnel_type =
9406                         str2fdir_tunneltype(res->tunnel_type);
9407                 entry.input.flow.tunnel_flow.tunnel_id =
9408                         rte_cpu_to_be_32(res->tunnel_id_value);
9409         }
9410
9411         rte_memcpy(entry.input.flow_ext.flexbytes,
9412                    flexbytes,
9413                    RTE_ETH_FDIR_MAX_FLEXLEN);
9414
9415         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9416
9417         entry.action.flex_off = 0;  /*use 0 by default */
9418         if (!strcmp(res->drop, "drop"))
9419                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9420         else
9421                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9422
9423         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9424             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9425                 if (!strcmp(res->pf_vf, "pf"))
9426                         entry.input.flow_ext.is_vf = 0;
9427                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9428                         struct rte_eth_dev_info dev_info;
9429
9430                         memset(&dev_info, 0, sizeof(dev_info));
9431                         rte_eth_dev_info_get(res->port_id, &dev_info);
9432                         errno = 0;
9433                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9434                         if (errno != 0 || *end != '\0' ||
9435                             vf_id >= dev_info.max_vfs) {
9436                                 printf("invalid parameter %s.\n", res->pf_vf);
9437                                 return;
9438                         }
9439                         entry.input.flow_ext.is_vf = 1;
9440                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9441                 } else {
9442                         printf("invalid parameter %s.\n", res->pf_vf);
9443                         return;
9444                 }
9445         }
9446
9447         /* set to report FD ID by default */
9448         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9449         entry.action.rx_queue = res->queue_id;
9450         entry.soft_id = res->fd_id_value;
9451         if (!strcmp(res->ops, "add"))
9452                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9453                                              RTE_ETH_FILTER_ADD, &entry);
9454         else if (!strcmp(res->ops, "del"))
9455                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9456                                              RTE_ETH_FILTER_DELETE, &entry);
9457         else
9458                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9459                                              RTE_ETH_FILTER_UPDATE, &entry);
9460         if (ret < 0)
9461                 printf("flow director programming error: (%s)\n",
9462                         strerror(-ret));
9463 }
9464
9465 cmdline_parse_token_string_t cmd_flow_director_filter =
9466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9467                                  flow_director_filter, "flow_director_filter");
9468 cmdline_parse_token_num_t cmd_flow_director_port_id =
9469         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9470                               port_id, UINT8);
9471 cmdline_parse_token_string_t cmd_flow_director_ops =
9472         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9473                                  ops, "add#del#update");
9474 cmdline_parse_token_string_t cmd_flow_director_flow =
9475         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9476                                  flow, "flow");
9477 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9478         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9479                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9480                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9481 cmdline_parse_token_string_t cmd_flow_director_ether =
9482         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9483                                  ether, "ether");
9484 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9485         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9486                               ether_type, UINT16);
9487 cmdline_parse_token_string_t cmd_flow_director_src =
9488         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9489                                  src, "src");
9490 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9491         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9492                                  ip_src);
9493 cmdline_parse_token_num_t cmd_flow_director_port_src =
9494         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9495                               port_src, UINT16);
9496 cmdline_parse_token_string_t cmd_flow_director_dst =
9497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9498                                  dst, "dst");
9499 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9500         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9501                                  ip_dst);
9502 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9503         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9504                               port_dst, UINT16);
9505 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9506         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9507                                   verify_tag, "verify_tag");
9508 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9509         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9510                               verify_tag_value, UINT32);
9511 cmdline_parse_token_string_t cmd_flow_director_tos =
9512         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9513                                  tos, "tos");
9514 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9515         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9516                               tos_value, UINT8);
9517 cmdline_parse_token_string_t cmd_flow_director_proto =
9518         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9519                                  proto, "proto");
9520 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9521         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9522                               proto_value, UINT8);
9523 cmdline_parse_token_string_t cmd_flow_director_ttl =
9524         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9525                                  ttl, "ttl");
9526 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9527         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9528                               ttl_value, UINT8);
9529 cmdline_parse_token_string_t cmd_flow_director_vlan =
9530         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9531                                  vlan, "vlan");
9532 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9533         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9534                               vlan_value, UINT16);
9535 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9536         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9537                                  flexbytes, "flexbytes");
9538 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9539         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9540                               flexbytes_value, NULL);
9541 cmdline_parse_token_string_t cmd_flow_director_drop =
9542         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9543                                  drop, "drop#fwd");
9544 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9545         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9546                               pf_vf, NULL);
9547 cmdline_parse_token_string_t cmd_flow_director_queue =
9548         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9549                                  queue, "queue");
9550 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9551         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9552                               queue_id, UINT16);
9553 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9554         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9555                                  fd_id, "fd_id");
9556 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9557         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9558                               fd_id_value, UINT32);
9559
9560 cmdline_parse_token_string_t cmd_flow_director_mode =
9561         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9562                                  mode, "mode");
9563 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9564         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9565                                  mode_value, "IP");
9566 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9567         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9568                                  mode_value, "MAC-VLAN");
9569 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9571                                  mode_value, "Tunnel");
9572 cmdline_parse_token_string_t cmd_flow_director_mac =
9573         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9574                                  mac, "mac");
9575 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9576         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9577                                     mac_addr);
9578 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9579         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9580                                  tunnel, "tunnel");
9581 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9582         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9583                                  tunnel_type, "NVGRE#VxLAN");
9584 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9585         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9586                                  tunnel_id, "tunnel-id");
9587 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9588         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9589                               tunnel_id_value, UINT32);
9590
9591 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9592         .f = cmd_flow_director_filter_parsed,
9593         .data = NULL,
9594         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9595                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9596                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9597                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9598                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9599                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9600                 "fd_id <fd_id_value>: "
9601                 "Add or delete an ip flow director entry on NIC",
9602         .tokens = {
9603                 (void *)&cmd_flow_director_filter,
9604                 (void *)&cmd_flow_director_port_id,
9605                 (void *)&cmd_flow_director_mode,
9606                 (void *)&cmd_flow_director_mode_ip,
9607                 (void *)&cmd_flow_director_ops,
9608                 (void *)&cmd_flow_director_flow,
9609                 (void *)&cmd_flow_director_flow_type,
9610                 (void *)&cmd_flow_director_src,
9611                 (void *)&cmd_flow_director_ip_src,
9612                 (void *)&cmd_flow_director_dst,
9613                 (void *)&cmd_flow_director_ip_dst,
9614                 (void *)&cmd_flow_director_tos,
9615                 (void *)&cmd_flow_director_tos_value,
9616                 (void *)&cmd_flow_director_proto,
9617                 (void *)&cmd_flow_director_proto_value,
9618                 (void *)&cmd_flow_director_ttl,
9619                 (void *)&cmd_flow_director_ttl_value,
9620                 (void *)&cmd_flow_director_vlan,
9621                 (void *)&cmd_flow_director_vlan_value,
9622                 (void *)&cmd_flow_director_flexbytes,
9623                 (void *)&cmd_flow_director_flexbytes_value,
9624                 (void *)&cmd_flow_director_drop,
9625                 (void *)&cmd_flow_director_pf_vf,
9626                 (void *)&cmd_flow_director_queue,
9627                 (void *)&cmd_flow_director_queue_id,
9628                 (void *)&cmd_flow_director_fd_id,
9629                 (void *)&cmd_flow_director_fd_id_value,
9630                 NULL,
9631         },
9632 };
9633
9634 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9635         .f = cmd_flow_director_filter_parsed,
9636         .data = NULL,
9637         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9638                 "director entry on NIC",
9639         .tokens = {
9640                 (void *)&cmd_flow_director_filter,
9641                 (void *)&cmd_flow_director_port_id,
9642                 (void *)&cmd_flow_director_mode,
9643                 (void *)&cmd_flow_director_mode_ip,
9644                 (void *)&cmd_flow_director_ops,
9645                 (void *)&cmd_flow_director_flow,
9646                 (void *)&cmd_flow_director_flow_type,
9647                 (void *)&cmd_flow_director_src,
9648                 (void *)&cmd_flow_director_ip_src,
9649                 (void *)&cmd_flow_director_port_src,
9650                 (void *)&cmd_flow_director_dst,
9651                 (void *)&cmd_flow_director_ip_dst,
9652                 (void *)&cmd_flow_director_port_dst,
9653                 (void *)&cmd_flow_director_tos,
9654                 (void *)&cmd_flow_director_tos_value,
9655                 (void *)&cmd_flow_director_ttl,
9656                 (void *)&cmd_flow_director_ttl_value,
9657                 (void *)&cmd_flow_director_vlan,
9658                 (void *)&cmd_flow_director_vlan_value,
9659                 (void *)&cmd_flow_director_flexbytes,
9660                 (void *)&cmd_flow_director_flexbytes_value,
9661                 (void *)&cmd_flow_director_drop,
9662                 (void *)&cmd_flow_director_pf_vf,
9663                 (void *)&cmd_flow_director_queue,
9664                 (void *)&cmd_flow_director_queue_id,
9665                 (void *)&cmd_flow_director_fd_id,
9666                 (void *)&cmd_flow_director_fd_id_value,
9667                 NULL,
9668         },
9669 };
9670
9671 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9672         .f = cmd_flow_director_filter_parsed,
9673         .data = NULL,
9674         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9675                 "director entry on NIC",
9676         .tokens = {
9677                 (void *)&cmd_flow_director_filter,
9678                 (void *)&cmd_flow_director_port_id,
9679                 (void *)&cmd_flow_director_mode,
9680                 (void *)&cmd_flow_director_mode_ip,
9681                 (void *)&cmd_flow_director_ops,
9682                 (void *)&cmd_flow_director_flow,
9683                 (void *)&cmd_flow_director_flow_type,
9684                 (void *)&cmd_flow_director_src,
9685                 (void *)&cmd_flow_director_ip_src,
9686                 (void *)&cmd_flow_director_port_dst,
9687                 (void *)&cmd_flow_director_dst,
9688                 (void *)&cmd_flow_director_ip_dst,
9689                 (void *)&cmd_flow_director_port_dst,
9690                 (void *)&cmd_flow_director_verify_tag,
9691                 (void *)&cmd_flow_director_verify_tag_value,
9692                 (void *)&cmd_flow_director_tos,
9693                 (void *)&cmd_flow_director_tos_value,
9694                 (void *)&cmd_flow_director_ttl,
9695                 (void *)&cmd_flow_director_ttl_value,
9696                 (void *)&cmd_flow_director_vlan,
9697                 (void *)&cmd_flow_director_vlan_value,
9698                 (void *)&cmd_flow_director_flexbytes,
9699                 (void *)&cmd_flow_director_flexbytes_value,
9700                 (void *)&cmd_flow_director_drop,
9701                 (void *)&cmd_flow_director_pf_vf,
9702                 (void *)&cmd_flow_director_queue,
9703                 (void *)&cmd_flow_director_queue_id,
9704                 (void *)&cmd_flow_director_fd_id,
9705                 (void *)&cmd_flow_director_fd_id_value,
9706                 NULL,
9707         },
9708 };
9709
9710 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9711         .f = cmd_flow_director_filter_parsed,
9712         .data = NULL,
9713         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9714                 "director entry on NIC",
9715         .tokens = {
9716                 (void *)&cmd_flow_director_filter,
9717                 (void *)&cmd_flow_director_port_id,
9718                 (void *)&cmd_flow_director_mode,
9719                 (void *)&cmd_flow_director_mode_ip,
9720                 (void *)&cmd_flow_director_ops,
9721                 (void *)&cmd_flow_director_flow,
9722                 (void *)&cmd_flow_director_flow_type,
9723                 (void *)&cmd_flow_director_ether,
9724                 (void *)&cmd_flow_director_ether_type,
9725                 (void *)&cmd_flow_director_flexbytes,
9726                 (void *)&cmd_flow_director_flexbytes_value,
9727                 (void *)&cmd_flow_director_drop,
9728                 (void *)&cmd_flow_director_pf_vf,
9729                 (void *)&cmd_flow_director_queue,
9730                 (void *)&cmd_flow_director_queue_id,
9731                 (void *)&cmd_flow_director_fd_id,
9732                 (void *)&cmd_flow_director_fd_id_value,
9733                 NULL,
9734         },
9735 };
9736
9737 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9738         .f = cmd_flow_director_filter_parsed,
9739         .data = NULL,
9740         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9741                 "director entry on NIC",
9742         .tokens = {
9743                 (void *)&cmd_flow_director_filter,
9744                 (void *)&cmd_flow_director_port_id,
9745                 (void *)&cmd_flow_director_mode,
9746                 (void *)&cmd_flow_director_mode_mac_vlan,
9747                 (void *)&cmd_flow_director_ops,
9748                 (void *)&cmd_flow_director_mac,
9749                 (void *)&cmd_flow_director_mac_addr,
9750                 (void *)&cmd_flow_director_vlan,
9751                 (void *)&cmd_flow_director_vlan_value,
9752                 (void *)&cmd_flow_director_flexbytes,
9753                 (void *)&cmd_flow_director_flexbytes_value,
9754                 (void *)&cmd_flow_director_drop,
9755                 (void *)&cmd_flow_director_queue,
9756                 (void *)&cmd_flow_director_queue_id,
9757                 (void *)&cmd_flow_director_fd_id,
9758                 (void *)&cmd_flow_director_fd_id_value,
9759                 NULL,
9760         },
9761 };
9762
9763 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9764         .f = cmd_flow_director_filter_parsed,
9765         .data = NULL,
9766         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9767                 "director entry on NIC",
9768         .tokens = {
9769                 (void *)&cmd_flow_director_filter,
9770                 (void *)&cmd_flow_director_port_id,
9771                 (void *)&cmd_flow_director_mode,
9772                 (void *)&cmd_flow_director_mode_tunnel,
9773                 (void *)&cmd_flow_director_ops,
9774                 (void *)&cmd_flow_director_mac,
9775                 (void *)&cmd_flow_director_mac_addr,
9776                 (void *)&cmd_flow_director_vlan,
9777                 (void *)&cmd_flow_director_vlan_value,
9778                 (void *)&cmd_flow_director_tunnel,
9779                 (void *)&cmd_flow_director_tunnel_type,
9780                 (void *)&cmd_flow_director_tunnel_id,
9781                 (void *)&cmd_flow_director_tunnel_id_value,
9782                 (void *)&cmd_flow_director_flexbytes,
9783                 (void *)&cmd_flow_director_flexbytes_value,
9784                 (void *)&cmd_flow_director_drop,
9785                 (void *)&cmd_flow_director_queue,
9786                 (void *)&cmd_flow_director_queue_id,
9787                 (void *)&cmd_flow_director_fd_id,
9788                 (void *)&cmd_flow_director_fd_id_value,
9789                 NULL,
9790         },
9791 };
9792
9793 struct cmd_flush_flow_director_result {
9794         cmdline_fixed_string_t flush_flow_director;
9795         uint8_t port_id;
9796 };
9797
9798 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9799         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9800                                  flush_flow_director, "flush_flow_director");
9801 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9802         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9803                               port_id, UINT8);
9804
9805 static void
9806 cmd_flush_flow_director_parsed(void *parsed_result,
9807                           __attribute__((unused)) struct cmdline *cl,
9808                           __attribute__((unused)) void *data)
9809 {
9810         struct cmd_flow_director_result *res = parsed_result;
9811         int ret = 0;
9812
9813         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9814         if (ret < 0) {
9815                 printf("flow director is not supported on port %u.\n",
9816                         res->port_id);
9817                 return;
9818         }
9819
9820         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9821                         RTE_ETH_FILTER_FLUSH, NULL);
9822         if (ret < 0)
9823                 printf("flow director table flushing error: (%s)\n",
9824                         strerror(-ret));
9825 }
9826
9827 cmdline_parse_inst_t cmd_flush_flow_director = {
9828         .f = cmd_flush_flow_director_parsed,
9829         .data = NULL,
9830         .help_str = "flush_flow_director <port_id>: "
9831                 "Flush all flow director entries of a device on NIC",
9832         .tokens = {
9833                 (void *)&cmd_flush_flow_director_flush,
9834                 (void *)&cmd_flush_flow_director_port_id,
9835                 NULL,
9836         },
9837 };
9838
9839 /* *** deal with flow director mask *** */
9840 struct cmd_flow_director_mask_result {
9841         cmdline_fixed_string_t flow_director_mask;
9842         uint8_t port_id;
9843         cmdline_fixed_string_t mode;
9844         cmdline_fixed_string_t mode_value;
9845         cmdline_fixed_string_t vlan;
9846         uint16_t vlan_mask;
9847         cmdline_fixed_string_t src_mask;
9848         cmdline_ipaddr_t ipv4_src;
9849         cmdline_ipaddr_t ipv6_src;
9850         uint16_t port_src;
9851         cmdline_fixed_string_t dst_mask;
9852         cmdline_ipaddr_t ipv4_dst;
9853         cmdline_ipaddr_t ipv6_dst;
9854         uint16_t port_dst;
9855         cmdline_fixed_string_t mac;
9856         uint8_t mac_addr_byte_mask;
9857         cmdline_fixed_string_t tunnel_id;
9858         uint32_t tunnel_id_mask;
9859         cmdline_fixed_string_t tunnel_type;
9860         uint8_t tunnel_type_mask;
9861 };
9862
9863 static void
9864 cmd_flow_director_mask_parsed(void *parsed_result,
9865                           __attribute__((unused)) struct cmdline *cl,
9866                           __attribute__((unused)) void *data)
9867 {
9868         struct cmd_flow_director_mask_result *res = parsed_result;
9869         struct rte_eth_fdir_masks *mask;
9870         struct rte_port *port;
9871
9872         if (res->port_id > nb_ports) {
9873                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9874                 return;
9875         }
9876
9877         port = &ports[res->port_id];
9878         /** Check if the port is not started **/
9879         if (port->port_status != RTE_PORT_STOPPED) {
9880                 printf("Please stop port %d first\n", res->port_id);
9881                 return;
9882         }
9883
9884         mask = &port->dev_conf.fdir_conf.mask;
9885
9886         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9887                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9888                         printf("Please set mode to MAC-VLAN.\n");
9889                         return;
9890                 }
9891
9892                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9893         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9894                 if (strcmp(res->mode_value, "Tunnel")) {
9895                         printf("Please set mode to Tunnel.\n");
9896                         return;
9897                 }
9898
9899                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9900                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9901                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9902                 mask->tunnel_type_mask = res->tunnel_type_mask;
9903         } else {
9904                 if (strcmp(res->mode_value, "IP")) {
9905                         printf("Please set mode to IP.\n");
9906                         return;
9907                 }
9908
9909                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9910                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9911                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9912                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9913                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9914                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9915                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9916         }
9917
9918         cmd_reconfig_device_queue(res->port_id, 1, 1);
9919 }
9920
9921 cmdline_parse_token_string_t cmd_flow_director_mask =
9922         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9923                                  flow_director_mask, "flow_director_mask");
9924 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9925         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9926                               port_id, UINT8);
9927 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9928         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9929                                  vlan, "vlan");
9930 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9931         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9932                               vlan_mask, UINT16);
9933 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9934         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9935                                  src_mask, "src_mask");
9936 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9937         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9938                                  ipv4_src);
9939 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9940         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9941                                  ipv6_src);
9942 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9943         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9944                               port_src, UINT16);
9945 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9946         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9947                                  dst_mask, "dst_mask");
9948 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9949         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9950                                  ipv4_dst);
9951 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9952         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9953                                  ipv6_dst);
9954 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9955         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9956                               port_dst, UINT16);
9957
9958 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9960                                  mode, "mode");
9961 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9962         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9963                                  mode_value, "IP");
9964 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9965         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9966                                  mode_value, "MAC-VLAN");
9967 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9968         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9969                                  mode_value, "Tunnel");
9970 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9971         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9972                                  mac, "mac");
9973 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9974         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9975                               mac_addr_byte_mask, UINT8);
9976 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9977         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9978                                  tunnel_type, "tunnel-type");
9979 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9980         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9981                               tunnel_type_mask, UINT8);
9982 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9983         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9984                                  tunnel_id, "tunnel-id");
9985 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9986         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9987                               tunnel_id_mask, UINT32);
9988
9989 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9990         .f = cmd_flow_director_mask_parsed,
9991         .data = NULL,
9992         .help_str = "flow_director_mask ... : "
9993                 "Set IP mode flow director's mask on NIC",
9994         .tokens = {
9995                 (void *)&cmd_flow_director_mask,
9996                 (void *)&cmd_flow_director_mask_port_id,
9997                 (void *)&cmd_flow_director_mask_mode,
9998                 (void *)&cmd_flow_director_mask_mode_ip,
9999                 (void *)&cmd_flow_director_mask_vlan,
10000                 (void *)&cmd_flow_director_mask_vlan_value,
10001                 (void *)&cmd_flow_director_mask_src,
10002                 (void *)&cmd_flow_director_mask_ipv4_src,
10003                 (void *)&cmd_flow_director_mask_ipv6_src,
10004                 (void *)&cmd_flow_director_mask_port_src,
10005                 (void *)&cmd_flow_director_mask_dst,
10006                 (void *)&cmd_flow_director_mask_ipv4_dst,
10007                 (void *)&cmd_flow_director_mask_ipv6_dst,
10008                 (void *)&cmd_flow_director_mask_port_dst,
10009                 NULL,
10010         },
10011 };
10012
10013 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10014         .f = cmd_flow_director_mask_parsed,
10015         .data = NULL,
10016         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10017                 "flow director's mask on NIC",
10018         .tokens = {
10019                 (void *)&cmd_flow_director_mask,
10020                 (void *)&cmd_flow_director_mask_port_id,
10021                 (void *)&cmd_flow_director_mask_mode,
10022                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10023                 (void *)&cmd_flow_director_mask_vlan,
10024                 (void *)&cmd_flow_director_mask_vlan_value,
10025                 NULL,
10026         },
10027 };
10028
10029 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10030         .f = cmd_flow_director_mask_parsed,
10031         .data = NULL,
10032         .help_str = "flow_director_mask ... : Set tunnel mode "
10033                 "flow director's mask on NIC",
10034         .tokens = {
10035                 (void *)&cmd_flow_director_mask,
10036                 (void *)&cmd_flow_director_mask_port_id,
10037                 (void *)&cmd_flow_director_mask_mode,
10038                 (void *)&cmd_flow_director_mask_mode_tunnel,
10039                 (void *)&cmd_flow_director_mask_vlan,
10040                 (void *)&cmd_flow_director_mask_vlan_value,
10041                 (void *)&cmd_flow_director_mask_mac,
10042                 (void *)&cmd_flow_director_mask_mac_value,
10043                 (void *)&cmd_flow_director_mask_tunnel_type,
10044                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10045                 (void *)&cmd_flow_director_mask_tunnel_id,
10046                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10047                 NULL,
10048         },
10049 };
10050
10051 /* *** deal with flow director mask on flexible payload *** */
10052 struct cmd_flow_director_flex_mask_result {
10053         cmdline_fixed_string_t flow_director_flexmask;
10054         uint8_t port_id;
10055         cmdline_fixed_string_t flow;
10056         cmdline_fixed_string_t flow_type;
10057         cmdline_fixed_string_t mask;
10058 };
10059
10060 static void
10061 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10062                           __attribute__((unused)) struct cmdline *cl,
10063                           __attribute__((unused)) void *data)
10064 {
10065         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10066         struct rte_eth_fdir_info fdir_info;
10067         struct rte_eth_fdir_flex_mask flex_mask;
10068         struct rte_port *port;
10069         uint32_t flow_type_mask;
10070         uint16_t i;
10071         int ret;
10072
10073         if (res->port_id > nb_ports) {
10074                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10075                 return;
10076         }
10077
10078         port = &ports[res->port_id];
10079         /** Check if the port is not started **/
10080         if (port->port_status != RTE_PORT_STOPPED) {
10081                 printf("Please stop port %d first\n", res->port_id);
10082                 return;
10083         }
10084
10085         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10086         ret = parse_flexbytes(res->mask,
10087                         flex_mask.mask,
10088                         RTE_ETH_FDIR_MAX_FLEXLEN);
10089         if (ret < 0) {
10090                 printf("error: Cannot parse mask input.\n");
10091                 return;
10092         }
10093
10094         memset(&fdir_info, 0, sizeof(fdir_info));
10095         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10096                                 RTE_ETH_FILTER_INFO, &fdir_info);
10097         if (ret < 0) {
10098                 printf("Cannot get FDir filter info\n");
10099                 return;
10100         }
10101
10102         if (!strcmp(res->flow_type, "none")) {
10103                 /* means don't specify the flow type */
10104                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10105                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10106                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10107                                0, sizeof(struct rte_eth_fdir_flex_mask));
10108                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10109                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10110                                  &flex_mask,
10111                                  sizeof(struct rte_eth_fdir_flex_mask));
10112                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10113                 return;
10114         }
10115         flow_type_mask = fdir_info.flow_types_mask[0];
10116         if (!strcmp(res->flow_type, "all")) {
10117                 if (!flow_type_mask) {
10118                         printf("No flow type supported\n");
10119                         return;
10120                 }
10121                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10122                         if (flow_type_mask & (1 << i)) {
10123                                 flex_mask.flow_type = i;
10124                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10125                         }
10126                 }
10127                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10128                 return;
10129         }
10130         flex_mask.flow_type = str2flowtype(res->flow_type);
10131         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10132                 printf("Flow type %s not supported on port %d\n",
10133                                 res->flow_type, res->port_id);
10134                 return;
10135         }
10136         fdir_set_flex_mask(res->port_id, &flex_mask);
10137         cmd_reconfig_device_queue(res->port_id, 1, 1);
10138 }
10139
10140 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10141         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10142                                  flow_director_flexmask,
10143                                  "flow_director_flex_mask");
10144 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10145         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10146                               port_id, UINT8);
10147 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10148         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10149                                  flow, "flow");
10150 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10152                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10153                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10154 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10156                                  mask, NULL);
10157
10158 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10159         .f = cmd_flow_director_flex_mask_parsed,
10160         .data = NULL,
10161         .help_str = "flow_director_flex_mask ... : "
10162                 "Set flow director's flex mask on NIC",
10163         .tokens = {
10164                 (void *)&cmd_flow_director_flexmask,
10165                 (void *)&cmd_flow_director_flexmask_port_id,
10166                 (void *)&cmd_flow_director_flexmask_flow,
10167                 (void *)&cmd_flow_director_flexmask_flow_type,
10168                 (void *)&cmd_flow_director_flexmask_mask,
10169                 NULL,
10170         },
10171 };
10172
10173 /* *** deal with flow director flexible payload configuration *** */
10174 struct cmd_flow_director_flexpayload_result {
10175         cmdline_fixed_string_t flow_director_flexpayload;
10176         uint8_t port_id;
10177         cmdline_fixed_string_t payload_layer;
10178         cmdline_fixed_string_t payload_cfg;
10179 };
10180
10181 static inline int
10182 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10183 {
10184         char s[256];
10185         const char *p, *p0 = q_arg;
10186         char *end;
10187         unsigned long int_fld;
10188         char *str_fld[max_num];
10189         int i;
10190         unsigned size;
10191         int ret = -1;
10192
10193         p = strchr(p0, '(');
10194         if (p == NULL)
10195                 return -1;
10196         ++p;
10197         p0 = strchr(p, ')');
10198         if (p0 == NULL)
10199                 return -1;
10200
10201         size = p0 - p;
10202         if (size >= sizeof(s))
10203                 return -1;
10204
10205         snprintf(s, sizeof(s), "%.*s", size, p);
10206         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10207         if (ret < 0 || ret > max_num)
10208                 return -1;
10209         for (i = 0; i < ret; i++) {
10210                 errno = 0;
10211                 int_fld = strtoul(str_fld[i], &end, 0);
10212                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10213                         return -1;
10214                 offsets[i] = (uint16_t)int_fld;
10215         }
10216         return ret;
10217 }
10218
10219 static void
10220 cmd_flow_director_flxpld_parsed(void *parsed_result,
10221                           __attribute__((unused)) struct cmdline *cl,
10222                           __attribute__((unused)) void *data)
10223 {
10224         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10225         struct rte_eth_flex_payload_cfg flex_cfg;
10226         struct rte_port *port;
10227         int ret = 0;
10228
10229         if (res->port_id > nb_ports) {
10230                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10231                 return;
10232         }
10233
10234         port = &ports[res->port_id];
10235         /** Check if the port is not started **/
10236         if (port->port_status != RTE_PORT_STOPPED) {
10237                 printf("Please stop port %d first\n", res->port_id);
10238                 return;
10239         }
10240
10241         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10242
10243         if (!strcmp(res->payload_layer, "raw"))
10244                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10245         else if (!strcmp(res->payload_layer, "l2"))
10246                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10247         else if (!strcmp(res->payload_layer, "l3"))
10248                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10249         else if (!strcmp(res->payload_layer, "l4"))
10250                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10251
10252         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10253                             RTE_ETH_FDIR_MAX_FLEXLEN);
10254         if (ret < 0) {
10255                 printf("error: Cannot parse flex payload input.\n");
10256                 return;
10257         }
10258
10259         fdir_set_flex_payload(res->port_id, &flex_cfg);
10260         cmd_reconfig_device_queue(res->port_id, 1, 1);
10261 }
10262
10263 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10265                                  flow_director_flexpayload,
10266                                  "flow_director_flex_payload");
10267 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10268         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10269                               port_id, UINT8);
10270 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10272                                  payload_layer, "raw#l2#l3#l4");
10273 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10275                                  payload_cfg, NULL);
10276
10277 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10278         .f = cmd_flow_director_flxpld_parsed,
10279         .data = NULL,
10280         .help_str = "flow_director_flexpayload ... : "
10281                 "Set flow director's flex payload on NIC",
10282         .tokens = {
10283                 (void *)&cmd_flow_director_flexpayload,
10284                 (void *)&cmd_flow_director_flexpayload_port_id,
10285                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10286                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10287                 NULL,
10288         },
10289 };
10290
10291 /* Generic flow interface command. */
10292 extern cmdline_parse_inst_t cmd_flow;
10293
10294 /* *** Classification Filters Control *** */
10295 /* *** Get symmetric hash enable per port *** */
10296 struct cmd_get_sym_hash_ena_per_port_result {
10297         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10298         uint8_t port_id;
10299 };
10300
10301 static void
10302 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10303                                  __rte_unused struct cmdline *cl,
10304                                  __rte_unused void *data)
10305 {
10306         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10307         struct rte_eth_hash_filter_info info;
10308         int ret;
10309
10310         if (rte_eth_dev_filter_supported(res->port_id,
10311                                 RTE_ETH_FILTER_HASH) < 0) {
10312                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10313                                                         res->port_id);
10314                 return;
10315         }
10316
10317         memset(&info, 0, sizeof(info));
10318         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10319         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10320                                                 RTE_ETH_FILTER_GET, &info);
10321
10322         if (ret < 0) {
10323                 printf("Cannot get symmetric hash enable per port "
10324                                         "on port %u\n", res->port_id);
10325                 return;
10326         }
10327
10328         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10329                                 "enabled" : "disabled", res->port_id);
10330 }
10331
10332 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10333         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10334                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10335 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10336         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10337                 port_id, UINT8);
10338
10339 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10340         .f = cmd_get_sym_hash_per_port_parsed,
10341         .data = NULL,
10342         .help_str = "get_sym_hash_ena_per_port <port_id>",
10343         .tokens = {
10344                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10345                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10346                 NULL,
10347         },
10348 };
10349
10350 /* *** Set symmetric hash enable per port *** */
10351 struct cmd_set_sym_hash_ena_per_port_result {
10352         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10353         cmdline_fixed_string_t enable;
10354         uint8_t port_id;
10355 };
10356
10357 static void
10358 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10359                                  __rte_unused struct cmdline *cl,
10360                                  __rte_unused void *data)
10361 {
10362         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10363         struct rte_eth_hash_filter_info info;
10364         int ret;
10365
10366         if (rte_eth_dev_filter_supported(res->port_id,
10367                                 RTE_ETH_FILTER_HASH) < 0) {
10368                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10369                                                         res->port_id);
10370                 return;
10371         }
10372
10373         memset(&info, 0, sizeof(info));
10374         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10375         if (!strcmp(res->enable, "enable"))
10376                 info.info.enable = 1;
10377         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10378                                         RTE_ETH_FILTER_SET, &info);
10379         if (ret < 0) {
10380                 printf("Cannot set symmetric hash enable per port on "
10381                                         "port %u\n", res->port_id);
10382                 return;
10383         }
10384         printf("Symmetric hash has been set to %s on port %u\n",
10385                                         res->enable, res->port_id);
10386 }
10387
10388 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10389         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10390                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10391 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10392         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10393                 port_id, UINT8);
10394 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10395         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10396                 enable, "enable#disable");
10397
10398 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10399         .f = cmd_set_sym_hash_per_port_parsed,
10400         .data = NULL,
10401         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10402         .tokens = {
10403                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10404                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10405                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10406                 NULL,
10407         },
10408 };
10409
10410 /* Get global config of hash function */
10411 struct cmd_get_hash_global_config_result {
10412         cmdline_fixed_string_t get_hash_global_config;
10413         uint8_t port_id;
10414 };
10415
10416 static char *
10417 flowtype_to_str(uint16_t ftype)
10418 {
10419         uint16_t i;
10420         static struct {
10421                 char str[16];
10422                 uint16_t ftype;
10423         } ftype_table[] = {
10424                 {"ipv4", RTE_ETH_FLOW_IPV4},
10425                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10426                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10427                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10428                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10429                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10430                 {"ipv6", RTE_ETH_FLOW_IPV6},
10431                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10432                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10433                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10434                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10435                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10436                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10437                 {"port", RTE_ETH_FLOW_PORT},
10438                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10439                 {"geneve", RTE_ETH_FLOW_GENEVE},
10440                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10441         };
10442
10443         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10444                 if (ftype_table[i].ftype == ftype)
10445                         return ftype_table[i].str;
10446         }
10447
10448         return NULL;
10449 }
10450
10451 static void
10452 cmd_get_hash_global_config_parsed(void *parsed_result,
10453                                   __rte_unused struct cmdline *cl,
10454                                   __rte_unused void *data)
10455 {
10456         struct cmd_get_hash_global_config_result *res = parsed_result;
10457         struct rte_eth_hash_filter_info info;
10458         uint32_t idx, offset;
10459         uint16_t i;
10460         char *str;
10461         int ret;
10462
10463         if (rte_eth_dev_filter_supported(res->port_id,
10464                         RTE_ETH_FILTER_HASH) < 0) {
10465                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10466                                                         res->port_id);
10467                 return;
10468         }
10469
10470         memset(&info, 0, sizeof(info));
10471         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10472         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10473                                         RTE_ETH_FILTER_GET, &info);
10474         if (ret < 0) {
10475                 printf("Cannot get hash global configurations by port %d\n",
10476                                                         res->port_id);
10477                 return;
10478         }
10479
10480         switch (info.info.global_conf.hash_func) {
10481         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10482                 printf("Hash function is Toeplitz\n");
10483                 break;
10484         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10485                 printf("Hash function is Simple XOR\n");
10486                 break;
10487         default:
10488                 printf("Unknown hash function\n");
10489                 break;
10490         }
10491
10492         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10493                 idx = i / UINT32_BIT;
10494                 offset = i % UINT32_BIT;
10495                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10496                                                 (1UL << offset)))
10497                         continue;
10498                 str = flowtype_to_str(i);
10499                 if (!str)
10500                         continue;
10501                 printf("Symmetric hash is %s globally for flow type %s "
10502                                                         "by port %d\n",
10503                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10504                         (1UL << offset)) ? "enabled" : "disabled"), str,
10505                                                         res->port_id);
10506         }
10507 }
10508
10509 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10510         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10511                 get_hash_global_config, "get_hash_global_config");
10512 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10513         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10514                 port_id, UINT8);
10515
10516 cmdline_parse_inst_t cmd_get_hash_global_config = {
10517         .f = cmd_get_hash_global_config_parsed,
10518         .data = NULL,
10519         .help_str = "get_hash_global_config <port_id>",
10520         .tokens = {
10521                 (void *)&cmd_get_hash_global_config_all,
10522                 (void *)&cmd_get_hash_global_config_port_id,
10523                 NULL,
10524         },
10525 };
10526
10527 /* Set global config of hash function */
10528 struct cmd_set_hash_global_config_result {
10529         cmdline_fixed_string_t set_hash_global_config;
10530         uint8_t port_id;
10531         cmdline_fixed_string_t hash_func;
10532         cmdline_fixed_string_t flow_type;
10533         cmdline_fixed_string_t enable;
10534 };
10535
10536 static void
10537 cmd_set_hash_global_config_parsed(void *parsed_result,
10538                                   __rte_unused struct cmdline *cl,
10539                                   __rte_unused void *data)
10540 {
10541         struct cmd_set_hash_global_config_result *res = parsed_result;
10542         struct rte_eth_hash_filter_info info;
10543         uint32_t ftype, idx, offset;
10544         int ret;
10545
10546         if (rte_eth_dev_filter_supported(res->port_id,
10547                                 RTE_ETH_FILTER_HASH) < 0) {
10548                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10549                                                         res->port_id);
10550                 return;
10551         }
10552         memset(&info, 0, sizeof(info));
10553         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10554         if (!strcmp(res->hash_func, "toeplitz"))
10555                 info.info.global_conf.hash_func =
10556                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10557         else if (!strcmp(res->hash_func, "simple_xor"))
10558                 info.info.global_conf.hash_func =
10559                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10560         else if (!strcmp(res->hash_func, "default"))
10561                 info.info.global_conf.hash_func =
10562                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10563
10564         ftype = str2flowtype(res->flow_type);
10565         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10566         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10567         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10568         if (!strcmp(res->enable, "enable"))
10569                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10570                                                 (1UL << offset);
10571         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10572                                         RTE_ETH_FILTER_SET, &info);
10573         if (ret < 0)
10574                 printf("Cannot set global hash configurations by port %d\n",
10575                                                         res->port_id);
10576         else
10577                 printf("Global hash configurations have been set "
10578                         "succcessfully by port %d\n", res->port_id);
10579 }
10580
10581 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10582         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10583                 set_hash_global_config, "set_hash_global_config");
10584 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10585         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10586                 port_id, UINT8);
10587 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10588         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10589                 hash_func, "toeplitz#simple_xor#default");
10590 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10591         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10592                 flow_type,
10593                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10594                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10595 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10596         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10597                 enable, "enable#disable");
10598
10599 cmdline_parse_inst_t cmd_set_hash_global_config = {
10600         .f = cmd_set_hash_global_config_parsed,
10601         .data = NULL,
10602         .help_str = "set_hash_global_config <port_id> "
10603                 "toeplitz|simple_xor|default "
10604                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10605                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10606                 "l2_payload enable|disable",
10607         .tokens = {
10608                 (void *)&cmd_set_hash_global_config_all,
10609                 (void *)&cmd_set_hash_global_config_port_id,
10610                 (void *)&cmd_set_hash_global_config_hash_func,
10611                 (void *)&cmd_set_hash_global_config_flow_type,
10612                 (void *)&cmd_set_hash_global_config_enable,
10613                 NULL,
10614         },
10615 };
10616
10617 /* Set hash input set */
10618 struct cmd_set_hash_input_set_result {
10619         cmdline_fixed_string_t set_hash_input_set;
10620         uint8_t port_id;
10621         cmdline_fixed_string_t flow_type;
10622         cmdline_fixed_string_t inset_field;
10623         cmdline_fixed_string_t select;
10624 };
10625
10626 static enum rte_eth_input_set_field
10627 str2inset(char *string)
10628 {
10629         uint16_t i;
10630
10631         static const struct {
10632                 char str[32];
10633                 enum rte_eth_input_set_field inset;
10634         } inset_table[] = {
10635                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10636                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10637                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10638                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10639                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10640                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10641                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10642                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10643                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10644                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10645                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10646                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10647                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10648                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10649                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10650                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10651                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10652                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10653                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10654                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10655                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10656                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10657                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10658                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10659                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10660                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10661                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10662                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10663                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10664                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10665                 {"none", RTE_ETH_INPUT_SET_NONE},
10666         };
10667
10668         for (i = 0; i < RTE_DIM(inset_table); i++) {
10669                 if (!strcmp(string, inset_table[i].str))
10670                         return inset_table[i].inset;
10671         }
10672
10673         return RTE_ETH_INPUT_SET_UNKNOWN;
10674 }
10675
10676 static void
10677 cmd_set_hash_input_set_parsed(void *parsed_result,
10678                               __rte_unused struct cmdline *cl,
10679                               __rte_unused void *data)
10680 {
10681         struct cmd_set_hash_input_set_result *res = parsed_result;
10682         struct rte_eth_hash_filter_info info;
10683
10684         memset(&info, 0, sizeof(info));
10685         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10686         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10687         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10688         info.info.input_set_conf.inset_size = 1;
10689         if (!strcmp(res->select, "select"))
10690                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10691         else if (!strcmp(res->select, "add"))
10692                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10693         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10694                                 RTE_ETH_FILTER_SET, &info);
10695 }
10696
10697 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10698         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10699                 set_hash_input_set, "set_hash_input_set");
10700 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10701         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10702                 port_id, UINT8);
10703 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10704         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10705                 flow_type, NULL);
10706 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10707         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10708                 inset_field,
10709                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10710                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10711                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10712                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10713                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10714                 "fld-8th#none");
10715 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10716         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10717                 select, "select#add");
10718
10719 cmdline_parse_inst_t cmd_set_hash_input_set = {
10720         .f = cmd_set_hash_input_set_parsed,
10721         .data = NULL,
10722         .help_str = "set_hash_input_set <port_id> "
10723         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10724         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10725         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10726         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10727         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10728         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10729         "fld-7th|fld-8th|none select|add",
10730         .tokens = {
10731                 (void *)&cmd_set_hash_input_set_cmd,
10732                 (void *)&cmd_set_hash_input_set_port_id,
10733                 (void *)&cmd_set_hash_input_set_flow_type,
10734                 (void *)&cmd_set_hash_input_set_field,
10735                 (void *)&cmd_set_hash_input_set_select,
10736                 NULL,
10737         },
10738 };
10739
10740 /* Set flow director input set */
10741 struct cmd_set_fdir_input_set_result {
10742         cmdline_fixed_string_t set_fdir_input_set;
10743         uint8_t port_id;
10744         cmdline_fixed_string_t flow_type;
10745         cmdline_fixed_string_t inset_field;
10746         cmdline_fixed_string_t select;
10747 };
10748
10749 static void
10750 cmd_set_fdir_input_set_parsed(void *parsed_result,
10751         __rte_unused struct cmdline *cl,
10752         __rte_unused void *data)
10753 {
10754         struct cmd_set_fdir_input_set_result *res = parsed_result;
10755         struct rte_eth_fdir_filter_info info;
10756
10757         memset(&info, 0, sizeof(info));
10758         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10759         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10760         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10761         info.info.input_set_conf.inset_size = 1;
10762         if (!strcmp(res->select, "select"))
10763                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10764         else if (!strcmp(res->select, "add"))
10765                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10766         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10767                 RTE_ETH_FILTER_SET, &info);
10768 }
10769
10770 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10771         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10772         set_fdir_input_set, "set_fdir_input_set");
10773 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10774         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10775         port_id, UINT8);
10776 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10777         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10778         flow_type,
10779         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10780         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10781 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10782         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10783         inset_field,
10784         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10785         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10786         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10787         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10788         "sctp-veri-tag#none");
10789 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10790         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10791         select, "select#add");
10792
10793 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10794         .f = cmd_set_fdir_input_set_parsed,
10795         .data = NULL,
10796         .help_str = "set_fdir_input_set <port_id> "
10797         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10798         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10799         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10800         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10801         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10802         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10803         "sctp-veri-tag|none select|add",
10804         .tokens = {
10805                 (void *)&cmd_set_fdir_input_set_cmd,
10806                 (void *)&cmd_set_fdir_input_set_port_id,
10807                 (void *)&cmd_set_fdir_input_set_flow_type,
10808                 (void *)&cmd_set_fdir_input_set_field,
10809                 (void *)&cmd_set_fdir_input_set_select,
10810                 NULL,
10811         },
10812 };
10813
10814 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10815 struct cmd_mcast_addr_result {
10816         cmdline_fixed_string_t mcast_addr_cmd;
10817         cmdline_fixed_string_t what;
10818         uint8_t port_num;
10819         struct ether_addr mc_addr;
10820 };
10821
10822 static void cmd_mcast_addr_parsed(void *parsed_result,
10823                 __attribute__((unused)) struct cmdline *cl,
10824                 __attribute__((unused)) void *data)
10825 {
10826         struct cmd_mcast_addr_result *res = parsed_result;
10827
10828         if (!is_multicast_ether_addr(&res->mc_addr)) {
10829                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10830                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10831                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10832                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10833                 return;
10834         }
10835         if (strcmp(res->what, "add") == 0)
10836                 mcast_addr_add(res->port_num, &res->mc_addr);
10837         else
10838                 mcast_addr_remove(res->port_num, &res->mc_addr);
10839 }
10840
10841 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10842         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10843                                  mcast_addr_cmd, "mcast_addr");
10844 cmdline_parse_token_string_t cmd_mcast_addr_what =
10845         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10846                                  "add#remove");
10847 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10848         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10849 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10851
10852 cmdline_parse_inst_t cmd_mcast_addr = {
10853         .f = cmd_mcast_addr_parsed,
10854         .data = (void *)0,
10855         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10856                 "Add/Remove multicast MAC address on port_id",
10857         .tokens = {
10858                 (void *)&cmd_mcast_addr_cmd,
10859                 (void *)&cmd_mcast_addr_what,
10860                 (void *)&cmd_mcast_addr_portnum,
10861                 (void *)&cmd_mcast_addr_addr,
10862                 NULL,
10863         },
10864 };
10865
10866 /* l2 tunnel config
10867  * only support E-tag now.
10868  */
10869
10870 /* Ether type config */
10871 struct cmd_config_l2_tunnel_eth_type_result {
10872         cmdline_fixed_string_t port;
10873         cmdline_fixed_string_t config;
10874         cmdline_fixed_string_t all;
10875         uint8_t id;
10876         cmdline_fixed_string_t l2_tunnel;
10877         cmdline_fixed_string_t l2_tunnel_type;
10878         cmdline_fixed_string_t eth_type;
10879         uint16_t eth_type_val;
10880 };
10881
10882 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10883         TOKEN_STRING_INITIALIZER
10884                 (struct cmd_config_l2_tunnel_eth_type_result,
10885                  port, "port");
10886 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10887         TOKEN_STRING_INITIALIZER
10888                 (struct cmd_config_l2_tunnel_eth_type_result,
10889                  config, "config");
10890 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10891         TOKEN_STRING_INITIALIZER
10892                 (struct cmd_config_l2_tunnel_eth_type_result,
10893                  all, "all");
10894 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10895         TOKEN_NUM_INITIALIZER
10896                 (struct cmd_config_l2_tunnel_eth_type_result,
10897                  id, UINT8);
10898 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10899         TOKEN_STRING_INITIALIZER
10900                 (struct cmd_config_l2_tunnel_eth_type_result,
10901                  l2_tunnel, "l2-tunnel");
10902 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10903         TOKEN_STRING_INITIALIZER
10904                 (struct cmd_config_l2_tunnel_eth_type_result,
10905                  l2_tunnel_type, "E-tag");
10906 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10907         TOKEN_STRING_INITIALIZER
10908                 (struct cmd_config_l2_tunnel_eth_type_result,
10909                  eth_type, "ether-type");
10910 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10911         TOKEN_NUM_INITIALIZER
10912                 (struct cmd_config_l2_tunnel_eth_type_result,
10913                  eth_type_val, UINT16);
10914
10915 static enum rte_eth_tunnel_type
10916 str2fdir_l2_tunnel_type(char *string)
10917 {
10918         uint32_t i = 0;
10919
10920         static const struct {
10921                 char str[32];
10922                 enum rte_eth_tunnel_type type;
10923         } l2_tunnel_type_str[] = {
10924                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10925         };
10926
10927         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10928                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10929                         return l2_tunnel_type_str[i].type;
10930         }
10931         return RTE_TUNNEL_TYPE_NONE;
10932 }
10933
10934 /* ether type config for all ports */
10935 static void
10936 cmd_config_l2_tunnel_eth_type_all_parsed
10937         (void *parsed_result,
10938          __attribute__((unused)) struct cmdline *cl,
10939          __attribute__((unused)) void *data)
10940 {
10941         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10942         struct rte_eth_l2_tunnel_conf entry;
10943         portid_t pid;
10944
10945         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10946         entry.ether_type = res->eth_type_val;
10947
10948         RTE_ETH_FOREACH_DEV(pid) {
10949                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10950         }
10951 }
10952
10953 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10954         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10955         .data = NULL,
10956         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10957         .tokens = {
10958                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10959                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10960                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10961                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10962                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10963                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10964                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10965                 NULL,
10966         },
10967 };
10968
10969 /* ether type config for a specific port */
10970 static void
10971 cmd_config_l2_tunnel_eth_type_specific_parsed(
10972         void *parsed_result,
10973         __attribute__((unused)) struct cmdline *cl,
10974         __attribute__((unused)) void *data)
10975 {
10976         struct cmd_config_l2_tunnel_eth_type_result *res =
10977                  parsed_result;
10978         struct rte_eth_l2_tunnel_conf entry;
10979
10980         if (port_id_is_invalid(res->id, ENABLED_WARN))
10981                 return;
10982
10983         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10984         entry.ether_type = res->eth_type_val;
10985
10986         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10987 }
10988
10989 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10990         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10991         .data = NULL,
10992         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10993         .tokens = {
10994                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10995                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10996                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10997                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10998                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10999                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11000                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11001                 NULL,
11002         },
11003 };
11004
11005 /* Enable/disable l2 tunnel */
11006 struct cmd_config_l2_tunnel_en_dis_result {
11007         cmdline_fixed_string_t port;
11008         cmdline_fixed_string_t config;
11009         cmdline_fixed_string_t all;
11010         uint8_t id;
11011         cmdline_fixed_string_t l2_tunnel;
11012         cmdline_fixed_string_t l2_tunnel_type;
11013         cmdline_fixed_string_t en_dis;
11014 };
11015
11016 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11017         TOKEN_STRING_INITIALIZER
11018                 (struct cmd_config_l2_tunnel_en_dis_result,
11019                  port, "port");
11020 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11021         TOKEN_STRING_INITIALIZER
11022                 (struct cmd_config_l2_tunnel_en_dis_result,
11023                  config, "config");
11024 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11025         TOKEN_STRING_INITIALIZER
11026                 (struct cmd_config_l2_tunnel_en_dis_result,
11027                  all, "all");
11028 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11029         TOKEN_NUM_INITIALIZER
11030                 (struct cmd_config_l2_tunnel_en_dis_result,
11031                  id, UINT8);
11032 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11033         TOKEN_STRING_INITIALIZER
11034                 (struct cmd_config_l2_tunnel_en_dis_result,
11035                  l2_tunnel, "l2-tunnel");
11036 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11037         TOKEN_STRING_INITIALIZER
11038                 (struct cmd_config_l2_tunnel_en_dis_result,
11039                  l2_tunnel_type, "E-tag");
11040 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11041         TOKEN_STRING_INITIALIZER
11042                 (struct cmd_config_l2_tunnel_en_dis_result,
11043                  en_dis, "enable#disable");
11044
11045 /* enable/disable l2 tunnel for all ports */
11046 static void
11047 cmd_config_l2_tunnel_en_dis_all_parsed(
11048         void *parsed_result,
11049         __attribute__((unused)) struct cmdline *cl,
11050         __attribute__((unused)) void *data)
11051 {
11052         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11053         struct rte_eth_l2_tunnel_conf entry;
11054         portid_t pid;
11055         uint8_t en;
11056
11057         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11058
11059         if (!strcmp("enable", res->en_dis))
11060                 en = 1;
11061         else
11062                 en = 0;
11063
11064         RTE_ETH_FOREACH_DEV(pid) {
11065                 rte_eth_dev_l2_tunnel_offload_set(pid,
11066                                                   &entry,
11067                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11068                                                   en);
11069         }
11070 }
11071
11072 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11073         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11074         .data = NULL,
11075         .help_str = "port config all l2-tunnel E-tag enable|disable",
11076         .tokens = {
11077                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11078                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11079                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11080                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11081                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11082                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11083                 NULL,
11084         },
11085 };
11086
11087 /* enable/disable l2 tunnel for a port */
11088 static void
11089 cmd_config_l2_tunnel_en_dis_specific_parsed(
11090         void *parsed_result,
11091         __attribute__((unused)) struct cmdline *cl,
11092         __attribute__((unused)) void *data)
11093 {
11094         struct cmd_config_l2_tunnel_en_dis_result *res =
11095                 parsed_result;
11096         struct rte_eth_l2_tunnel_conf entry;
11097
11098         if (port_id_is_invalid(res->id, ENABLED_WARN))
11099                 return;
11100
11101         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11102
11103         if (!strcmp("enable", res->en_dis))
11104                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11105                                                   &entry,
11106                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11107                                                   1);
11108         else
11109                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11110                                                   &entry,
11111                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11112                                                   0);
11113 }
11114
11115 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11116         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11117         .data = NULL,
11118         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11119         .tokens = {
11120                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11121                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11122                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11123                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11124                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11125                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11126                 NULL,
11127         },
11128 };
11129
11130 /* E-tag configuration */
11131
11132 /* Common result structure for all E-tag configuration */
11133 struct cmd_config_e_tag_result {
11134         cmdline_fixed_string_t e_tag;
11135         cmdline_fixed_string_t set;
11136         cmdline_fixed_string_t insertion;
11137         cmdline_fixed_string_t stripping;
11138         cmdline_fixed_string_t forwarding;
11139         cmdline_fixed_string_t filter;
11140         cmdline_fixed_string_t add;
11141         cmdline_fixed_string_t del;
11142         cmdline_fixed_string_t on;
11143         cmdline_fixed_string_t off;
11144         cmdline_fixed_string_t on_off;
11145         cmdline_fixed_string_t port_tag_id;
11146         uint32_t port_tag_id_val;
11147         cmdline_fixed_string_t e_tag_id;
11148         uint16_t e_tag_id_val;
11149         cmdline_fixed_string_t dst_pool;
11150         uint8_t dst_pool_val;
11151         cmdline_fixed_string_t port;
11152         uint8_t port_id;
11153         cmdline_fixed_string_t vf;
11154         uint8_t vf_id;
11155 };
11156
11157 /* Common CLI fields for all E-tag configuration */
11158 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11159         TOKEN_STRING_INITIALIZER
11160                 (struct cmd_config_e_tag_result,
11161                  e_tag, "E-tag");
11162 cmdline_parse_token_string_t cmd_config_e_tag_set =
11163         TOKEN_STRING_INITIALIZER
11164                 (struct cmd_config_e_tag_result,
11165                  set, "set");
11166 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11167         TOKEN_STRING_INITIALIZER
11168                 (struct cmd_config_e_tag_result,
11169                  insertion, "insertion");
11170 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11171         TOKEN_STRING_INITIALIZER
11172                 (struct cmd_config_e_tag_result,
11173                  stripping, "stripping");
11174 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11175         TOKEN_STRING_INITIALIZER
11176                 (struct cmd_config_e_tag_result,
11177                  forwarding, "forwarding");
11178 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11179         TOKEN_STRING_INITIALIZER
11180                 (struct cmd_config_e_tag_result,
11181                  filter, "filter");
11182 cmdline_parse_token_string_t cmd_config_e_tag_add =
11183         TOKEN_STRING_INITIALIZER
11184                 (struct cmd_config_e_tag_result,
11185                  add, "add");
11186 cmdline_parse_token_string_t cmd_config_e_tag_del =
11187         TOKEN_STRING_INITIALIZER
11188                 (struct cmd_config_e_tag_result,
11189                  del, "del");
11190 cmdline_parse_token_string_t cmd_config_e_tag_on =
11191         TOKEN_STRING_INITIALIZER
11192                 (struct cmd_config_e_tag_result,
11193                  on, "on");
11194 cmdline_parse_token_string_t cmd_config_e_tag_off =
11195         TOKEN_STRING_INITIALIZER
11196                 (struct cmd_config_e_tag_result,
11197                  off, "off");
11198 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11199         TOKEN_STRING_INITIALIZER
11200                 (struct cmd_config_e_tag_result,
11201                  on_off, "on#off");
11202 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11203         TOKEN_STRING_INITIALIZER
11204                 (struct cmd_config_e_tag_result,
11205                  port_tag_id, "port-tag-id");
11206 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11207         TOKEN_NUM_INITIALIZER
11208                 (struct cmd_config_e_tag_result,
11209                  port_tag_id_val, UINT32);
11210 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11211         TOKEN_STRING_INITIALIZER
11212                 (struct cmd_config_e_tag_result,
11213                  e_tag_id, "e-tag-id");
11214 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11215         TOKEN_NUM_INITIALIZER
11216                 (struct cmd_config_e_tag_result,
11217                  e_tag_id_val, UINT16);
11218 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11219         TOKEN_STRING_INITIALIZER
11220                 (struct cmd_config_e_tag_result,
11221                  dst_pool, "dst-pool");
11222 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11223         TOKEN_NUM_INITIALIZER
11224                 (struct cmd_config_e_tag_result,
11225                  dst_pool_val, UINT8);
11226 cmdline_parse_token_string_t cmd_config_e_tag_port =
11227         TOKEN_STRING_INITIALIZER
11228                 (struct cmd_config_e_tag_result,
11229                  port, "port");
11230 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11231         TOKEN_NUM_INITIALIZER
11232                 (struct cmd_config_e_tag_result,
11233                  port_id, UINT8);
11234 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11235         TOKEN_STRING_INITIALIZER
11236                 (struct cmd_config_e_tag_result,
11237                  vf, "vf");
11238 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11239         TOKEN_NUM_INITIALIZER
11240                 (struct cmd_config_e_tag_result,
11241                  vf_id, UINT8);
11242
11243 /* E-tag insertion configuration */
11244 static void
11245 cmd_config_e_tag_insertion_en_parsed(
11246         void *parsed_result,
11247         __attribute__((unused)) struct cmdline *cl,
11248         __attribute__((unused)) void *data)
11249 {
11250         struct cmd_config_e_tag_result *res =
11251                 parsed_result;
11252         struct rte_eth_l2_tunnel_conf entry;
11253
11254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11255                 return;
11256
11257         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11258         entry.tunnel_id = res->port_tag_id_val;
11259         entry.vf_id = res->vf_id;
11260         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11261                                           &entry,
11262                                           ETH_L2_TUNNEL_INSERTION_MASK,
11263                                           1);
11264 }
11265
11266 static void
11267 cmd_config_e_tag_insertion_dis_parsed(
11268         void *parsed_result,
11269         __attribute__((unused)) struct cmdline *cl,
11270         __attribute__((unused)) void *data)
11271 {
11272         struct cmd_config_e_tag_result *res =
11273                 parsed_result;
11274         struct rte_eth_l2_tunnel_conf entry;
11275
11276         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11277                 return;
11278
11279         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11280         entry.vf_id = res->vf_id;
11281
11282         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11283                                           &entry,
11284                                           ETH_L2_TUNNEL_INSERTION_MASK,
11285                                           0);
11286 }
11287
11288 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11289         .f = cmd_config_e_tag_insertion_en_parsed,
11290         .data = NULL,
11291         .help_str = "E-tag ... : E-tag insertion enable",
11292         .tokens = {
11293                 (void *)&cmd_config_e_tag_e_tag,
11294                 (void *)&cmd_config_e_tag_set,
11295                 (void *)&cmd_config_e_tag_insertion,
11296                 (void *)&cmd_config_e_tag_on,
11297                 (void *)&cmd_config_e_tag_port_tag_id,
11298                 (void *)&cmd_config_e_tag_port_tag_id_val,
11299                 (void *)&cmd_config_e_tag_port,
11300                 (void *)&cmd_config_e_tag_port_id,
11301                 (void *)&cmd_config_e_tag_vf,
11302                 (void *)&cmd_config_e_tag_vf_id,
11303                 NULL,
11304         },
11305 };
11306
11307 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11308         .f = cmd_config_e_tag_insertion_dis_parsed,
11309         .data = NULL,
11310         .help_str = "E-tag ... : E-tag insertion disable",
11311         .tokens = {
11312                 (void *)&cmd_config_e_tag_e_tag,
11313                 (void *)&cmd_config_e_tag_set,
11314                 (void *)&cmd_config_e_tag_insertion,
11315                 (void *)&cmd_config_e_tag_off,
11316                 (void *)&cmd_config_e_tag_port,
11317                 (void *)&cmd_config_e_tag_port_id,
11318                 (void *)&cmd_config_e_tag_vf,
11319                 (void *)&cmd_config_e_tag_vf_id,
11320                 NULL,
11321         },
11322 };
11323
11324 /* E-tag stripping configuration */
11325 static void
11326 cmd_config_e_tag_stripping_parsed(
11327         void *parsed_result,
11328         __attribute__((unused)) struct cmdline *cl,
11329         __attribute__((unused)) void *data)
11330 {
11331         struct cmd_config_e_tag_result *res =
11332                 parsed_result;
11333         struct rte_eth_l2_tunnel_conf entry;
11334
11335         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11336                 return;
11337
11338         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11339
11340         if (!strcmp(res->on_off, "on"))
11341                 rte_eth_dev_l2_tunnel_offload_set
11342                         (res->port_id,
11343                          &entry,
11344                          ETH_L2_TUNNEL_STRIPPING_MASK,
11345                          1);
11346         else
11347                 rte_eth_dev_l2_tunnel_offload_set
11348                         (res->port_id,
11349                          &entry,
11350                          ETH_L2_TUNNEL_STRIPPING_MASK,
11351                          0);
11352 }
11353
11354 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11355         .f = cmd_config_e_tag_stripping_parsed,
11356         .data = NULL,
11357         .help_str = "E-tag ... : E-tag stripping enable/disable",
11358         .tokens = {
11359                 (void *)&cmd_config_e_tag_e_tag,
11360                 (void *)&cmd_config_e_tag_set,
11361                 (void *)&cmd_config_e_tag_stripping,
11362                 (void *)&cmd_config_e_tag_on_off,
11363                 (void *)&cmd_config_e_tag_port,
11364                 (void *)&cmd_config_e_tag_port_id,
11365                 NULL,
11366         },
11367 };
11368
11369 /* E-tag forwarding configuration */
11370 static void
11371 cmd_config_e_tag_forwarding_parsed(
11372         void *parsed_result,
11373         __attribute__((unused)) struct cmdline *cl,
11374         __attribute__((unused)) void *data)
11375 {
11376         struct cmd_config_e_tag_result *res = parsed_result;
11377         struct rte_eth_l2_tunnel_conf entry;
11378
11379         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11380                 return;
11381
11382         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11383
11384         if (!strcmp(res->on_off, "on"))
11385                 rte_eth_dev_l2_tunnel_offload_set
11386                         (res->port_id,
11387                          &entry,
11388                          ETH_L2_TUNNEL_FORWARDING_MASK,
11389                          1);
11390         else
11391                 rte_eth_dev_l2_tunnel_offload_set
11392                         (res->port_id,
11393                          &entry,
11394                          ETH_L2_TUNNEL_FORWARDING_MASK,
11395                          0);
11396 }
11397
11398 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11399         .f = cmd_config_e_tag_forwarding_parsed,
11400         .data = NULL,
11401         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11402         .tokens = {
11403                 (void *)&cmd_config_e_tag_e_tag,
11404                 (void *)&cmd_config_e_tag_set,
11405                 (void *)&cmd_config_e_tag_forwarding,
11406                 (void *)&cmd_config_e_tag_on_off,
11407                 (void *)&cmd_config_e_tag_port,
11408                 (void *)&cmd_config_e_tag_port_id,
11409                 NULL,
11410         },
11411 };
11412
11413 /* E-tag filter configuration */
11414 static void
11415 cmd_config_e_tag_filter_add_parsed(
11416         void *parsed_result,
11417         __attribute__((unused)) struct cmdline *cl,
11418         __attribute__((unused)) void *data)
11419 {
11420         struct cmd_config_e_tag_result *res = parsed_result;
11421         struct rte_eth_l2_tunnel_conf entry;
11422         int ret = 0;
11423
11424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11425                 return;
11426
11427         if (res->e_tag_id_val > 0x3fff) {
11428                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11429                 return;
11430         }
11431
11432         ret = rte_eth_dev_filter_supported(res->port_id,
11433                                            RTE_ETH_FILTER_L2_TUNNEL);
11434         if (ret < 0) {
11435                 printf("E-tag filter is not supported on port %u.\n",
11436                        res->port_id);
11437                 return;
11438         }
11439
11440         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11441         entry.tunnel_id = res->e_tag_id_val;
11442         entry.pool = res->dst_pool_val;
11443
11444         ret = rte_eth_dev_filter_ctrl(res->port_id,
11445                                       RTE_ETH_FILTER_L2_TUNNEL,
11446                                       RTE_ETH_FILTER_ADD,
11447                                       &entry);
11448         if (ret < 0)
11449                 printf("E-tag filter programming error: (%s)\n",
11450                        strerror(-ret));
11451 }
11452
11453 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11454         .f = cmd_config_e_tag_filter_add_parsed,
11455         .data = NULL,
11456         .help_str = "E-tag ... : E-tag filter add",
11457         .tokens = {
11458                 (void *)&cmd_config_e_tag_e_tag,
11459                 (void *)&cmd_config_e_tag_set,
11460                 (void *)&cmd_config_e_tag_filter,
11461                 (void *)&cmd_config_e_tag_add,
11462                 (void *)&cmd_config_e_tag_e_tag_id,
11463                 (void *)&cmd_config_e_tag_e_tag_id_val,
11464                 (void *)&cmd_config_e_tag_dst_pool,
11465                 (void *)&cmd_config_e_tag_dst_pool_val,
11466                 (void *)&cmd_config_e_tag_port,
11467                 (void *)&cmd_config_e_tag_port_id,
11468                 NULL,
11469         },
11470 };
11471
11472 static void
11473 cmd_config_e_tag_filter_del_parsed(
11474         void *parsed_result,
11475         __attribute__((unused)) struct cmdline *cl,
11476         __attribute__((unused)) void *data)
11477 {
11478         struct cmd_config_e_tag_result *res = parsed_result;
11479         struct rte_eth_l2_tunnel_conf entry;
11480         int ret = 0;
11481
11482         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11483                 return;
11484
11485         if (res->e_tag_id_val > 0x3fff) {
11486                 printf("e-tag-id must be less than 0x3fff.\n");
11487                 return;
11488         }
11489
11490         ret = rte_eth_dev_filter_supported(res->port_id,
11491                                            RTE_ETH_FILTER_L2_TUNNEL);
11492         if (ret < 0) {
11493                 printf("E-tag filter is not supported on port %u.\n",
11494                        res->port_id);
11495                 return;
11496         }
11497
11498         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11499         entry.tunnel_id = res->e_tag_id_val;
11500
11501         ret = rte_eth_dev_filter_ctrl(res->port_id,
11502                                       RTE_ETH_FILTER_L2_TUNNEL,
11503                                       RTE_ETH_FILTER_DELETE,
11504                                       &entry);
11505         if (ret < 0)
11506                 printf("E-tag filter programming error: (%s)\n",
11507                        strerror(-ret));
11508 }
11509
11510 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11511         .f = cmd_config_e_tag_filter_del_parsed,
11512         .data = NULL,
11513         .help_str = "E-tag ... : E-tag filter delete",
11514         .tokens = {
11515                 (void *)&cmd_config_e_tag_e_tag,
11516                 (void *)&cmd_config_e_tag_set,
11517                 (void *)&cmd_config_e_tag_filter,
11518                 (void *)&cmd_config_e_tag_del,
11519                 (void *)&cmd_config_e_tag_e_tag_id,
11520                 (void *)&cmd_config_e_tag_e_tag_id_val,
11521                 (void *)&cmd_config_e_tag_port,
11522                 (void *)&cmd_config_e_tag_port_id,
11523                 NULL,
11524         },
11525 };
11526
11527 /* vf vlan anti spoof configuration */
11528
11529 /* Common result structure for vf vlan anti spoof */
11530 struct cmd_vf_vlan_anti_spoof_result {
11531         cmdline_fixed_string_t set;
11532         cmdline_fixed_string_t vf;
11533         cmdline_fixed_string_t vlan;
11534         cmdline_fixed_string_t antispoof;
11535         uint8_t port_id;
11536         uint32_t vf_id;
11537         cmdline_fixed_string_t on_off;
11538 };
11539
11540 /* Common CLI fields for vf vlan anti spoof enable disable */
11541 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11542         TOKEN_STRING_INITIALIZER
11543                 (struct cmd_vf_vlan_anti_spoof_result,
11544                  set, "set");
11545 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11546         TOKEN_STRING_INITIALIZER
11547                 (struct cmd_vf_vlan_anti_spoof_result,
11548                  vf, "vf");
11549 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11550         TOKEN_STRING_INITIALIZER
11551                 (struct cmd_vf_vlan_anti_spoof_result,
11552                  vlan, "vlan");
11553 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11554         TOKEN_STRING_INITIALIZER
11555                 (struct cmd_vf_vlan_anti_spoof_result,
11556                  antispoof, "antispoof");
11557 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11558         TOKEN_NUM_INITIALIZER
11559                 (struct cmd_vf_vlan_anti_spoof_result,
11560                  port_id, UINT8);
11561 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11562         TOKEN_NUM_INITIALIZER
11563                 (struct cmd_vf_vlan_anti_spoof_result,
11564                  vf_id, UINT32);
11565 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11566         TOKEN_STRING_INITIALIZER
11567                 (struct cmd_vf_vlan_anti_spoof_result,
11568                  on_off, "on#off");
11569
11570 static void
11571 cmd_set_vf_vlan_anti_spoof_parsed(
11572         void *parsed_result,
11573         __attribute__((unused)) struct cmdline *cl,
11574         __attribute__((unused)) void *data)
11575 {
11576         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11577         int ret = -ENOTSUP;
11578
11579         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11580
11581         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11582                 return;
11583
11584 #ifdef RTE_LIBRTE_IXGBE_PMD
11585         if (ret == -ENOTSUP)
11586                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11587                                 res->vf_id, is_on);
11588 #endif
11589 #ifdef RTE_LIBRTE_I40E_PMD
11590         if (ret == -ENOTSUP)
11591                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11592                                 res->vf_id, is_on);
11593 #endif
11594 #ifdef RTE_LIBRTE_BNXT_PMD
11595         if (ret == -ENOTSUP)
11596                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11597                                 res->vf_id, is_on);
11598 #endif
11599
11600         switch (ret) {
11601         case 0:
11602                 break;
11603         case -EINVAL:
11604                 printf("invalid vf_id %d\n", res->vf_id);
11605                 break;
11606         case -ENODEV:
11607                 printf("invalid port_id %d\n", res->port_id);
11608                 break;
11609         case -ENOTSUP:
11610                 printf("function not implemented\n");
11611                 break;
11612         default:
11613                 printf("programming error: (%s)\n", strerror(-ret));
11614         }
11615 }
11616
11617 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11618         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11619         .data = NULL,
11620         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11621         .tokens = {
11622                 (void *)&cmd_vf_vlan_anti_spoof_set,
11623                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11624                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11625                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11626                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11627                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11628                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11629                 NULL,
11630         },
11631 };
11632
11633 /* vf mac anti spoof configuration */
11634
11635 /* Common result structure for vf mac anti spoof */
11636 struct cmd_vf_mac_anti_spoof_result {
11637         cmdline_fixed_string_t set;
11638         cmdline_fixed_string_t vf;
11639         cmdline_fixed_string_t mac;
11640         cmdline_fixed_string_t antispoof;
11641         uint8_t port_id;
11642         uint32_t vf_id;
11643         cmdline_fixed_string_t on_off;
11644 };
11645
11646 /* Common CLI fields for vf mac anti spoof enable disable */
11647 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_vf_mac_anti_spoof_result,
11650                  set, "set");
11651 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11652         TOKEN_STRING_INITIALIZER
11653                 (struct cmd_vf_mac_anti_spoof_result,
11654                  vf, "vf");
11655 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_vf_mac_anti_spoof_result,
11658                  mac, "mac");
11659 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11660         TOKEN_STRING_INITIALIZER
11661                 (struct cmd_vf_mac_anti_spoof_result,
11662                  antispoof, "antispoof");
11663 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11664         TOKEN_NUM_INITIALIZER
11665                 (struct cmd_vf_mac_anti_spoof_result,
11666                  port_id, UINT8);
11667 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11668         TOKEN_NUM_INITIALIZER
11669                 (struct cmd_vf_mac_anti_spoof_result,
11670                  vf_id, UINT32);
11671 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11672         TOKEN_STRING_INITIALIZER
11673                 (struct cmd_vf_mac_anti_spoof_result,
11674                  on_off, "on#off");
11675
11676 static void
11677 cmd_set_vf_mac_anti_spoof_parsed(
11678         void *parsed_result,
11679         __attribute__((unused)) struct cmdline *cl,
11680         __attribute__((unused)) void *data)
11681 {
11682         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11683         int ret = -ENOTSUP;
11684
11685         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11686
11687         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11688                 return;
11689
11690 #ifdef RTE_LIBRTE_IXGBE_PMD
11691         if (ret == -ENOTSUP)
11692                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11693                         res->vf_id, is_on);
11694 #endif
11695 #ifdef RTE_LIBRTE_I40E_PMD
11696         if (ret == -ENOTSUP)
11697                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11698                         res->vf_id, is_on);
11699 #endif
11700 #ifdef RTE_LIBRTE_BNXT_PMD
11701         if (ret == -ENOTSUP)
11702                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11703                         res->vf_id, is_on);
11704 #endif
11705
11706         switch (ret) {
11707         case 0:
11708                 break;
11709         case -EINVAL:
11710                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11711                 break;
11712         case -ENODEV:
11713                 printf("invalid port_id %d\n", res->port_id);
11714                 break;
11715         case -ENOTSUP:
11716                 printf("function not implemented\n");
11717                 break;
11718         default:
11719                 printf("programming error: (%s)\n", strerror(-ret));
11720         }
11721 }
11722
11723 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11724         .f = cmd_set_vf_mac_anti_spoof_parsed,
11725         .data = NULL,
11726         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11727         .tokens = {
11728                 (void *)&cmd_vf_mac_anti_spoof_set,
11729                 (void *)&cmd_vf_mac_anti_spoof_vf,
11730                 (void *)&cmd_vf_mac_anti_spoof_mac,
11731                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11732                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11733                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11734                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11735                 NULL,
11736         },
11737 };
11738
11739 /* vf vlan strip queue configuration */
11740
11741 /* Common result structure for vf mac anti spoof */
11742 struct cmd_vf_vlan_stripq_result {
11743         cmdline_fixed_string_t set;
11744         cmdline_fixed_string_t vf;
11745         cmdline_fixed_string_t vlan;
11746         cmdline_fixed_string_t stripq;
11747         portid_t port_id;
11748         uint16_t vf_id;
11749         cmdline_fixed_string_t on_off;
11750 };
11751
11752 /* Common CLI fields for vf vlan strip enable disable */
11753 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11754         TOKEN_STRING_INITIALIZER
11755                 (struct cmd_vf_vlan_stripq_result,
11756                  set, "set");
11757 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11758         TOKEN_STRING_INITIALIZER
11759                 (struct cmd_vf_vlan_stripq_result,
11760                  vf, "vf");
11761 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11762         TOKEN_STRING_INITIALIZER
11763                 (struct cmd_vf_vlan_stripq_result,
11764                  vlan, "vlan");
11765 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11766         TOKEN_STRING_INITIALIZER
11767                 (struct cmd_vf_vlan_stripq_result,
11768                  stripq, "stripq");
11769 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11770         TOKEN_NUM_INITIALIZER
11771                 (struct cmd_vf_vlan_stripq_result,
11772                  port_id, UINT8);
11773 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11774         TOKEN_NUM_INITIALIZER
11775                 (struct cmd_vf_vlan_stripq_result,
11776                  vf_id, UINT16);
11777 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11778         TOKEN_STRING_INITIALIZER
11779                 (struct cmd_vf_vlan_stripq_result,
11780                  on_off, "on#off");
11781
11782 static void
11783 cmd_set_vf_vlan_stripq_parsed(
11784         void *parsed_result,
11785         __attribute__((unused)) struct cmdline *cl,
11786         __attribute__((unused)) void *data)
11787 {
11788         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11789         int ret = -ENOTSUP;
11790
11791         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11792
11793         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11794                 return;
11795
11796 #ifdef RTE_LIBRTE_IXGBE_PMD
11797         if (ret == -ENOTSUP)
11798                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11799                         res->vf_id, is_on);
11800 #endif
11801 #ifdef RTE_LIBRTE_I40E_PMD
11802         if (ret == -ENOTSUP)
11803                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11804                         res->vf_id, is_on);
11805 #endif
11806 #ifdef RTE_LIBRTE_BNXT_PMD
11807         if (ret == -ENOTSUP)
11808                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11809                         res->vf_id, is_on);
11810 #endif
11811
11812         switch (ret) {
11813         case 0:
11814                 break;
11815         case -EINVAL:
11816                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11817                 break;
11818         case -ENODEV:
11819                 printf("invalid port_id %d\n", res->port_id);
11820                 break;
11821         case -ENOTSUP:
11822                 printf("function not implemented\n");
11823                 break;
11824         default:
11825                 printf("programming error: (%s)\n", strerror(-ret));
11826         }
11827 }
11828
11829 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11830         .f = cmd_set_vf_vlan_stripq_parsed,
11831         .data = NULL,
11832         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11833         .tokens = {
11834                 (void *)&cmd_vf_vlan_stripq_set,
11835                 (void *)&cmd_vf_vlan_stripq_vf,
11836                 (void *)&cmd_vf_vlan_stripq_vlan,
11837                 (void *)&cmd_vf_vlan_stripq_stripq,
11838                 (void *)&cmd_vf_vlan_stripq_port_id,
11839                 (void *)&cmd_vf_vlan_stripq_vf_id,
11840                 (void *)&cmd_vf_vlan_stripq_on_off,
11841                 NULL,
11842         },
11843 };
11844
11845 /* vf vlan insert configuration */
11846
11847 /* Common result structure for vf vlan insert */
11848 struct cmd_vf_vlan_insert_result {
11849         cmdline_fixed_string_t set;
11850         cmdline_fixed_string_t vf;
11851         cmdline_fixed_string_t vlan;
11852         cmdline_fixed_string_t insert;
11853         uint8_t port_id;
11854         uint16_t vf_id;
11855         uint16_t vlan_id;
11856 };
11857
11858 /* Common CLI fields for vf vlan insert enable disable */
11859 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11860         TOKEN_STRING_INITIALIZER
11861                 (struct cmd_vf_vlan_insert_result,
11862                  set, "set");
11863 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11864         TOKEN_STRING_INITIALIZER
11865                 (struct cmd_vf_vlan_insert_result,
11866                  vf, "vf");
11867 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11868         TOKEN_STRING_INITIALIZER
11869                 (struct cmd_vf_vlan_insert_result,
11870                  vlan, "vlan");
11871 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_vf_vlan_insert_result,
11874                  insert, "insert");
11875 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11876         TOKEN_NUM_INITIALIZER
11877                 (struct cmd_vf_vlan_insert_result,
11878                  port_id, UINT8);
11879 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11880         TOKEN_NUM_INITIALIZER
11881                 (struct cmd_vf_vlan_insert_result,
11882                  vf_id, UINT16);
11883 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11884         TOKEN_NUM_INITIALIZER
11885                 (struct cmd_vf_vlan_insert_result,
11886                  vlan_id, UINT16);
11887
11888 static void
11889 cmd_set_vf_vlan_insert_parsed(
11890         void *parsed_result,
11891         __attribute__((unused)) struct cmdline *cl,
11892         __attribute__((unused)) void *data)
11893 {
11894         struct cmd_vf_vlan_insert_result *res = parsed_result;
11895         int ret = -ENOTSUP;
11896
11897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11898                 return;
11899
11900 #ifdef RTE_LIBRTE_IXGBE_PMD
11901         if (ret == -ENOTSUP)
11902                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11903                         res->vlan_id);
11904 #endif
11905 #ifdef RTE_LIBRTE_I40E_PMD
11906         if (ret == -ENOTSUP)
11907                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11908                         res->vlan_id);
11909 #endif
11910 #ifdef RTE_LIBRTE_BNXT_PMD
11911         if (ret == -ENOTSUP)
11912                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11913                         res->vlan_id);
11914 #endif
11915
11916         switch (ret) {
11917         case 0:
11918                 break;
11919         case -EINVAL:
11920                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11921                 break;
11922         case -ENODEV:
11923                 printf("invalid port_id %d\n", res->port_id);
11924                 break;
11925         case -ENOTSUP:
11926                 printf("function not implemented\n");
11927                 break;
11928         default:
11929                 printf("programming error: (%s)\n", strerror(-ret));
11930         }
11931 }
11932
11933 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11934         .f = cmd_set_vf_vlan_insert_parsed,
11935         .data = NULL,
11936         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11937         .tokens = {
11938                 (void *)&cmd_vf_vlan_insert_set,
11939                 (void *)&cmd_vf_vlan_insert_vf,
11940                 (void *)&cmd_vf_vlan_insert_vlan,
11941                 (void *)&cmd_vf_vlan_insert_insert,
11942                 (void *)&cmd_vf_vlan_insert_port_id,
11943                 (void *)&cmd_vf_vlan_insert_vf_id,
11944                 (void *)&cmd_vf_vlan_insert_vlan_id,
11945                 NULL,
11946         },
11947 };
11948
11949 /* tx loopback configuration */
11950
11951 /* Common result structure for tx loopback */
11952 struct cmd_tx_loopback_result {
11953         cmdline_fixed_string_t set;
11954         cmdline_fixed_string_t tx;
11955         cmdline_fixed_string_t loopback;
11956         uint8_t port_id;
11957         cmdline_fixed_string_t on_off;
11958 };
11959
11960 /* Common CLI fields for tx loopback enable disable */
11961 cmdline_parse_token_string_t cmd_tx_loopback_set =
11962         TOKEN_STRING_INITIALIZER
11963                 (struct cmd_tx_loopback_result,
11964                  set, "set");
11965 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11966         TOKEN_STRING_INITIALIZER
11967                 (struct cmd_tx_loopback_result,
11968                  tx, "tx");
11969 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11970         TOKEN_STRING_INITIALIZER
11971                 (struct cmd_tx_loopback_result,
11972                  loopback, "loopback");
11973 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11974         TOKEN_NUM_INITIALIZER
11975                 (struct cmd_tx_loopback_result,
11976                  port_id, UINT8);
11977 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11978         TOKEN_STRING_INITIALIZER
11979                 (struct cmd_tx_loopback_result,
11980                  on_off, "on#off");
11981
11982 static void
11983 cmd_set_tx_loopback_parsed(
11984         void *parsed_result,
11985         __attribute__((unused)) struct cmdline *cl,
11986         __attribute__((unused)) void *data)
11987 {
11988         struct cmd_tx_loopback_result *res = parsed_result;
11989         int ret = -ENOTSUP;
11990
11991         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11992
11993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11994                 return;
11995
11996 #ifdef RTE_LIBRTE_IXGBE_PMD
11997         if (ret == -ENOTSUP)
11998                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11999 #endif
12000 #ifdef RTE_LIBRTE_I40E_PMD
12001         if (ret == -ENOTSUP)
12002                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12003 #endif
12004 #ifdef RTE_LIBRTE_BNXT_PMD
12005         if (ret == -ENOTSUP)
12006                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12007 #endif
12008
12009         switch (ret) {
12010         case 0:
12011                 break;
12012         case -EINVAL:
12013                 printf("invalid is_on %d\n", is_on);
12014                 break;
12015         case -ENODEV:
12016                 printf("invalid port_id %d\n", res->port_id);
12017                 break;
12018         case -ENOTSUP:
12019                 printf("function not implemented\n");
12020                 break;
12021         default:
12022                 printf("programming error: (%s)\n", strerror(-ret));
12023         }
12024 }
12025
12026 cmdline_parse_inst_t cmd_set_tx_loopback = {
12027         .f = cmd_set_tx_loopback_parsed,
12028         .data = NULL,
12029         .help_str = "set tx loopback <port_id> on|off",
12030         .tokens = {
12031                 (void *)&cmd_tx_loopback_set,
12032                 (void *)&cmd_tx_loopback_tx,
12033                 (void *)&cmd_tx_loopback_loopback,
12034                 (void *)&cmd_tx_loopback_port_id,
12035                 (void *)&cmd_tx_loopback_on_off,
12036                 NULL,
12037         },
12038 };
12039
12040 /* all queues drop enable configuration */
12041
12042 /* Common result structure for all queues drop enable */
12043 struct cmd_all_queues_drop_en_result {
12044         cmdline_fixed_string_t set;
12045         cmdline_fixed_string_t all;
12046         cmdline_fixed_string_t queues;
12047         cmdline_fixed_string_t drop;
12048         uint8_t port_id;
12049         cmdline_fixed_string_t on_off;
12050 };
12051
12052 /* Common CLI fields for tx loopback enable disable */
12053 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12054         TOKEN_STRING_INITIALIZER
12055                 (struct cmd_all_queues_drop_en_result,
12056                  set, "set");
12057 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12058         TOKEN_STRING_INITIALIZER
12059                 (struct cmd_all_queues_drop_en_result,
12060                  all, "all");
12061 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12062         TOKEN_STRING_INITIALIZER
12063                 (struct cmd_all_queues_drop_en_result,
12064                  queues, "queues");
12065 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12066         TOKEN_STRING_INITIALIZER
12067                 (struct cmd_all_queues_drop_en_result,
12068                  drop, "drop");
12069 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12070         TOKEN_NUM_INITIALIZER
12071                 (struct cmd_all_queues_drop_en_result,
12072                  port_id, UINT8);
12073 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12074         TOKEN_STRING_INITIALIZER
12075                 (struct cmd_all_queues_drop_en_result,
12076                  on_off, "on#off");
12077
12078 static void
12079 cmd_set_all_queues_drop_en_parsed(
12080         void *parsed_result,
12081         __attribute__((unused)) struct cmdline *cl,
12082         __attribute__((unused)) void *data)
12083 {
12084         struct cmd_all_queues_drop_en_result *res = parsed_result;
12085         int ret = -ENOTSUP;
12086         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12087
12088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12089                 return;
12090
12091 #ifdef RTE_LIBRTE_IXGBE_PMD
12092         if (ret == -ENOTSUP)
12093                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12094 #endif
12095 #ifdef RTE_LIBRTE_BNXT_PMD
12096         if (ret == -ENOTSUP)
12097                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12098 #endif
12099         switch (ret) {
12100         case 0:
12101                 break;
12102         case -EINVAL:
12103                 printf("invalid is_on %d\n", is_on);
12104                 break;
12105         case -ENODEV:
12106                 printf("invalid port_id %d\n", res->port_id);
12107                 break;
12108         case -ENOTSUP:
12109                 printf("function not implemented\n");
12110                 break;
12111         default:
12112                 printf("programming error: (%s)\n", strerror(-ret));
12113         }
12114 }
12115
12116 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12117         .f = cmd_set_all_queues_drop_en_parsed,
12118         .data = NULL,
12119         .help_str = "set all queues drop <port_id> on|off",
12120         .tokens = {
12121                 (void *)&cmd_all_queues_drop_en_set,
12122                 (void *)&cmd_all_queues_drop_en_all,
12123                 (void *)&cmd_all_queues_drop_en_queues,
12124                 (void *)&cmd_all_queues_drop_en_drop,
12125                 (void *)&cmd_all_queues_drop_en_port_id,
12126                 (void *)&cmd_all_queues_drop_en_on_off,
12127                 NULL,
12128         },
12129 };
12130
12131 /* vf split drop enable configuration */
12132
12133 /* Common result structure for vf split drop enable */
12134 struct cmd_vf_split_drop_en_result {
12135         cmdline_fixed_string_t set;
12136         cmdline_fixed_string_t vf;
12137         cmdline_fixed_string_t split;
12138         cmdline_fixed_string_t drop;
12139         uint8_t port_id;
12140         uint16_t vf_id;
12141         cmdline_fixed_string_t on_off;
12142 };
12143
12144 /* Common CLI fields for vf split drop enable disable */
12145 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12146         TOKEN_STRING_INITIALIZER
12147                 (struct cmd_vf_split_drop_en_result,
12148                  set, "set");
12149 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12150         TOKEN_STRING_INITIALIZER
12151                 (struct cmd_vf_split_drop_en_result,
12152                  vf, "vf");
12153 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12154         TOKEN_STRING_INITIALIZER
12155                 (struct cmd_vf_split_drop_en_result,
12156                  split, "split");
12157 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12158         TOKEN_STRING_INITIALIZER
12159                 (struct cmd_vf_split_drop_en_result,
12160                  drop, "drop");
12161 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12162         TOKEN_NUM_INITIALIZER
12163                 (struct cmd_vf_split_drop_en_result,
12164                  port_id, UINT8);
12165 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12166         TOKEN_NUM_INITIALIZER
12167                 (struct cmd_vf_split_drop_en_result,
12168                  vf_id, UINT16);
12169 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_vf_split_drop_en_result,
12172                  on_off, "on#off");
12173
12174 static void
12175 cmd_set_vf_split_drop_en_parsed(
12176         void *parsed_result,
12177         __attribute__((unused)) struct cmdline *cl,
12178         __attribute__((unused)) void *data)
12179 {
12180         struct cmd_vf_split_drop_en_result *res = parsed_result;
12181         int ret = -ENOTSUP;
12182         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12183
12184         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12185                 return;
12186
12187 #ifdef RTE_LIBRTE_IXGBE_PMD
12188         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12189                         is_on);
12190 #endif
12191         switch (ret) {
12192         case 0:
12193                 break;
12194         case -EINVAL:
12195                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12196                 break;
12197         case -ENODEV:
12198                 printf("invalid port_id %d\n", res->port_id);
12199                 break;
12200         case -ENOTSUP:
12201                 printf("not supported on port %d\n", res->port_id);
12202                 break;
12203         default:
12204                 printf("programming error: (%s)\n", strerror(-ret));
12205         }
12206 }
12207
12208 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12209         .f = cmd_set_vf_split_drop_en_parsed,
12210         .data = NULL,
12211         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12212         .tokens = {
12213                 (void *)&cmd_vf_split_drop_en_set,
12214                 (void *)&cmd_vf_split_drop_en_vf,
12215                 (void *)&cmd_vf_split_drop_en_split,
12216                 (void *)&cmd_vf_split_drop_en_drop,
12217                 (void *)&cmd_vf_split_drop_en_port_id,
12218                 (void *)&cmd_vf_split_drop_en_vf_id,
12219                 (void *)&cmd_vf_split_drop_en_on_off,
12220                 NULL,
12221         },
12222 };
12223
12224 /* vf mac address configuration */
12225
12226 /* Common result structure for vf mac address */
12227 struct cmd_set_vf_mac_addr_result {
12228         cmdline_fixed_string_t set;
12229         cmdline_fixed_string_t vf;
12230         cmdline_fixed_string_t mac;
12231         cmdline_fixed_string_t addr;
12232         uint8_t port_id;
12233         uint16_t vf_id;
12234         struct ether_addr mac_addr;
12235
12236 };
12237
12238 /* Common CLI fields for vf split drop enable disable */
12239 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12240         TOKEN_STRING_INITIALIZER
12241                 (struct cmd_set_vf_mac_addr_result,
12242                  set, "set");
12243 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12244         TOKEN_STRING_INITIALIZER
12245                 (struct cmd_set_vf_mac_addr_result,
12246                  vf, "vf");
12247 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12248         TOKEN_STRING_INITIALIZER
12249                 (struct cmd_set_vf_mac_addr_result,
12250                  mac, "mac");
12251 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12252         TOKEN_STRING_INITIALIZER
12253                 (struct cmd_set_vf_mac_addr_result,
12254                  addr, "addr");
12255 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12256         TOKEN_NUM_INITIALIZER
12257                 (struct cmd_set_vf_mac_addr_result,
12258                  port_id, UINT8);
12259 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12260         TOKEN_NUM_INITIALIZER
12261                 (struct cmd_set_vf_mac_addr_result,
12262                  vf_id, UINT16);
12263 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12264         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12265                  mac_addr);
12266
12267 static void
12268 cmd_set_vf_mac_addr_parsed(
12269         void *parsed_result,
12270         __attribute__((unused)) struct cmdline *cl,
12271         __attribute__((unused)) void *data)
12272 {
12273         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12274         int ret = -ENOTSUP;
12275
12276         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12277                 return;
12278
12279 #ifdef RTE_LIBRTE_IXGBE_PMD
12280         if (ret == -ENOTSUP)
12281                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12282                                 &res->mac_addr);
12283 #endif
12284 #ifdef RTE_LIBRTE_I40E_PMD
12285         if (ret == -ENOTSUP)
12286                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12287                                 &res->mac_addr);
12288 #endif
12289 #ifdef RTE_LIBRTE_BNXT_PMD
12290         if (ret == -ENOTSUP)
12291                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12292                                 &res->mac_addr);
12293 #endif
12294
12295         switch (ret) {
12296         case 0:
12297                 break;
12298         case -EINVAL:
12299                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12300                 break;
12301         case -ENODEV:
12302                 printf("invalid port_id %d\n", res->port_id);
12303                 break;
12304         case -ENOTSUP:
12305                 printf("function not implemented\n");
12306                 break;
12307         default:
12308                 printf("programming error: (%s)\n", strerror(-ret));
12309         }
12310 }
12311
12312 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12313         .f = cmd_set_vf_mac_addr_parsed,
12314         .data = NULL,
12315         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12316         .tokens = {
12317                 (void *)&cmd_set_vf_mac_addr_set,
12318                 (void *)&cmd_set_vf_mac_addr_vf,
12319                 (void *)&cmd_set_vf_mac_addr_mac,
12320                 (void *)&cmd_set_vf_mac_addr_addr,
12321                 (void *)&cmd_set_vf_mac_addr_port_id,
12322                 (void *)&cmd_set_vf_mac_addr_vf_id,
12323                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12324                 NULL,
12325         },
12326 };
12327
12328 /* MACsec configuration */
12329
12330 /* Common result structure for MACsec offload enable */
12331 struct cmd_macsec_offload_on_result {
12332         cmdline_fixed_string_t set;
12333         cmdline_fixed_string_t macsec;
12334         cmdline_fixed_string_t offload;
12335         uint8_t port_id;
12336         cmdline_fixed_string_t on;
12337         cmdline_fixed_string_t encrypt;
12338         cmdline_fixed_string_t en_on_off;
12339         cmdline_fixed_string_t replay_protect;
12340         cmdline_fixed_string_t rp_on_off;
12341 };
12342
12343 /* Common CLI fields for MACsec offload disable */
12344 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12345         TOKEN_STRING_INITIALIZER
12346                 (struct cmd_macsec_offload_on_result,
12347                  set, "set");
12348 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12349         TOKEN_STRING_INITIALIZER
12350                 (struct cmd_macsec_offload_on_result,
12351                  macsec, "macsec");
12352 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_macsec_offload_on_result,
12355                  offload, "offload");
12356 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12357         TOKEN_NUM_INITIALIZER
12358                 (struct cmd_macsec_offload_on_result,
12359                  port_id, UINT8);
12360 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12361         TOKEN_STRING_INITIALIZER
12362                 (struct cmd_macsec_offload_on_result,
12363                  on, "on");
12364 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12365         TOKEN_STRING_INITIALIZER
12366                 (struct cmd_macsec_offload_on_result,
12367                  encrypt, "encrypt");
12368 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12369         TOKEN_STRING_INITIALIZER
12370                 (struct cmd_macsec_offload_on_result,
12371                  en_on_off, "on#off");
12372 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12373         TOKEN_STRING_INITIALIZER
12374                 (struct cmd_macsec_offload_on_result,
12375                  replay_protect, "replay-protect");
12376 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_macsec_offload_on_result,
12379                  rp_on_off, "on#off");
12380
12381 static void
12382 cmd_set_macsec_offload_on_parsed(
12383         void *parsed_result,
12384         __attribute__((unused)) struct cmdline *cl,
12385         __attribute__((unused)) void *data)
12386 {
12387         struct cmd_macsec_offload_on_result *res = parsed_result;
12388         int ret = -ENOTSUP;
12389         portid_t port_id = res->port_id;
12390         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12391         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12392
12393         if (port_id_is_invalid(port_id, ENABLED_WARN))
12394                 return;
12395
12396         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12397 #ifdef RTE_LIBRTE_IXGBE_PMD
12398         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12399 #endif
12400         RTE_SET_USED(en);
12401         RTE_SET_USED(rp);
12402
12403         switch (ret) {
12404         case 0:
12405                 break;
12406         case -ENODEV:
12407                 printf("invalid port_id %d\n", port_id);
12408                 break;
12409         case -ENOTSUP:
12410                 printf("not supported on port %d\n", port_id);
12411                 break;
12412         default:
12413                 printf("programming error: (%s)\n", strerror(-ret));
12414         }
12415 }
12416
12417 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12418         .f = cmd_set_macsec_offload_on_parsed,
12419         .data = NULL,
12420         .help_str = "set macsec offload <port_id> on "
12421                 "encrypt on|off replay-protect on|off",
12422         .tokens = {
12423                 (void *)&cmd_macsec_offload_on_set,
12424                 (void *)&cmd_macsec_offload_on_macsec,
12425                 (void *)&cmd_macsec_offload_on_offload,
12426                 (void *)&cmd_macsec_offload_on_port_id,
12427                 (void *)&cmd_macsec_offload_on_on,
12428                 (void *)&cmd_macsec_offload_on_encrypt,
12429                 (void *)&cmd_macsec_offload_on_en_on_off,
12430                 (void *)&cmd_macsec_offload_on_replay_protect,
12431                 (void *)&cmd_macsec_offload_on_rp_on_off,
12432                 NULL,
12433         },
12434 };
12435
12436 /* Common result structure for MACsec offload disable */
12437 struct cmd_macsec_offload_off_result {
12438         cmdline_fixed_string_t set;
12439         cmdline_fixed_string_t macsec;
12440         cmdline_fixed_string_t offload;
12441         uint8_t port_id;
12442         cmdline_fixed_string_t off;
12443 };
12444
12445 /* Common CLI fields for MACsec offload disable */
12446 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12447         TOKEN_STRING_INITIALIZER
12448                 (struct cmd_macsec_offload_off_result,
12449                  set, "set");
12450 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12451         TOKEN_STRING_INITIALIZER
12452                 (struct cmd_macsec_offload_off_result,
12453                  macsec, "macsec");
12454 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12455         TOKEN_STRING_INITIALIZER
12456                 (struct cmd_macsec_offload_off_result,
12457                  offload, "offload");
12458 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12459         TOKEN_NUM_INITIALIZER
12460                 (struct cmd_macsec_offload_off_result,
12461                  port_id, UINT8);
12462 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12463         TOKEN_STRING_INITIALIZER
12464                 (struct cmd_macsec_offload_off_result,
12465                  off, "off");
12466
12467 static void
12468 cmd_set_macsec_offload_off_parsed(
12469         void *parsed_result,
12470         __attribute__((unused)) struct cmdline *cl,
12471         __attribute__((unused)) void *data)
12472 {
12473         struct cmd_macsec_offload_off_result *res = parsed_result;
12474         int ret = -ENOTSUP;
12475         portid_t port_id = res->port_id;
12476
12477         if (port_id_is_invalid(port_id, ENABLED_WARN))
12478                 return;
12479
12480         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12481 #ifdef RTE_LIBRTE_IXGBE_PMD
12482         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12483 #endif
12484
12485         switch (ret) {
12486         case 0:
12487                 break;
12488         case -ENODEV:
12489                 printf("invalid port_id %d\n", port_id);
12490                 break;
12491         case -ENOTSUP:
12492                 printf("not supported on port %d\n", port_id);
12493                 break;
12494         default:
12495                 printf("programming error: (%s)\n", strerror(-ret));
12496         }
12497 }
12498
12499 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12500         .f = cmd_set_macsec_offload_off_parsed,
12501         .data = NULL,
12502         .help_str = "set macsec offload <port_id> off",
12503         .tokens = {
12504                 (void *)&cmd_macsec_offload_off_set,
12505                 (void *)&cmd_macsec_offload_off_macsec,
12506                 (void *)&cmd_macsec_offload_off_offload,
12507                 (void *)&cmd_macsec_offload_off_port_id,
12508                 (void *)&cmd_macsec_offload_off_off,
12509                 NULL,
12510         },
12511 };
12512
12513 /* Common result structure for MACsec secure connection configure */
12514 struct cmd_macsec_sc_result {
12515         cmdline_fixed_string_t set;
12516         cmdline_fixed_string_t macsec;
12517         cmdline_fixed_string_t sc;
12518         cmdline_fixed_string_t tx_rx;
12519         uint8_t port_id;
12520         struct ether_addr mac;
12521         uint16_t pi;
12522 };
12523
12524 /* Common CLI fields for MACsec secure connection configure */
12525 cmdline_parse_token_string_t cmd_macsec_sc_set =
12526         TOKEN_STRING_INITIALIZER
12527                 (struct cmd_macsec_sc_result,
12528                  set, "set");
12529 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_macsec_sc_result,
12532                  macsec, "macsec");
12533 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12534         TOKEN_STRING_INITIALIZER
12535                 (struct cmd_macsec_sc_result,
12536                  sc, "sc");
12537 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12538         TOKEN_STRING_INITIALIZER
12539                 (struct cmd_macsec_sc_result,
12540                  tx_rx, "tx#rx");
12541 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12542         TOKEN_NUM_INITIALIZER
12543                 (struct cmd_macsec_sc_result,
12544                  port_id, UINT8);
12545 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12546         TOKEN_ETHERADDR_INITIALIZER
12547                 (struct cmd_macsec_sc_result,
12548                  mac);
12549 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12550         TOKEN_NUM_INITIALIZER
12551                 (struct cmd_macsec_sc_result,
12552                  pi, UINT16);
12553
12554 static void
12555 cmd_set_macsec_sc_parsed(
12556         void *parsed_result,
12557         __attribute__((unused)) struct cmdline *cl,
12558         __attribute__((unused)) void *data)
12559 {
12560         struct cmd_macsec_sc_result *res = parsed_result;
12561         int ret = -ENOTSUP;
12562         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12563
12564 #ifdef RTE_LIBRTE_IXGBE_PMD
12565         ret = is_tx ?
12566                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12567                                 res->mac.addr_bytes) :
12568                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12569                                 res->mac.addr_bytes, res->pi);
12570 #endif
12571         RTE_SET_USED(is_tx);
12572
12573         switch (ret) {
12574         case 0:
12575                 break;
12576         case -ENODEV:
12577                 printf("invalid port_id %d\n", res->port_id);
12578                 break;
12579         case -ENOTSUP:
12580                 printf("not supported on port %d\n", res->port_id);
12581                 break;
12582         default:
12583                 printf("programming error: (%s)\n", strerror(-ret));
12584         }
12585 }
12586
12587 cmdline_parse_inst_t cmd_set_macsec_sc = {
12588         .f = cmd_set_macsec_sc_parsed,
12589         .data = NULL,
12590         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12591         .tokens = {
12592                 (void *)&cmd_macsec_sc_set,
12593                 (void *)&cmd_macsec_sc_macsec,
12594                 (void *)&cmd_macsec_sc_sc,
12595                 (void *)&cmd_macsec_sc_tx_rx,
12596                 (void *)&cmd_macsec_sc_port_id,
12597                 (void *)&cmd_macsec_sc_mac,
12598                 (void *)&cmd_macsec_sc_pi,
12599                 NULL,
12600         },
12601 };
12602
12603 /* Common result structure for MACsec secure connection configure */
12604 struct cmd_macsec_sa_result {
12605         cmdline_fixed_string_t set;
12606         cmdline_fixed_string_t macsec;
12607         cmdline_fixed_string_t sa;
12608         cmdline_fixed_string_t tx_rx;
12609         uint8_t port_id;
12610         uint8_t idx;
12611         uint8_t an;
12612         uint32_t pn;
12613         cmdline_fixed_string_t key;
12614 };
12615
12616 /* Common CLI fields for MACsec secure connection configure */
12617 cmdline_parse_token_string_t cmd_macsec_sa_set =
12618         TOKEN_STRING_INITIALIZER
12619                 (struct cmd_macsec_sa_result,
12620                  set, "set");
12621 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12622         TOKEN_STRING_INITIALIZER
12623                 (struct cmd_macsec_sa_result,
12624                  macsec, "macsec");
12625 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12626         TOKEN_STRING_INITIALIZER
12627                 (struct cmd_macsec_sa_result,
12628                  sa, "sa");
12629 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12630         TOKEN_STRING_INITIALIZER
12631                 (struct cmd_macsec_sa_result,
12632                  tx_rx, "tx#rx");
12633 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12634         TOKEN_NUM_INITIALIZER
12635                 (struct cmd_macsec_sa_result,
12636                  port_id, UINT8);
12637 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12638         TOKEN_NUM_INITIALIZER
12639                 (struct cmd_macsec_sa_result,
12640                  idx, UINT8);
12641 cmdline_parse_token_num_t cmd_macsec_sa_an =
12642         TOKEN_NUM_INITIALIZER
12643                 (struct cmd_macsec_sa_result,
12644                  an, UINT8);
12645 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12646         TOKEN_NUM_INITIALIZER
12647                 (struct cmd_macsec_sa_result,
12648                  pn, UINT32);
12649 cmdline_parse_token_string_t cmd_macsec_sa_key =
12650         TOKEN_STRING_INITIALIZER
12651                 (struct cmd_macsec_sa_result,
12652                  key, NULL);
12653
12654 static void
12655 cmd_set_macsec_sa_parsed(
12656         void *parsed_result,
12657         __attribute__((unused)) struct cmdline *cl,
12658         __attribute__((unused)) void *data)
12659 {
12660         struct cmd_macsec_sa_result *res = parsed_result;
12661         int ret = -ENOTSUP;
12662         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12663         uint8_t key[16] = { 0 };
12664         uint8_t xdgt0;
12665         uint8_t xdgt1;
12666         int key_len;
12667         int i;
12668
12669         key_len = strlen(res->key) / 2;
12670         if (key_len > 16)
12671                 key_len = 16;
12672
12673         for (i = 0; i < key_len; i++) {
12674                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12675                 if (xdgt0 == 0xFF)
12676                         return;
12677                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12678                 if (xdgt1 == 0xFF)
12679                         return;
12680                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12681         }
12682
12683 #ifdef RTE_LIBRTE_IXGBE_PMD
12684         ret = is_tx ?
12685                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12686                         res->idx, res->an, res->pn, key) :
12687                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12688                         res->idx, res->an, res->pn, key);
12689 #endif
12690         RTE_SET_USED(is_tx);
12691         RTE_SET_USED(key);
12692
12693         switch (ret) {
12694         case 0:
12695                 break;
12696         case -EINVAL:
12697                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12698                 break;
12699         case -ENODEV:
12700                 printf("invalid port_id %d\n", res->port_id);
12701                 break;
12702         case -ENOTSUP:
12703                 printf("not supported on port %d\n", res->port_id);
12704                 break;
12705         default:
12706                 printf("programming error: (%s)\n", strerror(-ret));
12707         }
12708 }
12709
12710 cmdline_parse_inst_t cmd_set_macsec_sa = {
12711         .f = cmd_set_macsec_sa_parsed,
12712         .data = NULL,
12713         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12714         .tokens = {
12715                 (void *)&cmd_macsec_sa_set,
12716                 (void *)&cmd_macsec_sa_macsec,
12717                 (void *)&cmd_macsec_sa_sa,
12718                 (void *)&cmd_macsec_sa_tx_rx,
12719                 (void *)&cmd_macsec_sa_port_id,
12720                 (void *)&cmd_macsec_sa_idx,
12721                 (void *)&cmd_macsec_sa_an,
12722                 (void *)&cmd_macsec_sa_pn,
12723                 (void *)&cmd_macsec_sa_key,
12724                 NULL,
12725         },
12726 };
12727
12728 /* VF unicast promiscuous mode configuration */
12729
12730 /* Common result structure for VF unicast promiscuous mode */
12731 struct cmd_vf_promisc_result {
12732         cmdline_fixed_string_t set;
12733         cmdline_fixed_string_t vf;
12734         cmdline_fixed_string_t promisc;
12735         uint8_t port_id;
12736         uint32_t vf_id;
12737         cmdline_fixed_string_t on_off;
12738 };
12739
12740 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12741 cmdline_parse_token_string_t cmd_vf_promisc_set =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_vf_promisc_result,
12744                  set, "set");
12745 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_vf_promisc_result,
12748                  vf, "vf");
12749 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12750         TOKEN_STRING_INITIALIZER
12751                 (struct cmd_vf_promisc_result,
12752                  promisc, "promisc");
12753 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12754         TOKEN_NUM_INITIALIZER
12755                 (struct cmd_vf_promisc_result,
12756                  port_id, UINT8);
12757 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12758         TOKEN_NUM_INITIALIZER
12759                 (struct cmd_vf_promisc_result,
12760                  vf_id, UINT32);
12761 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12762         TOKEN_STRING_INITIALIZER
12763                 (struct cmd_vf_promisc_result,
12764                  on_off, "on#off");
12765
12766 static void
12767 cmd_set_vf_promisc_parsed(
12768         void *parsed_result,
12769         __attribute__((unused)) struct cmdline *cl,
12770         __attribute__((unused)) void *data)
12771 {
12772         struct cmd_vf_promisc_result *res = parsed_result;
12773         int ret = -ENOTSUP;
12774
12775         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12776
12777         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12778                 return;
12779
12780 #ifdef RTE_LIBRTE_I40E_PMD
12781         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12782                                                   res->vf_id, is_on);
12783 #endif
12784
12785         switch (ret) {
12786         case 0:
12787                 break;
12788         case -EINVAL:
12789                 printf("invalid vf_id %d\n", res->vf_id);
12790                 break;
12791         case -ENODEV:
12792                 printf("invalid port_id %d\n", res->port_id);
12793                 break;
12794         case -ENOTSUP:
12795                 printf("function not implemented\n");
12796                 break;
12797         default:
12798                 printf("programming error: (%s)\n", strerror(-ret));
12799         }
12800 }
12801
12802 cmdline_parse_inst_t cmd_set_vf_promisc = {
12803         .f = cmd_set_vf_promisc_parsed,
12804         .data = NULL,
12805         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12806                 "Set unicast promiscuous mode for a VF from the PF",
12807         .tokens = {
12808                 (void *)&cmd_vf_promisc_set,
12809                 (void *)&cmd_vf_promisc_vf,
12810                 (void *)&cmd_vf_promisc_promisc,
12811                 (void *)&cmd_vf_promisc_port_id,
12812                 (void *)&cmd_vf_promisc_vf_id,
12813                 (void *)&cmd_vf_promisc_on_off,
12814                 NULL,
12815         },
12816 };
12817
12818 /* VF multicast promiscuous mode configuration */
12819
12820 /* Common result structure for VF multicast promiscuous mode */
12821 struct cmd_vf_allmulti_result {
12822         cmdline_fixed_string_t set;
12823         cmdline_fixed_string_t vf;
12824         cmdline_fixed_string_t allmulti;
12825         uint8_t port_id;
12826         uint32_t vf_id;
12827         cmdline_fixed_string_t on_off;
12828 };
12829
12830 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12831 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12832         TOKEN_STRING_INITIALIZER
12833                 (struct cmd_vf_allmulti_result,
12834                  set, "set");
12835 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12836         TOKEN_STRING_INITIALIZER
12837                 (struct cmd_vf_allmulti_result,
12838                  vf, "vf");
12839 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12840         TOKEN_STRING_INITIALIZER
12841                 (struct cmd_vf_allmulti_result,
12842                  allmulti, "allmulti");
12843 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12844         TOKEN_NUM_INITIALIZER
12845                 (struct cmd_vf_allmulti_result,
12846                  port_id, UINT8);
12847 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12848         TOKEN_NUM_INITIALIZER
12849                 (struct cmd_vf_allmulti_result,
12850                  vf_id, UINT32);
12851 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_vf_allmulti_result,
12854                  on_off, "on#off");
12855
12856 static void
12857 cmd_set_vf_allmulti_parsed(
12858         void *parsed_result,
12859         __attribute__((unused)) struct cmdline *cl,
12860         __attribute__((unused)) void *data)
12861 {
12862         struct cmd_vf_allmulti_result *res = parsed_result;
12863         int ret = -ENOTSUP;
12864
12865         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12866
12867         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12868                 return;
12869
12870 #ifdef RTE_LIBRTE_I40E_PMD
12871         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12872                                                     res->vf_id, is_on);
12873 #endif
12874
12875         switch (ret) {
12876         case 0:
12877                 break;
12878         case -EINVAL:
12879                 printf("invalid vf_id %d\n", res->vf_id);
12880                 break;
12881         case -ENODEV:
12882                 printf("invalid port_id %d\n", res->port_id);
12883                 break;
12884         case -ENOTSUP:
12885                 printf("function not implemented\n");
12886                 break;
12887         default:
12888                 printf("programming error: (%s)\n", strerror(-ret));
12889         }
12890 }
12891
12892 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12893         .f = cmd_set_vf_allmulti_parsed,
12894         .data = NULL,
12895         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12896                 "Set multicast promiscuous mode for a VF from the PF",
12897         .tokens = {
12898                 (void *)&cmd_vf_allmulti_set,
12899                 (void *)&cmd_vf_allmulti_vf,
12900                 (void *)&cmd_vf_allmulti_allmulti,
12901                 (void *)&cmd_vf_allmulti_port_id,
12902                 (void *)&cmd_vf_allmulti_vf_id,
12903                 (void *)&cmd_vf_allmulti_on_off,
12904                 NULL,
12905         },
12906 };
12907
12908 /* vf broadcast mode configuration */
12909
12910 /* Common result structure for vf broadcast */
12911 struct cmd_set_vf_broadcast_result {
12912         cmdline_fixed_string_t set;
12913         cmdline_fixed_string_t vf;
12914         cmdline_fixed_string_t broadcast;
12915         uint8_t port_id;
12916         uint16_t vf_id;
12917         cmdline_fixed_string_t on_off;
12918 };
12919
12920 /* Common CLI fields for vf broadcast enable disable */
12921 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12922         TOKEN_STRING_INITIALIZER
12923                 (struct cmd_set_vf_broadcast_result,
12924                  set, "set");
12925 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_set_vf_broadcast_result,
12928                  vf, "vf");
12929 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12930         TOKEN_STRING_INITIALIZER
12931                 (struct cmd_set_vf_broadcast_result,
12932                  broadcast, "broadcast");
12933 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12934         TOKEN_NUM_INITIALIZER
12935                 (struct cmd_set_vf_broadcast_result,
12936                  port_id, UINT8);
12937 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12938         TOKEN_NUM_INITIALIZER
12939                 (struct cmd_set_vf_broadcast_result,
12940                  vf_id, UINT16);
12941 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_set_vf_broadcast_result,
12944                  on_off, "on#off");
12945
12946 static void
12947 cmd_set_vf_broadcast_parsed(
12948         void *parsed_result,
12949         __attribute__((unused)) struct cmdline *cl,
12950         __attribute__((unused)) void *data)
12951 {
12952         struct cmd_set_vf_broadcast_result *res = parsed_result;
12953         int ret = -ENOTSUP;
12954
12955         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12956
12957         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12958                 return;
12959
12960 #ifdef RTE_LIBRTE_I40E_PMD
12961         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12962                                             res->vf_id, is_on);
12963 #endif
12964
12965         switch (ret) {
12966         case 0:
12967                 break;
12968         case -EINVAL:
12969                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12970                 break;
12971         case -ENODEV:
12972                 printf("invalid port_id %d\n", res->port_id);
12973                 break;
12974         case -ENOTSUP:
12975                 printf("function not implemented\n");
12976                 break;
12977         default:
12978                 printf("programming error: (%s)\n", strerror(-ret));
12979         }
12980 }
12981
12982 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12983         .f = cmd_set_vf_broadcast_parsed,
12984         .data = NULL,
12985         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12986         .tokens = {
12987                 (void *)&cmd_set_vf_broadcast_set,
12988                 (void *)&cmd_set_vf_broadcast_vf,
12989                 (void *)&cmd_set_vf_broadcast_broadcast,
12990                 (void *)&cmd_set_vf_broadcast_port_id,
12991                 (void *)&cmd_set_vf_broadcast_vf_id,
12992                 (void *)&cmd_set_vf_broadcast_on_off,
12993                 NULL,
12994         },
12995 };
12996
12997 /* vf vlan tag configuration */
12998
12999 /* Common result structure for vf vlan tag */
13000 struct cmd_set_vf_vlan_tag_result {
13001         cmdline_fixed_string_t set;
13002         cmdline_fixed_string_t vf;
13003         cmdline_fixed_string_t vlan;
13004         cmdline_fixed_string_t tag;
13005         uint8_t port_id;
13006         uint16_t vf_id;
13007         cmdline_fixed_string_t on_off;
13008 };
13009
13010 /* Common CLI fields for vf vlan tag enable disable */
13011 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13012         TOKEN_STRING_INITIALIZER
13013                 (struct cmd_set_vf_vlan_tag_result,
13014                  set, "set");
13015 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13016         TOKEN_STRING_INITIALIZER
13017                 (struct cmd_set_vf_vlan_tag_result,
13018                  vf, "vf");
13019 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13020         TOKEN_STRING_INITIALIZER
13021                 (struct cmd_set_vf_vlan_tag_result,
13022                  vlan, "vlan");
13023 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13024         TOKEN_STRING_INITIALIZER
13025                 (struct cmd_set_vf_vlan_tag_result,
13026                  tag, "tag");
13027 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13028         TOKEN_NUM_INITIALIZER
13029                 (struct cmd_set_vf_vlan_tag_result,
13030                  port_id, UINT8);
13031 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13032         TOKEN_NUM_INITIALIZER
13033                 (struct cmd_set_vf_vlan_tag_result,
13034                  vf_id, UINT16);
13035 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13036         TOKEN_STRING_INITIALIZER
13037                 (struct cmd_set_vf_vlan_tag_result,
13038                  on_off, "on#off");
13039
13040 static void
13041 cmd_set_vf_vlan_tag_parsed(
13042         void *parsed_result,
13043         __attribute__((unused)) struct cmdline *cl,
13044         __attribute__((unused)) void *data)
13045 {
13046         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13047         int ret = -ENOTSUP;
13048
13049         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13050
13051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13052                 return;
13053
13054 #ifdef RTE_LIBRTE_I40E_PMD
13055         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13056                                            res->vf_id, is_on);
13057 #endif
13058
13059         switch (ret) {
13060         case 0:
13061                 break;
13062         case -EINVAL:
13063                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13064                 break;
13065         case -ENODEV:
13066                 printf("invalid port_id %d\n", res->port_id);
13067                 break;
13068         case -ENOTSUP:
13069                 printf("function not implemented\n");
13070                 break;
13071         default:
13072                 printf("programming error: (%s)\n", strerror(-ret));
13073         }
13074 }
13075
13076 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13077         .f = cmd_set_vf_vlan_tag_parsed,
13078         .data = NULL,
13079         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13080         .tokens = {
13081                 (void *)&cmd_set_vf_vlan_tag_set,
13082                 (void *)&cmd_set_vf_vlan_tag_vf,
13083                 (void *)&cmd_set_vf_vlan_tag_vlan,
13084                 (void *)&cmd_set_vf_vlan_tag_tag,
13085                 (void *)&cmd_set_vf_vlan_tag_port_id,
13086                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13087                 (void *)&cmd_set_vf_vlan_tag_on_off,
13088                 NULL,
13089         },
13090 };
13091
13092 /* Common definition of VF and TC TX bandwidth configuration */
13093 struct cmd_vf_tc_bw_result {
13094         cmdline_fixed_string_t set;
13095         cmdline_fixed_string_t vf;
13096         cmdline_fixed_string_t tc;
13097         cmdline_fixed_string_t tx;
13098         cmdline_fixed_string_t min_bw;
13099         cmdline_fixed_string_t max_bw;
13100         cmdline_fixed_string_t strict_link_prio;
13101         uint8_t port_id;
13102         uint16_t vf_id;
13103         uint8_t tc_no;
13104         uint32_t bw;
13105         cmdline_fixed_string_t bw_list;
13106         uint8_t tc_map;
13107 };
13108
13109 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13110         TOKEN_STRING_INITIALIZER
13111                 (struct cmd_vf_tc_bw_result,
13112                  set, "set");
13113 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13114         TOKEN_STRING_INITIALIZER
13115                 (struct cmd_vf_tc_bw_result,
13116                  vf, "vf");
13117 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13118         TOKEN_STRING_INITIALIZER
13119                 (struct cmd_vf_tc_bw_result,
13120                  tc, "tc");
13121 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13122         TOKEN_STRING_INITIALIZER
13123                 (struct cmd_vf_tc_bw_result,
13124                  tx, "tx");
13125 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13126         TOKEN_STRING_INITIALIZER
13127                 (struct cmd_vf_tc_bw_result,
13128                  strict_link_prio, "strict-link-priority");
13129 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13130         TOKEN_STRING_INITIALIZER
13131                 (struct cmd_vf_tc_bw_result,
13132                  min_bw, "min-bandwidth");
13133 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13134         TOKEN_STRING_INITIALIZER
13135                 (struct cmd_vf_tc_bw_result,
13136                  max_bw, "max-bandwidth");
13137 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13138         TOKEN_NUM_INITIALIZER
13139                 (struct cmd_vf_tc_bw_result,
13140                  port_id, UINT8);
13141 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13142         TOKEN_NUM_INITIALIZER
13143                 (struct cmd_vf_tc_bw_result,
13144                  vf_id, UINT16);
13145 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13146         TOKEN_NUM_INITIALIZER
13147                 (struct cmd_vf_tc_bw_result,
13148                  tc_no, UINT8);
13149 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13150         TOKEN_NUM_INITIALIZER
13151                 (struct cmd_vf_tc_bw_result,
13152                  bw, UINT32);
13153 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13154         TOKEN_STRING_INITIALIZER
13155                 (struct cmd_vf_tc_bw_result,
13156                  bw_list, NULL);
13157 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13158         TOKEN_NUM_INITIALIZER
13159                 (struct cmd_vf_tc_bw_result,
13160                  tc_map, UINT8);
13161
13162 /* VF max bandwidth setting */
13163 static void
13164 cmd_vf_max_bw_parsed(
13165         void *parsed_result,
13166         __attribute__((unused)) struct cmdline *cl,
13167         __attribute__((unused)) void *data)
13168 {
13169         struct cmd_vf_tc_bw_result *res = parsed_result;
13170         int ret = -ENOTSUP;
13171
13172         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13173                 return;
13174
13175 #ifdef RTE_LIBRTE_I40E_PMD
13176         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13177                                          res->vf_id, res->bw);
13178 #endif
13179
13180         switch (ret) {
13181         case 0:
13182                 break;
13183         case -EINVAL:
13184                 printf("invalid vf_id %d or bandwidth %d\n",
13185                        res->vf_id, res->bw);
13186                 break;
13187         case -ENODEV:
13188                 printf("invalid port_id %d\n", res->port_id);
13189                 break;
13190         case -ENOTSUP:
13191                 printf("function not implemented\n");
13192                 break;
13193         default:
13194                 printf("programming error: (%s)\n", strerror(-ret));
13195         }
13196 }
13197
13198 cmdline_parse_inst_t cmd_vf_max_bw = {
13199         .f = cmd_vf_max_bw_parsed,
13200         .data = NULL,
13201         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13202         .tokens = {
13203                 (void *)&cmd_vf_tc_bw_set,
13204                 (void *)&cmd_vf_tc_bw_vf,
13205                 (void *)&cmd_vf_tc_bw_tx,
13206                 (void *)&cmd_vf_tc_bw_max_bw,
13207                 (void *)&cmd_vf_tc_bw_port_id,
13208                 (void *)&cmd_vf_tc_bw_vf_id,
13209                 (void *)&cmd_vf_tc_bw_bw,
13210                 NULL,
13211         },
13212 };
13213
13214 static int
13215 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13216                            uint8_t *tc_num,
13217                            char *str)
13218 {
13219         uint32_t size;
13220         const char *p, *p0 = str;
13221         char s[256];
13222         char *end;
13223         char *str_fld[16];
13224         uint16_t i;
13225         int ret;
13226
13227         p = strchr(p0, '(');
13228         if (p == NULL) {
13229                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13230                 return -1;
13231         }
13232         p++;
13233         p0 = strchr(p, ')');
13234         if (p0 == NULL) {
13235                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13236                 return -1;
13237         }
13238         size = p0 - p;
13239         if (size >= sizeof(s)) {
13240                 printf("The string size exceeds the internal buffer size\n");
13241                 return -1;
13242         }
13243         snprintf(s, sizeof(s), "%.*s", size, p);
13244         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13245         if (ret <= 0) {
13246                 printf("Failed to get the bandwidth list. ");
13247                 return -1;
13248         }
13249         *tc_num = ret;
13250         for (i = 0; i < ret; i++)
13251                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13252
13253         return 0;
13254 }
13255
13256 /* TC min bandwidth setting */
13257 static void
13258 cmd_vf_tc_min_bw_parsed(
13259         void *parsed_result,
13260         __attribute__((unused)) struct cmdline *cl,
13261         __attribute__((unused)) void *data)
13262 {
13263         struct cmd_vf_tc_bw_result *res = parsed_result;
13264         uint8_t tc_num;
13265         uint8_t bw[16];
13266         int ret = -ENOTSUP;
13267
13268         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13269                 return;
13270
13271         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13272         if (ret)
13273                 return;
13274
13275 #ifdef RTE_LIBRTE_I40E_PMD
13276         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13277                                               tc_num, bw);
13278 #endif
13279
13280         switch (ret) {
13281         case 0:
13282                 break;
13283         case -EINVAL:
13284                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13285                 break;
13286         case -ENODEV:
13287                 printf("invalid port_id %d\n", res->port_id);
13288                 break;
13289         case -ENOTSUP:
13290                 printf("function not implemented\n");
13291                 break;
13292         default:
13293                 printf("programming error: (%s)\n", strerror(-ret));
13294         }
13295 }
13296
13297 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13298         .f = cmd_vf_tc_min_bw_parsed,
13299         .data = NULL,
13300         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13301                     " <bw1, bw2, ...>",
13302         .tokens = {
13303                 (void *)&cmd_vf_tc_bw_set,
13304                 (void *)&cmd_vf_tc_bw_vf,
13305                 (void *)&cmd_vf_tc_bw_tc,
13306                 (void *)&cmd_vf_tc_bw_tx,
13307                 (void *)&cmd_vf_tc_bw_min_bw,
13308                 (void *)&cmd_vf_tc_bw_port_id,
13309                 (void *)&cmd_vf_tc_bw_vf_id,
13310                 (void *)&cmd_vf_tc_bw_bw_list,
13311                 NULL,
13312         },
13313 };
13314
13315 static void
13316 cmd_tc_min_bw_parsed(
13317         void *parsed_result,
13318         __attribute__((unused)) struct cmdline *cl,
13319         __attribute__((unused)) void *data)
13320 {
13321         struct cmd_vf_tc_bw_result *res = parsed_result;
13322         struct rte_port *port;
13323         uint8_t tc_num;
13324         uint8_t bw[16];
13325         int ret = -ENOTSUP;
13326
13327         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13328                 return;
13329
13330         port = &ports[res->port_id];
13331         /** Check if the port is not started **/
13332         if (port->port_status != RTE_PORT_STOPPED) {
13333                 printf("Please stop port %d first\n", res->port_id);
13334                 return;
13335         }
13336
13337         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13338         if (ret)
13339                 return;
13340
13341 #ifdef RTE_LIBRTE_IXGBE_PMD
13342         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13343 #endif
13344
13345         switch (ret) {
13346         case 0:
13347                 break;
13348         case -EINVAL:
13349                 printf("invalid bandwidth\n");
13350                 break;
13351         case -ENODEV:
13352                 printf("invalid port_id %d\n", res->port_id);
13353                 break;
13354         case -ENOTSUP:
13355                 printf("function not implemented\n");
13356                 break;
13357         default:
13358                 printf("programming error: (%s)\n", strerror(-ret));
13359         }
13360 }
13361
13362 cmdline_parse_inst_t cmd_tc_min_bw = {
13363         .f = cmd_tc_min_bw_parsed,
13364         .data = NULL,
13365         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13366         .tokens = {
13367                 (void *)&cmd_vf_tc_bw_set,
13368                 (void *)&cmd_vf_tc_bw_tc,
13369                 (void *)&cmd_vf_tc_bw_tx,
13370                 (void *)&cmd_vf_tc_bw_min_bw,
13371                 (void *)&cmd_vf_tc_bw_port_id,
13372                 (void *)&cmd_vf_tc_bw_bw_list,
13373                 NULL,
13374         },
13375 };
13376
13377 /* TC max bandwidth setting */
13378 static void
13379 cmd_vf_tc_max_bw_parsed(
13380         void *parsed_result,
13381         __attribute__((unused)) struct cmdline *cl,
13382         __attribute__((unused)) void *data)
13383 {
13384         struct cmd_vf_tc_bw_result *res = parsed_result;
13385         int ret = -ENOTSUP;
13386
13387         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13388                 return;
13389
13390 #ifdef RTE_LIBRTE_I40E_PMD
13391         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13392                                             res->tc_no, res->bw);
13393 #endif
13394
13395         switch (ret) {
13396         case 0:
13397                 break;
13398         case -EINVAL:
13399                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13400                        res->vf_id, res->tc_no, res->bw);
13401                 break;
13402         case -ENODEV:
13403                 printf("invalid port_id %d\n", res->port_id);
13404                 break;
13405         case -ENOTSUP:
13406                 printf("function not implemented\n");
13407                 break;
13408         default:
13409                 printf("programming error: (%s)\n", strerror(-ret));
13410         }
13411 }
13412
13413 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13414         .f = cmd_vf_tc_max_bw_parsed,
13415         .data = NULL,
13416         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13417                     " <bandwidth>",
13418         .tokens = {
13419                 (void *)&cmd_vf_tc_bw_set,
13420                 (void *)&cmd_vf_tc_bw_vf,
13421                 (void *)&cmd_vf_tc_bw_tc,
13422                 (void *)&cmd_vf_tc_bw_tx,
13423                 (void *)&cmd_vf_tc_bw_max_bw,
13424                 (void *)&cmd_vf_tc_bw_port_id,
13425                 (void *)&cmd_vf_tc_bw_vf_id,
13426                 (void *)&cmd_vf_tc_bw_tc_no,
13427                 (void *)&cmd_vf_tc_bw_bw,
13428                 NULL,
13429         },
13430 };
13431
13432
13433 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13434
13435 /* *** Set Port default Traffic Management Hierarchy *** */
13436 struct cmd_set_port_tm_hierarchy_default_result {
13437         cmdline_fixed_string_t set;
13438         cmdline_fixed_string_t port;
13439         cmdline_fixed_string_t tm;
13440         cmdline_fixed_string_t hierarchy;
13441         cmdline_fixed_string_t def;
13442         uint16_t port_id;
13443 };
13444
13445 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13446         TOKEN_STRING_INITIALIZER(
13447                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13448 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13449         TOKEN_STRING_INITIALIZER(
13450                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13451 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13452         TOKEN_STRING_INITIALIZER(
13453                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13454 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
13455         TOKEN_STRING_INITIALIZER(
13456                 struct cmd_set_port_tm_hierarchy_default_result,
13457                         hierarchy, "hierarchy");
13458 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
13459         TOKEN_STRING_INITIALIZER(
13460                 struct cmd_set_port_tm_hierarchy_default_result,
13461                         def, "default");
13462 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
13463         TOKEN_NUM_INITIALIZER(
13464                 struct cmd_set_port_tm_hierarchy_default_result,
13465                         port_id, UINT8);
13466
13467 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
13468         __attribute__((unused)) struct cmdline *cl,
13469         __attribute__((unused)) void *data)
13470 {
13471         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
13472         struct rte_port *p;
13473         uint16_t port_id = res->port_id;
13474
13475         if (port_id_is_invalid(port_id, ENABLED_WARN))
13476                 return;
13477
13478         p = &ports[port_id];
13479
13480         /* Port tm flag */
13481         if (p->softport.tm_flag == 0) {
13482                 printf("  tm not enabled on port %u (error)\n", port_id);
13483                 return;
13484         }
13485
13486         /* Forward mode: tm */
13487         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
13488                 printf("  tm mode not enabled(error)\n");
13489                 return;
13490         }
13491
13492         /* Set the default tm hierarchy */
13493         p->softport.tm.default_hierarchy_enable = 1;
13494 }
13495
13496 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
13497         .f = cmd_set_port_tm_hierarchy_default_parsed,
13498         .data = NULL,
13499         .help_str = "set port tm hierarchy default <port_id>",
13500         .tokens = {
13501                 (void *)&cmd_set_port_tm_hierarchy_default_set,
13502                 (void *)&cmd_set_port_tm_hierarchy_default_port,
13503                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
13504                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
13505                 (void *)&cmd_set_port_tm_hierarchy_default_default,
13506                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
13507                 NULL,
13508         },
13509 };
13510 #endif
13511
13512 /* Strict link priority scheduling mode setting */
13513 static void
13514 cmd_strict_link_prio_parsed(
13515         void *parsed_result,
13516         __attribute__((unused)) struct cmdline *cl,
13517         __attribute__((unused)) void *data)
13518 {
13519         struct cmd_vf_tc_bw_result *res = parsed_result;
13520         int ret = -ENOTSUP;
13521
13522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13523                 return;
13524
13525 #ifdef RTE_LIBRTE_I40E_PMD
13526         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13527 #endif
13528
13529         switch (ret) {
13530         case 0:
13531                 break;
13532         case -EINVAL:
13533                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13534                 break;
13535         case -ENODEV:
13536                 printf("invalid port_id %d\n", res->port_id);
13537                 break;
13538         case -ENOTSUP:
13539                 printf("function not implemented\n");
13540                 break;
13541         default:
13542                 printf("programming error: (%s)\n", strerror(-ret));
13543         }
13544 }
13545
13546 cmdline_parse_inst_t cmd_strict_link_prio = {
13547         .f = cmd_strict_link_prio_parsed,
13548         .data = NULL,
13549         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13550         .tokens = {
13551                 (void *)&cmd_vf_tc_bw_set,
13552                 (void *)&cmd_vf_tc_bw_tx,
13553                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13554                 (void *)&cmd_vf_tc_bw_port_id,
13555                 (void *)&cmd_vf_tc_bw_tc_map,
13556                 NULL,
13557         },
13558 };
13559
13560 /* Load dynamic device personalization*/
13561 struct cmd_ddp_add_result {
13562         cmdline_fixed_string_t ddp;
13563         cmdline_fixed_string_t add;
13564         uint8_t port_id;
13565         char filepath[];
13566 };
13567
13568 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13569         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13570 cmdline_parse_token_string_t cmd_ddp_add_add =
13571         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13572 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13573         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13574 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13575         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13576
13577 static void
13578 cmd_ddp_add_parsed(
13579         void *parsed_result,
13580         __attribute__((unused)) struct cmdline *cl,
13581         __attribute__((unused)) void *data)
13582 {
13583         struct cmd_ddp_add_result *res = parsed_result;
13584         uint8_t *buff;
13585         uint32_t size;
13586         char *filepath;
13587         char *file_fld[2];
13588         int file_num;
13589         int ret = -ENOTSUP;
13590
13591         if (res->port_id > nb_ports) {
13592                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13593                 return;
13594         }
13595
13596         if (!all_ports_stopped()) {
13597                 printf("Please stop all ports first\n");
13598                 return;
13599         }
13600
13601         filepath = strdup(res->filepath);
13602         if (filepath == NULL) {
13603                 printf("Failed to allocate memory\n");
13604                 return;
13605         }
13606         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13607
13608         buff = open_ddp_package_file(file_fld[0], &size);
13609         if (!buff) {
13610                 free((void *)filepath);
13611                 return;
13612         }
13613
13614 #ifdef RTE_LIBRTE_I40E_PMD
13615         if (ret == -ENOTSUP)
13616                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13617                                                buff, size,
13618                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13619 #endif
13620
13621         if (ret == -EEXIST)
13622                 printf("Profile has already existed.\n");
13623         else if (ret < 0)
13624                 printf("Failed to load profile.\n");
13625         else if (file_num == 2)
13626                 save_ddp_package_file(file_fld[1], buff, size);
13627
13628         close_ddp_package_file(buff);
13629         free((void *)filepath);
13630 }
13631
13632 cmdline_parse_inst_t cmd_ddp_add = {
13633         .f = cmd_ddp_add_parsed,
13634         .data = NULL,
13635         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13636         .tokens = {
13637                 (void *)&cmd_ddp_add_ddp,
13638                 (void *)&cmd_ddp_add_add,
13639                 (void *)&cmd_ddp_add_port_id,
13640                 (void *)&cmd_ddp_add_filepath,
13641                 NULL,
13642         },
13643 };
13644
13645 /* Delete dynamic device personalization*/
13646 struct cmd_ddp_del_result {
13647         cmdline_fixed_string_t ddp;
13648         cmdline_fixed_string_t del;
13649         uint8_t port_id;
13650         char filepath[];
13651 };
13652
13653 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13654         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13655 cmdline_parse_token_string_t cmd_ddp_del_del =
13656         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13657 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13658         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13659 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13660         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13661
13662 static void
13663 cmd_ddp_del_parsed(
13664         void *parsed_result,
13665         __attribute__((unused)) struct cmdline *cl,
13666         __attribute__((unused)) void *data)
13667 {
13668         struct cmd_ddp_del_result *res = parsed_result;
13669         uint8_t *buff;
13670         uint32_t size;
13671         int ret = -ENOTSUP;
13672
13673         if (res->port_id > nb_ports) {
13674                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13675                 return;
13676         }
13677
13678         if (!all_ports_stopped()) {
13679                 printf("Please stop all ports first\n");
13680                 return;
13681         }
13682
13683         buff = open_ddp_package_file(res->filepath, &size);
13684         if (!buff)
13685                 return;
13686
13687 #ifdef RTE_LIBRTE_I40E_PMD
13688         if (ret == -ENOTSUP)
13689                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13690                                                buff, size,
13691                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13692 #endif
13693
13694         if (ret == -EACCES)
13695                 printf("Profile does not exist.\n");
13696         else if (ret < 0)
13697                 printf("Failed to delete profile.\n");
13698
13699         close_ddp_package_file(buff);
13700 }
13701
13702 cmdline_parse_inst_t cmd_ddp_del = {
13703         .f = cmd_ddp_del_parsed,
13704         .data = NULL,
13705         .help_str = "ddp del <port_id> <profile_path>",
13706         .tokens = {
13707                 (void *)&cmd_ddp_del_ddp,
13708                 (void *)&cmd_ddp_del_del,
13709                 (void *)&cmd_ddp_del_port_id,
13710                 (void *)&cmd_ddp_del_filepath,
13711                 NULL,
13712         },
13713 };
13714
13715 /* Get dynamic device personalization profile info */
13716 struct cmd_ddp_info_result {
13717         cmdline_fixed_string_t ddp;
13718         cmdline_fixed_string_t get;
13719         cmdline_fixed_string_t info;
13720         char filepath[];
13721 };
13722
13723 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13724         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13725 cmdline_parse_token_string_t cmd_ddp_info_get =
13726         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13727 cmdline_parse_token_string_t cmd_ddp_info_info =
13728         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13729 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13730         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13731
13732 static void
13733 cmd_ddp_info_parsed(
13734         void *parsed_result,
13735         __attribute__((unused)) struct cmdline *cl,
13736         __attribute__((unused)) void *data)
13737 {
13738         struct cmd_ddp_info_result *res = parsed_result;
13739         uint8_t *pkg;
13740         uint32_t pkg_size;
13741         int ret = -ENOTSUP;
13742 #ifdef RTE_LIBRTE_I40E_PMD
13743         uint32_t i, j, n;
13744         uint8_t *buff;
13745         uint32_t buff_size = 0;
13746         struct rte_pmd_i40e_profile_info info;
13747         uint32_t dev_num = 0;
13748         struct rte_pmd_i40e_ddp_device_id *devs;
13749         uint32_t proto_num = 0;
13750         struct rte_pmd_i40e_proto_info *proto;
13751         uint32_t pctype_num = 0;
13752         struct rte_pmd_i40e_ptype_info *pctype;
13753         uint32_t ptype_num = 0;
13754         struct rte_pmd_i40e_ptype_info *ptype;
13755         uint8_t proto_id;
13756
13757 #endif
13758
13759         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13760         if (!pkg)
13761                 return;
13762
13763 #ifdef RTE_LIBRTE_I40E_PMD
13764         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13765                                 (uint8_t *)&info, sizeof(info),
13766                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13767         if (!ret) {
13768                 printf("Global Track id:       0x%x\n", info.track_id);
13769                 printf("Global Version:        %d.%d.%d.%d\n",
13770                         info.version.major,
13771                         info.version.minor,
13772                         info.version.update,
13773                         info.version.draft);
13774                 printf("Global Package name:   %s\n\n", info.name);
13775         }
13776
13777         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13778                                 (uint8_t *)&info, sizeof(info),
13779                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13780         if (!ret) {
13781                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13782                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13783                         info.version.major,
13784                         info.version.minor,
13785                         info.version.update,
13786                         info.version.draft);
13787                 printf("i40e Profile name:     %s\n\n", info.name);
13788         }
13789
13790         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13791                                 (uint8_t *)&buff_size, sizeof(buff_size),
13792                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13793         if (!ret && buff_size) {
13794                 buff = (uint8_t *)malloc(buff_size);
13795                 if (buff) {
13796                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13797                                                 buff, buff_size,
13798                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13799                         if (!ret)
13800                                 printf("Package Notes:\n%s\n\n", buff);
13801                         free(buff);
13802                 }
13803         }
13804
13805         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13806                                 (uint8_t *)&dev_num, sizeof(dev_num),
13807                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13808         if (!ret && dev_num) {
13809                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13810                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13811                 if (devs) {
13812                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13813                                                 (uint8_t *)devs, buff_size,
13814                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13815                         if (!ret) {
13816                                 printf("List of supported devices:\n");
13817                                 for (i = 0; i < dev_num; i++) {
13818                                         printf("  %04X:%04X %04X:%04X\n",
13819                                                 devs[i].vendor_dev_id >> 16,
13820                                                 devs[i].vendor_dev_id & 0xFFFF,
13821                                                 devs[i].sub_vendor_dev_id >> 16,
13822                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13823                                 }
13824                                 printf("\n");
13825                         }
13826                         free(devs);
13827                 }
13828         }
13829
13830         /* get information about protocols and packet types */
13831         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13832                 (uint8_t *)&proto_num, sizeof(proto_num),
13833                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13834         if (ret || !proto_num)
13835                 goto no_print_return;
13836
13837         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13838         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13839         if (!proto)
13840                 goto no_print_return;
13841
13842         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13843                                         buff_size,
13844                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13845         if (!ret) {
13846                 printf("List of used protocols:\n");
13847                 for (i = 0; i < proto_num; i++)
13848                         printf("  %2u: %s\n", proto[i].proto_id,
13849                                proto[i].name);
13850                 printf("\n");
13851         }
13852         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13853                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13854                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13855         if (ret || !pctype_num)
13856                 goto no_print_pctypes;
13857
13858         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13859         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13860         if (!pctype)
13861                 goto no_print_pctypes;
13862
13863         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13864                                         buff_size,
13865                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13866         if (ret) {
13867                 free(pctype);
13868                 goto no_print_pctypes;
13869         }
13870
13871         printf("List of defined packet classification types:\n");
13872         for (i = 0; i < pctype_num; i++) {
13873                 printf("  %2u:", pctype[i].ptype_id);
13874                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13875                         proto_id = pctype[i].protocols[j];
13876                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13877                                 for (n = 0; n < proto_num; n++) {
13878                                         if (proto[n].proto_id == proto_id) {
13879                                                 printf(" %s", proto[n].name);
13880                                                 break;
13881                                         }
13882                                 }
13883                         }
13884                 }
13885                 printf("\n");
13886         }
13887         printf("\n");
13888         free(pctype);
13889
13890 no_print_pctypes:
13891
13892         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13893                                         sizeof(ptype_num),
13894                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13895         if (ret || !ptype_num)
13896                 goto no_print_return;
13897
13898         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13899         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13900         if (!ptype)
13901                 goto no_print_return;
13902
13903         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13904                                         buff_size,
13905                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13906         if (ret) {
13907                 free(ptype);
13908                 goto no_print_return;
13909         }
13910         printf("List of defined packet types:\n");
13911         for (i = 0; i < ptype_num; i++) {
13912                 printf("  %2u:", ptype[i].ptype_id);
13913                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13914                         proto_id = ptype[i].protocols[j];
13915                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13916                                 for (n = 0; n < proto_num; n++) {
13917                                         if (proto[n].proto_id == proto_id) {
13918                                                 printf(" %s", proto[n].name);
13919                                                 break;
13920                                         }
13921                                 }
13922                         }
13923                 }
13924                 printf("\n");
13925         }
13926         free(ptype);
13927         printf("\n");
13928
13929         free(proto);
13930         ret = 0;
13931 no_print_return:
13932 #endif
13933         if (ret == -ENOTSUP)
13934                 printf("Function not supported in PMD driver\n");
13935         close_ddp_package_file(pkg);
13936 }
13937
13938 cmdline_parse_inst_t cmd_ddp_get_info = {
13939         .f = cmd_ddp_info_parsed,
13940         .data = NULL,
13941         .help_str = "ddp get info <profile_path>",
13942         .tokens = {
13943                 (void *)&cmd_ddp_info_ddp,
13944                 (void *)&cmd_ddp_info_get,
13945                 (void *)&cmd_ddp_info_info,
13946                 (void *)&cmd_ddp_info_filepath,
13947                 NULL,
13948         },
13949 };
13950
13951 /* Get dynamic device personalization profile info list*/
13952 #define PROFILE_INFO_SIZE 48
13953 #define MAX_PROFILE_NUM 16
13954
13955 struct cmd_ddp_get_list_result {
13956         cmdline_fixed_string_t ddp;
13957         cmdline_fixed_string_t get;
13958         cmdline_fixed_string_t list;
13959         uint8_t port_id;
13960 };
13961
13962 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13963         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13964 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13965         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13966 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13967         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13968 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13969         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13970
13971 static void
13972 cmd_ddp_get_list_parsed(
13973         void *parsed_result,
13974         __attribute__((unused)) struct cmdline *cl,
13975         __attribute__((unused)) void *data)
13976 {
13977         struct cmd_ddp_get_list_result *res = parsed_result;
13978 #ifdef RTE_LIBRTE_I40E_PMD
13979         struct rte_pmd_i40e_profile_list *p_list;
13980         struct rte_pmd_i40e_profile_info *p_info;
13981         uint32_t p_num;
13982         uint32_t size;
13983         uint32_t i;
13984 #endif
13985         int ret = -ENOTSUP;
13986
13987         if (res->port_id > nb_ports) {
13988                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13989                 return;
13990         }
13991
13992 #ifdef RTE_LIBRTE_I40E_PMD
13993         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13994         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13995         if (!p_list)
13996                 printf("%s: Failed to malloc buffer\n", __func__);
13997
13998         if (ret == -ENOTSUP)
13999                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14000                                                 (uint8_t *)p_list, size);
14001
14002         if (!ret) {
14003                 p_num = p_list->p_count;
14004                 printf("Profile number is: %d\n\n", p_num);
14005
14006                 for (i = 0; i < p_num; i++) {
14007                         p_info = &p_list->p_info[i];
14008                         printf("Profile %d:\n", i);
14009                         printf("Track id:     0x%x\n", p_info->track_id);
14010                         printf("Version:      %d.%d.%d.%d\n",
14011                                p_info->version.major,
14012                                p_info->version.minor,
14013                                p_info->version.update,
14014                                p_info->version.draft);
14015                         printf("Profile name: %s\n\n", p_info->name);
14016                 }
14017         }
14018
14019         free(p_list);
14020 #endif
14021
14022         if (ret < 0)
14023                 printf("Failed to get ddp list\n");
14024 }
14025
14026 cmdline_parse_inst_t cmd_ddp_get_list = {
14027         .f = cmd_ddp_get_list_parsed,
14028         .data = NULL,
14029         .help_str = "ddp get list <port_id>",
14030         .tokens = {
14031                 (void *)&cmd_ddp_get_list_ddp,
14032                 (void *)&cmd_ddp_get_list_get,
14033                 (void *)&cmd_ddp_get_list_list,
14034                 (void *)&cmd_ddp_get_list_port_id,
14035                 NULL,
14036         },
14037 };
14038
14039 /* show vf stats */
14040
14041 /* Common result structure for show vf stats */
14042 struct cmd_show_vf_stats_result {
14043         cmdline_fixed_string_t show;
14044         cmdline_fixed_string_t vf;
14045         cmdline_fixed_string_t stats;
14046         uint8_t port_id;
14047         uint16_t vf_id;
14048 };
14049
14050 /* Common CLI fields show vf stats*/
14051 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14052         TOKEN_STRING_INITIALIZER
14053                 (struct cmd_show_vf_stats_result,
14054                  show, "show");
14055 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14056         TOKEN_STRING_INITIALIZER
14057                 (struct cmd_show_vf_stats_result,
14058                  vf, "vf");
14059 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14060         TOKEN_STRING_INITIALIZER
14061                 (struct cmd_show_vf_stats_result,
14062                  stats, "stats");
14063 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14064         TOKEN_NUM_INITIALIZER
14065                 (struct cmd_show_vf_stats_result,
14066                  port_id, UINT8);
14067 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14068         TOKEN_NUM_INITIALIZER
14069                 (struct cmd_show_vf_stats_result,
14070                  vf_id, UINT16);
14071
14072 static void
14073 cmd_show_vf_stats_parsed(
14074         void *parsed_result,
14075         __attribute__((unused)) struct cmdline *cl,
14076         __attribute__((unused)) void *data)
14077 {
14078         struct cmd_show_vf_stats_result *res = parsed_result;
14079         struct rte_eth_stats stats;
14080         int ret = -ENOTSUP;
14081         static const char *nic_stats_border = "########################";
14082
14083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14084                 return;
14085
14086         memset(&stats, 0, sizeof(stats));
14087
14088 #ifdef RTE_LIBRTE_I40E_PMD
14089         if (ret == -ENOTSUP)
14090                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14091                                                 res->vf_id,
14092                                                 &stats);
14093 #endif
14094 #ifdef RTE_LIBRTE_BNXT_PMD
14095         if (ret == -ENOTSUP)
14096                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14097                                                 res->vf_id,
14098                                                 &stats);
14099 #endif
14100
14101         switch (ret) {
14102         case 0:
14103                 break;
14104         case -EINVAL:
14105                 printf("invalid vf_id %d\n", res->vf_id);
14106                 break;
14107         case -ENODEV:
14108                 printf("invalid port_id %d\n", res->port_id);
14109                 break;
14110         case -ENOTSUP:
14111                 printf("function not implemented\n");
14112                 break;
14113         default:
14114                 printf("programming error: (%s)\n", strerror(-ret));
14115         }
14116
14117         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14118                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14119
14120         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14121                "%-"PRIu64"\n",
14122                stats.ipackets, stats.imissed, stats.ibytes);
14123         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14124         printf("  RX-nombuf:  %-10"PRIu64"\n",
14125                stats.rx_nombuf);
14126         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14127                "%-"PRIu64"\n",
14128                stats.opackets, stats.oerrors, stats.obytes);
14129
14130         printf("  %s############################%s\n",
14131                                nic_stats_border, nic_stats_border);
14132 }
14133
14134 cmdline_parse_inst_t cmd_show_vf_stats = {
14135         .f = cmd_show_vf_stats_parsed,
14136         .data = NULL,
14137         .help_str = "show vf stats <port_id> <vf_id>",
14138         .tokens = {
14139                 (void *)&cmd_show_vf_stats_show,
14140                 (void *)&cmd_show_vf_stats_vf,
14141                 (void *)&cmd_show_vf_stats_stats,
14142                 (void *)&cmd_show_vf_stats_port_id,
14143                 (void *)&cmd_show_vf_stats_vf_id,
14144                 NULL,
14145         },
14146 };
14147
14148 /* clear vf stats */
14149
14150 /* Common result structure for clear vf stats */
14151 struct cmd_clear_vf_stats_result {
14152         cmdline_fixed_string_t clear;
14153         cmdline_fixed_string_t vf;
14154         cmdline_fixed_string_t stats;
14155         uint8_t port_id;
14156         uint16_t vf_id;
14157 };
14158
14159 /* Common CLI fields clear vf stats*/
14160 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14161         TOKEN_STRING_INITIALIZER
14162                 (struct cmd_clear_vf_stats_result,
14163                  clear, "clear");
14164 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14165         TOKEN_STRING_INITIALIZER
14166                 (struct cmd_clear_vf_stats_result,
14167                  vf, "vf");
14168 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14169         TOKEN_STRING_INITIALIZER
14170                 (struct cmd_clear_vf_stats_result,
14171                  stats, "stats");
14172 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14173         TOKEN_NUM_INITIALIZER
14174                 (struct cmd_clear_vf_stats_result,
14175                  port_id, UINT8);
14176 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14177         TOKEN_NUM_INITIALIZER
14178                 (struct cmd_clear_vf_stats_result,
14179                  vf_id, UINT16);
14180
14181 static void
14182 cmd_clear_vf_stats_parsed(
14183         void *parsed_result,
14184         __attribute__((unused)) struct cmdline *cl,
14185         __attribute__((unused)) void *data)
14186 {
14187         struct cmd_clear_vf_stats_result *res = parsed_result;
14188         int ret = -ENOTSUP;
14189
14190         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14191                 return;
14192
14193 #ifdef RTE_LIBRTE_I40E_PMD
14194         if (ret == -ENOTSUP)
14195                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14196                                                   res->vf_id);
14197 #endif
14198 #ifdef RTE_LIBRTE_BNXT_PMD
14199         if (ret == -ENOTSUP)
14200                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14201                                                   res->vf_id);
14202 #endif
14203
14204         switch (ret) {
14205         case 0:
14206                 break;
14207         case -EINVAL:
14208                 printf("invalid vf_id %d\n", res->vf_id);
14209                 break;
14210         case -ENODEV:
14211                 printf("invalid port_id %d\n", res->port_id);
14212                 break;
14213         case -ENOTSUP:
14214                 printf("function not implemented\n");
14215                 break;
14216         default:
14217                 printf("programming error: (%s)\n", strerror(-ret));
14218         }
14219 }
14220
14221 cmdline_parse_inst_t cmd_clear_vf_stats = {
14222         .f = cmd_clear_vf_stats_parsed,
14223         .data = NULL,
14224         .help_str = "clear vf stats <port_id> <vf_id>",
14225         .tokens = {
14226                 (void *)&cmd_clear_vf_stats_clear,
14227                 (void *)&cmd_clear_vf_stats_vf,
14228                 (void *)&cmd_clear_vf_stats_stats,
14229                 (void *)&cmd_clear_vf_stats_port_id,
14230                 (void *)&cmd_clear_vf_stats_vf_id,
14231                 NULL,
14232         },
14233 };
14234
14235 /* port config pctype mapping reset */
14236
14237 /* Common result structure for port config pctype mapping reset */
14238 struct cmd_pctype_mapping_reset_result {
14239         cmdline_fixed_string_t port;
14240         cmdline_fixed_string_t config;
14241         uint8_t port_id;
14242         cmdline_fixed_string_t pctype;
14243         cmdline_fixed_string_t mapping;
14244         cmdline_fixed_string_t reset;
14245 };
14246
14247 /* Common CLI fields for port config pctype mapping reset*/
14248 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14249         TOKEN_STRING_INITIALIZER
14250                 (struct cmd_pctype_mapping_reset_result,
14251                  port, "port");
14252 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14253         TOKEN_STRING_INITIALIZER
14254                 (struct cmd_pctype_mapping_reset_result,
14255                  config, "config");
14256 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14257         TOKEN_NUM_INITIALIZER
14258                 (struct cmd_pctype_mapping_reset_result,
14259                  port_id, UINT8);
14260 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14261         TOKEN_STRING_INITIALIZER
14262                 (struct cmd_pctype_mapping_reset_result,
14263                  pctype, "pctype");
14264 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_pctype_mapping_reset_result,
14267                  mapping, "mapping");
14268 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14269         TOKEN_STRING_INITIALIZER
14270                 (struct cmd_pctype_mapping_reset_result,
14271                  reset, "reset");
14272
14273 static void
14274 cmd_pctype_mapping_reset_parsed(
14275         void *parsed_result,
14276         __attribute__((unused)) struct cmdline *cl,
14277         __attribute__((unused)) void *data)
14278 {
14279         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14280         int ret = -ENOTSUP;
14281
14282         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14283                 return;
14284
14285 #ifdef RTE_LIBRTE_I40E_PMD
14286         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14287 #endif
14288
14289         switch (ret) {
14290         case 0:
14291                 break;
14292         case -ENODEV:
14293                 printf("invalid port_id %d\n", res->port_id);
14294                 break;
14295         case -ENOTSUP:
14296                 printf("function not implemented\n");
14297                 break;
14298         default:
14299                 printf("programming error: (%s)\n", strerror(-ret));
14300         }
14301 }
14302
14303 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14304         .f = cmd_pctype_mapping_reset_parsed,
14305         .data = NULL,
14306         .help_str = "port config <port_id> pctype mapping reset",
14307         .tokens = {
14308                 (void *)&cmd_pctype_mapping_reset_port,
14309                 (void *)&cmd_pctype_mapping_reset_config,
14310                 (void *)&cmd_pctype_mapping_reset_port_id,
14311                 (void *)&cmd_pctype_mapping_reset_pctype,
14312                 (void *)&cmd_pctype_mapping_reset_mapping,
14313                 (void *)&cmd_pctype_mapping_reset_reset,
14314                 NULL,
14315         },
14316 };
14317
14318 /* show port pctype mapping */
14319
14320 /* Common result structure for show port pctype mapping */
14321 struct cmd_pctype_mapping_get_result {
14322         cmdline_fixed_string_t show;
14323         cmdline_fixed_string_t port;
14324         uint8_t port_id;
14325         cmdline_fixed_string_t pctype;
14326         cmdline_fixed_string_t mapping;
14327 };
14328
14329 /* Common CLI fields for pctype mapping get */
14330 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14331         TOKEN_STRING_INITIALIZER
14332                 (struct cmd_pctype_mapping_get_result,
14333                  show, "show");
14334 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14335         TOKEN_STRING_INITIALIZER
14336                 (struct cmd_pctype_mapping_get_result,
14337                  port, "port");
14338 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14339         TOKEN_NUM_INITIALIZER
14340                 (struct cmd_pctype_mapping_get_result,
14341                  port_id, UINT8);
14342 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14343         TOKEN_STRING_INITIALIZER
14344                 (struct cmd_pctype_mapping_get_result,
14345                  pctype, "pctype");
14346 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14347         TOKEN_STRING_INITIALIZER
14348                 (struct cmd_pctype_mapping_get_result,
14349                  mapping, "mapping");
14350
14351 static void
14352 cmd_pctype_mapping_get_parsed(
14353         void *parsed_result,
14354         __attribute__((unused)) struct cmdline *cl,
14355         __attribute__((unused)) void *data)
14356 {
14357         struct cmd_pctype_mapping_get_result *res = parsed_result;
14358         int ret = -ENOTSUP;
14359 #ifdef RTE_LIBRTE_I40E_PMD
14360         struct rte_pmd_i40e_flow_type_mapping
14361                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14362         int i, j, first_pctype;
14363 #endif
14364
14365         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14366                 return;
14367
14368 #ifdef RTE_LIBRTE_I40E_PMD
14369         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14370 #endif
14371
14372         switch (ret) {
14373         case 0:
14374                 break;
14375         case -ENODEV:
14376                 printf("invalid port_id %d\n", res->port_id);
14377                 return;
14378         case -ENOTSUP:
14379                 printf("function not implemented\n");
14380                 return;
14381         default:
14382                 printf("programming error: (%s)\n", strerror(-ret));
14383                 return;
14384         }
14385
14386 #ifdef RTE_LIBRTE_I40E_PMD
14387         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14388                 if (mapping[i].pctype != 0ULL) {
14389                         first_pctype = 1;
14390
14391                         printf("pctype: ");
14392                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14393                                 if (mapping[i].pctype & (1ULL << j)) {
14394                                         printf(first_pctype ?
14395                                                "%02d" : ",%02d", j);
14396                                         first_pctype = 0;
14397                                 }
14398                         }
14399                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14400                 }
14401         }
14402 #endif
14403 }
14404
14405 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14406         .f = cmd_pctype_mapping_get_parsed,
14407         .data = NULL,
14408         .help_str = "show port <port_id> pctype mapping",
14409         .tokens = {
14410                 (void *)&cmd_pctype_mapping_get_show,
14411                 (void *)&cmd_pctype_mapping_get_port,
14412                 (void *)&cmd_pctype_mapping_get_port_id,
14413                 (void *)&cmd_pctype_mapping_get_pctype,
14414                 (void *)&cmd_pctype_mapping_get_mapping,
14415                 NULL,
14416         },
14417 };
14418
14419 /* port config pctype mapping update */
14420
14421 /* Common result structure for port config pctype mapping update */
14422 struct cmd_pctype_mapping_update_result {
14423         cmdline_fixed_string_t port;
14424         cmdline_fixed_string_t config;
14425         uint8_t port_id;
14426         cmdline_fixed_string_t pctype;
14427         cmdline_fixed_string_t mapping;
14428         cmdline_fixed_string_t update;
14429         cmdline_fixed_string_t pctype_list;
14430         uint16_t flow_type;
14431 };
14432
14433 /* Common CLI fields for pctype mapping update*/
14434 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14435         TOKEN_STRING_INITIALIZER
14436                 (struct cmd_pctype_mapping_update_result,
14437                  port, "port");
14438 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14439         TOKEN_STRING_INITIALIZER
14440                 (struct cmd_pctype_mapping_update_result,
14441                  config, "config");
14442 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14443         TOKEN_NUM_INITIALIZER
14444                 (struct cmd_pctype_mapping_update_result,
14445                  port_id, UINT8);
14446 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_pctype_mapping_update_result,
14449                  pctype, "pctype");
14450 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_pctype_mapping_update_result,
14453                  mapping, "mapping");
14454 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14455         TOKEN_STRING_INITIALIZER
14456                 (struct cmd_pctype_mapping_update_result,
14457                  update, "update");
14458 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14459         TOKEN_STRING_INITIALIZER
14460                 (struct cmd_pctype_mapping_update_result,
14461                  pctype_list, NULL);
14462 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14463         TOKEN_NUM_INITIALIZER
14464                 (struct cmd_pctype_mapping_update_result,
14465                  flow_type, UINT16);
14466
14467 static void
14468 cmd_pctype_mapping_update_parsed(
14469         void *parsed_result,
14470         __attribute__((unused)) struct cmdline *cl,
14471         __attribute__((unused)) void *data)
14472 {
14473         struct cmd_pctype_mapping_update_result *res = parsed_result;
14474         int ret = -ENOTSUP;
14475 #ifdef RTE_LIBRTE_I40E_PMD
14476         struct rte_pmd_i40e_flow_type_mapping mapping;
14477         unsigned int i;
14478         unsigned int nb_item;
14479         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14480 #endif
14481
14482         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14483                 return;
14484
14485 #ifdef RTE_LIBRTE_I40E_PMD
14486         nb_item = parse_item_list(res->pctype_list, "pctypes",
14487                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14488         mapping.flow_type = res->flow_type;
14489         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14490                 mapping.pctype |= (1ULL << pctype_list[i]);
14491         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14492                                                 &mapping,
14493                                                 1,
14494                                                 0);
14495 #endif
14496
14497         switch (ret) {
14498         case 0:
14499                 break;
14500         case -EINVAL:
14501                 printf("invalid pctype or flow type\n");
14502                 break;
14503         case -ENODEV:
14504                 printf("invalid port_id %d\n", res->port_id);
14505                 break;
14506         case -ENOTSUP:
14507                 printf("function not implemented\n");
14508                 break;
14509         default:
14510                 printf("programming error: (%s)\n", strerror(-ret));
14511         }
14512 }
14513
14514 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14515         .f = cmd_pctype_mapping_update_parsed,
14516         .data = NULL,
14517         .help_str = "port config <port_id> pctype mapping update"
14518         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14519         .tokens = {
14520                 (void *)&cmd_pctype_mapping_update_port,
14521                 (void *)&cmd_pctype_mapping_update_config,
14522                 (void *)&cmd_pctype_mapping_update_port_id,
14523                 (void *)&cmd_pctype_mapping_update_pctype,
14524                 (void *)&cmd_pctype_mapping_update_mapping,
14525                 (void *)&cmd_pctype_mapping_update_update,
14526                 (void *)&cmd_pctype_mapping_update_pc_type,
14527                 (void *)&cmd_pctype_mapping_update_flow_type,
14528                 NULL,
14529         },
14530 };
14531
14532 /* ptype mapping get */
14533
14534 /* Common result structure for ptype mapping get */
14535 struct cmd_ptype_mapping_get_result {
14536         cmdline_fixed_string_t ptype;
14537         cmdline_fixed_string_t mapping;
14538         cmdline_fixed_string_t get;
14539         uint8_t port_id;
14540         uint8_t valid_only;
14541 };
14542
14543 /* Common CLI fields for ptype mapping get */
14544 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14545         TOKEN_STRING_INITIALIZER
14546                 (struct cmd_ptype_mapping_get_result,
14547                  ptype, "ptype");
14548 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14549         TOKEN_STRING_INITIALIZER
14550                 (struct cmd_ptype_mapping_get_result,
14551                  mapping, "mapping");
14552 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14553         TOKEN_STRING_INITIALIZER
14554                 (struct cmd_ptype_mapping_get_result,
14555                  get, "get");
14556 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14557         TOKEN_NUM_INITIALIZER
14558                 (struct cmd_ptype_mapping_get_result,
14559                  port_id, UINT8);
14560 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14561         TOKEN_NUM_INITIALIZER
14562                 (struct cmd_ptype_mapping_get_result,
14563                  valid_only, UINT8);
14564
14565 static void
14566 cmd_ptype_mapping_get_parsed(
14567         void *parsed_result,
14568         __attribute__((unused)) struct cmdline *cl,
14569         __attribute__((unused)) void *data)
14570 {
14571         struct cmd_ptype_mapping_get_result *res = parsed_result;
14572         int ret = -ENOTSUP;
14573 #ifdef RTE_LIBRTE_I40E_PMD
14574         int max_ptype_num = 256;
14575         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14576         uint16_t count;
14577         int i;
14578 #endif
14579
14580         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14581                 return;
14582
14583 #ifdef RTE_LIBRTE_I40E_PMD
14584         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14585                                         mapping,
14586                                         max_ptype_num,
14587                                         &count,
14588                                         res->valid_only);
14589 #endif
14590
14591         switch (ret) {
14592         case 0:
14593                 break;
14594         case -ENODEV:
14595                 printf("invalid port_id %d\n", res->port_id);
14596                 break;
14597         case -ENOTSUP:
14598                 printf("function not implemented\n");
14599                 break;
14600         default:
14601                 printf("programming error: (%s)\n", strerror(-ret));
14602         }
14603
14604 #ifdef RTE_LIBRTE_I40E_PMD
14605         if (!ret) {
14606                 for (i = 0; i < count; i++)
14607                         printf("%3d\t0x%08x\n",
14608                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14609         }
14610 #endif
14611 }
14612
14613 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14614         .f = cmd_ptype_mapping_get_parsed,
14615         .data = NULL,
14616         .help_str = "ptype mapping get <port_id> <valid_only>",
14617         .tokens = {
14618                 (void *)&cmd_ptype_mapping_get_ptype,
14619                 (void *)&cmd_ptype_mapping_get_mapping,
14620                 (void *)&cmd_ptype_mapping_get_get,
14621                 (void *)&cmd_ptype_mapping_get_port_id,
14622                 (void *)&cmd_ptype_mapping_get_valid_only,
14623                 NULL,
14624         },
14625 };
14626
14627 /* ptype mapping replace */
14628
14629 /* Common result structure for ptype mapping replace */
14630 struct cmd_ptype_mapping_replace_result {
14631         cmdline_fixed_string_t ptype;
14632         cmdline_fixed_string_t mapping;
14633         cmdline_fixed_string_t replace;
14634         uint8_t port_id;
14635         uint32_t target;
14636         uint8_t mask;
14637         uint32_t pkt_type;
14638 };
14639
14640 /* Common CLI fields for ptype mapping replace */
14641 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14642         TOKEN_STRING_INITIALIZER
14643                 (struct cmd_ptype_mapping_replace_result,
14644                  ptype, "ptype");
14645 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14646         TOKEN_STRING_INITIALIZER
14647                 (struct cmd_ptype_mapping_replace_result,
14648                  mapping, "mapping");
14649 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14650         TOKEN_STRING_INITIALIZER
14651                 (struct cmd_ptype_mapping_replace_result,
14652                  replace, "replace");
14653 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14654         TOKEN_NUM_INITIALIZER
14655                 (struct cmd_ptype_mapping_replace_result,
14656                  port_id, UINT8);
14657 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14658         TOKEN_NUM_INITIALIZER
14659                 (struct cmd_ptype_mapping_replace_result,
14660                  target, UINT32);
14661 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14662         TOKEN_NUM_INITIALIZER
14663                 (struct cmd_ptype_mapping_replace_result,
14664                  mask, UINT8);
14665 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14666         TOKEN_NUM_INITIALIZER
14667                 (struct cmd_ptype_mapping_replace_result,
14668                  pkt_type, UINT32);
14669
14670 static void
14671 cmd_ptype_mapping_replace_parsed(
14672         void *parsed_result,
14673         __attribute__((unused)) struct cmdline *cl,
14674         __attribute__((unused)) void *data)
14675 {
14676         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14677         int ret = -ENOTSUP;
14678
14679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14680                 return;
14681
14682 #ifdef RTE_LIBRTE_I40E_PMD
14683         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14684                                         res->target,
14685                                         res->mask,
14686                                         res->pkt_type);
14687 #endif
14688
14689         switch (ret) {
14690         case 0:
14691                 break;
14692         case -EINVAL:
14693                 printf("invalid ptype 0x%8x or 0x%8x\n",
14694                                 res->target, res->pkt_type);
14695                 break;
14696         case -ENODEV:
14697                 printf("invalid port_id %d\n", res->port_id);
14698                 break;
14699         case -ENOTSUP:
14700                 printf("function not implemented\n");
14701                 break;
14702         default:
14703                 printf("programming error: (%s)\n", strerror(-ret));
14704         }
14705 }
14706
14707 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14708         .f = cmd_ptype_mapping_replace_parsed,
14709         .data = NULL,
14710         .help_str =
14711                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14712         .tokens = {
14713                 (void *)&cmd_ptype_mapping_replace_ptype,
14714                 (void *)&cmd_ptype_mapping_replace_mapping,
14715                 (void *)&cmd_ptype_mapping_replace_replace,
14716                 (void *)&cmd_ptype_mapping_replace_port_id,
14717                 (void *)&cmd_ptype_mapping_replace_target,
14718                 (void *)&cmd_ptype_mapping_replace_mask,
14719                 (void *)&cmd_ptype_mapping_replace_pkt_type,
14720                 NULL,
14721         },
14722 };
14723
14724 /* ptype mapping reset */
14725
14726 /* Common result structure for ptype mapping reset */
14727 struct cmd_ptype_mapping_reset_result {
14728         cmdline_fixed_string_t ptype;
14729         cmdline_fixed_string_t mapping;
14730         cmdline_fixed_string_t reset;
14731         uint8_t port_id;
14732 };
14733
14734 /* Common CLI fields for ptype mapping reset*/
14735 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14736         TOKEN_STRING_INITIALIZER
14737                 (struct cmd_ptype_mapping_reset_result,
14738                  ptype, "ptype");
14739 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14740         TOKEN_STRING_INITIALIZER
14741                 (struct cmd_ptype_mapping_reset_result,
14742                  mapping, "mapping");
14743 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14744         TOKEN_STRING_INITIALIZER
14745                 (struct cmd_ptype_mapping_reset_result,
14746                  reset, "reset");
14747 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14748         TOKEN_NUM_INITIALIZER
14749                 (struct cmd_ptype_mapping_reset_result,
14750                  port_id, UINT8);
14751
14752 static void
14753 cmd_ptype_mapping_reset_parsed(
14754         void *parsed_result,
14755         __attribute__((unused)) struct cmdline *cl,
14756         __attribute__((unused)) void *data)
14757 {
14758         struct cmd_ptype_mapping_reset_result *res = parsed_result;
14759         int ret = -ENOTSUP;
14760
14761         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14762                 return;
14763
14764 #ifdef RTE_LIBRTE_I40E_PMD
14765         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14766 #endif
14767
14768         switch (ret) {
14769         case 0:
14770                 break;
14771         case -ENODEV:
14772                 printf("invalid port_id %d\n", res->port_id);
14773                 break;
14774         case -ENOTSUP:
14775                 printf("function not implemented\n");
14776                 break;
14777         default:
14778                 printf("programming error: (%s)\n", strerror(-ret));
14779         }
14780 }
14781
14782 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14783         .f = cmd_ptype_mapping_reset_parsed,
14784         .data = NULL,
14785         .help_str = "ptype mapping reset <port_id>",
14786         .tokens = {
14787                 (void *)&cmd_ptype_mapping_reset_ptype,
14788                 (void *)&cmd_ptype_mapping_reset_mapping,
14789                 (void *)&cmd_ptype_mapping_reset_reset,
14790                 (void *)&cmd_ptype_mapping_reset_port_id,
14791                 NULL,
14792         },
14793 };
14794
14795 /* ptype mapping update */
14796
14797 /* Common result structure for ptype mapping update */
14798 struct cmd_ptype_mapping_update_result {
14799         cmdline_fixed_string_t ptype;
14800         cmdline_fixed_string_t mapping;
14801         cmdline_fixed_string_t reset;
14802         uint8_t port_id;
14803         uint8_t hw_ptype;
14804         uint32_t sw_ptype;
14805 };
14806
14807 /* Common CLI fields for ptype mapping update*/
14808 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14809         TOKEN_STRING_INITIALIZER
14810                 (struct cmd_ptype_mapping_update_result,
14811                  ptype, "ptype");
14812 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14813         TOKEN_STRING_INITIALIZER
14814                 (struct cmd_ptype_mapping_update_result,
14815                  mapping, "mapping");
14816 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14817         TOKEN_STRING_INITIALIZER
14818                 (struct cmd_ptype_mapping_update_result,
14819                  reset, "update");
14820 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14821         TOKEN_NUM_INITIALIZER
14822                 (struct cmd_ptype_mapping_update_result,
14823                  port_id, UINT8);
14824 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14825         TOKEN_NUM_INITIALIZER
14826                 (struct cmd_ptype_mapping_update_result,
14827                  hw_ptype, UINT8);
14828 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14829         TOKEN_NUM_INITIALIZER
14830                 (struct cmd_ptype_mapping_update_result,
14831                  sw_ptype, UINT32);
14832
14833 static void
14834 cmd_ptype_mapping_update_parsed(
14835         void *parsed_result,
14836         __attribute__((unused)) struct cmdline *cl,
14837         __attribute__((unused)) void *data)
14838 {
14839         struct cmd_ptype_mapping_update_result *res = parsed_result;
14840         int ret = -ENOTSUP;
14841 #ifdef RTE_LIBRTE_I40E_PMD
14842         struct rte_pmd_i40e_ptype_mapping mapping;
14843 #endif
14844         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14845                 return;
14846
14847 #ifdef RTE_LIBRTE_I40E_PMD
14848         mapping.hw_ptype = res->hw_ptype;
14849         mapping.sw_ptype = res->sw_ptype;
14850         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14851                                                 &mapping,
14852                                                 1,
14853                                                 0);
14854 #endif
14855
14856         switch (ret) {
14857         case 0:
14858                 break;
14859         case -EINVAL:
14860                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
14861                 break;
14862         case -ENODEV:
14863                 printf("invalid port_id %d\n", res->port_id);
14864                 break;
14865         case -ENOTSUP:
14866                 printf("function not implemented\n");
14867                 break;
14868         default:
14869                 printf("programming error: (%s)\n", strerror(-ret));
14870         }
14871 }
14872
14873 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14874         .f = cmd_ptype_mapping_update_parsed,
14875         .data = NULL,
14876         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14877         .tokens = {
14878                 (void *)&cmd_ptype_mapping_update_ptype,
14879                 (void *)&cmd_ptype_mapping_update_mapping,
14880                 (void *)&cmd_ptype_mapping_update_update,
14881                 (void *)&cmd_ptype_mapping_update_port_id,
14882                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14883                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14884                 NULL,
14885         },
14886 };
14887
14888 /* Common result structure for file commands */
14889 struct cmd_cmdfile_result {
14890         cmdline_fixed_string_t load;
14891         cmdline_fixed_string_t filename;
14892 };
14893
14894 /* Common CLI fields for file commands */
14895 cmdline_parse_token_string_t cmd_load_cmdfile =
14896         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14897 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14898         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14899
14900 static void
14901 cmd_load_from_file_parsed(
14902         void *parsed_result,
14903         __attribute__((unused)) struct cmdline *cl,
14904         __attribute__((unused)) void *data)
14905 {
14906         struct cmd_cmdfile_result *res = parsed_result;
14907
14908         cmdline_read_from_file(res->filename);
14909 }
14910
14911 cmdline_parse_inst_t cmd_load_from_file = {
14912         .f = cmd_load_from_file_parsed,
14913         .data = NULL,
14914         .help_str = "load <filename>",
14915         .tokens = {
14916                 (void *)&cmd_load_cmdfile,
14917                 (void *)&cmd_load_cmdfile_filename,
14918                 NULL,
14919         },
14920 };
14921
14922 /* ******************************************************************************** */
14923
14924 /* list of instructions */
14925 cmdline_parse_ctx_t main_ctx[] = {
14926         (cmdline_parse_inst_t *)&cmd_help_brief,
14927         (cmdline_parse_inst_t *)&cmd_help_long,
14928         (cmdline_parse_inst_t *)&cmd_quit,
14929         (cmdline_parse_inst_t *)&cmd_load_from_file,
14930         (cmdline_parse_inst_t *)&cmd_showport,
14931         (cmdline_parse_inst_t *)&cmd_showqueue,
14932         (cmdline_parse_inst_t *)&cmd_showportall,
14933         (cmdline_parse_inst_t *)&cmd_showcfg,
14934         (cmdline_parse_inst_t *)&cmd_start,
14935         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14936         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14937         (cmdline_parse_inst_t *)&cmd_set_link_up,
14938         (cmdline_parse_inst_t *)&cmd_set_link_down,
14939         (cmdline_parse_inst_t *)&cmd_reset,
14940         (cmdline_parse_inst_t *)&cmd_set_numbers,
14941         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14942         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14943         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14944         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14945         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14946         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14947         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14948         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14949         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14950         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14951         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14952         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14953         (cmdline_parse_inst_t *)&cmd_set_link_check,
14954         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14955         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14956         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14957         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14958 #ifdef RTE_LIBRTE_PMD_BOND
14959         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14960         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14961         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14962         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14963         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14964         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14965         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14966         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14967         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14968         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14969         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14970 #endif
14971         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14972         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14973         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14974         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14975         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14976         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14977         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14978         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14979         (cmdline_parse_inst_t *)&cmd_csum_set,
14980         (cmdline_parse_inst_t *)&cmd_csum_show,
14981         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14982         (cmdline_parse_inst_t *)&cmd_tso_set,
14983         (cmdline_parse_inst_t *)&cmd_tso_show,
14984         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14985         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14986         (cmdline_parse_inst_t *)&cmd_gro_enable,
14987         (cmdline_parse_inst_t *)&cmd_gro_flush,
14988         (cmdline_parse_inst_t *)&cmd_gro_show,
14989         (cmdline_parse_inst_t *)&cmd_gso_enable,
14990         (cmdline_parse_inst_t *)&cmd_gso_size,
14991         (cmdline_parse_inst_t *)&cmd_gso_show,
14992         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14993         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14994         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14995         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14996         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14997         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14998         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14999         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15000         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15001         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15002         (cmdline_parse_inst_t *)&cmd_config_dcb,
15003         (cmdline_parse_inst_t *)&cmd_read_reg,
15004         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15005         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15006         (cmdline_parse_inst_t *)&cmd_write_reg,
15007         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15008         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15009         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15010         (cmdline_parse_inst_t *)&cmd_stop,
15011         (cmdline_parse_inst_t *)&cmd_mac_addr,
15012         (cmdline_parse_inst_t *)&cmd_set_qmap,
15013         (cmdline_parse_inst_t *)&cmd_operate_port,
15014         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15015         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15016         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15017         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15018         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15019         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15020         (cmdline_parse_inst_t *)&cmd_config_mtu,
15021         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15022         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15023         (cmdline_parse_inst_t *)&cmd_config_rss,
15024         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15025         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15026         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15027         (cmdline_parse_inst_t *)&cmd_showport_reta,
15028         (cmdline_parse_inst_t *)&cmd_config_burst,
15029         (cmdline_parse_inst_t *)&cmd_config_thresh,
15030         (cmdline_parse_inst_t *)&cmd_config_threshold,
15031         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15032         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15033         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15034         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15035         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15036         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15037         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15038         (cmdline_parse_inst_t *)&cmd_global_config,
15039         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15040         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15041         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15042         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15043         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15044         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15045         (cmdline_parse_inst_t *)&cmd_dump,
15046         (cmdline_parse_inst_t *)&cmd_dump_one,
15047         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15048         (cmdline_parse_inst_t *)&cmd_syn_filter,
15049         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15050         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15051         (cmdline_parse_inst_t *)&cmd_flex_filter,
15052         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15053         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15054         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15055         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15056         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15057         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15058         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15059         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15060         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15061         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15062         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15063         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15064         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15065         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15066         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15067         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15068         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15069         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15070         (cmdline_parse_inst_t *)&cmd_flow,
15071         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15072         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15073         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15074         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15075         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15076         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15077         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15078         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15079         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15080         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15081         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15082         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15083         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15084         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15085         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15086         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15087         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15088         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15089         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15090         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15091         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15092         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15093         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15094         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15095         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15096         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15097         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15098         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15099         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15100         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15101         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15102         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15103         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15104         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15105         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15106         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15107 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15108         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15109 #endif
15110         (cmdline_parse_inst_t *)&cmd_ddp_add,
15111         (cmdline_parse_inst_t *)&cmd_ddp_del,
15112         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15113         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15114         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15115         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15116         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15117         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15118         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15119         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15120
15121         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15122         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15123         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15124         NULL,
15125 };
15126
15127 /* read cmdline commands from file */
15128 void
15129 cmdline_read_from_file(const char *filename)
15130 {
15131         struct cmdline *cl;
15132
15133         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15134         if (cl == NULL) {
15135                 printf("Failed to create file based cmdline context: %s\n",
15136                        filename);
15137                 return;
15138         }
15139
15140         cmdline_interact(cl);
15141         cmdline_quit(cl);
15142
15143         cmdline_free(cl);
15144
15145         printf("Read CLI commands from %s\n", filename);
15146 }
15147
15148 /* prompt function, called from main on MASTER lcore */
15149 void
15150 prompt(void)
15151 {
15152         /* initialize non-constant commands */
15153         cmd_set_fwd_mode_init();
15154         cmd_set_fwd_retry_mode_init();
15155
15156         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15157         if (testpmd_cl == NULL)
15158                 return;
15159         cmdline_interact(testpmd_cl);
15160         cmdline_stdin_exit(testpmd_cl);
15161 }
15162
15163 void
15164 prompt_exit(void)
15165 {
15166         if (testpmd_cl != NULL)
15167                 cmdline_quit(testpmd_cl);
15168 }
15169
15170 static void
15171 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15172 {
15173         if (id == (portid_t)RTE_PORT_ALL) {
15174                 portid_t pid;
15175
15176                 RTE_ETH_FOREACH_DEV(pid) {
15177                         /* check if need_reconfig has been set to 1 */
15178                         if (ports[pid].need_reconfig == 0)
15179                                 ports[pid].need_reconfig = dev;
15180                         /* check if need_reconfig_queues has been set to 1 */
15181                         if (ports[pid].need_reconfig_queues == 0)
15182                                 ports[pid].need_reconfig_queues = queue;
15183                 }
15184         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15185                 /* check if need_reconfig has been set to 1 */
15186                 if (ports[id].need_reconfig == 0)
15187                         ports[id].need_reconfig = dev;
15188                 /* check if need_reconfig_queues has been set to 1 */
15189                 if (ports[id].need_reconfig_queues == 0)
15190                         ports[id].need_reconfig_queues = queue;
15191         }
15192 }