app: fix port id type
[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                         "set port (port_id) queue-region region_id (value) "
664                         "queue_start_index (value) queue_num (value)\n"
665                         "    Set a queue region on a port\n\n"
666
667                         "set port (port_id) queue-region region_id (value) "
668                         "flowtype (value)\n"
669                         "    Set a flowtype region index on a port\n\n"
670
671                         "set port (port_id) queue-region UP (value) region_id (value)\n"
672                         "    Set the mapping of User Priority to "
673                         "queue region on a port\n\n"
674
675                         "set port (port_id) queue-region flush (on|off)\n"
676                         "    flush all queue region related configuration\n\n"
677
678                         "show port (port_id) queue-region\n"
679                         "    show all queue region related configuration info\n\n"
680
681                         , list_pkt_forwarding_modes()
682                 );
683         }
684
685         if (show_all || !strcmp(res->section, "ports")) {
686
687                 cmdline_printf(
688                         cl,
689                         "\n"
690                         "Port Operations:\n"
691                         "----------------\n\n"
692
693                         "port start (port_id|all)\n"
694                         "    Start all ports or port_id.\n\n"
695
696                         "port stop (port_id|all)\n"
697                         "    Stop all ports or port_id.\n\n"
698
699                         "port close (port_id|all)\n"
700                         "    Close all ports or port_id.\n\n"
701
702                         "port attach (ident)\n"
703                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
704
705                         "port detach (port_id)\n"
706                         "    Detach physical or virtual dev by port_id\n\n"
707
708                         "port config (port_id|all)"
709                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
710                         " duplex (half|full|auto)\n"
711                         "    Set speed and duplex for all ports or port_id\n\n"
712
713                         "port config all (rxq|txq|rxd|txd) (value)\n"
714                         "    Set number for rxq/txq/rxd/txd.\n\n"
715
716                         "port config all max-pkt-len (value)\n"
717                         "    Set the max packet length.\n\n"
718
719                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
720                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
721                         " (on|off)\n"
722                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
723                         " for ports.\n\n"
724
725                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
726                         "geneve|nvgre|none|<flowtype_id>)\n"
727                         "    Set the RSS mode.\n\n"
728
729                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
730                         "    Set the RSS redirection table.\n\n"
731
732                         "port config (port_id) dcb vt (on|off) (traffic_class)"
733                         " pfc (on|off)\n"
734                         "    Set the DCB mode.\n\n"
735
736                         "port config all burst (value)\n"
737                         "    Set the number of packets per burst.\n\n"
738
739                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
740                         " (value)\n"
741                         "    Set the ring prefetch/host/writeback threshold"
742                         " for tx/rx queue.\n\n"
743
744                         "port config all (txfreet|txrst|rxfreet) (value)\n"
745                         "    Set free threshold for rx/tx, or set"
746                         " tx rs bit threshold.\n\n"
747                         "port config mtu X value\n"
748                         "    Set the MTU of port X to a given value\n\n"
749
750                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
751                         "    Start/stop a rx/tx queue of port X. Only take effect"
752                         " when port X is started\n\n"
753
754                         "port config (port_id|all) l2-tunnel E-tag ether-type"
755                         " (value)\n"
756                         "    Set the value of E-tag ether-type.\n\n"
757
758                         "port config (port_id|all) l2-tunnel E-tag"
759                         " (enable|disable)\n"
760                         "    Enable/disable the E-tag support.\n\n"
761
762                         "port config (port_id) pctype mapping reset\n"
763                         "    Reset flow type to pctype mapping on a port\n\n"
764
765                         "port config (port_id) pctype mapping update"
766                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
767                         "    Update a flow type to pctype mapping item on a port\n\n"
768                 );
769         }
770
771         if (show_all || !strcmp(res->section, "registers")) {
772
773                 cmdline_printf(
774                         cl,
775                         "\n"
776                         "Registers:\n"
777                         "----------\n\n"
778
779                         "read reg (port_id) (address)\n"
780                         "    Display value of a port register.\n\n"
781
782                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
783                         "    Display a port register bit field.\n\n"
784
785                         "read regbit (port_id) (address) (bit_x)\n"
786                         "    Display a single port register bit.\n\n"
787
788                         "write reg (port_id) (address) (value)\n"
789                         "    Set value of a port register.\n\n"
790
791                         "write regfield (port_id) (address) (bit_x) (bit_y)"
792                         " (value)\n"
793                         "    Set bit field of a port register.\n\n"
794
795                         "write regbit (port_id) (address) (bit_x) (value)\n"
796                         "    Set single bit value of a port register.\n\n"
797                 );
798         }
799         if (show_all || !strcmp(res->section, "filters")) {
800
801                 cmdline_printf(
802                         cl,
803                         "\n"
804                         "filters:\n"
805                         "--------\n\n"
806
807                         "ethertype_filter (port_id) (add|del)"
808                         " (mac_addr|mac_ignr) (mac_address) ethertype"
809                         " (ether_type) (drop|fwd) queue (queue_id)\n"
810                         "    Add/Del an ethertype filter.\n\n"
811
812                         "2tuple_filter (port_id) (add|del)"
813                         " dst_port (dst_port_value) protocol (protocol_value)"
814                         " mask (mask_value) tcp_flags (tcp_flags_value)"
815                         " priority (prio_value) queue (queue_id)\n"
816                         "    Add/Del a 2tuple filter.\n\n"
817
818                         "5tuple_filter (port_id) (add|del)"
819                         " dst_ip (dst_address) src_ip (src_address)"
820                         " dst_port (dst_port_value) src_port (src_port_value)"
821                         " protocol (protocol_value)"
822                         " mask (mask_value) tcp_flags (tcp_flags_value)"
823                         " priority (prio_value) queue (queue_id)\n"
824                         "    Add/Del a 5tuple filter.\n\n"
825
826                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
827                         "    Add/Del syn filter.\n\n"
828
829                         "flex_filter (port_id) (add|del) len (len_value)"
830                         " bytes (bytes_value) mask (mask_value)"
831                         " priority (prio_value) queue (queue_id)\n"
832                         "    Add/Del a flex filter.\n\n"
833
834                         "flow_director_filter (port_id) mode IP (add|del|update)"
835                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
836                         " src (src_ip_address) dst (dst_ip_address)"
837                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
838                         " vlan (vlan_value) flexbytes (flexbytes_value)"
839                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
840                         " fd_id (fd_id_value)\n"
841                         "    Add/Del an IP type flow director filter.\n\n"
842
843                         "flow_director_filter (port_id) mode IP (add|del|update)"
844                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
845                         " src (src_ip_address) (src_port)"
846                         " dst (dst_ip_address) (dst_port)"
847                         " tos (tos_value) ttl (ttl_value)"
848                         " vlan (vlan_value) flexbytes (flexbytes_value)"
849                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
850                         " fd_id (fd_id_value)\n"
851                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
852
853                         "flow_director_filter (port_id) mode IP (add|del|update)"
854                         " flow (ipv4-sctp|ipv6-sctp)"
855                         " src (src_ip_address) (src_port)"
856                         " dst (dst_ip_address) (dst_port)"
857                         " tag (verification_tag) "
858                         " tos (tos_value) ttl (ttl_value)"
859                         " vlan (vlan_value)"
860                         " flexbytes (flexbytes_value) (drop|fwd)"
861                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
862                         "    Add/Del a SCTP type flow director filter.\n\n"
863
864                         "flow_director_filter (port_id) mode IP (add|del|update)"
865                         " flow l2_payload ether (ethertype)"
866                         " flexbytes (flexbytes_value) (drop|fwd)"
867                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
868                         "    Add/Del a l2 payload type flow director filter.\n\n"
869
870                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
871                         " mac (mac_address) vlan (vlan_value)"
872                         " flexbytes (flexbytes_value) (drop|fwd)"
873                         " queue (queue_id) fd_id (fd_id_value)\n"
874                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
875
876                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
877                         " mac (mac_address) vlan (vlan_value)"
878                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
879                         " flexbytes (flexbytes_value) (drop|fwd)"
880                         " queue (queue_id) fd_id (fd_id_value)\n"
881                         "    Add/Del a Tunnel flow director filter.\n\n"
882
883                         "flush_flow_director (port_id)\n"
884                         "    Flush all flow director entries of a device.\n\n"
885
886                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
887                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
888                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
889                         "    Set flow director IP mask.\n\n"
890
891                         "flow_director_mask (port_id) mode MAC-VLAN"
892                         " vlan (vlan_value)\n"
893                         "    Set flow director MAC-VLAN mask.\n\n"
894
895                         "flow_director_mask (port_id) mode Tunnel"
896                         " vlan (vlan_value) mac (mac_value)"
897                         " tunnel-type (tunnel_type_value)"
898                         " tunnel-id (tunnel_id_value)\n"
899                         "    Set flow director Tunnel mask.\n\n"
900
901                         "flow_director_flex_mask (port_id)"
902                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
903                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
904                         " (mask)\n"
905                         "    Configure mask of flex payload.\n\n"
906
907                         "flow_director_flex_payload (port_id)"
908                         " (raw|l2|l3|l4) (config)\n"
909                         "    Configure flex payload selection.\n\n"
910
911                         "get_sym_hash_ena_per_port (port_id)\n"
912                         "    get symmetric hash enable configuration per port.\n\n"
913
914                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
915                         "    set symmetric hash enable configuration per port"
916                         " to enable or disable.\n\n"
917
918                         "get_hash_global_config (port_id)\n"
919                         "    Get the global configurations of hash filters.\n\n"
920
921                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
922                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
923                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
924                         " (enable|disable)\n"
925                         "    Set the global configurations of hash filters.\n\n"
926
927                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
928                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
929                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
930                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
931                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
932                         "ipv6-next-header|udp-src-port|udp-dst-port|"
933                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
934                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
935                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
936                         "fld-8th|none) (select|add)\n"
937                         "    Set the input set for hash.\n\n"
938
939                         "set_fdir_input_set (port_id) "
940                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
941                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
942                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
943                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
944                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
945                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
946                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
947                         " (select|add)\n"
948                         "    Set the input set for FDir.\n\n"
949
950                         "flow validate {port_id}"
951                         " [group {group_id}] [priority {level}]"
952                         " [ingress] [egress]"
953                         " pattern {item} [/ {item} [...]] / end"
954                         " actions {action} [/ {action} [...]] / end\n"
955                         "    Check whether a flow rule can be created.\n\n"
956
957                         "flow create {port_id}"
958                         " [group {group_id}] [priority {level}]"
959                         " [ingress] [egress]"
960                         " pattern {item} [/ {item} [...]] / end"
961                         " actions {action} [/ {action} [...]] / end\n"
962                         "    Create a flow rule.\n\n"
963
964                         "flow destroy {port_id} rule {rule_id} [...]\n"
965                         "    Destroy specific flow rules.\n\n"
966
967                         "flow flush {port_id}\n"
968                         "    Destroy all flow rules.\n\n"
969
970                         "flow query {port_id} {rule_id} {action}\n"
971                         "    Query an existing flow rule.\n\n"
972
973                         "flow list {port_id} [group {group_id}] [...]\n"
974                         "    List existing flow rules sorted by priority,"
975                         " filtered by group identifiers.\n\n"
976
977                         "flow isolate {port_id} {boolean}\n"
978                         "    Restrict ingress traffic to the defined"
979                         " flow rules\n\n"
980                 );
981         }
982 }
983
984 cmdline_parse_token_string_t cmd_help_long_help =
985         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
986
987 cmdline_parse_token_string_t cmd_help_long_section =
988         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
989                         "all#control#display#config#"
990                         "ports#registers#filters");
991
992 cmdline_parse_inst_t cmd_help_long = {
993         .f = cmd_help_long_parsed,
994         .data = NULL,
995         .help_str = "help all|control|display|config|ports|register|filters: "
996                 "Show help",
997         .tokens = {
998                 (void *)&cmd_help_long_help,
999                 (void *)&cmd_help_long_section,
1000                 NULL,
1001         },
1002 };
1003
1004
1005 /* *** start/stop/close all ports *** */
1006 struct cmd_operate_port_result {
1007         cmdline_fixed_string_t keyword;
1008         cmdline_fixed_string_t name;
1009         cmdline_fixed_string_t value;
1010 };
1011
1012 static void cmd_operate_port_parsed(void *parsed_result,
1013                                 __attribute__((unused)) struct cmdline *cl,
1014                                 __attribute__((unused)) void *data)
1015 {
1016         struct cmd_operate_port_result *res = parsed_result;
1017
1018         if (!strcmp(res->name, "start"))
1019                 start_port(RTE_PORT_ALL);
1020         else if (!strcmp(res->name, "stop"))
1021                 stop_port(RTE_PORT_ALL);
1022         else if (!strcmp(res->name, "close"))
1023                 close_port(RTE_PORT_ALL);
1024         else if (!strcmp(res->name, "reset"))
1025                 reset_port(RTE_PORT_ALL);
1026         else
1027                 printf("Unknown parameter\n");
1028 }
1029
1030 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1031         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1032                                                                 "port");
1033 cmdline_parse_token_string_t cmd_operate_port_all_port =
1034         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1035                                                 "start#stop#close#reset");
1036 cmdline_parse_token_string_t cmd_operate_port_all_all =
1037         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1038
1039 cmdline_parse_inst_t cmd_operate_port = {
1040         .f = cmd_operate_port_parsed,
1041         .data = NULL,
1042         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1043         .tokens = {
1044                 (void *)&cmd_operate_port_all_cmd,
1045                 (void *)&cmd_operate_port_all_port,
1046                 (void *)&cmd_operate_port_all_all,
1047                 NULL,
1048         },
1049 };
1050
1051 /* *** start/stop/close specific port *** */
1052 struct cmd_operate_specific_port_result {
1053         cmdline_fixed_string_t keyword;
1054         cmdline_fixed_string_t name;
1055         uint8_t value;
1056 };
1057
1058 static void cmd_operate_specific_port_parsed(void *parsed_result,
1059                         __attribute__((unused)) struct cmdline *cl,
1060                                 __attribute__((unused)) void *data)
1061 {
1062         struct cmd_operate_specific_port_result *res = parsed_result;
1063
1064         if (!strcmp(res->name, "start"))
1065                 start_port(res->value);
1066         else if (!strcmp(res->name, "stop"))
1067                 stop_port(res->value);
1068         else if (!strcmp(res->name, "close"))
1069                 close_port(res->value);
1070         else if (!strcmp(res->name, "reset"))
1071                 reset_port(res->value);
1072         else
1073                 printf("Unknown parameter\n");
1074 }
1075
1076 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1077         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1078                                                         keyword, "port");
1079 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1080         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1081                                                 name, "start#stop#close#reset");
1082 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1083         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1084                                                         value, UINT8);
1085
1086 cmdline_parse_inst_t cmd_operate_specific_port = {
1087         .f = cmd_operate_specific_port_parsed,
1088         .data = NULL,
1089         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1090         .tokens = {
1091                 (void *)&cmd_operate_specific_port_cmd,
1092                 (void *)&cmd_operate_specific_port_port,
1093                 (void *)&cmd_operate_specific_port_id,
1094                 NULL,
1095         },
1096 };
1097
1098 /* *** attach a specified port *** */
1099 struct cmd_operate_attach_port_result {
1100         cmdline_fixed_string_t port;
1101         cmdline_fixed_string_t keyword;
1102         cmdline_fixed_string_t identifier;
1103 };
1104
1105 static void cmd_operate_attach_port_parsed(void *parsed_result,
1106                                 __attribute__((unused)) struct cmdline *cl,
1107                                 __attribute__((unused)) void *data)
1108 {
1109         struct cmd_operate_attach_port_result *res = parsed_result;
1110
1111         if (!strcmp(res->keyword, "attach"))
1112                 attach_port(res->identifier);
1113         else
1114                 printf("Unknown parameter\n");
1115 }
1116
1117 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1118         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1119                         port, "port");
1120 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1121         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1122                         keyword, "attach");
1123 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1124         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1125                         identifier, NULL);
1126
1127 cmdline_parse_inst_t cmd_operate_attach_port = {
1128         .f = cmd_operate_attach_port_parsed,
1129         .data = NULL,
1130         .help_str = "port attach <identifier>: "
1131                 "(identifier: pci address or virtual dev name)",
1132         .tokens = {
1133                 (void *)&cmd_operate_attach_port_port,
1134                 (void *)&cmd_operate_attach_port_keyword,
1135                 (void *)&cmd_operate_attach_port_identifier,
1136                 NULL,
1137         },
1138 };
1139
1140 /* *** detach a specified port *** */
1141 struct cmd_operate_detach_port_result {
1142         cmdline_fixed_string_t port;
1143         cmdline_fixed_string_t keyword;
1144         portid_t port_id;
1145 };
1146
1147 static void cmd_operate_detach_port_parsed(void *parsed_result,
1148                                 __attribute__((unused)) struct cmdline *cl,
1149                                 __attribute__((unused)) void *data)
1150 {
1151         struct cmd_operate_detach_port_result *res = parsed_result;
1152
1153         if (!strcmp(res->keyword, "detach"))
1154                 detach_port(res->port_id);
1155         else
1156                 printf("Unknown parameter\n");
1157 }
1158
1159 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1160         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1161                         port, "port");
1162 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1163         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1164                         keyword, "detach");
1165 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1166         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1167                         port_id, UINT16);
1168
1169 cmdline_parse_inst_t cmd_operate_detach_port = {
1170         .f = cmd_operate_detach_port_parsed,
1171         .data = NULL,
1172         .help_str = "port detach <port_id>",
1173         .tokens = {
1174                 (void *)&cmd_operate_detach_port_port,
1175                 (void *)&cmd_operate_detach_port_keyword,
1176                 (void *)&cmd_operate_detach_port_port_id,
1177                 NULL,
1178         },
1179 };
1180
1181 /* *** configure speed for all ports *** */
1182 struct cmd_config_speed_all {
1183         cmdline_fixed_string_t port;
1184         cmdline_fixed_string_t keyword;
1185         cmdline_fixed_string_t all;
1186         cmdline_fixed_string_t item1;
1187         cmdline_fixed_string_t item2;
1188         cmdline_fixed_string_t value1;
1189         cmdline_fixed_string_t value2;
1190 };
1191
1192 static int
1193 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1194 {
1195
1196         int duplex;
1197
1198         if (!strcmp(duplexstr, "half")) {
1199                 duplex = ETH_LINK_HALF_DUPLEX;
1200         } else if (!strcmp(duplexstr, "full")) {
1201                 duplex = ETH_LINK_FULL_DUPLEX;
1202         } else if (!strcmp(duplexstr, "auto")) {
1203                 duplex = ETH_LINK_FULL_DUPLEX;
1204         } else {
1205                 printf("Unknown duplex parameter\n");
1206                 return -1;
1207         }
1208
1209         if (!strcmp(speedstr, "10")) {
1210                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1211                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1212         } else if (!strcmp(speedstr, "100")) {
1213                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1214                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1215         } else {
1216                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1217                         printf("Invalid speed/duplex parameters\n");
1218                         return -1;
1219                 }
1220                 if (!strcmp(speedstr, "1000")) {
1221                         *speed = ETH_LINK_SPEED_1G;
1222                 } else if (!strcmp(speedstr, "10000")) {
1223                         *speed = ETH_LINK_SPEED_10G;
1224                 } else if (!strcmp(speedstr, "25000")) {
1225                         *speed = ETH_LINK_SPEED_25G;
1226                 } else if (!strcmp(speedstr, "40000")) {
1227                         *speed = ETH_LINK_SPEED_40G;
1228                 } else if (!strcmp(speedstr, "50000")) {
1229                         *speed = ETH_LINK_SPEED_50G;
1230                 } else if (!strcmp(speedstr, "100000")) {
1231                         *speed = ETH_LINK_SPEED_100G;
1232                 } else if (!strcmp(speedstr, "auto")) {
1233                         *speed = ETH_LINK_SPEED_AUTONEG;
1234                 } else {
1235                         printf("Unknown speed parameter\n");
1236                         return -1;
1237                 }
1238         }
1239
1240         return 0;
1241 }
1242
1243 static void
1244 cmd_config_speed_all_parsed(void *parsed_result,
1245                         __attribute__((unused)) struct cmdline *cl,
1246                         __attribute__((unused)) void *data)
1247 {
1248         struct cmd_config_speed_all *res = parsed_result;
1249         uint32_t link_speed;
1250         portid_t pid;
1251
1252         if (!all_ports_stopped()) {
1253                 printf("Please stop all ports first\n");
1254                 return;
1255         }
1256
1257         if (parse_and_check_speed_duplex(res->value1, res->value2,
1258                         &link_speed) < 0)
1259                 return;
1260
1261         RTE_ETH_FOREACH_DEV(pid) {
1262                 ports[pid].dev_conf.link_speeds = link_speed;
1263         }
1264
1265         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1266 }
1267
1268 cmdline_parse_token_string_t cmd_config_speed_all_port =
1269         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1270 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1271         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1272                                                         "config");
1273 cmdline_parse_token_string_t cmd_config_speed_all_all =
1274         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1275 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1276         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1277 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1278         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1279                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1280 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1281         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1282 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1283         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1284                                                 "half#full#auto");
1285
1286 cmdline_parse_inst_t cmd_config_speed_all = {
1287         .f = cmd_config_speed_all_parsed,
1288         .data = NULL,
1289         .help_str = "port config all speed "
1290                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1291                                                         "half|full|auto",
1292         .tokens = {
1293                 (void *)&cmd_config_speed_all_port,
1294                 (void *)&cmd_config_speed_all_keyword,
1295                 (void *)&cmd_config_speed_all_all,
1296                 (void *)&cmd_config_speed_all_item1,
1297                 (void *)&cmd_config_speed_all_value1,
1298                 (void *)&cmd_config_speed_all_item2,
1299                 (void *)&cmd_config_speed_all_value2,
1300                 NULL,
1301         },
1302 };
1303
1304 /* *** configure speed for specific port *** */
1305 struct cmd_config_speed_specific {
1306         cmdline_fixed_string_t port;
1307         cmdline_fixed_string_t keyword;
1308         uint8_t id;
1309         cmdline_fixed_string_t item1;
1310         cmdline_fixed_string_t item2;
1311         cmdline_fixed_string_t value1;
1312         cmdline_fixed_string_t value2;
1313 };
1314
1315 static void
1316 cmd_config_speed_specific_parsed(void *parsed_result,
1317                                 __attribute__((unused)) struct cmdline *cl,
1318                                 __attribute__((unused)) void *data)
1319 {
1320         struct cmd_config_speed_specific *res = parsed_result;
1321         uint32_t link_speed;
1322
1323         if (!all_ports_stopped()) {
1324                 printf("Please stop all ports first\n");
1325                 return;
1326         }
1327
1328         if (port_id_is_invalid(res->id, ENABLED_WARN))
1329                 return;
1330
1331         if (parse_and_check_speed_duplex(res->value1, res->value2,
1332                         &link_speed) < 0)
1333                 return;
1334
1335         ports[res->id].dev_conf.link_speeds = link_speed;
1336
1337         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1338 }
1339
1340
1341 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1342         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1343                                                                 "port");
1344 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1345         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1346                                                                 "config");
1347 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1348         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1349 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1350         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1351                                                                 "speed");
1352 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1353         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1354                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1355 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1356         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1357                                                                 "duplex");
1358 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1359         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1360                                                         "half#full#auto");
1361
1362 cmdline_parse_inst_t cmd_config_speed_specific = {
1363         .f = cmd_config_speed_specific_parsed,
1364         .data = NULL,
1365         .help_str = "port config <port_id> speed "
1366                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1367                                                         "half|full|auto",
1368         .tokens = {
1369                 (void *)&cmd_config_speed_specific_port,
1370                 (void *)&cmd_config_speed_specific_keyword,
1371                 (void *)&cmd_config_speed_specific_id,
1372                 (void *)&cmd_config_speed_specific_item1,
1373                 (void *)&cmd_config_speed_specific_value1,
1374                 (void *)&cmd_config_speed_specific_item2,
1375                 (void *)&cmd_config_speed_specific_value2,
1376                 NULL,
1377         },
1378 };
1379
1380 /* *** configure txq/rxq, txd/rxd *** */
1381 struct cmd_config_rx_tx {
1382         cmdline_fixed_string_t port;
1383         cmdline_fixed_string_t keyword;
1384         cmdline_fixed_string_t all;
1385         cmdline_fixed_string_t name;
1386         uint16_t value;
1387 };
1388
1389 static void
1390 cmd_config_rx_tx_parsed(void *parsed_result,
1391                         __attribute__((unused)) struct cmdline *cl,
1392                         __attribute__((unused)) void *data)
1393 {
1394         struct cmd_config_rx_tx *res = parsed_result;
1395
1396         if (!all_ports_stopped()) {
1397                 printf("Please stop all ports first\n");
1398                 return;
1399         }
1400         if (!strcmp(res->name, "rxq")) {
1401                 if (!res->value && !nb_txq) {
1402                         printf("Warning: Either rx or tx queues should be non zero\n");
1403                         return;
1404                 }
1405                 nb_rxq = res->value;
1406         }
1407         else if (!strcmp(res->name, "txq")) {
1408                 if (!res->value && !nb_rxq) {
1409                         printf("Warning: Either rx or tx queues should be non zero\n");
1410                         return;
1411                 }
1412                 nb_txq = res->value;
1413         }
1414         else if (!strcmp(res->name, "rxd")) {
1415                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1416                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1417                                         res->value, RTE_TEST_RX_DESC_MAX);
1418                         return;
1419                 }
1420                 nb_rxd = res->value;
1421         } else if (!strcmp(res->name, "txd")) {
1422                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1423                         printf("txd %d invalid - must be > 0 && <= %d\n",
1424                                         res->value, RTE_TEST_TX_DESC_MAX);
1425                         return;
1426                 }
1427                 nb_txd = res->value;
1428         } else {
1429                 printf("Unknown parameter\n");
1430                 return;
1431         }
1432
1433         fwd_config_setup();
1434
1435         init_port_config();
1436
1437         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1438 }
1439
1440 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1441         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1442 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1443         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1444 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1445         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1446 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1447         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1448                                                 "rxq#txq#rxd#txd");
1449 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1450         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1451
1452 cmdline_parse_inst_t cmd_config_rx_tx = {
1453         .f = cmd_config_rx_tx_parsed,
1454         .data = NULL,
1455         .help_str = "port config all rxq|txq|rxd|txd <value>",
1456         .tokens = {
1457                 (void *)&cmd_config_rx_tx_port,
1458                 (void *)&cmd_config_rx_tx_keyword,
1459                 (void *)&cmd_config_rx_tx_all,
1460                 (void *)&cmd_config_rx_tx_name,
1461                 (void *)&cmd_config_rx_tx_value,
1462                 NULL,
1463         },
1464 };
1465
1466 /* *** config max packet length *** */
1467 struct cmd_config_max_pkt_len_result {
1468         cmdline_fixed_string_t port;
1469         cmdline_fixed_string_t keyword;
1470         cmdline_fixed_string_t all;
1471         cmdline_fixed_string_t name;
1472         uint32_t value;
1473 };
1474
1475 static void
1476 cmd_config_max_pkt_len_parsed(void *parsed_result,
1477                                 __attribute__((unused)) struct cmdline *cl,
1478                                 __attribute__((unused)) void *data)
1479 {
1480         struct cmd_config_max_pkt_len_result *res = parsed_result;
1481
1482         if (!all_ports_stopped()) {
1483                 printf("Please stop all ports first\n");
1484                 return;
1485         }
1486
1487         if (!strcmp(res->name, "max-pkt-len")) {
1488                 if (res->value < ETHER_MIN_LEN) {
1489                         printf("max-pkt-len can not be less than %d\n",
1490                                                         ETHER_MIN_LEN);
1491                         return;
1492                 }
1493                 if (res->value == rx_mode.max_rx_pkt_len)
1494                         return;
1495
1496                 rx_mode.max_rx_pkt_len = res->value;
1497                 if (res->value > ETHER_MAX_LEN)
1498                         rx_mode.jumbo_frame = 1;
1499                 else
1500                         rx_mode.jumbo_frame = 0;
1501         } else {
1502                 printf("Unknown parameter\n");
1503                 return;
1504         }
1505
1506         init_port_config();
1507
1508         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1509 }
1510
1511 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1512         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1513                                                                 "port");
1514 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1515         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1516                                                                 "config");
1517 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1518         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1519                                                                 "all");
1520 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1521         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1522                                                                 "max-pkt-len");
1523 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1524         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1525                                                                 UINT32);
1526
1527 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1528         .f = cmd_config_max_pkt_len_parsed,
1529         .data = NULL,
1530         .help_str = "port config all max-pkt-len <value>",
1531         .tokens = {
1532                 (void *)&cmd_config_max_pkt_len_port,
1533                 (void *)&cmd_config_max_pkt_len_keyword,
1534                 (void *)&cmd_config_max_pkt_len_all,
1535                 (void *)&cmd_config_max_pkt_len_name,
1536                 (void *)&cmd_config_max_pkt_len_value,
1537                 NULL,
1538         },
1539 };
1540
1541 /* *** configure port MTU *** */
1542 struct cmd_config_mtu_result {
1543         cmdline_fixed_string_t port;
1544         cmdline_fixed_string_t keyword;
1545         cmdline_fixed_string_t mtu;
1546         portid_t port_id;
1547         uint16_t value;
1548 };
1549
1550 static void
1551 cmd_config_mtu_parsed(void *parsed_result,
1552                       __attribute__((unused)) struct cmdline *cl,
1553                       __attribute__((unused)) void *data)
1554 {
1555         struct cmd_config_mtu_result *res = parsed_result;
1556
1557         if (res->value < ETHER_MIN_LEN) {
1558                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1559                 return;
1560         }
1561         port_mtu_set(res->port_id, res->value);
1562 }
1563
1564 cmdline_parse_token_string_t cmd_config_mtu_port =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1566                                  "port");
1567 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1569                                  "config");
1570 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1572                                  "mtu");
1573 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1574         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1575 cmdline_parse_token_num_t cmd_config_mtu_value =
1576         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1577
1578 cmdline_parse_inst_t cmd_config_mtu = {
1579         .f = cmd_config_mtu_parsed,
1580         .data = NULL,
1581         .help_str = "port config mtu <port_id> <value>",
1582         .tokens = {
1583                 (void *)&cmd_config_mtu_port,
1584                 (void *)&cmd_config_mtu_keyword,
1585                 (void *)&cmd_config_mtu_mtu,
1586                 (void *)&cmd_config_mtu_port_id,
1587                 (void *)&cmd_config_mtu_value,
1588                 NULL,
1589         },
1590 };
1591
1592 /* *** configure rx mode *** */
1593 struct cmd_config_rx_mode_flag {
1594         cmdline_fixed_string_t port;
1595         cmdline_fixed_string_t keyword;
1596         cmdline_fixed_string_t all;
1597         cmdline_fixed_string_t name;
1598         cmdline_fixed_string_t value;
1599 };
1600
1601 static void
1602 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1603                                 __attribute__((unused)) struct cmdline *cl,
1604                                 __attribute__((unused)) void *data)
1605 {
1606         struct cmd_config_rx_mode_flag *res = parsed_result;
1607
1608         if (!all_ports_stopped()) {
1609                 printf("Please stop all ports first\n");
1610                 return;
1611         }
1612
1613         if (!strcmp(res->name, "crc-strip")) {
1614                 if (!strcmp(res->value, "on"))
1615                         rx_mode.hw_strip_crc = 1;
1616                 else if (!strcmp(res->value, "off"))
1617                         rx_mode.hw_strip_crc = 0;
1618                 else {
1619                         printf("Unknown parameter\n");
1620                         return;
1621                 }
1622         } else if (!strcmp(res->name, "scatter")) {
1623                 if (!strcmp(res->value, "on"))
1624                         rx_mode.enable_scatter = 1;
1625                 else if (!strcmp(res->value, "off"))
1626                         rx_mode.enable_scatter = 0;
1627                 else {
1628                         printf("Unknown parameter\n");
1629                         return;
1630                 }
1631         } else if (!strcmp(res->name, "rx-cksum")) {
1632                 if (!strcmp(res->value, "on"))
1633                         rx_mode.hw_ip_checksum = 1;
1634                 else if (!strcmp(res->value, "off"))
1635                         rx_mode.hw_ip_checksum = 0;
1636                 else {
1637                         printf("Unknown parameter\n");
1638                         return;
1639                 }
1640         } else if (!strcmp(res->name, "rx-timestamp")) {
1641                 if (!strcmp(res->value, "on"))
1642                         rx_mode.hw_timestamp = 1;
1643                 else if (!strcmp(res->value, "off"))
1644                         rx_mode.hw_timestamp = 0;
1645                 else {
1646                         printf("Unknown parameter\n");
1647                         return;
1648                 }
1649         } else if (!strcmp(res->name, "hw-vlan")) {
1650                 if (!strcmp(res->value, "on")) {
1651                         rx_mode.hw_vlan_filter = 1;
1652                         rx_mode.hw_vlan_strip  = 1;
1653                 }
1654                 else if (!strcmp(res->value, "off")) {
1655                         rx_mode.hw_vlan_filter = 0;
1656                         rx_mode.hw_vlan_strip  = 0;
1657                 }
1658                 else {
1659                         printf("Unknown parameter\n");
1660                         return;
1661                 }
1662         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1663                 if (!strcmp(res->value, "on"))
1664                         rx_mode.hw_vlan_filter = 1;
1665                 else if (!strcmp(res->value, "off"))
1666                         rx_mode.hw_vlan_filter = 0;
1667                 else {
1668                         printf("Unknown parameter\n");
1669                         return;
1670                 }
1671         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1672                 if (!strcmp(res->value, "on"))
1673                         rx_mode.hw_vlan_strip  = 1;
1674                 else if (!strcmp(res->value, "off"))
1675                         rx_mode.hw_vlan_strip  = 0;
1676                 else {
1677                         printf("Unknown parameter\n");
1678                         return;
1679                 }
1680         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1681                 if (!strcmp(res->value, "on"))
1682                         rx_mode.hw_vlan_extend = 1;
1683                 else if (!strcmp(res->value, "off"))
1684                         rx_mode.hw_vlan_extend = 0;
1685                 else {
1686                         printf("Unknown parameter\n");
1687                         return;
1688                 }
1689         } else if (!strcmp(res->name, "drop-en")) {
1690                 if (!strcmp(res->value, "on"))
1691                         rx_drop_en = 1;
1692                 else if (!strcmp(res->value, "off"))
1693                         rx_drop_en = 0;
1694                 else {
1695                         printf("Unknown parameter\n");
1696                         return;
1697                 }
1698         } else {
1699                 printf("Unknown parameter\n");
1700                 return;
1701         }
1702
1703         init_port_config();
1704
1705         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1706 }
1707
1708 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1710 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1711         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1712                                                                 "config");
1713 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1715 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1717                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1718                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1719 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1721                                                         "on#off");
1722
1723 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1724         .f = cmd_config_rx_mode_flag_parsed,
1725         .data = NULL,
1726         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1727                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1728         .tokens = {
1729                 (void *)&cmd_config_rx_mode_flag_port,
1730                 (void *)&cmd_config_rx_mode_flag_keyword,
1731                 (void *)&cmd_config_rx_mode_flag_all,
1732                 (void *)&cmd_config_rx_mode_flag_name,
1733                 (void *)&cmd_config_rx_mode_flag_value,
1734                 NULL,
1735         },
1736 };
1737
1738 /* *** configure rss *** */
1739 struct cmd_config_rss {
1740         cmdline_fixed_string_t port;
1741         cmdline_fixed_string_t keyword;
1742         cmdline_fixed_string_t all;
1743         cmdline_fixed_string_t name;
1744         cmdline_fixed_string_t value;
1745 };
1746
1747 static void
1748 cmd_config_rss_parsed(void *parsed_result,
1749                         __attribute__((unused)) struct cmdline *cl,
1750                         __attribute__((unused)) void *data)
1751 {
1752         struct cmd_config_rss *res = parsed_result;
1753         struct rte_eth_rss_conf rss_conf;
1754         int diag;
1755         uint8_t i;
1756
1757         if (!strcmp(res->value, "all"))
1758                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1759                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1760                                         ETH_RSS_L2_PAYLOAD;
1761         else if (!strcmp(res->value, "ip"))
1762                 rss_conf.rss_hf = ETH_RSS_IP;
1763         else if (!strcmp(res->value, "udp"))
1764                 rss_conf.rss_hf = ETH_RSS_UDP;
1765         else if (!strcmp(res->value, "tcp"))
1766                 rss_conf.rss_hf = ETH_RSS_TCP;
1767         else if (!strcmp(res->value, "sctp"))
1768                 rss_conf.rss_hf = ETH_RSS_SCTP;
1769         else if (!strcmp(res->value, "ether"))
1770                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1771         else if (!strcmp(res->value, "port"))
1772                 rss_conf.rss_hf = ETH_RSS_PORT;
1773         else if (!strcmp(res->value, "vxlan"))
1774                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1775         else if (!strcmp(res->value, "geneve"))
1776                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1777         else if (!strcmp(res->value, "nvgre"))
1778                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1779         else if (!strcmp(res->value, "none"))
1780                 rss_conf.rss_hf = 0;
1781         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1782                                                 atoi(res->value) < 64)
1783                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1784         else {
1785                 printf("Unknown parameter\n");
1786                 return;
1787         }
1788         rss_conf.rss_key = NULL;
1789         for (i = 0; i < rte_eth_dev_count(); i++) {
1790                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1791                 if (diag < 0)
1792                         printf("Configuration of RSS hash at ethernet port %d "
1793                                 "failed with error (%d): %s.\n",
1794                                 i, -diag, strerror(-diag));
1795         }
1796 }
1797
1798 cmdline_parse_token_string_t cmd_config_rss_port =
1799         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1800 cmdline_parse_token_string_t cmd_config_rss_keyword =
1801         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1802 cmdline_parse_token_string_t cmd_config_rss_all =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1804 cmdline_parse_token_string_t cmd_config_rss_name =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1806 cmdline_parse_token_string_t cmd_config_rss_value =
1807         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1808
1809 cmdline_parse_inst_t cmd_config_rss = {
1810         .f = cmd_config_rss_parsed,
1811         .data = NULL,
1812         .help_str = "port config all rss "
1813                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1814         .tokens = {
1815                 (void *)&cmd_config_rss_port,
1816                 (void *)&cmd_config_rss_keyword,
1817                 (void *)&cmd_config_rss_all,
1818                 (void *)&cmd_config_rss_name,
1819                 (void *)&cmd_config_rss_value,
1820                 NULL,
1821         },
1822 };
1823
1824 /* *** configure rss hash key *** */
1825 struct cmd_config_rss_hash_key {
1826         cmdline_fixed_string_t port;
1827         cmdline_fixed_string_t config;
1828         portid_t port_id;
1829         cmdline_fixed_string_t rss_hash_key;
1830         cmdline_fixed_string_t rss_type;
1831         cmdline_fixed_string_t key;
1832 };
1833
1834 static uint8_t
1835 hexa_digit_to_value(char hexa_digit)
1836 {
1837         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1838                 return (uint8_t) (hexa_digit - '0');
1839         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1840                 return (uint8_t) ((hexa_digit - 'a') + 10);
1841         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1842                 return (uint8_t) ((hexa_digit - 'A') + 10);
1843         /* Invalid hexa digit */
1844         return 0xFF;
1845 }
1846
1847 static uint8_t
1848 parse_and_check_key_hexa_digit(char *key, int idx)
1849 {
1850         uint8_t hexa_v;
1851
1852         hexa_v = hexa_digit_to_value(key[idx]);
1853         if (hexa_v == 0xFF)
1854                 printf("invalid key: character %c at position %d is not a "
1855                        "valid hexa digit\n", key[idx], idx);
1856         return hexa_v;
1857 }
1858
1859 static void
1860 cmd_config_rss_hash_key_parsed(void *parsed_result,
1861                                __attribute__((unused)) struct cmdline *cl,
1862                                __attribute__((unused)) void *data)
1863 {
1864         struct cmd_config_rss_hash_key *res = parsed_result;
1865         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1866         uint8_t xdgt0;
1867         uint8_t xdgt1;
1868         int i;
1869         struct rte_eth_dev_info dev_info;
1870         uint8_t hash_key_size;
1871         uint32_t key_len;
1872
1873         memset(&dev_info, 0, sizeof(dev_info));
1874         rte_eth_dev_info_get(res->port_id, &dev_info);
1875         if (dev_info.hash_key_size > 0 &&
1876                         dev_info.hash_key_size <= sizeof(hash_key))
1877                 hash_key_size = dev_info.hash_key_size;
1878         else {
1879                 printf("dev_info did not provide a valid hash key size\n");
1880                 return;
1881         }
1882         /* Check the length of the RSS hash key */
1883         key_len = strlen(res->key);
1884         if (key_len != (hash_key_size * 2)) {
1885                 printf("key length: %d invalid - key must be a string of %d"
1886                            " hexa-decimal numbers\n",
1887                            (int) key_len, hash_key_size * 2);
1888                 return;
1889         }
1890         /* Translate RSS hash key into binary representation */
1891         for (i = 0; i < hash_key_size; i++) {
1892                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1893                 if (xdgt0 == 0xFF)
1894                         return;
1895                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1896                 if (xdgt1 == 0xFF)
1897                         return;
1898                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1899         }
1900         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1901                         hash_key_size);
1902 }
1903
1904 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1905         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1906 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1907         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1908                                  "config");
1909 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1910         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
1911 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1912         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1913                                  rss_hash_key, "rss-hash-key");
1914 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1915         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1916                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1917                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1918                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1919                                  "ipv6-tcp-ex#ipv6-udp-ex");
1920 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1921         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1922
1923 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1924         .f = cmd_config_rss_hash_key_parsed,
1925         .data = NULL,
1926         .help_str = "port config <port_id> rss-hash-key "
1927                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1928                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1929                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1930                 "<string of hex digits (variable length, NIC dependent)>",
1931         .tokens = {
1932                 (void *)&cmd_config_rss_hash_key_port,
1933                 (void *)&cmd_config_rss_hash_key_config,
1934                 (void *)&cmd_config_rss_hash_key_port_id,
1935                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1936                 (void *)&cmd_config_rss_hash_key_rss_type,
1937                 (void *)&cmd_config_rss_hash_key_value,
1938                 NULL,
1939         },
1940 };
1941
1942 /* *** configure port rxq/txq start/stop *** */
1943 struct cmd_config_rxtx_queue {
1944         cmdline_fixed_string_t port;
1945         portid_t portid;
1946         cmdline_fixed_string_t rxtxq;
1947         uint16_t qid;
1948         cmdline_fixed_string_t opname;
1949 };
1950
1951 static void
1952 cmd_config_rxtx_queue_parsed(void *parsed_result,
1953                         __attribute__((unused)) struct cmdline *cl,
1954                         __attribute__((unused)) void *data)
1955 {
1956         struct cmd_config_rxtx_queue *res = parsed_result;
1957         uint8_t isrx;
1958         uint8_t isstart;
1959         int ret = 0;
1960
1961         if (test_done == 0) {
1962                 printf("Please stop forwarding first\n");
1963                 return;
1964         }
1965
1966         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1967                 return;
1968
1969         if (port_is_started(res->portid) != 1) {
1970                 printf("Please start port %u first\n", res->portid);
1971                 return;
1972         }
1973
1974         if (!strcmp(res->rxtxq, "rxq"))
1975                 isrx = 1;
1976         else if (!strcmp(res->rxtxq, "txq"))
1977                 isrx = 0;
1978         else {
1979                 printf("Unknown parameter\n");
1980                 return;
1981         }
1982
1983         if (isrx && rx_queue_id_is_invalid(res->qid))
1984                 return;
1985         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1986                 return;
1987
1988         if (!strcmp(res->opname, "start"))
1989                 isstart = 1;
1990         else if (!strcmp(res->opname, "stop"))
1991                 isstart = 0;
1992         else {
1993                 printf("Unknown parameter\n");
1994                 return;
1995         }
1996
1997         if (isstart && isrx)
1998                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1999         else if (!isstart && isrx)
2000                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2001         else if (isstart && !isrx)
2002                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2003         else
2004                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2005
2006         if (ret == -ENOTSUP)
2007                 printf("Function not supported in PMD driver\n");
2008 }
2009
2010 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2012 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2013         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2014 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2016 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2017         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2018 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2019         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2020                                                 "start#stop");
2021
2022 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2023         .f = cmd_config_rxtx_queue_parsed,
2024         .data = NULL,
2025         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2026         .tokens = {
2027                 (void *)&cmd_config_speed_all_port,
2028                 (void *)&cmd_config_rxtx_queue_portid,
2029                 (void *)&cmd_config_rxtx_queue_rxtxq,
2030                 (void *)&cmd_config_rxtx_queue_qid,
2031                 (void *)&cmd_config_rxtx_queue_opname,
2032                 NULL,
2033         },
2034 };
2035
2036 /* *** Configure RSS RETA *** */
2037 struct cmd_config_rss_reta {
2038         cmdline_fixed_string_t port;
2039         cmdline_fixed_string_t keyword;
2040         portid_t port_id;
2041         cmdline_fixed_string_t name;
2042         cmdline_fixed_string_t list_name;
2043         cmdline_fixed_string_t list_of_items;
2044 };
2045
2046 static int
2047 parse_reta_config(const char *str,
2048                   struct rte_eth_rss_reta_entry64 *reta_conf,
2049                   uint16_t nb_entries)
2050 {
2051         int i;
2052         unsigned size;
2053         uint16_t hash_index, idx, shift;
2054         uint16_t nb_queue;
2055         char s[256];
2056         const char *p, *p0 = str;
2057         char *end;
2058         enum fieldnames {
2059                 FLD_HASH_INDEX = 0,
2060                 FLD_QUEUE,
2061                 _NUM_FLD
2062         };
2063         unsigned long int_fld[_NUM_FLD];
2064         char *str_fld[_NUM_FLD];
2065
2066         while ((p = strchr(p0,'(')) != NULL) {
2067                 ++p;
2068                 if((p0 = strchr(p,')')) == NULL)
2069                         return -1;
2070
2071                 size = p0 - p;
2072                 if(size >= sizeof(s))
2073                         return -1;
2074
2075                 snprintf(s, sizeof(s), "%.*s", size, p);
2076                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2077                         return -1;
2078                 for (i = 0; i < _NUM_FLD; i++) {
2079                         errno = 0;
2080                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2081                         if (errno != 0 || end == str_fld[i] ||
2082                                         int_fld[i] > 65535)
2083                                 return -1;
2084                 }
2085
2086                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2087                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2088
2089                 if (hash_index >= nb_entries) {
2090                         printf("Invalid RETA hash index=%d\n", hash_index);
2091                         return -1;
2092                 }
2093
2094                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2095                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2096                 reta_conf[idx].mask |= (1ULL << shift);
2097                 reta_conf[idx].reta[shift] = nb_queue;
2098         }
2099
2100         return 0;
2101 }
2102
2103 static void
2104 cmd_set_rss_reta_parsed(void *parsed_result,
2105                         __attribute__((unused)) struct cmdline *cl,
2106                         __attribute__((unused)) void *data)
2107 {
2108         int ret;
2109         struct rte_eth_dev_info dev_info;
2110         struct rte_eth_rss_reta_entry64 reta_conf[8];
2111         struct cmd_config_rss_reta *res = parsed_result;
2112
2113         memset(&dev_info, 0, sizeof(dev_info));
2114         rte_eth_dev_info_get(res->port_id, &dev_info);
2115         if (dev_info.reta_size == 0) {
2116                 printf("Redirection table size is 0 which is "
2117                                         "invalid for RSS\n");
2118                 return;
2119         } else
2120                 printf("The reta size of port %d is %u\n",
2121                         res->port_id, dev_info.reta_size);
2122         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2123                 printf("Currently do not support more than %u entries of "
2124                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2125                 return;
2126         }
2127
2128         memset(reta_conf, 0, sizeof(reta_conf));
2129         if (!strcmp(res->list_name, "reta")) {
2130                 if (parse_reta_config(res->list_of_items, reta_conf,
2131                                                 dev_info.reta_size)) {
2132                         printf("Invalid RSS Redirection Table "
2133                                         "config entered\n");
2134                         return;
2135                 }
2136                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2137                                 reta_conf, dev_info.reta_size);
2138                 if (ret != 0)
2139                         printf("Bad redirection table parameter, "
2140                                         "return code = %d \n", ret);
2141         }
2142 }
2143
2144 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2146 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2147         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2148 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2149         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2150 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2152 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2154 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2156                                  NULL);
2157 cmdline_parse_inst_t cmd_config_rss_reta = {
2158         .f = cmd_set_rss_reta_parsed,
2159         .data = NULL,
2160         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2161         .tokens = {
2162                 (void *)&cmd_config_rss_reta_port,
2163                 (void *)&cmd_config_rss_reta_keyword,
2164                 (void *)&cmd_config_rss_reta_port_id,
2165                 (void *)&cmd_config_rss_reta_name,
2166                 (void *)&cmd_config_rss_reta_list_name,
2167                 (void *)&cmd_config_rss_reta_list_of_items,
2168                 NULL,
2169         },
2170 };
2171
2172 /* *** SHOW PORT RETA INFO *** */
2173 struct cmd_showport_reta {
2174         cmdline_fixed_string_t show;
2175         cmdline_fixed_string_t port;
2176         portid_t port_id;
2177         cmdline_fixed_string_t rss;
2178         cmdline_fixed_string_t reta;
2179         uint16_t size;
2180         cmdline_fixed_string_t list_of_items;
2181 };
2182
2183 static int
2184 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2185                            uint16_t nb_entries,
2186                            char *str)
2187 {
2188         uint32_t size;
2189         const char *p, *p0 = str;
2190         char s[256];
2191         char *end;
2192         char *str_fld[8];
2193         uint16_t i;
2194         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2195                         RTE_RETA_GROUP_SIZE;
2196         int ret;
2197
2198         p = strchr(p0, '(');
2199         if (p == NULL)
2200                 return -1;
2201         p++;
2202         p0 = strchr(p, ')');
2203         if (p0 == NULL)
2204                 return -1;
2205         size = p0 - p;
2206         if (size >= sizeof(s)) {
2207                 printf("The string size exceeds the internal buffer size\n");
2208                 return -1;
2209         }
2210         snprintf(s, sizeof(s), "%.*s", size, p);
2211         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2212         if (ret <= 0 || ret != num) {
2213                 printf("The bits of masks do not match the number of "
2214                                         "reta entries: %u\n", num);
2215                 return -1;
2216         }
2217         for (i = 0; i < ret; i++)
2218                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2219
2220         return 0;
2221 }
2222
2223 static void
2224 cmd_showport_reta_parsed(void *parsed_result,
2225                          __attribute__((unused)) struct cmdline *cl,
2226                          __attribute__((unused)) void *data)
2227 {
2228         struct cmd_showport_reta *res = parsed_result;
2229         struct rte_eth_rss_reta_entry64 reta_conf[8];
2230         struct rte_eth_dev_info dev_info;
2231         uint16_t max_reta_size;
2232
2233         memset(&dev_info, 0, sizeof(dev_info));
2234         rte_eth_dev_info_get(res->port_id, &dev_info);
2235         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2236         if (res->size == 0 || res->size > max_reta_size) {
2237                 printf("Invalid redirection table size: %u (1-%u)\n",
2238                         res->size, max_reta_size);
2239                 return;
2240         }
2241
2242         memset(reta_conf, 0, sizeof(reta_conf));
2243         if (showport_parse_reta_config(reta_conf, res->size,
2244                                 res->list_of_items) < 0) {
2245                 printf("Invalid string: %s for reta masks\n",
2246                                         res->list_of_items);
2247                 return;
2248         }
2249         port_rss_reta_info(res->port_id, reta_conf, res->size);
2250 }
2251
2252 cmdline_parse_token_string_t cmd_showport_reta_show =
2253         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2254 cmdline_parse_token_string_t cmd_showport_reta_port =
2255         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2256 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2257         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2258 cmdline_parse_token_string_t cmd_showport_reta_rss =
2259         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2260 cmdline_parse_token_string_t cmd_showport_reta_reta =
2261         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2262 cmdline_parse_token_num_t cmd_showport_reta_size =
2263         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2264 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2265         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2266                                         list_of_items, NULL);
2267
2268 cmdline_parse_inst_t cmd_showport_reta = {
2269         .f = cmd_showport_reta_parsed,
2270         .data = NULL,
2271         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2272         .tokens = {
2273                 (void *)&cmd_showport_reta_show,
2274                 (void *)&cmd_showport_reta_port,
2275                 (void *)&cmd_showport_reta_port_id,
2276                 (void *)&cmd_showport_reta_rss,
2277                 (void *)&cmd_showport_reta_reta,
2278                 (void *)&cmd_showport_reta_size,
2279                 (void *)&cmd_showport_reta_list_of_items,
2280                 NULL,
2281         },
2282 };
2283
2284 /* *** Show RSS hash configuration *** */
2285 struct cmd_showport_rss_hash {
2286         cmdline_fixed_string_t show;
2287         cmdline_fixed_string_t port;
2288         portid_t port_id;
2289         cmdline_fixed_string_t rss_hash;
2290         cmdline_fixed_string_t rss_type;
2291         cmdline_fixed_string_t key; /* optional argument */
2292 };
2293
2294 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2295                                 __attribute__((unused)) struct cmdline *cl,
2296                                 void *show_rss_key)
2297 {
2298         struct cmd_showport_rss_hash *res = parsed_result;
2299
2300         port_rss_hash_conf_show(res->port_id, res->rss_type,
2301                                 show_rss_key != NULL);
2302 }
2303
2304 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2305         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2306 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2307         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2308 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2309         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2310 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2311         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2312                                  "rss-hash");
2313 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2314         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2315                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2316                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2317                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2318                                  "ipv6-tcp-ex#ipv6-udp-ex");
2319 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2320         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2321
2322 cmdline_parse_inst_t cmd_showport_rss_hash = {
2323         .f = cmd_showport_rss_hash_parsed,
2324         .data = NULL,
2325         .help_str = "show port <port_id> rss-hash "
2326                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2327                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2328                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2329         .tokens = {
2330                 (void *)&cmd_showport_rss_hash_show,
2331                 (void *)&cmd_showport_rss_hash_port,
2332                 (void *)&cmd_showport_rss_hash_port_id,
2333                 (void *)&cmd_showport_rss_hash_rss_hash,
2334                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2335                 NULL,
2336         },
2337 };
2338
2339 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2340         .f = cmd_showport_rss_hash_parsed,
2341         .data = (void *)1,
2342         .help_str = "show port <port_id> rss-hash "
2343                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2344                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2345                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2346         .tokens = {
2347                 (void *)&cmd_showport_rss_hash_show,
2348                 (void *)&cmd_showport_rss_hash_port,
2349                 (void *)&cmd_showport_rss_hash_port_id,
2350                 (void *)&cmd_showport_rss_hash_rss_hash,
2351                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2352                 (void *)&cmd_showport_rss_hash_rss_key,
2353                 NULL,
2354         },
2355 };
2356
2357 /* *** Configure DCB *** */
2358 struct cmd_config_dcb {
2359         cmdline_fixed_string_t port;
2360         cmdline_fixed_string_t config;
2361         portid_t port_id;
2362         cmdline_fixed_string_t dcb;
2363         cmdline_fixed_string_t vt;
2364         cmdline_fixed_string_t vt_en;
2365         uint8_t num_tcs;
2366         cmdline_fixed_string_t pfc;
2367         cmdline_fixed_string_t pfc_en;
2368 };
2369
2370 static void
2371 cmd_config_dcb_parsed(void *parsed_result,
2372                         __attribute__((unused)) struct cmdline *cl,
2373                         __attribute__((unused)) void *data)
2374 {
2375         struct cmd_config_dcb *res = parsed_result;
2376         portid_t port_id = res->port_id;
2377         struct rte_port *port;
2378         uint8_t pfc_en;
2379         int ret;
2380
2381         port = &ports[port_id];
2382         /** Check if the port is not started **/
2383         if (port->port_status != RTE_PORT_STOPPED) {
2384                 printf("Please stop port %d first\n", port_id);
2385                 return;
2386         }
2387
2388         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2389                 printf("The invalid number of traffic class,"
2390                         " only 4 or 8 allowed.\n");
2391                 return;
2392         }
2393
2394         if (nb_fwd_lcores < res->num_tcs) {
2395                 printf("nb_cores shouldn't be less than number of TCs.\n");
2396                 return;
2397         }
2398         if (!strncmp(res->pfc_en, "on", 2))
2399                 pfc_en = 1;
2400         else
2401                 pfc_en = 0;
2402
2403         /* DCB in VT mode */
2404         if (!strncmp(res->vt_en, "on", 2))
2405                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2406                                 (enum rte_eth_nb_tcs)res->num_tcs,
2407                                 pfc_en);
2408         else
2409                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2410                                 (enum rte_eth_nb_tcs)res->num_tcs,
2411                                 pfc_en);
2412
2413
2414         if (ret != 0) {
2415                 printf("Cannot initialize network ports.\n");
2416                 return;
2417         }
2418
2419         cmd_reconfig_device_queue(port_id, 1, 1);
2420 }
2421
2422 cmdline_parse_token_string_t cmd_config_dcb_port =
2423         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2424 cmdline_parse_token_string_t cmd_config_dcb_config =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2426 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2427         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2428 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2429         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2430 cmdline_parse_token_string_t cmd_config_dcb_vt =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2432 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2433         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2434 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2435         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2436 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2438 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2440
2441 cmdline_parse_inst_t cmd_config_dcb = {
2442         .f = cmd_config_dcb_parsed,
2443         .data = NULL,
2444         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2445         .tokens = {
2446                 (void *)&cmd_config_dcb_port,
2447                 (void *)&cmd_config_dcb_config,
2448                 (void *)&cmd_config_dcb_port_id,
2449                 (void *)&cmd_config_dcb_dcb,
2450                 (void *)&cmd_config_dcb_vt,
2451                 (void *)&cmd_config_dcb_vt_en,
2452                 (void *)&cmd_config_dcb_num_tcs,
2453                 (void *)&cmd_config_dcb_pfc,
2454                 (void *)&cmd_config_dcb_pfc_en,
2455                 NULL,
2456         },
2457 };
2458
2459 /* *** configure number of packets per burst *** */
2460 struct cmd_config_burst {
2461         cmdline_fixed_string_t port;
2462         cmdline_fixed_string_t keyword;
2463         cmdline_fixed_string_t all;
2464         cmdline_fixed_string_t name;
2465         uint16_t value;
2466 };
2467
2468 static void
2469 cmd_config_burst_parsed(void *parsed_result,
2470                         __attribute__((unused)) struct cmdline *cl,
2471                         __attribute__((unused)) void *data)
2472 {
2473         struct cmd_config_burst *res = parsed_result;
2474
2475         if (!all_ports_stopped()) {
2476                 printf("Please stop all ports first\n");
2477                 return;
2478         }
2479
2480         if (!strcmp(res->name, "burst")) {
2481                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2482                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2483                         return;
2484                 }
2485                 nb_pkt_per_burst = res->value;
2486         } else {
2487                 printf("Unknown parameter\n");
2488                 return;
2489         }
2490
2491         init_port_config();
2492
2493         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2494 }
2495
2496 cmdline_parse_token_string_t cmd_config_burst_port =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2498 cmdline_parse_token_string_t cmd_config_burst_keyword =
2499         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2500 cmdline_parse_token_string_t cmd_config_burst_all =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2502 cmdline_parse_token_string_t cmd_config_burst_name =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2504 cmdline_parse_token_num_t cmd_config_burst_value =
2505         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2506
2507 cmdline_parse_inst_t cmd_config_burst = {
2508         .f = cmd_config_burst_parsed,
2509         .data = NULL,
2510         .help_str = "port config all burst <value>",
2511         .tokens = {
2512                 (void *)&cmd_config_burst_port,
2513                 (void *)&cmd_config_burst_keyword,
2514                 (void *)&cmd_config_burst_all,
2515                 (void *)&cmd_config_burst_name,
2516                 (void *)&cmd_config_burst_value,
2517                 NULL,
2518         },
2519 };
2520
2521 /* *** configure rx/tx queues *** */
2522 struct cmd_config_thresh {
2523         cmdline_fixed_string_t port;
2524         cmdline_fixed_string_t keyword;
2525         cmdline_fixed_string_t all;
2526         cmdline_fixed_string_t name;
2527         uint8_t value;
2528 };
2529
2530 static void
2531 cmd_config_thresh_parsed(void *parsed_result,
2532                         __attribute__((unused)) struct cmdline *cl,
2533                         __attribute__((unused)) void *data)
2534 {
2535         struct cmd_config_thresh *res = parsed_result;
2536
2537         if (!all_ports_stopped()) {
2538                 printf("Please stop all ports first\n");
2539                 return;
2540         }
2541
2542         if (!strcmp(res->name, "txpt"))
2543                 tx_pthresh = res->value;
2544         else if(!strcmp(res->name, "txht"))
2545                 tx_hthresh = res->value;
2546         else if(!strcmp(res->name, "txwt"))
2547                 tx_wthresh = res->value;
2548         else if(!strcmp(res->name, "rxpt"))
2549                 rx_pthresh = res->value;
2550         else if(!strcmp(res->name, "rxht"))
2551                 rx_hthresh = res->value;
2552         else if(!strcmp(res->name, "rxwt"))
2553                 rx_wthresh = res->value;
2554         else {
2555                 printf("Unknown parameter\n");
2556                 return;
2557         }
2558
2559         init_port_config();
2560
2561         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2562 }
2563
2564 cmdline_parse_token_string_t cmd_config_thresh_port =
2565         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2566 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2568 cmdline_parse_token_string_t cmd_config_thresh_all =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2570 cmdline_parse_token_string_t cmd_config_thresh_name =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2572                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2573 cmdline_parse_token_num_t cmd_config_thresh_value =
2574         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2575
2576 cmdline_parse_inst_t cmd_config_thresh = {
2577         .f = cmd_config_thresh_parsed,
2578         .data = NULL,
2579         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2580         .tokens = {
2581                 (void *)&cmd_config_thresh_port,
2582                 (void *)&cmd_config_thresh_keyword,
2583                 (void *)&cmd_config_thresh_all,
2584                 (void *)&cmd_config_thresh_name,
2585                 (void *)&cmd_config_thresh_value,
2586                 NULL,
2587         },
2588 };
2589
2590 /* *** configure free/rs threshold *** */
2591 struct cmd_config_threshold {
2592         cmdline_fixed_string_t port;
2593         cmdline_fixed_string_t keyword;
2594         cmdline_fixed_string_t all;
2595         cmdline_fixed_string_t name;
2596         uint16_t value;
2597 };
2598
2599 static void
2600 cmd_config_threshold_parsed(void *parsed_result,
2601                         __attribute__((unused)) struct cmdline *cl,
2602                         __attribute__((unused)) void *data)
2603 {
2604         struct cmd_config_threshold *res = parsed_result;
2605
2606         if (!all_ports_stopped()) {
2607                 printf("Please stop all ports first\n");
2608                 return;
2609         }
2610
2611         if (!strcmp(res->name, "txfreet"))
2612                 tx_free_thresh = res->value;
2613         else if (!strcmp(res->name, "txrst"))
2614                 tx_rs_thresh = res->value;
2615         else if (!strcmp(res->name, "rxfreet"))
2616                 rx_free_thresh = res->value;
2617         else {
2618                 printf("Unknown parameter\n");
2619                 return;
2620         }
2621
2622         init_port_config();
2623
2624         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2625 }
2626
2627 cmdline_parse_token_string_t cmd_config_threshold_port =
2628         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2629 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2630         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2631                                                                 "config");
2632 cmdline_parse_token_string_t cmd_config_threshold_all =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2634 cmdline_parse_token_string_t cmd_config_threshold_name =
2635         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2636                                                 "txfreet#txrst#rxfreet");
2637 cmdline_parse_token_num_t cmd_config_threshold_value =
2638         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2639
2640 cmdline_parse_inst_t cmd_config_threshold = {
2641         .f = cmd_config_threshold_parsed,
2642         .data = NULL,
2643         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2644         .tokens = {
2645                 (void *)&cmd_config_threshold_port,
2646                 (void *)&cmd_config_threshold_keyword,
2647                 (void *)&cmd_config_threshold_all,
2648                 (void *)&cmd_config_threshold_name,
2649                 (void *)&cmd_config_threshold_value,
2650                 NULL,
2651         },
2652 };
2653
2654 /* *** stop *** */
2655 struct cmd_stop_result {
2656         cmdline_fixed_string_t stop;
2657 };
2658
2659 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2660                             __attribute__((unused)) struct cmdline *cl,
2661                             __attribute__((unused)) void *data)
2662 {
2663         stop_packet_forwarding();
2664 }
2665
2666 cmdline_parse_token_string_t cmd_stop_stop =
2667         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2668
2669 cmdline_parse_inst_t cmd_stop = {
2670         .f = cmd_stop_parsed,
2671         .data = NULL,
2672         .help_str = "stop: Stop packet forwarding",
2673         .tokens = {
2674                 (void *)&cmd_stop_stop,
2675                 NULL,
2676         },
2677 };
2678
2679 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2680
2681 unsigned int
2682 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2683                 unsigned int *parsed_items, int check_unique_values)
2684 {
2685         unsigned int nb_item;
2686         unsigned int value;
2687         unsigned int i;
2688         unsigned int j;
2689         int value_ok;
2690         char c;
2691
2692         /*
2693          * First parse all items in the list and store their value.
2694          */
2695         value = 0;
2696         nb_item = 0;
2697         value_ok = 0;
2698         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2699                 c = str[i];
2700                 if ((c >= '0') && (c <= '9')) {
2701                         value = (unsigned int) (value * 10 + (c - '0'));
2702                         value_ok = 1;
2703                         continue;
2704                 }
2705                 if (c != ',') {
2706                         printf("character %c is not a decimal digit\n", c);
2707                         return 0;
2708                 }
2709                 if (! value_ok) {
2710                         printf("No valid value before comma\n");
2711                         return 0;
2712                 }
2713                 if (nb_item < max_items) {
2714                         parsed_items[nb_item] = value;
2715                         value_ok = 0;
2716                         value = 0;
2717                 }
2718                 nb_item++;
2719         }
2720         if (nb_item >= max_items) {
2721                 printf("Number of %s = %u > %u (maximum items)\n",
2722                        item_name, nb_item + 1, max_items);
2723                 return 0;
2724         }
2725         parsed_items[nb_item++] = value;
2726         if (! check_unique_values)
2727                 return nb_item;
2728
2729         /*
2730          * Then, check that all values in the list are differents.
2731          * No optimization here...
2732          */
2733         for (i = 0; i < nb_item; i++) {
2734                 for (j = i + 1; j < nb_item; j++) {
2735                         if (parsed_items[j] == parsed_items[i]) {
2736                                 printf("duplicated %s %u at index %u and %u\n",
2737                                        item_name, parsed_items[i], i, j);
2738                                 return 0;
2739                         }
2740                 }
2741         }
2742         return nb_item;
2743 }
2744
2745 struct cmd_set_list_result {
2746         cmdline_fixed_string_t cmd_keyword;
2747         cmdline_fixed_string_t list_name;
2748         cmdline_fixed_string_t list_of_items;
2749 };
2750
2751 static void cmd_set_list_parsed(void *parsed_result,
2752                                 __attribute__((unused)) struct cmdline *cl,
2753                                 __attribute__((unused)) void *data)
2754 {
2755         struct cmd_set_list_result *res;
2756         union {
2757                 unsigned int lcorelist[RTE_MAX_LCORE];
2758                 unsigned int portlist[RTE_MAX_ETHPORTS];
2759         } parsed_items;
2760         unsigned int nb_item;
2761
2762         if (test_done == 0) {
2763                 printf("Please stop forwarding first\n");
2764                 return;
2765         }
2766
2767         res = parsed_result;
2768         if (!strcmp(res->list_name, "corelist")) {
2769                 nb_item = parse_item_list(res->list_of_items, "core",
2770                                           RTE_MAX_LCORE,
2771                                           parsed_items.lcorelist, 1);
2772                 if (nb_item > 0) {
2773                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2774                         fwd_config_setup();
2775                 }
2776                 return;
2777         }
2778         if (!strcmp(res->list_name, "portlist")) {
2779                 nb_item = parse_item_list(res->list_of_items, "port",
2780                                           RTE_MAX_ETHPORTS,
2781                                           parsed_items.portlist, 1);
2782                 if (nb_item > 0) {
2783                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2784                         fwd_config_setup();
2785                 }
2786         }
2787 }
2788
2789 cmdline_parse_token_string_t cmd_set_list_keyword =
2790         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2791                                  "set");
2792 cmdline_parse_token_string_t cmd_set_list_name =
2793         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2794                                  "corelist#portlist");
2795 cmdline_parse_token_string_t cmd_set_list_of_items =
2796         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2797                                  NULL);
2798
2799 cmdline_parse_inst_t cmd_set_fwd_list = {
2800         .f = cmd_set_list_parsed,
2801         .data = NULL,
2802         .help_str = "set corelist|portlist <list0[,list1]*>",
2803         .tokens = {
2804                 (void *)&cmd_set_list_keyword,
2805                 (void *)&cmd_set_list_name,
2806                 (void *)&cmd_set_list_of_items,
2807                 NULL,
2808         },
2809 };
2810
2811 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2812
2813 struct cmd_setmask_result {
2814         cmdline_fixed_string_t set;
2815         cmdline_fixed_string_t mask;
2816         uint64_t hexavalue;
2817 };
2818
2819 static void cmd_set_mask_parsed(void *parsed_result,
2820                                 __attribute__((unused)) struct cmdline *cl,
2821                                 __attribute__((unused)) void *data)
2822 {
2823         struct cmd_setmask_result *res = parsed_result;
2824
2825         if (test_done == 0) {
2826                 printf("Please stop forwarding first\n");
2827                 return;
2828         }
2829         if (!strcmp(res->mask, "coremask")) {
2830                 set_fwd_lcores_mask(res->hexavalue);
2831                 fwd_config_setup();
2832         } else if (!strcmp(res->mask, "portmask")) {
2833                 set_fwd_ports_mask(res->hexavalue);
2834                 fwd_config_setup();
2835         }
2836 }
2837
2838 cmdline_parse_token_string_t cmd_setmask_set =
2839         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2840 cmdline_parse_token_string_t cmd_setmask_mask =
2841         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2842                                  "coremask#portmask");
2843 cmdline_parse_token_num_t cmd_setmask_value =
2844         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2845
2846 cmdline_parse_inst_t cmd_set_fwd_mask = {
2847         .f = cmd_set_mask_parsed,
2848         .data = NULL,
2849         .help_str = "set coremask|portmask <hexadecimal value>",
2850         .tokens = {
2851                 (void *)&cmd_setmask_set,
2852                 (void *)&cmd_setmask_mask,
2853                 (void *)&cmd_setmask_value,
2854                 NULL,
2855         },
2856 };
2857
2858 /*
2859  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2860  */
2861 struct cmd_set_result {
2862         cmdline_fixed_string_t set;
2863         cmdline_fixed_string_t what;
2864         uint16_t value;
2865 };
2866
2867 static void cmd_set_parsed(void *parsed_result,
2868                            __attribute__((unused)) struct cmdline *cl,
2869                            __attribute__((unused)) void *data)
2870 {
2871         struct cmd_set_result *res = parsed_result;
2872         if (!strcmp(res->what, "nbport")) {
2873                 set_fwd_ports_number(res->value);
2874                 fwd_config_setup();
2875         } else if (!strcmp(res->what, "nbcore")) {
2876                 set_fwd_lcores_number(res->value);
2877                 fwd_config_setup();
2878         } else if (!strcmp(res->what, "burst"))
2879                 set_nb_pkt_per_burst(res->value);
2880         else if (!strcmp(res->what, "verbose"))
2881                 set_verbose_level(res->value);
2882 }
2883
2884 cmdline_parse_token_string_t cmd_set_set =
2885         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2886 cmdline_parse_token_string_t cmd_set_what =
2887         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2888                                  "nbport#nbcore#burst#verbose");
2889 cmdline_parse_token_num_t cmd_set_value =
2890         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2891
2892 cmdline_parse_inst_t cmd_set_numbers = {
2893         .f = cmd_set_parsed,
2894         .data = NULL,
2895         .help_str = "set nbport|nbcore|burst|verbose <value>",
2896         .tokens = {
2897                 (void *)&cmd_set_set,
2898                 (void *)&cmd_set_what,
2899                 (void *)&cmd_set_value,
2900                 NULL,
2901         },
2902 };
2903
2904 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2905
2906 struct cmd_set_txpkts_result {
2907         cmdline_fixed_string_t cmd_keyword;
2908         cmdline_fixed_string_t txpkts;
2909         cmdline_fixed_string_t seg_lengths;
2910 };
2911
2912 static void
2913 cmd_set_txpkts_parsed(void *parsed_result,
2914                       __attribute__((unused)) struct cmdline *cl,
2915                       __attribute__((unused)) void *data)
2916 {
2917         struct cmd_set_txpkts_result *res;
2918         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2919         unsigned int nb_segs;
2920
2921         res = parsed_result;
2922         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2923                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2924         if (nb_segs > 0)
2925                 set_tx_pkt_segments(seg_lengths, nb_segs);
2926 }
2927
2928 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2929         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2930                                  cmd_keyword, "set");
2931 cmdline_parse_token_string_t cmd_set_txpkts_name =
2932         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2933                                  txpkts, "txpkts");
2934 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2935         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2936                                  seg_lengths, NULL);
2937
2938 cmdline_parse_inst_t cmd_set_txpkts = {
2939         .f = cmd_set_txpkts_parsed,
2940         .data = NULL,
2941         .help_str = "set txpkts <len0[,len1]*>",
2942         .tokens = {
2943                 (void *)&cmd_set_txpkts_keyword,
2944                 (void *)&cmd_set_txpkts_name,
2945                 (void *)&cmd_set_txpkts_lengths,
2946                 NULL,
2947         },
2948 };
2949
2950 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2951
2952 struct cmd_set_txsplit_result {
2953         cmdline_fixed_string_t cmd_keyword;
2954         cmdline_fixed_string_t txsplit;
2955         cmdline_fixed_string_t mode;
2956 };
2957
2958 static void
2959 cmd_set_txsplit_parsed(void *parsed_result,
2960                       __attribute__((unused)) struct cmdline *cl,
2961                       __attribute__((unused)) void *data)
2962 {
2963         struct cmd_set_txsplit_result *res;
2964
2965         res = parsed_result;
2966         set_tx_pkt_split(res->mode);
2967 }
2968
2969 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2970         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2971                                  cmd_keyword, "set");
2972 cmdline_parse_token_string_t cmd_set_txsplit_name =
2973         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2974                                  txsplit, "txsplit");
2975 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2976         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2977                                  mode, NULL);
2978
2979 cmdline_parse_inst_t cmd_set_txsplit = {
2980         .f = cmd_set_txsplit_parsed,
2981         .data = NULL,
2982         .help_str = "set txsplit on|off|rand",
2983         .tokens = {
2984                 (void *)&cmd_set_txsplit_keyword,
2985                 (void *)&cmd_set_txsplit_name,
2986                 (void *)&cmd_set_txsplit_mode,
2987                 NULL,
2988         },
2989 };
2990
2991 /* *** CONFIG TX QUEUE FLAGS *** */
2992
2993 struct cmd_config_txqflags_result {
2994         cmdline_fixed_string_t port;
2995         cmdline_fixed_string_t config;
2996         cmdline_fixed_string_t all;
2997         cmdline_fixed_string_t what;
2998         int32_t hexvalue;
2999 };
3000
3001 static void cmd_config_txqflags_parsed(void *parsed_result,
3002                                 __attribute__((unused)) struct cmdline *cl,
3003                                 __attribute__((unused)) void *data)
3004 {
3005         struct cmd_config_txqflags_result *res = parsed_result;
3006
3007         if (!all_ports_stopped()) {
3008                 printf("Please stop all ports first\n");
3009                 return;
3010         }
3011
3012         if (strcmp(res->what, "txqflags")) {
3013                 printf("Unknown parameter\n");
3014                 return;
3015         }
3016
3017         if (res->hexvalue >= 0) {
3018                 txq_flags = res->hexvalue;
3019         } else {
3020                 printf("txqflags must be >= 0\n");
3021                 return;
3022         }
3023
3024         init_port_config();
3025
3026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3027 }
3028
3029 cmdline_parse_token_string_t cmd_config_txqflags_port =
3030         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3031                                  "port");
3032 cmdline_parse_token_string_t cmd_config_txqflags_config =
3033         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3034                                  "config");
3035 cmdline_parse_token_string_t cmd_config_txqflags_all =
3036         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3037                                  "all");
3038 cmdline_parse_token_string_t cmd_config_txqflags_what =
3039         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3040                                  "txqflags");
3041 cmdline_parse_token_num_t cmd_config_txqflags_value =
3042         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3043                                 hexvalue, INT32);
3044
3045 cmdline_parse_inst_t cmd_config_txqflags = {
3046         .f = cmd_config_txqflags_parsed,
3047         .data = NULL,
3048         .help_str = "port config all txqflags <value>",
3049         .tokens = {
3050                 (void *)&cmd_config_txqflags_port,
3051                 (void *)&cmd_config_txqflags_config,
3052                 (void *)&cmd_config_txqflags_all,
3053                 (void *)&cmd_config_txqflags_what,
3054                 (void *)&cmd_config_txqflags_value,
3055                 NULL,
3056         },
3057 };
3058
3059 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3060 struct cmd_rx_vlan_filter_all_result {
3061         cmdline_fixed_string_t rx_vlan;
3062         cmdline_fixed_string_t what;
3063         cmdline_fixed_string_t all;
3064         portid_t port_id;
3065 };
3066
3067 static void
3068 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3069                               __attribute__((unused)) struct cmdline *cl,
3070                               __attribute__((unused)) void *data)
3071 {
3072         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3073
3074         if (!strcmp(res->what, "add"))
3075                 rx_vlan_all_filter_set(res->port_id, 1);
3076         else
3077                 rx_vlan_all_filter_set(res->port_id, 0);
3078 }
3079
3080 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3081         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3082                                  rx_vlan, "rx_vlan");
3083 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3084         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3085                                  what, "add#rm");
3086 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3087         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3088                                  all, "all");
3089 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3090         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3091                               port_id, UINT16);
3092
3093 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3094         .f = cmd_rx_vlan_filter_all_parsed,
3095         .data = NULL,
3096         .help_str = "rx_vlan add|rm all <port_id>: "
3097                 "Add/Remove all identifiers to/from the set of VLAN "
3098                 "identifiers filtered by a port",
3099         .tokens = {
3100                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3101                 (void *)&cmd_rx_vlan_filter_all_what,
3102                 (void *)&cmd_rx_vlan_filter_all_all,
3103                 (void *)&cmd_rx_vlan_filter_all_portid,
3104                 NULL,
3105         },
3106 };
3107
3108 /* *** VLAN OFFLOAD SET ON A PORT *** */
3109 struct cmd_vlan_offload_result {
3110         cmdline_fixed_string_t vlan;
3111         cmdline_fixed_string_t set;
3112         cmdline_fixed_string_t vlan_type;
3113         cmdline_fixed_string_t what;
3114         cmdline_fixed_string_t on;
3115         cmdline_fixed_string_t port_id;
3116 };
3117
3118 static void
3119 cmd_vlan_offload_parsed(void *parsed_result,
3120                           __attribute__((unused)) struct cmdline *cl,
3121                           __attribute__((unused)) void *data)
3122 {
3123         int on;
3124         struct cmd_vlan_offload_result *res = parsed_result;
3125         char *str;
3126         int i, len = 0;
3127         portid_t port_id = 0;
3128         unsigned int tmp;
3129
3130         str = res->port_id;
3131         len = strnlen(str, STR_TOKEN_SIZE);
3132         i = 0;
3133         /* Get port_id first */
3134         while(i < len){
3135                 if(str[i] == ',')
3136                         break;
3137
3138                 i++;
3139         }
3140         str[i]='\0';
3141         tmp = strtoul(str, NULL, 0);
3142         /* If port_id greater that what portid_t can represent, return */
3143         if(tmp >= RTE_MAX_ETHPORTS)
3144                 return;
3145         port_id = (portid_t)tmp;
3146
3147         if (!strcmp(res->on, "on"))
3148                 on = 1;
3149         else
3150                 on = 0;
3151
3152         if (!strcmp(res->what, "strip"))
3153                 rx_vlan_strip_set(port_id,  on);
3154         else if(!strcmp(res->what, "stripq")){
3155                 uint16_t queue_id = 0;
3156
3157                 /* No queue_id, return */
3158                 if(i + 1 >= len) {
3159                         printf("must specify (port,queue_id)\n");
3160                         return;
3161                 }
3162                 tmp = strtoul(str + i + 1, NULL, 0);
3163                 /* If queue_id greater that what 16-bits can represent, return */
3164                 if(tmp > 0xffff)
3165                         return;
3166
3167                 queue_id = (uint16_t)tmp;
3168                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3169         }
3170         else if (!strcmp(res->what, "filter"))
3171                 rx_vlan_filter_set(port_id, on);
3172         else
3173                 vlan_extend_set(port_id, on);
3174
3175         return;
3176 }
3177
3178 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3179         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3180                                  vlan, "vlan");
3181 cmdline_parse_token_string_t cmd_vlan_offload_set =
3182         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3183                                  set, "set");
3184 cmdline_parse_token_string_t cmd_vlan_offload_what =
3185         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3186                                  what, "strip#filter#qinq#stripq");
3187 cmdline_parse_token_string_t cmd_vlan_offload_on =
3188         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3189                               on, "on#off");
3190 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3191         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3192                               port_id, NULL);
3193
3194 cmdline_parse_inst_t cmd_vlan_offload = {
3195         .f = cmd_vlan_offload_parsed,
3196         .data = NULL,
3197         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3198                 "<port_id[,queue_id]>: "
3199                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3200         .tokens = {
3201                 (void *)&cmd_vlan_offload_vlan,
3202                 (void *)&cmd_vlan_offload_set,
3203                 (void *)&cmd_vlan_offload_what,
3204                 (void *)&cmd_vlan_offload_on,
3205                 (void *)&cmd_vlan_offload_portid,
3206                 NULL,
3207         },
3208 };
3209
3210 /* *** VLAN TPID SET ON A PORT *** */
3211 struct cmd_vlan_tpid_result {
3212         cmdline_fixed_string_t vlan;
3213         cmdline_fixed_string_t set;
3214         cmdline_fixed_string_t vlan_type;
3215         cmdline_fixed_string_t what;
3216         uint16_t tp_id;
3217         portid_t port_id;
3218 };
3219
3220 static void
3221 cmd_vlan_tpid_parsed(void *parsed_result,
3222                           __attribute__((unused)) struct cmdline *cl,
3223                           __attribute__((unused)) void *data)
3224 {
3225         struct cmd_vlan_tpid_result *res = parsed_result;
3226         enum rte_vlan_type vlan_type;
3227
3228         if (!strcmp(res->vlan_type, "inner"))
3229                 vlan_type = ETH_VLAN_TYPE_INNER;
3230         else if (!strcmp(res->vlan_type, "outer"))
3231                 vlan_type = ETH_VLAN_TYPE_OUTER;
3232         else {
3233                 printf("Unknown vlan type\n");
3234                 return;
3235         }
3236         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3237 }
3238
3239 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3241                                  vlan, "vlan");
3242 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3243         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3244                                  set, "set");
3245 cmdline_parse_token_string_t cmd_vlan_type =
3246         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3247                                  vlan_type, "inner#outer");
3248 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3249         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3250                                  what, "tpid");
3251 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3252         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3253                               tp_id, UINT16);
3254 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3255         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3256                               port_id, UINT8);
3257
3258 cmdline_parse_inst_t cmd_vlan_tpid = {
3259         .f = cmd_vlan_tpid_parsed,
3260         .data = NULL,
3261         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3262                 "Set the VLAN Ether type",
3263         .tokens = {
3264                 (void *)&cmd_vlan_tpid_vlan,
3265                 (void *)&cmd_vlan_tpid_set,
3266                 (void *)&cmd_vlan_type,
3267                 (void *)&cmd_vlan_tpid_what,
3268                 (void *)&cmd_vlan_tpid_tpid,
3269                 (void *)&cmd_vlan_tpid_portid,
3270                 NULL,
3271         },
3272 };
3273
3274 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3275 struct cmd_rx_vlan_filter_result {
3276         cmdline_fixed_string_t rx_vlan;
3277         cmdline_fixed_string_t what;
3278         uint16_t vlan_id;
3279         portid_t port_id;
3280 };
3281
3282 static void
3283 cmd_rx_vlan_filter_parsed(void *parsed_result,
3284                           __attribute__((unused)) struct cmdline *cl,
3285                           __attribute__((unused)) void *data)
3286 {
3287         struct cmd_rx_vlan_filter_result *res = parsed_result;
3288
3289         if (!strcmp(res->what, "add"))
3290                 rx_vft_set(res->port_id, res->vlan_id, 1);
3291         else
3292                 rx_vft_set(res->port_id, res->vlan_id, 0);
3293 }
3294
3295 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3296         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3297                                  rx_vlan, "rx_vlan");
3298 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3299         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3300                                  what, "add#rm");
3301 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3302         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3303                               vlan_id, UINT16);
3304 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3305         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3306                               port_id, UINT16);
3307
3308 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3309         .f = cmd_rx_vlan_filter_parsed,
3310         .data = NULL,
3311         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3312                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3313                 "identifiers filtered by a port",
3314         .tokens = {
3315                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3316                 (void *)&cmd_rx_vlan_filter_what,
3317                 (void *)&cmd_rx_vlan_filter_vlanid,
3318                 (void *)&cmd_rx_vlan_filter_portid,
3319                 NULL,
3320         },
3321 };
3322
3323 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3324 struct cmd_tx_vlan_set_result {
3325         cmdline_fixed_string_t tx_vlan;
3326         cmdline_fixed_string_t set;
3327         portid_t port_id;
3328         uint16_t vlan_id;
3329 };
3330
3331 static void
3332 cmd_tx_vlan_set_parsed(void *parsed_result,
3333                        __attribute__((unused)) struct cmdline *cl,
3334                        __attribute__((unused)) void *data)
3335 {
3336         struct cmd_tx_vlan_set_result *res = parsed_result;
3337
3338         tx_vlan_set(res->port_id, res->vlan_id);
3339 }
3340
3341 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3342         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3343                                  tx_vlan, "tx_vlan");
3344 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3345         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3346                                  set, "set");
3347 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3348         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3349                               port_id, UINT16);
3350 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3351         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3352                               vlan_id, UINT16);
3353
3354 cmdline_parse_inst_t cmd_tx_vlan_set = {
3355         .f = cmd_tx_vlan_set_parsed,
3356         .data = NULL,
3357         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3358                 "Enable hardware insertion of a single VLAN header "
3359                 "with a given TAG Identifier in packets sent on a port",
3360         .tokens = {
3361                 (void *)&cmd_tx_vlan_set_tx_vlan,
3362                 (void *)&cmd_tx_vlan_set_set,
3363                 (void *)&cmd_tx_vlan_set_portid,
3364                 (void *)&cmd_tx_vlan_set_vlanid,
3365                 NULL,
3366         },
3367 };
3368
3369 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3370 struct cmd_tx_vlan_set_qinq_result {
3371         cmdline_fixed_string_t tx_vlan;
3372         cmdline_fixed_string_t set;
3373         portid_t port_id;
3374         uint16_t vlan_id;
3375         uint16_t vlan_id_outer;
3376 };
3377
3378 static void
3379 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3380                             __attribute__((unused)) struct cmdline *cl,
3381                             __attribute__((unused)) void *data)
3382 {
3383         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3384
3385         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3386 }
3387
3388 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3389         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3390                 tx_vlan, "tx_vlan");
3391 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3392         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3393                 set, "set");
3394 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3395         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3396                 port_id, UINT16);
3397 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3398         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3399                 vlan_id, UINT16);
3400 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3401         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3402                 vlan_id_outer, UINT16);
3403
3404 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3405         .f = cmd_tx_vlan_set_qinq_parsed,
3406         .data = NULL,
3407         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3408                 "Enable hardware insertion of double VLAN header "
3409                 "with given TAG Identifiers in packets sent on a port",
3410         .tokens = {
3411                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3412                 (void *)&cmd_tx_vlan_set_qinq_set,
3413                 (void *)&cmd_tx_vlan_set_qinq_portid,
3414                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3415                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3416                 NULL,
3417         },
3418 };
3419
3420 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3421 struct cmd_tx_vlan_set_pvid_result {
3422         cmdline_fixed_string_t tx_vlan;
3423         cmdline_fixed_string_t set;
3424         cmdline_fixed_string_t pvid;
3425         portid_t port_id;
3426         uint16_t vlan_id;
3427         cmdline_fixed_string_t mode;
3428 };
3429
3430 static void
3431 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3432                             __attribute__((unused)) struct cmdline *cl,
3433                             __attribute__((unused)) void *data)
3434 {
3435         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3436
3437         if (strcmp(res->mode, "on") == 0)
3438                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3439         else
3440                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3441 }
3442
3443 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3444         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3445                                  tx_vlan, "tx_vlan");
3446 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3447         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3448                                  set, "set");
3449 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3450         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3451                                  pvid, "pvid");
3452 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3453         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3454                              port_id, UINT16);
3455 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3456         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3457                               vlan_id, UINT16);
3458 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3460                                  mode, "on#off");
3461
3462 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3463         .f = cmd_tx_vlan_set_pvid_parsed,
3464         .data = NULL,
3465         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3466         .tokens = {
3467                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3468                 (void *)&cmd_tx_vlan_set_pvid_set,
3469                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3470                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3471                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3472                 (void *)&cmd_tx_vlan_set_pvid_mode,
3473                 NULL,
3474         },
3475 };
3476
3477 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3478 struct cmd_tx_vlan_reset_result {
3479         cmdline_fixed_string_t tx_vlan;
3480         cmdline_fixed_string_t reset;
3481         portid_t port_id;
3482 };
3483
3484 static void
3485 cmd_tx_vlan_reset_parsed(void *parsed_result,
3486                          __attribute__((unused)) struct cmdline *cl,
3487                          __attribute__((unused)) void *data)
3488 {
3489         struct cmd_tx_vlan_reset_result *res = parsed_result;
3490
3491         tx_vlan_reset(res->port_id);
3492 }
3493
3494 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3495         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3496                                  tx_vlan, "tx_vlan");
3497 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3498         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3499                                  reset, "reset");
3500 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3501         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3502                               port_id, UINT16);
3503
3504 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3505         .f = cmd_tx_vlan_reset_parsed,
3506         .data = NULL,
3507         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3508                 "VLAN header in packets sent on a port",
3509         .tokens = {
3510                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3511                 (void *)&cmd_tx_vlan_reset_reset,
3512                 (void *)&cmd_tx_vlan_reset_portid,
3513                 NULL,
3514         },
3515 };
3516
3517
3518 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3519 struct cmd_csum_result {
3520         cmdline_fixed_string_t csum;
3521         cmdline_fixed_string_t mode;
3522         cmdline_fixed_string_t proto;
3523         cmdline_fixed_string_t hwsw;
3524         portid_t port_id;
3525 };
3526
3527 static void
3528 csum_show(int port_id)
3529 {
3530         struct rte_eth_dev_info dev_info;
3531         uint16_t ol_flags;
3532
3533         ol_flags = ports[port_id].tx_ol_flags;
3534         printf("Parse tunnel is %s\n",
3535                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3536         printf("IP checksum offload is %s\n",
3537                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3538         printf("UDP checksum offload is %s\n",
3539                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3540         printf("TCP checksum offload is %s\n",
3541                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3542         printf("SCTP checksum offload is %s\n",
3543                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3544         printf("Outer-Ip checksum offload is %s\n",
3545                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3546
3547         /* display warnings if configuration is not supported by the NIC */
3548         rte_eth_dev_info_get(port_id, &dev_info);
3549         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3550                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3551                 printf("Warning: hardware IP checksum enabled but not "
3552                         "supported by port %d\n", port_id);
3553         }
3554         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3555                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3556                 printf("Warning: hardware UDP checksum enabled but not "
3557                         "supported by port %d\n", port_id);
3558         }
3559         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3560                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3561                 printf("Warning: hardware TCP checksum enabled but not "
3562                         "supported by port %d\n", port_id);
3563         }
3564         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3565                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3566                 printf("Warning: hardware SCTP checksum enabled but not "
3567                         "supported by port %d\n", port_id);
3568         }
3569         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3570                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3571                 printf("Warning: hardware outer IP checksum enabled but not "
3572                         "supported by port %d\n", port_id);
3573         }
3574 }
3575
3576 static void
3577 cmd_csum_parsed(void *parsed_result,
3578                        __attribute__((unused)) struct cmdline *cl,
3579                        __attribute__((unused)) void *data)
3580 {
3581         struct cmd_csum_result *res = parsed_result;
3582         int hw = 0;
3583         uint16_t mask = 0;
3584
3585         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3586                 printf("invalid port %d\n", res->port_id);
3587                 return;
3588         }
3589
3590         if (!strcmp(res->mode, "set")) {
3591
3592                 if (!strcmp(res->hwsw, "hw"))
3593                         hw = 1;
3594
3595                 if (!strcmp(res->proto, "ip")) {
3596                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3597                 } else if (!strcmp(res->proto, "udp")) {
3598                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3599                 } else if (!strcmp(res->proto, "tcp")) {
3600                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3601                 } else if (!strcmp(res->proto, "sctp")) {
3602                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3603                 } else if (!strcmp(res->proto, "outer-ip")) {
3604                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3605                 }
3606
3607                 if (hw)
3608                         ports[res->port_id].tx_ol_flags |= mask;
3609                 else
3610                         ports[res->port_id].tx_ol_flags &= (~mask);
3611         }
3612         csum_show(res->port_id);
3613 }
3614
3615 cmdline_parse_token_string_t cmd_csum_csum =
3616         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3617                                 csum, "csum");
3618 cmdline_parse_token_string_t cmd_csum_mode =
3619         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3620                                 mode, "set");
3621 cmdline_parse_token_string_t cmd_csum_proto =
3622         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3623                                 proto, "ip#tcp#udp#sctp#outer-ip");
3624 cmdline_parse_token_string_t cmd_csum_hwsw =
3625         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3626                                 hwsw, "hw#sw");
3627 cmdline_parse_token_num_t cmd_csum_portid =
3628         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3629                                 port_id, UINT16);
3630
3631 cmdline_parse_inst_t cmd_csum_set = {
3632         .f = cmd_csum_parsed,
3633         .data = NULL,
3634         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3635                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3636                 "using csum forward engine",
3637         .tokens = {
3638                 (void *)&cmd_csum_csum,
3639                 (void *)&cmd_csum_mode,
3640                 (void *)&cmd_csum_proto,
3641                 (void *)&cmd_csum_hwsw,
3642                 (void *)&cmd_csum_portid,
3643                 NULL,
3644         },
3645 };
3646
3647 cmdline_parse_token_string_t cmd_csum_mode_show =
3648         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3649                                 mode, "show");
3650
3651 cmdline_parse_inst_t cmd_csum_show = {
3652         .f = cmd_csum_parsed,
3653         .data = NULL,
3654         .help_str = "csum show <port_id>: Show checksum offload configuration",
3655         .tokens = {
3656                 (void *)&cmd_csum_csum,
3657                 (void *)&cmd_csum_mode_show,
3658                 (void *)&cmd_csum_portid,
3659                 NULL,
3660         },
3661 };
3662
3663 /* Enable/disable tunnel parsing */
3664 struct cmd_csum_tunnel_result {
3665         cmdline_fixed_string_t csum;
3666         cmdline_fixed_string_t parse;
3667         cmdline_fixed_string_t onoff;
3668         portid_t port_id;
3669 };
3670
3671 static void
3672 cmd_csum_tunnel_parsed(void *parsed_result,
3673                        __attribute__((unused)) struct cmdline *cl,
3674                        __attribute__((unused)) void *data)
3675 {
3676         struct cmd_csum_tunnel_result *res = parsed_result;
3677
3678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3679                 return;
3680
3681         if (!strcmp(res->onoff, "on"))
3682                 ports[res->port_id].tx_ol_flags |=
3683                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3684         else
3685                 ports[res->port_id].tx_ol_flags &=
3686                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3687
3688         csum_show(res->port_id);
3689 }
3690
3691 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3692         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3693                                 csum, "csum");
3694 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3695         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3696                                 parse, "parse_tunnel");
3697 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3698         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3699                                 onoff, "on#off");
3700 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3701         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3702                                 port_id, UINT16);
3703
3704 cmdline_parse_inst_t cmd_csum_tunnel = {
3705         .f = cmd_csum_tunnel_parsed,
3706         .data = NULL,
3707         .help_str = "csum parse_tunnel on|off <port_id>: "
3708                 "Enable/Disable parsing of tunnels for csum engine",
3709         .tokens = {
3710                 (void *)&cmd_csum_tunnel_csum,
3711                 (void *)&cmd_csum_tunnel_parse,
3712                 (void *)&cmd_csum_tunnel_onoff,
3713                 (void *)&cmd_csum_tunnel_portid,
3714                 NULL,
3715         },
3716 };
3717
3718 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3719 struct cmd_tso_set_result {
3720         cmdline_fixed_string_t tso;
3721         cmdline_fixed_string_t mode;
3722         uint16_t tso_segsz;
3723         portid_t port_id;
3724 };
3725
3726 static void
3727 cmd_tso_set_parsed(void *parsed_result,
3728                        __attribute__((unused)) struct cmdline *cl,
3729                        __attribute__((unused)) void *data)
3730 {
3731         struct cmd_tso_set_result *res = parsed_result;
3732         struct rte_eth_dev_info dev_info;
3733
3734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3735                 return;
3736
3737         if (!strcmp(res->mode, "set"))
3738                 ports[res->port_id].tso_segsz = res->tso_segsz;
3739
3740         if (ports[res->port_id].tso_segsz == 0)
3741                 printf("TSO for non-tunneled packets is disabled\n");
3742         else
3743                 printf("TSO segment size for non-tunneled packets is %d\n",
3744                         ports[res->port_id].tso_segsz);
3745
3746         /* display warnings if configuration is not supported by the NIC */
3747         rte_eth_dev_info_get(res->port_id, &dev_info);
3748         if ((ports[res->port_id].tso_segsz != 0) &&
3749                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3750                 printf("Warning: TSO enabled but not "
3751                         "supported by port %d\n", res->port_id);
3752         }
3753 }
3754
3755 cmdline_parse_token_string_t cmd_tso_set_tso =
3756         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3757                                 tso, "tso");
3758 cmdline_parse_token_string_t cmd_tso_set_mode =
3759         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3760                                 mode, "set");
3761 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3762         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3763                                 tso_segsz, UINT16);
3764 cmdline_parse_token_num_t cmd_tso_set_portid =
3765         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3766                                 port_id, UINT16);
3767
3768 cmdline_parse_inst_t cmd_tso_set = {
3769         .f = cmd_tso_set_parsed,
3770         .data = NULL,
3771         .help_str = "tso set <tso_segsz> <port_id>: "
3772                 "Set TSO segment size of non-tunneled packets for csum engine "
3773                 "(0 to disable)",
3774         .tokens = {
3775                 (void *)&cmd_tso_set_tso,
3776                 (void *)&cmd_tso_set_mode,
3777                 (void *)&cmd_tso_set_tso_segsz,
3778                 (void *)&cmd_tso_set_portid,
3779                 NULL,
3780         },
3781 };
3782
3783 cmdline_parse_token_string_t cmd_tso_show_mode =
3784         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3785                                 mode, "show");
3786
3787
3788 cmdline_parse_inst_t cmd_tso_show = {
3789         .f = cmd_tso_set_parsed,
3790         .data = NULL,
3791         .help_str = "tso show <port_id>: "
3792                 "Show TSO segment size of non-tunneled packets for csum engine",
3793         .tokens = {
3794                 (void *)&cmd_tso_set_tso,
3795                 (void *)&cmd_tso_show_mode,
3796                 (void *)&cmd_tso_set_portid,
3797                 NULL,
3798         },
3799 };
3800
3801 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3802 struct cmd_tunnel_tso_set_result {
3803         cmdline_fixed_string_t tso;
3804         cmdline_fixed_string_t mode;
3805         uint16_t tso_segsz;
3806         portid_t port_id;
3807 };
3808
3809 static void
3810 check_tunnel_tso_nic_support(portid_t port_id)
3811 {
3812         struct rte_eth_dev_info dev_info;
3813
3814         rte_eth_dev_info_get(port_id, &dev_info);
3815         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3816                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3817                        "supported by port %d\n", port_id);
3818         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3819                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3820                         "supported by port %d\n", port_id);
3821         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3822                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3823                        "supported by port %d\n", port_id);
3824         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3825                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3826                        "supported by port %d\n", port_id);
3827 }
3828
3829 static void
3830 cmd_tunnel_tso_set_parsed(void *parsed_result,
3831                           __attribute__((unused)) struct cmdline *cl,
3832                           __attribute__((unused)) void *data)
3833 {
3834         struct cmd_tunnel_tso_set_result *res = parsed_result;
3835
3836         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3837                 return;
3838
3839         if (!strcmp(res->mode, "set"))
3840                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3841
3842         if (ports[res->port_id].tunnel_tso_segsz == 0)
3843                 printf("TSO for tunneled packets is disabled\n");
3844         else {
3845                 printf("TSO segment size for tunneled packets is %d\n",
3846                         ports[res->port_id].tunnel_tso_segsz);
3847
3848                 /* Below conditions are needed to make it work:
3849                  * (1) tunnel TSO is supported by the NIC;
3850                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3851                  * are recognized;
3852                  * (3) for tunneled pkts with outer L3 of IPv4,
3853                  * "csum set outer-ip" must be set to hw, because after tso,
3854                  * total_len of outer IP header is changed, and the checksum
3855                  * of outer IP header calculated by sw should be wrong; that
3856                  * is not necessary for IPv6 tunneled pkts because there's no
3857                  * checksum in IP header anymore.
3858                  */
3859                 check_tunnel_tso_nic_support(res->port_id);
3860
3861                 if (!(ports[res->port_id].tx_ol_flags &
3862                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3863                         printf("Warning: csum parse_tunnel must be set "
3864                                 "so that tunneled packets are recognized\n");
3865                 if (!(ports[res->port_id].tx_ol_flags &
3866                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3867                         printf("Warning: csum set outer-ip must be set to hw "
3868                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3869         }
3870 }
3871
3872 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3873         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3874                                 tso, "tunnel_tso");
3875 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3876         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3877                                 mode, "set");
3878 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3879         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3880                                 tso_segsz, UINT16);
3881 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3882         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3883                                 port_id, UINT16);
3884
3885 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3886         .f = cmd_tunnel_tso_set_parsed,
3887         .data = NULL,
3888         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3889                 "Set TSO segment size of tunneled packets for csum engine "
3890                 "(0 to disable)",
3891         .tokens = {
3892                 (void *)&cmd_tunnel_tso_set_tso,
3893                 (void *)&cmd_tunnel_tso_set_mode,
3894                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3895                 (void *)&cmd_tunnel_tso_set_portid,
3896                 NULL,
3897         },
3898 };
3899
3900 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3901         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3902                                 mode, "show");
3903
3904
3905 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3906         .f = cmd_tunnel_tso_set_parsed,
3907         .data = NULL,
3908         .help_str = "tunnel_tso show <port_id> "
3909                 "Show TSO segment size of tunneled packets for csum engine",
3910         .tokens = {
3911                 (void *)&cmd_tunnel_tso_set_tso,
3912                 (void *)&cmd_tunnel_tso_show_mode,
3913                 (void *)&cmd_tunnel_tso_set_portid,
3914                 NULL,
3915         },
3916 };
3917
3918 /* *** SET GRO FOR A PORT *** */
3919 struct cmd_gro_enable_result {
3920         cmdline_fixed_string_t cmd_set;
3921         cmdline_fixed_string_t cmd_port;
3922         cmdline_fixed_string_t cmd_keyword;
3923         cmdline_fixed_string_t cmd_onoff;
3924         portid_t cmd_pid;
3925 };
3926
3927 static void
3928 cmd_gro_enable_parsed(void *parsed_result,
3929                 __attribute__((unused)) struct cmdline *cl,
3930                 __attribute__((unused)) void *data)
3931 {
3932         struct cmd_gro_enable_result *res;
3933
3934         res = parsed_result;
3935         if (!strcmp(res->cmd_keyword, "gro"))
3936                 setup_gro(res->cmd_onoff, res->cmd_pid);
3937 }
3938
3939 cmdline_parse_token_string_t cmd_gro_enable_set =
3940         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3941                         cmd_set, "set");
3942 cmdline_parse_token_string_t cmd_gro_enable_port =
3943         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3944                         cmd_keyword, "port");
3945 cmdline_parse_token_num_t cmd_gro_enable_pid =
3946         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3947                         cmd_pid, UINT16);
3948 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3949         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3950                         cmd_keyword, "gro");
3951 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3952         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3953                         cmd_onoff, "on#off");
3954
3955 cmdline_parse_inst_t cmd_gro_enable = {
3956         .f = cmd_gro_enable_parsed,
3957         .data = NULL,
3958         .help_str = "set port <port_id> gro on|off",
3959         .tokens = {
3960                 (void *)&cmd_gro_enable_set,
3961                 (void *)&cmd_gro_enable_port,
3962                 (void *)&cmd_gro_enable_pid,
3963                 (void *)&cmd_gro_enable_keyword,
3964                 (void *)&cmd_gro_enable_onoff,
3965                 NULL,
3966         },
3967 };
3968
3969 /* *** DISPLAY GRO CONFIGURATION *** */
3970 struct cmd_gro_show_result {
3971         cmdline_fixed_string_t cmd_show;
3972         cmdline_fixed_string_t cmd_port;
3973         cmdline_fixed_string_t cmd_keyword;
3974         portid_t cmd_pid;
3975 };
3976
3977 static void
3978 cmd_gro_show_parsed(void *parsed_result,
3979                 __attribute__((unused)) struct cmdline *cl,
3980                 __attribute__((unused)) void *data)
3981 {
3982         struct cmd_gro_show_result *res;
3983
3984         res = parsed_result;
3985         if (!strcmp(res->cmd_keyword, "gro"))
3986                 show_gro(res->cmd_pid);
3987 }
3988
3989 cmdline_parse_token_string_t cmd_gro_show_show =
3990         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3991                         cmd_show, "show");
3992 cmdline_parse_token_string_t cmd_gro_show_port =
3993         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3994                         cmd_port, "port");
3995 cmdline_parse_token_num_t cmd_gro_show_pid =
3996         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3997                         cmd_pid, UINT16);
3998 cmdline_parse_token_string_t cmd_gro_show_keyword =
3999         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4000                         cmd_keyword, "gro");
4001
4002 cmdline_parse_inst_t cmd_gro_show = {
4003         .f = cmd_gro_show_parsed,
4004         .data = NULL,
4005         .help_str = "show port <port_id> gro",
4006         .tokens = {
4007                 (void *)&cmd_gro_show_show,
4008                 (void *)&cmd_gro_show_port,
4009                 (void *)&cmd_gro_show_pid,
4010                 (void *)&cmd_gro_show_keyword,
4011                 NULL,
4012         },
4013 };
4014
4015 /* *** SET FLUSH CYCLES FOR GRO *** */
4016 struct cmd_gro_flush_result {
4017         cmdline_fixed_string_t cmd_set;
4018         cmdline_fixed_string_t cmd_keyword;
4019         cmdline_fixed_string_t cmd_flush;
4020         uint8_t cmd_cycles;
4021 };
4022
4023 static void
4024 cmd_gro_flush_parsed(void *parsed_result,
4025                 __attribute__((unused)) struct cmdline *cl,
4026                 __attribute__((unused)) void *data)
4027 {
4028         struct cmd_gro_flush_result *res;
4029
4030         res = parsed_result;
4031         if ((!strcmp(res->cmd_keyword, "gro")) &&
4032                         (!strcmp(res->cmd_flush, "flush")))
4033                 setup_gro_flush_cycles(res->cmd_cycles);
4034 }
4035
4036 cmdline_parse_token_string_t cmd_gro_flush_set =
4037         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4038                         cmd_set, "set");
4039 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4040         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4041                         cmd_keyword, "gro");
4042 cmdline_parse_token_string_t cmd_gro_flush_flush =
4043         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4044                         cmd_flush, "flush");
4045 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4046         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4047                         cmd_cycles, UINT8);
4048
4049 cmdline_parse_inst_t cmd_gro_flush = {
4050         .f = cmd_gro_flush_parsed,
4051         .data = NULL,
4052         .help_str = "set gro flush <cycles>",
4053         .tokens = {
4054                 (void *)&cmd_gro_flush_set,
4055                 (void *)&cmd_gro_flush_keyword,
4056                 (void *)&cmd_gro_flush_flush,
4057                 (void *)&cmd_gro_flush_cycles,
4058                 NULL,
4059         },
4060 };
4061
4062 /* *** ENABLE/DISABLE GSO *** */
4063 struct cmd_gso_enable_result {
4064         cmdline_fixed_string_t cmd_set;
4065         cmdline_fixed_string_t cmd_port;
4066         cmdline_fixed_string_t cmd_keyword;
4067         cmdline_fixed_string_t cmd_mode;
4068         portid_t cmd_pid;
4069 };
4070
4071 static void
4072 cmd_gso_enable_parsed(void *parsed_result,
4073                 __attribute__((unused)) struct cmdline *cl,
4074                 __attribute__((unused)) void *data)
4075 {
4076         struct cmd_gso_enable_result *res;
4077
4078         res = parsed_result;
4079         if (!strcmp(res->cmd_keyword, "gso"))
4080                 setup_gso(res->cmd_mode, res->cmd_pid);
4081 }
4082
4083 cmdline_parse_token_string_t cmd_gso_enable_set =
4084         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4085                         cmd_set, "set");
4086 cmdline_parse_token_string_t cmd_gso_enable_port =
4087         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4088                         cmd_port, "port");
4089 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4090         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4091                         cmd_keyword, "gso");
4092 cmdline_parse_token_string_t cmd_gso_enable_mode =
4093         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4094                         cmd_mode, "on#off");
4095 cmdline_parse_token_num_t cmd_gso_enable_pid =
4096         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4097                         cmd_pid, UINT16);
4098
4099 cmdline_parse_inst_t cmd_gso_enable = {
4100         .f = cmd_gso_enable_parsed,
4101         .data = NULL,
4102         .help_str = "set port <port_id> gso on|off",
4103         .tokens = {
4104                 (void *)&cmd_gso_enable_set,
4105                 (void *)&cmd_gso_enable_port,
4106                 (void *)&cmd_gso_enable_pid,
4107                 (void *)&cmd_gso_enable_keyword,
4108                 (void *)&cmd_gso_enable_mode,
4109                 NULL,
4110         },
4111 };
4112
4113 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4114 struct cmd_gso_size_result {
4115         cmdline_fixed_string_t cmd_set;
4116         cmdline_fixed_string_t cmd_keyword;
4117         cmdline_fixed_string_t cmd_segsz;
4118         uint16_t cmd_size;
4119 };
4120
4121 static void
4122 cmd_gso_size_parsed(void *parsed_result,
4123                        __attribute__((unused)) struct cmdline *cl,
4124                        __attribute__((unused)) void *data)
4125 {
4126         struct cmd_gso_size_result *res = parsed_result;
4127
4128         if (test_done == 0) {
4129                 printf("Before setting GSO segsz, please first"
4130                                 " stop fowarding\n");
4131                 return;
4132         }
4133
4134         if (!strcmp(res->cmd_keyword, "gso") &&
4135                         !strcmp(res->cmd_segsz, "segsz")) {
4136                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4137                         printf("gso_size should be larger than %zu."
4138                                         " Please input a legal value\n",
4139                                         RTE_GSO_SEG_SIZE_MIN);
4140                 else
4141                         gso_max_segment_size = res->cmd_size;
4142         }
4143 }
4144
4145 cmdline_parse_token_string_t cmd_gso_size_set =
4146         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4147                                 cmd_set, "set");
4148 cmdline_parse_token_string_t cmd_gso_size_keyword =
4149         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4150                                 cmd_keyword, "gso");
4151 cmdline_parse_token_string_t cmd_gso_size_segsz =
4152         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4153                                 cmd_segsz, "segsz");
4154 cmdline_parse_token_num_t cmd_gso_size_size =
4155         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4156                                 cmd_size, UINT16);
4157
4158 cmdline_parse_inst_t cmd_gso_size = {
4159         .f = cmd_gso_size_parsed,
4160         .data = NULL,
4161         .help_str = "set gso segsz <length>",
4162         .tokens = {
4163                 (void *)&cmd_gso_size_set,
4164                 (void *)&cmd_gso_size_keyword,
4165                 (void *)&cmd_gso_size_segsz,
4166                 (void *)&cmd_gso_size_size,
4167                 NULL,
4168         },
4169 };
4170
4171 /* *** SHOW GSO CONFIGURATION *** */
4172 struct cmd_gso_show_result {
4173         cmdline_fixed_string_t cmd_show;
4174         cmdline_fixed_string_t cmd_port;
4175         cmdline_fixed_string_t cmd_keyword;
4176         portid_t cmd_pid;
4177 };
4178
4179 static void
4180 cmd_gso_show_parsed(void *parsed_result,
4181                        __attribute__((unused)) struct cmdline *cl,
4182                        __attribute__((unused)) void *data)
4183 {
4184         struct cmd_gso_show_result *res = parsed_result;
4185
4186         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4187                 printf("invalid port id %u\n", res->cmd_pid);
4188                 return;
4189         }
4190         if (!strcmp(res->cmd_keyword, "gso")) {
4191                 if (gso_ports[res->cmd_pid].enable) {
4192                         printf("Max GSO'd packet size: %uB\n"
4193                                         "Supported GSO types: TCP/IPv4, "
4194                                         "VxLAN with inner TCP/IPv4 packet, "
4195                                         "GRE with inner TCP/IPv4  packet\n",
4196                                         gso_max_segment_size);
4197                 } else
4198                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4199         }
4200 }
4201
4202 cmdline_parse_token_string_t cmd_gso_show_show =
4203 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4204                 cmd_show, "show");
4205 cmdline_parse_token_string_t cmd_gso_show_port =
4206 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4207                 cmd_port, "port");
4208 cmdline_parse_token_string_t cmd_gso_show_keyword =
4209         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4210                                 cmd_keyword, "gso");
4211 cmdline_parse_token_num_t cmd_gso_show_pid =
4212         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4213                                 cmd_pid, UINT16);
4214
4215 cmdline_parse_inst_t cmd_gso_show = {
4216         .f = cmd_gso_show_parsed,
4217         .data = NULL,
4218         .help_str = "show port <port_id> gso",
4219         .tokens = {
4220                 (void *)&cmd_gso_show_show,
4221                 (void *)&cmd_gso_show_port,
4222                 (void *)&cmd_gso_show_pid,
4223                 (void *)&cmd_gso_show_keyword,
4224                 NULL,
4225         },
4226 };
4227
4228 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4229 struct cmd_set_flush_rx {
4230         cmdline_fixed_string_t set;
4231         cmdline_fixed_string_t flush_rx;
4232         cmdline_fixed_string_t mode;
4233 };
4234
4235 static void
4236 cmd_set_flush_rx_parsed(void *parsed_result,
4237                 __attribute__((unused)) struct cmdline *cl,
4238                 __attribute__((unused)) void *data)
4239 {
4240         struct cmd_set_flush_rx *res = parsed_result;
4241         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4242 }
4243
4244 cmdline_parse_token_string_t cmd_setflushrx_set =
4245         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4246                         set, "set");
4247 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4248         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4249                         flush_rx, "flush_rx");
4250 cmdline_parse_token_string_t cmd_setflushrx_mode =
4251         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4252                         mode, "on#off");
4253
4254
4255 cmdline_parse_inst_t cmd_set_flush_rx = {
4256         .f = cmd_set_flush_rx_parsed,
4257         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4258         .data = NULL,
4259         .tokens = {
4260                 (void *)&cmd_setflushrx_set,
4261                 (void *)&cmd_setflushrx_flush_rx,
4262                 (void *)&cmd_setflushrx_mode,
4263                 NULL,
4264         },
4265 };
4266
4267 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4268 struct cmd_set_link_check {
4269         cmdline_fixed_string_t set;
4270         cmdline_fixed_string_t link_check;
4271         cmdline_fixed_string_t mode;
4272 };
4273
4274 static void
4275 cmd_set_link_check_parsed(void *parsed_result,
4276                 __attribute__((unused)) struct cmdline *cl,
4277                 __attribute__((unused)) void *data)
4278 {
4279         struct cmd_set_link_check *res = parsed_result;
4280         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4281 }
4282
4283 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4284         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4285                         set, "set");
4286 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4287         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4288                         link_check, "link_check");
4289 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4290         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4291                         mode, "on#off");
4292
4293
4294 cmdline_parse_inst_t cmd_set_link_check = {
4295         .f = cmd_set_link_check_parsed,
4296         .help_str = "set link_check on|off: Enable/Disable link status check "
4297                     "when starting/stopping a port",
4298         .data = NULL,
4299         .tokens = {
4300                 (void *)&cmd_setlinkcheck_set,
4301                 (void *)&cmd_setlinkcheck_link_check,
4302                 (void *)&cmd_setlinkcheck_mode,
4303                 NULL,
4304         },
4305 };
4306
4307 /* *** SET NIC BYPASS MODE *** */
4308 struct cmd_set_bypass_mode_result {
4309         cmdline_fixed_string_t set;
4310         cmdline_fixed_string_t bypass;
4311         cmdline_fixed_string_t mode;
4312         cmdline_fixed_string_t value;
4313         portid_t port_id;
4314 };
4315
4316 static void
4317 cmd_set_bypass_mode_parsed(void *parsed_result,
4318                 __attribute__((unused)) struct cmdline *cl,
4319                 __attribute__((unused)) void *data)
4320 {
4321         struct cmd_set_bypass_mode_result *res = parsed_result;
4322         portid_t port_id = res->port_id;
4323         int32_t rc = -EINVAL;
4324
4325 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4326         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4327
4328         if (!strcmp(res->value, "bypass"))
4329                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4330         else if (!strcmp(res->value, "isolate"))
4331                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4332         else
4333                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4334
4335         /* Set the bypass mode for the relevant port. */
4336         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4337 #endif
4338         if (rc != 0)
4339                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4340 }
4341
4342 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4343         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4344                         set, "set");
4345 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4346         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4347                         bypass, "bypass");
4348 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4349         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4350                         mode, "mode");
4351 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4352         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4353                         value, "normal#bypass#isolate");
4354 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4355         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4356                                 port_id, UINT16);
4357
4358 cmdline_parse_inst_t cmd_set_bypass_mode = {
4359         .f = cmd_set_bypass_mode_parsed,
4360         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4361                     "Set the NIC bypass mode for port_id",
4362         .data = NULL,
4363         .tokens = {
4364                 (void *)&cmd_setbypass_mode_set,
4365                 (void *)&cmd_setbypass_mode_bypass,
4366                 (void *)&cmd_setbypass_mode_mode,
4367                 (void *)&cmd_setbypass_mode_value,
4368                 (void *)&cmd_setbypass_mode_port,
4369                 NULL,
4370         },
4371 };
4372
4373 /* *** SET NIC BYPASS EVENT *** */
4374 struct cmd_set_bypass_event_result {
4375         cmdline_fixed_string_t set;
4376         cmdline_fixed_string_t bypass;
4377         cmdline_fixed_string_t event;
4378         cmdline_fixed_string_t event_value;
4379         cmdline_fixed_string_t mode;
4380         cmdline_fixed_string_t mode_value;
4381         portid_t port_id;
4382 };
4383
4384 static void
4385 cmd_set_bypass_event_parsed(void *parsed_result,
4386                 __attribute__((unused)) struct cmdline *cl,
4387                 __attribute__((unused)) void *data)
4388 {
4389         int32_t rc = -EINVAL;
4390         struct cmd_set_bypass_event_result *res = parsed_result;
4391         portid_t port_id = res->port_id;
4392
4393 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4394         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4395         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4396
4397         if (!strcmp(res->event_value, "timeout"))
4398                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4399         else if (!strcmp(res->event_value, "os_on"))
4400                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4401         else if (!strcmp(res->event_value, "os_off"))
4402                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4403         else if (!strcmp(res->event_value, "power_on"))
4404                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4405         else if (!strcmp(res->event_value, "power_off"))
4406                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4407         else
4408                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4409
4410         if (!strcmp(res->mode_value, "bypass"))
4411                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4412         else if (!strcmp(res->mode_value, "isolate"))
4413                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4414         else
4415                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4416
4417         /* Set the watchdog timeout. */
4418         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4419
4420                 rc = -EINVAL;
4421                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4422                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4423                                                            bypass_timeout);
4424                 }
4425                 if (rc != 0) {
4426                         printf("Failed to set timeout value %u "
4427                         "for port %d, errto code: %d.\n",
4428                         bypass_timeout, port_id, rc);
4429                 }
4430         }
4431
4432         /* Set the bypass event to transition to bypass mode. */
4433         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4434                                               bypass_mode);
4435 #endif
4436
4437         if (rc != 0)
4438                 printf("\t Failed to set bypass event for port = %d.\n",
4439                        port_id);
4440 }
4441
4442 cmdline_parse_token_string_t cmd_setbypass_event_set =
4443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4444                         set, "set");
4445 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4447                         bypass, "bypass");
4448 cmdline_parse_token_string_t cmd_setbypass_event_event =
4449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4450                         event, "event");
4451 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4452         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4453                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4454 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4455         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4456                         mode, "mode");
4457 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4458         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4459                         mode_value, "normal#bypass#isolate");
4460 cmdline_parse_token_num_t cmd_setbypass_event_port =
4461         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4462                                 port_id, UINT16);
4463
4464 cmdline_parse_inst_t cmd_set_bypass_event = {
4465         .f = cmd_set_bypass_event_parsed,
4466         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4467                 "power_off mode normal|bypass|isolate <port_id>: "
4468                 "Set the NIC bypass event mode for port_id",
4469         .data = NULL,
4470         .tokens = {
4471                 (void *)&cmd_setbypass_event_set,
4472                 (void *)&cmd_setbypass_event_bypass,
4473                 (void *)&cmd_setbypass_event_event,
4474                 (void *)&cmd_setbypass_event_event_value,
4475                 (void *)&cmd_setbypass_event_mode,
4476                 (void *)&cmd_setbypass_event_mode_value,
4477                 (void *)&cmd_setbypass_event_port,
4478                 NULL,
4479         },
4480 };
4481
4482
4483 /* *** SET NIC BYPASS TIMEOUT *** */
4484 struct cmd_set_bypass_timeout_result {
4485         cmdline_fixed_string_t set;
4486         cmdline_fixed_string_t bypass;
4487         cmdline_fixed_string_t timeout;
4488         cmdline_fixed_string_t value;
4489 };
4490
4491 static void
4492 cmd_set_bypass_timeout_parsed(void *parsed_result,
4493                 __attribute__((unused)) struct cmdline *cl,
4494                 __attribute__((unused)) void *data)
4495 {
4496         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4497
4498 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4499         if (!strcmp(res->value, "1.5"))
4500                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4501         else if (!strcmp(res->value, "2"))
4502                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4503         else if (!strcmp(res->value, "3"))
4504                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4505         else if (!strcmp(res->value, "4"))
4506                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4507         else if (!strcmp(res->value, "8"))
4508                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4509         else if (!strcmp(res->value, "16"))
4510                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4511         else if (!strcmp(res->value, "32"))
4512                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4513         else
4514                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4515 #endif
4516 }
4517
4518 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4519         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4520                         set, "set");
4521 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4522         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4523                         bypass, "bypass");
4524 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4525         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4526                         timeout, "timeout");
4527 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4528         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4529                         value, "0#1.5#2#3#4#8#16#32");
4530
4531 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4532         .f = cmd_set_bypass_timeout_parsed,
4533         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4534                 "Set the NIC bypass watchdog timeout in seconds",
4535         .data = NULL,
4536         .tokens = {
4537                 (void *)&cmd_setbypass_timeout_set,
4538                 (void *)&cmd_setbypass_timeout_bypass,
4539                 (void *)&cmd_setbypass_timeout_timeout,
4540                 (void *)&cmd_setbypass_timeout_value,
4541                 NULL,
4542         },
4543 };
4544
4545 /* *** SHOW NIC BYPASS MODE *** */
4546 struct cmd_show_bypass_config_result {
4547         cmdline_fixed_string_t show;
4548         cmdline_fixed_string_t bypass;
4549         cmdline_fixed_string_t config;
4550         portid_t port_id;
4551 };
4552
4553 static void
4554 cmd_show_bypass_config_parsed(void *parsed_result,
4555                 __attribute__((unused)) struct cmdline *cl,
4556                 __attribute__((unused)) void *data)
4557 {
4558         struct cmd_show_bypass_config_result *res = parsed_result;
4559         portid_t port_id = res->port_id;
4560         int rc = -EINVAL;
4561 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4562         uint32_t event_mode;
4563         uint32_t bypass_mode;
4564         uint32_t timeout = bypass_timeout;
4565         int i;
4566
4567         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4568                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4569         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4570                 {"UNKNOWN", "normal", "bypass", "isolate"};
4571         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4572                 "NONE",
4573                 "OS/board on",
4574                 "power supply on",
4575                 "OS/board off",
4576                 "power supply off",
4577                 "timeout"};
4578         int num_events = (sizeof events) / (sizeof events[0]);
4579
4580         /* Display the bypass mode.*/
4581         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4582                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4583                 return;
4584         }
4585         else {
4586                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4587                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4588
4589                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4590         }
4591
4592         /* Display the bypass timeout.*/
4593         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4594                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4595
4596         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4597
4598         /* Display the bypass events and associated modes. */
4599         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4600
4601                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4602                         printf("\tFailed to get bypass mode for event = %s\n",
4603                                 events[i]);
4604                 } else {
4605                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4606                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4607
4608                         printf("\tbypass event: %-16s = %s\n", events[i],
4609                                 modes[event_mode]);
4610                 }
4611         }
4612 #endif
4613         if (rc != 0)
4614                 printf("\tFailed to get bypass configuration for port = %d\n",
4615                        port_id);
4616 }
4617
4618 cmdline_parse_token_string_t cmd_showbypass_config_show =
4619         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4620                         show, "show");
4621 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4622         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4623                         bypass, "bypass");
4624 cmdline_parse_token_string_t cmd_showbypass_config_config =
4625         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4626                         config, "config");
4627 cmdline_parse_token_num_t cmd_showbypass_config_port =
4628         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4629                                 port_id, UINT16);
4630
4631 cmdline_parse_inst_t cmd_show_bypass_config = {
4632         .f = cmd_show_bypass_config_parsed,
4633         .help_str = "show bypass config <port_id>: "
4634                     "Show the NIC bypass config for port_id",
4635         .data = NULL,
4636         .tokens = {
4637                 (void *)&cmd_showbypass_config_show,
4638                 (void *)&cmd_showbypass_config_bypass,
4639                 (void *)&cmd_showbypass_config_config,
4640                 (void *)&cmd_showbypass_config_port,
4641                 NULL,
4642         },
4643 };
4644
4645 #ifdef RTE_LIBRTE_PMD_BOND
4646 /* *** SET BONDING MODE *** */
4647 struct cmd_set_bonding_mode_result {
4648         cmdline_fixed_string_t set;
4649         cmdline_fixed_string_t bonding;
4650         cmdline_fixed_string_t mode;
4651         uint8_t value;
4652         portid_t port_id;
4653 };
4654
4655 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4656                 __attribute__((unused))  struct cmdline *cl,
4657                 __attribute__((unused)) void *data)
4658 {
4659         struct cmd_set_bonding_mode_result *res = parsed_result;
4660         portid_t port_id = res->port_id;
4661
4662         /* Set the bonding mode for the relevant port. */
4663         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4664                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4665 }
4666
4667 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4668 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4669                 set, "set");
4670 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4671 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4672                 bonding, "bonding");
4673 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4674 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4675                 mode, "mode");
4676 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4677 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4678                 value, UINT8);
4679 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4680 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4681                 port_id, UINT16);
4682
4683 cmdline_parse_inst_t cmd_set_bonding_mode = {
4684                 .f = cmd_set_bonding_mode_parsed,
4685                 .help_str = "set bonding mode <mode_value> <port_id>: "
4686                         "Set the bonding mode for port_id",
4687                 .data = NULL,
4688                 .tokens = {
4689                                 (void *) &cmd_setbonding_mode_set,
4690                                 (void *) &cmd_setbonding_mode_bonding,
4691                                 (void *) &cmd_setbonding_mode_mode,
4692                                 (void *) &cmd_setbonding_mode_value,
4693                                 (void *) &cmd_setbonding_mode_port,
4694                                 NULL
4695                 }
4696 };
4697
4698 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4699 struct cmd_set_bonding_lacp_dedicated_queues_result {
4700         cmdline_fixed_string_t set;
4701         cmdline_fixed_string_t bonding;
4702         cmdline_fixed_string_t lacp;
4703         cmdline_fixed_string_t dedicated_queues;
4704         portid_t port_id;
4705         cmdline_fixed_string_t mode;
4706 };
4707
4708 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4709                 __attribute__((unused))  struct cmdline *cl,
4710                 __attribute__((unused)) void *data)
4711 {
4712         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4713         portid_t port_id = res->port_id;
4714         struct rte_port *port;
4715
4716         port = &ports[port_id];
4717
4718         /** Check if the port is not started **/
4719         if (port->port_status != RTE_PORT_STOPPED) {
4720                 printf("Please stop port %d first\n", port_id);
4721                 return;
4722         }
4723
4724         if (!strcmp(res->mode, "enable")) {
4725                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4726                         printf("Dedicate queues for LACP control packets"
4727                                         " enabled\n");
4728                 else
4729                         printf("Enabling dedicate queues for LACP control "
4730                                         "packets on port %d failed\n", port_id);
4731         } else if (!strcmp(res->mode, "disable")) {
4732                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4733                         printf("Dedicated queues for LACP control packets "
4734                                         "disabled\n");
4735                 else
4736                         printf("Disabling dedicated queues for LACP control "
4737                                         "traffic on port %d failed\n", port_id);
4738         }
4739 }
4740
4741 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4742 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4743                 set, "set");
4744 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4745 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4746                 bonding, "bonding");
4747 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4748 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4749                 lacp, "lacp");
4750 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4751 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4752                 dedicated_queues, "dedicated_queues");
4753 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4754 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4755                 port_id, UINT16);
4756 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4757 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4758                 mode, "enable#disable");
4759
4760 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4761                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4762                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4763                         "enable|disable: "
4764                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4765                 .data = NULL,
4766                 .tokens = {
4767                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4768                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4769                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4770                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4771                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4772                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4773                         NULL
4774                 }
4775 };
4776
4777 /* *** SET BALANCE XMIT POLICY *** */
4778 struct cmd_set_bonding_balance_xmit_policy_result {
4779         cmdline_fixed_string_t set;
4780         cmdline_fixed_string_t bonding;
4781         cmdline_fixed_string_t balance_xmit_policy;
4782         portid_t port_id;
4783         cmdline_fixed_string_t policy;
4784 };
4785
4786 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4787                 __attribute__((unused))  struct cmdline *cl,
4788                 __attribute__((unused)) void *data)
4789 {
4790         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4791         portid_t port_id = res->port_id;
4792         uint8_t policy;
4793
4794         if (!strcmp(res->policy, "l2")) {
4795                 policy = BALANCE_XMIT_POLICY_LAYER2;
4796         } else if (!strcmp(res->policy, "l23")) {
4797                 policy = BALANCE_XMIT_POLICY_LAYER23;
4798         } else if (!strcmp(res->policy, "l34")) {
4799                 policy = BALANCE_XMIT_POLICY_LAYER34;
4800         } else {
4801                 printf("\t Invalid xmit policy selection");
4802                 return;
4803         }
4804
4805         /* Set the bonding mode for the relevant port. */
4806         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4807                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4808                                 port_id);
4809         }
4810 }
4811
4812 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4813 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4814                 set, "set");
4815 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4816 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4817                 bonding, "bonding");
4818 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4819 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4820                 balance_xmit_policy, "balance_xmit_policy");
4821 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4822 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4823                 port_id, UINT16);
4824 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4825 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4826                 policy, "l2#l23#l34");
4827
4828 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4829                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4830                 .help_str = "set bonding balance_xmit_policy <port_id> "
4831                         "l2|l23|l34: "
4832                         "Set the bonding balance_xmit_policy for port_id",
4833                 .data = NULL,
4834                 .tokens = {
4835                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4836                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4837                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4838                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4839                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4840                                 NULL
4841                 }
4842 };
4843
4844 /* *** SHOW NIC BONDING CONFIGURATION *** */
4845 struct cmd_show_bonding_config_result {
4846         cmdline_fixed_string_t show;
4847         cmdline_fixed_string_t bonding;
4848         cmdline_fixed_string_t config;
4849         portid_t port_id;
4850 };
4851
4852 static void cmd_show_bonding_config_parsed(void *parsed_result,
4853                 __attribute__((unused))  struct cmdline *cl,
4854                 __attribute__((unused)) void *data)
4855 {
4856         struct cmd_show_bonding_config_result *res = parsed_result;
4857         int bonding_mode, agg_mode;
4858         portid_t slaves[RTE_MAX_ETHPORTS];
4859         int num_slaves, num_active_slaves;
4860         int primary_id;
4861         int i;
4862         portid_t port_id = res->port_id;
4863
4864         /* Display the bonding mode.*/
4865         bonding_mode = rte_eth_bond_mode_get(port_id);
4866         if (bonding_mode < 0) {
4867                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4868                 return;
4869         } else
4870                 printf("\tBonding mode: %d\n", bonding_mode);
4871
4872         if (bonding_mode == BONDING_MODE_BALANCE) {
4873                 int balance_xmit_policy;
4874
4875                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4876                 if (balance_xmit_policy < 0) {
4877                         printf("\tFailed to get balance xmit policy for port = %d\n",
4878                                         port_id);
4879                         return;
4880                 } else {
4881                         printf("\tBalance Xmit Policy: ");
4882
4883                         switch (balance_xmit_policy) {
4884                         case BALANCE_XMIT_POLICY_LAYER2:
4885                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4886                                 break;
4887                         case BALANCE_XMIT_POLICY_LAYER23:
4888                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4889                                 break;
4890                         case BALANCE_XMIT_POLICY_LAYER34:
4891                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4892                                 break;
4893                         }
4894                         printf("\n");
4895                 }
4896         }
4897
4898         if (bonding_mode == BONDING_MODE_8023AD) {
4899                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4900                 printf("\tIEEE802.3AD Aggregator Mode: ");
4901                 switch (agg_mode) {
4902                 case AGG_BANDWIDTH:
4903                         printf("bandwidth");
4904                         break;
4905                 case AGG_STABLE:
4906                         printf("stable");
4907                         break;
4908                 case AGG_COUNT:
4909                         printf("count");
4910                         break;
4911                 }
4912                 printf("\n");
4913         }
4914
4915         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4916
4917         if (num_slaves < 0) {
4918                 printf("\tFailed to get slave list for port = %d\n", port_id);
4919                 return;
4920         }
4921         if (num_slaves > 0) {
4922                 printf("\tSlaves (%d): [", num_slaves);
4923                 for (i = 0; i < num_slaves - 1; i++)
4924                         printf("%d ", slaves[i]);
4925
4926                 printf("%d]\n", slaves[num_slaves - 1]);
4927         } else {
4928                 printf("\tSlaves: []\n");
4929
4930         }
4931
4932         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4933                         RTE_MAX_ETHPORTS);
4934
4935         if (num_active_slaves < 0) {
4936                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4937                 return;
4938         }
4939         if (num_active_slaves > 0) {
4940                 printf("\tActive Slaves (%d): [", num_active_slaves);
4941                 for (i = 0; i < num_active_slaves - 1; i++)
4942                         printf("%d ", slaves[i]);
4943
4944                 printf("%d]\n", slaves[num_active_slaves - 1]);
4945
4946         } else {
4947                 printf("\tActive Slaves: []\n");
4948
4949         }
4950
4951         primary_id = rte_eth_bond_primary_get(port_id);
4952         if (primary_id < 0) {
4953                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4954                 return;
4955         } else
4956                 printf("\tPrimary: [%d]\n", primary_id);
4957
4958 }
4959
4960 cmdline_parse_token_string_t cmd_showbonding_config_show =
4961 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4962                 show, "show");
4963 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4964 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4965                 bonding, "bonding");
4966 cmdline_parse_token_string_t cmd_showbonding_config_config =
4967 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4968                 config, "config");
4969 cmdline_parse_token_num_t cmd_showbonding_config_port =
4970 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4971                 port_id, UINT16);
4972
4973 cmdline_parse_inst_t cmd_show_bonding_config = {
4974                 .f = cmd_show_bonding_config_parsed,
4975                 .help_str = "show bonding config <port_id>: "
4976                         "Show the bonding config for port_id",
4977                 .data = NULL,
4978                 .tokens = {
4979                                 (void *)&cmd_showbonding_config_show,
4980                                 (void *)&cmd_showbonding_config_bonding,
4981                                 (void *)&cmd_showbonding_config_config,
4982                                 (void *)&cmd_showbonding_config_port,
4983                                 NULL
4984                 }
4985 };
4986
4987 /* *** SET BONDING PRIMARY *** */
4988 struct cmd_set_bonding_primary_result {
4989         cmdline_fixed_string_t set;
4990         cmdline_fixed_string_t bonding;
4991         cmdline_fixed_string_t primary;
4992         portid_t slave_id;
4993         portid_t port_id;
4994 };
4995
4996 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4997                 __attribute__((unused))  struct cmdline *cl,
4998                 __attribute__((unused)) void *data)
4999 {
5000         struct cmd_set_bonding_primary_result *res = parsed_result;
5001         portid_t master_port_id = res->port_id;
5002         portid_t slave_port_id = res->slave_id;
5003
5004         /* Set the primary slave for a bonded device. */
5005         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5006                 printf("\t Failed to set primary slave for port = %d.\n",
5007                                 master_port_id);
5008                 return;
5009         }
5010         init_port_config();
5011 }
5012
5013 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5014 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5015                 set, "set");
5016 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5017 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5018                 bonding, "bonding");
5019 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5020 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5021                 primary, "primary");
5022 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5023 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5024                 slave_id, UINT16);
5025 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5026 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5027                 port_id, UINT16);
5028
5029 cmdline_parse_inst_t cmd_set_bonding_primary = {
5030                 .f = cmd_set_bonding_primary_parsed,
5031                 .help_str = "set bonding primary <slave_id> <port_id>: "
5032                         "Set the primary slave for port_id",
5033                 .data = NULL,
5034                 .tokens = {
5035                                 (void *)&cmd_setbonding_primary_set,
5036                                 (void *)&cmd_setbonding_primary_bonding,
5037                                 (void *)&cmd_setbonding_primary_primary,
5038                                 (void *)&cmd_setbonding_primary_slave,
5039                                 (void *)&cmd_setbonding_primary_port,
5040                                 NULL
5041                 }
5042 };
5043
5044 /* *** ADD SLAVE *** */
5045 struct cmd_add_bonding_slave_result {
5046         cmdline_fixed_string_t add;
5047         cmdline_fixed_string_t bonding;
5048         cmdline_fixed_string_t slave;
5049         portid_t slave_id;
5050         portid_t port_id;
5051 };
5052
5053 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5054                 __attribute__((unused))  struct cmdline *cl,
5055                 __attribute__((unused)) void *data)
5056 {
5057         struct cmd_add_bonding_slave_result *res = parsed_result;
5058         portid_t master_port_id = res->port_id;
5059         portid_t slave_port_id = res->slave_id;
5060
5061         /* add the slave for a bonded device. */
5062         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5063                 printf("\t Failed to add slave %d to master port = %d.\n",
5064                                 slave_port_id, master_port_id);
5065                 return;
5066         }
5067         init_port_config();
5068         set_port_slave_flag(slave_port_id);
5069 }
5070
5071 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5072 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5073                 add, "add");
5074 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5075 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5076                 bonding, "bonding");
5077 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5078 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5079                 slave, "slave");
5080 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5081 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5082                 slave_id, UINT16);
5083 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5084 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5085                 port_id, UINT16);
5086
5087 cmdline_parse_inst_t cmd_add_bonding_slave = {
5088                 .f = cmd_add_bonding_slave_parsed,
5089                 .help_str = "add bonding slave <slave_id> <port_id>: "
5090                         "Add a slave device to a bonded device",
5091                 .data = NULL,
5092                 .tokens = {
5093                                 (void *)&cmd_addbonding_slave_add,
5094                                 (void *)&cmd_addbonding_slave_bonding,
5095                                 (void *)&cmd_addbonding_slave_slave,
5096                                 (void *)&cmd_addbonding_slave_slaveid,
5097                                 (void *)&cmd_addbonding_slave_port,
5098                                 NULL
5099                 }
5100 };
5101
5102 /* *** REMOVE SLAVE *** */
5103 struct cmd_remove_bonding_slave_result {
5104         cmdline_fixed_string_t remove;
5105         cmdline_fixed_string_t bonding;
5106         cmdline_fixed_string_t slave;
5107         portid_t slave_id;
5108         portid_t port_id;
5109 };
5110
5111 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5112                 __attribute__((unused))  struct cmdline *cl,
5113                 __attribute__((unused)) void *data)
5114 {
5115         struct cmd_remove_bonding_slave_result *res = parsed_result;
5116         portid_t master_port_id = res->port_id;
5117         portid_t slave_port_id = res->slave_id;
5118
5119         /* remove the slave from a bonded device. */
5120         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5121                 printf("\t Failed to remove slave %d from master port = %d.\n",
5122                                 slave_port_id, master_port_id);
5123                 return;
5124         }
5125         init_port_config();
5126         clear_port_slave_flag(slave_port_id);
5127 }
5128
5129 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5130                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5131                                 remove, "remove");
5132 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5133                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5134                                 bonding, "bonding");
5135 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5136                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5137                                 slave, "slave");
5138 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5139                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5140                                 slave_id, UINT16);
5141 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5142                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5143                                 port_id, UINT16);
5144
5145 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5146                 .f = cmd_remove_bonding_slave_parsed,
5147                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5148                         "Remove a slave device from a bonded device",
5149                 .data = NULL,
5150                 .tokens = {
5151                                 (void *)&cmd_removebonding_slave_remove,
5152                                 (void *)&cmd_removebonding_slave_bonding,
5153                                 (void *)&cmd_removebonding_slave_slave,
5154                                 (void *)&cmd_removebonding_slave_slaveid,
5155                                 (void *)&cmd_removebonding_slave_port,
5156                                 NULL
5157                 }
5158 };
5159
5160 /* *** CREATE BONDED DEVICE *** */
5161 struct cmd_create_bonded_device_result {
5162         cmdline_fixed_string_t create;
5163         cmdline_fixed_string_t bonded;
5164         cmdline_fixed_string_t device;
5165         uint8_t mode;
5166         uint8_t socket;
5167 };
5168
5169 static int bond_dev_num = 0;
5170
5171 static void cmd_create_bonded_device_parsed(void *parsed_result,
5172                 __attribute__((unused))  struct cmdline *cl,
5173                 __attribute__((unused)) void *data)
5174 {
5175         struct cmd_create_bonded_device_result *res = parsed_result;
5176         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5177         int port_id;
5178
5179         if (test_done == 0) {
5180                 printf("Please stop forwarding first\n");
5181                 return;
5182         }
5183
5184         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5185                         bond_dev_num++);
5186
5187         /* Create a new bonded device. */
5188         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5189         if (port_id < 0) {
5190                 printf("\t Failed to create bonded device.\n");
5191                 return;
5192         } else {
5193                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5194                                 port_id);
5195
5196                 /* Update number of ports */
5197                 nb_ports = rte_eth_dev_count();
5198                 reconfig(port_id, res->socket);
5199                 rte_eth_promiscuous_enable(port_id);
5200         }
5201
5202 }
5203
5204 cmdline_parse_token_string_t cmd_createbonded_device_create =
5205                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5206                                 create, "create");
5207 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5208                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5209                                 bonded, "bonded");
5210 cmdline_parse_token_string_t cmd_createbonded_device_device =
5211                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5212                                 device, "device");
5213 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5214                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5215                                 mode, UINT8);
5216 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5217                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5218                                 socket, UINT8);
5219
5220 cmdline_parse_inst_t cmd_create_bonded_device = {
5221                 .f = cmd_create_bonded_device_parsed,
5222                 .help_str = "create bonded device <mode> <socket>: "
5223                         "Create a new bonded device with specific bonding mode and socket",
5224                 .data = NULL,
5225                 .tokens = {
5226                                 (void *)&cmd_createbonded_device_create,
5227                                 (void *)&cmd_createbonded_device_bonded,
5228                                 (void *)&cmd_createbonded_device_device,
5229                                 (void *)&cmd_createbonded_device_mode,
5230                                 (void *)&cmd_createbonded_device_socket,
5231                                 NULL
5232                 }
5233 };
5234
5235 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5236 struct cmd_set_bond_mac_addr_result {
5237         cmdline_fixed_string_t set;
5238         cmdline_fixed_string_t bonding;
5239         cmdline_fixed_string_t mac_addr;
5240         uint16_t port_num;
5241         struct ether_addr address;
5242 };
5243
5244 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5245                 __attribute__((unused))  struct cmdline *cl,
5246                 __attribute__((unused)) void *data)
5247 {
5248         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5249         int ret;
5250
5251         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5252                 return;
5253
5254         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5255
5256         /* check the return value and print it if is < 0 */
5257         if (ret < 0)
5258                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5259 }
5260
5261 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5262                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5263 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5264                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5265                                 "bonding");
5266 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5267                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5268                                 "mac_addr");
5269 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5270                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5271                                 port_num, UINT16);
5272 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5273                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5274
5275 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5276                 .f = cmd_set_bond_mac_addr_parsed,
5277                 .data = (void *) 0,
5278                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5279                 .tokens = {
5280                                 (void *)&cmd_set_bond_mac_addr_set,
5281                                 (void *)&cmd_set_bond_mac_addr_bonding,
5282                                 (void *)&cmd_set_bond_mac_addr_mac,
5283                                 (void *)&cmd_set_bond_mac_addr_portnum,
5284                                 (void *)&cmd_set_bond_mac_addr_addr,
5285                                 NULL
5286                 }
5287 };
5288
5289
5290 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5291 struct cmd_set_bond_mon_period_result {
5292         cmdline_fixed_string_t set;
5293         cmdline_fixed_string_t bonding;
5294         cmdline_fixed_string_t mon_period;
5295         uint16_t port_num;
5296         uint32_t period_ms;
5297 };
5298
5299 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5300                 __attribute__((unused))  struct cmdline *cl,
5301                 __attribute__((unused)) void *data)
5302 {
5303         struct cmd_set_bond_mon_period_result *res = parsed_result;
5304         int ret;
5305
5306         if (res->port_num >= nb_ports) {
5307                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5308                 return;
5309         }
5310
5311         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5312
5313         /* check the return value and print it if is < 0 */
5314         if (ret < 0)
5315                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5316 }
5317
5318 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5319                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5320                                 set, "set");
5321 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5322                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5323                                 bonding, "bonding");
5324 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5325                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5326                                 mon_period,     "mon_period");
5327 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5328                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5329                                 port_num, UINT16);
5330 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5331                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5332                                 period_ms, UINT32);
5333
5334 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5335                 .f = cmd_set_bond_mon_period_parsed,
5336                 .data = (void *) 0,
5337                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5338                 .tokens = {
5339                                 (void *)&cmd_set_bond_mon_period_set,
5340                                 (void *)&cmd_set_bond_mon_period_bonding,
5341                                 (void *)&cmd_set_bond_mon_period_mon_period,
5342                                 (void *)&cmd_set_bond_mon_period_portnum,
5343                                 (void *)&cmd_set_bond_mon_period_period_ms,
5344                                 NULL
5345                 }
5346 };
5347
5348
5349
5350 struct cmd_set_bonding_agg_mode_policy_result {
5351         cmdline_fixed_string_t set;
5352         cmdline_fixed_string_t bonding;
5353         cmdline_fixed_string_t agg_mode;
5354         uint16_t port_num;
5355         cmdline_fixed_string_t policy;
5356 };
5357
5358
5359 static void
5360 cmd_set_bonding_agg_mode(void *parsed_result,
5361                 __attribute__((unused)) struct cmdline *cl,
5362                 __attribute__((unused)) void *data)
5363 {
5364         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5365         uint8_t policy = AGG_BANDWIDTH;
5366
5367         if (res->port_num >= nb_ports) {
5368                 printf("Port id %d must be less than %d\n",
5369                                 res->port_num, nb_ports);
5370                 return;
5371         }
5372
5373         if (!strcmp(res->policy, "bandwidth"))
5374                 policy = AGG_BANDWIDTH;
5375         else if (!strcmp(res->policy, "stable"))
5376                 policy = AGG_STABLE;
5377         else if (!strcmp(res->policy, "count"))
5378                 policy = AGG_COUNT;
5379
5380         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5381 }
5382
5383
5384 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5385         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5386                                 set, "set");
5387 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5388         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5389                                 bonding, "bonding");
5390
5391 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5392         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5393                                 agg_mode, "agg_mode");
5394
5395 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5396         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5397                                 port_num, UINT16);
5398
5399 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5400         TOKEN_STRING_INITIALIZER(
5401                         struct cmd_set_bonding_balance_xmit_policy_result,
5402                 policy, "stable#bandwidth#count");
5403
5404 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5405         .f = cmd_set_bonding_agg_mode,
5406         .data = (void *) 0,
5407         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5408         .tokens = {
5409                         (void *)&cmd_set_bonding_agg_mode_set,
5410                         (void *)&cmd_set_bonding_agg_mode_bonding,
5411                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5412                         (void *)&cmd_set_bonding_agg_mode_portnum,
5413                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5414                         NULL
5415                 }
5416 };
5417
5418
5419 #endif /* RTE_LIBRTE_PMD_BOND */
5420
5421 /* *** SET FORWARDING MODE *** */
5422 struct cmd_set_fwd_mode_result {
5423         cmdline_fixed_string_t set;
5424         cmdline_fixed_string_t fwd;
5425         cmdline_fixed_string_t mode;
5426 };
5427
5428 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5429                                     __attribute__((unused)) struct cmdline *cl,
5430                                     __attribute__((unused)) void *data)
5431 {
5432         struct cmd_set_fwd_mode_result *res = parsed_result;
5433
5434         retry_enabled = 0;
5435         set_pkt_forwarding_mode(res->mode);
5436 }
5437
5438 cmdline_parse_token_string_t cmd_setfwd_set =
5439         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5440 cmdline_parse_token_string_t cmd_setfwd_fwd =
5441         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5442 cmdline_parse_token_string_t cmd_setfwd_mode =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5444                 "" /* defined at init */);
5445
5446 cmdline_parse_inst_t cmd_set_fwd_mode = {
5447         .f = cmd_set_fwd_mode_parsed,
5448         .data = NULL,
5449         .help_str = NULL, /* defined at init */
5450         .tokens = {
5451                 (void *)&cmd_setfwd_set,
5452                 (void *)&cmd_setfwd_fwd,
5453                 (void *)&cmd_setfwd_mode,
5454                 NULL,
5455         },
5456 };
5457
5458 static void cmd_set_fwd_mode_init(void)
5459 {
5460         char *modes, *c;
5461         static char token[128];
5462         static char help[256];
5463         cmdline_parse_token_string_t *token_struct;
5464
5465         modes = list_pkt_forwarding_modes();
5466         snprintf(help, sizeof(help), "set fwd %s: "
5467                 "Set packet forwarding mode", modes);
5468         cmd_set_fwd_mode.help_str = help;
5469
5470         /* string token separator is # */
5471         for (c = token; *modes != '\0'; modes++)
5472                 if (*modes == '|')
5473                         *c++ = '#';
5474                 else
5475                         *c++ = *modes;
5476         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5477         token_struct->string_data.str = token;
5478 }
5479
5480 /* *** SET RETRY FORWARDING MODE *** */
5481 struct cmd_set_fwd_retry_mode_result {
5482         cmdline_fixed_string_t set;
5483         cmdline_fixed_string_t fwd;
5484         cmdline_fixed_string_t mode;
5485         cmdline_fixed_string_t retry;
5486 };
5487
5488 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5489                             __attribute__((unused)) struct cmdline *cl,
5490                             __attribute__((unused)) void *data)
5491 {
5492         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5493
5494         retry_enabled = 1;
5495         set_pkt_forwarding_mode(res->mode);
5496 }
5497
5498 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5500                         set, "set");
5501 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5503                         fwd, "fwd");
5504 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5505         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5506                         mode,
5507                 "" /* defined at init */);
5508 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5509         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5510                         retry, "retry");
5511
5512 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5513         .f = cmd_set_fwd_retry_mode_parsed,
5514         .data = NULL,
5515         .help_str = NULL, /* defined at init */
5516         .tokens = {
5517                 (void *)&cmd_setfwd_retry_set,
5518                 (void *)&cmd_setfwd_retry_fwd,
5519                 (void *)&cmd_setfwd_retry_mode,
5520                 (void *)&cmd_setfwd_retry_retry,
5521                 NULL,
5522         },
5523 };
5524
5525 static void cmd_set_fwd_retry_mode_init(void)
5526 {
5527         char *modes, *c;
5528         static char token[128];
5529         static char help[256];
5530         cmdline_parse_token_string_t *token_struct;
5531
5532         modes = list_pkt_forwarding_retry_modes();
5533         snprintf(help, sizeof(help), "set fwd %s retry: "
5534                 "Set packet forwarding mode with retry", modes);
5535         cmd_set_fwd_retry_mode.help_str = help;
5536
5537         /* string token separator is # */
5538         for (c = token; *modes != '\0'; modes++)
5539                 if (*modes == '|')
5540                         *c++ = '#';
5541                 else
5542                         *c++ = *modes;
5543         token_struct = (cmdline_parse_token_string_t *)
5544                 cmd_set_fwd_retry_mode.tokens[2];
5545         token_struct->string_data.str = token;
5546 }
5547
5548 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5549 struct cmd_set_burst_tx_retry_result {
5550         cmdline_fixed_string_t set;
5551         cmdline_fixed_string_t burst;
5552         cmdline_fixed_string_t tx;
5553         cmdline_fixed_string_t delay;
5554         uint32_t time;
5555         cmdline_fixed_string_t retry;
5556         uint32_t retry_num;
5557 };
5558
5559 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5560                                         __attribute__((unused)) struct cmdline *cl,
5561                                         __attribute__((unused)) void *data)
5562 {
5563         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5564
5565         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5566                 && !strcmp(res->tx, "tx")) {
5567                 if (!strcmp(res->delay, "delay"))
5568                         burst_tx_delay_time = res->time;
5569                 if (!strcmp(res->retry, "retry"))
5570                         burst_tx_retry_num = res->retry_num;
5571         }
5572
5573 }
5574
5575 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5576         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5577 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5579                                  "burst");
5580 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5581         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5582 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5583         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5584 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5585         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5586 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5587         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5588 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5589         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5590
5591 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5592         .f = cmd_set_burst_tx_retry_parsed,
5593         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5594         .tokens = {
5595                 (void *)&cmd_set_burst_tx_retry_set,
5596                 (void *)&cmd_set_burst_tx_retry_burst,
5597                 (void *)&cmd_set_burst_tx_retry_tx,
5598                 (void *)&cmd_set_burst_tx_retry_delay,
5599                 (void *)&cmd_set_burst_tx_retry_time,
5600                 (void *)&cmd_set_burst_tx_retry_retry,
5601                 (void *)&cmd_set_burst_tx_retry_retry_num,
5602                 NULL,
5603         },
5604 };
5605
5606 /* *** SET PROMISC MODE *** */
5607 struct cmd_set_promisc_mode_result {
5608         cmdline_fixed_string_t set;
5609         cmdline_fixed_string_t promisc;
5610         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5611         uint16_t port_num;               /* valid if "allports" argument == 0 */
5612         cmdline_fixed_string_t mode;
5613 };
5614
5615 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5616                                         __attribute__((unused)) struct cmdline *cl,
5617                                         void *allports)
5618 {
5619         struct cmd_set_promisc_mode_result *res = parsed_result;
5620         int enable;
5621         portid_t i;
5622
5623         if (!strcmp(res->mode, "on"))
5624                 enable = 1;
5625         else
5626                 enable = 0;
5627
5628         /* all ports */
5629         if (allports) {
5630                 RTE_ETH_FOREACH_DEV(i) {
5631                         if (enable)
5632                                 rte_eth_promiscuous_enable(i);
5633                         else
5634                                 rte_eth_promiscuous_disable(i);
5635                 }
5636         }
5637         else {
5638                 if (enable)
5639                         rte_eth_promiscuous_enable(res->port_num);
5640                 else
5641                         rte_eth_promiscuous_disable(res->port_num);
5642         }
5643 }
5644
5645 cmdline_parse_token_string_t cmd_setpromisc_set =
5646         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5647 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5648         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5649                                  "promisc");
5650 cmdline_parse_token_string_t cmd_setpromisc_portall =
5651         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5652                                  "all");
5653 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5654         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5655                               UINT8);
5656 cmdline_parse_token_string_t cmd_setpromisc_mode =
5657         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5658                                  "on#off");
5659
5660 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5661         .f = cmd_set_promisc_mode_parsed,
5662         .data = (void *)1,
5663         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5664         .tokens = {
5665                 (void *)&cmd_setpromisc_set,
5666                 (void *)&cmd_setpromisc_promisc,
5667                 (void *)&cmd_setpromisc_portall,
5668                 (void *)&cmd_setpromisc_mode,
5669                 NULL,
5670         },
5671 };
5672
5673 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5674         .f = cmd_set_promisc_mode_parsed,
5675         .data = (void *)0,
5676         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5677         .tokens = {
5678                 (void *)&cmd_setpromisc_set,
5679                 (void *)&cmd_setpromisc_promisc,
5680                 (void *)&cmd_setpromisc_portnum,
5681                 (void *)&cmd_setpromisc_mode,
5682                 NULL,
5683         },
5684 };
5685
5686 /* *** SET ALLMULTI MODE *** */
5687 struct cmd_set_allmulti_mode_result {
5688         cmdline_fixed_string_t set;
5689         cmdline_fixed_string_t allmulti;
5690         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5691         uint16_t port_num;               /* valid if "allports" argument == 0 */
5692         cmdline_fixed_string_t mode;
5693 };
5694
5695 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5696                                         __attribute__((unused)) struct cmdline *cl,
5697                                         void *allports)
5698 {
5699         struct cmd_set_allmulti_mode_result *res = parsed_result;
5700         int enable;
5701         portid_t i;
5702
5703         if (!strcmp(res->mode, "on"))
5704                 enable = 1;
5705         else
5706                 enable = 0;
5707
5708         /* all ports */
5709         if (allports) {
5710                 RTE_ETH_FOREACH_DEV(i) {
5711                         if (enable)
5712                                 rte_eth_allmulticast_enable(i);
5713                         else
5714                                 rte_eth_allmulticast_disable(i);
5715                 }
5716         }
5717         else {
5718                 if (enable)
5719                         rte_eth_allmulticast_enable(res->port_num);
5720                 else
5721                         rte_eth_allmulticast_disable(res->port_num);
5722         }
5723 }
5724
5725 cmdline_parse_token_string_t cmd_setallmulti_set =
5726         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5727 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5728         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5729                                  "allmulti");
5730 cmdline_parse_token_string_t cmd_setallmulti_portall =
5731         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5732                                  "all");
5733 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5734         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5735                               UINT16);
5736 cmdline_parse_token_string_t cmd_setallmulti_mode =
5737         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5738                                  "on#off");
5739
5740 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5741         .f = cmd_set_allmulti_mode_parsed,
5742         .data = (void *)1,
5743         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5744         .tokens = {
5745                 (void *)&cmd_setallmulti_set,
5746                 (void *)&cmd_setallmulti_allmulti,
5747                 (void *)&cmd_setallmulti_portall,
5748                 (void *)&cmd_setallmulti_mode,
5749                 NULL,
5750         },
5751 };
5752
5753 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5754         .f = cmd_set_allmulti_mode_parsed,
5755         .data = (void *)0,
5756         .help_str = "set allmulti <port_id> on|off: "
5757                 "Set allmulti mode on port_id",
5758         .tokens = {
5759                 (void *)&cmd_setallmulti_set,
5760                 (void *)&cmd_setallmulti_allmulti,
5761                 (void *)&cmd_setallmulti_portnum,
5762                 (void *)&cmd_setallmulti_mode,
5763                 NULL,
5764         },
5765 };
5766
5767 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5768 struct cmd_link_flow_ctrl_set_result {
5769         cmdline_fixed_string_t set;
5770         cmdline_fixed_string_t flow_ctrl;
5771         cmdline_fixed_string_t rx;
5772         cmdline_fixed_string_t rx_lfc_mode;
5773         cmdline_fixed_string_t tx;
5774         cmdline_fixed_string_t tx_lfc_mode;
5775         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5776         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5777         cmdline_fixed_string_t autoneg_str;
5778         cmdline_fixed_string_t autoneg;
5779         cmdline_fixed_string_t hw_str;
5780         uint32_t high_water;
5781         cmdline_fixed_string_t lw_str;
5782         uint32_t low_water;
5783         cmdline_fixed_string_t pt_str;
5784         uint16_t pause_time;
5785         cmdline_fixed_string_t xon_str;
5786         uint16_t send_xon;
5787         portid_t port_id;
5788 };
5789
5790 cmdline_parse_token_string_t cmd_lfc_set_set =
5791         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5792                                 set, "set");
5793 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5794         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5795                                 flow_ctrl, "flow_ctrl");
5796 cmdline_parse_token_string_t cmd_lfc_set_rx =
5797         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5798                                 rx, "rx");
5799 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5800         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5801                                 rx_lfc_mode, "on#off");
5802 cmdline_parse_token_string_t cmd_lfc_set_tx =
5803         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5804                                 tx, "tx");
5805 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5806         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5807                                 tx_lfc_mode, "on#off");
5808 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5809         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5810                                 hw_str, "high_water");
5811 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5812         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5813                                 high_water, UINT32);
5814 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5815         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5816                                 lw_str, "low_water");
5817 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5818         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5819                                 low_water, UINT32);
5820 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5822                                 pt_str, "pause_time");
5823 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5824         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5825                                 pause_time, UINT16);
5826 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5827         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5828                                 xon_str, "send_xon");
5829 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5830         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5831                                 send_xon, UINT16);
5832 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5833         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5834                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5835 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5836         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5837                                 mac_ctrl_frame_fwd_mode, "on#off");
5838 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5839         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5840                                 autoneg_str, "autoneg");
5841 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5842         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5843                                 autoneg, "on#off");
5844 cmdline_parse_token_num_t cmd_lfc_set_portid =
5845         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5846                                 port_id, UINT16);
5847
5848 /* forward declaration */
5849 static void
5850 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5851                               void *data);
5852
5853 cmdline_parse_inst_t cmd_link_flow_control_set = {
5854         .f = cmd_link_flow_ctrl_set_parsed,
5855         .data = NULL,
5856         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5857                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5858                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5859         .tokens = {
5860                 (void *)&cmd_lfc_set_set,
5861                 (void *)&cmd_lfc_set_flow_ctrl,
5862                 (void *)&cmd_lfc_set_rx,
5863                 (void *)&cmd_lfc_set_rx_mode,
5864                 (void *)&cmd_lfc_set_tx,
5865                 (void *)&cmd_lfc_set_tx_mode,
5866                 (void *)&cmd_lfc_set_high_water,
5867                 (void *)&cmd_lfc_set_low_water,
5868                 (void *)&cmd_lfc_set_pause_time,
5869                 (void *)&cmd_lfc_set_send_xon,
5870                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5871                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5872                 (void *)&cmd_lfc_set_autoneg_str,
5873                 (void *)&cmd_lfc_set_autoneg,
5874                 (void *)&cmd_lfc_set_portid,
5875                 NULL,
5876         },
5877 };
5878
5879 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5880         .f = cmd_link_flow_ctrl_set_parsed,
5881         .data = (void *)&cmd_link_flow_control_set_rx,
5882         .help_str = "set flow_ctrl rx on|off <port_id>: "
5883                 "Change rx flow control parameter",
5884         .tokens = {
5885                 (void *)&cmd_lfc_set_set,
5886                 (void *)&cmd_lfc_set_flow_ctrl,
5887                 (void *)&cmd_lfc_set_rx,
5888                 (void *)&cmd_lfc_set_rx_mode,
5889                 (void *)&cmd_lfc_set_portid,
5890                 NULL,
5891         },
5892 };
5893
5894 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5895         .f = cmd_link_flow_ctrl_set_parsed,
5896         .data = (void *)&cmd_link_flow_control_set_tx,
5897         .help_str = "set flow_ctrl tx on|off <port_id>: "
5898                 "Change tx flow control parameter",
5899         .tokens = {
5900                 (void *)&cmd_lfc_set_set,
5901                 (void *)&cmd_lfc_set_flow_ctrl,
5902                 (void *)&cmd_lfc_set_tx,
5903                 (void *)&cmd_lfc_set_tx_mode,
5904                 (void *)&cmd_lfc_set_portid,
5905                 NULL,
5906         },
5907 };
5908
5909 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5910         .f = cmd_link_flow_ctrl_set_parsed,
5911         .data = (void *)&cmd_link_flow_control_set_hw,
5912         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5913                 "Change high water flow control parameter",
5914         .tokens = {
5915                 (void *)&cmd_lfc_set_set,
5916                 (void *)&cmd_lfc_set_flow_ctrl,
5917                 (void *)&cmd_lfc_set_high_water_str,
5918                 (void *)&cmd_lfc_set_high_water,
5919                 (void *)&cmd_lfc_set_portid,
5920                 NULL,
5921         },
5922 };
5923
5924 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5925         .f = cmd_link_flow_ctrl_set_parsed,
5926         .data = (void *)&cmd_link_flow_control_set_lw,
5927         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5928                 "Change low water flow control parameter",
5929         .tokens = {
5930                 (void *)&cmd_lfc_set_set,
5931                 (void *)&cmd_lfc_set_flow_ctrl,
5932                 (void *)&cmd_lfc_set_low_water_str,
5933                 (void *)&cmd_lfc_set_low_water,
5934                 (void *)&cmd_lfc_set_portid,
5935                 NULL,
5936         },
5937 };
5938
5939 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5940         .f = cmd_link_flow_ctrl_set_parsed,
5941         .data = (void *)&cmd_link_flow_control_set_pt,
5942         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5943                 "Change pause time flow control parameter",
5944         .tokens = {
5945                 (void *)&cmd_lfc_set_set,
5946                 (void *)&cmd_lfc_set_flow_ctrl,
5947                 (void *)&cmd_lfc_set_pause_time_str,
5948                 (void *)&cmd_lfc_set_pause_time,
5949                 (void *)&cmd_lfc_set_portid,
5950                 NULL,
5951         },
5952 };
5953
5954 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5955         .f = cmd_link_flow_ctrl_set_parsed,
5956         .data = (void *)&cmd_link_flow_control_set_xon,
5957         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5958                 "Change send_xon flow control parameter",
5959         .tokens = {
5960                 (void *)&cmd_lfc_set_set,
5961                 (void *)&cmd_lfc_set_flow_ctrl,
5962                 (void *)&cmd_lfc_set_send_xon_str,
5963                 (void *)&cmd_lfc_set_send_xon,
5964                 (void *)&cmd_lfc_set_portid,
5965                 NULL,
5966         },
5967 };
5968
5969 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5970         .f = cmd_link_flow_ctrl_set_parsed,
5971         .data = (void *)&cmd_link_flow_control_set_macfwd,
5972         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5973                 "Change mac ctrl fwd flow control parameter",
5974         .tokens = {
5975                 (void *)&cmd_lfc_set_set,
5976                 (void *)&cmd_lfc_set_flow_ctrl,
5977                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5978                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5979                 (void *)&cmd_lfc_set_portid,
5980                 NULL,
5981         },
5982 };
5983
5984 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5985         .f = cmd_link_flow_ctrl_set_parsed,
5986         .data = (void *)&cmd_link_flow_control_set_autoneg,
5987         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5988                 "Change autoneg flow control parameter",
5989         .tokens = {
5990                 (void *)&cmd_lfc_set_set,
5991                 (void *)&cmd_lfc_set_flow_ctrl,
5992                 (void *)&cmd_lfc_set_autoneg_str,
5993                 (void *)&cmd_lfc_set_autoneg,
5994                 (void *)&cmd_lfc_set_portid,
5995                 NULL,
5996         },
5997 };
5998
5999 static void
6000 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6001                               __attribute__((unused)) struct cmdline *cl,
6002                               void *data)
6003 {
6004         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6005         cmdline_parse_inst_t *cmd = data;
6006         struct rte_eth_fc_conf fc_conf;
6007         int rx_fc_en = 0;
6008         int tx_fc_en = 0;
6009         int ret;
6010
6011         /*
6012          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6013          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6014          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6015          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6016          */
6017         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6018                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6019         };
6020
6021         /* Partial command line, retrieve current configuration */
6022         if (cmd) {
6023                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6024                 if (ret != 0) {
6025                         printf("cannot get current flow ctrl parameters, return"
6026                                "code = %d\n", ret);
6027                         return;
6028                 }
6029
6030                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6031                     (fc_conf.mode == RTE_FC_FULL))
6032                         rx_fc_en = 1;
6033                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6034                     (fc_conf.mode == RTE_FC_FULL))
6035                         tx_fc_en = 1;
6036         }
6037
6038         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6039                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6040
6041         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6042                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6043
6044         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6045
6046         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6047                 fc_conf.high_water = res->high_water;
6048
6049         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6050                 fc_conf.low_water = res->low_water;
6051
6052         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6053                 fc_conf.pause_time = res->pause_time;
6054
6055         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6056                 fc_conf.send_xon = res->send_xon;
6057
6058         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6059                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6060                         fc_conf.mac_ctrl_frame_fwd = 1;
6061                 else
6062                         fc_conf.mac_ctrl_frame_fwd = 0;
6063         }
6064
6065         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6066                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6067
6068         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6069         if (ret != 0)
6070                 printf("bad flow contrl parameter, return code = %d \n", ret);
6071 }
6072
6073 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6074 struct cmd_priority_flow_ctrl_set_result {
6075         cmdline_fixed_string_t set;
6076         cmdline_fixed_string_t pfc_ctrl;
6077         cmdline_fixed_string_t rx;
6078         cmdline_fixed_string_t rx_pfc_mode;
6079         cmdline_fixed_string_t tx;
6080         cmdline_fixed_string_t tx_pfc_mode;
6081         uint32_t high_water;
6082         uint32_t low_water;
6083         uint16_t pause_time;
6084         uint8_t  priority;
6085         portid_t port_id;
6086 };
6087
6088 static void
6089 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6090                        __attribute__((unused)) struct cmdline *cl,
6091                        __attribute__((unused)) void *data)
6092 {
6093         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6094         struct rte_eth_pfc_conf pfc_conf;
6095         int rx_fc_enable, tx_fc_enable;
6096         int ret;
6097
6098         /*
6099          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6100          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6101          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6102          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6103          */
6104         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6105                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6106         };
6107
6108         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6109         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6110         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6111         pfc_conf.fc.high_water = res->high_water;
6112         pfc_conf.fc.low_water  = res->low_water;
6113         pfc_conf.fc.pause_time = res->pause_time;
6114         pfc_conf.priority      = res->priority;
6115
6116         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6117         if (ret != 0)
6118                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6119 }
6120
6121 cmdline_parse_token_string_t cmd_pfc_set_set =
6122         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6123                                 set, "set");
6124 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6125         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6126                                 pfc_ctrl, "pfc_ctrl");
6127 cmdline_parse_token_string_t cmd_pfc_set_rx =
6128         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6129                                 rx, "rx");
6130 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6131         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6132                                 rx_pfc_mode, "on#off");
6133 cmdline_parse_token_string_t cmd_pfc_set_tx =
6134         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6135                                 tx, "tx");
6136 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6137         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6138                                 tx_pfc_mode, "on#off");
6139 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6140         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6141                                 high_water, UINT32);
6142 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6143         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6144                                 low_water, UINT32);
6145 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6146         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6147                                 pause_time, UINT16);
6148 cmdline_parse_token_num_t cmd_pfc_set_priority =
6149         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6150                                 priority, UINT8);
6151 cmdline_parse_token_num_t cmd_pfc_set_portid =
6152         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6153                                 port_id, UINT16);
6154
6155 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6156         .f = cmd_priority_flow_ctrl_set_parsed,
6157         .data = NULL,
6158         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6159                 "<pause_time> <priority> <port_id>: "
6160                 "Configure the Ethernet priority flow control",
6161         .tokens = {
6162                 (void *)&cmd_pfc_set_set,
6163                 (void *)&cmd_pfc_set_flow_ctrl,
6164                 (void *)&cmd_pfc_set_rx,
6165                 (void *)&cmd_pfc_set_rx_mode,
6166                 (void *)&cmd_pfc_set_tx,
6167                 (void *)&cmd_pfc_set_tx_mode,
6168                 (void *)&cmd_pfc_set_high_water,
6169                 (void *)&cmd_pfc_set_low_water,
6170                 (void *)&cmd_pfc_set_pause_time,
6171                 (void *)&cmd_pfc_set_priority,
6172                 (void *)&cmd_pfc_set_portid,
6173                 NULL,
6174         },
6175 };
6176
6177 /* *** RESET CONFIGURATION *** */
6178 struct cmd_reset_result {
6179         cmdline_fixed_string_t reset;
6180         cmdline_fixed_string_t def;
6181 };
6182
6183 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6184                              struct cmdline *cl,
6185                              __attribute__((unused)) void *data)
6186 {
6187         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6188         set_def_fwd_config();
6189 }
6190
6191 cmdline_parse_token_string_t cmd_reset_set =
6192         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6193 cmdline_parse_token_string_t cmd_reset_def =
6194         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6195                                  "default");
6196
6197 cmdline_parse_inst_t cmd_reset = {
6198         .f = cmd_reset_parsed,
6199         .data = NULL,
6200         .help_str = "set default: Reset default forwarding configuration",
6201         .tokens = {
6202                 (void *)&cmd_reset_set,
6203                 (void *)&cmd_reset_def,
6204                 NULL,
6205         },
6206 };
6207
6208 /* *** START FORWARDING *** */
6209 struct cmd_start_result {
6210         cmdline_fixed_string_t start;
6211 };
6212
6213 cmdline_parse_token_string_t cmd_start_start =
6214         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6215
6216 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6217                              __attribute__((unused)) struct cmdline *cl,
6218                              __attribute__((unused)) void *data)
6219 {
6220         start_packet_forwarding(0);
6221 }
6222
6223 cmdline_parse_inst_t cmd_start = {
6224         .f = cmd_start_parsed,
6225         .data = NULL,
6226         .help_str = "start: Start packet forwarding",
6227         .tokens = {
6228                 (void *)&cmd_start_start,
6229                 NULL,
6230         },
6231 };
6232
6233 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6234 struct cmd_start_tx_first_result {
6235         cmdline_fixed_string_t start;
6236         cmdline_fixed_string_t tx_first;
6237 };
6238
6239 static void
6240 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6241                           __attribute__((unused)) struct cmdline *cl,
6242                           __attribute__((unused)) void *data)
6243 {
6244         start_packet_forwarding(1);
6245 }
6246
6247 cmdline_parse_token_string_t cmd_start_tx_first_start =
6248         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6249                                  "start");
6250 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6251         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6252                                  tx_first, "tx_first");
6253
6254 cmdline_parse_inst_t cmd_start_tx_first = {
6255         .f = cmd_start_tx_first_parsed,
6256         .data = NULL,
6257         .help_str = "start tx_first: Start packet forwarding, "
6258                 "after sending 1 burst of packets",
6259         .tokens = {
6260                 (void *)&cmd_start_tx_first_start,
6261                 (void *)&cmd_start_tx_first_tx_first,
6262                 NULL,
6263         },
6264 };
6265
6266 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6267 struct cmd_start_tx_first_n_result {
6268         cmdline_fixed_string_t start;
6269         cmdline_fixed_string_t tx_first;
6270         uint32_t tx_num;
6271 };
6272
6273 static void
6274 cmd_start_tx_first_n_parsed(void *parsed_result,
6275                           __attribute__((unused)) struct cmdline *cl,
6276                           __attribute__((unused)) void *data)
6277 {
6278         struct cmd_start_tx_first_n_result *res = parsed_result;
6279
6280         start_packet_forwarding(res->tx_num);
6281 }
6282
6283 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6284         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6285                         start, "start");
6286 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6287         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6288                         tx_first, "tx_first");
6289 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6290         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6291                         tx_num, UINT32);
6292
6293 cmdline_parse_inst_t cmd_start_tx_first_n = {
6294         .f = cmd_start_tx_first_n_parsed,
6295         .data = NULL,
6296         .help_str = "start tx_first <num>: "
6297                 "packet forwarding, after sending <num> bursts of packets",
6298         .tokens = {
6299                 (void *)&cmd_start_tx_first_n_start,
6300                 (void *)&cmd_start_tx_first_n_tx_first,
6301                 (void *)&cmd_start_tx_first_n_tx_num,
6302                 NULL,
6303         },
6304 };
6305
6306 /* *** SET LINK UP *** */
6307 struct cmd_set_link_up_result {
6308         cmdline_fixed_string_t set;
6309         cmdline_fixed_string_t link_up;
6310         cmdline_fixed_string_t port;
6311         portid_t port_id;
6312 };
6313
6314 cmdline_parse_token_string_t cmd_set_link_up_set =
6315         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6316 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6317         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6318                                 "link-up");
6319 cmdline_parse_token_string_t cmd_set_link_up_port =
6320         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6321 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6322         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6323
6324 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6325                              __attribute__((unused)) struct cmdline *cl,
6326                              __attribute__((unused)) void *data)
6327 {
6328         struct cmd_set_link_up_result *res = parsed_result;
6329         dev_set_link_up(res->port_id);
6330 }
6331
6332 cmdline_parse_inst_t cmd_set_link_up = {
6333         .f = cmd_set_link_up_parsed,
6334         .data = NULL,
6335         .help_str = "set link-up port <port id>",
6336         .tokens = {
6337                 (void *)&cmd_set_link_up_set,
6338                 (void *)&cmd_set_link_up_link_up,
6339                 (void *)&cmd_set_link_up_port,
6340                 (void *)&cmd_set_link_up_port_id,
6341                 NULL,
6342         },
6343 };
6344
6345 /* *** SET LINK DOWN *** */
6346 struct cmd_set_link_down_result {
6347         cmdline_fixed_string_t set;
6348         cmdline_fixed_string_t link_down;
6349         cmdline_fixed_string_t port;
6350         portid_t port_id;
6351 };
6352
6353 cmdline_parse_token_string_t cmd_set_link_down_set =
6354         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6355 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6356         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6357                                 "link-down");
6358 cmdline_parse_token_string_t cmd_set_link_down_port =
6359         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6360 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6361         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6362
6363 static void cmd_set_link_down_parsed(
6364                                 __attribute__((unused)) void *parsed_result,
6365                                 __attribute__((unused)) struct cmdline *cl,
6366                                 __attribute__((unused)) void *data)
6367 {
6368         struct cmd_set_link_down_result *res = parsed_result;
6369         dev_set_link_down(res->port_id);
6370 }
6371
6372 cmdline_parse_inst_t cmd_set_link_down = {
6373         .f = cmd_set_link_down_parsed,
6374         .data = NULL,
6375         .help_str = "set link-down port <port id>",
6376         .tokens = {
6377                 (void *)&cmd_set_link_down_set,
6378                 (void *)&cmd_set_link_down_link_down,
6379                 (void *)&cmd_set_link_down_port,
6380                 (void *)&cmd_set_link_down_port_id,
6381                 NULL,
6382         },
6383 };
6384
6385 /* *** SHOW CFG *** */
6386 struct cmd_showcfg_result {
6387         cmdline_fixed_string_t show;
6388         cmdline_fixed_string_t cfg;
6389         cmdline_fixed_string_t what;
6390 };
6391
6392 static void cmd_showcfg_parsed(void *parsed_result,
6393                                __attribute__((unused)) struct cmdline *cl,
6394                                __attribute__((unused)) void *data)
6395 {
6396         struct cmd_showcfg_result *res = parsed_result;
6397         if (!strcmp(res->what, "rxtx"))
6398                 rxtx_config_display();
6399         else if (!strcmp(res->what, "cores"))
6400                 fwd_lcores_config_display();
6401         else if (!strcmp(res->what, "fwd"))
6402                 pkt_fwd_config_display(&cur_fwd_config);
6403         else if (!strcmp(res->what, "txpkts"))
6404                 show_tx_pkt_segments();
6405 }
6406
6407 cmdline_parse_token_string_t cmd_showcfg_show =
6408         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6409 cmdline_parse_token_string_t cmd_showcfg_port =
6410         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6411 cmdline_parse_token_string_t cmd_showcfg_what =
6412         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6413                                  "rxtx#cores#fwd#txpkts");
6414
6415 cmdline_parse_inst_t cmd_showcfg = {
6416         .f = cmd_showcfg_parsed,
6417         .data = NULL,
6418         .help_str = "show config rxtx|cores|fwd|txpkts",
6419         .tokens = {
6420                 (void *)&cmd_showcfg_show,
6421                 (void *)&cmd_showcfg_port,
6422                 (void *)&cmd_showcfg_what,
6423                 NULL,
6424         },
6425 };
6426
6427 /* *** SHOW ALL PORT INFO *** */
6428 struct cmd_showportall_result {
6429         cmdline_fixed_string_t show;
6430         cmdline_fixed_string_t port;
6431         cmdline_fixed_string_t what;
6432         cmdline_fixed_string_t all;
6433 };
6434
6435 static void cmd_showportall_parsed(void *parsed_result,
6436                                 __attribute__((unused)) struct cmdline *cl,
6437                                 __attribute__((unused)) void *data)
6438 {
6439         portid_t i;
6440
6441         struct cmd_showportall_result *res = parsed_result;
6442         if (!strcmp(res->show, "clear")) {
6443                 if (!strcmp(res->what, "stats"))
6444                         RTE_ETH_FOREACH_DEV(i)
6445                                 nic_stats_clear(i);
6446                 else if (!strcmp(res->what, "xstats"))
6447                         RTE_ETH_FOREACH_DEV(i)
6448                                 nic_xstats_clear(i);
6449         } else if (!strcmp(res->what, "info"))
6450                 RTE_ETH_FOREACH_DEV(i)
6451                         port_infos_display(i);
6452         else if (!strcmp(res->what, "stats"))
6453                 RTE_ETH_FOREACH_DEV(i)
6454                         nic_stats_display(i);
6455         else if (!strcmp(res->what, "xstats"))
6456                 RTE_ETH_FOREACH_DEV(i)
6457                         nic_xstats_display(i);
6458         else if (!strcmp(res->what, "fdir"))
6459                 RTE_ETH_FOREACH_DEV(i)
6460                         fdir_get_infos(i);
6461         else if (!strcmp(res->what, "stat_qmap"))
6462                 RTE_ETH_FOREACH_DEV(i)
6463                         nic_stats_mapping_display(i);
6464         else if (!strcmp(res->what, "dcb_tc"))
6465                 RTE_ETH_FOREACH_DEV(i)
6466                         port_dcb_info_display(i);
6467         else if (!strcmp(res->what, "cap"))
6468                 RTE_ETH_FOREACH_DEV(i)
6469                         port_offload_cap_display(i);
6470 }
6471
6472 cmdline_parse_token_string_t cmd_showportall_show =
6473         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6474                                  "show#clear");
6475 cmdline_parse_token_string_t cmd_showportall_port =
6476         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6477 cmdline_parse_token_string_t cmd_showportall_what =
6478         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6479                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6480 cmdline_parse_token_string_t cmd_showportall_all =
6481         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6482 cmdline_parse_inst_t cmd_showportall = {
6483         .f = cmd_showportall_parsed,
6484         .data = NULL,
6485         .help_str = "show|clear port "
6486                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6487         .tokens = {
6488                 (void *)&cmd_showportall_show,
6489                 (void *)&cmd_showportall_port,
6490                 (void *)&cmd_showportall_what,
6491                 (void *)&cmd_showportall_all,
6492                 NULL,
6493         },
6494 };
6495
6496 /* *** SHOW PORT INFO *** */
6497 struct cmd_showport_result {
6498         cmdline_fixed_string_t show;
6499         cmdline_fixed_string_t port;
6500         cmdline_fixed_string_t what;
6501         uint16_t portnum;
6502 };
6503
6504 static void cmd_showport_parsed(void *parsed_result,
6505                                 __attribute__((unused)) struct cmdline *cl,
6506                                 __attribute__((unused)) void *data)
6507 {
6508         struct cmd_showport_result *res = parsed_result;
6509         if (!strcmp(res->show, "clear")) {
6510                 if (!strcmp(res->what, "stats"))
6511                         nic_stats_clear(res->portnum);
6512                 else if (!strcmp(res->what, "xstats"))
6513                         nic_xstats_clear(res->portnum);
6514         } else if (!strcmp(res->what, "info"))
6515                 port_infos_display(res->portnum);
6516         else if (!strcmp(res->what, "stats"))
6517                 nic_stats_display(res->portnum);
6518         else if (!strcmp(res->what, "xstats"))
6519                 nic_xstats_display(res->portnum);
6520         else if (!strcmp(res->what, "fdir"))
6521                  fdir_get_infos(res->portnum);
6522         else if (!strcmp(res->what, "stat_qmap"))
6523                 nic_stats_mapping_display(res->portnum);
6524         else if (!strcmp(res->what, "dcb_tc"))
6525                 port_dcb_info_display(res->portnum);
6526         else if (!strcmp(res->what, "cap"))
6527                 port_offload_cap_display(res->portnum);
6528 }
6529
6530 cmdline_parse_token_string_t cmd_showport_show =
6531         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6532                                  "show#clear");
6533 cmdline_parse_token_string_t cmd_showport_port =
6534         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6535 cmdline_parse_token_string_t cmd_showport_what =
6536         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6537                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6538 cmdline_parse_token_num_t cmd_showport_portnum =
6539         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6540
6541 cmdline_parse_inst_t cmd_showport = {
6542         .f = cmd_showport_parsed,
6543         .data = NULL,
6544         .help_str = "show|clear port "
6545                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6546                 "<port_id>",
6547         .tokens = {
6548                 (void *)&cmd_showport_show,
6549                 (void *)&cmd_showport_port,
6550                 (void *)&cmd_showport_what,
6551                 (void *)&cmd_showport_portnum,
6552                 NULL,
6553         },
6554 };
6555
6556 /* *** SHOW QUEUE INFO *** */
6557 struct cmd_showqueue_result {
6558         cmdline_fixed_string_t show;
6559         cmdline_fixed_string_t type;
6560         cmdline_fixed_string_t what;
6561         uint16_t portnum;
6562         uint16_t queuenum;
6563 };
6564
6565 static void
6566 cmd_showqueue_parsed(void *parsed_result,
6567         __attribute__((unused)) struct cmdline *cl,
6568         __attribute__((unused)) void *data)
6569 {
6570         struct cmd_showqueue_result *res = parsed_result;
6571
6572         if (!strcmp(res->type, "rxq"))
6573                 rx_queue_infos_display(res->portnum, res->queuenum);
6574         else if (!strcmp(res->type, "txq"))
6575                 tx_queue_infos_display(res->portnum, res->queuenum);
6576 }
6577
6578 cmdline_parse_token_string_t cmd_showqueue_show =
6579         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6580 cmdline_parse_token_string_t cmd_showqueue_type =
6581         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6582 cmdline_parse_token_string_t cmd_showqueue_what =
6583         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6584 cmdline_parse_token_num_t cmd_showqueue_portnum =
6585         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6586 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6587         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6588
6589 cmdline_parse_inst_t cmd_showqueue = {
6590         .f = cmd_showqueue_parsed,
6591         .data = NULL,
6592         .help_str = "show rxq|txq info <port_id> <queue_id>",
6593         .tokens = {
6594                 (void *)&cmd_showqueue_show,
6595                 (void *)&cmd_showqueue_type,
6596                 (void *)&cmd_showqueue_what,
6597                 (void *)&cmd_showqueue_portnum,
6598                 (void *)&cmd_showqueue_queuenum,
6599                 NULL,
6600         },
6601 };
6602
6603 /* *** READ PORT REGISTER *** */
6604 struct cmd_read_reg_result {
6605         cmdline_fixed_string_t read;
6606         cmdline_fixed_string_t reg;
6607         portid_t port_id;
6608         uint32_t reg_off;
6609 };
6610
6611 static void
6612 cmd_read_reg_parsed(void *parsed_result,
6613                     __attribute__((unused)) struct cmdline *cl,
6614                     __attribute__((unused)) void *data)
6615 {
6616         struct cmd_read_reg_result *res = parsed_result;
6617         port_reg_display(res->port_id, res->reg_off);
6618 }
6619
6620 cmdline_parse_token_string_t cmd_read_reg_read =
6621         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6622 cmdline_parse_token_string_t cmd_read_reg_reg =
6623         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6624 cmdline_parse_token_num_t cmd_read_reg_port_id =
6625         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6626 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6627         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6628
6629 cmdline_parse_inst_t cmd_read_reg = {
6630         .f = cmd_read_reg_parsed,
6631         .data = NULL,
6632         .help_str = "read reg <port_id> <reg_off>",
6633         .tokens = {
6634                 (void *)&cmd_read_reg_read,
6635                 (void *)&cmd_read_reg_reg,
6636                 (void *)&cmd_read_reg_port_id,
6637                 (void *)&cmd_read_reg_reg_off,
6638                 NULL,
6639         },
6640 };
6641
6642 /* *** READ PORT REGISTER BIT FIELD *** */
6643 struct cmd_read_reg_bit_field_result {
6644         cmdline_fixed_string_t read;
6645         cmdline_fixed_string_t regfield;
6646         portid_t port_id;
6647         uint32_t reg_off;
6648         uint8_t bit1_pos;
6649         uint8_t bit2_pos;
6650 };
6651
6652 static void
6653 cmd_read_reg_bit_field_parsed(void *parsed_result,
6654                               __attribute__((unused)) struct cmdline *cl,
6655                               __attribute__((unused)) void *data)
6656 {
6657         struct cmd_read_reg_bit_field_result *res = parsed_result;
6658         port_reg_bit_field_display(res->port_id, res->reg_off,
6659                                    res->bit1_pos, res->bit2_pos);
6660 }
6661
6662 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6663         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6664                                  "read");
6665 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6666         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6667                                  regfield, "regfield");
6668 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6669         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6670                               UINT16);
6671 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6672         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6673                               UINT32);
6674 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6675         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6676                               UINT8);
6677 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6678         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6679                               UINT8);
6680
6681 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6682         .f = cmd_read_reg_bit_field_parsed,
6683         .data = NULL,
6684         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6685         "Read register bit field between bit_x and bit_y included",
6686         .tokens = {
6687                 (void *)&cmd_read_reg_bit_field_read,
6688                 (void *)&cmd_read_reg_bit_field_regfield,
6689                 (void *)&cmd_read_reg_bit_field_port_id,
6690                 (void *)&cmd_read_reg_bit_field_reg_off,
6691                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6692                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6693                 NULL,
6694         },
6695 };
6696
6697 /* *** READ PORT REGISTER BIT *** */
6698 struct cmd_read_reg_bit_result {
6699         cmdline_fixed_string_t read;
6700         cmdline_fixed_string_t regbit;
6701         portid_t port_id;
6702         uint32_t reg_off;
6703         uint8_t bit_pos;
6704 };
6705
6706 static void
6707 cmd_read_reg_bit_parsed(void *parsed_result,
6708                         __attribute__((unused)) struct cmdline *cl,
6709                         __attribute__((unused)) void *data)
6710 {
6711         struct cmd_read_reg_bit_result *res = parsed_result;
6712         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6713 }
6714
6715 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6716         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6717 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6718         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6719                                  regbit, "regbit");
6720 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6721         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6722 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6723         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6724 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6725         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6726
6727 cmdline_parse_inst_t cmd_read_reg_bit = {
6728         .f = cmd_read_reg_bit_parsed,
6729         .data = NULL,
6730         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6731         .tokens = {
6732                 (void *)&cmd_read_reg_bit_read,
6733                 (void *)&cmd_read_reg_bit_regbit,
6734                 (void *)&cmd_read_reg_bit_port_id,
6735                 (void *)&cmd_read_reg_bit_reg_off,
6736                 (void *)&cmd_read_reg_bit_bit_pos,
6737                 NULL,
6738         },
6739 };
6740
6741 /* *** WRITE PORT REGISTER *** */
6742 struct cmd_write_reg_result {
6743         cmdline_fixed_string_t write;
6744         cmdline_fixed_string_t reg;
6745         portid_t port_id;
6746         uint32_t reg_off;
6747         uint32_t value;
6748 };
6749
6750 static void
6751 cmd_write_reg_parsed(void *parsed_result,
6752                      __attribute__((unused)) struct cmdline *cl,
6753                      __attribute__((unused)) void *data)
6754 {
6755         struct cmd_write_reg_result *res = parsed_result;
6756         port_reg_set(res->port_id, res->reg_off, res->value);
6757 }
6758
6759 cmdline_parse_token_string_t cmd_write_reg_write =
6760         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6761 cmdline_parse_token_string_t cmd_write_reg_reg =
6762         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6763 cmdline_parse_token_num_t cmd_write_reg_port_id =
6764         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6765 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6766         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6767 cmdline_parse_token_num_t cmd_write_reg_value =
6768         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6769
6770 cmdline_parse_inst_t cmd_write_reg = {
6771         .f = cmd_write_reg_parsed,
6772         .data = NULL,
6773         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6774         .tokens = {
6775                 (void *)&cmd_write_reg_write,
6776                 (void *)&cmd_write_reg_reg,
6777                 (void *)&cmd_write_reg_port_id,
6778                 (void *)&cmd_write_reg_reg_off,
6779                 (void *)&cmd_write_reg_value,
6780                 NULL,
6781         },
6782 };
6783
6784 /* *** WRITE PORT REGISTER BIT FIELD *** */
6785 struct cmd_write_reg_bit_field_result {
6786         cmdline_fixed_string_t write;
6787         cmdline_fixed_string_t regfield;
6788         portid_t port_id;
6789         uint32_t reg_off;
6790         uint8_t bit1_pos;
6791         uint8_t bit2_pos;
6792         uint32_t value;
6793 };
6794
6795 static void
6796 cmd_write_reg_bit_field_parsed(void *parsed_result,
6797                                __attribute__((unused)) struct cmdline *cl,
6798                                __attribute__((unused)) void *data)
6799 {
6800         struct cmd_write_reg_bit_field_result *res = parsed_result;
6801         port_reg_bit_field_set(res->port_id, res->reg_off,
6802                           res->bit1_pos, res->bit2_pos, res->value);
6803 }
6804
6805 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6806         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6807                                  "write");
6808 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6809         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6810                                  regfield, "regfield");
6811 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6813                               UINT16);
6814 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6815         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6816                               UINT32);
6817 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6818         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6819                               UINT8);
6820 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6821         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6822                               UINT8);
6823 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6824         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6825                               UINT32);
6826
6827 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6828         .f = cmd_write_reg_bit_field_parsed,
6829         .data = NULL,
6830         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6831                 "<reg_value>: "
6832                 "Set register bit field between bit_x and bit_y included",
6833         .tokens = {
6834                 (void *)&cmd_write_reg_bit_field_write,
6835                 (void *)&cmd_write_reg_bit_field_regfield,
6836                 (void *)&cmd_write_reg_bit_field_port_id,
6837                 (void *)&cmd_write_reg_bit_field_reg_off,
6838                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6839                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6840                 (void *)&cmd_write_reg_bit_field_value,
6841                 NULL,
6842         },
6843 };
6844
6845 /* *** WRITE PORT REGISTER BIT *** */
6846 struct cmd_write_reg_bit_result {
6847         cmdline_fixed_string_t write;
6848         cmdline_fixed_string_t regbit;
6849         portid_t port_id;
6850         uint32_t reg_off;
6851         uint8_t bit_pos;
6852         uint8_t value;
6853 };
6854
6855 static void
6856 cmd_write_reg_bit_parsed(void *parsed_result,
6857                          __attribute__((unused)) struct cmdline *cl,
6858                          __attribute__((unused)) void *data)
6859 {
6860         struct cmd_write_reg_bit_result *res = parsed_result;
6861         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6862 }
6863
6864 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6865         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6866                                  "write");
6867 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6868         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6869                                  regbit, "regbit");
6870 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6872 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6873         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6874 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6876 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6877         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6878
6879 cmdline_parse_inst_t cmd_write_reg_bit = {
6880         .f = cmd_write_reg_bit_parsed,
6881         .data = NULL,
6882         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6883                 "0 <= bit_x <= 31",
6884         .tokens = {
6885                 (void *)&cmd_write_reg_bit_write,
6886                 (void *)&cmd_write_reg_bit_regbit,
6887                 (void *)&cmd_write_reg_bit_port_id,
6888                 (void *)&cmd_write_reg_bit_reg_off,
6889                 (void *)&cmd_write_reg_bit_bit_pos,
6890                 (void *)&cmd_write_reg_bit_value,
6891                 NULL,
6892         },
6893 };
6894
6895 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6896 struct cmd_read_rxd_txd_result {
6897         cmdline_fixed_string_t read;
6898         cmdline_fixed_string_t rxd_txd;
6899         portid_t port_id;
6900         uint16_t queue_id;
6901         uint16_t desc_id;
6902 };
6903
6904 static void
6905 cmd_read_rxd_txd_parsed(void *parsed_result,
6906                         __attribute__((unused)) struct cmdline *cl,
6907                         __attribute__((unused)) void *data)
6908 {
6909         struct cmd_read_rxd_txd_result *res = parsed_result;
6910
6911         if (!strcmp(res->rxd_txd, "rxd"))
6912                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6913         else if (!strcmp(res->rxd_txd, "txd"))
6914                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6915 }
6916
6917 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6918         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6919 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6920         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6921                                  "rxd#txd");
6922 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6923         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
6924 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6925         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6926 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6927         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6928
6929 cmdline_parse_inst_t cmd_read_rxd_txd = {
6930         .f = cmd_read_rxd_txd_parsed,
6931         .data = NULL,
6932         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6933         .tokens = {
6934                 (void *)&cmd_read_rxd_txd_read,
6935                 (void *)&cmd_read_rxd_txd_rxd_txd,
6936                 (void *)&cmd_read_rxd_txd_port_id,
6937                 (void *)&cmd_read_rxd_txd_queue_id,
6938                 (void *)&cmd_read_rxd_txd_desc_id,
6939                 NULL,
6940         },
6941 };
6942
6943 /* *** QUIT *** */
6944 struct cmd_quit_result {
6945         cmdline_fixed_string_t quit;
6946 };
6947
6948 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6949                             struct cmdline *cl,
6950                             __attribute__((unused)) void *data)
6951 {
6952         pmd_test_exit();
6953         cmdline_quit(cl);
6954 }
6955
6956 cmdline_parse_token_string_t cmd_quit_quit =
6957         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6958
6959 cmdline_parse_inst_t cmd_quit = {
6960         .f = cmd_quit_parsed,
6961         .data = NULL,
6962         .help_str = "quit: Exit application",
6963         .tokens = {
6964                 (void *)&cmd_quit_quit,
6965                 NULL,
6966         },
6967 };
6968
6969 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6970 struct cmd_mac_addr_result {
6971         cmdline_fixed_string_t mac_addr_cmd;
6972         cmdline_fixed_string_t what;
6973         uint16_t port_num;
6974         struct ether_addr address;
6975 };
6976
6977 static void cmd_mac_addr_parsed(void *parsed_result,
6978                 __attribute__((unused)) struct cmdline *cl,
6979                 __attribute__((unused)) void *data)
6980 {
6981         struct cmd_mac_addr_result *res = parsed_result;
6982         int ret;
6983
6984         if (strcmp(res->what, "add") == 0)
6985                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6986         else if (strcmp(res->what, "set") == 0)
6987                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6988                                                        &res->address);
6989         else
6990                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6991
6992         /* check the return value and print it if is < 0 */
6993         if(ret < 0)
6994                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6995
6996 }
6997
6998 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6999         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7000                                 "mac_addr");
7001 cmdline_parse_token_string_t cmd_mac_addr_what =
7002         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7003                                 "add#remove#set");
7004 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7005                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7006                                         UINT16);
7007 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7008                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7009
7010 cmdline_parse_inst_t cmd_mac_addr = {
7011         .f = cmd_mac_addr_parsed,
7012         .data = (void *)0,
7013         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7014                         "Add/Remove/Set MAC address on port_id",
7015         .tokens = {
7016                 (void *)&cmd_mac_addr_cmd,
7017                 (void *)&cmd_mac_addr_what,
7018                 (void *)&cmd_mac_addr_portnum,
7019                 (void *)&cmd_mac_addr_addr,
7020                 NULL,
7021         },
7022 };
7023
7024
7025 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7026 struct cmd_set_qmap_result {
7027         cmdline_fixed_string_t set;
7028         cmdline_fixed_string_t qmap;
7029         cmdline_fixed_string_t what;
7030         portid_t port_id;
7031         uint16_t queue_id;
7032         uint8_t map_value;
7033 };
7034
7035 static void
7036 cmd_set_qmap_parsed(void *parsed_result,
7037                        __attribute__((unused)) struct cmdline *cl,
7038                        __attribute__((unused)) void *data)
7039 {
7040         struct cmd_set_qmap_result *res = parsed_result;
7041         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7042
7043         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7044 }
7045
7046 cmdline_parse_token_string_t cmd_setqmap_set =
7047         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7048                                  set, "set");
7049 cmdline_parse_token_string_t cmd_setqmap_qmap =
7050         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7051                                  qmap, "stat_qmap");
7052 cmdline_parse_token_string_t cmd_setqmap_what =
7053         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7054                                  what, "tx#rx");
7055 cmdline_parse_token_num_t cmd_setqmap_portid =
7056         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7057                               port_id, UINT16);
7058 cmdline_parse_token_num_t cmd_setqmap_queueid =
7059         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7060                               queue_id, UINT16);
7061 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7062         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7063                               map_value, UINT8);
7064
7065 cmdline_parse_inst_t cmd_set_qmap = {
7066         .f = cmd_set_qmap_parsed,
7067         .data = NULL,
7068         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7069                 "Set statistics mapping value on tx|rx queue_id of port_id",
7070         .tokens = {
7071                 (void *)&cmd_setqmap_set,
7072                 (void *)&cmd_setqmap_qmap,
7073                 (void *)&cmd_setqmap_what,
7074                 (void *)&cmd_setqmap_portid,
7075                 (void *)&cmd_setqmap_queueid,
7076                 (void *)&cmd_setqmap_mapvalue,
7077                 NULL,
7078         },
7079 };
7080
7081 /* *** CONFIGURE UNICAST HASH TABLE *** */
7082 struct cmd_set_uc_hash_table {
7083         cmdline_fixed_string_t set;
7084         cmdline_fixed_string_t port;
7085         portid_t port_id;
7086         cmdline_fixed_string_t what;
7087         struct ether_addr address;
7088         cmdline_fixed_string_t mode;
7089 };
7090
7091 static void
7092 cmd_set_uc_hash_parsed(void *parsed_result,
7093                        __attribute__((unused)) struct cmdline *cl,
7094                        __attribute__((unused)) void *data)
7095 {
7096         int ret=0;
7097         struct cmd_set_uc_hash_table *res = parsed_result;
7098
7099         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7100
7101         if (strcmp(res->what, "uta") == 0)
7102                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7103                                                 &res->address,(uint8_t)is_on);
7104         if (ret < 0)
7105                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7106
7107 }
7108
7109 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7110         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7111                                  set, "set");
7112 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7113         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7114                                  port, "port");
7115 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7116         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7117                               port_id, UINT16);
7118 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7119         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7120                                  what, "uta");
7121 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7122         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7123                                 address);
7124 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7125         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7126                                  mode, "on#off");
7127
7128 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7129         .f = cmd_set_uc_hash_parsed,
7130         .data = NULL,
7131         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7132         .tokens = {
7133                 (void *)&cmd_set_uc_hash_set,
7134                 (void *)&cmd_set_uc_hash_port,
7135                 (void *)&cmd_set_uc_hash_portid,
7136                 (void *)&cmd_set_uc_hash_what,
7137                 (void *)&cmd_set_uc_hash_mac,
7138                 (void *)&cmd_set_uc_hash_mode,
7139                 NULL,
7140         },
7141 };
7142
7143 struct cmd_set_uc_all_hash_table {
7144         cmdline_fixed_string_t set;
7145         cmdline_fixed_string_t port;
7146         portid_t port_id;
7147         cmdline_fixed_string_t what;
7148         cmdline_fixed_string_t value;
7149         cmdline_fixed_string_t mode;
7150 };
7151
7152 static void
7153 cmd_set_uc_all_hash_parsed(void *parsed_result,
7154                        __attribute__((unused)) struct cmdline *cl,
7155                        __attribute__((unused)) void *data)
7156 {
7157         int ret=0;
7158         struct cmd_set_uc_all_hash_table *res = parsed_result;
7159
7160         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7161
7162         if ((strcmp(res->what, "uta") == 0) &&
7163                 (strcmp(res->value, "all") == 0))
7164                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7165         if (ret < 0)
7166                 printf("bad unicast hash table parameter,"
7167                         "return code = %d \n", ret);
7168 }
7169
7170 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7171         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7172                                  set, "set");
7173 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7174         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7175                                  port, "port");
7176 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7177         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7178                               port_id, UINT16);
7179 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7180         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7181                                  what, "uta");
7182 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7183         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7184                                 value,"all");
7185 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7186         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7187                                  mode, "on#off");
7188
7189 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7190         .f = cmd_set_uc_all_hash_parsed,
7191         .data = NULL,
7192         .help_str = "set port <port_id> uta all on|off",
7193         .tokens = {
7194                 (void *)&cmd_set_uc_all_hash_set,
7195                 (void *)&cmd_set_uc_all_hash_port,
7196                 (void *)&cmd_set_uc_all_hash_portid,
7197                 (void *)&cmd_set_uc_all_hash_what,
7198                 (void *)&cmd_set_uc_all_hash_value,
7199                 (void *)&cmd_set_uc_all_hash_mode,
7200                 NULL,
7201         },
7202 };
7203
7204 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7205 struct cmd_set_vf_macvlan_filter {
7206         cmdline_fixed_string_t set;
7207         cmdline_fixed_string_t port;
7208         portid_t port_id;
7209         cmdline_fixed_string_t vf;
7210         uint8_t vf_id;
7211         struct ether_addr address;
7212         cmdline_fixed_string_t filter_type;
7213         cmdline_fixed_string_t mode;
7214 };
7215
7216 static void
7217 cmd_set_vf_macvlan_parsed(void *parsed_result,
7218                        __attribute__((unused)) struct cmdline *cl,
7219                        __attribute__((unused)) void *data)
7220 {
7221         int is_on, ret = 0;
7222         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7223         struct rte_eth_mac_filter filter;
7224
7225         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7226
7227         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7228
7229         /* set VF MAC filter */
7230         filter.is_vf = 1;
7231
7232         /* set VF ID */
7233         filter.dst_id = res->vf_id;
7234
7235         if (!strcmp(res->filter_type, "exact-mac"))
7236                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7237         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7238                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7239         else if (!strcmp(res->filter_type, "hashmac"))
7240                 filter.filter_type = RTE_MAC_HASH_MATCH;
7241         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7242                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7243
7244         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7245
7246         if (is_on)
7247                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7248                                         RTE_ETH_FILTER_MACVLAN,
7249                                         RTE_ETH_FILTER_ADD,
7250                                          &filter);
7251         else
7252                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7253                                         RTE_ETH_FILTER_MACVLAN,
7254                                         RTE_ETH_FILTER_DELETE,
7255                                         &filter);
7256
7257         if (ret < 0)
7258                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7259
7260 }
7261
7262 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7263         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7264                                  set, "set");
7265 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7267                                  port, "port");
7268 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7269         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7270                               port_id, UINT16);
7271 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7272         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7273                                  vf, "vf");
7274 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7275         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7276                                 vf_id, UINT8);
7277 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7278         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7279                                 address);
7280 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7281         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7282                                 filter_type, "exact-mac#exact-mac-vlan"
7283                                 "#hashmac#hashmac-vlan");
7284 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7285         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7286                                  mode, "on#off");
7287
7288 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7289         .f = cmd_set_vf_macvlan_parsed,
7290         .data = NULL,
7291         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7292                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7293                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7294                 "hash match rule: hash match of MAC and exact match of VLAN",
7295         .tokens = {
7296                 (void *)&cmd_set_vf_macvlan_set,
7297                 (void *)&cmd_set_vf_macvlan_port,
7298                 (void *)&cmd_set_vf_macvlan_portid,
7299                 (void *)&cmd_set_vf_macvlan_vf,
7300                 (void *)&cmd_set_vf_macvlan_vf_id,
7301                 (void *)&cmd_set_vf_macvlan_mac,
7302                 (void *)&cmd_set_vf_macvlan_filter_type,
7303                 (void *)&cmd_set_vf_macvlan_mode,
7304                 NULL,
7305         },
7306 };
7307
7308 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7309 struct cmd_set_vf_traffic {
7310         cmdline_fixed_string_t set;
7311         cmdline_fixed_string_t port;
7312         portid_t port_id;
7313         cmdline_fixed_string_t vf;
7314         uint8_t vf_id;
7315         cmdline_fixed_string_t what;
7316         cmdline_fixed_string_t mode;
7317 };
7318
7319 static void
7320 cmd_set_vf_traffic_parsed(void *parsed_result,
7321                        __attribute__((unused)) struct cmdline *cl,
7322                        __attribute__((unused)) void *data)
7323 {
7324         struct cmd_set_vf_traffic *res = parsed_result;
7325         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7326         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7327
7328         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7329 }
7330
7331 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7332         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7333                                  set, "set");
7334 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7335         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7336                                  port, "port");
7337 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7338         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7339                               port_id, UINT16);
7340 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7341         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7342                                  vf, "vf");
7343 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7344         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7345                               vf_id, UINT8);
7346 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7347         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7348                                  what, "tx#rx");
7349 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7350         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7351                                  mode, "on#off");
7352
7353 cmdline_parse_inst_t cmd_set_vf_traffic = {
7354         .f = cmd_set_vf_traffic_parsed,
7355         .data = NULL,
7356         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7357         .tokens = {
7358                 (void *)&cmd_setvf_traffic_set,
7359                 (void *)&cmd_setvf_traffic_port,
7360                 (void *)&cmd_setvf_traffic_portid,
7361                 (void *)&cmd_setvf_traffic_vf,
7362                 (void *)&cmd_setvf_traffic_vfid,
7363                 (void *)&cmd_setvf_traffic_what,
7364                 (void *)&cmd_setvf_traffic_mode,
7365                 NULL,
7366         },
7367 };
7368
7369 /* *** CONFIGURE VF RECEIVE MODE *** */
7370 struct cmd_set_vf_rxmode {
7371         cmdline_fixed_string_t set;
7372         cmdline_fixed_string_t port;
7373         portid_t port_id;
7374         cmdline_fixed_string_t vf;
7375         uint8_t vf_id;
7376         cmdline_fixed_string_t what;
7377         cmdline_fixed_string_t mode;
7378         cmdline_fixed_string_t on;
7379 };
7380
7381 static void
7382 cmd_set_vf_rxmode_parsed(void *parsed_result,
7383                        __attribute__((unused)) struct cmdline *cl,
7384                        __attribute__((unused)) void *data)
7385 {
7386         int ret = -ENOTSUP;
7387         uint16_t rx_mode = 0;
7388         struct cmd_set_vf_rxmode *res = parsed_result;
7389
7390         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7391         if (!strcmp(res->what,"rxmode")) {
7392                 if (!strcmp(res->mode, "AUPE"))
7393                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7394                 else if (!strcmp(res->mode, "ROPE"))
7395                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7396                 else if (!strcmp(res->mode, "BAM"))
7397                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7398                 else if (!strncmp(res->mode, "MPE",3))
7399                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7400         }
7401
7402 #ifdef RTE_LIBRTE_IXGBE_PMD
7403         if (ret == -ENOTSUP)
7404                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7405                                                   rx_mode, (uint8_t)is_on);
7406 #endif
7407 #ifdef RTE_LIBRTE_BNXT_PMD
7408         if (ret == -ENOTSUP)
7409                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7410                                                  rx_mode, (uint8_t)is_on);
7411 #endif
7412         if (ret < 0)
7413                 printf("bad VF receive mode parameter, return code = %d \n",
7414                 ret);
7415 }
7416
7417 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7418         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7419                                  set, "set");
7420 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7422                                  port, "port");
7423 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7424         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7425                               port_id, UINT16);
7426 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7427         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7428                                  vf, "vf");
7429 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7430         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7431                               vf_id, UINT8);
7432 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7433         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7434                                  what, "rxmode");
7435 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7437                                  mode, "AUPE#ROPE#BAM#MPE");
7438 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7440                                  on, "on#off");
7441
7442 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7443         .f = cmd_set_vf_rxmode_parsed,
7444         .data = NULL,
7445         .help_str = "set port <port_id> vf <vf_id> rxmode "
7446                 "AUPE|ROPE|BAM|MPE on|off",
7447         .tokens = {
7448                 (void *)&cmd_set_vf_rxmode_set,
7449                 (void *)&cmd_set_vf_rxmode_port,
7450                 (void *)&cmd_set_vf_rxmode_portid,
7451                 (void *)&cmd_set_vf_rxmode_vf,
7452                 (void *)&cmd_set_vf_rxmode_vfid,
7453                 (void *)&cmd_set_vf_rxmode_what,
7454                 (void *)&cmd_set_vf_rxmode_mode,
7455                 (void *)&cmd_set_vf_rxmode_on,
7456                 NULL,
7457         },
7458 };
7459
7460 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7461 struct cmd_vf_mac_addr_result {
7462         cmdline_fixed_string_t mac_addr_cmd;
7463         cmdline_fixed_string_t what;
7464         cmdline_fixed_string_t port;
7465         uint16_t port_num;
7466         cmdline_fixed_string_t vf;
7467         uint8_t vf_num;
7468         struct ether_addr address;
7469 };
7470
7471 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7472                 __attribute__((unused)) struct cmdline *cl,
7473                 __attribute__((unused)) void *data)
7474 {
7475         struct cmd_vf_mac_addr_result *res = parsed_result;
7476         int ret = -ENOTSUP;
7477
7478         if (strcmp(res->what, "add") != 0)
7479                 return;
7480
7481 #ifdef RTE_LIBRTE_I40E_PMD
7482         if (ret == -ENOTSUP)
7483                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7484                                                    &res->address);
7485 #endif
7486 #ifdef RTE_LIBRTE_BNXT_PMD
7487         if (ret == -ENOTSUP)
7488                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7489                                                 res->vf_num);
7490 #endif
7491
7492         if(ret < 0)
7493                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7494
7495 }
7496
7497 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7498         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7499                                 mac_addr_cmd,"mac_addr");
7500 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7501         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7502                                 what,"add");
7503 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7504         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7505                                 port,"port");
7506 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7507         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7508                                 port_num, UINT16);
7509 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7510         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7511                                 vf,"vf");
7512 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7513         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7514                                 vf_num, UINT8);
7515 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7516         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7517                                 address);
7518
7519 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7520         .f = cmd_vf_mac_addr_parsed,
7521         .data = (void *)0,
7522         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7523                 "Add MAC address filtering for a VF on port_id",
7524         .tokens = {
7525                 (void *)&cmd_vf_mac_addr_cmd,
7526                 (void *)&cmd_vf_mac_addr_what,
7527                 (void *)&cmd_vf_mac_addr_port,
7528                 (void *)&cmd_vf_mac_addr_portnum,
7529                 (void *)&cmd_vf_mac_addr_vf,
7530                 (void *)&cmd_vf_mac_addr_vfnum,
7531                 (void *)&cmd_vf_mac_addr_addr,
7532                 NULL,
7533         },
7534 };
7535
7536 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7537 struct cmd_vf_rx_vlan_filter {
7538         cmdline_fixed_string_t rx_vlan;
7539         cmdline_fixed_string_t what;
7540         uint16_t vlan_id;
7541         cmdline_fixed_string_t port;
7542         portid_t port_id;
7543         cmdline_fixed_string_t vf;
7544         uint64_t vf_mask;
7545 };
7546
7547 static void
7548 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7549                           __attribute__((unused)) struct cmdline *cl,
7550                           __attribute__((unused)) void *data)
7551 {
7552         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7553         int ret = -ENOTSUP;
7554
7555         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7556
7557 #ifdef RTE_LIBRTE_IXGBE_PMD
7558         if (ret == -ENOTSUP)
7559                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7560                                 res->vlan_id, res->vf_mask, is_add);
7561 #endif
7562 #ifdef RTE_LIBRTE_I40E_PMD
7563         if (ret == -ENOTSUP)
7564                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7565                                 res->vlan_id, res->vf_mask, is_add);
7566 #endif
7567 #ifdef RTE_LIBRTE_BNXT_PMD
7568         if (ret == -ENOTSUP)
7569                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7570                                 res->vlan_id, res->vf_mask, is_add);
7571 #endif
7572
7573         switch (ret) {
7574         case 0:
7575                 break;
7576         case -EINVAL:
7577                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7578                                 res->vlan_id, res->vf_mask);
7579                 break;
7580         case -ENODEV:
7581                 printf("invalid port_id %d\n", res->port_id);
7582                 break;
7583         case -ENOTSUP:
7584                 printf("function not implemented or supported\n");
7585                 break;
7586         default:
7587                 printf("programming error: (%s)\n", strerror(-ret));
7588         }
7589 }
7590
7591 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7592         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7593                                  rx_vlan, "rx_vlan");
7594 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7595         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7596                                  what, "add#rm");
7597 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7598         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7599                               vlan_id, UINT16);
7600 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7601         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7602                                  port, "port");
7603 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7604         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7605                               port_id, UINT16);
7606 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7607         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7608                                  vf, "vf");
7609 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7610         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7611                               vf_mask, UINT64);
7612
7613 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7614         .f = cmd_vf_rx_vlan_filter_parsed,
7615         .data = NULL,
7616         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7617                 "(vf_mask = hexadecimal VF mask)",
7618         .tokens = {
7619                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7620                 (void *)&cmd_vf_rx_vlan_filter_what,
7621                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7622                 (void *)&cmd_vf_rx_vlan_filter_port,
7623                 (void *)&cmd_vf_rx_vlan_filter_portid,
7624                 (void *)&cmd_vf_rx_vlan_filter_vf,
7625                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7626                 NULL,
7627         },
7628 };
7629
7630 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7631 struct cmd_queue_rate_limit_result {
7632         cmdline_fixed_string_t set;
7633         cmdline_fixed_string_t port;
7634         uint16_t port_num;
7635         cmdline_fixed_string_t queue;
7636         uint8_t queue_num;
7637         cmdline_fixed_string_t rate;
7638         uint16_t rate_num;
7639 };
7640
7641 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7642                 __attribute__((unused)) struct cmdline *cl,
7643                 __attribute__((unused)) void *data)
7644 {
7645         struct cmd_queue_rate_limit_result *res = parsed_result;
7646         int ret = 0;
7647
7648         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7649                 && (strcmp(res->queue, "queue") == 0)
7650                 && (strcmp(res->rate, "rate") == 0))
7651                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7652                                         res->rate_num);
7653         if (ret < 0)
7654                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7655
7656 }
7657
7658 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7659         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7660                                 set, "set");
7661 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7662         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7663                                 port, "port");
7664 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7665         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7666                                 port_num, UINT16);
7667 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7668         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7669                                 queue, "queue");
7670 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7671         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7672                                 queue_num, UINT8);
7673 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7674         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7675                                 rate, "rate");
7676 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7677         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7678                                 rate_num, UINT16);
7679
7680 cmdline_parse_inst_t cmd_queue_rate_limit = {
7681         .f = cmd_queue_rate_limit_parsed,
7682         .data = (void *)0,
7683         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7684                 "Set rate limit for a queue on port_id",
7685         .tokens = {
7686                 (void *)&cmd_queue_rate_limit_set,
7687                 (void *)&cmd_queue_rate_limit_port,
7688                 (void *)&cmd_queue_rate_limit_portnum,
7689                 (void *)&cmd_queue_rate_limit_queue,
7690                 (void *)&cmd_queue_rate_limit_queuenum,
7691                 (void *)&cmd_queue_rate_limit_rate,
7692                 (void *)&cmd_queue_rate_limit_ratenum,
7693                 NULL,
7694         },
7695 };
7696
7697 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7698 struct cmd_vf_rate_limit_result {
7699         cmdline_fixed_string_t set;
7700         cmdline_fixed_string_t port;
7701         uint16_t port_num;
7702         cmdline_fixed_string_t vf;
7703         uint8_t vf_num;
7704         cmdline_fixed_string_t rate;
7705         uint16_t rate_num;
7706         cmdline_fixed_string_t q_msk;
7707         uint64_t q_msk_val;
7708 };
7709
7710 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7711                 __attribute__((unused)) struct cmdline *cl,
7712                 __attribute__((unused)) void *data)
7713 {
7714         struct cmd_vf_rate_limit_result *res = parsed_result;
7715         int ret = 0;
7716
7717         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7718                 && (strcmp(res->vf, "vf") == 0)
7719                 && (strcmp(res->rate, "rate") == 0)
7720                 && (strcmp(res->q_msk, "queue_mask") == 0))
7721                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7722                                         res->rate_num, res->q_msk_val);
7723         if (ret < 0)
7724                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7725
7726 }
7727
7728 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7729         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7730                                 set, "set");
7731 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7732         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7733                                 port, "port");
7734 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7735         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7736                                 port_num, UINT16);
7737 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7738         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7739                                 vf, "vf");
7740 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7741         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7742                                 vf_num, UINT8);
7743 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7744         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7745                                 rate, "rate");
7746 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7747         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7748                                 rate_num, UINT16);
7749 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7750         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7751                                 q_msk, "queue_mask");
7752 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7753         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7754                                 q_msk_val, UINT64);
7755
7756 cmdline_parse_inst_t cmd_vf_rate_limit = {
7757         .f = cmd_vf_rate_limit_parsed,
7758         .data = (void *)0,
7759         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7760                 "queue_mask <queue_mask_value>: "
7761                 "Set rate limit for queues of VF on port_id",
7762         .tokens = {
7763                 (void *)&cmd_vf_rate_limit_set,
7764                 (void *)&cmd_vf_rate_limit_port,
7765                 (void *)&cmd_vf_rate_limit_portnum,
7766                 (void *)&cmd_vf_rate_limit_vf,
7767                 (void *)&cmd_vf_rate_limit_vfnum,
7768                 (void *)&cmd_vf_rate_limit_rate,
7769                 (void *)&cmd_vf_rate_limit_ratenum,
7770                 (void *)&cmd_vf_rate_limit_q_msk,
7771                 (void *)&cmd_vf_rate_limit_q_msk_val,
7772                 NULL,
7773         },
7774 };
7775
7776 /* *** ADD TUNNEL FILTER OF A PORT *** */
7777 struct cmd_tunnel_filter_result {
7778         cmdline_fixed_string_t cmd;
7779         cmdline_fixed_string_t what;
7780         portid_t port_id;
7781         struct ether_addr outer_mac;
7782         struct ether_addr inner_mac;
7783         cmdline_ipaddr_t ip_value;
7784         uint16_t inner_vlan;
7785         cmdline_fixed_string_t tunnel_type;
7786         cmdline_fixed_string_t filter_type;
7787         uint32_t tenant_id;
7788         uint16_t queue_num;
7789 };
7790
7791 static void
7792 cmd_tunnel_filter_parsed(void *parsed_result,
7793                           __attribute__((unused)) struct cmdline *cl,
7794                           __attribute__((unused)) void *data)
7795 {
7796         struct cmd_tunnel_filter_result *res = parsed_result;
7797         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7798         int ret = 0;
7799
7800         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7801
7802         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7803         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7804         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7805
7806         if (res->ip_value.family == AF_INET) {
7807                 tunnel_filter_conf.ip_addr.ipv4_addr =
7808                         res->ip_value.addr.ipv4.s_addr;
7809                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7810         } else {
7811                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7812                         &(res->ip_value.addr.ipv6),
7813                         sizeof(struct in6_addr));
7814                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7815         }
7816
7817         if (!strcmp(res->filter_type, "imac-ivlan"))
7818                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7819         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7820                 tunnel_filter_conf.filter_type =
7821                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7822         else if (!strcmp(res->filter_type, "imac-tenid"))
7823                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7824         else if (!strcmp(res->filter_type, "imac"))
7825                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7826         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7827                 tunnel_filter_conf.filter_type =
7828                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7829         else if (!strcmp(res->filter_type, "oip"))
7830                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7831         else if (!strcmp(res->filter_type, "iip"))
7832                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7833         else {
7834                 printf("The filter type is not supported");
7835                 return;
7836         }
7837
7838         if (!strcmp(res->tunnel_type, "vxlan"))
7839                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7840         else if (!strcmp(res->tunnel_type, "nvgre"))
7841                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7842         else if (!strcmp(res->tunnel_type, "ipingre"))
7843                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7844         else {
7845                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7846                 return;
7847         }
7848
7849         tunnel_filter_conf.tenant_id = res->tenant_id;
7850         tunnel_filter_conf.queue_id = res->queue_num;
7851         if (!strcmp(res->what, "add"))
7852                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7853                                         RTE_ETH_FILTER_TUNNEL,
7854                                         RTE_ETH_FILTER_ADD,
7855                                         &tunnel_filter_conf);
7856         else
7857                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7858                                         RTE_ETH_FILTER_TUNNEL,
7859                                         RTE_ETH_FILTER_DELETE,
7860                                         &tunnel_filter_conf);
7861         if (ret < 0)
7862                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7863                                 strerror(-ret));
7864
7865 }
7866 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7867         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7868         cmd, "tunnel_filter");
7869 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7870         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7871         what, "add#rm");
7872 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7873         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7874         port_id, UINT16);
7875 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7876         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7877         outer_mac);
7878 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7879         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7880         inner_mac);
7881 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7882         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7883         inner_vlan, UINT16);
7884 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7885         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7886         ip_value);
7887 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7888         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7889         tunnel_type, "vxlan#nvgre#ipingre");
7890
7891 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7892         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7893         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7894                 "imac#omac-imac-tenid");
7895 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7896         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7897         tenant_id, UINT32);
7898 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7899         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7900         queue_num, UINT16);
7901
7902 cmdline_parse_inst_t cmd_tunnel_filter = {
7903         .f = cmd_tunnel_filter_parsed,
7904         .data = (void *)0,
7905         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7906                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7907                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7908                 "<queue_id>: Add/Rm tunnel filter of a port",
7909         .tokens = {
7910                 (void *)&cmd_tunnel_filter_cmd,
7911                 (void *)&cmd_tunnel_filter_what,
7912                 (void *)&cmd_tunnel_filter_port_id,
7913                 (void *)&cmd_tunnel_filter_outer_mac,
7914                 (void *)&cmd_tunnel_filter_inner_mac,
7915                 (void *)&cmd_tunnel_filter_ip_value,
7916                 (void *)&cmd_tunnel_filter_innner_vlan,
7917                 (void *)&cmd_tunnel_filter_tunnel_type,
7918                 (void *)&cmd_tunnel_filter_filter_type,
7919                 (void *)&cmd_tunnel_filter_tenant_id,
7920                 (void *)&cmd_tunnel_filter_queue_num,
7921                 NULL,
7922         },
7923 };
7924
7925 /* *** CONFIGURE TUNNEL UDP PORT *** */
7926 struct cmd_tunnel_udp_config {
7927         cmdline_fixed_string_t cmd;
7928         cmdline_fixed_string_t what;
7929         uint16_t udp_port;
7930         portid_t port_id;
7931 };
7932
7933 static void
7934 cmd_tunnel_udp_config_parsed(void *parsed_result,
7935                           __attribute__((unused)) struct cmdline *cl,
7936                           __attribute__((unused)) void *data)
7937 {
7938         struct cmd_tunnel_udp_config *res = parsed_result;
7939         struct rte_eth_udp_tunnel tunnel_udp;
7940         int ret;
7941
7942         tunnel_udp.udp_port = res->udp_port;
7943
7944         if (!strcmp(res->cmd, "rx_vxlan_port"))
7945                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7946
7947         if (!strcmp(res->what, "add"))
7948                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7949                                                       &tunnel_udp);
7950         else
7951                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7952                                                          &tunnel_udp);
7953
7954         if (ret < 0)
7955                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7956 }
7957
7958 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7959         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7960                                 cmd, "rx_vxlan_port");
7961 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7962         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7963                                 what, "add#rm");
7964 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7965         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7966                                 udp_port, UINT16);
7967 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7968         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7969                                 port_id, UINT16);
7970
7971 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7972         .f = cmd_tunnel_udp_config_parsed,
7973         .data = (void *)0,
7974         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7975                 "Add/Remove a tunneling UDP port filter",
7976         .tokens = {
7977                 (void *)&cmd_tunnel_udp_config_cmd,
7978                 (void *)&cmd_tunnel_udp_config_what,
7979                 (void *)&cmd_tunnel_udp_config_udp_port,
7980                 (void *)&cmd_tunnel_udp_config_port_id,
7981                 NULL,
7982         },
7983 };
7984
7985 /* *** GLOBAL CONFIG *** */
7986 struct cmd_global_config_result {
7987         cmdline_fixed_string_t cmd;
7988         portid_t port_id;
7989         cmdline_fixed_string_t cfg_type;
7990         uint8_t len;
7991 };
7992
7993 static void
7994 cmd_global_config_parsed(void *parsed_result,
7995                          __attribute__((unused)) struct cmdline *cl,
7996                          __attribute__((unused)) void *data)
7997 {
7998         struct cmd_global_config_result *res = parsed_result;
7999         struct rte_eth_global_cfg conf;
8000         int ret;
8001
8002         memset(&conf, 0, sizeof(conf));
8003         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8004         conf.cfg.gre_key_len = res->len;
8005         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8006                                       RTE_ETH_FILTER_SET, &conf);
8007         if (ret != 0)
8008                 printf("Global config error\n");
8009 }
8010
8011 cmdline_parse_token_string_t cmd_global_config_cmd =
8012         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8013                 "global_config");
8014 cmdline_parse_token_num_t cmd_global_config_port_id =
8015         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8016                                UINT16);
8017 cmdline_parse_token_string_t cmd_global_config_type =
8018         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8019                 cfg_type, "gre-key-len");
8020 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8021         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8022                 len, UINT8);
8023
8024 cmdline_parse_inst_t cmd_global_config = {
8025         .f = cmd_global_config_parsed,
8026         .data = (void *)NULL,
8027         .help_str = "global_config <port_id> gre-key-len <key_len>",
8028         .tokens = {
8029                 (void *)&cmd_global_config_cmd,
8030                 (void *)&cmd_global_config_port_id,
8031                 (void *)&cmd_global_config_type,
8032                 (void *)&cmd_global_config_gre_key_len,
8033                 NULL,
8034         },
8035 };
8036
8037 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8038 struct cmd_set_mirror_mask_result {
8039         cmdline_fixed_string_t set;
8040         cmdline_fixed_string_t port;
8041         portid_t port_id;
8042         cmdline_fixed_string_t mirror;
8043         uint8_t rule_id;
8044         cmdline_fixed_string_t what;
8045         cmdline_fixed_string_t value;
8046         cmdline_fixed_string_t dstpool;
8047         uint8_t dstpool_id;
8048         cmdline_fixed_string_t on;
8049 };
8050
8051 cmdline_parse_token_string_t cmd_mirror_mask_set =
8052         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8053                                 set, "set");
8054 cmdline_parse_token_string_t cmd_mirror_mask_port =
8055         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8056                                 port, "port");
8057 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8058         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8059                                 port_id, UINT16);
8060 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8061         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8062                                 mirror, "mirror-rule");
8063 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8064         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8065                                 rule_id, UINT8);
8066 cmdline_parse_token_string_t cmd_mirror_mask_what =
8067         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8068                                 what, "pool-mirror-up#pool-mirror-down"
8069                                       "#vlan-mirror");
8070 cmdline_parse_token_string_t cmd_mirror_mask_value =
8071         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8072                                 value, NULL);
8073 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8074         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8075                                 dstpool, "dst-pool");
8076 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8077         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8078                                 dstpool_id, UINT8);
8079 cmdline_parse_token_string_t cmd_mirror_mask_on =
8080         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8081                                 on, "on#off");
8082
8083 static void
8084 cmd_set_mirror_mask_parsed(void *parsed_result,
8085                        __attribute__((unused)) struct cmdline *cl,
8086                        __attribute__((unused)) void *data)
8087 {
8088         int ret,nb_item,i;
8089         struct cmd_set_mirror_mask_result *res = parsed_result;
8090         struct rte_eth_mirror_conf mr_conf;
8091
8092         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8093
8094         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8095
8096         mr_conf.dst_pool = res->dstpool_id;
8097
8098         if (!strcmp(res->what, "pool-mirror-up")) {
8099                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8100                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8101         } else if (!strcmp(res->what, "pool-mirror-down")) {
8102                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8103                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8104         } else if (!strcmp(res->what, "vlan-mirror")) {
8105                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8106                 nb_item = parse_item_list(res->value, "vlan",
8107                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8108                 if (nb_item <= 0)
8109                         return;
8110
8111                 for (i = 0; i < nb_item; i++) {
8112                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8113                                 printf("Invalid vlan_id: must be < 4096\n");
8114                                 return;
8115                         }
8116
8117                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8118                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8119                 }
8120         }
8121
8122         if (!strcmp(res->on, "on"))
8123                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8124                                                 res->rule_id, 1);
8125         else
8126                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8127                                                 res->rule_id, 0);
8128         if (ret < 0)
8129                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8130 }
8131
8132 cmdline_parse_inst_t cmd_set_mirror_mask = {
8133                 .f = cmd_set_mirror_mask_parsed,
8134                 .data = NULL,
8135                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8136                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8137                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8138                 .tokens = {
8139                         (void *)&cmd_mirror_mask_set,
8140                         (void *)&cmd_mirror_mask_port,
8141                         (void *)&cmd_mirror_mask_portid,
8142                         (void *)&cmd_mirror_mask_mirror,
8143                         (void *)&cmd_mirror_mask_ruleid,
8144                         (void *)&cmd_mirror_mask_what,
8145                         (void *)&cmd_mirror_mask_value,
8146                         (void *)&cmd_mirror_mask_dstpool,
8147                         (void *)&cmd_mirror_mask_poolid,
8148                         (void *)&cmd_mirror_mask_on,
8149                         NULL,
8150                 },
8151 };
8152
8153 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8154 struct cmd_set_mirror_link_result {
8155         cmdline_fixed_string_t set;
8156         cmdline_fixed_string_t port;
8157         portid_t port_id;
8158         cmdline_fixed_string_t mirror;
8159         uint8_t rule_id;
8160         cmdline_fixed_string_t what;
8161         cmdline_fixed_string_t dstpool;
8162         uint8_t dstpool_id;
8163         cmdline_fixed_string_t on;
8164 };
8165
8166 cmdline_parse_token_string_t cmd_mirror_link_set =
8167         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8168                                  set, "set");
8169 cmdline_parse_token_string_t cmd_mirror_link_port =
8170         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8171                                 port, "port");
8172 cmdline_parse_token_num_t cmd_mirror_link_portid =
8173         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8174                                 port_id, UINT16);
8175 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8176         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8177                                 mirror, "mirror-rule");
8178 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8179         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8180                             rule_id, UINT8);
8181 cmdline_parse_token_string_t cmd_mirror_link_what =
8182         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8183                                 what, "uplink-mirror#downlink-mirror");
8184 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8185         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8186                                 dstpool, "dst-pool");
8187 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8188         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8189                                 dstpool_id, UINT8);
8190 cmdline_parse_token_string_t cmd_mirror_link_on =
8191         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8192                                 on, "on#off");
8193
8194 static void
8195 cmd_set_mirror_link_parsed(void *parsed_result,
8196                        __attribute__((unused)) struct cmdline *cl,
8197                        __attribute__((unused)) void *data)
8198 {
8199         int ret;
8200         struct cmd_set_mirror_link_result *res = parsed_result;
8201         struct rte_eth_mirror_conf mr_conf;
8202
8203         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8204         if (!strcmp(res->what, "uplink-mirror"))
8205                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8206         else
8207                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8208
8209         mr_conf.dst_pool = res->dstpool_id;
8210
8211         if (!strcmp(res->on, "on"))
8212                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8213                                                 res->rule_id, 1);
8214         else
8215                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8216                                                 res->rule_id, 0);
8217
8218         /* check the return value and print it if is < 0 */
8219         if (ret < 0)
8220                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8221
8222 }
8223
8224 cmdline_parse_inst_t cmd_set_mirror_link = {
8225                 .f = cmd_set_mirror_link_parsed,
8226                 .data = NULL,
8227                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8228                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8229                 .tokens = {
8230                         (void *)&cmd_mirror_link_set,
8231                         (void *)&cmd_mirror_link_port,
8232                         (void *)&cmd_mirror_link_portid,
8233                         (void *)&cmd_mirror_link_mirror,
8234                         (void *)&cmd_mirror_link_ruleid,
8235                         (void *)&cmd_mirror_link_what,
8236                         (void *)&cmd_mirror_link_dstpool,
8237                         (void *)&cmd_mirror_link_poolid,
8238                         (void *)&cmd_mirror_link_on,
8239                         NULL,
8240                 },
8241 };
8242
8243 /* *** RESET VM MIRROR RULE *** */
8244 struct cmd_rm_mirror_rule_result {
8245         cmdline_fixed_string_t reset;
8246         cmdline_fixed_string_t port;
8247         portid_t port_id;
8248         cmdline_fixed_string_t mirror;
8249         uint8_t rule_id;
8250 };
8251
8252 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8253         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8254                                  reset, "reset");
8255 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8256         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8257                                 port, "port");
8258 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8259         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8260                                 port_id, UINT16);
8261 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8262         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8263                                 mirror, "mirror-rule");
8264 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8265         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8266                                 rule_id, UINT8);
8267
8268 static void
8269 cmd_reset_mirror_rule_parsed(void *parsed_result,
8270                        __attribute__((unused)) struct cmdline *cl,
8271                        __attribute__((unused)) void *data)
8272 {
8273         int ret;
8274         struct cmd_set_mirror_link_result *res = parsed_result;
8275         /* check rule_id */
8276         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8277         if(ret < 0)
8278                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8279 }
8280
8281 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8282                 .f = cmd_reset_mirror_rule_parsed,
8283                 .data = NULL,
8284                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8285                 .tokens = {
8286                         (void *)&cmd_rm_mirror_rule_reset,
8287                         (void *)&cmd_rm_mirror_rule_port,
8288                         (void *)&cmd_rm_mirror_rule_portid,
8289                         (void *)&cmd_rm_mirror_rule_mirror,
8290                         (void *)&cmd_rm_mirror_rule_ruleid,
8291                         NULL,
8292                 },
8293 };
8294
8295 /* ******************************************************************************** */
8296
8297 struct cmd_dump_result {
8298         cmdline_fixed_string_t dump;
8299 };
8300
8301 static void
8302 dump_struct_sizes(void)
8303 {
8304 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8305         DUMP_SIZE(struct rte_mbuf);
8306         DUMP_SIZE(struct rte_mempool);
8307         DUMP_SIZE(struct rte_ring);
8308 #undef DUMP_SIZE
8309 }
8310
8311 static void cmd_dump_parsed(void *parsed_result,
8312                             __attribute__((unused)) struct cmdline *cl,
8313                             __attribute__((unused)) void *data)
8314 {
8315         struct cmd_dump_result *res = parsed_result;
8316
8317         if (!strcmp(res->dump, "dump_physmem"))
8318                 rte_dump_physmem_layout(stdout);
8319         else if (!strcmp(res->dump, "dump_memzone"))
8320                 rte_memzone_dump(stdout);
8321         else if (!strcmp(res->dump, "dump_struct_sizes"))
8322                 dump_struct_sizes();
8323         else if (!strcmp(res->dump, "dump_ring"))
8324                 rte_ring_list_dump(stdout);
8325         else if (!strcmp(res->dump, "dump_mempool"))
8326                 rte_mempool_list_dump(stdout);
8327         else if (!strcmp(res->dump, "dump_devargs"))
8328                 rte_eal_devargs_dump(stdout);
8329         else if (!strcmp(res->dump, "dump_log_types"))
8330                 rte_log_dump(stdout);
8331 }
8332
8333 cmdline_parse_token_string_t cmd_dump_dump =
8334         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8335                 "dump_physmem#"
8336                 "dump_memzone#"
8337                 "dump_struct_sizes#"
8338                 "dump_ring#"
8339                 "dump_mempool#"
8340                 "dump_devargs#"
8341                 "dump_log_types");
8342
8343 cmdline_parse_inst_t cmd_dump = {
8344         .f = cmd_dump_parsed,  /* function to call */
8345         .data = NULL,      /* 2nd arg of func */
8346         .help_str = "Dump status",
8347         .tokens = {        /* token list, NULL terminated */
8348                 (void *)&cmd_dump_dump,
8349                 NULL,
8350         },
8351 };
8352
8353 /* ******************************************************************************** */
8354
8355 struct cmd_dump_one_result {
8356         cmdline_fixed_string_t dump;
8357         cmdline_fixed_string_t name;
8358 };
8359
8360 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8361                                 __attribute__((unused)) void *data)
8362 {
8363         struct cmd_dump_one_result *res = parsed_result;
8364
8365         if (!strcmp(res->dump, "dump_ring")) {
8366                 struct rte_ring *r;
8367                 r = rte_ring_lookup(res->name);
8368                 if (r == NULL) {
8369                         cmdline_printf(cl, "Cannot find ring\n");
8370                         return;
8371                 }
8372                 rte_ring_dump(stdout, r);
8373         } else if (!strcmp(res->dump, "dump_mempool")) {
8374                 struct rte_mempool *mp;
8375                 mp = rte_mempool_lookup(res->name);
8376                 if (mp == NULL) {
8377                         cmdline_printf(cl, "Cannot find mempool\n");
8378                         return;
8379                 }
8380                 rte_mempool_dump(stdout, mp);
8381         }
8382 }
8383
8384 cmdline_parse_token_string_t cmd_dump_one_dump =
8385         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8386                                  "dump_ring#dump_mempool");
8387
8388 cmdline_parse_token_string_t cmd_dump_one_name =
8389         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8390
8391 cmdline_parse_inst_t cmd_dump_one = {
8392         .f = cmd_dump_one_parsed,  /* function to call */
8393         .data = NULL,      /* 2nd arg of func */
8394         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8395         .tokens = {        /* token list, NULL terminated */
8396                 (void *)&cmd_dump_one_dump,
8397                 (void *)&cmd_dump_one_name,
8398                 NULL,
8399         },
8400 };
8401
8402 /* *** Add/Del syn filter *** */
8403 struct cmd_syn_filter_result {
8404         cmdline_fixed_string_t filter;
8405         portid_t port_id;
8406         cmdline_fixed_string_t ops;
8407         cmdline_fixed_string_t priority;
8408         cmdline_fixed_string_t high;
8409         cmdline_fixed_string_t queue;
8410         uint16_t queue_id;
8411 };
8412
8413 static void
8414 cmd_syn_filter_parsed(void *parsed_result,
8415                         __attribute__((unused)) struct cmdline *cl,
8416                         __attribute__((unused)) void *data)
8417 {
8418         struct cmd_syn_filter_result *res = parsed_result;
8419         struct rte_eth_syn_filter syn_filter;
8420         int ret = 0;
8421
8422         ret = rte_eth_dev_filter_supported(res->port_id,
8423                                         RTE_ETH_FILTER_SYN);
8424         if (ret < 0) {
8425                 printf("syn filter is not supported on port %u.\n",
8426                                 res->port_id);
8427                 return;
8428         }
8429
8430         memset(&syn_filter, 0, sizeof(syn_filter));
8431
8432         if (!strcmp(res->ops, "add")) {
8433                 if (!strcmp(res->high, "high"))
8434                         syn_filter.hig_pri = 1;
8435                 else
8436                         syn_filter.hig_pri = 0;
8437
8438                 syn_filter.queue = res->queue_id;
8439                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8440                                                 RTE_ETH_FILTER_SYN,
8441                                                 RTE_ETH_FILTER_ADD,
8442                                                 &syn_filter);
8443         } else
8444                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8445                                                 RTE_ETH_FILTER_SYN,
8446                                                 RTE_ETH_FILTER_DELETE,
8447                                                 &syn_filter);
8448
8449         if (ret < 0)
8450                 printf("syn filter programming error: (%s)\n",
8451                                 strerror(-ret));
8452 }
8453
8454 cmdline_parse_token_string_t cmd_syn_filter_filter =
8455         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8456         filter, "syn_filter");
8457 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8458         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8459         port_id, UINT16);
8460 cmdline_parse_token_string_t cmd_syn_filter_ops =
8461         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8462         ops, "add#del");
8463 cmdline_parse_token_string_t cmd_syn_filter_priority =
8464         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8465                                 priority, "priority");
8466 cmdline_parse_token_string_t cmd_syn_filter_high =
8467         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8468                                 high, "high#low");
8469 cmdline_parse_token_string_t cmd_syn_filter_queue =
8470         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8471                                 queue, "queue");
8472 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8473         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8474                                 queue_id, UINT16);
8475
8476 cmdline_parse_inst_t cmd_syn_filter = {
8477         .f = cmd_syn_filter_parsed,
8478         .data = NULL,
8479         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8480                 "<queue_id>: Add/Delete syn filter",
8481         .tokens = {
8482                 (void *)&cmd_syn_filter_filter,
8483                 (void *)&cmd_syn_filter_port_id,
8484                 (void *)&cmd_syn_filter_ops,
8485                 (void *)&cmd_syn_filter_priority,
8486                 (void *)&cmd_syn_filter_high,
8487                 (void *)&cmd_syn_filter_queue,
8488                 (void *)&cmd_syn_filter_queue_id,
8489                 NULL,
8490         },
8491 };
8492
8493 /* *** queue region set *** */
8494 struct cmd_queue_region_result {
8495         cmdline_fixed_string_t set;
8496         cmdline_fixed_string_t port;
8497         portid_t port_id;
8498         cmdline_fixed_string_t cmd;
8499         cmdline_fixed_string_t region;
8500         uint8_t  region_id;
8501         cmdline_fixed_string_t queue_start_index;
8502         uint8_t  queue_id;
8503         cmdline_fixed_string_t queue_num;
8504         uint8_t  queue_num_value;
8505 };
8506
8507 static void
8508 cmd_queue_region_parsed(void *parsed_result,
8509                         __attribute__((unused)) struct cmdline *cl,
8510                         __attribute__((unused)) void *data)
8511 {
8512         struct cmd_queue_region_result *res = parsed_result;
8513         int ret = -ENOTSUP;
8514 #ifdef RTE_LIBRTE_I40E_PMD
8515         struct rte_pmd_i40e_queue_region_conf region_conf;
8516         enum rte_pmd_i40e_queue_region_op op_type;
8517 #endif
8518
8519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8520                 return;
8521
8522 #ifdef RTE_LIBRTE_I40E_PMD
8523         memset(&region_conf, 0, sizeof(region_conf));
8524         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8525         region_conf.region_id = res->region_id;
8526         region_conf.queue_num = res->queue_num_value;
8527         region_conf.queue_start_index = res->queue_id;
8528
8529         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8530                                 op_type, &region_conf);
8531 #endif
8532
8533         switch (ret) {
8534         case 0:
8535                 break;
8536         case -ENOTSUP:
8537                 printf("function not implemented or supported\n");
8538                 break;
8539         default:
8540                 printf("queue region config error: (%s)\n", strerror(-ret));
8541         }
8542 }
8543
8544 cmdline_parse_token_string_t cmd_queue_region_set =
8545 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8546                 set, "set");
8547 cmdline_parse_token_string_t cmd_queue_region_port =
8548         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8549 cmdline_parse_token_num_t cmd_queue_region_port_id =
8550         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8551                                 port_id, UINT16);
8552 cmdline_parse_token_string_t cmd_queue_region_cmd =
8553         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8554                                  cmd, "queue-region");
8555 cmdline_parse_token_string_t cmd_queue_region_id =
8556         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8557                                 region, "region_id");
8558 cmdline_parse_token_num_t cmd_queue_region_index =
8559         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8560                                 region_id, UINT8);
8561 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8562         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8563                                 queue_start_index, "queue_start_index");
8564 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8565         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8566                                 queue_id, UINT8);
8567 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8568         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8569                                 queue_num, "queue_num");
8570 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8571         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8572                                 queue_num_value, UINT8);
8573
8574 cmdline_parse_inst_t cmd_queue_region = {
8575         .f = cmd_queue_region_parsed,
8576         .data = NULL,
8577         .help_str = "set port <port_id> queue-region region_id <value> "
8578                 "queue_start_index <value> queue_num <value>: Set a queue region",
8579         .tokens = {
8580                 (void *)&cmd_queue_region_set,
8581                 (void *)&cmd_queue_region_port,
8582                 (void *)&cmd_queue_region_port_id,
8583                 (void *)&cmd_queue_region_cmd,
8584                 (void *)&cmd_queue_region_id,
8585                 (void *)&cmd_queue_region_index,
8586                 (void *)&cmd_queue_region_queue_start_index,
8587                 (void *)&cmd_queue_region_queue_id,
8588                 (void *)&cmd_queue_region_queue_num,
8589                 (void *)&cmd_queue_region_queue_num_value,
8590                 NULL,
8591         },
8592 };
8593
8594 /* *** queue region and flowtype set *** */
8595 struct cmd_region_flowtype_result {
8596         cmdline_fixed_string_t set;
8597         cmdline_fixed_string_t port;
8598         portid_t port_id;
8599         cmdline_fixed_string_t cmd;
8600         cmdline_fixed_string_t region;
8601         uint8_t  region_id;
8602         cmdline_fixed_string_t flowtype;
8603         uint8_t  flowtype_id;
8604 };
8605
8606 static void
8607 cmd_region_flowtype_parsed(void *parsed_result,
8608                         __attribute__((unused)) struct cmdline *cl,
8609                         __attribute__((unused)) void *data)
8610 {
8611         struct cmd_region_flowtype_result *res = parsed_result;
8612         int ret = -ENOTSUP;
8613 #ifdef RTE_LIBRTE_I40E_PMD
8614         struct rte_pmd_i40e_queue_region_conf region_conf;
8615         enum rte_pmd_i40e_queue_region_op op_type;
8616 #endif
8617
8618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8619                 return;
8620
8621 #ifdef RTE_LIBRTE_I40E_PMD
8622         memset(&region_conf, 0, sizeof(region_conf));
8623
8624         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8625         region_conf.region_id = res->region_id;
8626         region_conf.hw_flowtype = res->flowtype_id;
8627
8628         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8629                         op_type, &region_conf);
8630 #endif
8631
8632         switch (ret) {
8633         case 0:
8634                 break;
8635         case -ENOTSUP:
8636                 printf("function not implemented or supported\n");
8637                 break;
8638         default:
8639                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8640         }
8641 }
8642
8643 cmdline_parse_token_string_t cmd_region_flowtype_set =
8644 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8645                                 set, "set");
8646 cmdline_parse_token_string_t cmd_region_flowtype_port =
8647         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8648                                 port, "port");
8649 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8650         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8651                                 port_id, UINT16);
8652 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8653         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8654                                 cmd, "queue-region");
8655 cmdline_parse_token_string_t cmd_region_flowtype_index =
8656         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8657                                 region, "region_id");
8658 cmdline_parse_token_num_t cmd_region_flowtype_id =
8659         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8660                                 region_id, UINT8);
8661 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8662         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8663                                 flowtype, "flowtype");
8664 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8665         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8666                                 flowtype_id, UINT8);
8667 cmdline_parse_inst_t cmd_region_flowtype = {
8668         .f = cmd_region_flowtype_parsed,
8669         .data = NULL,
8670         .help_str = "set port <port_id> queue-region region_id <value> "
8671                 "flowtype <value>: Set a flowtype region index",
8672         .tokens = {
8673                 (void *)&cmd_region_flowtype_set,
8674                 (void *)&cmd_region_flowtype_port,
8675                 (void *)&cmd_region_flowtype_port_index,
8676                 (void *)&cmd_region_flowtype_cmd,
8677                 (void *)&cmd_region_flowtype_index,
8678                 (void *)&cmd_region_flowtype_id,
8679                 (void *)&cmd_region_flowtype_flow_index,
8680                 (void *)&cmd_region_flowtype_flow_id,
8681                 NULL,
8682         },
8683 };
8684
8685 /* *** User Priority (UP) to queue region (region_id) set *** */
8686 struct cmd_user_priority_region_result {
8687         cmdline_fixed_string_t set;
8688         cmdline_fixed_string_t port;
8689         portid_t port_id;
8690         cmdline_fixed_string_t cmd;
8691         cmdline_fixed_string_t user_priority;
8692         uint8_t  user_priority_id;
8693         cmdline_fixed_string_t region;
8694         uint8_t  region_id;
8695 };
8696
8697 static void
8698 cmd_user_priority_region_parsed(void *parsed_result,
8699                         __attribute__((unused)) struct cmdline *cl,
8700                         __attribute__((unused)) void *data)
8701 {
8702         struct cmd_user_priority_region_result *res = parsed_result;
8703         int ret = -ENOTSUP;
8704 #ifdef RTE_LIBRTE_I40E_PMD
8705         struct rte_pmd_i40e_queue_region_conf region_conf;
8706         enum rte_pmd_i40e_queue_region_op op_type;
8707 #endif
8708
8709         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8710                 return;
8711
8712 #ifdef RTE_LIBRTE_I40E_PMD
8713         memset(&region_conf, 0, sizeof(region_conf));
8714         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8715         region_conf.user_priority = res->user_priority_id;
8716         region_conf.region_id = res->region_id;
8717
8718         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8719                                 op_type, &region_conf);
8720 #endif
8721
8722         switch (ret) {
8723         case 0:
8724                 break;
8725         case -ENOTSUP:
8726                 printf("function not implemented or supported\n");
8727                 break;
8728         default:
8729                 printf("user_priority region config error: (%s)\n",
8730                                 strerror(-ret));
8731         }
8732 }
8733
8734 cmdline_parse_token_string_t cmd_user_priority_region_set =
8735         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8736                                 set, "set");
8737 cmdline_parse_token_string_t cmd_user_priority_region_port =
8738         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8739                                 port, "port");
8740 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8741         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8742                                 port_id, UINT16);
8743 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8744         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8745                                 cmd, "queue-region");
8746 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8747         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8748                                 user_priority, "UP");
8749 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8750         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8751                                 user_priority_id, UINT8);
8752 cmdline_parse_token_string_t cmd_user_priority_region_region =
8753         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8754                                 region, "region_id");
8755 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8756         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8757                                 region_id, UINT8);
8758
8759 cmdline_parse_inst_t cmd_user_priority_region = {
8760         .f = cmd_user_priority_region_parsed,
8761         .data = NULL,
8762         .help_str = "set port <port_id> queue-region UP <value> "
8763                 "region_id <value>: Set the mapping of User Priority (UP) "
8764                 "to queue region (region_id) ",
8765         .tokens = {
8766                 (void *)&cmd_user_priority_region_set,
8767                 (void *)&cmd_user_priority_region_port,
8768                 (void *)&cmd_user_priority_region_port_index,
8769                 (void *)&cmd_user_priority_region_cmd,
8770                 (void *)&cmd_user_priority_region_UP,
8771                 (void *)&cmd_user_priority_region_UP_id,
8772                 (void *)&cmd_user_priority_region_region,
8773                 (void *)&cmd_user_priority_region_region_id,
8774                 NULL,
8775         },
8776 };
8777
8778 /* *** flush all queue region related configuration *** */
8779 struct cmd_flush_queue_region_result {
8780         cmdline_fixed_string_t set;
8781         cmdline_fixed_string_t port;
8782         portid_t port_id;
8783         cmdline_fixed_string_t cmd;
8784         cmdline_fixed_string_t flush;
8785         cmdline_fixed_string_t what;
8786 };
8787
8788 static void
8789 cmd_flush_queue_region_parsed(void *parsed_result,
8790                         __attribute__((unused)) struct cmdline *cl,
8791                         __attribute__((unused)) void *data)
8792 {
8793         struct cmd_flush_queue_region_result *res = parsed_result;
8794         int ret = -ENOTSUP;
8795 #ifdef RTE_LIBRTE_I40E_PMD
8796         struct rte_pmd_i40e_queue_region_conf region_conf;
8797         enum rte_pmd_i40e_queue_region_op op_type;
8798 #endif
8799
8800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8801                 return;
8802
8803 #ifdef RTE_LIBRTE_I40E_PMD
8804         memset(&region_conf, 0, sizeof(region_conf));
8805
8806         if (strcmp(res->what, "on") == 0)
8807                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8808         else
8809                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8810
8811         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8812                                 op_type, &region_conf);
8813 #endif
8814
8815         switch (ret) {
8816         case 0:
8817                 break;
8818         case -ENOTSUP:
8819                 printf("function not implemented or supported\n");
8820                 break;
8821         default:
8822                 printf("queue region config flush error: (%s)\n",
8823                                 strerror(-ret));
8824         }
8825 }
8826
8827 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8828         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8829                                 set, "set");
8830 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8831         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8832                                 port, "port");
8833 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8834         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8835                                 port_id, UINT16);
8836 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8837         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8838                                 cmd, "queue-region");
8839 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8840         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8841                                 flush, "flush");
8842 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8843         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8844                                 what, "on#off");
8845
8846 cmdline_parse_inst_t cmd_flush_queue_region = {
8847         .f = cmd_flush_queue_region_parsed,
8848         .data = NULL,
8849         .help_str = "set port <port_id> queue-region flush on|off"
8850                 ": flush all queue region related configuration",
8851         .tokens = {
8852                 (void *)&cmd_flush_queue_region_set,
8853                 (void *)&cmd_flush_queue_region_port,
8854                 (void *)&cmd_flush_queue_region_port_index,
8855                 (void *)&cmd_flush_queue_region_cmd,
8856                 (void *)&cmd_flush_queue_region_flush,
8857                 (void *)&cmd_flush_queue_region_what,
8858                 NULL,
8859         },
8860 };
8861
8862 /* *** get all queue region related configuration info *** */
8863 struct cmd_show_queue_region_info {
8864         cmdline_fixed_string_t show;
8865         cmdline_fixed_string_t port;
8866         portid_t port_id;
8867         cmdline_fixed_string_t cmd;
8868 };
8869
8870 static void
8871 cmd_show_queue_region_info_parsed(void *parsed_result,
8872                         __attribute__((unused)) struct cmdline *cl,
8873                         __attribute__((unused)) void *data)
8874 {
8875         struct cmd_show_queue_region_info *res = parsed_result;
8876         int ret = -ENOTSUP;
8877 #ifdef RTE_LIBRTE_I40E_PMD
8878         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8879         enum rte_pmd_i40e_queue_region_op op_type;
8880 #endif
8881
8882         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8883                 return;
8884
8885 #ifdef RTE_LIBRTE_I40E_PMD
8886         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8887
8888         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8889
8890         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8891                                         op_type, &rte_pmd_regions);
8892
8893         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8894 #endif
8895
8896         switch (ret) {
8897         case 0:
8898                 break;
8899         case -ENOTSUP:
8900                 printf("function not implemented or supported\n");
8901                 break;
8902         default:
8903                 printf("queue region config info show error: (%s)\n",
8904                                 strerror(-ret));
8905         }
8906 }
8907
8908 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
8909 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8910                                 show, "show");
8911 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
8912         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8913                                 port, "port");
8914 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
8915         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
8916                                 port_id, UINT16);
8917 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
8918         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8919                                 cmd, "queue-region");
8920
8921 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
8922         .f = cmd_show_queue_region_info_parsed,
8923         .data = NULL,
8924         .help_str = "show port <port_id> queue-region"
8925                 ": show all queue region related configuration info",
8926         .tokens = {
8927                 (void *)&cmd_show_queue_region_info_get,
8928                 (void *)&cmd_show_queue_region_info_port,
8929                 (void *)&cmd_show_queue_region_info_port_index,
8930                 (void *)&cmd_show_queue_region_info_cmd,
8931                 NULL,
8932         },
8933 };
8934
8935 /* *** ADD/REMOVE A 2tuple FILTER *** */
8936 struct cmd_2tuple_filter_result {
8937         cmdline_fixed_string_t filter;
8938         portid_t port_id;
8939         cmdline_fixed_string_t ops;
8940         cmdline_fixed_string_t dst_port;
8941         uint16_t dst_port_value;
8942         cmdline_fixed_string_t protocol;
8943         uint8_t protocol_value;
8944         cmdline_fixed_string_t mask;
8945         uint8_t  mask_value;
8946         cmdline_fixed_string_t tcp_flags;
8947         uint8_t tcp_flags_value;
8948         cmdline_fixed_string_t priority;
8949         uint8_t  priority_value;
8950         cmdline_fixed_string_t queue;
8951         uint16_t  queue_id;
8952 };
8953
8954 static void
8955 cmd_2tuple_filter_parsed(void *parsed_result,
8956                         __attribute__((unused)) struct cmdline *cl,
8957                         __attribute__((unused)) void *data)
8958 {
8959         struct rte_eth_ntuple_filter filter;
8960         struct cmd_2tuple_filter_result *res = parsed_result;
8961         int ret = 0;
8962
8963         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8964         if (ret < 0) {
8965                 printf("ntuple filter is not supported on port %u.\n",
8966                         res->port_id);
8967                 return;
8968         }
8969
8970         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8971
8972         filter.flags = RTE_2TUPLE_FLAGS;
8973         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8974         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8975         filter.proto = res->protocol_value;
8976         filter.priority = res->priority_value;
8977         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8978                 printf("nonzero tcp_flags is only meaningful"
8979                         " when protocol is TCP.\n");
8980                 return;
8981         }
8982         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8983                 printf("invalid TCP flags.\n");
8984                 return;
8985         }
8986
8987         if (res->tcp_flags_value != 0) {
8988                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8989                 filter.tcp_flags = res->tcp_flags_value;
8990         }
8991
8992         /* need convert to big endian. */
8993         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8994         filter.queue = res->queue_id;
8995
8996         if (!strcmp(res->ops, "add"))
8997                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8998                                 RTE_ETH_FILTER_NTUPLE,
8999                                 RTE_ETH_FILTER_ADD,
9000                                 &filter);
9001         else
9002                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9003                                 RTE_ETH_FILTER_NTUPLE,
9004                                 RTE_ETH_FILTER_DELETE,
9005                                 &filter);
9006         if (ret < 0)
9007                 printf("2tuple filter programming error: (%s)\n",
9008                         strerror(-ret));
9009
9010 }
9011
9012 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9013         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9014                                  filter, "2tuple_filter");
9015 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9016         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9017                                 port_id, UINT16);
9018 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9019         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9020                                  ops, "add#del");
9021 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9022         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9023                                 dst_port, "dst_port");
9024 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9025         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9026                                 dst_port_value, UINT16);
9027 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9028         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9029                                 protocol, "protocol");
9030 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9031         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9032                                 protocol_value, UINT8);
9033 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9034         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9035                                 mask, "mask");
9036 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9037         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9038                                 mask_value, INT8);
9039 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9040         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9041                                 tcp_flags, "tcp_flags");
9042 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9043         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9044                                 tcp_flags_value, UINT8);
9045 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9046         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9047                                 priority, "priority");
9048 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9049         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9050                                 priority_value, UINT8);
9051 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9052         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9053                                 queue, "queue");
9054 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9055         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9056                                 queue_id, UINT16);
9057
9058 cmdline_parse_inst_t cmd_2tuple_filter = {
9059         .f = cmd_2tuple_filter_parsed,
9060         .data = NULL,
9061         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9062                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9063                 "<queue_id>: Add a 2tuple filter",
9064         .tokens = {
9065                 (void *)&cmd_2tuple_filter_filter,
9066                 (void *)&cmd_2tuple_filter_port_id,
9067                 (void *)&cmd_2tuple_filter_ops,
9068                 (void *)&cmd_2tuple_filter_dst_port,
9069                 (void *)&cmd_2tuple_filter_dst_port_value,
9070                 (void *)&cmd_2tuple_filter_protocol,
9071                 (void *)&cmd_2tuple_filter_protocol_value,
9072                 (void *)&cmd_2tuple_filter_mask,
9073                 (void *)&cmd_2tuple_filter_mask_value,
9074                 (void *)&cmd_2tuple_filter_tcp_flags,
9075                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9076                 (void *)&cmd_2tuple_filter_priority,
9077                 (void *)&cmd_2tuple_filter_priority_value,
9078                 (void *)&cmd_2tuple_filter_queue,
9079                 (void *)&cmd_2tuple_filter_queue_id,
9080                 NULL,
9081         },
9082 };
9083
9084 /* *** ADD/REMOVE A 5tuple FILTER *** */
9085 struct cmd_5tuple_filter_result {
9086         cmdline_fixed_string_t filter;
9087         portid_t port_id;
9088         cmdline_fixed_string_t ops;
9089         cmdline_fixed_string_t dst_ip;
9090         cmdline_ipaddr_t dst_ip_value;
9091         cmdline_fixed_string_t src_ip;
9092         cmdline_ipaddr_t src_ip_value;
9093         cmdline_fixed_string_t dst_port;
9094         uint16_t dst_port_value;
9095         cmdline_fixed_string_t src_port;
9096         uint16_t src_port_value;
9097         cmdline_fixed_string_t protocol;
9098         uint8_t protocol_value;
9099         cmdline_fixed_string_t mask;
9100         uint8_t  mask_value;
9101         cmdline_fixed_string_t tcp_flags;
9102         uint8_t tcp_flags_value;
9103         cmdline_fixed_string_t priority;
9104         uint8_t  priority_value;
9105         cmdline_fixed_string_t queue;
9106         uint16_t  queue_id;
9107 };
9108
9109 static void
9110 cmd_5tuple_filter_parsed(void *parsed_result,
9111                         __attribute__((unused)) struct cmdline *cl,
9112                         __attribute__((unused)) void *data)
9113 {
9114         struct rte_eth_ntuple_filter filter;
9115         struct cmd_5tuple_filter_result *res = parsed_result;
9116         int ret = 0;
9117
9118         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9119         if (ret < 0) {
9120                 printf("ntuple filter is not supported on port %u.\n",
9121                         res->port_id);
9122                 return;
9123         }
9124
9125         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9126
9127         filter.flags = RTE_5TUPLE_FLAGS;
9128         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9129         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9130         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9131         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9132         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9133         filter.proto = res->protocol_value;
9134         filter.priority = res->priority_value;
9135         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9136                 printf("nonzero tcp_flags is only meaningful"
9137                         " when protocol is TCP.\n");
9138                 return;
9139         }
9140         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9141                 printf("invalid TCP flags.\n");
9142                 return;
9143         }
9144
9145         if (res->tcp_flags_value != 0) {
9146                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9147                 filter.tcp_flags = res->tcp_flags_value;
9148         }
9149
9150         if (res->dst_ip_value.family == AF_INET)
9151                 /* no need to convert, already big endian. */
9152                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9153         else {
9154                 if (filter.dst_ip_mask == 0) {
9155                         printf("can not support ipv6 involved compare.\n");
9156                         return;
9157                 }
9158                 filter.dst_ip = 0;
9159         }
9160
9161         if (res->src_ip_value.family == AF_INET)
9162                 /* no need to convert, already big endian. */
9163                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9164         else {
9165                 if (filter.src_ip_mask == 0) {
9166                         printf("can not support ipv6 involved compare.\n");
9167                         return;
9168                 }
9169                 filter.src_ip = 0;
9170         }
9171         /* need convert to big endian. */
9172         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9173         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9174         filter.queue = res->queue_id;
9175
9176         if (!strcmp(res->ops, "add"))
9177                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9178                                 RTE_ETH_FILTER_NTUPLE,
9179                                 RTE_ETH_FILTER_ADD,
9180                                 &filter);
9181         else
9182                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9183                                 RTE_ETH_FILTER_NTUPLE,
9184                                 RTE_ETH_FILTER_DELETE,
9185                                 &filter);
9186         if (ret < 0)
9187                 printf("5tuple filter programming error: (%s)\n",
9188                         strerror(-ret));
9189 }
9190
9191 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9192         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9193                                  filter, "5tuple_filter");
9194 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9195         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9196                                 port_id, UINT16);
9197 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9198         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9199                                  ops, "add#del");
9200 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9201         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9202                                 dst_ip, "dst_ip");
9203 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9204         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9205                                 dst_ip_value);
9206 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9207         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9208                                 src_ip, "src_ip");
9209 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9210         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9211                                 src_ip_value);
9212 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9213         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9214                                 dst_port, "dst_port");
9215 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9216         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9217                                 dst_port_value, UINT16);
9218 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9219         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9220                                 src_port, "src_port");
9221 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9222         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9223                                 src_port_value, UINT16);
9224 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9225         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9226                                 protocol, "protocol");
9227 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9228         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9229                                 protocol_value, UINT8);
9230 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9231         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9232                                 mask, "mask");
9233 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9234         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9235                                 mask_value, INT8);
9236 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9237         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9238                                 tcp_flags, "tcp_flags");
9239 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9240         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9241                                 tcp_flags_value, UINT8);
9242 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9243         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9244                                 priority, "priority");
9245 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9246         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9247                                 priority_value, UINT8);
9248 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9249         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9250                                 queue, "queue");
9251 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9252         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9253                                 queue_id, UINT16);
9254
9255 cmdline_parse_inst_t cmd_5tuple_filter = {
9256         .f = cmd_5tuple_filter_parsed,
9257         .data = NULL,
9258         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9259                 "src_ip <value> dst_port <value> src_port <value> "
9260                 "protocol <value>  mask <value> tcp_flags <value> "
9261                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9262         .tokens = {
9263                 (void *)&cmd_5tuple_filter_filter,
9264                 (void *)&cmd_5tuple_filter_port_id,
9265                 (void *)&cmd_5tuple_filter_ops,
9266                 (void *)&cmd_5tuple_filter_dst_ip,
9267                 (void *)&cmd_5tuple_filter_dst_ip_value,
9268                 (void *)&cmd_5tuple_filter_src_ip,
9269                 (void *)&cmd_5tuple_filter_src_ip_value,
9270                 (void *)&cmd_5tuple_filter_dst_port,
9271                 (void *)&cmd_5tuple_filter_dst_port_value,
9272                 (void *)&cmd_5tuple_filter_src_port,
9273                 (void *)&cmd_5tuple_filter_src_port_value,
9274                 (void *)&cmd_5tuple_filter_protocol,
9275                 (void *)&cmd_5tuple_filter_protocol_value,
9276                 (void *)&cmd_5tuple_filter_mask,
9277                 (void *)&cmd_5tuple_filter_mask_value,
9278                 (void *)&cmd_5tuple_filter_tcp_flags,
9279                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9280                 (void *)&cmd_5tuple_filter_priority,
9281                 (void *)&cmd_5tuple_filter_priority_value,
9282                 (void *)&cmd_5tuple_filter_queue,
9283                 (void *)&cmd_5tuple_filter_queue_id,
9284                 NULL,
9285         },
9286 };
9287
9288 /* *** ADD/REMOVE A flex FILTER *** */
9289 struct cmd_flex_filter_result {
9290         cmdline_fixed_string_t filter;
9291         cmdline_fixed_string_t ops;
9292         portid_t port_id;
9293         cmdline_fixed_string_t len;
9294         uint8_t len_value;
9295         cmdline_fixed_string_t bytes;
9296         cmdline_fixed_string_t bytes_value;
9297         cmdline_fixed_string_t mask;
9298         cmdline_fixed_string_t mask_value;
9299         cmdline_fixed_string_t priority;
9300         uint8_t priority_value;
9301         cmdline_fixed_string_t queue;
9302         uint16_t queue_id;
9303 };
9304
9305 static int xdigit2val(unsigned char c)
9306 {
9307         int val;
9308         if (isdigit(c))
9309                 val = c - '0';
9310         else if (isupper(c))
9311                 val = c - 'A' + 10;
9312         else
9313                 val = c - 'a' + 10;
9314         return val;
9315 }
9316
9317 static void
9318 cmd_flex_filter_parsed(void *parsed_result,
9319                           __attribute__((unused)) struct cmdline *cl,
9320                           __attribute__((unused)) void *data)
9321 {
9322         int ret = 0;
9323         struct rte_eth_flex_filter filter;
9324         struct cmd_flex_filter_result *res = parsed_result;
9325         char *bytes_ptr, *mask_ptr;
9326         uint16_t len, i, j = 0;
9327         char c;
9328         int val;
9329         uint8_t byte = 0;
9330
9331         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9332                 printf("the len exceed the max length 128\n");
9333                 return;
9334         }
9335         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9336         filter.len = res->len_value;
9337         filter.priority = res->priority_value;
9338         filter.queue = res->queue_id;
9339         bytes_ptr = res->bytes_value;
9340         mask_ptr = res->mask_value;
9341
9342          /* translate bytes string to array. */
9343         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9344                 (bytes_ptr[1] == 'X')))
9345                 bytes_ptr += 2;
9346         len = strnlen(bytes_ptr, res->len_value * 2);
9347         if (len == 0 || (len % 8 != 0)) {
9348                 printf("please check len and bytes input\n");
9349                 return;
9350         }
9351         for (i = 0; i < len; i++) {
9352                 c = bytes_ptr[i];
9353                 if (isxdigit(c) == 0) {
9354                         /* invalid characters. */
9355                         printf("invalid input\n");
9356                         return;
9357                 }
9358                 val = xdigit2val(c);
9359                 if (i % 2) {
9360                         byte |= val;
9361                         filter.bytes[j] = byte;
9362                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9363                         j++;
9364                         byte = 0;
9365                 } else
9366                         byte |= val << 4;
9367         }
9368         printf("\n");
9369          /* translate mask string to uint8_t array. */
9370         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9371                 (mask_ptr[1] == 'X')))
9372                 mask_ptr += 2;
9373         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9374         if (len == 0) {
9375                 printf("invalid input\n");
9376                 return;
9377         }
9378         j = 0;
9379         byte = 0;
9380         for (i = 0; i < len; i++) {
9381                 c = mask_ptr[i];
9382                 if (isxdigit(c) == 0) {
9383                         /* invalid characters. */
9384                         printf("invalid input\n");
9385                         return;
9386                 }
9387                 val = xdigit2val(c);
9388                 if (i % 2) {
9389                         byte |= val;
9390                         filter.mask[j] = byte;
9391                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9392                         j++;
9393                         byte = 0;
9394                 } else
9395                         byte |= val << 4;
9396         }
9397         printf("\n");
9398
9399         if (!strcmp(res->ops, "add"))
9400                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9401                                 RTE_ETH_FILTER_FLEXIBLE,
9402                                 RTE_ETH_FILTER_ADD,
9403                                 &filter);
9404         else
9405                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9406                                 RTE_ETH_FILTER_FLEXIBLE,
9407                                 RTE_ETH_FILTER_DELETE,
9408                                 &filter);
9409
9410         if (ret < 0)
9411                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9412 }
9413
9414 cmdline_parse_token_string_t cmd_flex_filter_filter =
9415         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9416                                 filter, "flex_filter");
9417 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9418         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9419                                 port_id, UINT16);
9420 cmdline_parse_token_string_t cmd_flex_filter_ops =
9421         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9422                                 ops, "add#del");
9423 cmdline_parse_token_string_t cmd_flex_filter_len =
9424         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9425                                 len, "len");
9426 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9427         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9428                                 len_value, UINT8);
9429 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9430         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9431                                 bytes, "bytes");
9432 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9433         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9434                                 bytes_value, NULL);
9435 cmdline_parse_token_string_t cmd_flex_filter_mask =
9436         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9437                                 mask, "mask");
9438 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9439         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9440                                 mask_value, NULL);
9441 cmdline_parse_token_string_t cmd_flex_filter_priority =
9442         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9443                                 priority, "priority");
9444 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9445         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9446                                 priority_value, UINT8);
9447 cmdline_parse_token_string_t cmd_flex_filter_queue =
9448         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9449                                 queue, "queue");
9450 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9451         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9452                                 queue_id, UINT16);
9453 cmdline_parse_inst_t cmd_flex_filter = {
9454         .f = cmd_flex_filter_parsed,
9455         .data = NULL,
9456         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9457                 "<value> mask <value> priority <value> queue <queue_id>: "
9458                 "Add/Del a flex filter",
9459         .tokens = {
9460                 (void *)&cmd_flex_filter_filter,
9461                 (void *)&cmd_flex_filter_port_id,
9462                 (void *)&cmd_flex_filter_ops,
9463                 (void *)&cmd_flex_filter_len,
9464                 (void *)&cmd_flex_filter_len_value,
9465                 (void *)&cmd_flex_filter_bytes,
9466                 (void *)&cmd_flex_filter_bytes_value,
9467                 (void *)&cmd_flex_filter_mask,
9468                 (void *)&cmd_flex_filter_mask_value,
9469                 (void *)&cmd_flex_filter_priority,
9470                 (void *)&cmd_flex_filter_priority_value,
9471                 (void *)&cmd_flex_filter_queue,
9472                 (void *)&cmd_flex_filter_queue_id,
9473                 NULL,
9474         },
9475 };
9476
9477 /* *** Filters Control *** */
9478
9479 /* *** deal with ethertype filter *** */
9480 struct cmd_ethertype_filter_result {
9481         cmdline_fixed_string_t filter;
9482         portid_t port_id;
9483         cmdline_fixed_string_t ops;
9484         cmdline_fixed_string_t mac;
9485         struct ether_addr mac_addr;
9486         cmdline_fixed_string_t ethertype;
9487         uint16_t ethertype_value;
9488         cmdline_fixed_string_t drop;
9489         cmdline_fixed_string_t queue;
9490         uint16_t  queue_id;
9491 };
9492
9493 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9494         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9495                                  filter, "ethertype_filter");
9496 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9497         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9498                               port_id, UINT16);
9499 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9500         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9501                                  ops, "add#del");
9502 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9503         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9504                                  mac, "mac_addr#mac_ignr");
9505 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9506         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9507                                      mac_addr);
9508 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9509         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9510                                  ethertype, "ethertype");
9511 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9512         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9513                               ethertype_value, UINT16);
9514 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9515         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9516                                  drop, "drop#fwd");
9517 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9518         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9519                                  queue, "queue");
9520 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9521         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9522                               queue_id, UINT16);
9523
9524 static void
9525 cmd_ethertype_filter_parsed(void *parsed_result,
9526                           __attribute__((unused)) struct cmdline *cl,
9527                           __attribute__((unused)) void *data)
9528 {
9529         struct cmd_ethertype_filter_result *res = parsed_result;
9530         struct rte_eth_ethertype_filter filter;
9531         int ret = 0;
9532
9533         ret = rte_eth_dev_filter_supported(res->port_id,
9534                         RTE_ETH_FILTER_ETHERTYPE);
9535         if (ret < 0) {
9536                 printf("ethertype filter is not supported on port %u.\n",
9537                         res->port_id);
9538                 return;
9539         }
9540
9541         memset(&filter, 0, sizeof(filter));
9542         if (!strcmp(res->mac, "mac_addr")) {
9543                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9544                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9545                         sizeof(struct ether_addr));
9546         }
9547         if (!strcmp(res->drop, "drop"))
9548                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9549         filter.ether_type = res->ethertype_value;
9550         filter.queue = res->queue_id;
9551
9552         if (!strcmp(res->ops, "add"))
9553                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9554                                 RTE_ETH_FILTER_ETHERTYPE,
9555                                 RTE_ETH_FILTER_ADD,
9556                                 &filter);
9557         else
9558                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9559                                 RTE_ETH_FILTER_ETHERTYPE,
9560                                 RTE_ETH_FILTER_DELETE,
9561                                 &filter);
9562         if (ret < 0)
9563                 printf("ethertype filter programming error: (%s)\n",
9564                         strerror(-ret));
9565 }
9566
9567 cmdline_parse_inst_t cmd_ethertype_filter = {
9568         .f = cmd_ethertype_filter_parsed,
9569         .data = NULL,
9570         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9571                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9572                 "Add or delete an ethertype filter entry",
9573         .tokens = {
9574                 (void *)&cmd_ethertype_filter_filter,
9575                 (void *)&cmd_ethertype_filter_port_id,
9576                 (void *)&cmd_ethertype_filter_ops,
9577                 (void *)&cmd_ethertype_filter_mac,
9578                 (void *)&cmd_ethertype_filter_mac_addr,
9579                 (void *)&cmd_ethertype_filter_ethertype,
9580                 (void *)&cmd_ethertype_filter_ethertype_value,
9581                 (void *)&cmd_ethertype_filter_drop,
9582                 (void *)&cmd_ethertype_filter_queue,
9583                 (void *)&cmd_ethertype_filter_queue_id,
9584                 NULL,
9585         },
9586 };
9587
9588 /* *** deal with flow director filter *** */
9589 struct cmd_flow_director_result {
9590         cmdline_fixed_string_t flow_director_filter;
9591         portid_t port_id;
9592         cmdline_fixed_string_t mode;
9593         cmdline_fixed_string_t mode_value;
9594         cmdline_fixed_string_t ops;
9595         cmdline_fixed_string_t flow;
9596         cmdline_fixed_string_t flow_type;
9597         cmdline_fixed_string_t ether;
9598         uint16_t ether_type;
9599         cmdline_fixed_string_t src;
9600         cmdline_ipaddr_t ip_src;
9601         uint16_t port_src;
9602         cmdline_fixed_string_t dst;
9603         cmdline_ipaddr_t ip_dst;
9604         uint16_t port_dst;
9605         cmdline_fixed_string_t verify_tag;
9606         uint32_t verify_tag_value;
9607         cmdline_ipaddr_t tos;
9608         uint8_t tos_value;
9609         cmdline_ipaddr_t proto;
9610         uint8_t proto_value;
9611         cmdline_ipaddr_t ttl;
9612         uint8_t ttl_value;
9613         cmdline_fixed_string_t vlan;
9614         uint16_t vlan_value;
9615         cmdline_fixed_string_t flexbytes;
9616         cmdline_fixed_string_t flexbytes_value;
9617         cmdline_fixed_string_t pf_vf;
9618         cmdline_fixed_string_t drop;
9619         cmdline_fixed_string_t queue;
9620         uint16_t  queue_id;
9621         cmdline_fixed_string_t fd_id;
9622         uint32_t  fd_id_value;
9623         cmdline_fixed_string_t mac;
9624         struct ether_addr mac_addr;
9625         cmdline_fixed_string_t tunnel;
9626         cmdline_fixed_string_t tunnel_type;
9627         cmdline_fixed_string_t tunnel_id;
9628         uint32_t tunnel_id_value;
9629 };
9630
9631 static inline int
9632 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9633 {
9634         char s[256];
9635         const char *p, *p0 = q_arg;
9636         char *end;
9637         unsigned long int_fld;
9638         char *str_fld[max_num];
9639         int i;
9640         unsigned size;
9641         int ret = -1;
9642
9643         p = strchr(p0, '(');
9644         if (p == NULL)
9645                 return -1;
9646         ++p;
9647         p0 = strchr(p, ')');
9648         if (p0 == NULL)
9649                 return -1;
9650
9651         size = p0 - p;
9652         if (size >= sizeof(s))
9653                 return -1;
9654
9655         snprintf(s, sizeof(s), "%.*s", size, p);
9656         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9657         if (ret < 0 || ret > max_num)
9658                 return -1;
9659         for (i = 0; i < ret; i++) {
9660                 errno = 0;
9661                 int_fld = strtoul(str_fld[i], &end, 0);
9662                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9663                         return -1;
9664                 flexbytes[i] = (uint8_t)int_fld;
9665         }
9666         return ret;
9667 }
9668
9669 static uint16_t
9670 str2flowtype(char *string)
9671 {
9672         uint8_t i = 0;
9673         static const struct {
9674                 char str[32];
9675                 uint16_t type;
9676         } flowtype_str[] = {
9677                 {"raw", RTE_ETH_FLOW_RAW},
9678                 {"ipv4", RTE_ETH_FLOW_IPV4},
9679                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9680                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9681                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9682                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9683                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9684                 {"ipv6", RTE_ETH_FLOW_IPV6},
9685                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9686                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9687                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9688                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9689                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9690                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9691         };
9692
9693         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9694                 if (!strcmp(flowtype_str[i].str, string))
9695                         return flowtype_str[i].type;
9696         }
9697
9698         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9699                 return (uint16_t)atoi(string);
9700
9701         return RTE_ETH_FLOW_UNKNOWN;
9702 }
9703
9704 static enum rte_eth_fdir_tunnel_type
9705 str2fdir_tunneltype(char *string)
9706 {
9707         uint8_t i = 0;
9708
9709         static const struct {
9710                 char str[32];
9711                 enum rte_eth_fdir_tunnel_type type;
9712         } tunneltype_str[] = {
9713                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9714                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9715         };
9716
9717         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9718                 if (!strcmp(tunneltype_str[i].str, string))
9719                         return tunneltype_str[i].type;
9720         }
9721         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9722 }
9723
9724 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9725 do { \
9726         if ((ip_addr).family == AF_INET) \
9727                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9728         else { \
9729                 printf("invalid parameter.\n"); \
9730                 return; \
9731         } \
9732 } while (0)
9733
9734 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9735 do { \
9736         if ((ip_addr).family == AF_INET6) \
9737                 rte_memcpy(&(ip), \
9738                                  &((ip_addr).addr.ipv6), \
9739                                  sizeof(struct in6_addr)); \
9740         else { \
9741                 printf("invalid parameter.\n"); \
9742                 return; \
9743         } \
9744 } while (0)
9745
9746 static void
9747 cmd_flow_director_filter_parsed(void *parsed_result,
9748                           __attribute__((unused)) struct cmdline *cl,
9749                           __attribute__((unused)) void *data)
9750 {
9751         struct cmd_flow_director_result *res = parsed_result;
9752         struct rte_eth_fdir_filter entry;
9753         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9754         char *end;
9755         unsigned long vf_id;
9756         int ret = 0;
9757
9758         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9759         if (ret < 0) {
9760                 printf("flow director is not supported on port %u.\n",
9761                         res->port_id);
9762                 return;
9763         }
9764         memset(flexbytes, 0, sizeof(flexbytes));
9765         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9766
9767         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9768                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9769                         printf("Please set mode to MAC-VLAN.\n");
9770                         return;
9771                 }
9772         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9773                 if (strcmp(res->mode_value, "Tunnel")) {
9774                         printf("Please set mode to Tunnel.\n");
9775                         return;
9776                 }
9777         } else {
9778                 if (strcmp(res->mode_value, "IP")) {
9779                         printf("Please set mode to IP.\n");
9780                         return;
9781                 }
9782                 entry.input.flow_type = str2flowtype(res->flow_type);
9783         }
9784
9785         ret = parse_flexbytes(res->flexbytes_value,
9786                                         flexbytes,
9787                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9788         if (ret < 0) {
9789                 printf("error: Cannot parse flexbytes input.\n");
9790                 return;
9791         }
9792
9793         switch (entry.input.flow_type) {
9794         case RTE_ETH_FLOW_FRAG_IPV4:
9795         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9796                 entry.input.flow.ip4_flow.proto = res->proto_value;
9797                 /* fall-through */
9798         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9799         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9800                 IPV4_ADDR_TO_UINT(res->ip_dst,
9801                         entry.input.flow.ip4_flow.dst_ip);
9802                 IPV4_ADDR_TO_UINT(res->ip_src,
9803                         entry.input.flow.ip4_flow.src_ip);
9804                 entry.input.flow.ip4_flow.tos = res->tos_value;
9805                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9806                 /* need convert to big endian. */
9807                 entry.input.flow.udp4_flow.dst_port =
9808                                 rte_cpu_to_be_16(res->port_dst);
9809                 entry.input.flow.udp4_flow.src_port =
9810                                 rte_cpu_to_be_16(res->port_src);
9811                 break;
9812         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9813                 IPV4_ADDR_TO_UINT(res->ip_dst,
9814                         entry.input.flow.sctp4_flow.ip.dst_ip);
9815                 IPV4_ADDR_TO_UINT(res->ip_src,
9816                         entry.input.flow.sctp4_flow.ip.src_ip);
9817                 entry.input.flow.ip4_flow.tos = res->tos_value;
9818                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9819                 /* need convert to big endian. */
9820                 entry.input.flow.sctp4_flow.dst_port =
9821                                 rte_cpu_to_be_16(res->port_dst);
9822                 entry.input.flow.sctp4_flow.src_port =
9823                                 rte_cpu_to_be_16(res->port_src);
9824                 entry.input.flow.sctp4_flow.verify_tag =
9825                                 rte_cpu_to_be_32(res->verify_tag_value);
9826                 break;
9827         case RTE_ETH_FLOW_FRAG_IPV6:
9828         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9829                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9830                 /* fall-through */
9831         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9832         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9833                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9834                         entry.input.flow.ipv6_flow.dst_ip);
9835                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9836                         entry.input.flow.ipv6_flow.src_ip);
9837                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9838                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9839                 /* need convert to big endian. */
9840                 entry.input.flow.udp6_flow.dst_port =
9841                                 rte_cpu_to_be_16(res->port_dst);
9842                 entry.input.flow.udp6_flow.src_port =
9843                                 rte_cpu_to_be_16(res->port_src);
9844                 break;
9845         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9846                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9847                         entry.input.flow.sctp6_flow.ip.dst_ip);
9848                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9849                         entry.input.flow.sctp6_flow.ip.src_ip);
9850                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9851                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9852                 /* need convert to big endian. */
9853                 entry.input.flow.sctp6_flow.dst_port =
9854                                 rte_cpu_to_be_16(res->port_dst);
9855                 entry.input.flow.sctp6_flow.src_port =
9856                                 rte_cpu_to_be_16(res->port_src);
9857                 entry.input.flow.sctp6_flow.verify_tag =
9858                                 rte_cpu_to_be_32(res->verify_tag_value);
9859                 break;
9860         case RTE_ETH_FLOW_L2_PAYLOAD:
9861                 entry.input.flow.l2_flow.ether_type =
9862                         rte_cpu_to_be_16(res->ether_type);
9863                 break;
9864         default:
9865                 break;
9866         }
9867
9868         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9869                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9870                                  &res->mac_addr,
9871                                  sizeof(struct ether_addr));
9872
9873         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9874                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9875                                  &res->mac_addr,
9876                                  sizeof(struct ether_addr));
9877                 entry.input.flow.tunnel_flow.tunnel_type =
9878                         str2fdir_tunneltype(res->tunnel_type);
9879                 entry.input.flow.tunnel_flow.tunnel_id =
9880                         rte_cpu_to_be_32(res->tunnel_id_value);
9881         }
9882
9883         rte_memcpy(entry.input.flow_ext.flexbytes,
9884                    flexbytes,
9885                    RTE_ETH_FDIR_MAX_FLEXLEN);
9886
9887         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9888
9889         entry.action.flex_off = 0;  /*use 0 by default */
9890         if (!strcmp(res->drop, "drop"))
9891                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9892         else
9893                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9894
9895         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9896             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9897                 if (!strcmp(res->pf_vf, "pf"))
9898                         entry.input.flow_ext.is_vf = 0;
9899                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9900                         struct rte_eth_dev_info dev_info;
9901
9902                         memset(&dev_info, 0, sizeof(dev_info));
9903                         rte_eth_dev_info_get(res->port_id, &dev_info);
9904                         errno = 0;
9905                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9906                         if (errno != 0 || *end != '\0' ||
9907                             vf_id >= dev_info.max_vfs) {
9908                                 printf("invalid parameter %s.\n", res->pf_vf);
9909                                 return;
9910                         }
9911                         entry.input.flow_ext.is_vf = 1;
9912                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9913                 } else {
9914                         printf("invalid parameter %s.\n", res->pf_vf);
9915                         return;
9916                 }
9917         }
9918
9919         /* set to report FD ID by default */
9920         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9921         entry.action.rx_queue = res->queue_id;
9922         entry.soft_id = res->fd_id_value;
9923         if (!strcmp(res->ops, "add"))
9924                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9925                                              RTE_ETH_FILTER_ADD, &entry);
9926         else if (!strcmp(res->ops, "del"))
9927                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9928                                              RTE_ETH_FILTER_DELETE, &entry);
9929         else
9930                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9931                                              RTE_ETH_FILTER_UPDATE, &entry);
9932         if (ret < 0)
9933                 printf("flow director programming error: (%s)\n",
9934                         strerror(-ret));
9935 }
9936
9937 cmdline_parse_token_string_t cmd_flow_director_filter =
9938         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9939                                  flow_director_filter, "flow_director_filter");
9940 cmdline_parse_token_num_t cmd_flow_director_port_id =
9941         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9942                               port_id, UINT16);
9943 cmdline_parse_token_string_t cmd_flow_director_ops =
9944         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9945                                  ops, "add#del#update");
9946 cmdline_parse_token_string_t cmd_flow_director_flow =
9947         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9948                                  flow, "flow");
9949 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9951                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9952                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9953 cmdline_parse_token_string_t cmd_flow_director_ether =
9954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9955                                  ether, "ether");
9956 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9957         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9958                               ether_type, UINT16);
9959 cmdline_parse_token_string_t cmd_flow_director_src =
9960         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9961                                  src, "src");
9962 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9963         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9964                                  ip_src);
9965 cmdline_parse_token_num_t cmd_flow_director_port_src =
9966         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9967                               port_src, UINT16);
9968 cmdline_parse_token_string_t cmd_flow_director_dst =
9969         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9970                                  dst, "dst");
9971 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9972         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9973                                  ip_dst);
9974 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9975         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9976                               port_dst, UINT16);
9977 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9978         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9979                                   verify_tag, "verify_tag");
9980 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9981         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9982                               verify_tag_value, UINT32);
9983 cmdline_parse_token_string_t cmd_flow_director_tos =
9984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9985                                  tos, "tos");
9986 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9987         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9988                               tos_value, UINT8);
9989 cmdline_parse_token_string_t cmd_flow_director_proto =
9990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9991                                  proto, "proto");
9992 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9993         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9994                               proto_value, UINT8);
9995 cmdline_parse_token_string_t cmd_flow_director_ttl =
9996         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9997                                  ttl, "ttl");
9998 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9999         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10000                               ttl_value, UINT8);
10001 cmdline_parse_token_string_t cmd_flow_director_vlan =
10002         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10003                                  vlan, "vlan");
10004 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10005         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10006                               vlan_value, UINT16);
10007 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10008         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10009                                  flexbytes, "flexbytes");
10010 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10011         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10012                               flexbytes_value, NULL);
10013 cmdline_parse_token_string_t cmd_flow_director_drop =
10014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10015                                  drop, "drop#fwd");
10016 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10017         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10018                               pf_vf, NULL);
10019 cmdline_parse_token_string_t cmd_flow_director_queue =
10020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10021                                  queue, "queue");
10022 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10023         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10024                               queue_id, UINT16);
10025 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10026         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10027                                  fd_id, "fd_id");
10028 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10029         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10030                               fd_id_value, UINT32);
10031
10032 cmdline_parse_token_string_t cmd_flow_director_mode =
10033         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10034                                  mode, "mode");
10035 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10037                                  mode_value, "IP");
10038 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10040                                  mode_value, "MAC-VLAN");
10041 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10043                                  mode_value, "Tunnel");
10044 cmdline_parse_token_string_t cmd_flow_director_mac =
10045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10046                                  mac, "mac");
10047 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10048         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10049                                     mac_addr);
10050 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10051         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10052                                  tunnel, "tunnel");
10053 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10054         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10055                                  tunnel_type, "NVGRE#VxLAN");
10056 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10058                                  tunnel_id, "tunnel-id");
10059 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10060         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10061                               tunnel_id_value, UINT32);
10062
10063 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10064         .f = cmd_flow_director_filter_parsed,
10065         .data = NULL,
10066         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10067                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10068                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10069                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10070                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10071                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10072                 "fd_id <fd_id_value>: "
10073                 "Add or delete an ip flow director entry on NIC",
10074         .tokens = {
10075                 (void *)&cmd_flow_director_filter,
10076                 (void *)&cmd_flow_director_port_id,
10077                 (void *)&cmd_flow_director_mode,
10078                 (void *)&cmd_flow_director_mode_ip,
10079                 (void *)&cmd_flow_director_ops,
10080                 (void *)&cmd_flow_director_flow,
10081                 (void *)&cmd_flow_director_flow_type,
10082                 (void *)&cmd_flow_director_src,
10083                 (void *)&cmd_flow_director_ip_src,
10084                 (void *)&cmd_flow_director_dst,
10085                 (void *)&cmd_flow_director_ip_dst,
10086                 (void *)&cmd_flow_director_tos,
10087                 (void *)&cmd_flow_director_tos_value,
10088                 (void *)&cmd_flow_director_proto,
10089                 (void *)&cmd_flow_director_proto_value,
10090                 (void *)&cmd_flow_director_ttl,
10091                 (void *)&cmd_flow_director_ttl_value,
10092                 (void *)&cmd_flow_director_vlan,
10093                 (void *)&cmd_flow_director_vlan_value,
10094                 (void *)&cmd_flow_director_flexbytes,
10095                 (void *)&cmd_flow_director_flexbytes_value,
10096                 (void *)&cmd_flow_director_drop,
10097                 (void *)&cmd_flow_director_pf_vf,
10098                 (void *)&cmd_flow_director_queue,
10099                 (void *)&cmd_flow_director_queue_id,
10100                 (void *)&cmd_flow_director_fd_id,
10101                 (void *)&cmd_flow_director_fd_id_value,
10102                 NULL,
10103         },
10104 };
10105
10106 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10107         .f = cmd_flow_director_filter_parsed,
10108         .data = NULL,
10109         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10110                 "director entry on NIC",
10111         .tokens = {
10112                 (void *)&cmd_flow_director_filter,
10113                 (void *)&cmd_flow_director_port_id,
10114                 (void *)&cmd_flow_director_mode,
10115                 (void *)&cmd_flow_director_mode_ip,
10116                 (void *)&cmd_flow_director_ops,
10117                 (void *)&cmd_flow_director_flow,
10118                 (void *)&cmd_flow_director_flow_type,
10119                 (void *)&cmd_flow_director_src,
10120                 (void *)&cmd_flow_director_ip_src,
10121                 (void *)&cmd_flow_director_port_src,
10122                 (void *)&cmd_flow_director_dst,
10123                 (void *)&cmd_flow_director_ip_dst,
10124                 (void *)&cmd_flow_director_port_dst,
10125                 (void *)&cmd_flow_director_tos,
10126                 (void *)&cmd_flow_director_tos_value,
10127                 (void *)&cmd_flow_director_ttl,
10128                 (void *)&cmd_flow_director_ttl_value,
10129                 (void *)&cmd_flow_director_vlan,
10130                 (void *)&cmd_flow_director_vlan_value,
10131                 (void *)&cmd_flow_director_flexbytes,
10132                 (void *)&cmd_flow_director_flexbytes_value,
10133                 (void *)&cmd_flow_director_drop,
10134                 (void *)&cmd_flow_director_pf_vf,
10135                 (void *)&cmd_flow_director_queue,
10136                 (void *)&cmd_flow_director_queue_id,
10137                 (void *)&cmd_flow_director_fd_id,
10138                 (void *)&cmd_flow_director_fd_id_value,
10139                 NULL,
10140         },
10141 };
10142
10143 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10144         .f = cmd_flow_director_filter_parsed,
10145         .data = NULL,
10146         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10147                 "director entry on NIC",
10148         .tokens = {
10149                 (void *)&cmd_flow_director_filter,
10150                 (void *)&cmd_flow_director_port_id,
10151                 (void *)&cmd_flow_director_mode,
10152                 (void *)&cmd_flow_director_mode_ip,
10153                 (void *)&cmd_flow_director_ops,
10154                 (void *)&cmd_flow_director_flow,
10155                 (void *)&cmd_flow_director_flow_type,
10156                 (void *)&cmd_flow_director_src,
10157                 (void *)&cmd_flow_director_ip_src,
10158                 (void *)&cmd_flow_director_port_dst,
10159                 (void *)&cmd_flow_director_dst,
10160                 (void *)&cmd_flow_director_ip_dst,
10161                 (void *)&cmd_flow_director_port_dst,
10162                 (void *)&cmd_flow_director_verify_tag,
10163                 (void *)&cmd_flow_director_verify_tag_value,
10164                 (void *)&cmd_flow_director_tos,
10165                 (void *)&cmd_flow_director_tos_value,
10166                 (void *)&cmd_flow_director_ttl,
10167                 (void *)&cmd_flow_director_ttl_value,
10168                 (void *)&cmd_flow_director_vlan,
10169                 (void *)&cmd_flow_director_vlan_value,
10170                 (void *)&cmd_flow_director_flexbytes,
10171                 (void *)&cmd_flow_director_flexbytes_value,
10172                 (void *)&cmd_flow_director_drop,
10173                 (void *)&cmd_flow_director_pf_vf,
10174                 (void *)&cmd_flow_director_queue,
10175                 (void *)&cmd_flow_director_queue_id,
10176                 (void *)&cmd_flow_director_fd_id,
10177                 (void *)&cmd_flow_director_fd_id_value,
10178                 NULL,
10179         },
10180 };
10181
10182 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10183         .f = cmd_flow_director_filter_parsed,
10184         .data = NULL,
10185         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10186                 "director entry on NIC",
10187         .tokens = {
10188                 (void *)&cmd_flow_director_filter,
10189                 (void *)&cmd_flow_director_port_id,
10190                 (void *)&cmd_flow_director_mode,
10191                 (void *)&cmd_flow_director_mode_ip,
10192                 (void *)&cmd_flow_director_ops,
10193                 (void *)&cmd_flow_director_flow,
10194                 (void *)&cmd_flow_director_flow_type,
10195                 (void *)&cmd_flow_director_ether,
10196                 (void *)&cmd_flow_director_ether_type,
10197                 (void *)&cmd_flow_director_flexbytes,
10198                 (void *)&cmd_flow_director_flexbytes_value,
10199                 (void *)&cmd_flow_director_drop,
10200                 (void *)&cmd_flow_director_pf_vf,
10201                 (void *)&cmd_flow_director_queue,
10202                 (void *)&cmd_flow_director_queue_id,
10203                 (void *)&cmd_flow_director_fd_id,
10204                 (void *)&cmd_flow_director_fd_id_value,
10205                 NULL,
10206         },
10207 };
10208
10209 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10210         .f = cmd_flow_director_filter_parsed,
10211         .data = NULL,
10212         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10213                 "director entry on NIC",
10214         .tokens = {
10215                 (void *)&cmd_flow_director_filter,
10216                 (void *)&cmd_flow_director_port_id,
10217                 (void *)&cmd_flow_director_mode,
10218                 (void *)&cmd_flow_director_mode_mac_vlan,
10219                 (void *)&cmd_flow_director_ops,
10220                 (void *)&cmd_flow_director_mac,
10221                 (void *)&cmd_flow_director_mac_addr,
10222                 (void *)&cmd_flow_director_vlan,
10223                 (void *)&cmd_flow_director_vlan_value,
10224                 (void *)&cmd_flow_director_flexbytes,
10225                 (void *)&cmd_flow_director_flexbytes_value,
10226                 (void *)&cmd_flow_director_drop,
10227                 (void *)&cmd_flow_director_queue,
10228                 (void *)&cmd_flow_director_queue_id,
10229                 (void *)&cmd_flow_director_fd_id,
10230                 (void *)&cmd_flow_director_fd_id_value,
10231                 NULL,
10232         },
10233 };
10234
10235 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10236         .f = cmd_flow_director_filter_parsed,
10237         .data = NULL,
10238         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10239                 "director entry on NIC",
10240         .tokens = {
10241                 (void *)&cmd_flow_director_filter,
10242                 (void *)&cmd_flow_director_port_id,
10243                 (void *)&cmd_flow_director_mode,
10244                 (void *)&cmd_flow_director_mode_tunnel,
10245                 (void *)&cmd_flow_director_ops,
10246                 (void *)&cmd_flow_director_mac,
10247                 (void *)&cmd_flow_director_mac_addr,
10248                 (void *)&cmd_flow_director_vlan,
10249                 (void *)&cmd_flow_director_vlan_value,
10250                 (void *)&cmd_flow_director_tunnel,
10251                 (void *)&cmd_flow_director_tunnel_type,
10252                 (void *)&cmd_flow_director_tunnel_id,
10253                 (void *)&cmd_flow_director_tunnel_id_value,
10254                 (void *)&cmd_flow_director_flexbytes,
10255                 (void *)&cmd_flow_director_flexbytes_value,
10256                 (void *)&cmd_flow_director_drop,
10257                 (void *)&cmd_flow_director_queue,
10258                 (void *)&cmd_flow_director_queue_id,
10259                 (void *)&cmd_flow_director_fd_id,
10260                 (void *)&cmd_flow_director_fd_id_value,
10261                 NULL,
10262         },
10263 };
10264
10265 struct cmd_flush_flow_director_result {
10266         cmdline_fixed_string_t flush_flow_director;
10267         portid_t port_id;
10268 };
10269
10270 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10272                                  flush_flow_director, "flush_flow_director");
10273 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10274         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10275                               port_id, UINT16);
10276
10277 static void
10278 cmd_flush_flow_director_parsed(void *parsed_result,
10279                           __attribute__((unused)) struct cmdline *cl,
10280                           __attribute__((unused)) void *data)
10281 {
10282         struct cmd_flow_director_result *res = parsed_result;
10283         int ret = 0;
10284
10285         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10286         if (ret < 0) {
10287                 printf("flow director is not supported on port %u.\n",
10288                         res->port_id);
10289                 return;
10290         }
10291
10292         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10293                         RTE_ETH_FILTER_FLUSH, NULL);
10294         if (ret < 0)
10295                 printf("flow director table flushing error: (%s)\n",
10296                         strerror(-ret));
10297 }
10298
10299 cmdline_parse_inst_t cmd_flush_flow_director = {
10300         .f = cmd_flush_flow_director_parsed,
10301         .data = NULL,
10302         .help_str = "flush_flow_director <port_id>: "
10303                 "Flush all flow director entries of a device on NIC",
10304         .tokens = {
10305                 (void *)&cmd_flush_flow_director_flush,
10306                 (void *)&cmd_flush_flow_director_port_id,
10307                 NULL,
10308         },
10309 };
10310
10311 /* *** deal with flow director mask *** */
10312 struct cmd_flow_director_mask_result {
10313         cmdline_fixed_string_t flow_director_mask;
10314         portid_t port_id;
10315         cmdline_fixed_string_t mode;
10316         cmdline_fixed_string_t mode_value;
10317         cmdline_fixed_string_t vlan;
10318         uint16_t vlan_mask;
10319         cmdline_fixed_string_t src_mask;
10320         cmdline_ipaddr_t ipv4_src;
10321         cmdline_ipaddr_t ipv6_src;
10322         uint16_t port_src;
10323         cmdline_fixed_string_t dst_mask;
10324         cmdline_ipaddr_t ipv4_dst;
10325         cmdline_ipaddr_t ipv6_dst;
10326         uint16_t port_dst;
10327         cmdline_fixed_string_t mac;
10328         uint8_t mac_addr_byte_mask;
10329         cmdline_fixed_string_t tunnel_id;
10330         uint32_t tunnel_id_mask;
10331         cmdline_fixed_string_t tunnel_type;
10332         uint8_t tunnel_type_mask;
10333 };
10334
10335 static void
10336 cmd_flow_director_mask_parsed(void *parsed_result,
10337                           __attribute__((unused)) struct cmdline *cl,
10338                           __attribute__((unused)) void *data)
10339 {
10340         struct cmd_flow_director_mask_result *res = parsed_result;
10341         struct rte_eth_fdir_masks *mask;
10342         struct rte_port *port;
10343
10344         if (res->port_id > nb_ports) {
10345                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10346                 return;
10347         }
10348
10349         port = &ports[res->port_id];
10350         /** Check if the port is not started **/
10351         if (port->port_status != RTE_PORT_STOPPED) {
10352                 printf("Please stop port %d first\n", res->port_id);
10353                 return;
10354         }
10355
10356         mask = &port->dev_conf.fdir_conf.mask;
10357
10358         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10359                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10360                         printf("Please set mode to MAC-VLAN.\n");
10361                         return;
10362                 }
10363
10364                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10365         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10366                 if (strcmp(res->mode_value, "Tunnel")) {
10367                         printf("Please set mode to Tunnel.\n");
10368                         return;
10369                 }
10370
10371                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10372                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10373                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10374                 mask->tunnel_type_mask = res->tunnel_type_mask;
10375         } else {
10376                 if (strcmp(res->mode_value, "IP")) {
10377                         printf("Please set mode to IP.\n");
10378                         return;
10379                 }
10380
10381                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10382                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10383                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10384                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10385                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10386                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10387                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10388         }
10389
10390         cmd_reconfig_device_queue(res->port_id, 1, 1);
10391 }
10392
10393 cmdline_parse_token_string_t cmd_flow_director_mask =
10394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10395                                  flow_director_mask, "flow_director_mask");
10396 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10397         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10398                               port_id, UINT16);
10399 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10400         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10401                                  vlan, "vlan");
10402 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10403         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10404                               vlan_mask, UINT16);
10405 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10407                                  src_mask, "src_mask");
10408 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10409         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10410                                  ipv4_src);
10411 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10412         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10413                                  ipv6_src);
10414 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10415         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10416                               port_src, UINT16);
10417 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10418         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10419                                  dst_mask, "dst_mask");
10420 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10421         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  ipv4_dst);
10423 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10424         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  ipv6_dst);
10426 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10427         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10428                               port_dst, UINT16);
10429
10430 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10432                                  mode, "mode");
10433 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10435                                  mode_value, "IP");
10436 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10438                                  mode_value, "MAC-VLAN");
10439 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10441                                  mode_value, "Tunnel");
10442 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10443         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10444                                  mac, "mac");
10445 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10446         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10447                               mac_addr_byte_mask, UINT8);
10448 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10449         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10450                                  tunnel_type, "tunnel-type");
10451 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10452         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10453                               tunnel_type_mask, UINT8);
10454 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10455         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10456                                  tunnel_id, "tunnel-id");
10457 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10458         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10459                               tunnel_id_mask, UINT32);
10460
10461 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10462         .f = cmd_flow_director_mask_parsed,
10463         .data = NULL,
10464         .help_str = "flow_director_mask ... : "
10465                 "Set IP mode flow director's mask on NIC",
10466         .tokens = {
10467                 (void *)&cmd_flow_director_mask,
10468                 (void *)&cmd_flow_director_mask_port_id,
10469                 (void *)&cmd_flow_director_mask_mode,
10470                 (void *)&cmd_flow_director_mask_mode_ip,
10471                 (void *)&cmd_flow_director_mask_vlan,
10472                 (void *)&cmd_flow_director_mask_vlan_value,
10473                 (void *)&cmd_flow_director_mask_src,
10474                 (void *)&cmd_flow_director_mask_ipv4_src,
10475                 (void *)&cmd_flow_director_mask_ipv6_src,
10476                 (void *)&cmd_flow_director_mask_port_src,
10477                 (void *)&cmd_flow_director_mask_dst,
10478                 (void *)&cmd_flow_director_mask_ipv4_dst,
10479                 (void *)&cmd_flow_director_mask_ipv6_dst,
10480                 (void *)&cmd_flow_director_mask_port_dst,
10481                 NULL,
10482         },
10483 };
10484
10485 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10486         .f = cmd_flow_director_mask_parsed,
10487         .data = NULL,
10488         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10489                 "flow director's mask on NIC",
10490         .tokens = {
10491                 (void *)&cmd_flow_director_mask,
10492                 (void *)&cmd_flow_director_mask_port_id,
10493                 (void *)&cmd_flow_director_mask_mode,
10494                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10495                 (void *)&cmd_flow_director_mask_vlan,
10496                 (void *)&cmd_flow_director_mask_vlan_value,
10497                 NULL,
10498         },
10499 };
10500
10501 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10502         .f = cmd_flow_director_mask_parsed,
10503         .data = NULL,
10504         .help_str = "flow_director_mask ... : Set tunnel mode "
10505                 "flow director's mask on NIC",
10506         .tokens = {
10507                 (void *)&cmd_flow_director_mask,
10508                 (void *)&cmd_flow_director_mask_port_id,
10509                 (void *)&cmd_flow_director_mask_mode,
10510                 (void *)&cmd_flow_director_mask_mode_tunnel,
10511                 (void *)&cmd_flow_director_mask_vlan,
10512                 (void *)&cmd_flow_director_mask_vlan_value,
10513                 (void *)&cmd_flow_director_mask_mac,
10514                 (void *)&cmd_flow_director_mask_mac_value,
10515                 (void *)&cmd_flow_director_mask_tunnel_type,
10516                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10517                 (void *)&cmd_flow_director_mask_tunnel_id,
10518                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10519                 NULL,
10520         },
10521 };
10522
10523 /* *** deal with flow director mask on flexible payload *** */
10524 struct cmd_flow_director_flex_mask_result {
10525         cmdline_fixed_string_t flow_director_flexmask;
10526         portid_t port_id;
10527         cmdline_fixed_string_t flow;
10528         cmdline_fixed_string_t flow_type;
10529         cmdline_fixed_string_t mask;
10530 };
10531
10532 static void
10533 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10534                           __attribute__((unused)) struct cmdline *cl,
10535                           __attribute__((unused)) void *data)
10536 {
10537         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10538         struct rte_eth_fdir_info fdir_info;
10539         struct rte_eth_fdir_flex_mask flex_mask;
10540         struct rte_port *port;
10541         uint32_t flow_type_mask;
10542         uint16_t i;
10543         int ret;
10544
10545         if (res->port_id > nb_ports) {
10546                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10547                 return;
10548         }
10549
10550         port = &ports[res->port_id];
10551         /** Check if the port is not started **/
10552         if (port->port_status != RTE_PORT_STOPPED) {
10553                 printf("Please stop port %d first\n", res->port_id);
10554                 return;
10555         }
10556
10557         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10558         ret = parse_flexbytes(res->mask,
10559                         flex_mask.mask,
10560                         RTE_ETH_FDIR_MAX_FLEXLEN);
10561         if (ret < 0) {
10562                 printf("error: Cannot parse mask input.\n");
10563                 return;
10564         }
10565
10566         memset(&fdir_info, 0, sizeof(fdir_info));
10567         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10568                                 RTE_ETH_FILTER_INFO, &fdir_info);
10569         if (ret < 0) {
10570                 printf("Cannot get FDir filter info\n");
10571                 return;
10572         }
10573
10574         if (!strcmp(res->flow_type, "none")) {
10575                 /* means don't specify the flow type */
10576                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10577                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10578                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10579                                0, sizeof(struct rte_eth_fdir_flex_mask));
10580                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10581                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10582                                  &flex_mask,
10583                                  sizeof(struct rte_eth_fdir_flex_mask));
10584                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10585                 return;
10586         }
10587         flow_type_mask = fdir_info.flow_types_mask[0];
10588         if (!strcmp(res->flow_type, "all")) {
10589                 if (!flow_type_mask) {
10590                         printf("No flow type supported\n");
10591                         return;
10592                 }
10593                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10594                         if (flow_type_mask & (1 << i)) {
10595                                 flex_mask.flow_type = i;
10596                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10597                         }
10598                 }
10599                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10600                 return;
10601         }
10602         flex_mask.flow_type = str2flowtype(res->flow_type);
10603         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10604                 printf("Flow type %s not supported on port %d\n",
10605                                 res->flow_type, res->port_id);
10606                 return;
10607         }
10608         fdir_set_flex_mask(res->port_id, &flex_mask);
10609         cmd_reconfig_device_queue(res->port_id, 1, 1);
10610 }
10611
10612 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10613         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10614                                  flow_director_flexmask,
10615                                  "flow_director_flex_mask");
10616 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10617         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10618                               port_id, UINT16);
10619 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10620         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10621                                  flow, "flow");
10622 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10623         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10624                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10625                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10626 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10627         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10628                                  mask, NULL);
10629
10630 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10631         .f = cmd_flow_director_flex_mask_parsed,
10632         .data = NULL,
10633         .help_str = "flow_director_flex_mask ... : "
10634                 "Set flow director's flex mask on NIC",
10635         .tokens = {
10636                 (void *)&cmd_flow_director_flexmask,
10637                 (void *)&cmd_flow_director_flexmask_port_id,
10638                 (void *)&cmd_flow_director_flexmask_flow,
10639                 (void *)&cmd_flow_director_flexmask_flow_type,
10640                 (void *)&cmd_flow_director_flexmask_mask,
10641                 NULL,
10642         },
10643 };
10644
10645 /* *** deal with flow director flexible payload configuration *** */
10646 struct cmd_flow_director_flexpayload_result {
10647         cmdline_fixed_string_t flow_director_flexpayload;
10648         portid_t port_id;
10649         cmdline_fixed_string_t payload_layer;
10650         cmdline_fixed_string_t payload_cfg;
10651 };
10652
10653 static inline int
10654 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10655 {
10656         char s[256];
10657         const char *p, *p0 = q_arg;
10658         char *end;
10659         unsigned long int_fld;
10660         char *str_fld[max_num];
10661         int i;
10662         unsigned size;
10663         int ret = -1;
10664
10665         p = strchr(p0, '(');
10666         if (p == NULL)
10667                 return -1;
10668         ++p;
10669         p0 = strchr(p, ')');
10670         if (p0 == NULL)
10671                 return -1;
10672
10673         size = p0 - p;
10674         if (size >= sizeof(s))
10675                 return -1;
10676
10677         snprintf(s, sizeof(s), "%.*s", size, p);
10678         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10679         if (ret < 0 || ret > max_num)
10680                 return -1;
10681         for (i = 0; i < ret; i++) {
10682                 errno = 0;
10683                 int_fld = strtoul(str_fld[i], &end, 0);
10684                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10685                         return -1;
10686                 offsets[i] = (uint16_t)int_fld;
10687         }
10688         return ret;
10689 }
10690
10691 static void
10692 cmd_flow_director_flxpld_parsed(void *parsed_result,
10693                           __attribute__((unused)) struct cmdline *cl,
10694                           __attribute__((unused)) void *data)
10695 {
10696         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10697         struct rte_eth_flex_payload_cfg flex_cfg;
10698         struct rte_port *port;
10699         int ret = 0;
10700
10701         if (res->port_id > nb_ports) {
10702                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10703                 return;
10704         }
10705
10706         port = &ports[res->port_id];
10707         /** Check if the port is not started **/
10708         if (port->port_status != RTE_PORT_STOPPED) {
10709                 printf("Please stop port %d first\n", res->port_id);
10710                 return;
10711         }
10712
10713         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10714
10715         if (!strcmp(res->payload_layer, "raw"))
10716                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10717         else if (!strcmp(res->payload_layer, "l2"))
10718                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10719         else if (!strcmp(res->payload_layer, "l3"))
10720                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10721         else if (!strcmp(res->payload_layer, "l4"))
10722                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10723
10724         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10725                             RTE_ETH_FDIR_MAX_FLEXLEN);
10726         if (ret < 0) {
10727                 printf("error: Cannot parse flex payload input.\n");
10728                 return;
10729         }
10730
10731         fdir_set_flex_payload(res->port_id, &flex_cfg);
10732         cmd_reconfig_device_queue(res->port_id, 1, 1);
10733 }
10734
10735 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10737                                  flow_director_flexpayload,
10738                                  "flow_director_flex_payload");
10739 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10740         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10741                               port_id, UINT16);
10742 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10743         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10744                                  payload_layer, "raw#l2#l3#l4");
10745 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10746         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10747                                  payload_cfg, NULL);
10748
10749 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10750         .f = cmd_flow_director_flxpld_parsed,
10751         .data = NULL,
10752         .help_str = "flow_director_flexpayload ... : "
10753                 "Set flow director's flex payload on NIC",
10754         .tokens = {
10755                 (void *)&cmd_flow_director_flexpayload,
10756                 (void *)&cmd_flow_director_flexpayload_port_id,
10757                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10758                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10759                 NULL,
10760         },
10761 };
10762
10763 /* Generic flow interface command. */
10764 extern cmdline_parse_inst_t cmd_flow;
10765
10766 /* *** Classification Filters Control *** */
10767 /* *** Get symmetric hash enable per port *** */
10768 struct cmd_get_sym_hash_ena_per_port_result {
10769         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10770         portid_t port_id;
10771 };
10772
10773 static void
10774 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10775                                  __rte_unused struct cmdline *cl,
10776                                  __rte_unused void *data)
10777 {
10778         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10779         struct rte_eth_hash_filter_info info;
10780         int ret;
10781
10782         if (rte_eth_dev_filter_supported(res->port_id,
10783                                 RTE_ETH_FILTER_HASH) < 0) {
10784                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10785                                                         res->port_id);
10786                 return;
10787         }
10788
10789         memset(&info, 0, sizeof(info));
10790         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10791         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10792                                                 RTE_ETH_FILTER_GET, &info);
10793
10794         if (ret < 0) {
10795                 printf("Cannot get symmetric hash enable per port "
10796                                         "on port %u\n", res->port_id);
10797                 return;
10798         }
10799
10800         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10801                                 "enabled" : "disabled", res->port_id);
10802 }
10803
10804 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10805         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10806                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10807 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10808         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10809                 port_id, UINT16);
10810
10811 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10812         .f = cmd_get_sym_hash_per_port_parsed,
10813         .data = NULL,
10814         .help_str = "get_sym_hash_ena_per_port <port_id>",
10815         .tokens = {
10816                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10817                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10818                 NULL,
10819         },
10820 };
10821
10822 /* *** Set symmetric hash enable per port *** */
10823 struct cmd_set_sym_hash_ena_per_port_result {
10824         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10825         cmdline_fixed_string_t enable;
10826         portid_t port_id;
10827 };
10828
10829 static void
10830 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10831                                  __rte_unused struct cmdline *cl,
10832                                  __rte_unused void *data)
10833 {
10834         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10835         struct rte_eth_hash_filter_info info;
10836         int ret;
10837
10838         if (rte_eth_dev_filter_supported(res->port_id,
10839                                 RTE_ETH_FILTER_HASH) < 0) {
10840                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10841                                                         res->port_id);
10842                 return;
10843         }
10844
10845         memset(&info, 0, sizeof(info));
10846         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10847         if (!strcmp(res->enable, "enable"))
10848                 info.info.enable = 1;
10849         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10850                                         RTE_ETH_FILTER_SET, &info);
10851         if (ret < 0) {
10852                 printf("Cannot set symmetric hash enable per port on "
10853                                         "port %u\n", res->port_id);
10854                 return;
10855         }
10856         printf("Symmetric hash has been set to %s on port %u\n",
10857                                         res->enable, res->port_id);
10858 }
10859
10860 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10861         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10862                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10863 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10864         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10865                 port_id, UINT16);
10866 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10867         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10868                 enable, "enable#disable");
10869
10870 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10871         .f = cmd_set_sym_hash_per_port_parsed,
10872         .data = NULL,
10873         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10874         .tokens = {
10875                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10876                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10877                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10878                 NULL,
10879         },
10880 };
10881
10882 /* Get global config of hash function */
10883 struct cmd_get_hash_global_config_result {
10884         cmdline_fixed_string_t get_hash_global_config;
10885         portid_t port_id;
10886 };
10887
10888 static char *
10889 flowtype_to_str(uint16_t ftype)
10890 {
10891         uint16_t i;
10892         static struct {
10893                 char str[16];
10894                 uint16_t ftype;
10895         } ftype_table[] = {
10896                 {"ipv4", RTE_ETH_FLOW_IPV4},
10897                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10898                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10899                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10900                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10901                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10902                 {"ipv6", RTE_ETH_FLOW_IPV6},
10903                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10904                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10905                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10906                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10907                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10908                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10909                 {"port", RTE_ETH_FLOW_PORT},
10910                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10911                 {"geneve", RTE_ETH_FLOW_GENEVE},
10912                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10913         };
10914
10915         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10916                 if (ftype_table[i].ftype == ftype)
10917                         return ftype_table[i].str;
10918         }
10919
10920         return NULL;
10921 }
10922
10923 static void
10924 cmd_get_hash_global_config_parsed(void *parsed_result,
10925                                   __rte_unused struct cmdline *cl,
10926                                   __rte_unused void *data)
10927 {
10928         struct cmd_get_hash_global_config_result *res = parsed_result;
10929         struct rte_eth_hash_filter_info info;
10930         uint32_t idx, offset;
10931         uint16_t i;
10932         char *str;
10933         int ret;
10934
10935         if (rte_eth_dev_filter_supported(res->port_id,
10936                         RTE_ETH_FILTER_HASH) < 0) {
10937                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10938                                                         res->port_id);
10939                 return;
10940         }
10941
10942         memset(&info, 0, sizeof(info));
10943         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10944         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10945                                         RTE_ETH_FILTER_GET, &info);
10946         if (ret < 0) {
10947                 printf("Cannot get hash global configurations by port %d\n",
10948                                                         res->port_id);
10949                 return;
10950         }
10951
10952         switch (info.info.global_conf.hash_func) {
10953         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10954                 printf("Hash function is Toeplitz\n");
10955                 break;
10956         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10957                 printf("Hash function is Simple XOR\n");
10958                 break;
10959         default:
10960                 printf("Unknown hash function\n");
10961                 break;
10962         }
10963
10964         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10965                 idx = i / UINT32_BIT;
10966                 offset = i % UINT32_BIT;
10967                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10968                                                 (1UL << offset)))
10969                         continue;
10970                 str = flowtype_to_str(i);
10971                 if (!str)
10972                         continue;
10973                 printf("Symmetric hash is %s globally for flow type %s "
10974                                                         "by port %d\n",
10975                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10976                         (1UL << offset)) ? "enabled" : "disabled"), str,
10977                                                         res->port_id);
10978         }
10979 }
10980
10981 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10982         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10983                 get_hash_global_config, "get_hash_global_config");
10984 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10985         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10986                 port_id, UINT16);
10987
10988 cmdline_parse_inst_t cmd_get_hash_global_config = {
10989         .f = cmd_get_hash_global_config_parsed,
10990         .data = NULL,
10991         .help_str = "get_hash_global_config <port_id>",
10992         .tokens = {
10993                 (void *)&cmd_get_hash_global_config_all,
10994                 (void *)&cmd_get_hash_global_config_port_id,
10995                 NULL,
10996         },
10997 };
10998
10999 /* Set global config of hash function */
11000 struct cmd_set_hash_global_config_result {
11001         cmdline_fixed_string_t set_hash_global_config;
11002         portid_t port_id;
11003         cmdline_fixed_string_t hash_func;
11004         cmdline_fixed_string_t flow_type;
11005         cmdline_fixed_string_t enable;
11006 };
11007
11008 static void
11009 cmd_set_hash_global_config_parsed(void *parsed_result,
11010                                   __rte_unused struct cmdline *cl,
11011                                   __rte_unused void *data)
11012 {
11013         struct cmd_set_hash_global_config_result *res = parsed_result;
11014         struct rte_eth_hash_filter_info info;
11015         uint32_t ftype, idx, offset;
11016         int ret;
11017
11018         if (rte_eth_dev_filter_supported(res->port_id,
11019                                 RTE_ETH_FILTER_HASH) < 0) {
11020                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11021                                                         res->port_id);
11022                 return;
11023         }
11024         memset(&info, 0, sizeof(info));
11025         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11026         if (!strcmp(res->hash_func, "toeplitz"))
11027                 info.info.global_conf.hash_func =
11028                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11029         else if (!strcmp(res->hash_func, "simple_xor"))
11030                 info.info.global_conf.hash_func =
11031                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11032         else if (!strcmp(res->hash_func, "default"))
11033                 info.info.global_conf.hash_func =
11034                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11035
11036         ftype = str2flowtype(res->flow_type);
11037         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11038         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11039         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11040         if (!strcmp(res->enable, "enable"))
11041                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11042                                                 (1UL << offset);
11043         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11044                                         RTE_ETH_FILTER_SET, &info);
11045         if (ret < 0)
11046                 printf("Cannot set global hash configurations by port %d\n",
11047                                                         res->port_id);
11048         else
11049                 printf("Global hash configurations have been set "
11050                         "succcessfully by port %d\n", res->port_id);
11051 }
11052
11053 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11054         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11055                 set_hash_global_config, "set_hash_global_config");
11056 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11057         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11058                 port_id, UINT16);
11059 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11060         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11061                 hash_func, "toeplitz#simple_xor#default");
11062 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11063         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11064                 flow_type,
11065                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11066                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11067 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11068         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11069                 enable, "enable#disable");
11070
11071 cmdline_parse_inst_t cmd_set_hash_global_config = {
11072         .f = cmd_set_hash_global_config_parsed,
11073         .data = NULL,
11074         .help_str = "set_hash_global_config <port_id> "
11075                 "toeplitz|simple_xor|default "
11076                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11077                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11078                 "l2_payload enable|disable",
11079         .tokens = {
11080                 (void *)&cmd_set_hash_global_config_all,
11081                 (void *)&cmd_set_hash_global_config_port_id,
11082                 (void *)&cmd_set_hash_global_config_hash_func,
11083                 (void *)&cmd_set_hash_global_config_flow_type,
11084                 (void *)&cmd_set_hash_global_config_enable,
11085                 NULL,
11086         },
11087 };
11088
11089 /* Set hash input set */
11090 struct cmd_set_hash_input_set_result {
11091         cmdline_fixed_string_t set_hash_input_set;
11092         portid_t port_id;
11093         cmdline_fixed_string_t flow_type;
11094         cmdline_fixed_string_t inset_field;
11095         cmdline_fixed_string_t select;
11096 };
11097
11098 static enum rte_eth_input_set_field
11099 str2inset(char *string)
11100 {
11101         uint16_t i;
11102
11103         static const struct {
11104                 char str[32];
11105                 enum rte_eth_input_set_field inset;
11106         } inset_table[] = {
11107                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11108                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11109                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11110                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11111                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11112                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11113                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11114                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11115                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11116                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11117                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11118                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11119                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11120                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11121                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11122                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11123                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11124                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11125                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11126                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11127                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11128                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11129                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11130                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11131                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11132                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11133                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11134                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11135                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11136                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11137                 {"none", RTE_ETH_INPUT_SET_NONE},
11138         };
11139
11140         for (i = 0; i < RTE_DIM(inset_table); i++) {
11141                 if (!strcmp(string, inset_table[i].str))
11142                         return inset_table[i].inset;
11143         }
11144
11145         return RTE_ETH_INPUT_SET_UNKNOWN;
11146 }
11147
11148 static void
11149 cmd_set_hash_input_set_parsed(void *parsed_result,
11150                               __rte_unused struct cmdline *cl,
11151                               __rte_unused void *data)
11152 {
11153         struct cmd_set_hash_input_set_result *res = parsed_result;
11154         struct rte_eth_hash_filter_info info;
11155
11156         memset(&info, 0, sizeof(info));
11157         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11158         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11159         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11160         info.info.input_set_conf.inset_size = 1;
11161         if (!strcmp(res->select, "select"))
11162                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11163         else if (!strcmp(res->select, "add"))
11164                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11165         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11166                                 RTE_ETH_FILTER_SET, &info);
11167 }
11168
11169 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11170         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11171                 set_hash_input_set, "set_hash_input_set");
11172 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11173         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11174                 port_id, UINT16);
11175 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11176         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11177                 flow_type, NULL);
11178 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11179         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11180                 inset_field,
11181                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11182                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11183                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11184                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11185                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11186                 "fld-8th#none");
11187 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11188         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11189                 select, "select#add");
11190
11191 cmdline_parse_inst_t cmd_set_hash_input_set = {
11192         .f = cmd_set_hash_input_set_parsed,
11193         .data = NULL,
11194         .help_str = "set_hash_input_set <port_id> "
11195         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11196         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11197         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11198         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11199         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11200         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11201         "fld-7th|fld-8th|none select|add",
11202         .tokens = {
11203                 (void *)&cmd_set_hash_input_set_cmd,
11204                 (void *)&cmd_set_hash_input_set_port_id,
11205                 (void *)&cmd_set_hash_input_set_flow_type,
11206                 (void *)&cmd_set_hash_input_set_field,
11207                 (void *)&cmd_set_hash_input_set_select,
11208                 NULL,
11209         },
11210 };
11211
11212 /* Set flow director input set */
11213 struct cmd_set_fdir_input_set_result {
11214         cmdline_fixed_string_t set_fdir_input_set;
11215         portid_t port_id;
11216         cmdline_fixed_string_t flow_type;
11217         cmdline_fixed_string_t inset_field;
11218         cmdline_fixed_string_t select;
11219 };
11220
11221 static void
11222 cmd_set_fdir_input_set_parsed(void *parsed_result,
11223         __rte_unused struct cmdline *cl,
11224         __rte_unused void *data)
11225 {
11226         struct cmd_set_fdir_input_set_result *res = parsed_result;
11227         struct rte_eth_fdir_filter_info info;
11228
11229         memset(&info, 0, sizeof(info));
11230         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11231         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11232         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11233         info.info.input_set_conf.inset_size = 1;
11234         if (!strcmp(res->select, "select"))
11235                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11236         else if (!strcmp(res->select, "add"))
11237                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11238         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11239                 RTE_ETH_FILTER_SET, &info);
11240 }
11241
11242 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11243         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11244         set_fdir_input_set, "set_fdir_input_set");
11245 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11246         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11247         port_id, UINT16);
11248 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11249         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11250         flow_type,
11251         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11252         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11253 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11254         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11255         inset_field,
11256         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11257         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11258         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11259         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11260         "sctp-veri-tag#none");
11261 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11262         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11263         select, "select#add");
11264
11265 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11266         .f = cmd_set_fdir_input_set_parsed,
11267         .data = NULL,
11268         .help_str = "set_fdir_input_set <port_id> "
11269         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11270         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11271         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11272         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11273         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11274         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11275         "sctp-veri-tag|none select|add",
11276         .tokens = {
11277                 (void *)&cmd_set_fdir_input_set_cmd,
11278                 (void *)&cmd_set_fdir_input_set_port_id,
11279                 (void *)&cmd_set_fdir_input_set_flow_type,
11280                 (void *)&cmd_set_fdir_input_set_field,
11281                 (void *)&cmd_set_fdir_input_set_select,
11282                 NULL,
11283         },
11284 };
11285
11286 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11287 struct cmd_mcast_addr_result {
11288         cmdline_fixed_string_t mcast_addr_cmd;
11289         cmdline_fixed_string_t what;
11290         uint16_t port_num;
11291         struct ether_addr mc_addr;
11292 };
11293
11294 static void cmd_mcast_addr_parsed(void *parsed_result,
11295                 __attribute__((unused)) struct cmdline *cl,
11296                 __attribute__((unused)) void *data)
11297 {
11298         struct cmd_mcast_addr_result *res = parsed_result;
11299
11300         if (!is_multicast_ether_addr(&res->mc_addr)) {
11301                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11302                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11303                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11304                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11305                 return;
11306         }
11307         if (strcmp(res->what, "add") == 0)
11308                 mcast_addr_add(res->port_num, &res->mc_addr);
11309         else
11310                 mcast_addr_remove(res->port_num, &res->mc_addr);
11311 }
11312
11313 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11314         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11315                                  mcast_addr_cmd, "mcast_addr");
11316 cmdline_parse_token_string_t cmd_mcast_addr_what =
11317         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11318                                  "add#remove");
11319 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11320         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11321 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11322         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11323
11324 cmdline_parse_inst_t cmd_mcast_addr = {
11325         .f = cmd_mcast_addr_parsed,
11326         .data = (void *)0,
11327         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11328                 "Add/Remove multicast MAC address on port_id",
11329         .tokens = {
11330                 (void *)&cmd_mcast_addr_cmd,
11331                 (void *)&cmd_mcast_addr_what,
11332                 (void *)&cmd_mcast_addr_portnum,
11333                 (void *)&cmd_mcast_addr_addr,
11334                 NULL,
11335         },
11336 };
11337
11338 /* l2 tunnel config
11339  * only support E-tag now.
11340  */
11341
11342 /* Ether type config */
11343 struct cmd_config_l2_tunnel_eth_type_result {
11344         cmdline_fixed_string_t port;
11345         cmdline_fixed_string_t config;
11346         cmdline_fixed_string_t all;
11347         uint8_t id;
11348         cmdline_fixed_string_t l2_tunnel;
11349         cmdline_fixed_string_t l2_tunnel_type;
11350         cmdline_fixed_string_t eth_type;
11351         uint16_t eth_type_val;
11352 };
11353
11354 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11355         TOKEN_STRING_INITIALIZER
11356                 (struct cmd_config_l2_tunnel_eth_type_result,
11357                  port, "port");
11358 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11359         TOKEN_STRING_INITIALIZER
11360                 (struct cmd_config_l2_tunnel_eth_type_result,
11361                  config, "config");
11362 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11363         TOKEN_STRING_INITIALIZER
11364                 (struct cmd_config_l2_tunnel_eth_type_result,
11365                  all, "all");
11366 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11367         TOKEN_NUM_INITIALIZER
11368                 (struct cmd_config_l2_tunnel_eth_type_result,
11369                  id, UINT8);
11370 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11371         TOKEN_STRING_INITIALIZER
11372                 (struct cmd_config_l2_tunnel_eth_type_result,
11373                  l2_tunnel, "l2-tunnel");
11374 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11375         TOKEN_STRING_INITIALIZER
11376                 (struct cmd_config_l2_tunnel_eth_type_result,
11377                  l2_tunnel_type, "E-tag");
11378 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11379         TOKEN_STRING_INITIALIZER
11380                 (struct cmd_config_l2_tunnel_eth_type_result,
11381                  eth_type, "ether-type");
11382 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11383         TOKEN_NUM_INITIALIZER
11384                 (struct cmd_config_l2_tunnel_eth_type_result,
11385                  eth_type_val, UINT16);
11386
11387 static enum rte_eth_tunnel_type
11388 str2fdir_l2_tunnel_type(char *string)
11389 {
11390         uint32_t i = 0;
11391
11392         static const struct {
11393                 char str[32];
11394                 enum rte_eth_tunnel_type type;
11395         } l2_tunnel_type_str[] = {
11396                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11397         };
11398
11399         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11400                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11401                         return l2_tunnel_type_str[i].type;
11402         }
11403         return RTE_TUNNEL_TYPE_NONE;
11404 }
11405
11406 /* ether type config for all ports */
11407 static void
11408 cmd_config_l2_tunnel_eth_type_all_parsed
11409         (void *parsed_result,
11410          __attribute__((unused)) struct cmdline *cl,
11411          __attribute__((unused)) void *data)
11412 {
11413         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11414         struct rte_eth_l2_tunnel_conf entry;
11415         portid_t pid;
11416
11417         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11418         entry.ether_type = res->eth_type_val;
11419
11420         RTE_ETH_FOREACH_DEV(pid) {
11421                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11422         }
11423 }
11424
11425 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11426         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11427         .data = NULL,
11428         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11429         .tokens = {
11430                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11431                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11432                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11433                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11434                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11435                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11436                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11437                 NULL,
11438         },
11439 };
11440
11441 /* ether type config for a specific port */
11442 static void
11443 cmd_config_l2_tunnel_eth_type_specific_parsed(
11444         void *parsed_result,
11445         __attribute__((unused)) struct cmdline *cl,
11446         __attribute__((unused)) void *data)
11447 {
11448         struct cmd_config_l2_tunnel_eth_type_result *res =
11449                  parsed_result;
11450         struct rte_eth_l2_tunnel_conf entry;
11451
11452         if (port_id_is_invalid(res->id, ENABLED_WARN))
11453                 return;
11454
11455         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11456         entry.ether_type = res->eth_type_val;
11457
11458         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11459 }
11460
11461 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11462         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11463         .data = NULL,
11464         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11465         .tokens = {
11466                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11467                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11468                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11469                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11470                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11471                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11472                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11473                 NULL,
11474         },
11475 };
11476
11477 /* Enable/disable l2 tunnel */
11478 struct cmd_config_l2_tunnel_en_dis_result {
11479         cmdline_fixed_string_t port;
11480         cmdline_fixed_string_t config;
11481         cmdline_fixed_string_t all;
11482         uint8_t id;
11483         cmdline_fixed_string_t l2_tunnel;
11484         cmdline_fixed_string_t l2_tunnel_type;
11485         cmdline_fixed_string_t en_dis;
11486 };
11487
11488 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11489         TOKEN_STRING_INITIALIZER
11490                 (struct cmd_config_l2_tunnel_en_dis_result,
11491                  port, "port");
11492 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11493         TOKEN_STRING_INITIALIZER
11494                 (struct cmd_config_l2_tunnel_en_dis_result,
11495                  config, "config");
11496 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11497         TOKEN_STRING_INITIALIZER
11498                 (struct cmd_config_l2_tunnel_en_dis_result,
11499                  all, "all");
11500 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11501         TOKEN_NUM_INITIALIZER
11502                 (struct cmd_config_l2_tunnel_en_dis_result,
11503                  id, UINT8);
11504 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11505         TOKEN_STRING_INITIALIZER
11506                 (struct cmd_config_l2_tunnel_en_dis_result,
11507                  l2_tunnel, "l2-tunnel");
11508 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11509         TOKEN_STRING_INITIALIZER
11510                 (struct cmd_config_l2_tunnel_en_dis_result,
11511                  l2_tunnel_type, "E-tag");
11512 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11513         TOKEN_STRING_INITIALIZER
11514                 (struct cmd_config_l2_tunnel_en_dis_result,
11515                  en_dis, "enable#disable");
11516
11517 /* enable/disable l2 tunnel for all ports */
11518 static void
11519 cmd_config_l2_tunnel_en_dis_all_parsed(
11520         void *parsed_result,
11521         __attribute__((unused)) struct cmdline *cl,
11522         __attribute__((unused)) void *data)
11523 {
11524         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11525         struct rte_eth_l2_tunnel_conf entry;
11526         portid_t pid;
11527         uint8_t en;
11528
11529         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11530
11531         if (!strcmp("enable", res->en_dis))
11532                 en = 1;
11533         else
11534                 en = 0;
11535
11536         RTE_ETH_FOREACH_DEV(pid) {
11537                 rte_eth_dev_l2_tunnel_offload_set(pid,
11538                                                   &entry,
11539                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11540                                                   en);
11541         }
11542 }
11543
11544 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11545         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11546         .data = NULL,
11547         .help_str = "port config all l2-tunnel E-tag enable|disable",
11548         .tokens = {
11549                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11550                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11551                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11552                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11553                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11554                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11555                 NULL,
11556         },
11557 };
11558
11559 /* enable/disable l2 tunnel for a port */
11560 static void
11561 cmd_config_l2_tunnel_en_dis_specific_parsed(
11562         void *parsed_result,
11563         __attribute__((unused)) struct cmdline *cl,
11564         __attribute__((unused)) void *data)
11565 {
11566         struct cmd_config_l2_tunnel_en_dis_result *res =
11567                 parsed_result;
11568         struct rte_eth_l2_tunnel_conf entry;
11569
11570         if (port_id_is_invalid(res->id, ENABLED_WARN))
11571                 return;
11572
11573         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11574
11575         if (!strcmp("enable", res->en_dis))
11576                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11577                                                   &entry,
11578                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11579                                                   1);
11580         else
11581                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11582                                                   &entry,
11583                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11584                                                   0);
11585 }
11586
11587 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11588         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11589         .data = NULL,
11590         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11591         .tokens = {
11592                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11593                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11594                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11595                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11596                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11597                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11598                 NULL,
11599         },
11600 };
11601
11602 /* E-tag configuration */
11603
11604 /* Common result structure for all E-tag configuration */
11605 struct cmd_config_e_tag_result {
11606         cmdline_fixed_string_t e_tag;
11607         cmdline_fixed_string_t set;
11608         cmdline_fixed_string_t insertion;
11609         cmdline_fixed_string_t stripping;
11610         cmdline_fixed_string_t forwarding;
11611         cmdline_fixed_string_t filter;
11612         cmdline_fixed_string_t add;
11613         cmdline_fixed_string_t del;
11614         cmdline_fixed_string_t on;
11615         cmdline_fixed_string_t off;
11616         cmdline_fixed_string_t on_off;
11617         cmdline_fixed_string_t port_tag_id;
11618         uint32_t port_tag_id_val;
11619         cmdline_fixed_string_t e_tag_id;
11620         uint16_t e_tag_id_val;
11621         cmdline_fixed_string_t dst_pool;
11622         uint8_t dst_pool_val;
11623         cmdline_fixed_string_t port;
11624         portid_t port_id;
11625         cmdline_fixed_string_t vf;
11626         uint8_t vf_id;
11627 };
11628
11629 /* Common CLI fields for all E-tag configuration */
11630 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11631         TOKEN_STRING_INITIALIZER
11632                 (struct cmd_config_e_tag_result,
11633                  e_tag, "E-tag");
11634 cmdline_parse_token_string_t cmd_config_e_tag_set =
11635         TOKEN_STRING_INITIALIZER
11636                 (struct cmd_config_e_tag_result,
11637                  set, "set");
11638 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11639         TOKEN_STRING_INITIALIZER
11640                 (struct cmd_config_e_tag_result,
11641                  insertion, "insertion");
11642 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11643         TOKEN_STRING_INITIALIZER
11644                 (struct cmd_config_e_tag_result,
11645                  stripping, "stripping");
11646 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11647         TOKEN_STRING_INITIALIZER
11648                 (struct cmd_config_e_tag_result,
11649                  forwarding, "forwarding");
11650 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11651         TOKEN_STRING_INITIALIZER
11652                 (struct cmd_config_e_tag_result,
11653                  filter, "filter");
11654 cmdline_parse_token_string_t cmd_config_e_tag_add =
11655         TOKEN_STRING_INITIALIZER
11656                 (struct cmd_config_e_tag_result,
11657                  add, "add");
11658 cmdline_parse_token_string_t cmd_config_e_tag_del =
11659         TOKEN_STRING_INITIALIZER
11660                 (struct cmd_config_e_tag_result,
11661                  del, "del");
11662 cmdline_parse_token_string_t cmd_config_e_tag_on =
11663         TOKEN_STRING_INITIALIZER
11664                 (struct cmd_config_e_tag_result,
11665                  on, "on");
11666 cmdline_parse_token_string_t cmd_config_e_tag_off =
11667         TOKEN_STRING_INITIALIZER
11668                 (struct cmd_config_e_tag_result,
11669                  off, "off");
11670 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11671         TOKEN_STRING_INITIALIZER
11672                 (struct cmd_config_e_tag_result,
11673                  on_off, "on#off");
11674 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11675         TOKEN_STRING_INITIALIZER
11676                 (struct cmd_config_e_tag_result,
11677                  port_tag_id, "port-tag-id");
11678 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11679         TOKEN_NUM_INITIALIZER
11680                 (struct cmd_config_e_tag_result,
11681                  port_tag_id_val, UINT32);
11682 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11683         TOKEN_STRING_INITIALIZER
11684                 (struct cmd_config_e_tag_result,
11685                  e_tag_id, "e-tag-id");
11686 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11687         TOKEN_NUM_INITIALIZER
11688                 (struct cmd_config_e_tag_result,
11689                  e_tag_id_val, UINT16);
11690 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11691         TOKEN_STRING_INITIALIZER
11692                 (struct cmd_config_e_tag_result,
11693                  dst_pool, "dst-pool");
11694 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11695         TOKEN_NUM_INITIALIZER
11696                 (struct cmd_config_e_tag_result,
11697                  dst_pool_val, UINT8);
11698 cmdline_parse_token_string_t cmd_config_e_tag_port =
11699         TOKEN_STRING_INITIALIZER
11700                 (struct cmd_config_e_tag_result,
11701                  port, "port");
11702 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11703         TOKEN_NUM_INITIALIZER
11704                 (struct cmd_config_e_tag_result,
11705                  port_id, UINT16);
11706 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11707         TOKEN_STRING_INITIALIZER
11708                 (struct cmd_config_e_tag_result,
11709                  vf, "vf");
11710 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11711         TOKEN_NUM_INITIALIZER
11712                 (struct cmd_config_e_tag_result,
11713                  vf_id, UINT8);
11714
11715 /* E-tag insertion configuration */
11716 static void
11717 cmd_config_e_tag_insertion_en_parsed(
11718         void *parsed_result,
11719         __attribute__((unused)) struct cmdline *cl,
11720         __attribute__((unused)) void *data)
11721 {
11722         struct cmd_config_e_tag_result *res =
11723                 parsed_result;
11724         struct rte_eth_l2_tunnel_conf entry;
11725
11726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11727                 return;
11728
11729         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11730         entry.tunnel_id = res->port_tag_id_val;
11731         entry.vf_id = res->vf_id;
11732         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11733                                           &entry,
11734                                           ETH_L2_TUNNEL_INSERTION_MASK,
11735                                           1);
11736 }
11737
11738 static void
11739 cmd_config_e_tag_insertion_dis_parsed(
11740         void *parsed_result,
11741         __attribute__((unused)) struct cmdline *cl,
11742         __attribute__((unused)) void *data)
11743 {
11744         struct cmd_config_e_tag_result *res =
11745                 parsed_result;
11746         struct rte_eth_l2_tunnel_conf entry;
11747
11748         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11749                 return;
11750
11751         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11752         entry.vf_id = res->vf_id;
11753
11754         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11755                                           &entry,
11756                                           ETH_L2_TUNNEL_INSERTION_MASK,
11757                                           0);
11758 }
11759
11760 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11761         .f = cmd_config_e_tag_insertion_en_parsed,
11762         .data = NULL,
11763         .help_str = "E-tag ... : E-tag insertion enable",
11764         .tokens = {
11765                 (void *)&cmd_config_e_tag_e_tag,
11766                 (void *)&cmd_config_e_tag_set,
11767                 (void *)&cmd_config_e_tag_insertion,
11768                 (void *)&cmd_config_e_tag_on,
11769                 (void *)&cmd_config_e_tag_port_tag_id,
11770                 (void *)&cmd_config_e_tag_port_tag_id_val,
11771                 (void *)&cmd_config_e_tag_port,
11772                 (void *)&cmd_config_e_tag_port_id,
11773                 (void *)&cmd_config_e_tag_vf,
11774                 (void *)&cmd_config_e_tag_vf_id,
11775                 NULL,
11776         },
11777 };
11778
11779 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11780         .f = cmd_config_e_tag_insertion_dis_parsed,
11781         .data = NULL,
11782         .help_str = "E-tag ... : E-tag insertion disable",
11783         .tokens = {
11784                 (void *)&cmd_config_e_tag_e_tag,
11785                 (void *)&cmd_config_e_tag_set,
11786                 (void *)&cmd_config_e_tag_insertion,
11787                 (void *)&cmd_config_e_tag_off,
11788                 (void *)&cmd_config_e_tag_port,
11789                 (void *)&cmd_config_e_tag_port_id,
11790                 (void *)&cmd_config_e_tag_vf,
11791                 (void *)&cmd_config_e_tag_vf_id,
11792                 NULL,
11793         },
11794 };
11795
11796 /* E-tag stripping configuration */
11797 static void
11798 cmd_config_e_tag_stripping_parsed(
11799         void *parsed_result,
11800         __attribute__((unused)) struct cmdline *cl,
11801         __attribute__((unused)) void *data)
11802 {
11803         struct cmd_config_e_tag_result *res =
11804                 parsed_result;
11805         struct rte_eth_l2_tunnel_conf entry;
11806
11807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11808                 return;
11809
11810         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11811
11812         if (!strcmp(res->on_off, "on"))
11813                 rte_eth_dev_l2_tunnel_offload_set
11814                         (res->port_id,
11815                          &entry,
11816                          ETH_L2_TUNNEL_STRIPPING_MASK,
11817                          1);
11818         else
11819                 rte_eth_dev_l2_tunnel_offload_set
11820                         (res->port_id,
11821                          &entry,
11822                          ETH_L2_TUNNEL_STRIPPING_MASK,
11823                          0);
11824 }
11825
11826 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11827         .f = cmd_config_e_tag_stripping_parsed,
11828         .data = NULL,
11829         .help_str = "E-tag ... : E-tag stripping enable/disable",
11830         .tokens = {
11831                 (void *)&cmd_config_e_tag_e_tag,
11832                 (void *)&cmd_config_e_tag_set,
11833                 (void *)&cmd_config_e_tag_stripping,
11834                 (void *)&cmd_config_e_tag_on_off,
11835                 (void *)&cmd_config_e_tag_port,
11836                 (void *)&cmd_config_e_tag_port_id,
11837                 NULL,
11838         },
11839 };
11840
11841 /* E-tag forwarding configuration */
11842 static void
11843 cmd_config_e_tag_forwarding_parsed(
11844         void *parsed_result,
11845         __attribute__((unused)) struct cmdline *cl,
11846         __attribute__((unused)) void *data)
11847 {
11848         struct cmd_config_e_tag_result *res = parsed_result;
11849         struct rte_eth_l2_tunnel_conf entry;
11850
11851         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11852                 return;
11853
11854         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11855
11856         if (!strcmp(res->on_off, "on"))
11857                 rte_eth_dev_l2_tunnel_offload_set
11858                         (res->port_id,
11859                          &entry,
11860                          ETH_L2_TUNNEL_FORWARDING_MASK,
11861                          1);
11862         else
11863                 rte_eth_dev_l2_tunnel_offload_set
11864                         (res->port_id,
11865                          &entry,
11866                          ETH_L2_TUNNEL_FORWARDING_MASK,
11867                          0);
11868 }
11869
11870 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11871         .f = cmd_config_e_tag_forwarding_parsed,
11872         .data = NULL,
11873         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11874         .tokens = {
11875                 (void *)&cmd_config_e_tag_e_tag,
11876                 (void *)&cmd_config_e_tag_set,
11877                 (void *)&cmd_config_e_tag_forwarding,
11878                 (void *)&cmd_config_e_tag_on_off,
11879                 (void *)&cmd_config_e_tag_port,
11880                 (void *)&cmd_config_e_tag_port_id,
11881                 NULL,
11882         },
11883 };
11884
11885 /* E-tag filter configuration */
11886 static void
11887 cmd_config_e_tag_filter_add_parsed(
11888         void *parsed_result,
11889         __attribute__((unused)) struct cmdline *cl,
11890         __attribute__((unused)) void *data)
11891 {
11892         struct cmd_config_e_tag_result *res = parsed_result;
11893         struct rte_eth_l2_tunnel_conf entry;
11894         int ret = 0;
11895
11896         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11897                 return;
11898
11899         if (res->e_tag_id_val > 0x3fff) {
11900                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11901                 return;
11902         }
11903
11904         ret = rte_eth_dev_filter_supported(res->port_id,
11905                                            RTE_ETH_FILTER_L2_TUNNEL);
11906         if (ret < 0) {
11907                 printf("E-tag filter is not supported on port %u.\n",
11908                        res->port_id);
11909                 return;
11910         }
11911
11912         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11913         entry.tunnel_id = res->e_tag_id_val;
11914         entry.pool = res->dst_pool_val;
11915
11916         ret = rte_eth_dev_filter_ctrl(res->port_id,
11917                                       RTE_ETH_FILTER_L2_TUNNEL,
11918                                       RTE_ETH_FILTER_ADD,
11919                                       &entry);
11920         if (ret < 0)
11921                 printf("E-tag filter programming error: (%s)\n",
11922                        strerror(-ret));
11923 }
11924
11925 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11926         .f = cmd_config_e_tag_filter_add_parsed,
11927         .data = NULL,
11928         .help_str = "E-tag ... : E-tag filter add",
11929         .tokens = {
11930                 (void *)&cmd_config_e_tag_e_tag,
11931                 (void *)&cmd_config_e_tag_set,
11932                 (void *)&cmd_config_e_tag_filter,
11933                 (void *)&cmd_config_e_tag_add,
11934                 (void *)&cmd_config_e_tag_e_tag_id,
11935                 (void *)&cmd_config_e_tag_e_tag_id_val,
11936                 (void *)&cmd_config_e_tag_dst_pool,
11937                 (void *)&cmd_config_e_tag_dst_pool_val,
11938                 (void *)&cmd_config_e_tag_port,
11939                 (void *)&cmd_config_e_tag_port_id,
11940                 NULL,
11941         },
11942 };
11943
11944 static void
11945 cmd_config_e_tag_filter_del_parsed(
11946         void *parsed_result,
11947         __attribute__((unused)) struct cmdline *cl,
11948         __attribute__((unused)) void *data)
11949 {
11950         struct cmd_config_e_tag_result *res = parsed_result;
11951         struct rte_eth_l2_tunnel_conf entry;
11952         int ret = 0;
11953
11954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11955                 return;
11956
11957         if (res->e_tag_id_val > 0x3fff) {
11958                 printf("e-tag-id must be less than 0x3fff.\n");
11959                 return;
11960         }
11961
11962         ret = rte_eth_dev_filter_supported(res->port_id,
11963                                            RTE_ETH_FILTER_L2_TUNNEL);
11964         if (ret < 0) {
11965                 printf("E-tag filter is not supported on port %u.\n",
11966                        res->port_id);
11967                 return;
11968         }
11969
11970         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11971         entry.tunnel_id = res->e_tag_id_val;
11972
11973         ret = rte_eth_dev_filter_ctrl(res->port_id,
11974                                       RTE_ETH_FILTER_L2_TUNNEL,
11975                                       RTE_ETH_FILTER_DELETE,
11976                                       &entry);
11977         if (ret < 0)
11978                 printf("E-tag filter programming error: (%s)\n",
11979                        strerror(-ret));
11980 }
11981
11982 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11983         .f = cmd_config_e_tag_filter_del_parsed,
11984         .data = NULL,
11985         .help_str = "E-tag ... : E-tag filter delete",
11986         .tokens = {
11987                 (void *)&cmd_config_e_tag_e_tag,
11988                 (void *)&cmd_config_e_tag_set,
11989                 (void *)&cmd_config_e_tag_filter,
11990                 (void *)&cmd_config_e_tag_del,
11991                 (void *)&cmd_config_e_tag_e_tag_id,
11992                 (void *)&cmd_config_e_tag_e_tag_id_val,
11993                 (void *)&cmd_config_e_tag_port,
11994                 (void *)&cmd_config_e_tag_port_id,
11995                 NULL,
11996         },
11997 };
11998
11999 /* vf vlan anti spoof configuration */
12000
12001 /* Common result structure for vf vlan anti spoof */
12002 struct cmd_vf_vlan_anti_spoof_result {
12003         cmdline_fixed_string_t set;
12004         cmdline_fixed_string_t vf;
12005         cmdline_fixed_string_t vlan;
12006         cmdline_fixed_string_t antispoof;
12007         portid_t port_id;
12008         uint32_t vf_id;
12009         cmdline_fixed_string_t on_off;
12010 };
12011
12012 /* Common CLI fields for vf vlan anti spoof enable disable */
12013 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12014         TOKEN_STRING_INITIALIZER
12015                 (struct cmd_vf_vlan_anti_spoof_result,
12016                  set, "set");
12017 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12018         TOKEN_STRING_INITIALIZER
12019                 (struct cmd_vf_vlan_anti_spoof_result,
12020                  vf, "vf");
12021 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12022         TOKEN_STRING_INITIALIZER
12023                 (struct cmd_vf_vlan_anti_spoof_result,
12024                  vlan, "vlan");
12025 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12026         TOKEN_STRING_INITIALIZER
12027                 (struct cmd_vf_vlan_anti_spoof_result,
12028                  antispoof, "antispoof");
12029 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12030         TOKEN_NUM_INITIALIZER
12031                 (struct cmd_vf_vlan_anti_spoof_result,
12032                  port_id, UINT16);
12033 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12034         TOKEN_NUM_INITIALIZER
12035                 (struct cmd_vf_vlan_anti_spoof_result,
12036                  vf_id, UINT32);
12037 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12038         TOKEN_STRING_INITIALIZER
12039                 (struct cmd_vf_vlan_anti_spoof_result,
12040                  on_off, "on#off");
12041
12042 static void
12043 cmd_set_vf_vlan_anti_spoof_parsed(
12044         void *parsed_result,
12045         __attribute__((unused)) struct cmdline *cl,
12046         __attribute__((unused)) void *data)
12047 {
12048         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12049         int ret = -ENOTSUP;
12050
12051         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12052
12053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12054                 return;
12055
12056 #ifdef RTE_LIBRTE_IXGBE_PMD
12057         if (ret == -ENOTSUP)
12058                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12059                                 res->vf_id, is_on);
12060 #endif
12061 #ifdef RTE_LIBRTE_I40E_PMD
12062         if (ret == -ENOTSUP)
12063                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12064                                 res->vf_id, is_on);
12065 #endif
12066 #ifdef RTE_LIBRTE_BNXT_PMD
12067         if (ret == -ENOTSUP)
12068                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12069                                 res->vf_id, is_on);
12070 #endif
12071
12072         switch (ret) {
12073         case 0:
12074                 break;
12075         case -EINVAL:
12076                 printf("invalid vf_id %d\n", res->vf_id);
12077                 break;
12078         case -ENODEV:
12079                 printf("invalid port_id %d\n", res->port_id);
12080                 break;
12081         case -ENOTSUP:
12082                 printf("function not implemented\n");
12083                 break;
12084         default:
12085                 printf("programming error: (%s)\n", strerror(-ret));
12086         }
12087 }
12088
12089 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12090         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12091         .data = NULL,
12092         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12093         .tokens = {
12094                 (void *)&cmd_vf_vlan_anti_spoof_set,
12095                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12096                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12097                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12098                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12099                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12100                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12101                 NULL,
12102         },
12103 };
12104
12105 /* vf mac anti spoof configuration */
12106
12107 /* Common result structure for vf mac anti spoof */
12108 struct cmd_vf_mac_anti_spoof_result {
12109         cmdline_fixed_string_t set;
12110         cmdline_fixed_string_t vf;
12111         cmdline_fixed_string_t mac;
12112         cmdline_fixed_string_t antispoof;
12113         portid_t port_id;
12114         uint32_t vf_id;
12115         cmdline_fixed_string_t on_off;
12116 };
12117
12118 /* Common CLI fields for vf mac anti spoof enable disable */
12119 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12120         TOKEN_STRING_INITIALIZER
12121                 (struct cmd_vf_mac_anti_spoof_result,
12122                  set, "set");
12123 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12124         TOKEN_STRING_INITIALIZER
12125                 (struct cmd_vf_mac_anti_spoof_result,
12126                  vf, "vf");
12127 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12128         TOKEN_STRING_INITIALIZER
12129                 (struct cmd_vf_mac_anti_spoof_result,
12130                  mac, "mac");
12131 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12132         TOKEN_STRING_INITIALIZER
12133                 (struct cmd_vf_mac_anti_spoof_result,
12134                  antispoof, "antispoof");
12135 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12136         TOKEN_NUM_INITIALIZER
12137                 (struct cmd_vf_mac_anti_spoof_result,
12138                  port_id, UINT16);
12139 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12140         TOKEN_NUM_INITIALIZER
12141                 (struct cmd_vf_mac_anti_spoof_result,
12142                  vf_id, UINT32);
12143 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12144         TOKEN_STRING_INITIALIZER
12145                 (struct cmd_vf_mac_anti_spoof_result,
12146                  on_off, "on#off");
12147
12148 static void
12149 cmd_set_vf_mac_anti_spoof_parsed(
12150         void *parsed_result,
12151         __attribute__((unused)) struct cmdline *cl,
12152         __attribute__((unused)) void *data)
12153 {
12154         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12155         int ret = -ENOTSUP;
12156
12157         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12158
12159         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12160                 return;
12161
12162 #ifdef RTE_LIBRTE_IXGBE_PMD
12163         if (ret == -ENOTSUP)
12164                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12165                         res->vf_id, is_on);
12166 #endif
12167 #ifdef RTE_LIBRTE_I40E_PMD
12168         if (ret == -ENOTSUP)
12169                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12170                         res->vf_id, is_on);
12171 #endif
12172 #ifdef RTE_LIBRTE_BNXT_PMD
12173         if (ret == -ENOTSUP)
12174                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12175                         res->vf_id, is_on);
12176 #endif
12177
12178         switch (ret) {
12179         case 0:
12180                 break;
12181         case -EINVAL:
12182                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12183                 break;
12184         case -ENODEV:
12185                 printf("invalid port_id %d\n", res->port_id);
12186                 break;
12187         case -ENOTSUP:
12188                 printf("function not implemented\n");
12189                 break;
12190         default:
12191                 printf("programming error: (%s)\n", strerror(-ret));
12192         }
12193 }
12194
12195 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12196         .f = cmd_set_vf_mac_anti_spoof_parsed,
12197         .data = NULL,
12198         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12199         .tokens = {
12200                 (void *)&cmd_vf_mac_anti_spoof_set,
12201                 (void *)&cmd_vf_mac_anti_spoof_vf,
12202                 (void *)&cmd_vf_mac_anti_spoof_mac,
12203                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12204                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12205                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12206                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12207                 NULL,
12208         },
12209 };
12210
12211 /* vf vlan strip queue configuration */
12212
12213 /* Common result structure for vf mac anti spoof */
12214 struct cmd_vf_vlan_stripq_result {
12215         cmdline_fixed_string_t set;
12216         cmdline_fixed_string_t vf;
12217         cmdline_fixed_string_t vlan;
12218         cmdline_fixed_string_t stripq;
12219         portid_t port_id;
12220         uint16_t vf_id;
12221         cmdline_fixed_string_t on_off;
12222 };
12223
12224 /* Common CLI fields for vf vlan strip enable disable */
12225 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12226         TOKEN_STRING_INITIALIZER
12227                 (struct cmd_vf_vlan_stripq_result,
12228                  set, "set");
12229 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12230         TOKEN_STRING_INITIALIZER
12231                 (struct cmd_vf_vlan_stripq_result,
12232                  vf, "vf");
12233 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12234         TOKEN_STRING_INITIALIZER
12235                 (struct cmd_vf_vlan_stripq_result,
12236                  vlan, "vlan");
12237 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12238         TOKEN_STRING_INITIALIZER
12239                 (struct cmd_vf_vlan_stripq_result,
12240                  stripq, "stripq");
12241 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12242         TOKEN_NUM_INITIALIZER
12243                 (struct cmd_vf_vlan_stripq_result,
12244                  port_id, UINT16);
12245 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12246         TOKEN_NUM_INITIALIZER
12247                 (struct cmd_vf_vlan_stripq_result,
12248                  vf_id, UINT16);
12249 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12250         TOKEN_STRING_INITIALIZER
12251                 (struct cmd_vf_vlan_stripq_result,
12252                  on_off, "on#off");
12253
12254 static void
12255 cmd_set_vf_vlan_stripq_parsed(
12256         void *parsed_result,
12257         __attribute__((unused)) struct cmdline *cl,
12258         __attribute__((unused)) void *data)
12259 {
12260         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12261         int ret = -ENOTSUP;
12262
12263         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12264
12265         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12266                 return;
12267
12268 #ifdef RTE_LIBRTE_IXGBE_PMD
12269         if (ret == -ENOTSUP)
12270                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12271                         res->vf_id, is_on);
12272 #endif
12273 #ifdef RTE_LIBRTE_I40E_PMD
12274         if (ret == -ENOTSUP)
12275                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12276                         res->vf_id, is_on);
12277 #endif
12278 #ifdef RTE_LIBRTE_BNXT_PMD
12279         if (ret == -ENOTSUP)
12280                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12281                         res->vf_id, is_on);
12282 #endif
12283
12284         switch (ret) {
12285         case 0:
12286                 break;
12287         case -EINVAL:
12288                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12289                 break;
12290         case -ENODEV:
12291                 printf("invalid port_id %d\n", res->port_id);
12292                 break;
12293         case -ENOTSUP:
12294                 printf("function not implemented\n");
12295                 break;
12296         default:
12297                 printf("programming error: (%s)\n", strerror(-ret));
12298         }
12299 }
12300
12301 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12302         .f = cmd_set_vf_vlan_stripq_parsed,
12303         .data = NULL,
12304         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12305         .tokens = {
12306                 (void *)&cmd_vf_vlan_stripq_set,
12307                 (void *)&cmd_vf_vlan_stripq_vf,
12308                 (void *)&cmd_vf_vlan_stripq_vlan,
12309                 (void *)&cmd_vf_vlan_stripq_stripq,
12310                 (void *)&cmd_vf_vlan_stripq_port_id,
12311                 (void *)&cmd_vf_vlan_stripq_vf_id,
12312                 (void *)&cmd_vf_vlan_stripq_on_off,
12313                 NULL,
12314         },
12315 };
12316
12317 /* vf vlan insert configuration */
12318
12319 /* Common result structure for vf vlan insert */
12320 struct cmd_vf_vlan_insert_result {
12321         cmdline_fixed_string_t set;
12322         cmdline_fixed_string_t vf;
12323         cmdline_fixed_string_t vlan;
12324         cmdline_fixed_string_t insert;
12325         portid_t port_id;
12326         uint16_t vf_id;
12327         uint16_t vlan_id;
12328 };
12329
12330 /* Common CLI fields for vf vlan insert enable disable */
12331 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12332         TOKEN_STRING_INITIALIZER
12333                 (struct cmd_vf_vlan_insert_result,
12334                  set, "set");
12335 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12336         TOKEN_STRING_INITIALIZER
12337                 (struct cmd_vf_vlan_insert_result,
12338                  vf, "vf");
12339 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_vf_vlan_insert_result,
12342                  vlan, "vlan");
12343 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12344         TOKEN_STRING_INITIALIZER
12345                 (struct cmd_vf_vlan_insert_result,
12346                  insert, "insert");
12347 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12348         TOKEN_NUM_INITIALIZER
12349                 (struct cmd_vf_vlan_insert_result,
12350                  port_id, UINT16);
12351 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12352         TOKEN_NUM_INITIALIZER
12353                 (struct cmd_vf_vlan_insert_result,
12354                  vf_id, UINT16);
12355 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12356         TOKEN_NUM_INITIALIZER
12357                 (struct cmd_vf_vlan_insert_result,
12358                  vlan_id, UINT16);
12359
12360 static void
12361 cmd_set_vf_vlan_insert_parsed(
12362         void *parsed_result,
12363         __attribute__((unused)) struct cmdline *cl,
12364         __attribute__((unused)) void *data)
12365 {
12366         struct cmd_vf_vlan_insert_result *res = parsed_result;
12367         int ret = -ENOTSUP;
12368
12369         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12370                 return;
12371
12372 #ifdef RTE_LIBRTE_IXGBE_PMD
12373         if (ret == -ENOTSUP)
12374                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12375                         res->vlan_id);
12376 #endif
12377 #ifdef RTE_LIBRTE_I40E_PMD
12378         if (ret == -ENOTSUP)
12379                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12380                         res->vlan_id);
12381 #endif
12382 #ifdef RTE_LIBRTE_BNXT_PMD
12383         if (ret == -ENOTSUP)
12384                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12385                         res->vlan_id);
12386 #endif
12387
12388         switch (ret) {
12389         case 0:
12390                 break;
12391         case -EINVAL:
12392                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12393                 break;
12394         case -ENODEV:
12395                 printf("invalid port_id %d\n", res->port_id);
12396                 break;
12397         case -ENOTSUP:
12398                 printf("function not implemented\n");
12399                 break;
12400         default:
12401                 printf("programming error: (%s)\n", strerror(-ret));
12402         }
12403 }
12404
12405 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12406         .f = cmd_set_vf_vlan_insert_parsed,
12407         .data = NULL,
12408         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12409         .tokens = {
12410                 (void *)&cmd_vf_vlan_insert_set,
12411                 (void *)&cmd_vf_vlan_insert_vf,
12412                 (void *)&cmd_vf_vlan_insert_vlan,
12413                 (void *)&cmd_vf_vlan_insert_insert,
12414                 (void *)&cmd_vf_vlan_insert_port_id,
12415                 (void *)&cmd_vf_vlan_insert_vf_id,
12416                 (void *)&cmd_vf_vlan_insert_vlan_id,
12417                 NULL,
12418         },
12419 };
12420
12421 /* tx loopback configuration */
12422
12423 /* Common result structure for tx loopback */
12424 struct cmd_tx_loopback_result {
12425         cmdline_fixed_string_t set;
12426         cmdline_fixed_string_t tx;
12427         cmdline_fixed_string_t loopback;
12428         portid_t port_id;
12429         cmdline_fixed_string_t on_off;
12430 };
12431
12432 /* Common CLI fields for tx loopback enable disable */
12433 cmdline_parse_token_string_t cmd_tx_loopback_set =
12434         TOKEN_STRING_INITIALIZER
12435                 (struct cmd_tx_loopback_result,
12436                  set, "set");
12437 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12438         TOKEN_STRING_INITIALIZER
12439                 (struct cmd_tx_loopback_result,
12440                  tx, "tx");
12441 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12442         TOKEN_STRING_INITIALIZER
12443                 (struct cmd_tx_loopback_result,
12444                  loopback, "loopback");
12445 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12446         TOKEN_NUM_INITIALIZER
12447                 (struct cmd_tx_loopback_result,
12448                  port_id, UINT16);
12449 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12450         TOKEN_STRING_INITIALIZER
12451                 (struct cmd_tx_loopback_result,
12452                  on_off, "on#off");
12453
12454 static void
12455 cmd_set_tx_loopback_parsed(
12456         void *parsed_result,
12457         __attribute__((unused)) struct cmdline *cl,
12458         __attribute__((unused)) void *data)
12459 {
12460         struct cmd_tx_loopback_result *res = parsed_result;
12461         int ret = -ENOTSUP;
12462
12463         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12464
12465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12466                 return;
12467
12468 #ifdef RTE_LIBRTE_IXGBE_PMD
12469         if (ret == -ENOTSUP)
12470                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12471 #endif
12472 #ifdef RTE_LIBRTE_I40E_PMD
12473         if (ret == -ENOTSUP)
12474                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12475 #endif
12476 #ifdef RTE_LIBRTE_BNXT_PMD
12477         if (ret == -ENOTSUP)
12478                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12479 #endif
12480
12481         switch (ret) {
12482         case 0:
12483                 break;
12484         case -EINVAL:
12485                 printf("invalid is_on %d\n", is_on);
12486                 break;
12487         case -ENODEV:
12488                 printf("invalid port_id %d\n", res->port_id);
12489                 break;
12490         case -ENOTSUP:
12491                 printf("function not implemented\n");
12492                 break;
12493         default:
12494                 printf("programming error: (%s)\n", strerror(-ret));
12495         }
12496 }
12497
12498 cmdline_parse_inst_t cmd_set_tx_loopback = {
12499         .f = cmd_set_tx_loopback_parsed,
12500         .data = NULL,
12501         .help_str = "set tx loopback <port_id> on|off",
12502         .tokens = {
12503                 (void *)&cmd_tx_loopback_set,
12504                 (void *)&cmd_tx_loopback_tx,
12505                 (void *)&cmd_tx_loopback_loopback,
12506                 (void *)&cmd_tx_loopback_port_id,
12507                 (void *)&cmd_tx_loopback_on_off,
12508                 NULL,
12509         },
12510 };
12511
12512 /* all queues drop enable configuration */
12513
12514 /* Common result structure for all queues drop enable */
12515 struct cmd_all_queues_drop_en_result {
12516         cmdline_fixed_string_t set;
12517         cmdline_fixed_string_t all;
12518         cmdline_fixed_string_t queues;
12519         cmdline_fixed_string_t drop;
12520         portid_t port_id;
12521         cmdline_fixed_string_t on_off;
12522 };
12523
12524 /* Common CLI fields for tx loopback enable disable */
12525 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12526         TOKEN_STRING_INITIALIZER
12527                 (struct cmd_all_queues_drop_en_result,
12528                  set, "set");
12529 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_all_queues_drop_en_result,
12532                  all, "all");
12533 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12534         TOKEN_STRING_INITIALIZER
12535                 (struct cmd_all_queues_drop_en_result,
12536                  queues, "queues");
12537 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12538         TOKEN_STRING_INITIALIZER
12539                 (struct cmd_all_queues_drop_en_result,
12540                  drop, "drop");
12541 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12542         TOKEN_NUM_INITIALIZER
12543                 (struct cmd_all_queues_drop_en_result,
12544                  port_id, UINT16);
12545 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12546         TOKEN_STRING_INITIALIZER
12547                 (struct cmd_all_queues_drop_en_result,
12548                  on_off, "on#off");
12549
12550 static void
12551 cmd_set_all_queues_drop_en_parsed(
12552         void *parsed_result,
12553         __attribute__((unused)) struct cmdline *cl,
12554         __attribute__((unused)) void *data)
12555 {
12556         struct cmd_all_queues_drop_en_result *res = parsed_result;
12557         int ret = -ENOTSUP;
12558         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12559
12560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12561                 return;
12562
12563 #ifdef RTE_LIBRTE_IXGBE_PMD
12564         if (ret == -ENOTSUP)
12565                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12566 #endif
12567 #ifdef RTE_LIBRTE_BNXT_PMD
12568         if (ret == -ENOTSUP)
12569                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12570 #endif
12571         switch (ret) {
12572         case 0:
12573                 break;
12574         case -EINVAL:
12575                 printf("invalid is_on %d\n", is_on);
12576                 break;
12577         case -ENODEV:
12578                 printf("invalid port_id %d\n", res->port_id);
12579                 break;
12580         case -ENOTSUP:
12581                 printf("function not implemented\n");
12582                 break;
12583         default:
12584                 printf("programming error: (%s)\n", strerror(-ret));
12585         }
12586 }
12587
12588 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12589         .f = cmd_set_all_queues_drop_en_parsed,
12590         .data = NULL,
12591         .help_str = "set all queues drop <port_id> on|off",
12592         .tokens = {
12593                 (void *)&cmd_all_queues_drop_en_set,
12594                 (void *)&cmd_all_queues_drop_en_all,
12595                 (void *)&cmd_all_queues_drop_en_queues,
12596                 (void *)&cmd_all_queues_drop_en_drop,
12597                 (void *)&cmd_all_queues_drop_en_port_id,
12598                 (void *)&cmd_all_queues_drop_en_on_off,
12599                 NULL,
12600         },
12601 };
12602
12603 /* vf split drop enable configuration */
12604
12605 /* Common result structure for vf split drop enable */
12606 struct cmd_vf_split_drop_en_result {
12607         cmdline_fixed_string_t set;
12608         cmdline_fixed_string_t vf;
12609         cmdline_fixed_string_t split;
12610         cmdline_fixed_string_t drop;
12611         portid_t port_id;
12612         uint16_t vf_id;
12613         cmdline_fixed_string_t on_off;
12614 };
12615
12616 /* Common CLI fields for vf split drop enable disable */
12617 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12618         TOKEN_STRING_INITIALIZER
12619                 (struct cmd_vf_split_drop_en_result,
12620                  set, "set");
12621 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12622         TOKEN_STRING_INITIALIZER
12623                 (struct cmd_vf_split_drop_en_result,
12624                  vf, "vf");
12625 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12626         TOKEN_STRING_INITIALIZER
12627                 (struct cmd_vf_split_drop_en_result,
12628                  split, "split");
12629 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12630         TOKEN_STRING_INITIALIZER
12631                 (struct cmd_vf_split_drop_en_result,
12632                  drop, "drop");
12633 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12634         TOKEN_NUM_INITIALIZER
12635                 (struct cmd_vf_split_drop_en_result,
12636                  port_id, UINT16);
12637 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12638         TOKEN_NUM_INITIALIZER
12639                 (struct cmd_vf_split_drop_en_result,
12640                  vf_id, UINT16);
12641 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12642         TOKEN_STRING_INITIALIZER
12643                 (struct cmd_vf_split_drop_en_result,
12644                  on_off, "on#off");
12645
12646 static void
12647 cmd_set_vf_split_drop_en_parsed(
12648         void *parsed_result,
12649         __attribute__((unused)) struct cmdline *cl,
12650         __attribute__((unused)) void *data)
12651 {
12652         struct cmd_vf_split_drop_en_result *res = parsed_result;
12653         int ret = -ENOTSUP;
12654         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12655
12656         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12657                 return;
12658
12659 #ifdef RTE_LIBRTE_IXGBE_PMD
12660         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12661                         is_on);
12662 #endif
12663         switch (ret) {
12664         case 0:
12665                 break;
12666         case -EINVAL:
12667                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12668                 break;
12669         case -ENODEV:
12670                 printf("invalid port_id %d\n", res->port_id);
12671                 break;
12672         case -ENOTSUP:
12673                 printf("not supported on port %d\n", res->port_id);
12674                 break;
12675         default:
12676                 printf("programming error: (%s)\n", strerror(-ret));
12677         }
12678 }
12679
12680 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12681         .f = cmd_set_vf_split_drop_en_parsed,
12682         .data = NULL,
12683         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12684         .tokens = {
12685                 (void *)&cmd_vf_split_drop_en_set,
12686                 (void *)&cmd_vf_split_drop_en_vf,
12687                 (void *)&cmd_vf_split_drop_en_split,
12688                 (void *)&cmd_vf_split_drop_en_drop,
12689                 (void *)&cmd_vf_split_drop_en_port_id,
12690                 (void *)&cmd_vf_split_drop_en_vf_id,
12691                 (void *)&cmd_vf_split_drop_en_on_off,
12692                 NULL,
12693         },
12694 };
12695
12696 /* vf mac address configuration */
12697
12698 /* Common result structure for vf mac address */
12699 struct cmd_set_vf_mac_addr_result {
12700         cmdline_fixed_string_t set;
12701         cmdline_fixed_string_t vf;
12702         cmdline_fixed_string_t mac;
12703         cmdline_fixed_string_t addr;
12704         portid_t port_id;
12705         uint16_t vf_id;
12706         struct ether_addr mac_addr;
12707
12708 };
12709
12710 /* Common CLI fields for vf split drop enable disable */
12711 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12712         TOKEN_STRING_INITIALIZER
12713                 (struct cmd_set_vf_mac_addr_result,
12714                  set, "set");
12715 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12716         TOKEN_STRING_INITIALIZER
12717                 (struct cmd_set_vf_mac_addr_result,
12718                  vf, "vf");
12719 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12720         TOKEN_STRING_INITIALIZER
12721                 (struct cmd_set_vf_mac_addr_result,
12722                  mac, "mac");
12723 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12724         TOKEN_STRING_INITIALIZER
12725                 (struct cmd_set_vf_mac_addr_result,
12726                  addr, "addr");
12727 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12728         TOKEN_NUM_INITIALIZER
12729                 (struct cmd_set_vf_mac_addr_result,
12730                  port_id, UINT16);
12731 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12732         TOKEN_NUM_INITIALIZER
12733                 (struct cmd_set_vf_mac_addr_result,
12734                  vf_id, UINT16);
12735 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12736         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12737                  mac_addr);
12738
12739 static void
12740 cmd_set_vf_mac_addr_parsed(
12741         void *parsed_result,
12742         __attribute__((unused)) struct cmdline *cl,
12743         __attribute__((unused)) void *data)
12744 {
12745         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12746         int ret = -ENOTSUP;
12747
12748         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12749                 return;
12750
12751 #ifdef RTE_LIBRTE_IXGBE_PMD
12752         if (ret == -ENOTSUP)
12753                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12754                                 &res->mac_addr);
12755 #endif
12756 #ifdef RTE_LIBRTE_I40E_PMD
12757         if (ret == -ENOTSUP)
12758                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12759                                 &res->mac_addr);
12760 #endif
12761 #ifdef RTE_LIBRTE_BNXT_PMD
12762         if (ret == -ENOTSUP)
12763                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12764                                 &res->mac_addr);
12765 #endif
12766
12767         switch (ret) {
12768         case 0:
12769                 break;
12770         case -EINVAL:
12771                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12772                 break;
12773         case -ENODEV:
12774                 printf("invalid port_id %d\n", res->port_id);
12775                 break;
12776         case -ENOTSUP:
12777                 printf("function not implemented\n");
12778                 break;
12779         default:
12780                 printf("programming error: (%s)\n", strerror(-ret));
12781         }
12782 }
12783
12784 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12785         .f = cmd_set_vf_mac_addr_parsed,
12786         .data = NULL,
12787         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12788         .tokens = {
12789                 (void *)&cmd_set_vf_mac_addr_set,
12790                 (void *)&cmd_set_vf_mac_addr_vf,
12791                 (void *)&cmd_set_vf_mac_addr_mac,
12792                 (void *)&cmd_set_vf_mac_addr_addr,
12793                 (void *)&cmd_set_vf_mac_addr_port_id,
12794                 (void *)&cmd_set_vf_mac_addr_vf_id,
12795                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12796                 NULL,
12797         },
12798 };
12799
12800 /* MACsec configuration */
12801
12802 /* Common result structure for MACsec offload enable */
12803 struct cmd_macsec_offload_on_result {
12804         cmdline_fixed_string_t set;
12805         cmdline_fixed_string_t macsec;
12806         cmdline_fixed_string_t offload;
12807         portid_t port_id;
12808         cmdline_fixed_string_t on;
12809         cmdline_fixed_string_t encrypt;
12810         cmdline_fixed_string_t en_on_off;
12811         cmdline_fixed_string_t replay_protect;
12812         cmdline_fixed_string_t rp_on_off;
12813 };
12814
12815 /* Common CLI fields for MACsec offload disable */
12816 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12817         TOKEN_STRING_INITIALIZER
12818                 (struct cmd_macsec_offload_on_result,
12819                  set, "set");
12820 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12821         TOKEN_STRING_INITIALIZER
12822                 (struct cmd_macsec_offload_on_result,
12823                  macsec, "macsec");
12824 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12825         TOKEN_STRING_INITIALIZER
12826                 (struct cmd_macsec_offload_on_result,
12827                  offload, "offload");
12828 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12829         TOKEN_NUM_INITIALIZER
12830                 (struct cmd_macsec_offload_on_result,
12831                  port_id, UINT16);
12832 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12833         TOKEN_STRING_INITIALIZER
12834                 (struct cmd_macsec_offload_on_result,
12835                  on, "on");
12836 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12837         TOKEN_STRING_INITIALIZER
12838                 (struct cmd_macsec_offload_on_result,
12839                  encrypt, "encrypt");
12840 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12841         TOKEN_STRING_INITIALIZER
12842                 (struct cmd_macsec_offload_on_result,
12843                  en_on_off, "on#off");
12844 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12845         TOKEN_STRING_INITIALIZER
12846                 (struct cmd_macsec_offload_on_result,
12847                  replay_protect, "replay-protect");
12848 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12849         TOKEN_STRING_INITIALIZER
12850                 (struct cmd_macsec_offload_on_result,
12851                  rp_on_off, "on#off");
12852
12853 static void
12854 cmd_set_macsec_offload_on_parsed(
12855         void *parsed_result,
12856         __attribute__((unused)) struct cmdline *cl,
12857         __attribute__((unused)) void *data)
12858 {
12859         struct cmd_macsec_offload_on_result *res = parsed_result;
12860         int ret = -ENOTSUP;
12861         portid_t port_id = res->port_id;
12862         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12863         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12864
12865         if (port_id_is_invalid(port_id, ENABLED_WARN))
12866                 return;
12867
12868         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12869 #ifdef RTE_LIBRTE_IXGBE_PMD
12870         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12871 #endif
12872         RTE_SET_USED(en);
12873         RTE_SET_USED(rp);
12874
12875         switch (ret) {
12876         case 0:
12877                 break;
12878         case -ENODEV:
12879                 printf("invalid port_id %d\n", port_id);
12880                 break;
12881         case -ENOTSUP:
12882                 printf("not supported on port %d\n", port_id);
12883                 break;
12884         default:
12885                 printf("programming error: (%s)\n", strerror(-ret));
12886         }
12887 }
12888
12889 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12890         .f = cmd_set_macsec_offload_on_parsed,
12891         .data = NULL,
12892         .help_str = "set macsec offload <port_id> on "
12893                 "encrypt on|off replay-protect on|off",
12894         .tokens = {
12895                 (void *)&cmd_macsec_offload_on_set,
12896                 (void *)&cmd_macsec_offload_on_macsec,
12897                 (void *)&cmd_macsec_offload_on_offload,
12898                 (void *)&cmd_macsec_offload_on_port_id,
12899                 (void *)&cmd_macsec_offload_on_on,
12900                 (void *)&cmd_macsec_offload_on_encrypt,
12901                 (void *)&cmd_macsec_offload_on_en_on_off,
12902                 (void *)&cmd_macsec_offload_on_replay_protect,
12903                 (void *)&cmd_macsec_offload_on_rp_on_off,
12904                 NULL,
12905         },
12906 };
12907
12908 /* Common result structure for MACsec offload disable */
12909 struct cmd_macsec_offload_off_result {
12910         cmdline_fixed_string_t set;
12911         cmdline_fixed_string_t macsec;
12912         cmdline_fixed_string_t offload;
12913         portid_t port_id;
12914         cmdline_fixed_string_t off;
12915 };
12916
12917 /* Common CLI fields for MACsec offload disable */
12918 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12919         TOKEN_STRING_INITIALIZER
12920                 (struct cmd_macsec_offload_off_result,
12921                  set, "set");
12922 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12923         TOKEN_STRING_INITIALIZER
12924                 (struct cmd_macsec_offload_off_result,
12925                  macsec, "macsec");
12926 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12927         TOKEN_STRING_INITIALIZER
12928                 (struct cmd_macsec_offload_off_result,
12929                  offload, "offload");
12930 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12931         TOKEN_NUM_INITIALIZER
12932                 (struct cmd_macsec_offload_off_result,
12933                  port_id, UINT16);
12934 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12935         TOKEN_STRING_INITIALIZER
12936                 (struct cmd_macsec_offload_off_result,
12937                  off, "off");
12938
12939 static void
12940 cmd_set_macsec_offload_off_parsed(
12941         void *parsed_result,
12942         __attribute__((unused)) struct cmdline *cl,
12943         __attribute__((unused)) void *data)
12944 {
12945         struct cmd_macsec_offload_off_result *res = parsed_result;
12946         int ret = -ENOTSUP;
12947         portid_t port_id = res->port_id;
12948
12949         if (port_id_is_invalid(port_id, ENABLED_WARN))
12950                 return;
12951
12952         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12953 #ifdef RTE_LIBRTE_IXGBE_PMD
12954         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12955 #endif
12956
12957         switch (ret) {
12958         case 0:
12959                 break;
12960         case -ENODEV:
12961                 printf("invalid port_id %d\n", port_id);
12962                 break;
12963         case -ENOTSUP:
12964                 printf("not supported on port %d\n", port_id);
12965                 break;
12966         default:
12967                 printf("programming error: (%s)\n", strerror(-ret));
12968         }
12969 }
12970
12971 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12972         .f = cmd_set_macsec_offload_off_parsed,
12973         .data = NULL,
12974         .help_str = "set macsec offload <port_id> off",
12975         .tokens = {
12976                 (void *)&cmd_macsec_offload_off_set,
12977                 (void *)&cmd_macsec_offload_off_macsec,
12978                 (void *)&cmd_macsec_offload_off_offload,
12979                 (void *)&cmd_macsec_offload_off_port_id,
12980                 (void *)&cmd_macsec_offload_off_off,
12981                 NULL,
12982         },
12983 };
12984
12985 /* Common result structure for MACsec secure connection configure */
12986 struct cmd_macsec_sc_result {
12987         cmdline_fixed_string_t set;
12988         cmdline_fixed_string_t macsec;
12989         cmdline_fixed_string_t sc;
12990         cmdline_fixed_string_t tx_rx;
12991         portid_t port_id;
12992         struct ether_addr mac;
12993         uint16_t pi;
12994 };
12995
12996 /* Common CLI fields for MACsec secure connection configure */
12997 cmdline_parse_token_string_t cmd_macsec_sc_set =
12998         TOKEN_STRING_INITIALIZER
12999                 (struct cmd_macsec_sc_result,
13000                  set, "set");
13001 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13002         TOKEN_STRING_INITIALIZER
13003                 (struct cmd_macsec_sc_result,
13004                  macsec, "macsec");
13005 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13006         TOKEN_STRING_INITIALIZER
13007                 (struct cmd_macsec_sc_result,
13008                  sc, "sc");
13009 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13010         TOKEN_STRING_INITIALIZER
13011                 (struct cmd_macsec_sc_result,
13012                  tx_rx, "tx#rx");
13013 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13014         TOKEN_NUM_INITIALIZER
13015                 (struct cmd_macsec_sc_result,
13016                  port_id, UINT16);
13017 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13018         TOKEN_ETHERADDR_INITIALIZER
13019                 (struct cmd_macsec_sc_result,
13020                  mac);
13021 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13022         TOKEN_NUM_INITIALIZER
13023                 (struct cmd_macsec_sc_result,
13024                  pi, UINT16);
13025
13026 static void
13027 cmd_set_macsec_sc_parsed(
13028         void *parsed_result,
13029         __attribute__((unused)) struct cmdline *cl,
13030         __attribute__((unused)) void *data)
13031 {
13032         struct cmd_macsec_sc_result *res = parsed_result;
13033         int ret = -ENOTSUP;
13034         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13035
13036 #ifdef RTE_LIBRTE_IXGBE_PMD
13037         ret = is_tx ?
13038                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13039                                 res->mac.addr_bytes) :
13040                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13041                                 res->mac.addr_bytes, res->pi);
13042 #endif
13043         RTE_SET_USED(is_tx);
13044
13045         switch (ret) {
13046         case 0:
13047                 break;
13048         case -ENODEV:
13049                 printf("invalid port_id %d\n", res->port_id);
13050                 break;
13051         case -ENOTSUP:
13052                 printf("not supported on port %d\n", res->port_id);
13053                 break;
13054         default:
13055                 printf("programming error: (%s)\n", strerror(-ret));
13056         }
13057 }
13058
13059 cmdline_parse_inst_t cmd_set_macsec_sc = {
13060         .f = cmd_set_macsec_sc_parsed,
13061         .data = NULL,
13062         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13063         .tokens = {
13064                 (void *)&cmd_macsec_sc_set,
13065                 (void *)&cmd_macsec_sc_macsec,
13066                 (void *)&cmd_macsec_sc_sc,
13067                 (void *)&cmd_macsec_sc_tx_rx,
13068                 (void *)&cmd_macsec_sc_port_id,
13069                 (void *)&cmd_macsec_sc_mac,
13070                 (void *)&cmd_macsec_sc_pi,
13071                 NULL,
13072         },
13073 };
13074
13075 /* Common result structure for MACsec secure connection configure */
13076 struct cmd_macsec_sa_result {
13077         cmdline_fixed_string_t set;
13078         cmdline_fixed_string_t macsec;
13079         cmdline_fixed_string_t sa;
13080         cmdline_fixed_string_t tx_rx;
13081         portid_t port_id;
13082         uint8_t idx;
13083         uint8_t an;
13084         uint32_t pn;
13085         cmdline_fixed_string_t key;
13086 };
13087
13088 /* Common CLI fields for MACsec secure connection configure */
13089 cmdline_parse_token_string_t cmd_macsec_sa_set =
13090         TOKEN_STRING_INITIALIZER
13091                 (struct cmd_macsec_sa_result,
13092                  set, "set");
13093 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_macsec_sa_result,
13096                  macsec, "macsec");
13097 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13098         TOKEN_STRING_INITIALIZER
13099                 (struct cmd_macsec_sa_result,
13100                  sa, "sa");
13101 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13102         TOKEN_STRING_INITIALIZER
13103                 (struct cmd_macsec_sa_result,
13104                  tx_rx, "tx#rx");
13105 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13106         TOKEN_NUM_INITIALIZER
13107                 (struct cmd_macsec_sa_result,
13108                  port_id, UINT16);
13109 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13110         TOKEN_NUM_INITIALIZER
13111                 (struct cmd_macsec_sa_result,
13112                  idx, UINT8);
13113 cmdline_parse_token_num_t cmd_macsec_sa_an =
13114         TOKEN_NUM_INITIALIZER
13115                 (struct cmd_macsec_sa_result,
13116                  an, UINT8);
13117 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13118         TOKEN_NUM_INITIALIZER
13119                 (struct cmd_macsec_sa_result,
13120                  pn, UINT32);
13121 cmdline_parse_token_string_t cmd_macsec_sa_key =
13122         TOKEN_STRING_INITIALIZER
13123                 (struct cmd_macsec_sa_result,
13124                  key, NULL);
13125
13126 static void
13127 cmd_set_macsec_sa_parsed(
13128         void *parsed_result,
13129         __attribute__((unused)) struct cmdline *cl,
13130         __attribute__((unused)) void *data)
13131 {
13132         struct cmd_macsec_sa_result *res = parsed_result;
13133         int ret = -ENOTSUP;
13134         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13135         uint8_t key[16] = { 0 };
13136         uint8_t xdgt0;
13137         uint8_t xdgt1;
13138         int key_len;
13139         int i;
13140
13141         key_len = strlen(res->key) / 2;
13142         if (key_len > 16)
13143                 key_len = 16;
13144
13145         for (i = 0; i < key_len; i++) {
13146                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13147                 if (xdgt0 == 0xFF)
13148                         return;
13149                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13150                 if (xdgt1 == 0xFF)
13151                         return;
13152                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13153         }
13154
13155 #ifdef RTE_LIBRTE_IXGBE_PMD
13156         ret = is_tx ?
13157                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13158                         res->idx, res->an, res->pn, key) :
13159                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13160                         res->idx, res->an, res->pn, key);
13161 #endif
13162         RTE_SET_USED(is_tx);
13163         RTE_SET_USED(key);
13164
13165         switch (ret) {
13166         case 0:
13167                 break;
13168         case -EINVAL:
13169                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13170                 break;
13171         case -ENODEV:
13172                 printf("invalid port_id %d\n", res->port_id);
13173                 break;
13174         case -ENOTSUP:
13175                 printf("not supported on port %d\n", res->port_id);
13176                 break;
13177         default:
13178                 printf("programming error: (%s)\n", strerror(-ret));
13179         }
13180 }
13181
13182 cmdline_parse_inst_t cmd_set_macsec_sa = {
13183         .f = cmd_set_macsec_sa_parsed,
13184         .data = NULL,
13185         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13186         .tokens = {
13187                 (void *)&cmd_macsec_sa_set,
13188                 (void *)&cmd_macsec_sa_macsec,
13189                 (void *)&cmd_macsec_sa_sa,
13190                 (void *)&cmd_macsec_sa_tx_rx,
13191                 (void *)&cmd_macsec_sa_port_id,
13192                 (void *)&cmd_macsec_sa_idx,
13193                 (void *)&cmd_macsec_sa_an,
13194                 (void *)&cmd_macsec_sa_pn,
13195                 (void *)&cmd_macsec_sa_key,
13196                 NULL,
13197         },
13198 };
13199
13200 /* VF unicast promiscuous mode configuration */
13201
13202 /* Common result structure for VF unicast promiscuous mode */
13203 struct cmd_vf_promisc_result {
13204         cmdline_fixed_string_t set;
13205         cmdline_fixed_string_t vf;
13206         cmdline_fixed_string_t promisc;
13207         portid_t port_id;
13208         uint32_t vf_id;
13209         cmdline_fixed_string_t on_off;
13210 };
13211
13212 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13213 cmdline_parse_token_string_t cmd_vf_promisc_set =
13214         TOKEN_STRING_INITIALIZER
13215                 (struct cmd_vf_promisc_result,
13216                  set, "set");
13217 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13218         TOKEN_STRING_INITIALIZER
13219                 (struct cmd_vf_promisc_result,
13220                  vf, "vf");
13221 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13222         TOKEN_STRING_INITIALIZER
13223                 (struct cmd_vf_promisc_result,
13224                  promisc, "promisc");
13225 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13226         TOKEN_NUM_INITIALIZER
13227                 (struct cmd_vf_promisc_result,
13228                  port_id, UINT16);
13229 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13230         TOKEN_NUM_INITIALIZER
13231                 (struct cmd_vf_promisc_result,
13232                  vf_id, UINT32);
13233 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13234         TOKEN_STRING_INITIALIZER
13235                 (struct cmd_vf_promisc_result,
13236                  on_off, "on#off");
13237
13238 static void
13239 cmd_set_vf_promisc_parsed(
13240         void *parsed_result,
13241         __attribute__((unused)) struct cmdline *cl,
13242         __attribute__((unused)) void *data)
13243 {
13244         struct cmd_vf_promisc_result *res = parsed_result;
13245         int ret = -ENOTSUP;
13246
13247         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13248
13249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13250                 return;
13251
13252 #ifdef RTE_LIBRTE_I40E_PMD
13253         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13254                                                   res->vf_id, is_on);
13255 #endif
13256
13257         switch (ret) {
13258         case 0:
13259                 break;
13260         case -EINVAL:
13261                 printf("invalid vf_id %d\n", res->vf_id);
13262                 break;
13263         case -ENODEV:
13264                 printf("invalid port_id %d\n", res->port_id);
13265                 break;
13266         case -ENOTSUP:
13267                 printf("function not implemented\n");
13268                 break;
13269         default:
13270                 printf("programming error: (%s)\n", strerror(-ret));
13271         }
13272 }
13273
13274 cmdline_parse_inst_t cmd_set_vf_promisc = {
13275         .f = cmd_set_vf_promisc_parsed,
13276         .data = NULL,
13277         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13278                 "Set unicast promiscuous mode for a VF from the PF",
13279         .tokens = {
13280                 (void *)&cmd_vf_promisc_set,
13281                 (void *)&cmd_vf_promisc_vf,
13282                 (void *)&cmd_vf_promisc_promisc,
13283                 (void *)&cmd_vf_promisc_port_id,
13284                 (void *)&cmd_vf_promisc_vf_id,
13285                 (void *)&cmd_vf_promisc_on_off,
13286                 NULL,
13287         },
13288 };
13289
13290 /* VF multicast promiscuous mode configuration */
13291
13292 /* Common result structure for VF multicast promiscuous mode */
13293 struct cmd_vf_allmulti_result {
13294         cmdline_fixed_string_t set;
13295         cmdline_fixed_string_t vf;
13296         cmdline_fixed_string_t allmulti;
13297         portid_t port_id;
13298         uint32_t vf_id;
13299         cmdline_fixed_string_t on_off;
13300 };
13301
13302 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13303 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13304         TOKEN_STRING_INITIALIZER
13305                 (struct cmd_vf_allmulti_result,
13306                  set, "set");
13307 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13308         TOKEN_STRING_INITIALIZER
13309                 (struct cmd_vf_allmulti_result,
13310                  vf, "vf");
13311 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13312         TOKEN_STRING_INITIALIZER
13313                 (struct cmd_vf_allmulti_result,
13314                  allmulti, "allmulti");
13315 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13316         TOKEN_NUM_INITIALIZER
13317                 (struct cmd_vf_allmulti_result,
13318                  port_id, UINT16);
13319 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13320         TOKEN_NUM_INITIALIZER
13321                 (struct cmd_vf_allmulti_result,
13322                  vf_id, UINT32);
13323 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13324         TOKEN_STRING_INITIALIZER
13325                 (struct cmd_vf_allmulti_result,
13326                  on_off, "on#off");
13327
13328 static void
13329 cmd_set_vf_allmulti_parsed(
13330         void *parsed_result,
13331         __attribute__((unused)) struct cmdline *cl,
13332         __attribute__((unused)) void *data)
13333 {
13334         struct cmd_vf_allmulti_result *res = parsed_result;
13335         int ret = -ENOTSUP;
13336
13337         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13338
13339         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13340                 return;
13341
13342 #ifdef RTE_LIBRTE_I40E_PMD
13343         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13344                                                     res->vf_id, is_on);
13345 #endif
13346
13347         switch (ret) {
13348         case 0:
13349                 break;
13350         case -EINVAL:
13351                 printf("invalid vf_id %d\n", res->vf_id);
13352                 break;
13353         case -ENODEV:
13354                 printf("invalid port_id %d\n", res->port_id);
13355                 break;
13356         case -ENOTSUP:
13357                 printf("function not implemented\n");
13358                 break;
13359         default:
13360                 printf("programming error: (%s)\n", strerror(-ret));
13361         }
13362 }
13363
13364 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13365         .f = cmd_set_vf_allmulti_parsed,
13366         .data = NULL,
13367         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13368                 "Set multicast promiscuous mode for a VF from the PF",
13369         .tokens = {
13370                 (void *)&cmd_vf_allmulti_set,
13371                 (void *)&cmd_vf_allmulti_vf,
13372                 (void *)&cmd_vf_allmulti_allmulti,
13373                 (void *)&cmd_vf_allmulti_port_id,
13374                 (void *)&cmd_vf_allmulti_vf_id,
13375                 (void *)&cmd_vf_allmulti_on_off,
13376                 NULL,
13377         },
13378 };
13379
13380 /* vf broadcast mode configuration */
13381
13382 /* Common result structure for vf broadcast */
13383 struct cmd_set_vf_broadcast_result {
13384         cmdline_fixed_string_t set;
13385         cmdline_fixed_string_t vf;
13386         cmdline_fixed_string_t broadcast;
13387         portid_t port_id;
13388         uint16_t vf_id;
13389         cmdline_fixed_string_t on_off;
13390 };
13391
13392 /* Common CLI fields for vf broadcast enable disable */
13393 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_set_vf_broadcast_result,
13396                  set, "set");
13397 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13398         TOKEN_STRING_INITIALIZER
13399                 (struct cmd_set_vf_broadcast_result,
13400                  vf, "vf");
13401 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13402         TOKEN_STRING_INITIALIZER
13403                 (struct cmd_set_vf_broadcast_result,
13404                  broadcast, "broadcast");
13405 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13406         TOKEN_NUM_INITIALIZER
13407                 (struct cmd_set_vf_broadcast_result,
13408                  port_id, UINT16);
13409 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13410         TOKEN_NUM_INITIALIZER
13411                 (struct cmd_set_vf_broadcast_result,
13412                  vf_id, UINT16);
13413 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13414         TOKEN_STRING_INITIALIZER
13415                 (struct cmd_set_vf_broadcast_result,
13416                  on_off, "on#off");
13417
13418 static void
13419 cmd_set_vf_broadcast_parsed(
13420         void *parsed_result,
13421         __attribute__((unused)) struct cmdline *cl,
13422         __attribute__((unused)) void *data)
13423 {
13424         struct cmd_set_vf_broadcast_result *res = parsed_result;
13425         int ret = -ENOTSUP;
13426
13427         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13428
13429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13430                 return;
13431
13432 #ifdef RTE_LIBRTE_I40E_PMD
13433         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13434                                             res->vf_id, is_on);
13435 #endif
13436
13437         switch (ret) {
13438         case 0:
13439                 break;
13440         case -EINVAL:
13441                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13442                 break;
13443         case -ENODEV:
13444                 printf("invalid port_id %d\n", res->port_id);
13445                 break;
13446         case -ENOTSUP:
13447                 printf("function not implemented\n");
13448                 break;
13449         default:
13450                 printf("programming error: (%s)\n", strerror(-ret));
13451         }
13452 }
13453
13454 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13455         .f = cmd_set_vf_broadcast_parsed,
13456         .data = NULL,
13457         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13458         .tokens = {
13459                 (void *)&cmd_set_vf_broadcast_set,
13460                 (void *)&cmd_set_vf_broadcast_vf,
13461                 (void *)&cmd_set_vf_broadcast_broadcast,
13462                 (void *)&cmd_set_vf_broadcast_port_id,
13463                 (void *)&cmd_set_vf_broadcast_vf_id,
13464                 (void *)&cmd_set_vf_broadcast_on_off,
13465                 NULL,
13466         },
13467 };
13468
13469 /* vf vlan tag configuration */
13470
13471 /* Common result structure for vf vlan tag */
13472 struct cmd_set_vf_vlan_tag_result {
13473         cmdline_fixed_string_t set;
13474         cmdline_fixed_string_t vf;
13475         cmdline_fixed_string_t vlan;
13476         cmdline_fixed_string_t tag;
13477         portid_t port_id;
13478         uint16_t vf_id;
13479         cmdline_fixed_string_t on_off;
13480 };
13481
13482 /* Common CLI fields for vf vlan tag enable disable */
13483 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13484         TOKEN_STRING_INITIALIZER
13485                 (struct cmd_set_vf_vlan_tag_result,
13486                  set, "set");
13487 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13488         TOKEN_STRING_INITIALIZER
13489                 (struct cmd_set_vf_vlan_tag_result,
13490                  vf, "vf");
13491 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13492         TOKEN_STRING_INITIALIZER
13493                 (struct cmd_set_vf_vlan_tag_result,
13494                  vlan, "vlan");
13495 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13496         TOKEN_STRING_INITIALIZER
13497                 (struct cmd_set_vf_vlan_tag_result,
13498                  tag, "tag");
13499 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13500         TOKEN_NUM_INITIALIZER
13501                 (struct cmd_set_vf_vlan_tag_result,
13502                  port_id, UINT16);
13503 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13504         TOKEN_NUM_INITIALIZER
13505                 (struct cmd_set_vf_vlan_tag_result,
13506                  vf_id, UINT16);
13507 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13508         TOKEN_STRING_INITIALIZER
13509                 (struct cmd_set_vf_vlan_tag_result,
13510                  on_off, "on#off");
13511
13512 static void
13513 cmd_set_vf_vlan_tag_parsed(
13514         void *parsed_result,
13515         __attribute__((unused)) struct cmdline *cl,
13516         __attribute__((unused)) void *data)
13517 {
13518         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13519         int ret = -ENOTSUP;
13520
13521         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13522
13523         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13524                 return;
13525
13526 #ifdef RTE_LIBRTE_I40E_PMD
13527         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13528                                            res->vf_id, is_on);
13529 #endif
13530
13531         switch (ret) {
13532         case 0:
13533                 break;
13534         case -EINVAL:
13535                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13536                 break;
13537         case -ENODEV:
13538                 printf("invalid port_id %d\n", res->port_id);
13539                 break;
13540         case -ENOTSUP:
13541                 printf("function not implemented\n");
13542                 break;
13543         default:
13544                 printf("programming error: (%s)\n", strerror(-ret));
13545         }
13546 }
13547
13548 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13549         .f = cmd_set_vf_vlan_tag_parsed,
13550         .data = NULL,
13551         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13552         .tokens = {
13553                 (void *)&cmd_set_vf_vlan_tag_set,
13554                 (void *)&cmd_set_vf_vlan_tag_vf,
13555                 (void *)&cmd_set_vf_vlan_tag_vlan,
13556                 (void *)&cmd_set_vf_vlan_tag_tag,
13557                 (void *)&cmd_set_vf_vlan_tag_port_id,
13558                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13559                 (void *)&cmd_set_vf_vlan_tag_on_off,
13560                 NULL,
13561         },
13562 };
13563
13564 /* Common definition of VF and TC TX bandwidth configuration */
13565 struct cmd_vf_tc_bw_result {
13566         cmdline_fixed_string_t set;
13567         cmdline_fixed_string_t vf;
13568         cmdline_fixed_string_t tc;
13569         cmdline_fixed_string_t tx;
13570         cmdline_fixed_string_t min_bw;
13571         cmdline_fixed_string_t max_bw;
13572         cmdline_fixed_string_t strict_link_prio;
13573         portid_t port_id;
13574         uint16_t vf_id;
13575         uint8_t tc_no;
13576         uint32_t bw;
13577         cmdline_fixed_string_t bw_list;
13578         uint8_t tc_map;
13579 };
13580
13581 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13582         TOKEN_STRING_INITIALIZER
13583                 (struct cmd_vf_tc_bw_result,
13584                  set, "set");
13585 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13586         TOKEN_STRING_INITIALIZER
13587                 (struct cmd_vf_tc_bw_result,
13588                  vf, "vf");
13589 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13590         TOKEN_STRING_INITIALIZER
13591                 (struct cmd_vf_tc_bw_result,
13592                  tc, "tc");
13593 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_vf_tc_bw_result,
13596                  tx, "tx");
13597 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_tc_bw_result,
13600                  strict_link_prio, "strict-link-priority");
13601 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13602         TOKEN_STRING_INITIALIZER
13603                 (struct cmd_vf_tc_bw_result,
13604                  min_bw, "min-bandwidth");
13605 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13606         TOKEN_STRING_INITIALIZER
13607                 (struct cmd_vf_tc_bw_result,
13608                  max_bw, "max-bandwidth");
13609 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_tc_bw_result,
13612                  port_id, UINT16);
13613 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13614         TOKEN_NUM_INITIALIZER
13615                 (struct cmd_vf_tc_bw_result,
13616                  vf_id, UINT16);
13617 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13618         TOKEN_NUM_INITIALIZER
13619                 (struct cmd_vf_tc_bw_result,
13620                  tc_no, UINT8);
13621 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13622         TOKEN_NUM_INITIALIZER
13623                 (struct cmd_vf_tc_bw_result,
13624                  bw, UINT32);
13625 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13626         TOKEN_STRING_INITIALIZER
13627                 (struct cmd_vf_tc_bw_result,
13628                  bw_list, NULL);
13629 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13630         TOKEN_NUM_INITIALIZER
13631                 (struct cmd_vf_tc_bw_result,
13632                  tc_map, UINT8);
13633
13634 /* VF max bandwidth setting */
13635 static void
13636 cmd_vf_max_bw_parsed(
13637         void *parsed_result,
13638         __attribute__((unused)) struct cmdline *cl,
13639         __attribute__((unused)) void *data)
13640 {
13641         struct cmd_vf_tc_bw_result *res = parsed_result;
13642         int ret = -ENOTSUP;
13643
13644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13645                 return;
13646
13647 #ifdef RTE_LIBRTE_I40E_PMD
13648         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13649                                          res->vf_id, res->bw);
13650 #endif
13651
13652         switch (ret) {
13653         case 0:
13654                 break;
13655         case -EINVAL:
13656                 printf("invalid vf_id %d or bandwidth %d\n",
13657                        res->vf_id, res->bw);
13658                 break;
13659         case -ENODEV:
13660                 printf("invalid port_id %d\n", res->port_id);
13661                 break;
13662         case -ENOTSUP:
13663                 printf("function not implemented\n");
13664                 break;
13665         default:
13666                 printf("programming error: (%s)\n", strerror(-ret));
13667         }
13668 }
13669
13670 cmdline_parse_inst_t cmd_vf_max_bw = {
13671         .f = cmd_vf_max_bw_parsed,
13672         .data = NULL,
13673         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13674         .tokens = {
13675                 (void *)&cmd_vf_tc_bw_set,
13676                 (void *)&cmd_vf_tc_bw_vf,
13677                 (void *)&cmd_vf_tc_bw_tx,
13678                 (void *)&cmd_vf_tc_bw_max_bw,
13679                 (void *)&cmd_vf_tc_bw_port_id,
13680                 (void *)&cmd_vf_tc_bw_vf_id,
13681                 (void *)&cmd_vf_tc_bw_bw,
13682                 NULL,
13683         },
13684 };
13685
13686 static int
13687 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13688                            uint8_t *tc_num,
13689                            char *str)
13690 {
13691         uint32_t size;
13692         const char *p, *p0 = str;
13693         char s[256];
13694         char *end;
13695         char *str_fld[16];
13696         uint16_t i;
13697         int ret;
13698
13699         p = strchr(p0, '(');
13700         if (p == NULL) {
13701                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13702                 return -1;
13703         }
13704         p++;
13705         p0 = strchr(p, ')');
13706         if (p0 == NULL) {
13707                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13708                 return -1;
13709         }
13710         size = p0 - p;
13711         if (size >= sizeof(s)) {
13712                 printf("The string size exceeds the internal buffer size\n");
13713                 return -1;
13714         }
13715         snprintf(s, sizeof(s), "%.*s", size, p);
13716         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13717         if (ret <= 0) {
13718                 printf("Failed to get the bandwidth list. ");
13719                 return -1;
13720         }
13721         *tc_num = ret;
13722         for (i = 0; i < ret; i++)
13723                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13724
13725         return 0;
13726 }
13727
13728 /* TC min bandwidth setting */
13729 static void
13730 cmd_vf_tc_min_bw_parsed(
13731         void *parsed_result,
13732         __attribute__((unused)) struct cmdline *cl,
13733         __attribute__((unused)) void *data)
13734 {
13735         struct cmd_vf_tc_bw_result *res = parsed_result;
13736         uint8_t tc_num;
13737         uint8_t bw[16];
13738         int ret = -ENOTSUP;
13739
13740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13741                 return;
13742
13743         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13744         if (ret)
13745                 return;
13746
13747 #ifdef RTE_LIBRTE_I40E_PMD
13748         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13749                                               tc_num, bw);
13750 #endif
13751
13752         switch (ret) {
13753         case 0:
13754                 break;
13755         case -EINVAL:
13756                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13757                 break;
13758         case -ENODEV:
13759                 printf("invalid port_id %d\n", res->port_id);
13760                 break;
13761         case -ENOTSUP:
13762                 printf("function not implemented\n");
13763                 break;
13764         default:
13765                 printf("programming error: (%s)\n", strerror(-ret));
13766         }
13767 }
13768
13769 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13770         .f = cmd_vf_tc_min_bw_parsed,
13771         .data = NULL,
13772         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13773                     " <bw1, bw2, ...>",
13774         .tokens = {
13775                 (void *)&cmd_vf_tc_bw_set,
13776                 (void *)&cmd_vf_tc_bw_vf,
13777                 (void *)&cmd_vf_tc_bw_tc,
13778                 (void *)&cmd_vf_tc_bw_tx,
13779                 (void *)&cmd_vf_tc_bw_min_bw,
13780                 (void *)&cmd_vf_tc_bw_port_id,
13781                 (void *)&cmd_vf_tc_bw_vf_id,
13782                 (void *)&cmd_vf_tc_bw_bw_list,
13783                 NULL,
13784         },
13785 };
13786
13787 static void
13788 cmd_tc_min_bw_parsed(
13789         void *parsed_result,
13790         __attribute__((unused)) struct cmdline *cl,
13791         __attribute__((unused)) void *data)
13792 {
13793         struct cmd_vf_tc_bw_result *res = parsed_result;
13794         struct rte_port *port;
13795         uint8_t tc_num;
13796         uint8_t bw[16];
13797         int ret = -ENOTSUP;
13798
13799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13800                 return;
13801
13802         port = &ports[res->port_id];
13803         /** Check if the port is not started **/
13804         if (port->port_status != RTE_PORT_STOPPED) {
13805                 printf("Please stop port %d first\n", res->port_id);
13806                 return;
13807         }
13808
13809         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13810         if (ret)
13811                 return;
13812
13813 #ifdef RTE_LIBRTE_IXGBE_PMD
13814         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13815 #endif
13816
13817         switch (ret) {
13818         case 0:
13819                 break;
13820         case -EINVAL:
13821                 printf("invalid bandwidth\n");
13822                 break;
13823         case -ENODEV:
13824                 printf("invalid port_id %d\n", res->port_id);
13825                 break;
13826         case -ENOTSUP:
13827                 printf("function not implemented\n");
13828                 break;
13829         default:
13830                 printf("programming error: (%s)\n", strerror(-ret));
13831         }
13832 }
13833
13834 cmdline_parse_inst_t cmd_tc_min_bw = {
13835         .f = cmd_tc_min_bw_parsed,
13836         .data = NULL,
13837         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13838         .tokens = {
13839                 (void *)&cmd_vf_tc_bw_set,
13840                 (void *)&cmd_vf_tc_bw_tc,
13841                 (void *)&cmd_vf_tc_bw_tx,
13842                 (void *)&cmd_vf_tc_bw_min_bw,
13843                 (void *)&cmd_vf_tc_bw_port_id,
13844                 (void *)&cmd_vf_tc_bw_bw_list,
13845                 NULL,
13846         },
13847 };
13848
13849 /* TC max bandwidth setting */
13850 static void
13851 cmd_vf_tc_max_bw_parsed(
13852         void *parsed_result,
13853         __attribute__((unused)) struct cmdline *cl,
13854         __attribute__((unused)) void *data)
13855 {
13856         struct cmd_vf_tc_bw_result *res = parsed_result;
13857         int ret = -ENOTSUP;
13858
13859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13860                 return;
13861
13862 #ifdef RTE_LIBRTE_I40E_PMD
13863         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13864                                             res->tc_no, res->bw);
13865 #endif
13866
13867         switch (ret) {
13868         case 0:
13869                 break;
13870         case -EINVAL:
13871                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13872                        res->vf_id, res->tc_no, res->bw);
13873                 break;
13874         case -ENODEV:
13875                 printf("invalid port_id %d\n", res->port_id);
13876                 break;
13877         case -ENOTSUP:
13878                 printf("function not implemented\n");
13879                 break;
13880         default:
13881                 printf("programming error: (%s)\n", strerror(-ret));
13882         }
13883 }
13884
13885 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13886         .f = cmd_vf_tc_max_bw_parsed,
13887         .data = NULL,
13888         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13889                     " <bandwidth>",
13890         .tokens = {
13891                 (void *)&cmd_vf_tc_bw_set,
13892                 (void *)&cmd_vf_tc_bw_vf,
13893                 (void *)&cmd_vf_tc_bw_tc,
13894                 (void *)&cmd_vf_tc_bw_tx,
13895                 (void *)&cmd_vf_tc_bw_max_bw,
13896                 (void *)&cmd_vf_tc_bw_port_id,
13897                 (void *)&cmd_vf_tc_bw_vf_id,
13898                 (void *)&cmd_vf_tc_bw_tc_no,
13899                 (void *)&cmd_vf_tc_bw_bw,
13900                 NULL,
13901         },
13902 };
13903
13904
13905 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13906
13907 /* *** Set Port default Traffic Management Hierarchy *** */
13908 struct cmd_set_port_tm_hierarchy_default_result {
13909         cmdline_fixed_string_t set;
13910         cmdline_fixed_string_t port;
13911         cmdline_fixed_string_t tm;
13912         cmdline_fixed_string_t hierarchy;
13913         cmdline_fixed_string_t def;
13914         portid_t port_id;
13915 };
13916
13917 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13918         TOKEN_STRING_INITIALIZER(
13919                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13920 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13921         TOKEN_STRING_INITIALIZER(
13922                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13923 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13924         TOKEN_STRING_INITIALIZER(
13925                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13926 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
13927         TOKEN_STRING_INITIALIZER(
13928                 struct cmd_set_port_tm_hierarchy_default_result,
13929                         hierarchy, "hierarchy");
13930 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
13931         TOKEN_STRING_INITIALIZER(
13932                 struct cmd_set_port_tm_hierarchy_default_result,
13933                         def, "default");
13934 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
13935         TOKEN_NUM_INITIALIZER(
13936                 struct cmd_set_port_tm_hierarchy_default_result,
13937                         port_id, UINT16);
13938
13939 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
13940         __attribute__((unused)) struct cmdline *cl,
13941         __attribute__((unused)) void *data)
13942 {
13943         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
13944         struct rte_port *p;
13945         portid_t port_id = res->port_id;
13946
13947         if (port_id_is_invalid(port_id, ENABLED_WARN))
13948                 return;
13949
13950         p = &ports[port_id];
13951
13952         /* Port tm flag */
13953         if (p->softport.tm_flag == 0) {
13954                 printf("  tm not enabled on port %u (error)\n", port_id);
13955                 return;
13956         }
13957
13958         /* Forward mode: tm */
13959         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
13960                 printf("  tm mode not enabled(error)\n");
13961                 return;
13962         }
13963
13964         /* Set the default tm hierarchy */
13965         p->softport.tm.default_hierarchy_enable = 1;
13966 }
13967
13968 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
13969         .f = cmd_set_port_tm_hierarchy_default_parsed,
13970         .data = NULL,
13971         .help_str = "set port tm hierarchy default <port_id>",
13972         .tokens = {
13973                 (void *)&cmd_set_port_tm_hierarchy_default_set,
13974                 (void *)&cmd_set_port_tm_hierarchy_default_port,
13975                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
13976                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
13977                 (void *)&cmd_set_port_tm_hierarchy_default_default,
13978                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
13979                 NULL,
13980         },
13981 };
13982 #endif
13983
13984 /* Strict link priority scheduling mode setting */
13985 static void
13986 cmd_strict_link_prio_parsed(
13987         void *parsed_result,
13988         __attribute__((unused)) struct cmdline *cl,
13989         __attribute__((unused)) void *data)
13990 {
13991         struct cmd_vf_tc_bw_result *res = parsed_result;
13992         int ret = -ENOTSUP;
13993
13994         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13995                 return;
13996
13997 #ifdef RTE_LIBRTE_I40E_PMD
13998         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13999 #endif
14000
14001         switch (ret) {
14002         case 0:
14003                 break;
14004         case -EINVAL:
14005                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14006                 break;
14007         case -ENODEV:
14008                 printf("invalid port_id %d\n", res->port_id);
14009                 break;
14010         case -ENOTSUP:
14011                 printf("function not implemented\n");
14012                 break;
14013         default:
14014                 printf("programming error: (%s)\n", strerror(-ret));
14015         }
14016 }
14017
14018 cmdline_parse_inst_t cmd_strict_link_prio = {
14019         .f = cmd_strict_link_prio_parsed,
14020         .data = NULL,
14021         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14022         .tokens = {
14023                 (void *)&cmd_vf_tc_bw_set,
14024                 (void *)&cmd_vf_tc_bw_tx,
14025                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14026                 (void *)&cmd_vf_tc_bw_port_id,
14027                 (void *)&cmd_vf_tc_bw_tc_map,
14028                 NULL,
14029         },
14030 };
14031
14032 /* Load dynamic device personalization*/
14033 struct cmd_ddp_add_result {
14034         cmdline_fixed_string_t ddp;
14035         cmdline_fixed_string_t add;
14036         portid_t port_id;
14037         char filepath[];
14038 };
14039
14040 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14041         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14042 cmdline_parse_token_string_t cmd_ddp_add_add =
14043         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14044 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14045         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14046 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14047         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14048
14049 static void
14050 cmd_ddp_add_parsed(
14051         void *parsed_result,
14052         __attribute__((unused)) struct cmdline *cl,
14053         __attribute__((unused)) void *data)
14054 {
14055         struct cmd_ddp_add_result *res = parsed_result;
14056         uint8_t *buff;
14057         uint32_t size;
14058         char *filepath;
14059         char *file_fld[2];
14060         int file_num;
14061         int ret = -ENOTSUP;
14062
14063         if (res->port_id > nb_ports) {
14064                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14065                 return;
14066         }
14067
14068         if (!all_ports_stopped()) {
14069                 printf("Please stop all ports first\n");
14070                 return;
14071         }
14072
14073         filepath = strdup(res->filepath);
14074         if (filepath == NULL) {
14075                 printf("Failed to allocate memory\n");
14076                 return;
14077         }
14078         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14079
14080         buff = open_ddp_package_file(file_fld[0], &size);
14081         if (!buff) {
14082                 free((void *)filepath);
14083                 return;
14084         }
14085
14086 #ifdef RTE_LIBRTE_I40E_PMD
14087         if (ret == -ENOTSUP)
14088                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14089                                                buff, size,
14090                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14091 #endif
14092
14093         if (ret == -EEXIST)
14094                 printf("Profile has already existed.\n");
14095         else if (ret < 0)
14096                 printf("Failed to load profile.\n");
14097         else if (file_num == 2)
14098                 save_ddp_package_file(file_fld[1], buff, size);
14099
14100         close_ddp_package_file(buff);
14101         free((void *)filepath);
14102 }
14103
14104 cmdline_parse_inst_t cmd_ddp_add = {
14105         .f = cmd_ddp_add_parsed,
14106         .data = NULL,
14107         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14108         .tokens = {
14109                 (void *)&cmd_ddp_add_ddp,
14110                 (void *)&cmd_ddp_add_add,
14111                 (void *)&cmd_ddp_add_port_id,
14112                 (void *)&cmd_ddp_add_filepath,
14113                 NULL,
14114         },
14115 };
14116
14117 /* Delete dynamic device personalization*/
14118 struct cmd_ddp_del_result {
14119         cmdline_fixed_string_t ddp;
14120         cmdline_fixed_string_t del;
14121         portid_t port_id;
14122         char filepath[];
14123 };
14124
14125 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14126         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14127 cmdline_parse_token_string_t cmd_ddp_del_del =
14128         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14129 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14130         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14131 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14132         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14133
14134 static void
14135 cmd_ddp_del_parsed(
14136         void *parsed_result,
14137         __attribute__((unused)) struct cmdline *cl,
14138         __attribute__((unused)) void *data)
14139 {
14140         struct cmd_ddp_del_result *res = parsed_result;
14141         uint8_t *buff;
14142         uint32_t size;
14143         int ret = -ENOTSUP;
14144
14145         if (res->port_id > nb_ports) {
14146                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14147                 return;
14148         }
14149
14150         if (!all_ports_stopped()) {
14151                 printf("Please stop all ports first\n");
14152                 return;
14153         }
14154
14155         buff = open_ddp_package_file(res->filepath, &size);
14156         if (!buff)
14157                 return;
14158
14159 #ifdef RTE_LIBRTE_I40E_PMD
14160         if (ret == -ENOTSUP)
14161                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14162                                                buff, size,
14163                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14164 #endif
14165
14166         if (ret == -EACCES)
14167                 printf("Profile does not exist.\n");
14168         else if (ret < 0)
14169                 printf("Failed to delete profile.\n");
14170
14171         close_ddp_package_file(buff);
14172 }
14173
14174 cmdline_parse_inst_t cmd_ddp_del = {
14175         .f = cmd_ddp_del_parsed,
14176         .data = NULL,
14177         .help_str = "ddp del <port_id> <profile_path>",
14178         .tokens = {
14179                 (void *)&cmd_ddp_del_ddp,
14180                 (void *)&cmd_ddp_del_del,
14181                 (void *)&cmd_ddp_del_port_id,
14182                 (void *)&cmd_ddp_del_filepath,
14183                 NULL,
14184         },
14185 };
14186
14187 /* Get dynamic device personalization profile info */
14188 struct cmd_ddp_info_result {
14189         cmdline_fixed_string_t ddp;
14190         cmdline_fixed_string_t get;
14191         cmdline_fixed_string_t info;
14192         char filepath[];
14193 };
14194
14195 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14196         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14197 cmdline_parse_token_string_t cmd_ddp_info_get =
14198         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14199 cmdline_parse_token_string_t cmd_ddp_info_info =
14200         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14201 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14202         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14203
14204 static void
14205 cmd_ddp_info_parsed(
14206         void *parsed_result,
14207         __attribute__((unused)) struct cmdline *cl,
14208         __attribute__((unused)) void *data)
14209 {
14210         struct cmd_ddp_info_result *res = parsed_result;
14211         uint8_t *pkg;
14212         uint32_t pkg_size;
14213         int ret = -ENOTSUP;
14214 #ifdef RTE_LIBRTE_I40E_PMD
14215         uint32_t i, j, n;
14216         uint8_t *buff;
14217         uint32_t buff_size = 0;
14218         struct rte_pmd_i40e_profile_info info;
14219         uint32_t dev_num = 0;
14220         struct rte_pmd_i40e_ddp_device_id *devs;
14221         uint32_t proto_num = 0;
14222         struct rte_pmd_i40e_proto_info *proto;
14223         uint32_t pctype_num = 0;
14224         struct rte_pmd_i40e_ptype_info *pctype;
14225         uint32_t ptype_num = 0;
14226         struct rte_pmd_i40e_ptype_info *ptype;
14227         uint8_t proto_id;
14228
14229 #endif
14230
14231         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14232         if (!pkg)
14233                 return;
14234
14235 #ifdef RTE_LIBRTE_I40E_PMD
14236         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14237                                 (uint8_t *)&info, sizeof(info),
14238                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14239         if (!ret) {
14240                 printf("Global Track id:       0x%x\n", info.track_id);
14241                 printf("Global Version:        %d.%d.%d.%d\n",
14242                         info.version.major,
14243                         info.version.minor,
14244                         info.version.update,
14245                         info.version.draft);
14246                 printf("Global Package name:   %s\n\n", info.name);
14247         }
14248
14249         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14250                                 (uint8_t *)&info, sizeof(info),
14251                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14252         if (!ret) {
14253                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14254                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14255                         info.version.major,
14256                         info.version.minor,
14257                         info.version.update,
14258                         info.version.draft);
14259                 printf("i40e Profile name:     %s\n\n", info.name);
14260         }
14261
14262         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14263                                 (uint8_t *)&buff_size, sizeof(buff_size),
14264                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14265         if (!ret && buff_size) {
14266                 buff = (uint8_t *)malloc(buff_size);
14267                 if (buff) {
14268                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14269                                                 buff, buff_size,
14270                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14271                         if (!ret)
14272                                 printf("Package Notes:\n%s\n\n", buff);
14273                         free(buff);
14274                 }
14275         }
14276
14277         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14278                                 (uint8_t *)&dev_num, sizeof(dev_num),
14279                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14280         if (!ret && dev_num) {
14281                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14282                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14283                 if (devs) {
14284                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14285                                                 (uint8_t *)devs, buff_size,
14286                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14287                         if (!ret) {
14288                                 printf("List of supported devices:\n");
14289                                 for (i = 0; i < dev_num; i++) {
14290                                         printf("  %04X:%04X %04X:%04X\n",
14291                                                 devs[i].vendor_dev_id >> 16,
14292                                                 devs[i].vendor_dev_id & 0xFFFF,
14293                                                 devs[i].sub_vendor_dev_id >> 16,
14294                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14295                                 }
14296                                 printf("\n");
14297                         }
14298                         free(devs);
14299                 }
14300         }
14301
14302         /* get information about protocols and packet types */
14303         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14304                 (uint8_t *)&proto_num, sizeof(proto_num),
14305                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14306         if (ret || !proto_num)
14307                 goto no_print_return;
14308
14309         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14310         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14311         if (!proto)
14312                 goto no_print_return;
14313
14314         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14315                                         buff_size,
14316                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14317         if (!ret) {
14318                 printf("List of used protocols:\n");
14319                 for (i = 0; i < proto_num; i++)
14320                         printf("  %2u: %s\n", proto[i].proto_id,
14321                                proto[i].name);
14322                 printf("\n");
14323         }
14324         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14325                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14326                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14327         if (ret || !pctype_num)
14328                 goto no_print_pctypes;
14329
14330         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14331         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14332         if (!pctype)
14333                 goto no_print_pctypes;
14334
14335         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14336                                         buff_size,
14337                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14338         if (ret) {
14339                 free(pctype);
14340                 goto no_print_pctypes;
14341         }
14342
14343         printf("List of defined packet classification types:\n");
14344         for (i = 0; i < pctype_num; i++) {
14345                 printf("  %2u:", pctype[i].ptype_id);
14346                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14347                         proto_id = pctype[i].protocols[j];
14348                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14349                                 for (n = 0; n < proto_num; n++) {
14350                                         if (proto[n].proto_id == proto_id) {
14351                                                 printf(" %s", proto[n].name);
14352                                                 break;
14353                                         }
14354                                 }
14355                         }
14356                 }
14357                 printf("\n");
14358         }
14359         printf("\n");
14360         free(pctype);
14361
14362 no_print_pctypes:
14363
14364         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14365                                         sizeof(ptype_num),
14366                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14367         if (ret || !ptype_num)
14368                 goto no_print_return;
14369
14370         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14371         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14372         if (!ptype)
14373                 goto no_print_return;
14374
14375         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14376                                         buff_size,
14377                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14378         if (ret) {
14379                 free(ptype);
14380                 goto no_print_return;
14381         }
14382         printf("List of defined packet types:\n");
14383         for (i = 0; i < ptype_num; i++) {
14384                 printf("  %2u:", ptype[i].ptype_id);
14385                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14386                         proto_id = ptype[i].protocols[j];
14387                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14388                                 for (n = 0; n < proto_num; n++) {
14389                                         if (proto[n].proto_id == proto_id) {
14390                                                 printf(" %s", proto[n].name);
14391                                                 break;
14392                                         }
14393                                 }
14394                         }
14395                 }
14396                 printf("\n");
14397         }
14398         free(ptype);
14399         printf("\n");
14400
14401         free(proto);
14402         ret = 0;
14403 no_print_return:
14404 #endif
14405         if (ret == -ENOTSUP)
14406                 printf("Function not supported in PMD driver\n");
14407         close_ddp_package_file(pkg);
14408 }
14409
14410 cmdline_parse_inst_t cmd_ddp_get_info = {
14411         .f = cmd_ddp_info_parsed,
14412         .data = NULL,
14413         .help_str = "ddp get info <profile_path>",
14414         .tokens = {
14415                 (void *)&cmd_ddp_info_ddp,
14416                 (void *)&cmd_ddp_info_get,
14417                 (void *)&cmd_ddp_info_info,
14418                 (void *)&cmd_ddp_info_filepath,
14419                 NULL,
14420         },
14421 };
14422
14423 /* Get dynamic device personalization profile info list*/
14424 #define PROFILE_INFO_SIZE 48
14425 #define MAX_PROFILE_NUM 16
14426
14427 struct cmd_ddp_get_list_result {
14428         cmdline_fixed_string_t ddp;
14429         cmdline_fixed_string_t get;
14430         cmdline_fixed_string_t list;
14431         portid_t port_id;
14432 };
14433
14434 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14435         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14436 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14437         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14438 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14439         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14440 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14441         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14442
14443 static void
14444 cmd_ddp_get_list_parsed(
14445         void *parsed_result,
14446         __attribute__((unused)) struct cmdline *cl,
14447         __attribute__((unused)) void *data)
14448 {
14449         struct cmd_ddp_get_list_result *res = parsed_result;
14450 #ifdef RTE_LIBRTE_I40E_PMD
14451         struct rte_pmd_i40e_profile_list *p_list;
14452         struct rte_pmd_i40e_profile_info *p_info;
14453         uint32_t p_num;
14454         uint32_t size;
14455         uint32_t i;
14456 #endif
14457         int ret = -ENOTSUP;
14458
14459         if (res->port_id > nb_ports) {
14460                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14461                 return;
14462         }
14463
14464 #ifdef RTE_LIBRTE_I40E_PMD
14465         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14466         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14467         if (!p_list)
14468                 printf("%s: Failed to malloc buffer\n", __func__);
14469
14470         if (ret == -ENOTSUP)
14471                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14472                                                 (uint8_t *)p_list, size);
14473
14474         if (!ret) {
14475                 p_num = p_list->p_count;
14476                 printf("Profile number is: %d\n\n", p_num);
14477
14478                 for (i = 0; i < p_num; i++) {
14479                         p_info = &p_list->p_info[i];
14480                         printf("Profile %d:\n", i);
14481                         printf("Track id:     0x%x\n", p_info->track_id);
14482                         printf("Version:      %d.%d.%d.%d\n",
14483                                p_info->version.major,
14484                                p_info->version.minor,
14485                                p_info->version.update,
14486                                p_info->version.draft);
14487                         printf("Profile name: %s\n\n", p_info->name);
14488                 }
14489         }
14490
14491         free(p_list);
14492 #endif
14493
14494         if (ret < 0)
14495                 printf("Failed to get ddp list\n");
14496 }
14497
14498 cmdline_parse_inst_t cmd_ddp_get_list = {
14499         .f = cmd_ddp_get_list_parsed,
14500         .data = NULL,
14501         .help_str = "ddp get list <port_id>",
14502         .tokens = {
14503                 (void *)&cmd_ddp_get_list_ddp,
14504                 (void *)&cmd_ddp_get_list_get,
14505                 (void *)&cmd_ddp_get_list_list,
14506                 (void *)&cmd_ddp_get_list_port_id,
14507                 NULL,
14508         },
14509 };
14510
14511 /* show vf stats */
14512
14513 /* Common result structure for show vf stats */
14514 struct cmd_show_vf_stats_result {
14515         cmdline_fixed_string_t show;
14516         cmdline_fixed_string_t vf;
14517         cmdline_fixed_string_t stats;
14518         portid_t port_id;
14519         uint16_t vf_id;
14520 };
14521
14522 /* Common CLI fields show vf stats*/
14523 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14524         TOKEN_STRING_INITIALIZER
14525                 (struct cmd_show_vf_stats_result,
14526                  show, "show");
14527 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14528         TOKEN_STRING_INITIALIZER
14529                 (struct cmd_show_vf_stats_result,
14530                  vf, "vf");
14531 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14532         TOKEN_STRING_INITIALIZER
14533                 (struct cmd_show_vf_stats_result,
14534                  stats, "stats");
14535 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14536         TOKEN_NUM_INITIALIZER
14537                 (struct cmd_show_vf_stats_result,
14538                  port_id, UINT16);
14539 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14540         TOKEN_NUM_INITIALIZER
14541                 (struct cmd_show_vf_stats_result,
14542                  vf_id, UINT16);
14543
14544 static void
14545 cmd_show_vf_stats_parsed(
14546         void *parsed_result,
14547         __attribute__((unused)) struct cmdline *cl,
14548         __attribute__((unused)) void *data)
14549 {
14550         struct cmd_show_vf_stats_result *res = parsed_result;
14551         struct rte_eth_stats stats;
14552         int ret = -ENOTSUP;
14553         static const char *nic_stats_border = "########################";
14554
14555         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14556                 return;
14557
14558         memset(&stats, 0, sizeof(stats));
14559
14560 #ifdef RTE_LIBRTE_I40E_PMD
14561         if (ret == -ENOTSUP)
14562                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14563                                                 res->vf_id,
14564                                                 &stats);
14565 #endif
14566 #ifdef RTE_LIBRTE_BNXT_PMD
14567         if (ret == -ENOTSUP)
14568                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14569                                                 res->vf_id,
14570                                                 &stats);
14571 #endif
14572
14573         switch (ret) {
14574         case 0:
14575                 break;
14576         case -EINVAL:
14577                 printf("invalid vf_id %d\n", res->vf_id);
14578                 break;
14579         case -ENODEV:
14580                 printf("invalid port_id %d\n", res->port_id);
14581                 break;
14582         case -ENOTSUP:
14583                 printf("function not implemented\n");
14584                 break;
14585         default:
14586                 printf("programming error: (%s)\n", strerror(-ret));
14587         }
14588
14589         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14590                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14591
14592         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14593                "%-"PRIu64"\n",
14594                stats.ipackets, stats.imissed, stats.ibytes);
14595         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14596         printf("  RX-nombuf:  %-10"PRIu64"\n",
14597                stats.rx_nombuf);
14598         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14599                "%-"PRIu64"\n",
14600                stats.opackets, stats.oerrors, stats.obytes);
14601
14602         printf("  %s############################%s\n",
14603                                nic_stats_border, nic_stats_border);
14604 }
14605
14606 cmdline_parse_inst_t cmd_show_vf_stats = {
14607         .f = cmd_show_vf_stats_parsed,
14608         .data = NULL,
14609         .help_str = "show vf stats <port_id> <vf_id>",
14610         .tokens = {
14611                 (void *)&cmd_show_vf_stats_show,
14612                 (void *)&cmd_show_vf_stats_vf,
14613                 (void *)&cmd_show_vf_stats_stats,
14614                 (void *)&cmd_show_vf_stats_port_id,
14615                 (void *)&cmd_show_vf_stats_vf_id,
14616                 NULL,
14617         },
14618 };
14619
14620 /* clear vf stats */
14621
14622 /* Common result structure for clear vf stats */
14623 struct cmd_clear_vf_stats_result {
14624         cmdline_fixed_string_t clear;
14625         cmdline_fixed_string_t vf;
14626         cmdline_fixed_string_t stats;
14627         portid_t port_id;
14628         uint16_t vf_id;
14629 };
14630
14631 /* Common CLI fields clear vf stats*/
14632 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14633         TOKEN_STRING_INITIALIZER
14634                 (struct cmd_clear_vf_stats_result,
14635                  clear, "clear");
14636 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14637         TOKEN_STRING_INITIALIZER
14638                 (struct cmd_clear_vf_stats_result,
14639                  vf, "vf");
14640 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14641         TOKEN_STRING_INITIALIZER
14642                 (struct cmd_clear_vf_stats_result,
14643                  stats, "stats");
14644 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14645         TOKEN_NUM_INITIALIZER
14646                 (struct cmd_clear_vf_stats_result,
14647                  port_id, UINT16);
14648 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14649         TOKEN_NUM_INITIALIZER
14650                 (struct cmd_clear_vf_stats_result,
14651                  vf_id, UINT16);
14652
14653 static void
14654 cmd_clear_vf_stats_parsed(
14655         void *parsed_result,
14656         __attribute__((unused)) struct cmdline *cl,
14657         __attribute__((unused)) void *data)
14658 {
14659         struct cmd_clear_vf_stats_result *res = parsed_result;
14660         int ret = -ENOTSUP;
14661
14662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14663                 return;
14664
14665 #ifdef RTE_LIBRTE_I40E_PMD
14666         if (ret == -ENOTSUP)
14667                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14668                                                   res->vf_id);
14669 #endif
14670 #ifdef RTE_LIBRTE_BNXT_PMD
14671         if (ret == -ENOTSUP)
14672                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14673                                                   res->vf_id);
14674 #endif
14675
14676         switch (ret) {
14677         case 0:
14678                 break;
14679         case -EINVAL:
14680                 printf("invalid vf_id %d\n", res->vf_id);
14681                 break;
14682         case -ENODEV:
14683                 printf("invalid port_id %d\n", res->port_id);
14684                 break;
14685         case -ENOTSUP:
14686                 printf("function not implemented\n");
14687                 break;
14688         default:
14689                 printf("programming error: (%s)\n", strerror(-ret));
14690         }
14691 }
14692
14693 cmdline_parse_inst_t cmd_clear_vf_stats = {
14694         .f = cmd_clear_vf_stats_parsed,
14695         .data = NULL,
14696         .help_str = "clear vf stats <port_id> <vf_id>",
14697         .tokens = {
14698                 (void *)&cmd_clear_vf_stats_clear,
14699                 (void *)&cmd_clear_vf_stats_vf,
14700                 (void *)&cmd_clear_vf_stats_stats,
14701                 (void *)&cmd_clear_vf_stats_port_id,
14702                 (void *)&cmd_clear_vf_stats_vf_id,
14703                 NULL,
14704         },
14705 };
14706
14707 /* port config pctype mapping reset */
14708
14709 /* Common result structure for port config pctype mapping reset */
14710 struct cmd_pctype_mapping_reset_result {
14711         cmdline_fixed_string_t port;
14712         cmdline_fixed_string_t config;
14713         portid_t port_id;
14714         cmdline_fixed_string_t pctype;
14715         cmdline_fixed_string_t mapping;
14716         cmdline_fixed_string_t reset;
14717 };
14718
14719 /* Common CLI fields for port config pctype mapping reset*/
14720 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14721         TOKEN_STRING_INITIALIZER
14722                 (struct cmd_pctype_mapping_reset_result,
14723                  port, "port");
14724 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14725         TOKEN_STRING_INITIALIZER
14726                 (struct cmd_pctype_mapping_reset_result,
14727                  config, "config");
14728 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14729         TOKEN_NUM_INITIALIZER
14730                 (struct cmd_pctype_mapping_reset_result,
14731                  port_id, UINT16);
14732 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14733         TOKEN_STRING_INITIALIZER
14734                 (struct cmd_pctype_mapping_reset_result,
14735                  pctype, "pctype");
14736 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14737         TOKEN_STRING_INITIALIZER
14738                 (struct cmd_pctype_mapping_reset_result,
14739                  mapping, "mapping");
14740 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14741         TOKEN_STRING_INITIALIZER
14742                 (struct cmd_pctype_mapping_reset_result,
14743                  reset, "reset");
14744
14745 static void
14746 cmd_pctype_mapping_reset_parsed(
14747         void *parsed_result,
14748         __attribute__((unused)) struct cmdline *cl,
14749         __attribute__((unused)) void *data)
14750 {
14751         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14752         int ret = -ENOTSUP;
14753
14754         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14755                 return;
14756
14757 #ifdef RTE_LIBRTE_I40E_PMD
14758         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14759 #endif
14760
14761         switch (ret) {
14762         case 0:
14763                 break;
14764         case -ENODEV:
14765                 printf("invalid port_id %d\n", res->port_id);
14766                 break;
14767         case -ENOTSUP:
14768                 printf("function not implemented\n");
14769                 break;
14770         default:
14771                 printf("programming error: (%s)\n", strerror(-ret));
14772         }
14773 }
14774
14775 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14776         .f = cmd_pctype_mapping_reset_parsed,
14777         .data = NULL,
14778         .help_str = "port config <port_id> pctype mapping reset",
14779         .tokens = {
14780                 (void *)&cmd_pctype_mapping_reset_port,
14781                 (void *)&cmd_pctype_mapping_reset_config,
14782                 (void *)&cmd_pctype_mapping_reset_port_id,
14783                 (void *)&cmd_pctype_mapping_reset_pctype,
14784                 (void *)&cmd_pctype_mapping_reset_mapping,
14785                 (void *)&cmd_pctype_mapping_reset_reset,
14786                 NULL,
14787         },
14788 };
14789
14790 /* show port pctype mapping */
14791
14792 /* Common result structure for show port pctype mapping */
14793 struct cmd_pctype_mapping_get_result {
14794         cmdline_fixed_string_t show;
14795         cmdline_fixed_string_t port;
14796         portid_t port_id;
14797         cmdline_fixed_string_t pctype;
14798         cmdline_fixed_string_t mapping;
14799 };
14800
14801 /* Common CLI fields for pctype mapping get */
14802 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14803         TOKEN_STRING_INITIALIZER
14804                 (struct cmd_pctype_mapping_get_result,
14805                  show, "show");
14806 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14807         TOKEN_STRING_INITIALIZER
14808                 (struct cmd_pctype_mapping_get_result,
14809                  port, "port");
14810 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14811         TOKEN_NUM_INITIALIZER
14812                 (struct cmd_pctype_mapping_get_result,
14813                  port_id, UINT16);
14814 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14815         TOKEN_STRING_INITIALIZER
14816                 (struct cmd_pctype_mapping_get_result,
14817                  pctype, "pctype");
14818 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14819         TOKEN_STRING_INITIALIZER
14820                 (struct cmd_pctype_mapping_get_result,
14821                  mapping, "mapping");
14822
14823 static void
14824 cmd_pctype_mapping_get_parsed(
14825         void *parsed_result,
14826         __attribute__((unused)) struct cmdline *cl,
14827         __attribute__((unused)) void *data)
14828 {
14829         struct cmd_pctype_mapping_get_result *res = parsed_result;
14830         int ret = -ENOTSUP;
14831 #ifdef RTE_LIBRTE_I40E_PMD
14832         struct rte_pmd_i40e_flow_type_mapping
14833                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14834         int i, j, first_pctype;
14835 #endif
14836
14837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14838                 return;
14839
14840 #ifdef RTE_LIBRTE_I40E_PMD
14841         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14842 #endif
14843
14844         switch (ret) {
14845         case 0:
14846                 break;
14847         case -ENODEV:
14848                 printf("invalid port_id %d\n", res->port_id);
14849                 return;
14850         case -ENOTSUP:
14851                 printf("function not implemented\n");
14852                 return;
14853         default:
14854                 printf("programming error: (%s)\n", strerror(-ret));
14855                 return;
14856         }
14857
14858 #ifdef RTE_LIBRTE_I40E_PMD
14859         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14860                 if (mapping[i].pctype != 0ULL) {
14861                         first_pctype = 1;
14862
14863                         printf("pctype: ");
14864                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14865                                 if (mapping[i].pctype & (1ULL << j)) {
14866                                         printf(first_pctype ?
14867                                                "%02d" : ",%02d", j);
14868                                         first_pctype = 0;
14869                                 }
14870                         }
14871                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14872                 }
14873         }
14874 #endif
14875 }
14876
14877 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14878         .f = cmd_pctype_mapping_get_parsed,
14879         .data = NULL,
14880         .help_str = "show port <port_id> pctype mapping",
14881         .tokens = {
14882                 (void *)&cmd_pctype_mapping_get_show,
14883                 (void *)&cmd_pctype_mapping_get_port,
14884                 (void *)&cmd_pctype_mapping_get_port_id,
14885                 (void *)&cmd_pctype_mapping_get_pctype,
14886                 (void *)&cmd_pctype_mapping_get_mapping,
14887                 NULL,
14888         },
14889 };
14890
14891 /* port config pctype mapping update */
14892
14893 /* Common result structure for port config pctype mapping update */
14894 struct cmd_pctype_mapping_update_result {
14895         cmdline_fixed_string_t port;
14896         cmdline_fixed_string_t config;
14897         portid_t port_id;
14898         cmdline_fixed_string_t pctype;
14899         cmdline_fixed_string_t mapping;
14900         cmdline_fixed_string_t update;
14901         cmdline_fixed_string_t pctype_list;
14902         uint16_t flow_type;
14903 };
14904
14905 /* Common CLI fields for pctype mapping update*/
14906 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14907         TOKEN_STRING_INITIALIZER
14908                 (struct cmd_pctype_mapping_update_result,
14909                  port, "port");
14910 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14911         TOKEN_STRING_INITIALIZER
14912                 (struct cmd_pctype_mapping_update_result,
14913                  config, "config");
14914 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14915         TOKEN_NUM_INITIALIZER
14916                 (struct cmd_pctype_mapping_update_result,
14917                  port_id, UINT16);
14918 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14919         TOKEN_STRING_INITIALIZER
14920                 (struct cmd_pctype_mapping_update_result,
14921                  pctype, "pctype");
14922 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14923         TOKEN_STRING_INITIALIZER
14924                 (struct cmd_pctype_mapping_update_result,
14925                  mapping, "mapping");
14926 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14927         TOKEN_STRING_INITIALIZER
14928                 (struct cmd_pctype_mapping_update_result,
14929                  update, "update");
14930 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14931         TOKEN_STRING_INITIALIZER
14932                 (struct cmd_pctype_mapping_update_result,
14933                  pctype_list, NULL);
14934 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14935         TOKEN_NUM_INITIALIZER
14936                 (struct cmd_pctype_mapping_update_result,
14937                  flow_type, UINT16);
14938
14939 static void
14940 cmd_pctype_mapping_update_parsed(
14941         void *parsed_result,
14942         __attribute__((unused)) struct cmdline *cl,
14943         __attribute__((unused)) void *data)
14944 {
14945         struct cmd_pctype_mapping_update_result *res = parsed_result;
14946         int ret = -ENOTSUP;
14947 #ifdef RTE_LIBRTE_I40E_PMD
14948         struct rte_pmd_i40e_flow_type_mapping mapping;
14949         unsigned int i;
14950         unsigned int nb_item;
14951         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14952 #endif
14953
14954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14955                 return;
14956
14957 #ifdef RTE_LIBRTE_I40E_PMD
14958         nb_item = parse_item_list(res->pctype_list, "pctypes",
14959                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14960         mapping.flow_type = res->flow_type;
14961         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14962                 mapping.pctype |= (1ULL << pctype_list[i]);
14963         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14964                                                 &mapping,
14965                                                 1,
14966                                                 0);
14967 #endif
14968
14969         switch (ret) {
14970         case 0:
14971                 break;
14972         case -EINVAL:
14973                 printf("invalid pctype or flow type\n");
14974                 break;
14975         case -ENODEV:
14976                 printf("invalid port_id %d\n", res->port_id);
14977                 break;
14978         case -ENOTSUP:
14979                 printf("function not implemented\n");
14980                 break;
14981         default:
14982                 printf("programming error: (%s)\n", strerror(-ret));
14983         }
14984 }
14985
14986 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14987         .f = cmd_pctype_mapping_update_parsed,
14988         .data = NULL,
14989         .help_str = "port config <port_id> pctype mapping update"
14990         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14991         .tokens = {
14992                 (void *)&cmd_pctype_mapping_update_port,
14993                 (void *)&cmd_pctype_mapping_update_config,
14994                 (void *)&cmd_pctype_mapping_update_port_id,
14995                 (void *)&cmd_pctype_mapping_update_pctype,
14996                 (void *)&cmd_pctype_mapping_update_mapping,
14997                 (void *)&cmd_pctype_mapping_update_update,
14998                 (void *)&cmd_pctype_mapping_update_pc_type,
14999                 (void *)&cmd_pctype_mapping_update_flow_type,
15000                 NULL,
15001         },
15002 };
15003
15004 /* ptype mapping get */
15005
15006 /* Common result structure for ptype mapping get */
15007 struct cmd_ptype_mapping_get_result {
15008         cmdline_fixed_string_t ptype;
15009         cmdline_fixed_string_t mapping;
15010         cmdline_fixed_string_t get;
15011         portid_t port_id;
15012         uint8_t valid_only;
15013 };
15014
15015 /* Common CLI fields for ptype mapping get */
15016 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15017         TOKEN_STRING_INITIALIZER
15018                 (struct cmd_ptype_mapping_get_result,
15019                  ptype, "ptype");
15020 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15021         TOKEN_STRING_INITIALIZER
15022                 (struct cmd_ptype_mapping_get_result,
15023                  mapping, "mapping");
15024 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15025         TOKEN_STRING_INITIALIZER
15026                 (struct cmd_ptype_mapping_get_result,
15027                  get, "get");
15028 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15029         TOKEN_NUM_INITIALIZER
15030                 (struct cmd_ptype_mapping_get_result,
15031                  port_id, UINT16);
15032 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15033         TOKEN_NUM_INITIALIZER
15034                 (struct cmd_ptype_mapping_get_result,
15035                  valid_only, UINT8);
15036
15037 static void
15038 cmd_ptype_mapping_get_parsed(
15039         void *parsed_result,
15040         __attribute__((unused)) struct cmdline *cl,
15041         __attribute__((unused)) void *data)
15042 {
15043         struct cmd_ptype_mapping_get_result *res = parsed_result;
15044         int ret = -ENOTSUP;
15045 #ifdef RTE_LIBRTE_I40E_PMD
15046         int max_ptype_num = 256;
15047         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15048         uint16_t count;
15049         int i;
15050 #endif
15051
15052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15053                 return;
15054
15055 #ifdef RTE_LIBRTE_I40E_PMD
15056         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15057                                         mapping,
15058                                         max_ptype_num,
15059                                         &count,
15060                                         res->valid_only);
15061 #endif
15062
15063         switch (ret) {
15064         case 0:
15065                 break;
15066         case -ENODEV:
15067                 printf("invalid port_id %d\n", res->port_id);
15068                 break;
15069         case -ENOTSUP:
15070                 printf("function not implemented\n");
15071                 break;
15072         default:
15073                 printf("programming error: (%s)\n", strerror(-ret));
15074         }
15075
15076 #ifdef RTE_LIBRTE_I40E_PMD
15077         if (!ret) {
15078                 for (i = 0; i < count; i++)
15079                         printf("%3d\t0x%08x\n",
15080                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15081         }
15082 #endif
15083 }
15084
15085 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15086         .f = cmd_ptype_mapping_get_parsed,
15087         .data = NULL,
15088         .help_str = "ptype mapping get <port_id> <valid_only>",
15089         .tokens = {
15090                 (void *)&cmd_ptype_mapping_get_ptype,
15091                 (void *)&cmd_ptype_mapping_get_mapping,
15092                 (void *)&cmd_ptype_mapping_get_get,
15093                 (void *)&cmd_ptype_mapping_get_port_id,
15094                 (void *)&cmd_ptype_mapping_get_valid_only,
15095                 NULL,
15096         },
15097 };
15098
15099 /* ptype mapping replace */
15100
15101 /* Common result structure for ptype mapping replace */
15102 struct cmd_ptype_mapping_replace_result {
15103         cmdline_fixed_string_t ptype;
15104         cmdline_fixed_string_t mapping;
15105         cmdline_fixed_string_t replace;
15106         portid_t port_id;
15107         uint32_t target;
15108         uint8_t mask;
15109         uint32_t pkt_type;
15110 };
15111
15112 /* Common CLI fields for ptype mapping replace */
15113 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15114         TOKEN_STRING_INITIALIZER
15115                 (struct cmd_ptype_mapping_replace_result,
15116                  ptype, "ptype");
15117 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15118         TOKEN_STRING_INITIALIZER
15119                 (struct cmd_ptype_mapping_replace_result,
15120                  mapping, "mapping");
15121 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15122         TOKEN_STRING_INITIALIZER
15123                 (struct cmd_ptype_mapping_replace_result,
15124                  replace, "replace");
15125 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15126         TOKEN_NUM_INITIALIZER
15127                 (struct cmd_ptype_mapping_replace_result,
15128                  port_id, UINT16);
15129 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15130         TOKEN_NUM_INITIALIZER
15131                 (struct cmd_ptype_mapping_replace_result,
15132                  target, UINT32);
15133 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15134         TOKEN_NUM_INITIALIZER
15135                 (struct cmd_ptype_mapping_replace_result,
15136                  mask, UINT8);
15137 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15138         TOKEN_NUM_INITIALIZER
15139                 (struct cmd_ptype_mapping_replace_result,
15140                  pkt_type, UINT32);
15141
15142 static void
15143 cmd_ptype_mapping_replace_parsed(
15144         void *parsed_result,
15145         __attribute__((unused)) struct cmdline *cl,
15146         __attribute__((unused)) void *data)
15147 {
15148         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15149         int ret = -ENOTSUP;
15150
15151         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15152                 return;
15153
15154 #ifdef RTE_LIBRTE_I40E_PMD
15155         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15156                                         res->target,
15157                                         res->mask,
15158                                         res->pkt_type);
15159 #endif
15160
15161         switch (ret) {
15162         case 0:
15163                 break;
15164         case -EINVAL:
15165                 printf("invalid ptype 0x%8x or 0x%8x\n",
15166                                 res->target, res->pkt_type);
15167                 break;
15168         case -ENODEV:
15169                 printf("invalid port_id %d\n", res->port_id);
15170                 break;
15171         case -ENOTSUP:
15172                 printf("function not implemented\n");
15173                 break;
15174         default:
15175                 printf("programming error: (%s)\n", strerror(-ret));
15176         }
15177 }
15178
15179 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15180         .f = cmd_ptype_mapping_replace_parsed,
15181         .data = NULL,
15182         .help_str =
15183                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15184         .tokens = {
15185                 (void *)&cmd_ptype_mapping_replace_ptype,
15186                 (void *)&cmd_ptype_mapping_replace_mapping,
15187                 (void *)&cmd_ptype_mapping_replace_replace,
15188                 (void *)&cmd_ptype_mapping_replace_port_id,
15189                 (void *)&cmd_ptype_mapping_replace_target,
15190                 (void *)&cmd_ptype_mapping_replace_mask,
15191                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15192                 NULL,
15193         },
15194 };
15195
15196 /* ptype mapping reset */
15197
15198 /* Common result structure for ptype mapping reset */
15199 struct cmd_ptype_mapping_reset_result {
15200         cmdline_fixed_string_t ptype;
15201         cmdline_fixed_string_t mapping;
15202         cmdline_fixed_string_t reset;
15203         portid_t port_id;
15204 };
15205
15206 /* Common CLI fields for ptype mapping reset*/
15207 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15208         TOKEN_STRING_INITIALIZER
15209                 (struct cmd_ptype_mapping_reset_result,
15210                  ptype, "ptype");
15211 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15212         TOKEN_STRING_INITIALIZER
15213                 (struct cmd_ptype_mapping_reset_result,
15214                  mapping, "mapping");
15215 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15216         TOKEN_STRING_INITIALIZER
15217                 (struct cmd_ptype_mapping_reset_result,
15218                  reset, "reset");
15219 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15220         TOKEN_NUM_INITIALIZER
15221                 (struct cmd_ptype_mapping_reset_result,
15222                  port_id, UINT16);
15223
15224 static void
15225 cmd_ptype_mapping_reset_parsed(
15226         void *parsed_result,
15227         __attribute__((unused)) struct cmdline *cl,
15228         __attribute__((unused)) void *data)
15229 {
15230         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15231         int ret = -ENOTSUP;
15232
15233         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15234                 return;
15235
15236 #ifdef RTE_LIBRTE_I40E_PMD
15237         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15238 #endif
15239
15240         switch (ret) {
15241         case 0:
15242                 break;
15243         case -ENODEV:
15244                 printf("invalid port_id %d\n", res->port_id);
15245                 break;
15246         case -ENOTSUP:
15247                 printf("function not implemented\n");
15248                 break;
15249         default:
15250                 printf("programming error: (%s)\n", strerror(-ret));
15251         }
15252 }
15253
15254 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15255         .f = cmd_ptype_mapping_reset_parsed,
15256         .data = NULL,
15257         .help_str = "ptype mapping reset <port_id>",
15258         .tokens = {
15259                 (void *)&cmd_ptype_mapping_reset_ptype,
15260                 (void *)&cmd_ptype_mapping_reset_mapping,
15261                 (void *)&cmd_ptype_mapping_reset_reset,
15262                 (void *)&cmd_ptype_mapping_reset_port_id,
15263                 NULL,
15264         },
15265 };
15266
15267 /* ptype mapping update */
15268
15269 /* Common result structure for ptype mapping update */
15270 struct cmd_ptype_mapping_update_result {
15271         cmdline_fixed_string_t ptype;
15272         cmdline_fixed_string_t mapping;
15273         cmdline_fixed_string_t reset;
15274         portid_t port_id;
15275         uint8_t hw_ptype;
15276         uint32_t sw_ptype;
15277 };
15278
15279 /* Common CLI fields for ptype mapping update*/
15280 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_ptype_mapping_update_result,
15283                  ptype, "ptype");
15284 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15285         TOKEN_STRING_INITIALIZER
15286                 (struct cmd_ptype_mapping_update_result,
15287                  mapping, "mapping");
15288 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15289         TOKEN_STRING_INITIALIZER
15290                 (struct cmd_ptype_mapping_update_result,
15291                  reset, "update");
15292 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15293         TOKEN_NUM_INITIALIZER
15294                 (struct cmd_ptype_mapping_update_result,
15295                  port_id, UINT16);
15296 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15297         TOKEN_NUM_INITIALIZER
15298                 (struct cmd_ptype_mapping_update_result,
15299                  hw_ptype, UINT8);
15300 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15301         TOKEN_NUM_INITIALIZER
15302                 (struct cmd_ptype_mapping_update_result,
15303                  sw_ptype, UINT32);
15304
15305 static void
15306 cmd_ptype_mapping_update_parsed(
15307         void *parsed_result,
15308         __attribute__((unused)) struct cmdline *cl,
15309         __attribute__((unused)) void *data)
15310 {
15311         struct cmd_ptype_mapping_update_result *res = parsed_result;
15312         int ret = -ENOTSUP;
15313 #ifdef RTE_LIBRTE_I40E_PMD
15314         struct rte_pmd_i40e_ptype_mapping mapping;
15315 #endif
15316         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15317                 return;
15318
15319 #ifdef RTE_LIBRTE_I40E_PMD
15320         mapping.hw_ptype = res->hw_ptype;
15321         mapping.sw_ptype = res->sw_ptype;
15322         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15323                                                 &mapping,
15324                                                 1,
15325                                                 0);
15326 #endif
15327
15328         switch (ret) {
15329         case 0:
15330                 break;
15331         case -EINVAL:
15332                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15333                 break;
15334         case -ENODEV:
15335                 printf("invalid port_id %d\n", res->port_id);
15336                 break;
15337         case -ENOTSUP:
15338                 printf("function not implemented\n");
15339                 break;
15340         default:
15341                 printf("programming error: (%s)\n", strerror(-ret));
15342         }
15343 }
15344
15345 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15346         .f = cmd_ptype_mapping_update_parsed,
15347         .data = NULL,
15348         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15349         .tokens = {
15350                 (void *)&cmd_ptype_mapping_update_ptype,
15351                 (void *)&cmd_ptype_mapping_update_mapping,
15352                 (void *)&cmd_ptype_mapping_update_update,
15353                 (void *)&cmd_ptype_mapping_update_port_id,
15354                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15355                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15356                 NULL,
15357         },
15358 };
15359
15360 /* Common result structure for file commands */
15361 struct cmd_cmdfile_result {
15362         cmdline_fixed_string_t load;
15363         cmdline_fixed_string_t filename;
15364 };
15365
15366 /* Common CLI fields for file commands */
15367 cmdline_parse_token_string_t cmd_load_cmdfile =
15368         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15369 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15370         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15371
15372 static void
15373 cmd_load_from_file_parsed(
15374         void *parsed_result,
15375         __attribute__((unused)) struct cmdline *cl,
15376         __attribute__((unused)) void *data)
15377 {
15378         struct cmd_cmdfile_result *res = parsed_result;
15379
15380         cmdline_read_from_file(res->filename);
15381 }
15382
15383 cmdline_parse_inst_t cmd_load_from_file = {
15384         .f = cmd_load_from_file_parsed,
15385         .data = NULL,
15386         .help_str = "load <filename>",
15387         .tokens = {
15388                 (void *)&cmd_load_cmdfile,
15389                 (void *)&cmd_load_cmdfile_filename,
15390                 NULL,
15391         },
15392 };
15393
15394 /* ******************************************************************************** */
15395
15396 /* list of instructions */
15397 cmdline_parse_ctx_t main_ctx[] = {
15398         (cmdline_parse_inst_t *)&cmd_help_brief,
15399         (cmdline_parse_inst_t *)&cmd_help_long,
15400         (cmdline_parse_inst_t *)&cmd_quit,
15401         (cmdline_parse_inst_t *)&cmd_load_from_file,
15402         (cmdline_parse_inst_t *)&cmd_showport,
15403         (cmdline_parse_inst_t *)&cmd_showqueue,
15404         (cmdline_parse_inst_t *)&cmd_showportall,
15405         (cmdline_parse_inst_t *)&cmd_showcfg,
15406         (cmdline_parse_inst_t *)&cmd_start,
15407         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15408         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15409         (cmdline_parse_inst_t *)&cmd_set_link_up,
15410         (cmdline_parse_inst_t *)&cmd_set_link_down,
15411         (cmdline_parse_inst_t *)&cmd_reset,
15412         (cmdline_parse_inst_t *)&cmd_set_numbers,
15413         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15414         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15415         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15416         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15417         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15418         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15419         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15420         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15421         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15422         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15423         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15424         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15425         (cmdline_parse_inst_t *)&cmd_set_link_check,
15426         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15427         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15428         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15429         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15430 #ifdef RTE_LIBRTE_PMD_BOND
15431         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15432         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15433         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15434         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15435         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15436         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15437         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15438         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15439         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15440         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15441         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15442 #endif
15443         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15444         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15445         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15446         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15447         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15448         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15449         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15450         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15451         (cmdline_parse_inst_t *)&cmd_csum_set,
15452         (cmdline_parse_inst_t *)&cmd_csum_show,
15453         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15454         (cmdline_parse_inst_t *)&cmd_tso_set,
15455         (cmdline_parse_inst_t *)&cmd_tso_show,
15456         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15457         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15458         (cmdline_parse_inst_t *)&cmd_gro_enable,
15459         (cmdline_parse_inst_t *)&cmd_gro_flush,
15460         (cmdline_parse_inst_t *)&cmd_gro_show,
15461         (cmdline_parse_inst_t *)&cmd_gso_enable,
15462         (cmdline_parse_inst_t *)&cmd_gso_size,
15463         (cmdline_parse_inst_t *)&cmd_gso_show,
15464         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15465         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15466         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15467         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15468         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15469         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15470         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15471         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15472         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15473         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15474         (cmdline_parse_inst_t *)&cmd_config_dcb,
15475         (cmdline_parse_inst_t *)&cmd_read_reg,
15476         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15477         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15478         (cmdline_parse_inst_t *)&cmd_write_reg,
15479         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15480         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15481         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15482         (cmdline_parse_inst_t *)&cmd_stop,
15483         (cmdline_parse_inst_t *)&cmd_mac_addr,
15484         (cmdline_parse_inst_t *)&cmd_set_qmap,
15485         (cmdline_parse_inst_t *)&cmd_operate_port,
15486         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15487         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15488         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15489         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15490         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15491         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15492         (cmdline_parse_inst_t *)&cmd_config_mtu,
15493         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15494         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15495         (cmdline_parse_inst_t *)&cmd_config_rss,
15496         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15497         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15498         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15499         (cmdline_parse_inst_t *)&cmd_showport_reta,
15500         (cmdline_parse_inst_t *)&cmd_config_burst,
15501         (cmdline_parse_inst_t *)&cmd_config_thresh,
15502         (cmdline_parse_inst_t *)&cmd_config_threshold,
15503         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15504         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15505         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15506         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15507         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15508         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15509         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15510         (cmdline_parse_inst_t *)&cmd_global_config,
15511         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15512         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15513         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15514         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15515         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15516         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15517         (cmdline_parse_inst_t *)&cmd_dump,
15518         (cmdline_parse_inst_t *)&cmd_dump_one,
15519         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15520         (cmdline_parse_inst_t *)&cmd_syn_filter,
15521         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15522         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15523         (cmdline_parse_inst_t *)&cmd_flex_filter,
15524         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15525         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15526         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15527         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15528         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15529         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15530         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15531         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15532         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15533         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15534         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15535         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15536         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15537         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15538         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15539         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15540         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15541         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15542         (cmdline_parse_inst_t *)&cmd_flow,
15543         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15544         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15545         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15546         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15547         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15548         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15549         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15550         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15551         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15552         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15553         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15554         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15555         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15556         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15557         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15558         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15559         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15560         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15561         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15562         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15563         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15564         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15565         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15566         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15567         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15568         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15569         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15570         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15571         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15572         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15573         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15574         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15575         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15576         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15577         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15578         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15579 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15580         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15581 #endif
15582         (cmdline_parse_inst_t *)&cmd_ddp_add,
15583         (cmdline_parse_inst_t *)&cmd_ddp_del,
15584         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15585         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15586         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15587         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15588         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15589         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15590         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15591         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15592
15593         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15594         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15595         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15596         (cmdline_parse_inst_t *)&cmd_queue_region,
15597         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15598         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15599         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15600         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15601         NULL,
15602 };
15603
15604 /* read cmdline commands from file */
15605 void
15606 cmdline_read_from_file(const char *filename)
15607 {
15608         struct cmdline *cl;
15609
15610         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15611         if (cl == NULL) {
15612                 printf("Failed to create file based cmdline context: %s\n",
15613                        filename);
15614                 return;
15615         }
15616
15617         cmdline_interact(cl);
15618         cmdline_quit(cl);
15619
15620         cmdline_free(cl);
15621
15622         printf("Read CLI commands from %s\n", filename);
15623 }
15624
15625 /* prompt function, called from main on MASTER lcore */
15626 void
15627 prompt(void)
15628 {
15629         /* initialize non-constant commands */
15630         cmd_set_fwd_mode_init();
15631         cmd_set_fwd_retry_mode_init();
15632
15633         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15634         if (testpmd_cl == NULL)
15635                 return;
15636         cmdline_interact(testpmd_cl);
15637         cmdline_stdin_exit(testpmd_cl);
15638 }
15639
15640 void
15641 prompt_exit(void)
15642 {
15643         if (testpmd_cl != NULL)
15644                 cmdline_quit(testpmd_cl);
15645 }
15646
15647 static void
15648 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15649 {
15650         if (id == (portid_t)RTE_PORT_ALL) {
15651                 portid_t pid;
15652
15653                 RTE_ETH_FOREACH_DEV(pid) {
15654                         /* check if need_reconfig has been set to 1 */
15655                         if (ports[pid].need_reconfig == 0)
15656                                 ports[pid].need_reconfig = dev;
15657                         /* check if need_reconfig_queues has been set to 1 */
15658                         if (ports[pid].need_reconfig_queues == 0)
15659                                 ports[pid].need_reconfig_queues = queue;
15660                 }
15661         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15662                 /* check if need_reconfig has been set to 1 */
15663                 if (ports[id].need_reconfig == 0)
15664                         ports[id].need_reconfig = dev;
15665                 /* check if need_reconfig_queues has been set to 1 */
15666                 if (ports[id].need_reconfig_queues == 0)
15667                         ports[id].need_reconfig_queues = queue;
15668         }
15669 }