app/testpmd: add commands traffic metering and policing
[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 #include "cmdline_mtr.h"
103
104 static struct cmdline *testpmd_cl;
105
106 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
107
108 /* *** Help command with introduction. *** */
109 struct cmd_help_brief_result {
110         cmdline_fixed_string_t help;
111 };
112
113 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
114                                   struct cmdline *cl,
115                                   __attribute__((unused)) void *data)
116 {
117         cmdline_printf(
118                 cl,
119                 "\n"
120                 "Help is available for the following sections:\n\n"
121                 "    help control    : Start and stop forwarding.\n"
122                 "    help display    : Displaying port, stats and config "
123                 "information.\n"
124                 "    help config     : Configuration information.\n"
125                 "    help ports      : Configuring ports.\n"
126                 "    help registers  : Reading and setting port registers.\n"
127                 "    help filters    : Filters configuration help.\n"
128                 "    help all        : All of the above sections.\n\n"
129         );
130
131 }
132
133 cmdline_parse_token_string_t cmd_help_brief_help =
134         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
135
136 cmdline_parse_inst_t cmd_help_brief = {
137         .f = cmd_help_brief_parsed,
138         .data = NULL,
139         .help_str = "help: Show help",
140         .tokens = {
141                 (void *)&cmd_help_brief_help,
142                 NULL,
143         },
144 };
145
146 /* *** Help command with help sections. *** */
147 struct cmd_help_long_result {
148         cmdline_fixed_string_t help;
149         cmdline_fixed_string_t section;
150 };
151
152 static void cmd_help_long_parsed(void *parsed_result,
153                                  struct cmdline *cl,
154                                  __attribute__((unused)) void *data)
155 {
156         int show_all = 0;
157         struct cmd_help_long_result *res = parsed_result;
158
159         if (!strcmp(res->section, "all"))
160                 show_all = 1;
161
162         if (show_all || !strcmp(res->section, "control")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Control forwarding:\n"
168                         "-------------------\n\n"
169
170                         "start\n"
171                         "    Start packet forwarding with current configuration.\n\n"
172
173                         "start tx_first\n"
174                         "    Start packet forwarding with current config"
175                         " after sending one burst of packets.\n\n"
176
177                         "stop\n"
178                         "    Stop packet forwarding, and display accumulated"
179                         " statistics.\n\n"
180
181                         "quit\n"
182                         "    Quit to prompt.\n\n"
183                 );
184         }
185
186         if (show_all || !strcmp(res->section, "display")) {
187
188                 cmdline_printf(
189                         cl,
190                         "\n"
191                         "Display:\n"
192                         "--------\n\n"
193
194                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
195                         "    Display information for port_id, or all.\n\n"
196
197                         "show port X rss reta (size) (mask0,mask1,...)\n"
198                         "    Display the rss redirection table entry indicated"
199                         " by masks on port X. size is used to indicate the"
200                         " hardware supported reta size\n\n"
201
202                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
203                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
204                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
205                         "    Display the RSS hash functions and RSS hash key"
206                         " of port X\n\n"
207
208                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
209                         "    Clear information for port_id, or all.\n\n"
210
211                         "show (rxq|txq) info (port_id) (queue_id)\n"
212                         "    Display information for configured RX/TX queue.\n\n"
213
214                         "show config (rxtx|cores|fwd|txpkts)\n"
215                         "    Display the given configuration.\n\n"
216
217                         "read rxd (port_id) (queue_id) (rxd_id)\n"
218                         "    Display an RX descriptor of a port RX queue.\n\n"
219
220                         "read txd (port_id) (queue_id) (txd_id)\n"
221                         "    Display a TX descriptor of a port TX queue.\n\n"
222
223                         "ddp get list (port_id)\n"
224                         "    Get ddp profile info list\n\n"
225
226                         "ddp get info (profile_path)\n"
227                         "    Get ddp profile information.\n\n"
228
229                         "show vf stats (port_id) (vf_id)\n"
230                         "    Display a VF's statistics.\n\n"
231
232                         "clear vf stats (port_id) (vf_id)\n"
233                         "    Reset a VF's statistics.\n\n"
234
235                         "show port (port_id) pctype mapping\n"
236                         "    Get flow ptype to pctype mapping on a port\n\n"
237
238                         "show port meter stats (port_id) (meter_id) (clear)\n"
239                         "    Get meter stats on a port\n\n"
240                 );
241         }
242
243         if (show_all || !strcmp(res->section, "config")) {
244                 cmdline_printf(
245                         cl,
246                         "\n"
247                         "Configuration:\n"
248                         "--------------\n"
249                         "Configuration changes only become active when"
250                         " forwarding is started/restarted.\n\n"
251
252                         "set default\n"
253                         "    Reset forwarding to the default configuration.\n\n"
254
255                         "set verbose (level)\n"
256                         "    Set the debug verbosity level X.\n\n"
257
258                         "set nbport (num)\n"
259                         "    Set number of ports.\n\n"
260
261                         "set nbcore (num)\n"
262                         "    Set number of cores.\n\n"
263
264                         "set coremask (mask)\n"
265                         "    Set the forwarding cores hexadecimal mask.\n\n"
266
267                         "set portmask (mask)\n"
268                         "    Set the forwarding ports hexadecimal mask.\n\n"
269
270                         "set burst (num)\n"
271                         "    Set number of packets per burst.\n\n"
272
273                         "set burst tx delay (microseconds) retry (num)\n"
274                         "    Set the transmit delay time and number of retries,"
275                         " effective when retry is enabled.\n\n"
276
277                         "set txpkts (x[,y]*)\n"
278                         "    Set the length of each segment of TXONLY"
279                         " and optionally CSUM packets.\n\n"
280
281                         "set txsplit (off|on|rand)\n"
282                         "    Set the split policy for the TX packets."
283                         " Right now only applicable for CSUM and TXONLY"
284                         " modes\n\n"
285
286                         "set corelist (x[,y]*)\n"
287                         "    Set the list of forwarding cores.\n\n"
288
289                         "set portlist (x[,y]*)\n"
290                         "    Set the list of forwarding ports.\n\n"
291
292                         "set tx loopback (port_id) (on|off)\n"
293                         "    Enable or disable tx loopback.\n\n"
294
295                         "set all queues drop (port_id) (on|off)\n"
296                         "    Set drop enable bit for all queues.\n\n"
297
298                         "set vf split drop (port_id) (vf_id) (on|off)\n"
299                         "    Set split drop enable bit for a VF from the PF.\n\n"
300
301                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
302                         "    Set MAC antispoof for a VF from the PF.\n\n"
303
304                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
305                         "    Enable MACsec offload.\n\n"
306
307                         "set macsec offload (port_id) off\n"
308                         "    Disable MACsec offload.\n\n"
309
310                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
311                         "    Configure MACsec secure connection (SC).\n\n"
312
313                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
314                         "    Configure MACsec secure association (SA).\n\n"
315
316                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
317                         "    Set VF broadcast for a VF from the PF.\n\n"
318
319                         "vlan set strip (on|off) (port_id)\n"
320                         "    Set the VLAN strip on a port.\n\n"
321
322                         "vlan set stripq (on|off) (port_id,queue_id)\n"
323                         "    Set the VLAN strip for a queue on a port.\n\n"
324
325                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
326                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
327
328                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
329                         "    Set VLAN insert for a VF from the PF.\n\n"
330
331                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN antispoof for a VF from the PF.\n\n"
333
334                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
335                         "    Set VLAN tag for a VF from the PF.\n\n"
336
337                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
338                         "    Set a VF's max bandwidth(Mbps).\n\n"
339
340                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
341                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
342
343                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
344                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
345
346                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
347                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
348
349                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
351
352                         "vlan set filter (on|off) (port_id)\n"
353                         "    Set the VLAN filter on a port.\n\n"
354
355                         "vlan set qinq (on|off) (port_id)\n"
356                         "    Set the VLAN QinQ (extended queue in queue)"
357                         " on a port.\n\n"
358
359                         "vlan set (inner|outer) tpid (value) (port_id)\n"
360                         "    Set the VLAN TPID for Packet Filtering on"
361                         " a port\n\n"
362
363                         "rx_vlan add (vlan_id|all) (port_id)\n"
364                         "    Add a vlan_id, or all identifiers, to the set"
365                         " of VLAN identifiers filtered by port_id.\n\n"
366
367                         "rx_vlan rm (vlan_id|all) (port_id)\n"
368                         "    Remove a vlan_id, or all identifiers, from the set"
369                         " of VLAN identifiers filtered by port_id.\n\n"
370
371                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
372                         "    Add a vlan_id, to the set of VLAN identifiers"
373                         "filtered for VF(s) from port_id.\n\n"
374
375                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
376                         "    Remove a vlan_id, to the set of VLAN identifiers"
377                         "filtered for VF(s) from port_id.\n\n"
378
379                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
380                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
381                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
382                         "   add a tunnel filter of a port.\n\n"
383
384                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
385                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
386                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
387                         "   remove a tunnel filter of a port.\n\n"
388
389                         "rx_vxlan_port add (udp_port) (port_id)\n"
390                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "rx_vxlan_port rm (udp_port) (port_id)\n"
393                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
394
395                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
396                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
397                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
398
399                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
400                         "    Set port based TX VLAN insertion.\n\n"
401
402                         "tx_vlan reset (port_id)\n"
403                         "    Disable hardware insertion of a VLAN header in"
404                         " packets sent on a port.\n\n"
405
406                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
407                         "    Select hardware or software calculation of the"
408                         " checksum when transmitting a packet using the"
409                         " csum forward engine.\n"
410                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
411                         "    outer-ip concerns the outer IP layer in"
412                         " case the packet is recognized as a tunnel packet by"
413                         " the forward engine (vxlan, gre and ipip are supported)\n"
414                         "    Please check the NIC datasheet for HW limits.\n\n"
415
416                         "csum parse-tunnel (on|off) (tx_port_id)\n"
417                         "    If disabled, treat tunnel packets as non-tunneled"
418                         " packets (treat inner headers as payload). The port\n"
419                         "    argument is the port used for TX in csum forward"
420                         " engine.\n\n"
421
422                         "csum show (port_id)\n"
423                         "    Display tx checksum offload configuration\n\n"
424
425                         "tso set (segsize) (portid)\n"
426                         "    Enable TCP Segmentation Offload in csum forward"
427                         " engine.\n"
428                         "    Please check the NIC datasheet for HW limits.\n\n"
429
430                         "tso show (portid)"
431                         "    Display the status of TCP Segmentation Offload.\n\n"
432
433                         "set port (port_id) gro on|off\n"
434                         "    Enable or disable Generic Receive Offload in"
435                         " csum forwarding engine.\n\n"
436
437                         "show port (port_id) gro\n"
438                         "    Display GRO configuration.\n\n"
439
440                         "set gro flush (cycles)\n"
441                         "    Set the cycle to flush GROed packets from"
442                         " reassembly tables.\n\n"
443
444                         "set port (port_id) gso (on|off)"
445                         "    Enable or disable Generic Segmentation Offload in"
446                         " csum forwarding engine.\n\n"
447
448                         "set gso segsz (length)\n"
449                         "    Set max packet length for output GSO segments,"
450                         " including packet header and payload.\n\n"
451
452                         "show port (port_id) gso\n"
453                         "    Show GSO configuration.\n\n"
454
455                         "set fwd (%s)\n"
456                         "    Set packet forwarding mode.\n\n"
457
458                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Add a MAC address on port_id.\n\n"
460
461                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Remove a MAC address from port_id.\n\n"
463
464                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Set the default MAC address for port_id.\n\n"
466
467                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
468                         "    Add a MAC address for a VF on the port.\n\n"
469
470                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the MAC address for a VF from the PF.\n\n"
472
473                         "set port (port_id) uta (mac_address|all) (on|off)\n"
474                         "    Add/Remove a or all unicast hash filter(s)"
475                         "from port X.\n\n"
476
477                         "set promisc (port_id|all) (on|off)\n"
478                         "    Set the promiscuous mode on port_id, or all.\n\n"
479
480                         "set allmulti (port_id|all) (on|off)\n"
481                         "    Set the allmulti mode on port_id, or all.\n\n"
482
483                         "set vf promisc (port_id) (vf_id) (on|off)\n"
484                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
487                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
488
489                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
490                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
491                         " (on|off) autoneg (on|off) (port_id)\n"
492                         "set flow_ctrl rx (on|off) (portid)\n"
493                         "set flow_ctrl tx (on|off) (portid)\n"
494                         "set flow_ctrl high_water (high_water) (portid)\n"
495                         "set flow_ctrl low_water (low_water) (portid)\n"
496                         "set flow_ctrl pause_time (pause_time) (portid)\n"
497                         "set flow_ctrl send_xon (send_xon) (portid)\n"
498                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
499                         "set flow_ctrl autoneg (on|off) (port_id)\n"
500                         "    Set the link flow control parameter on a port.\n\n"
501
502                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (priority) (port_id)\n"
504                         "    Set the priority flow control parameter on a"
505                         " port.\n\n"
506
507                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
508                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
509                         " queue on port.\n"
510                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
511                         " on port 0 to mapping 5.\n\n"
512
513                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
514                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
515
516                         "set port (port_id) vf (vf_id) (mac_addr)"
517                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
518                         "   Add/Remove unicast or multicast MAC addr filter"
519                         " for a VF.\n\n"
520
521                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
522                         "|MPE) (on|off)\n"
523                         "    AUPE:accepts untagged VLAN;"
524                         "ROPE:accept unicast hash\n\n"
525                         "    BAM:accepts broadcast packets;"
526                         "MPE:accepts all multicast packets\n\n"
527                         "    Enable/Disable a VF receive mode of a port\n\n"
528
529                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
530                         "    Set rate limit for a queue of a port\n\n"
531
532                         "set port (port_id) vf (vf_id) rate (rate_num) "
533                         "queue_mask (queue_mask_value)\n"
534                         "    Set rate limit for queues in VF of a port\n\n"
535
536                         "set port (port_id) mirror-rule (rule_id)"
537                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
538                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
539                         "   Set pool or vlan type mirror rule on a port.\n"
540                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
541                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
542                         " to pool 0.\n\n"
543
544                         "set port (port_id) mirror-rule (rule_id)"
545                         " (uplink-mirror|downlink-mirror) dst-pool"
546                         " (pool_id) (on|off)\n"
547                         "   Set uplink or downlink type mirror rule on a port.\n"
548                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
549                         " 0 on' enable mirror income traffic to pool 0.\n\n"
550
551                         "reset port (port_id) mirror-rule (rule_id)\n"
552                         "   Reset a mirror rule.\n\n"
553
554                         "set flush_rx (on|off)\n"
555                         "   Flush (default) or don't flush RX streams before"
556                         " forwarding. Mainly used with PCAP drivers.\n\n"
557
558                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
559                         "   Set the bypass mode for the lowest port on bypass enabled"
560                         " NIC.\n\n"
561
562                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
563                         "mode (normal|bypass|isolate) (port_id)\n"
564                         "   Set the event required to initiate specified bypass mode for"
565                         " the lowest port on a bypass enabled NIC where:\n"
566                         "       timeout   = enable bypass after watchdog timeout.\n"
567                         "       os_on     = enable bypass when OS/board is powered on.\n"
568                         "       os_off    = enable bypass when OS/board is powered off.\n"
569                         "       power_on  = enable bypass when power supply is turned on.\n"
570                         "       power_off = enable bypass when power supply is turned off."
571                         "\n\n"
572
573                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
574                         "   Set the bypass watchdog timeout to 'n' seconds"
575                         " where 0 = instant.\n\n"
576
577                         "show bypass config (port_id)\n"
578                         "   Show the bypass configuration for a bypass enabled NIC"
579                         " using the lowest port on the NIC.\n\n"
580
581 #ifdef RTE_LIBRTE_PMD_BOND
582                         "create bonded device (mode) (socket)\n"
583                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
584
585                         "add bonding slave (slave_id) (port_id)\n"
586                         "       Add a slave device to a bonded device.\n\n"
587
588                         "remove bonding slave (slave_id) (port_id)\n"
589                         "       Remove a slave device from a bonded device.\n\n"
590
591                         "set bonding mode (value) (port_id)\n"
592                         "       Set the bonding mode on a bonded device.\n\n"
593
594                         "set bonding primary (slave_id) (port_id)\n"
595                         "       Set the primary slave for a bonded device.\n\n"
596
597                         "show bonding config (port_id)\n"
598                         "       Show the bonding config for port_id.\n\n"
599
600                         "set bonding mac_addr (port_id) (address)\n"
601                         "       Set the MAC address of a bonded device.\n\n"
602
603                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
604                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
605
606                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
607                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
608
609                         "set bonding mon_period (port_id) (value)\n"
610                         "       Set the bonding link status monitoring polling period in ms.\n\n"
611
612                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
613                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
614
615 #endif
616                         "set link-up port (port_id)\n"
617                         "       Set link up for a port.\n\n"
618
619                         "set link-down port (port_id)\n"
620                         "       Set link down for a port.\n\n"
621
622                         "E-tag set insertion on port-tag-id (value)"
623                         " port (port_id) vf (vf_id)\n"
624                         "    Enable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
627                         "    Disable E-tag insertion for a VF on a port\n\n"
628
629                         "E-tag set stripping (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag stripping on a port\n\n"
631
632                         "E-tag set forwarding (on|off) port (port_id)\n"
633                         "    Enable/disable E-tag based forwarding"
634                         " on a port\n\n"
635
636                         "E-tag set filter add e-tag-id (value) dst-pool"
637                         " (pool_id) port (port_id)\n"
638                         "    Add an E-tag forwarding filter on a port\n\n"
639
640                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
641                         "    Delete an E-tag forwarding filter on a port\n\n"
642
643 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
644                         "set port tm hierarchy default (port_id)\n"
645                         "       Set default traffic Management hierarchy on a port\n\n"
646
647 #endif
648                         "ddp add (port_id) (profile_path[,output_path])\n"
649                         "    Load a profile package on a port\n\n"
650
651                         "ddp del (port_id) (profile_path)\n"
652                         "    Delete a profile package from a port\n\n"
653
654                         "ptype mapping get (port_id) (valid_only)\n"
655                         "    Get ptype mapping on a port\n\n"
656
657                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
658                         "    Replace target with the pkt_type in ptype mapping\n\n"
659
660                         "ptype mapping reset (port_id)\n"
661                         "    Reset ptype mapping on a port\n\n"
662
663                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
664                         "    Update a ptype mapping item on a port\n\n"
665
666                         "set port (port_id) queue-region region_id (value) "
667                         "queue_start_index (value) queue_num (value)\n"
668                         "    Set a queue region on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "flowtype (value)\n"
672                         "    Set a flowtype region index on a port\n\n"
673
674                         "set port (port_id) queue-region UP (value) region_id (value)\n"
675                         "    Set the mapping of User Priority to "
676                         "queue region on a port\n\n"
677
678                         "set port (port_id) queue-region flush (on|off)\n"
679                         "    flush all queue region related configuration\n\n"
680
681                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
682                         "    meter profile add - srtcm rfc 2697\n\n"
683
684                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
685                         "    meter profile add - trtcm rfc 2698\n\n"
686
687                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
688                         "    meter profile add - trtcm rfc 4115\n\n"
689
690                         "del port meter profile (port_id) (profile_id)\n"
691                         "    meter profile delete\n\n"
692
693                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
694                         "    meter create\n\n"
695
696                         "del port meter (port_id) (mtr_id)\n"
697                         "    meter delete\n\n"
698
699                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
700                         "    meter update meter profile\n\n"
701
702                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
703                         "    meter update policer action\n\n"
704
705                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
706                         "    meter update stats\n\n"
707
708                         "show port (port_id) queue-region\n"
709                         "    show all queue region related configuration info\n\n"
710
711                         , list_pkt_forwarding_modes()
712                 );
713         }
714
715         if (show_all || !strcmp(res->section, "ports")) {
716
717                 cmdline_printf(
718                         cl,
719                         "\n"
720                         "Port Operations:\n"
721                         "----------------\n\n"
722
723                         "port start (port_id|all)\n"
724                         "    Start all ports or port_id.\n\n"
725
726                         "port stop (port_id|all)\n"
727                         "    Stop all ports or port_id.\n\n"
728
729                         "port close (port_id|all)\n"
730                         "    Close all ports or port_id.\n\n"
731
732                         "port attach (ident)\n"
733                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
734
735                         "port detach (port_id)\n"
736                         "    Detach physical or virtual dev by port_id\n\n"
737
738                         "port config (port_id|all)"
739                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
740                         " duplex (half|full|auto)\n"
741                         "    Set speed and duplex for all ports or port_id\n\n"
742
743                         "port config all (rxq|txq|rxd|txd) (value)\n"
744                         "    Set number for rxq/txq/rxd/txd.\n\n"
745
746                         "port config all max-pkt-len (value)\n"
747                         "    Set the max packet length.\n\n"
748
749                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
750                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
751                         " (on|off)\n"
752                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
753                         " for ports.\n\n"
754
755                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
756                         "geneve|nvgre|none|<flowtype_id>)\n"
757                         "    Set the RSS mode.\n\n"
758
759                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
760                         "    Set the RSS redirection table.\n\n"
761
762                         "port config (port_id) dcb vt (on|off) (traffic_class)"
763                         " pfc (on|off)\n"
764                         "    Set the DCB mode.\n\n"
765
766                         "port config all burst (value)\n"
767                         "    Set the number of packets per burst.\n\n"
768
769                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
770                         " (value)\n"
771                         "    Set the ring prefetch/host/writeback threshold"
772                         " for tx/rx queue.\n\n"
773
774                         "port config all (txfreet|txrst|rxfreet) (value)\n"
775                         "    Set free threshold for rx/tx, or set"
776                         " tx rs bit threshold.\n\n"
777                         "port config mtu X value\n"
778                         "    Set the MTU of port X to a given value\n\n"
779
780                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
781                         "    Start/stop a rx/tx queue of port X. Only take effect"
782                         " when port X is started\n\n"
783
784                         "port config (port_id|all) l2-tunnel E-tag ether-type"
785                         " (value)\n"
786                         "    Set the value of E-tag ether-type.\n\n"
787
788                         "port config (port_id|all) l2-tunnel E-tag"
789                         " (enable|disable)\n"
790                         "    Enable/disable the E-tag support.\n\n"
791
792                         "port config (port_id) pctype mapping reset\n"
793                         "    Reset flow type to pctype mapping on a port\n\n"
794
795                         "port config (port_id) pctype mapping update"
796                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
797                         "    Update a flow type to pctype mapping item on a port\n\n"
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "registers")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Registers:\n"
807                         "----------\n\n"
808
809                         "read reg (port_id) (address)\n"
810                         "    Display value of a port register.\n\n"
811
812                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
813                         "    Display a port register bit field.\n\n"
814
815                         "read regbit (port_id) (address) (bit_x)\n"
816                         "    Display a single port register bit.\n\n"
817
818                         "write reg (port_id) (address) (value)\n"
819                         "    Set value of a port register.\n\n"
820
821                         "write regfield (port_id) (address) (bit_x) (bit_y)"
822                         " (value)\n"
823                         "    Set bit field of a port register.\n\n"
824
825                         "write regbit (port_id) (address) (bit_x) (value)\n"
826                         "    Set single bit value of a port register.\n\n"
827                 );
828         }
829         if (show_all || !strcmp(res->section, "filters")) {
830
831                 cmdline_printf(
832                         cl,
833                         "\n"
834                         "filters:\n"
835                         "--------\n\n"
836
837                         "ethertype_filter (port_id) (add|del)"
838                         " (mac_addr|mac_ignr) (mac_address) ethertype"
839                         " (ether_type) (drop|fwd) queue (queue_id)\n"
840                         "    Add/Del an ethertype filter.\n\n"
841
842                         "2tuple_filter (port_id) (add|del)"
843                         " dst_port (dst_port_value) protocol (protocol_value)"
844                         " mask (mask_value) tcp_flags (tcp_flags_value)"
845                         " priority (prio_value) queue (queue_id)\n"
846                         "    Add/Del a 2tuple filter.\n\n"
847
848                         "5tuple_filter (port_id) (add|del)"
849                         " dst_ip (dst_address) src_ip (src_address)"
850                         " dst_port (dst_port_value) src_port (src_port_value)"
851                         " protocol (protocol_value)"
852                         " mask (mask_value) tcp_flags (tcp_flags_value)"
853                         " priority (prio_value) queue (queue_id)\n"
854                         "    Add/Del a 5tuple filter.\n\n"
855
856                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
857                         "    Add/Del syn filter.\n\n"
858
859                         "flex_filter (port_id) (add|del) len (len_value)"
860                         " bytes (bytes_value) mask (mask_value)"
861                         " priority (prio_value) queue (queue_id)\n"
862                         "    Add/Del a flex filter.\n\n"
863
864                         "flow_director_filter (port_id) mode IP (add|del|update)"
865                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
866                         " src (src_ip_address) dst (dst_ip_address)"
867                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
868                         " vlan (vlan_value) flexbytes (flexbytes_value)"
869                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
870                         " fd_id (fd_id_value)\n"
871                         "    Add/Del an IP type flow director filter.\n\n"
872
873                         "flow_director_filter (port_id) mode IP (add|del|update)"
874                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
875                         " src (src_ip_address) (src_port)"
876                         " dst (dst_ip_address) (dst_port)"
877                         " tos (tos_value) ttl (ttl_value)"
878                         " vlan (vlan_value) flexbytes (flexbytes_value)"
879                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
880                         " fd_id (fd_id_value)\n"
881                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
882
883                         "flow_director_filter (port_id) mode IP (add|del|update)"
884                         " flow (ipv4-sctp|ipv6-sctp)"
885                         " src (src_ip_address) (src_port)"
886                         " dst (dst_ip_address) (dst_port)"
887                         " tag (verification_tag) "
888                         " tos (tos_value) ttl (ttl_value)"
889                         " vlan (vlan_value)"
890                         " flexbytes (flexbytes_value) (drop|fwd)"
891                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
892                         "    Add/Del a SCTP type flow director filter.\n\n"
893
894                         "flow_director_filter (port_id) mode IP (add|del|update)"
895                         " flow l2_payload ether (ethertype)"
896                         " flexbytes (flexbytes_value) (drop|fwd)"
897                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
898                         "    Add/Del a l2 payload type flow director filter.\n\n"
899
900                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
901                         " mac (mac_address) vlan (vlan_value)"
902                         " flexbytes (flexbytes_value) (drop|fwd)"
903                         " queue (queue_id) fd_id (fd_id_value)\n"
904                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
905
906                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
907                         " mac (mac_address) vlan (vlan_value)"
908                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
909                         " flexbytes (flexbytes_value) (drop|fwd)"
910                         " queue (queue_id) fd_id (fd_id_value)\n"
911                         "    Add/Del a Tunnel flow director filter.\n\n"
912
913                         "flush_flow_director (port_id)\n"
914                         "    Flush all flow director entries of a device.\n\n"
915
916                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
917                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
918                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
919                         "    Set flow director IP mask.\n\n"
920
921                         "flow_director_mask (port_id) mode MAC-VLAN"
922                         " vlan (vlan_value)\n"
923                         "    Set flow director MAC-VLAN mask.\n\n"
924
925                         "flow_director_mask (port_id) mode Tunnel"
926                         " vlan (vlan_value) mac (mac_value)"
927                         " tunnel-type (tunnel_type_value)"
928                         " tunnel-id (tunnel_id_value)\n"
929                         "    Set flow director Tunnel mask.\n\n"
930
931                         "flow_director_flex_mask (port_id)"
932                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
933                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
934                         " (mask)\n"
935                         "    Configure mask of flex payload.\n\n"
936
937                         "flow_director_flex_payload (port_id)"
938                         " (raw|l2|l3|l4) (config)\n"
939                         "    Configure flex payload selection.\n\n"
940
941                         "get_sym_hash_ena_per_port (port_id)\n"
942                         "    get symmetric hash enable configuration per port.\n\n"
943
944                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
945                         "    set symmetric hash enable configuration per port"
946                         " to enable or disable.\n\n"
947
948                         "get_hash_global_config (port_id)\n"
949                         "    Get the global configurations of hash filters.\n\n"
950
951                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
952                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
953                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
954                         " (enable|disable)\n"
955                         "    Set the global configurations of hash filters.\n\n"
956
957                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
958                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
959                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
960                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
961                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
962                         "ipv6-next-header|udp-src-port|udp-dst-port|"
963                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
964                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
965                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
966                         "fld-8th|none) (select|add)\n"
967                         "    Set the input set for hash.\n\n"
968
969                         "set_fdir_input_set (port_id) "
970                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
971                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
972                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
973                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
974                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
975                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
976                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
977                         " (select|add)\n"
978                         "    Set the input set for FDir.\n\n"
979
980                         "flow validate {port_id}"
981                         " [group {group_id}] [priority {level}]"
982                         " [ingress] [egress]"
983                         " pattern {item} [/ {item} [...]] / end"
984                         " actions {action} [/ {action} [...]] / end\n"
985                         "    Check whether a flow rule can be created.\n\n"
986
987                         "flow create {port_id}"
988                         " [group {group_id}] [priority {level}]"
989                         " [ingress] [egress]"
990                         " pattern {item} [/ {item} [...]] / end"
991                         " actions {action} [/ {action} [...]] / end\n"
992                         "    Create a flow rule.\n\n"
993
994                         "flow destroy {port_id} rule {rule_id} [...]\n"
995                         "    Destroy specific flow rules.\n\n"
996
997                         "flow flush {port_id}\n"
998                         "    Destroy all flow rules.\n\n"
999
1000                         "flow query {port_id} {rule_id} {action}\n"
1001                         "    Query an existing flow rule.\n\n"
1002
1003                         "flow list {port_id} [group {group_id}] [...]\n"
1004                         "    List existing flow rules sorted by priority,"
1005                         " filtered by group identifiers.\n\n"
1006
1007                         "flow isolate {port_id} {boolean}\n"
1008                         "    Restrict ingress traffic to the defined"
1009                         " flow rules\n\n"
1010                 );
1011         }
1012 }
1013
1014 cmdline_parse_token_string_t cmd_help_long_help =
1015         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1016
1017 cmdline_parse_token_string_t cmd_help_long_section =
1018         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1019                         "all#control#display#config#"
1020                         "ports#registers#filters");
1021
1022 cmdline_parse_inst_t cmd_help_long = {
1023         .f = cmd_help_long_parsed,
1024         .data = NULL,
1025         .help_str = "help all|control|display|config|ports|register|filters: "
1026                 "Show help",
1027         .tokens = {
1028                 (void *)&cmd_help_long_help,
1029                 (void *)&cmd_help_long_section,
1030                 NULL,
1031         },
1032 };
1033
1034
1035 /* *** start/stop/close all ports *** */
1036 struct cmd_operate_port_result {
1037         cmdline_fixed_string_t keyword;
1038         cmdline_fixed_string_t name;
1039         cmdline_fixed_string_t value;
1040 };
1041
1042 static void cmd_operate_port_parsed(void *parsed_result,
1043                                 __attribute__((unused)) struct cmdline *cl,
1044                                 __attribute__((unused)) void *data)
1045 {
1046         struct cmd_operate_port_result *res = parsed_result;
1047
1048         if (!strcmp(res->name, "start"))
1049                 start_port(RTE_PORT_ALL);
1050         else if (!strcmp(res->name, "stop"))
1051                 stop_port(RTE_PORT_ALL);
1052         else if (!strcmp(res->name, "close"))
1053                 close_port(RTE_PORT_ALL);
1054         else if (!strcmp(res->name, "reset"))
1055                 reset_port(RTE_PORT_ALL);
1056         else
1057                 printf("Unknown parameter\n");
1058 }
1059
1060 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1061         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1062                                                                 "port");
1063 cmdline_parse_token_string_t cmd_operate_port_all_port =
1064         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1065                                                 "start#stop#close#reset");
1066 cmdline_parse_token_string_t cmd_operate_port_all_all =
1067         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1068
1069 cmdline_parse_inst_t cmd_operate_port = {
1070         .f = cmd_operate_port_parsed,
1071         .data = NULL,
1072         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1073         .tokens = {
1074                 (void *)&cmd_operate_port_all_cmd,
1075                 (void *)&cmd_operate_port_all_port,
1076                 (void *)&cmd_operate_port_all_all,
1077                 NULL,
1078         },
1079 };
1080
1081 /* *** start/stop/close specific port *** */
1082 struct cmd_operate_specific_port_result {
1083         cmdline_fixed_string_t keyword;
1084         cmdline_fixed_string_t name;
1085         uint8_t value;
1086 };
1087
1088 static void cmd_operate_specific_port_parsed(void *parsed_result,
1089                         __attribute__((unused)) struct cmdline *cl,
1090                                 __attribute__((unused)) void *data)
1091 {
1092         struct cmd_operate_specific_port_result *res = parsed_result;
1093
1094         if (!strcmp(res->name, "start"))
1095                 start_port(res->value);
1096         else if (!strcmp(res->name, "stop"))
1097                 stop_port(res->value);
1098         else if (!strcmp(res->name, "close"))
1099                 close_port(res->value);
1100         else if (!strcmp(res->name, "reset"))
1101                 reset_port(res->value);
1102         else
1103                 printf("Unknown parameter\n");
1104 }
1105
1106 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1107         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1108                                                         keyword, "port");
1109 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1110         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1111                                                 name, "start#stop#close#reset");
1112 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1113         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1114                                                         value, UINT8);
1115
1116 cmdline_parse_inst_t cmd_operate_specific_port = {
1117         .f = cmd_operate_specific_port_parsed,
1118         .data = NULL,
1119         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1120         .tokens = {
1121                 (void *)&cmd_operate_specific_port_cmd,
1122                 (void *)&cmd_operate_specific_port_port,
1123                 (void *)&cmd_operate_specific_port_id,
1124                 NULL,
1125         },
1126 };
1127
1128 /* *** attach a specified port *** */
1129 struct cmd_operate_attach_port_result {
1130         cmdline_fixed_string_t port;
1131         cmdline_fixed_string_t keyword;
1132         cmdline_fixed_string_t identifier;
1133 };
1134
1135 static void cmd_operate_attach_port_parsed(void *parsed_result,
1136                                 __attribute__((unused)) struct cmdline *cl,
1137                                 __attribute__((unused)) void *data)
1138 {
1139         struct cmd_operate_attach_port_result *res = parsed_result;
1140
1141         if (!strcmp(res->keyword, "attach"))
1142                 attach_port(res->identifier);
1143         else
1144                 printf("Unknown parameter\n");
1145 }
1146
1147 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1148         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1149                         port, "port");
1150 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1151         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1152                         keyword, "attach");
1153 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1154         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1155                         identifier, NULL);
1156
1157 cmdline_parse_inst_t cmd_operate_attach_port = {
1158         .f = cmd_operate_attach_port_parsed,
1159         .data = NULL,
1160         .help_str = "port attach <identifier>: "
1161                 "(identifier: pci address or virtual dev name)",
1162         .tokens = {
1163                 (void *)&cmd_operate_attach_port_port,
1164                 (void *)&cmd_operate_attach_port_keyword,
1165                 (void *)&cmd_operate_attach_port_identifier,
1166                 NULL,
1167         },
1168 };
1169
1170 /* *** detach a specified port *** */
1171 struct cmd_operate_detach_port_result {
1172         cmdline_fixed_string_t port;
1173         cmdline_fixed_string_t keyword;
1174         portid_t port_id;
1175 };
1176
1177 static void cmd_operate_detach_port_parsed(void *parsed_result,
1178                                 __attribute__((unused)) struct cmdline *cl,
1179                                 __attribute__((unused)) void *data)
1180 {
1181         struct cmd_operate_detach_port_result *res = parsed_result;
1182
1183         if (!strcmp(res->keyword, "detach"))
1184                 detach_port(res->port_id);
1185         else
1186                 printf("Unknown parameter\n");
1187 }
1188
1189 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1190         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1191                         port, "port");
1192 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1194                         keyword, "detach");
1195 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1196         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1197                         port_id, UINT16);
1198
1199 cmdline_parse_inst_t cmd_operate_detach_port = {
1200         .f = cmd_operate_detach_port_parsed,
1201         .data = NULL,
1202         .help_str = "port detach <port_id>",
1203         .tokens = {
1204                 (void *)&cmd_operate_detach_port_port,
1205                 (void *)&cmd_operate_detach_port_keyword,
1206                 (void *)&cmd_operate_detach_port_port_id,
1207                 NULL,
1208         },
1209 };
1210
1211 /* *** configure speed for all ports *** */
1212 struct cmd_config_speed_all {
1213         cmdline_fixed_string_t port;
1214         cmdline_fixed_string_t keyword;
1215         cmdline_fixed_string_t all;
1216         cmdline_fixed_string_t item1;
1217         cmdline_fixed_string_t item2;
1218         cmdline_fixed_string_t value1;
1219         cmdline_fixed_string_t value2;
1220 };
1221
1222 static int
1223 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1224 {
1225
1226         int duplex;
1227
1228         if (!strcmp(duplexstr, "half")) {
1229                 duplex = ETH_LINK_HALF_DUPLEX;
1230         } else if (!strcmp(duplexstr, "full")) {
1231                 duplex = ETH_LINK_FULL_DUPLEX;
1232         } else if (!strcmp(duplexstr, "auto")) {
1233                 duplex = ETH_LINK_FULL_DUPLEX;
1234         } else {
1235                 printf("Unknown duplex parameter\n");
1236                 return -1;
1237         }
1238
1239         if (!strcmp(speedstr, "10")) {
1240                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1241                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1242         } else if (!strcmp(speedstr, "100")) {
1243                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1244                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1245         } else {
1246                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1247                         printf("Invalid speed/duplex parameters\n");
1248                         return -1;
1249                 }
1250                 if (!strcmp(speedstr, "1000")) {
1251                         *speed = ETH_LINK_SPEED_1G;
1252                 } else if (!strcmp(speedstr, "10000")) {
1253                         *speed = ETH_LINK_SPEED_10G;
1254                 } else if (!strcmp(speedstr, "25000")) {
1255                         *speed = ETH_LINK_SPEED_25G;
1256                 } else if (!strcmp(speedstr, "40000")) {
1257                         *speed = ETH_LINK_SPEED_40G;
1258                 } else if (!strcmp(speedstr, "50000")) {
1259                         *speed = ETH_LINK_SPEED_50G;
1260                 } else if (!strcmp(speedstr, "100000")) {
1261                         *speed = ETH_LINK_SPEED_100G;
1262                 } else if (!strcmp(speedstr, "auto")) {
1263                         *speed = ETH_LINK_SPEED_AUTONEG;
1264                 } else {
1265                         printf("Unknown speed parameter\n");
1266                         return -1;
1267                 }
1268         }
1269
1270         return 0;
1271 }
1272
1273 static void
1274 cmd_config_speed_all_parsed(void *parsed_result,
1275                         __attribute__((unused)) struct cmdline *cl,
1276                         __attribute__((unused)) void *data)
1277 {
1278         struct cmd_config_speed_all *res = parsed_result;
1279         uint32_t link_speed;
1280         portid_t pid;
1281
1282         if (!all_ports_stopped()) {
1283                 printf("Please stop all ports first\n");
1284                 return;
1285         }
1286
1287         if (parse_and_check_speed_duplex(res->value1, res->value2,
1288                         &link_speed) < 0)
1289                 return;
1290
1291         RTE_ETH_FOREACH_DEV(pid) {
1292                 ports[pid].dev_conf.link_speeds = link_speed;
1293         }
1294
1295         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1296 }
1297
1298 cmdline_parse_token_string_t cmd_config_speed_all_port =
1299         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1300 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1301         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1302                                                         "config");
1303 cmdline_parse_token_string_t cmd_config_speed_all_all =
1304         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1305 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1306         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1307 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1308         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1309                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1310 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1311         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1312 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1313         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1314                                                 "half#full#auto");
1315
1316 cmdline_parse_inst_t cmd_config_speed_all = {
1317         .f = cmd_config_speed_all_parsed,
1318         .data = NULL,
1319         .help_str = "port config all speed "
1320                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1321                                                         "half|full|auto",
1322         .tokens = {
1323                 (void *)&cmd_config_speed_all_port,
1324                 (void *)&cmd_config_speed_all_keyword,
1325                 (void *)&cmd_config_speed_all_all,
1326                 (void *)&cmd_config_speed_all_item1,
1327                 (void *)&cmd_config_speed_all_value1,
1328                 (void *)&cmd_config_speed_all_item2,
1329                 (void *)&cmd_config_speed_all_value2,
1330                 NULL,
1331         },
1332 };
1333
1334 /* *** configure speed for specific port *** */
1335 struct cmd_config_speed_specific {
1336         cmdline_fixed_string_t port;
1337         cmdline_fixed_string_t keyword;
1338         uint8_t id;
1339         cmdline_fixed_string_t item1;
1340         cmdline_fixed_string_t item2;
1341         cmdline_fixed_string_t value1;
1342         cmdline_fixed_string_t value2;
1343 };
1344
1345 static void
1346 cmd_config_speed_specific_parsed(void *parsed_result,
1347                                 __attribute__((unused)) struct cmdline *cl,
1348                                 __attribute__((unused)) void *data)
1349 {
1350         struct cmd_config_speed_specific *res = parsed_result;
1351         uint32_t link_speed;
1352
1353         if (!all_ports_stopped()) {
1354                 printf("Please stop all ports first\n");
1355                 return;
1356         }
1357
1358         if (port_id_is_invalid(res->id, ENABLED_WARN))
1359                 return;
1360
1361         if (parse_and_check_speed_duplex(res->value1, res->value2,
1362                         &link_speed) < 0)
1363                 return;
1364
1365         ports[res->id].dev_conf.link_speeds = link_speed;
1366
1367         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1368 }
1369
1370
1371 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1372         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1373                                                                 "port");
1374 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1375         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1376                                                                 "config");
1377 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1378         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1379 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1380         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1381                                                                 "speed");
1382 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1383         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1384                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1385 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1386         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1387                                                                 "duplex");
1388 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1389         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1390                                                         "half#full#auto");
1391
1392 cmdline_parse_inst_t cmd_config_speed_specific = {
1393         .f = cmd_config_speed_specific_parsed,
1394         .data = NULL,
1395         .help_str = "port config <port_id> speed "
1396                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1397                                                         "half|full|auto",
1398         .tokens = {
1399                 (void *)&cmd_config_speed_specific_port,
1400                 (void *)&cmd_config_speed_specific_keyword,
1401                 (void *)&cmd_config_speed_specific_id,
1402                 (void *)&cmd_config_speed_specific_item1,
1403                 (void *)&cmd_config_speed_specific_value1,
1404                 (void *)&cmd_config_speed_specific_item2,
1405                 (void *)&cmd_config_speed_specific_value2,
1406                 NULL,
1407         },
1408 };
1409
1410 /* *** configure txq/rxq, txd/rxd *** */
1411 struct cmd_config_rx_tx {
1412         cmdline_fixed_string_t port;
1413         cmdline_fixed_string_t keyword;
1414         cmdline_fixed_string_t all;
1415         cmdline_fixed_string_t name;
1416         uint16_t value;
1417 };
1418
1419 static void
1420 cmd_config_rx_tx_parsed(void *parsed_result,
1421                         __attribute__((unused)) struct cmdline *cl,
1422                         __attribute__((unused)) void *data)
1423 {
1424         struct cmd_config_rx_tx *res = parsed_result;
1425
1426         if (!all_ports_stopped()) {
1427                 printf("Please stop all ports first\n");
1428                 return;
1429         }
1430         if (!strcmp(res->name, "rxq")) {
1431                 if (!res->value && !nb_txq) {
1432                         printf("Warning: Either rx or tx queues should be non zero\n");
1433                         return;
1434                 }
1435                 nb_rxq = res->value;
1436         }
1437         else if (!strcmp(res->name, "txq")) {
1438                 if (!res->value && !nb_rxq) {
1439                         printf("Warning: Either rx or tx queues should be non zero\n");
1440                         return;
1441                 }
1442                 nb_txq = res->value;
1443         }
1444         else if (!strcmp(res->name, "rxd")) {
1445                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1446                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1447                                         res->value, RTE_TEST_RX_DESC_MAX);
1448                         return;
1449                 }
1450                 nb_rxd = res->value;
1451         } else if (!strcmp(res->name, "txd")) {
1452                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1453                         printf("txd %d invalid - must be > 0 && <= %d\n",
1454                                         res->value, RTE_TEST_TX_DESC_MAX);
1455                         return;
1456                 }
1457                 nb_txd = res->value;
1458         } else {
1459                 printf("Unknown parameter\n");
1460                 return;
1461         }
1462
1463         fwd_config_setup();
1464
1465         init_port_config();
1466
1467         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1468 }
1469
1470 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1471         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1472 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1473         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1474 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1476 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1478                                                 "rxq#txq#rxd#txd");
1479 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1480         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1481
1482 cmdline_parse_inst_t cmd_config_rx_tx = {
1483         .f = cmd_config_rx_tx_parsed,
1484         .data = NULL,
1485         .help_str = "port config all rxq|txq|rxd|txd <value>",
1486         .tokens = {
1487                 (void *)&cmd_config_rx_tx_port,
1488                 (void *)&cmd_config_rx_tx_keyword,
1489                 (void *)&cmd_config_rx_tx_all,
1490                 (void *)&cmd_config_rx_tx_name,
1491                 (void *)&cmd_config_rx_tx_value,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** config max packet length *** */
1497 struct cmd_config_max_pkt_len_result {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint32_t value;
1503 };
1504
1505 static void
1506 cmd_config_max_pkt_len_parsed(void *parsed_result,
1507                                 __attribute__((unused)) struct cmdline *cl,
1508                                 __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_max_pkt_len_result *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516
1517         if (!strcmp(res->name, "max-pkt-len")) {
1518                 if (res->value < ETHER_MIN_LEN) {
1519                         printf("max-pkt-len can not be less than %d\n",
1520                                                         ETHER_MIN_LEN);
1521                         return;
1522                 }
1523                 if (res->value == rx_mode.max_rx_pkt_len)
1524                         return;
1525
1526                 rx_mode.max_rx_pkt_len = res->value;
1527                 if (res->value > ETHER_MAX_LEN)
1528                         rx_mode.jumbo_frame = 1;
1529                 else
1530                         rx_mode.jumbo_frame = 0;
1531         } else {
1532                 printf("Unknown parameter\n");
1533                 return;
1534         }
1535
1536         init_port_config();
1537
1538         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1539 }
1540
1541 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1543                                                                 "port");
1544 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1545         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1546                                                                 "config");
1547 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1548         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1549                                                                 "all");
1550 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1551         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1552                                                                 "max-pkt-len");
1553 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1554         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1555                                                                 UINT32);
1556
1557 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1558         .f = cmd_config_max_pkt_len_parsed,
1559         .data = NULL,
1560         .help_str = "port config all max-pkt-len <value>",
1561         .tokens = {
1562                 (void *)&cmd_config_max_pkt_len_port,
1563                 (void *)&cmd_config_max_pkt_len_keyword,
1564                 (void *)&cmd_config_max_pkt_len_all,
1565                 (void *)&cmd_config_max_pkt_len_name,
1566                 (void *)&cmd_config_max_pkt_len_value,
1567                 NULL,
1568         },
1569 };
1570
1571 /* *** configure port MTU *** */
1572 struct cmd_config_mtu_result {
1573         cmdline_fixed_string_t port;
1574         cmdline_fixed_string_t keyword;
1575         cmdline_fixed_string_t mtu;
1576         portid_t port_id;
1577         uint16_t value;
1578 };
1579
1580 static void
1581 cmd_config_mtu_parsed(void *parsed_result,
1582                       __attribute__((unused)) struct cmdline *cl,
1583                       __attribute__((unused)) void *data)
1584 {
1585         struct cmd_config_mtu_result *res = parsed_result;
1586
1587         if (res->value < ETHER_MIN_LEN) {
1588                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1589                 return;
1590         }
1591         port_mtu_set(res->port_id, res->value);
1592 }
1593
1594 cmdline_parse_token_string_t cmd_config_mtu_port =
1595         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1596                                  "port");
1597 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1599                                  "config");
1600 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1601         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1602                                  "mtu");
1603 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1604         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1605 cmdline_parse_token_num_t cmd_config_mtu_value =
1606         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1607
1608 cmdline_parse_inst_t cmd_config_mtu = {
1609         .f = cmd_config_mtu_parsed,
1610         .data = NULL,
1611         .help_str = "port config mtu <port_id> <value>",
1612         .tokens = {
1613                 (void *)&cmd_config_mtu_port,
1614                 (void *)&cmd_config_mtu_keyword,
1615                 (void *)&cmd_config_mtu_mtu,
1616                 (void *)&cmd_config_mtu_port_id,
1617                 (void *)&cmd_config_mtu_value,
1618                 NULL,
1619         },
1620 };
1621
1622 /* *** configure rx mode *** */
1623 struct cmd_config_rx_mode_flag {
1624         cmdline_fixed_string_t port;
1625         cmdline_fixed_string_t keyword;
1626         cmdline_fixed_string_t all;
1627         cmdline_fixed_string_t name;
1628         cmdline_fixed_string_t value;
1629 };
1630
1631 static void
1632 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1633                                 __attribute__((unused)) struct cmdline *cl,
1634                                 __attribute__((unused)) void *data)
1635 {
1636         struct cmd_config_rx_mode_flag *res = parsed_result;
1637
1638         if (!all_ports_stopped()) {
1639                 printf("Please stop all ports first\n");
1640                 return;
1641         }
1642
1643         if (!strcmp(res->name, "crc-strip")) {
1644                 if (!strcmp(res->value, "on"))
1645                         rx_mode.hw_strip_crc = 1;
1646                 else if (!strcmp(res->value, "off"))
1647                         rx_mode.hw_strip_crc = 0;
1648                 else {
1649                         printf("Unknown parameter\n");
1650                         return;
1651                 }
1652         } else if (!strcmp(res->name, "scatter")) {
1653                 if (!strcmp(res->value, "on"))
1654                         rx_mode.enable_scatter = 1;
1655                 else if (!strcmp(res->value, "off"))
1656                         rx_mode.enable_scatter = 0;
1657                 else {
1658                         printf("Unknown parameter\n");
1659                         return;
1660                 }
1661         } else if (!strcmp(res->name, "rx-cksum")) {
1662                 if (!strcmp(res->value, "on"))
1663                         rx_mode.hw_ip_checksum = 1;
1664                 else if (!strcmp(res->value, "off"))
1665                         rx_mode.hw_ip_checksum = 0;
1666                 else {
1667                         printf("Unknown parameter\n");
1668                         return;
1669                 }
1670         } else if (!strcmp(res->name, "rx-timestamp")) {
1671                 if (!strcmp(res->value, "on"))
1672                         rx_mode.hw_timestamp = 1;
1673                 else if (!strcmp(res->value, "off"))
1674                         rx_mode.hw_timestamp = 0;
1675                 else {
1676                         printf("Unknown parameter\n");
1677                         return;
1678                 }
1679         } else if (!strcmp(res->name, "hw-vlan")) {
1680                 if (!strcmp(res->value, "on")) {
1681                         rx_mode.hw_vlan_filter = 1;
1682                         rx_mode.hw_vlan_strip  = 1;
1683                 }
1684                 else if (!strcmp(res->value, "off")) {
1685                         rx_mode.hw_vlan_filter = 0;
1686                         rx_mode.hw_vlan_strip  = 0;
1687                 }
1688                 else {
1689                         printf("Unknown parameter\n");
1690                         return;
1691                 }
1692         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1693                 if (!strcmp(res->value, "on"))
1694                         rx_mode.hw_vlan_filter = 1;
1695                 else if (!strcmp(res->value, "off"))
1696                         rx_mode.hw_vlan_filter = 0;
1697                 else {
1698                         printf("Unknown parameter\n");
1699                         return;
1700                 }
1701         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1702                 if (!strcmp(res->value, "on"))
1703                         rx_mode.hw_vlan_strip  = 1;
1704                 else if (!strcmp(res->value, "off"))
1705                         rx_mode.hw_vlan_strip  = 0;
1706                 else {
1707                         printf("Unknown parameter\n");
1708                         return;
1709                 }
1710         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1711                 if (!strcmp(res->value, "on"))
1712                         rx_mode.hw_vlan_extend = 1;
1713                 else if (!strcmp(res->value, "off"))
1714                         rx_mode.hw_vlan_extend = 0;
1715                 else {
1716                         printf("Unknown parameter\n");
1717                         return;
1718                 }
1719         } else if (!strcmp(res->name, "drop-en")) {
1720                 if (!strcmp(res->value, "on"))
1721                         rx_drop_en = 1;
1722                 else if (!strcmp(res->value, "off"))
1723                         rx_drop_en = 0;
1724                 else {
1725                         printf("Unknown parameter\n");
1726                         return;
1727                 }
1728         } else {
1729                 printf("Unknown parameter\n");
1730                 return;
1731         }
1732
1733         init_port_config();
1734
1735         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1736 }
1737
1738 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1740 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1742                                                                 "config");
1743 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1744         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1745 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1747                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1748                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1749 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1750         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1751                                                         "on#off");
1752
1753 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1754         .f = cmd_config_rx_mode_flag_parsed,
1755         .data = NULL,
1756         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1757                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1758         .tokens = {
1759                 (void *)&cmd_config_rx_mode_flag_port,
1760                 (void *)&cmd_config_rx_mode_flag_keyword,
1761                 (void *)&cmd_config_rx_mode_flag_all,
1762                 (void *)&cmd_config_rx_mode_flag_name,
1763                 (void *)&cmd_config_rx_mode_flag_value,
1764                 NULL,
1765         },
1766 };
1767
1768 /* *** configure rss *** */
1769 struct cmd_config_rss {
1770         cmdline_fixed_string_t port;
1771         cmdline_fixed_string_t keyword;
1772         cmdline_fixed_string_t all;
1773         cmdline_fixed_string_t name;
1774         cmdline_fixed_string_t value;
1775 };
1776
1777 static void
1778 cmd_config_rss_parsed(void *parsed_result,
1779                         __attribute__((unused)) struct cmdline *cl,
1780                         __attribute__((unused)) void *data)
1781 {
1782         struct cmd_config_rss *res = parsed_result;
1783         struct rte_eth_rss_conf rss_conf;
1784         int diag;
1785         uint8_t i;
1786
1787         if (!strcmp(res->value, "all"))
1788                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1789                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1790                                         ETH_RSS_L2_PAYLOAD;
1791         else if (!strcmp(res->value, "ip"))
1792                 rss_conf.rss_hf = ETH_RSS_IP;
1793         else if (!strcmp(res->value, "udp"))
1794                 rss_conf.rss_hf = ETH_RSS_UDP;
1795         else if (!strcmp(res->value, "tcp"))
1796                 rss_conf.rss_hf = ETH_RSS_TCP;
1797         else if (!strcmp(res->value, "sctp"))
1798                 rss_conf.rss_hf = ETH_RSS_SCTP;
1799         else if (!strcmp(res->value, "ether"))
1800                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1801         else if (!strcmp(res->value, "port"))
1802                 rss_conf.rss_hf = ETH_RSS_PORT;
1803         else if (!strcmp(res->value, "vxlan"))
1804                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1805         else if (!strcmp(res->value, "geneve"))
1806                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1807         else if (!strcmp(res->value, "nvgre"))
1808                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1809         else if (!strcmp(res->value, "none"))
1810                 rss_conf.rss_hf = 0;
1811         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1812                                                 atoi(res->value) < 64)
1813                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1814         else {
1815                 printf("Unknown parameter\n");
1816                 return;
1817         }
1818         rss_conf.rss_key = NULL;
1819         for (i = 0; i < rte_eth_dev_count(); i++) {
1820                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1821                 if (diag < 0)
1822                         printf("Configuration of RSS hash at ethernet port %d "
1823                                 "failed with error (%d): %s.\n",
1824                                 i, -diag, strerror(-diag));
1825         }
1826 }
1827
1828 cmdline_parse_token_string_t cmd_config_rss_port =
1829         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1830 cmdline_parse_token_string_t cmd_config_rss_keyword =
1831         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1832 cmdline_parse_token_string_t cmd_config_rss_all =
1833         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1834 cmdline_parse_token_string_t cmd_config_rss_name =
1835         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1836 cmdline_parse_token_string_t cmd_config_rss_value =
1837         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1838
1839 cmdline_parse_inst_t cmd_config_rss = {
1840         .f = cmd_config_rss_parsed,
1841         .data = NULL,
1842         .help_str = "port config all rss "
1843                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1844         .tokens = {
1845                 (void *)&cmd_config_rss_port,
1846                 (void *)&cmd_config_rss_keyword,
1847                 (void *)&cmd_config_rss_all,
1848                 (void *)&cmd_config_rss_name,
1849                 (void *)&cmd_config_rss_value,
1850                 NULL,
1851         },
1852 };
1853
1854 /* *** configure rss hash key *** */
1855 struct cmd_config_rss_hash_key {
1856         cmdline_fixed_string_t port;
1857         cmdline_fixed_string_t config;
1858         portid_t port_id;
1859         cmdline_fixed_string_t rss_hash_key;
1860         cmdline_fixed_string_t rss_type;
1861         cmdline_fixed_string_t key;
1862 };
1863
1864 static uint8_t
1865 hexa_digit_to_value(char hexa_digit)
1866 {
1867         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1868                 return (uint8_t) (hexa_digit - '0');
1869         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1870                 return (uint8_t) ((hexa_digit - 'a') + 10);
1871         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1872                 return (uint8_t) ((hexa_digit - 'A') + 10);
1873         /* Invalid hexa digit */
1874         return 0xFF;
1875 }
1876
1877 static uint8_t
1878 parse_and_check_key_hexa_digit(char *key, int idx)
1879 {
1880         uint8_t hexa_v;
1881
1882         hexa_v = hexa_digit_to_value(key[idx]);
1883         if (hexa_v == 0xFF)
1884                 printf("invalid key: character %c at position %d is not a "
1885                        "valid hexa digit\n", key[idx], idx);
1886         return hexa_v;
1887 }
1888
1889 static void
1890 cmd_config_rss_hash_key_parsed(void *parsed_result,
1891                                __attribute__((unused)) struct cmdline *cl,
1892                                __attribute__((unused)) void *data)
1893 {
1894         struct cmd_config_rss_hash_key *res = parsed_result;
1895         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1896         uint8_t xdgt0;
1897         uint8_t xdgt1;
1898         int i;
1899         struct rte_eth_dev_info dev_info;
1900         uint8_t hash_key_size;
1901         uint32_t key_len;
1902
1903         memset(&dev_info, 0, sizeof(dev_info));
1904         rte_eth_dev_info_get(res->port_id, &dev_info);
1905         if (dev_info.hash_key_size > 0 &&
1906                         dev_info.hash_key_size <= sizeof(hash_key))
1907                 hash_key_size = dev_info.hash_key_size;
1908         else {
1909                 printf("dev_info did not provide a valid hash key size\n");
1910                 return;
1911         }
1912         /* Check the length of the RSS hash key */
1913         key_len = strlen(res->key);
1914         if (key_len != (hash_key_size * 2)) {
1915                 printf("key length: %d invalid - key must be a string of %d"
1916                            " hexa-decimal numbers\n",
1917                            (int) key_len, hash_key_size * 2);
1918                 return;
1919         }
1920         /* Translate RSS hash key into binary representation */
1921         for (i = 0; i < hash_key_size; i++) {
1922                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1923                 if (xdgt0 == 0xFF)
1924                         return;
1925                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1926                 if (xdgt1 == 0xFF)
1927                         return;
1928                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1929         }
1930         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1931                         hash_key_size);
1932 }
1933
1934 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1936 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1938                                  "config");
1939 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1940         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
1941 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1943                                  rss_hash_key, "rss-hash-key");
1944 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1946                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1947                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1948                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1949                                  "ipv6-tcp-ex#ipv6-udp-ex");
1950 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1952
1953 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1954         .f = cmd_config_rss_hash_key_parsed,
1955         .data = NULL,
1956         .help_str = "port config <port_id> rss-hash-key "
1957                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1958                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1959                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1960                 "<string of hex digits (variable length, NIC dependent)>",
1961         .tokens = {
1962                 (void *)&cmd_config_rss_hash_key_port,
1963                 (void *)&cmd_config_rss_hash_key_config,
1964                 (void *)&cmd_config_rss_hash_key_port_id,
1965                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1966                 (void *)&cmd_config_rss_hash_key_rss_type,
1967                 (void *)&cmd_config_rss_hash_key_value,
1968                 NULL,
1969         },
1970 };
1971
1972 /* *** configure port rxq/txq start/stop *** */
1973 struct cmd_config_rxtx_queue {
1974         cmdline_fixed_string_t port;
1975         portid_t portid;
1976         cmdline_fixed_string_t rxtxq;
1977         uint16_t qid;
1978         cmdline_fixed_string_t opname;
1979 };
1980
1981 static void
1982 cmd_config_rxtx_queue_parsed(void *parsed_result,
1983                         __attribute__((unused)) struct cmdline *cl,
1984                         __attribute__((unused)) void *data)
1985 {
1986         struct cmd_config_rxtx_queue *res = parsed_result;
1987         uint8_t isrx;
1988         uint8_t isstart;
1989         int ret = 0;
1990
1991         if (test_done == 0) {
1992                 printf("Please stop forwarding first\n");
1993                 return;
1994         }
1995
1996         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1997                 return;
1998
1999         if (port_is_started(res->portid) != 1) {
2000                 printf("Please start port %u first\n", res->portid);
2001                 return;
2002         }
2003
2004         if (!strcmp(res->rxtxq, "rxq"))
2005                 isrx = 1;
2006         else if (!strcmp(res->rxtxq, "txq"))
2007                 isrx = 0;
2008         else {
2009                 printf("Unknown parameter\n");
2010                 return;
2011         }
2012
2013         if (isrx && rx_queue_id_is_invalid(res->qid))
2014                 return;
2015         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2016                 return;
2017
2018         if (!strcmp(res->opname, "start"))
2019                 isstart = 1;
2020         else if (!strcmp(res->opname, "stop"))
2021                 isstart = 0;
2022         else {
2023                 printf("Unknown parameter\n");
2024                 return;
2025         }
2026
2027         if (isstart && isrx)
2028                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2029         else if (!isstart && isrx)
2030                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2031         else if (isstart && !isrx)
2032                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2033         else
2034                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2035
2036         if (ret == -ENOTSUP)
2037                 printf("Function not supported in PMD driver\n");
2038 }
2039
2040 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2041         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2042 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2043         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2044 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2045         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2046 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2047         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2048 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2049         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2050                                                 "start#stop");
2051
2052 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2053         .f = cmd_config_rxtx_queue_parsed,
2054         .data = NULL,
2055         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2056         .tokens = {
2057                 (void *)&cmd_config_speed_all_port,
2058                 (void *)&cmd_config_rxtx_queue_portid,
2059                 (void *)&cmd_config_rxtx_queue_rxtxq,
2060                 (void *)&cmd_config_rxtx_queue_qid,
2061                 (void *)&cmd_config_rxtx_queue_opname,
2062                 NULL,
2063         },
2064 };
2065
2066 /* *** Configure RSS RETA *** */
2067 struct cmd_config_rss_reta {
2068         cmdline_fixed_string_t port;
2069         cmdline_fixed_string_t keyword;
2070         portid_t port_id;
2071         cmdline_fixed_string_t name;
2072         cmdline_fixed_string_t list_name;
2073         cmdline_fixed_string_t list_of_items;
2074 };
2075
2076 static int
2077 parse_reta_config(const char *str,
2078                   struct rte_eth_rss_reta_entry64 *reta_conf,
2079                   uint16_t nb_entries)
2080 {
2081         int i;
2082         unsigned size;
2083         uint16_t hash_index, idx, shift;
2084         uint16_t nb_queue;
2085         char s[256];
2086         const char *p, *p0 = str;
2087         char *end;
2088         enum fieldnames {
2089                 FLD_HASH_INDEX = 0,
2090                 FLD_QUEUE,
2091                 _NUM_FLD
2092         };
2093         unsigned long int_fld[_NUM_FLD];
2094         char *str_fld[_NUM_FLD];
2095
2096         while ((p = strchr(p0,'(')) != NULL) {
2097                 ++p;
2098                 if((p0 = strchr(p,')')) == NULL)
2099                         return -1;
2100
2101                 size = p0 - p;
2102                 if(size >= sizeof(s))
2103                         return -1;
2104
2105                 snprintf(s, sizeof(s), "%.*s", size, p);
2106                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2107                         return -1;
2108                 for (i = 0; i < _NUM_FLD; i++) {
2109                         errno = 0;
2110                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2111                         if (errno != 0 || end == str_fld[i] ||
2112                                         int_fld[i] > 65535)
2113                                 return -1;
2114                 }
2115
2116                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2117                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2118
2119                 if (hash_index >= nb_entries) {
2120                         printf("Invalid RETA hash index=%d\n", hash_index);
2121                         return -1;
2122                 }
2123
2124                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2125                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2126                 reta_conf[idx].mask |= (1ULL << shift);
2127                 reta_conf[idx].reta[shift] = nb_queue;
2128         }
2129
2130         return 0;
2131 }
2132
2133 static void
2134 cmd_set_rss_reta_parsed(void *parsed_result,
2135                         __attribute__((unused)) struct cmdline *cl,
2136                         __attribute__((unused)) void *data)
2137 {
2138         int ret;
2139         struct rte_eth_dev_info dev_info;
2140         struct rte_eth_rss_reta_entry64 reta_conf[8];
2141         struct cmd_config_rss_reta *res = parsed_result;
2142
2143         memset(&dev_info, 0, sizeof(dev_info));
2144         rte_eth_dev_info_get(res->port_id, &dev_info);
2145         if (dev_info.reta_size == 0) {
2146                 printf("Redirection table size is 0 which is "
2147                                         "invalid for RSS\n");
2148                 return;
2149         } else
2150                 printf("The reta size of port %d is %u\n",
2151                         res->port_id, dev_info.reta_size);
2152         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2153                 printf("Currently do not support more than %u entries of "
2154                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2155                 return;
2156         }
2157
2158         memset(reta_conf, 0, sizeof(reta_conf));
2159         if (!strcmp(res->list_name, "reta")) {
2160                 if (parse_reta_config(res->list_of_items, reta_conf,
2161                                                 dev_info.reta_size)) {
2162                         printf("Invalid RSS Redirection Table "
2163                                         "config entered\n");
2164                         return;
2165                 }
2166                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2167                                 reta_conf, dev_info.reta_size);
2168                 if (ret != 0)
2169                         printf("Bad redirection table parameter, "
2170                                         "return code = %d \n", ret);
2171         }
2172 }
2173
2174 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2175         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2176 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2177         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2178 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2179         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2180 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2181         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2182 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2183         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2184 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2185         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2186                                  NULL);
2187 cmdline_parse_inst_t cmd_config_rss_reta = {
2188         .f = cmd_set_rss_reta_parsed,
2189         .data = NULL,
2190         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2191         .tokens = {
2192                 (void *)&cmd_config_rss_reta_port,
2193                 (void *)&cmd_config_rss_reta_keyword,
2194                 (void *)&cmd_config_rss_reta_port_id,
2195                 (void *)&cmd_config_rss_reta_name,
2196                 (void *)&cmd_config_rss_reta_list_name,
2197                 (void *)&cmd_config_rss_reta_list_of_items,
2198                 NULL,
2199         },
2200 };
2201
2202 /* *** SHOW PORT RETA INFO *** */
2203 struct cmd_showport_reta {
2204         cmdline_fixed_string_t show;
2205         cmdline_fixed_string_t port;
2206         portid_t port_id;
2207         cmdline_fixed_string_t rss;
2208         cmdline_fixed_string_t reta;
2209         uint16_t size;
2210         cmdline_fixed_string_t list_of_items;
2211 };
2212
2213 static int
2214 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2215                            uint16_t nb_entries,
2216                            char *str)
2217 {
2218         uint32_t size;
2219         const char *p, *p0 = str;
2220         char s[256];
2221         char *end;
2222         char *str_fld[8];
2223         uint16_t i;
2224         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2225                         RTE_RETA_GROUP_SIZE;
2226         int ret;
2227
2228         p = strchr(p0, '(');
2229         if (p == NULL)
2230                 return -1;
2231         p++;
2232         p0 = strchr(p, ')');
2233         if (p0 == NULL)
2234                 return -1;
2235         size = p0 - p;
2236         if (size >= sizeof(s)) {
2237                 printf("The string size exceeds the internal buffer size\n");
2238                 return -1;
2239         }
2240         snprintf(s, sizeof(s), "%.*s", size, p);
2241         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2242         if (ret <= 0 || ret != num) {
2243                 printf("The bits of masks do not match the number of "
2244                                         "reta entries: %u\n", num);
2245                 return -1;
2246         }
2247         for (i = 0; i < ret; i++)
2248                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2249
2250         return 0;
2251 }
2252
2253 static void
2254 cmd_showport_reta_parsed(void *parsed_result,
2255                          __attribute__((unused)) struct cmdline *cl,
2256                          __attribute__((unused)) void *data)
2257 {
2258         struct cmd_showport_reta *res = parsed_result;
2259         struct rte_eth_rss_reta_entry64 reta_conf[8];
2260         struct rte_eth_dev_info dev_info;
2261         uint16_t max_reta_size;
2262
2263         memset(&dev_info, 0, sizeof(dev_info));
2264         rte_eth_dev_info_get(res->port_id, &dev_info);
2265         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2266         if (res->size == 0 || res->size > max_reta_size) {
2267                 printf("Invalid redirection table size: %u (1-%u)\n",
2268                         res->size, max_reta_size);
2269                 return;
2270         }
2271
2272         memset(reta_conf, 0, sizeof(reta_conf));
2273         if (showport_parse_reta_config(reta_conf, res->size,
2274                                 res->list_of_items) < 0) {
2275                 printf("Invalid string: %s for reta masks\n",
2276                                         res->list_of_items);
2277                 return;
2278         }
2279         port_rss_reta_info(res->port_id, reta_conf, res->size);
2280 }
2281
2282 cmdline_parse_token_string_t cmd_showport_reta_show =
2283         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2284 cmdline_parse_token_string_t cmd_showport_reta_port =
2285         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2286 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2287         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2288 cmdline_parse_token_string_t cmd_showport_reta_rss =
2289         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2290 cmdline_parse_token_string_t cmd_showport_reta_reta =
2291         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2292 cmdline_parse_token_num_t cmd_showport_reta_size =
2293         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2294 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2295         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2296                                         list_of_items, NULL);
2297
2298 cmdline_parse_inst_t cmd_showport_reta = {
2299         .f = cmd_showport_reta_parsed,
2300         .data = NULL,
2301         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2302         .tokens = {
2303                 (void *)&cmd_showport_reta_show,
2304                 (void *)&cmd_showport_reta_port,
2305                 (void *)&cmd_showport_reta_port_id,
2306                 (void *)&cmd_showport_reta_rss,
2307                 (void *)&cmd_showport_reta_reta,
2308                 (void *)&cmd_showport_reta_size,
2309                 (void *)&cmd_showport_reta_list_of_items,
2310                 NULL,
2311         },
2312 };
2313
2314 /* *** Show RSS hash configuration *** */
2315 struct cmd_showport_rss_hash {
2316         cmdline_fixed_string_t show;
2317         cmdline_fixed_string_t port;
2318         portid_t port_id;
2319         cmdline_fixed_string_t rss_hash;
2320         cmdline_fixed_string_t rss_type;
2321         cmdline_fixed_string_t key; /* optional argument */
2322 };
2323
2324 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2325                                 __attribute__((unused)) struct cmdline *cl,
2326                                 void *show_rss_key)
2327 {
2328         struct cmd_showport_rss_hash *res = parsed_result;
2329
2330         port_rss_hash_conf_show(res->port_id, res->rss_type,
2331                                 show_rss_key != NULL);
2332 }
2333
2334 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2335         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2336 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2337         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2338 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2339         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2340 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2341         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2342                                  "rss-hash");
2343 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2344         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2345                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2346                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2347                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2348                                  "ipv6-tcp-ex#ipv6-udp-ex");
2349 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2350         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2351
2352 cmdline_parse_inst_t cmd_showport_rss_hash = {
2353         .f = cmd_showport_rss_hash_parsed,
2354         .data = NULL,
2355         .help_str = "show port <port_id> rss-hash "
2356                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2357                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2358                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2359         .tokens = {
2360                 (void *)&cmd_showport_rss_hash_show,
2361                 (void *)&cmd_showport_rss_hash_port,
2362                 (void *)&cmd_showport_rss_hash_port_id,
2363                 (void *)&cmd_showport_rss_hash_rss_hash,
2364                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2365                 NULL,
2366         },
2367 };
2368
2369 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2370         .f = cmd_showport_rss_hash_parsed,
2371         .data = (void *)1,
2372         .help_str = "show port <port_id> rss-hash "
2373                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2374                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2375                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2376         .tokens = {
2377                 (void *)&cmd_showport_rss_hash_show,
2378                 (void *)&cmd_showport_rss_hash_port,
2379                 (void *)&cmd_showport_rss_hash_port_id,
2380                 (void *)&cmd_showport_rss_hash_rss_hash,
2381                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2382                 (void *)&cmd_showport_rss_hash_rss_key,
2383                 NULL,
2384         },
2385 };
2386
2387 /* *** Configure DCB *** */
2388 struct cmd_config_dcb {
2389         cmdline_fixed_string_t port;
2390         cmdline_fixed_string_t config;
2391         portid_t port_id;
2392         cmdline_fixed_string_t dcb;
2393         cmdline_fixed_string_t vt;
2394         cmdline_fixed_string_t vt_en;
2395         uint8_t num_tcs;
2396         cmdline_fixed_string_t pfc;
2397         cmdline_fixed_string_t pfc_en;
2398 };
2399
2400 static void
2401 cmd_config_dcb_parsed(void *parsed_result,
2402                         __attribute__((unused)) struct cmdline *cl,
2403                         __attribute__((unused)) void *data)
2404 {
2405         struct cmd_config_dcb *res = parsed_result;
2406         portid_t port_id = res->port_id;
2407         struct rte_port *port;
2408         uint8_t pfc_en;
2409         int ret;
2410
2411         port = &ports[port_id];
2412         /** Check if the port is not started **/
2413         if (port->port_status != RTE_PORT_STOPPED) {
2414                 printf("Please stop port %d first\n", port_id);
2415                 return;
2416         }
2417
2418         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2419                 printf("The invalid number of traffic class,"
2420                         " only 4 or 8 allowed.\n");
2421                 return;
2422         }
2423
2424         if (nb_fwd_lcores < res->num_tcs) {
2425                 printf("nb_cores shouldn't be less than number of TCs.\n");
2426                 return;
2427         }
2428         if (!strncmp(res->pfc_en, "on", 2))
2429                 pfc_en = 1;
2430         else
2431                 pfc_en = 0;
2432
2433         /* DCB in VT mode */
2434         if (!strncmp(res->vt_en, "on", 2))
2435                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2436                                 (enum rte_eth_nb_tcs)res->num_tcs,
2437                                 pfc_en);
2438         else
2439                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2440                                 (enum rte_eth_nb_tcs)res->num_tcs,
2441                                 pfc_en);
2442
2443
2444         if (ret != 0) {
2445                 printf("Cannot initialize network ports.\n");
2446                 return;
2447         }
2448
2449         cmd_reconfig_device_queue(port_id, 1, 1);
2450 }
2451
2452 cmdline_parse_token_string_t cmd_config_dcb_port =
2453         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2454 cmdline_parse_token_string_t cmd_config_dcb_config =
2455         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2456 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2457         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2458 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2459         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2460 cmdline_parse_token_string_t cmd_config_dcb_vt =
2461         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2462 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2463         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2464 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2465         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2466 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2467         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2468 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2470
2471 cmdline_parse_inst_t cmd_config_dcb = {
2472         .f = cmd_config_dcb_parsed,
2473         .data = NULL,
2474         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2475         .tokens = {
2476                 (void *)&cmd_config_dcb_port,
2477                 (void *)&cmd_config_dcb_config,
2478                 (void *)&cmd_config_dcb_port_id,
2479                 (void *)&cmd_config_dcb_dcb,
2480                 (void *)&cmd_config_dcb_vt,
2481                 (void *)&cmd_config_dcb_vt_en,
2482                 (void *)&cmd_config_dcb_num_tcs,
2483                 (void *)&cmd_config_dcb_pfc,
2484                 (void *)&cmd_config_dcb_pfc_en,
2485                 NULL,
2486         },
2487 };
2488
2489 /* *** configure number of packets per burst *** */
2490 struct cmd_config_burst {
2491         cmdline_fixed_string_t port;
2492         cmdline_fixed_string_t keyword;
2493         cmdline_fixed_string_t all;
2494         cmdline_fixed_string_t name;
2495         uint16_t value;
2496 };
2497
2498 static void
2499 cmd_config_burst_parsed(void *parsed_result,
2500                         __attribute__((unused)) struct cmdline *cl,
2501                         __attribute__((unused)) void *data)
2502 {
2503         struct cmd_config_burst *res = parsed_result;
2504
2505         if (!all_ports_stopped()) {
2506                 printf("Please stop all ports first\n");
2507                 return;
2508         }
2509
2510         if (!strcmp(res->name, "burst")) {
2511                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2512                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2513                         return;
2514                 }
2515                 nb_pkt_per_burst = res->value;
2516         } else {
2517                 printf("Unknown parameter\n");
2518                 return;
2519         }
2520
2521         init_port_config();
2522
2523         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2524 }
2525
2526 cmdline_parse_token_string_t cmd_config_burst_port =
2527         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2528 cmdline_parse_token_string_t cmd_config_burst_keyword =
2529         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2530 cmdline_parse_token_string_t cmd_config_burst_all =
2531         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2532 cmdline_parse_token_string_t cmd_config_burst_name =
2533         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2534 cmdline_parse_token_num_t cmd_config_burst_value =
2535         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2536
2537 cmdline_parse_inst_t cmd_config_burst = {
2538         .f = cmd_config_burst_parsed,
2539         .data = NULL,
2540         .help_str = "port config all burst <value>",
2541         .tokens = {
2542                 (void *)&cmd_config_burst_port,
2543                 (void *)&cmd_config_burst_keyword,
2544                 (void *)&cmd_config_burst_all,
2545                 (void *)&cmd_config_burst_name,
2546                 (void *)&cmd_config_burst_value,
2547                 NULL,
2548         },
2549 };
2550
2551 /* *** configure rx/tx queues *** */
2552 struct cmd_config_thresh {
2553         cmdline_fixed_string_t port;
2554         cmdline_fixed_string_t keyword;
2555         cmdline_fixed_string_t all;
2556         cmdline_fixed_string_t name;
2557         uint8_t value;
2558 };
2559
2560 static void
2561 cmd_config_thresh_parsed(void *parsed_result,
2562                         __attribute__((unused)) struct cmdline *cl,
2563                         __attribute__((unused)) void *data)
2564 {
2565         struct cmd_config_thresh *res = parsed_result;
2566
2567         if (!all_ports_stopped()) {
2568                 printf("Please stop all ports first\n");
2569                 return;
2570         }
2571
2572         if (!strcmp(res->name, "txpt"))
2573                 tx_pthresh = res->value;
2574         else if(!strcmp(res->name, "txht"))
2575                 tx_hthresh = res->value;
2576         else if(!strcmp(res->name, "txwt"))
2577                 tx_wthresh = res->value;
2578         else if(!strcmp(res->name, "rxpt"))
2579                 rx_pthresh = res->value;
2580         else if(!strcmp(res->name, "rxht"))
2581                 rx_hthresh = res->value;
2582         else if(!strcmp(res->name, "rxwt"))
2583                 rx_wthresh = res->value;
2584         else {
2585                 printf("Unknown parameter\n");
2586                 return;
2587         }
2588
2589         init_port_config();
2590
2591         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2592 }
2593
2594 cmdline_parse_token_string_t cmd_config_thresh_port =
2595         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2596 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2597         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2598 cmdline_parse_token_string_t cmd_config_thresh_all =
2599         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2600 cmdline_parse_token_string_t cmd_config_thresh_name =
2601         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2602                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2603 cmdline_parse_token_num_t cmd_config_thresh_value =
2604         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2605
2606 cmdline_parse_inst_t cmd_config_thresh = {
2607         .f = cmd_config_thresh_parsed,
2608         .data = NULL,
2609         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2610         .tokens = {
2611                 (void *)&cmd_config_thresh_port,
2612                 (void *)&cmd_config_thresh_keyword,
2613                 (void *)&cmd_config_thresh_all,
2614                 (void *)&cmd_config_thresh_name,
2615                 (void *)&cmd_config_thresh_value,
2616                 NULL,
2617         },
2618 };
2619
2620 /* *** configure free/rs threshold *** */
2621 struct cmd_config_threshold {
2622         cmdline_fixed_string_t port;
2623         cmdline_fixed_string_t keyword;
2624         cmdline_fixed_string_t all;
2625         cmdline_fixed_string_t name;
2626         uint16_t value;
2627 };
2628
2629 static void
2630 cmd_config_threshold_parsed(void *parsed_result,
2631                         __attribute__((unused)) struct cmdline *cl,
2632                         __attribute__((unused)) void *data)
2633 {
2634         struct cmd_config_threshold *res = parsed_result;
2635
2636         if (!all_ports_stopped()) {
2637                 printf("Please stop all ports first\n");
2638                 return;
2639         }
2640
2641         if (!strcmp(res->name, "txfreet"))
2642                 tx_free_thresh = res->value;
2643         else if (!strcmp(res->name, "txrst"))
2644                 tx_rs_thresh = res->value;
2645         else if (!strcmp(res->name, "rxfreet"))
2646                 rx_free_thresh = res->value;
2647         else {
2648                 printf("Unknown parameter\n");
2649                 return;
2650         }
2651
2652         init_port_config();
2653
2654         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2655 }
2656
2657 cmdline_parse_token_string_t cmd_config_threshold_port =
2658         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2659 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2660         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2661                                                                 "config");
2662 cmdline_parse_token_string_t cmd_config_threshold_all =
2663         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2664 cmdline_parse_token_string_t cmd_config_threshold_name =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2666                                                 "txfreet#txrst#rxfreet");
2667 cmdline_parse_token_num_t cmd_config_threshold_value =
2668         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2669
2670 cmdline_parse_inst_t cmd_config_threshold = {
2671         .f = cmd_config_threshold_parsed,
2672         .data = NULL,
2673         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2674         .tokens = {
2675                 (void *)&cmd_config_threshold_port,
2676                 (void *)&cmd_config_threshold_keyword,
2677                 (void *)&cmd_config_threshold_all,
2678                 (void *)&cmd_config_threshold_name,
2679                 (void *)&cmd_config_threshold_value,
2680                 NULL,
2681         },
2682 };
2683
2684 /* *** stop *** */
2685 struct cmd_stop_result {
2686         cmdline_fixed_string_t stop;
2687 };
2688
2689 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2690                             __attribute__((unused)) struct cmdline *cl,
2691                             __attribute__((unused)) void *data)
2692 {
2693         stop_packet_forwarding();
2694 }
2695
2696 cmdline_parse_token_string_t cmd_stop_stop =
2697         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2698
2699 cmdline_parse_inst_t cmd_stop = {
2700         .f = cmd_stop_parsed,
2701         .data = NULL,
2702         .help_str = "stop: Stop packet forwarding",
2703         .tokens = {
2704                 (void *)&cmd_stop_stop,
2705                 NULL,
2706         },
2707 };
2708
2709 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2710
2711 unsigned int
2712 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2713                 unsigned int *parsed_items, int check_unique_values)
2714 {
2715         unsigned int nb_item;
2716         unsigned int value;
2717         unsigned int i;
2718         unsigned int j;
2719         int value_ok;
2720         char c;
2721
2722         /*
2723          * First parse all items in the list and store their value.
2724          */
2725         value = 0;
2726         nb_item = 0;
2727         value_ok = 0;
2728         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2729                 c = str[i];
2730                 if ((c >= '0') && (c <= '9')) {
2731                         value = (unsigned int) (value * 10 + (c - '0'));
2732                         value_ok = 1;
2733                         continue;
2734                 }
2735                 if (c != ',') {
2736                         printf("character %c is not a decimal digit\n", c);
2737                         return 0;
2738                 }
2739                 if (! value_ok) {
2740                         printf("No valid value before comma\n");
2741                         return 0;
2742                 }
2743                 if (nb_item < max_items) {
2744                         parsed_items[nb_item] = value;
2745                         value_ok = 0;
2746                         value = 0;
2747                 }
2748                 nb_item++;
2749         }
2750         if (nb_item >= max_items) {
2751                 printf("Number of %s = %u > %u (maximum items)\n",
2752                        item_name, nb_item + 1, max_items);
2753                 return 0;
2754         }
2755         parsed_items[nb_item++] = value;
2756         if (! check_unique_values)
2757                 return nb_item;
2758
2759         /*
2760          * Then, check that all values in the list are differents.
2761          * No optimization here...
2762          */
2763         for (i = 0; i < nb_item; i++) {
2764                 for (j = i + 1; j < nb_item; j++) {
2765                         if (parsed_items[j] == parsed_items[i]) {
2766                                 printf("duplicated %s %u at index %u and %u\n",
2767                                        item_name, parsed_items[i], i, j);
2768                                 return 0;
2769                         }
2770                 }
2771         }
2772         return nb_item;
2773 }
2774
2775 struct cmd_set_list_result {
2776         cmdline_fixed_string_t cmd_keyword;
2777         cmdline_fixed_string_t list_name;
2778         cmdline_fixed_string_t list_of_items;
2779 };
2780
2781 static void cmd_set_list_parsed(void *parsed_result,
2782                                 __attribute__((unused)) struct cmdline *cl,
2783                                 __attribute__((unused)) void *data)
2784 {
2785         struct cmd_set_list_result *res;
2786         union {
2787                 unsigned int lcorelist[RTE_MAX_LCORE];
2788                 unsigned int portlist[RTE_MAX_ETHPORTS];
2789         } parsed_items;
2790         unsigned int nb_item;
2791
2792         if (test_done == 0) {
2793                 printf("Please stop forwarding first\n");
2794                 return;
2795         }
2796
2797         res = parsed_result;
2798         if (!strcmp(res->list_name, "corelist")) {
2799                 nb_item = parse_item_list(res->list_of_items, "core",
2800                                           RTE_MAX_LCORE,
2801                                           parsed_items.lcorelist, 1);
2802                 if (nb_item > 0) {
2803                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2804                         fwd_config_setup();
2805                 }
2806                 return;
2807         }
2808         if (!strcmp(res->list_name, "portlist")) {
2809                 nb_item = parse_item_list(res->list_of_items, "port",
2810                                           RTE_MAX_ETHPORTS,
2811                                           parsed_items.portlist, 1);
2812                 if (nb_item > 0) {
2813                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2814                         fwd_config_setup();
2815                 }
2816         }
2817 }
2818
2819 cmdline_parse_token_string_t cmd_set_list_keyword =
2820         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2821                                  "set");
2822 cmdline_parse_token_string_t cmd_set_list_name =
2823         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2824                                  "corelist#portlist");
2825 cmdline_parse_token_string_t cmd_set_list_of_items =
2826         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2827                                  NULL);
2828
2829 cmdline_parse_inst_t cmd_set_fwd_list = {
2830         .f = cmd_set_list_parsed,
2831         .data = NULL,
2832         .help_str = "set corelist|portlist <list0[,list1]*>",
2833         .tokens = {
2834                 (void *)&cmd_set_list_keyword,
2835                 (void *)&cmd_set_list_name,
2836                 (void *)&cmd_set_list_of_items,
2837                 NULL,
2838         },
2839 };
2840
2841 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2842
2843 struct cmd_setmask_result {
2844         cmdline_fixed_string_t set;
2845         cmdline_fixed_string_t mask;
2846         uint64_t hexavalue;
2847 };
2848
2849 static void cmd_set_mask_parsed(void *parsed_result,
2850                                 __attribute__((unused)) struct cmdline *cl,
2851                                 __attribute__((unused)) void *data)
2852 {
2853         struct cmd_setmask_result *res = parsed_result;
2854
2855         if (test_done == 0) {
2856                 printf("Please stop forwarding first\n");
2857                 return;
2858         }
2859         if (!strcmp(res->mask, "coremask")) {
2860                 set_fwd_lcores_mask(res->hexavalue);
2861                 fwd_config_setup();
2862         } else if (!strcmp(res->mask, "portmask")) {
2863                 set_fwd_ports_mask(res->hexavalue);
2864                 fwd_config_setup();
2865         }
2866 }
2867
2868 cmdline_parse_token_string_t cmd_setmask_set =
2869         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2870 cmdline_parse_token_string_t cmd_setmask_mask =
2871         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2872                                  "coremask#portmask");
2873 cmdline_parse_token_num_t cmd_setmask_value =
2874         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2875
2876 cmdline_parse_inst_t cmd_set_fwd_mask = {
2877         .f = cmd_set_mask_parsed,
2878         .data = NULL,
2879         .help_str = "set coremask|portmask <hexadecimal value>",
2880         .tokens = {
2881                 (void *)&cmd_setmask_set,
2882                 (void *)&cmd_setmask_mask,
2883                 (void *)&cmd_setmask_value,
2884                 NULL,
2885         },
2886 };
2887
2888 /*
2889  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2890  */
2891 struct cmd_set_result {
2892         cmdline_fixed_string_t set;
2893         cmdline_fixed_string_t what;
2894         uint16_t value;
2895 };
2896
2897 static void cmd_set_parsed(void *parsed_result,
2898                            __attribute__((unused)) struct cmdline *cl,
2899                            __attribute__((unused)) void *data)
2900 {
2901         struct cmd_set_result *res = parsed_result;
2902         if (!strcmp(res->what, "nbport")) {
2903                 set_fwd_ports_number(res->value);
2904                 fwd_config_setup();
2905         } else if (!strcmp(res->what, "nbcore")) {
2906                 set_fwd_lcores_number(res->value);
2907                 fwd_config_setup();
2908         } else if (!strcmp(res->what, "burst"))
2909                 set_nb_pkt_per_burst(res->value);
2910         else if (!strcmp(res->what, "verbose"))
2911                 set_verbose_level(res->value);
2912 }
2913
2914 cmdline_parse_token_string_t cmd_set_set =
2915         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2916 cmdline_parse_token_string_t cmd_set_what =
2917         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2918                                  "nbport#nbcore#burst#verbose");
2919 cmdline_parse_token_num_t cmd_set_value =
2920         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2921
2922 cmdline_parse_inst_t cmd_set_numbers = {
2923         .f = cmd_set_parsed,
2924         .data = NULL,
2925         .help_str = "set nbport|nbcore|burst|verbose <value>",
2926         .tokens = {
2927                 (void *)&cmd_set_set,
2928                 (void *)&cmd_set_what,
2929                 (void *)&cmd_set_value,
2930                 NULL,
2931         },
2932 };
2933
2934 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2935
2936 struct cmd_set_txpkts_result {
2937         cmdline_fixed_string_t cmd_keyword;
2938         cmdline_fixed_string_t txpkts;
2939         cmdline_fixed_string_t seg_lengths;
2940 };
2941
2942 static void
2943 cmd_set_txpkts_parsed(void *parsed_result,
2944                       __attribute__((unused)) struct cmdline *cl,
2945                       __attribute__((unused)) void *data)
2946 {
2947         struct cmd_set_txpkts_result *res;
2948         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2949         unsigned int nb_segs;
2950
2951         res = parsed_result;
2952         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2953                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2954         if (nb_segs > 0)
2955                 set_tx_pkt_segments(seg_lengths, nb_segs);
2956 }
2957
2958 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2959         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2960                                  cmd_keyword, "set");
2961 cmdline_parse_token_string_t cmd_set_txpkts_name =
2962         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2963                                  txpkts, "txpkts");
2964 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2965         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2966                                  seg_lengths, NULL);
2967
2968 cmdline_parse_inst_t cmd_set_txpkts = {
2969         .f = cmd_set_txpkts_parsed,
2970         .data = NULL,
2971         .help_str = "set txpkts <len0[,len1]*>",
2972         .tokens = {
2973                 (void *)&cmd_set_txpkts_keyword,
2974                 (void *)&cmd_set_txpkts_name,
2975                 (void *)&cmd_set_txpkts_lengths,
2976                 NULL,
2977         },
2978 };
2979
2980 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2981
2982 struct cmd_set_txsplit_result {
2983         cmdline_fixed_string_t cmd_keyword;
2984         cmdline_fixed_string_t txsplit;
2985         cmdline_fixed_string_t mode;
2986 };
2987
2988 static void
2989 cmd_set_txsplit_parsed(void *parsed_result,
2990                       __attribute__((unused)) struct cmdline *cl,
2991                       __attribute__((unused)) void *data)
2992 {
2993         struct cmd_set_txsplit_result *res;
2994
2995         res = parsed_result;
2996         set_tx_pkt_split(res->mode);
2997 }
2998
2999 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3000         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3001                                  cmd_keyword, "set");
3002 cmdline_parse_token_string_t cmd_set_txsplit_name =
3003         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3004                                  txsplit, "txsplit");
3005 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3006         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3007                                  mode, NULL);
3008
3009 cmdline_parse_inst_t cmd_set_txsplit = {
3010         .f = cmd_set_txsplit_parsed,
3011         .data = NULL,
3012         .help_str = "set txsplit on|off|rand",
3013         .tokens = {
3014                 (void *)&cmd_set_txsplit_keyword,
3015                 (void *)&cmd_set_txsplit_name,
3016                 (void *)&cmd_set_txsplit_mode,
3017                 NULL,
3018         },
3019 };
3020
3021 /* *** CONFIG TX QUEUE FLAGS *** */
3022
3023 struct cmd_config_txqflags_result {
3024         cmdline_fixed_string_t port;
3025         cmdline_fixed_string_t config;
3026         cmdline_fixed_string_t all;
3027         cmdline_fixed_string_t what;
3028         int32_t hexvalue;
3029 };
3030
3031 static void cmd_config_txqflags_parsed(void *parsed_result,
3032                                 __attribute__((unused)) struct cmdline *cl,
3033                                 __attribute__((unused)) void *data)
3034 {
3035         struct cmd_config_txqflags_result *res = parsed_result;
3036
3037         if (!all_ports_stopped()) {
3038                 printf("Please stop all ports first\n");
3039                 return;
3040         }
3041
3042         if (strcmp(res->what, "txqflags")) {
3043                 printf("Unknown parameter\n");
3044                 return;
3045         }
3046
3047         if (res->hexvalue >= 0) {
3048                 txq_flags = res->hexvalue;
3049         } else {
3050                 printf("txqflags must be >= 0\n");
3051                 return;
3052         }
3053
3054         init_port_config();
3055
3056         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3057 }
3058
3059 cmdline_parse_token_string_t cmd_config_txqflags_port =
3060         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3061                                  "port");
3062 cmdline_parse_token_string_t cmd_config_txqflags_config =
3063         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3064                                  "config");
3065 cmdline_parse_token_string_t cmd_config_txqflags_all =
3066         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3067                                  "all");
3068 cmdline_parse_token_string_t cmd_config_txqflags_what =
3069         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3070                                  "txqflags");
3071 cmdline_parse_token_num_t cmd_config_txqflags_value =
3072         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3073                                 hexvalue, INT32);
3074
3075 cmdline_parse_inst_t cmd_config_txqflags = {
3076         .f = cmd_config_txqflags_parsed,
3077         .data = NULL,
3078         .help_str = "port config all txqflags <value>",
3079         .tokens = {
3080                 (void *)&cmd_config_txqflags_port,
3081                 (void *)&cmd_config_txqflags_config,
3082                 (void *)&cmd_config_txqflags_all,
3083                 (void *)&cmd_config_txqflags_what,
3084                 (void *)&cmd_config_txqflags_value,
3085                 NULL,
3086         },
3087 };
3088
3089 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3090 struct cmd_rx_vlan_filter_all_result {
3091         cmdline_fixed_string_t rx_vlan;
3092         cmdline_fixed_string_t what;
3093         cmdline_fixed_string_t all;
3094         portid_t port_id;
3095 };
3096
3097 static void
3098 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3099                               __attribute__((unused)) struct cmdline *cl,
3100                               __attribute__((unused)) void *data)
3101 {
3102         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3103
3104         if (!strcmp(res->what, "add"))
3105                 rx_vlan_all_filter_set(res->port_id, 1);
3106         else
3107                 rx_vlan_all_filter_set(res->port_id, 0);
3108 }
3109
3110 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3111         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3112                                  rx_vlan, "rx_vlan");
3113 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3114         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3115                                  what, "add#rm");
3116 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3117         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3118                                  all, "all");
3119 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3120         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3121                               port_id, UINT16);
3122
3123 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3124         .f = cmd_rx_vlan_filter_all_parsed,
3125         .data = NULL,
3126         .help_str = "rx_vlan add|rm all <port_id>: "
3127                 "Add/Remove all identifiers to/from the set of VLAN "
3128                 "identifiers filtered by a port",
3129         .tokens = {
3130                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3131                 (void *)&cmd_rx_vlan_filter_all_what,
3132                 (void *)&cmd_rx_vlan_filter_all_all,
3133                 (void *)&cmd_rx_vlan_filter_all_portid,
3134                 NULL,
3135         },
3136 };
3137
3138 /* *** VLAN OFFLOAD SET ON A PORT *** */
3139 struct cmd_vlan_offload_result {
3140         cmdline_fixed_string_t vlan;
3141         cmdline_fixed_string_t set;
3142         cmdline_fixed_string_t vlan_type;
3143         cmdline_fixed_string_t what;
3144         cmdline_fixed_string_t on;
3145         cmdline_fixed_string_t port_id;
3146 };
3147
3148 static void
3149 cmd_vlan_offload_parsed(void *parsed_result,
3150                           __attribute__((unused)) struct cmdline *cl,
3151                           __attribute__((unused)) void *data)
3152 {
3153         int on;
3154         struct cmd_vlan_offload_result *res = parsed_result;
3155         char *str;
3156         int i, len = 0;
3157         portid_t port_id = 0;
3158         unsigned int tmp;
3159
3160         str = res->port_id;
3161         len = strnlen(str, STR_TOKEN_SIZE);
3162         i = 0;
3163         /* Get port_id first */
3164         while(i < len){
3165                 if(str[i] == ',')
3166                         break;
3167
3168                 i++;
3169         }
3170         str[i]='\0';
3171         tmp = strtoul(str, NULL, 0);
3172         /* If port_id greater that what portid_t can represent, return */
3173         if(tmp >= RTE_MAX_ETHPORTS)
3174                 return;
3175         port_id = (portid_t)tmp;
3176
3177         if (!strcmp(res->on, "on"))
3178                 on = 1;
3179         else
3180                 on = 0;
3181
3182         if (!strcmp(res->what, "strip"))
3183                 rx_vlan_strip_set(port_id,  on);
3184         else if(!strcmp(res->what, "stripq")){
3185                 uint16_t queue_id = 0;
3186
3187                 /* No queue_id, return */
3188                 if(i + 1 >= len) {
3189                         printf("must specify (port,queue_id)\n");
3190                         return;
3191                 }
3192                 tmp = strtoul(str + i + 1, NULL, 0);
3193                 /* If queue_id greater that what 16-bits can represent, return */
3194                 if(tmp > 0xffff)
3195                         return;
3196
3197                 queue_id = (uint16_t)tmp;
3198                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3199         }
3200         else if (!strcmp(res->what, "filter"))
3201                 rx_vlan_filter_set(port_id, on);
3202         else
3203                 vlan_extend_set(port_id, on);
3204
3205         return;
3206 }
3207
3208 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3209         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3210                                  vlan, "vlan");
3211 cmdline_parse_token_string_t cmd_vlan_offload_set =
3212         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3213                                  set, "set");
3214 cmdline_parse_token_string_t cmd_vlan_offload_what =
3215         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3216                                  what, "strip#filter#qinq#stripq");
3217 cmdline_parse_token_string_t cmd_vlan_offload_on =
3218         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3219                               on, "on#off");
3220 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3221         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3222                               port_id, NULL);
3223
3224 cmdline_parse_inst_t cmd_vlan_offload = {
3225         .f = cmd_vlan_offload_parsed,
3226         .data = NULL,
3227         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3228                 "<port_id[,queue_id]>: "
3229                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3230         .tokens = {
3231                 (void *)&cmd_vlan_offload_vlan,
3232                 (void *)&cmd_vlan_offload_set,
3233                 (void *)&cmd_vlan_offload_what,
3234                 (void *)&cmd_vlan_offload_on,
3235                 (void *)&cmd_vlan_offload_portid,
3236                 NULL,
3237         },
3238 };
3239
3240 /* *** VLAN TPID SET ON A PORT *** */
3241 struct cmd_vlan_tpid_result {
3242         cmdline_fixed_string_t vlan;
3243         cmdline_fixed_string_t set;
3244         cmdline_fixed_string_t vlan_type;
3245         cmdline_fixed_string_t what;
3246         uint16_t tp_id;
3247         portid_t port_id;
3248 };
3249
3250 static void
3251 cmd_vlan_tpid_parsed(void *parsed_result,
3252                           __attribute__((unused)) struct cmdline *cl,
3253                           __attribute__((unused)) void *data)
3254 {
3255         struct cmd_vlan_tpid_result *res = parsed_result;
3256         enum rte_vlan_type vlan_type;
3257
3258         if (!strcmp(res->vlan_type, "inner"))
3259                 vlan_type = ETH_VLAN_TYPE_INNER;
3260         else if (!strcmp(res->vlan_type, "outer"))
3261                 vlan_type = ETH_VLAN_TYPE_OUTER;
3262         else {
3263                 printf("Unknown vlan type\n");
3264                 return;
3265         }
3266         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3267 }
3268
3269 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3270         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3271                                  vlan, "vlan");
3272 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3273         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3274                                  set, "set");
3275 cmdline_parse_token_string_t cmd_vlan_type =
3276         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3277                                  vlan_type, "inner#outer");
3278 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3279         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3280                                  what, "tpid");
3281 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3282         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3283                               tp_id, UINT16);
3284 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3285         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3286                               port_id, UINT8);
3287
3288 cmdline_parse_inst_t cmd_vlan_tpid = {
3289         .f = cmd_vlan_tpid_parsed,
3290         .data = NULL,
3291         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3292                 "Set the VLAN Ether type",
3293         .tokens = {
3294                 (void *)&cmd_vlan_tpid_vlan,
3295                 (void *)&cmd_vlan_tpid_set,
3296                 (void *)&cmd_vlan_type,
3297                 (void *)&cmd_vlan_tpid_what,
3298                 (void *)&cmd_vlan_tpid_tpid,
3299                 (void *)&cmd_vlan_tpid_portid,
3300                 NULL,
3301         },
3302 };
3303
3304 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3305 struct cmd_rx_vlan_filter_result {
3306         cmdline_fixed_string_t rx_vlan;
3307         cmdline_fixed_string_t what;
3308         uint16_t vlan_id;
3309         portid_t port_id;
3310 };
3311
3312 static void
3313 cmd_rx_vlan_filter_parsed(void *parsed_result,
3314                           __attribute__((unused)) struct cmdline *cl,
3315                           __attribute__((unused)) void *data)
3316 {
3317         struct cmd_rx_vlan_filter_result *res = parsed_result;
3318
3319         if (!strcmp(res->what, "add"))
3320                 rx_vft_set(res->port_id, res->vlan_id, 1);
3321         else
3322                 rx_vft_set(res->port_id, res->vlan_id, 0);
3323 }
3324
3325 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3326         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3327                                  rx_vlan, "rx_vlan");
3328 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3329         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3330                                  what, "add#rm");
3331 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3332         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3333                               vlan_id, UINT16);
3334 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3335         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3336                               port_id, UINT16);
3337
3338 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3339         .f = cmd_rx_vlan_filter_parsed,
3340         .data = NULL,
3341         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3342                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3343                 "identifiers filtered by a port",
3344         .tokens = {
3345                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3346                 (void *)&cmd_rx_vlan_filter_what,
3347                 (void *)&cmd_rx_vlan_filter_vlanid,
3348                 (void *)&cmd_rx_vlan_filter_portid,
3349                 NULL,
3350         },
3351 };
3352
3353 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3354 struct cmd_tx_vlan_set_result {
3355         cmdline_fixed_string_t tx_vlan;
3356         cmdline_fixed_string_t set;
3357         portid_t port_id;
3358         uint16_t vlan_id;
3359 };
3360
3361 static void
3362 cmd_tx_vlan_set_parsed(void *parsed_result,
3363                        __attribute__((unused)) struct cmdline *cl,
3364                        __attribute__((unused)) void *data)
3365 {
3366         struct cmd_tx_vlan_set_result *res = parsed_result;
3367
3368         tx_vlan_set(res->port_id, res->vlan_id);
3369 }
3370
3371 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3372         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3373                                  tx_vlan, "tx_vlan");
3374 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3375         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3376                                  set, "set");
3377 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3378         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3379                               port_id, UINT16);
3380 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3381         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3382                               vlan_id, UINT16);
3383
3384 cmdline_parse_inst_t cmd_tx_vlan_set = {
3385         .f = cmd_tx_vlan_set_parsed,
3386         .data = NULL,
3387         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3388                 "Enable hardware insertion of a single VLAN header "
3389                 "with a given TAG Identifier in packets sent on a port",
3390         .tokens = {
3391                 (void *)&cmd_tx_vlan_set_tx_vlan,
3392                 (void *)&cmd_tx_vlan_set_set,
3393                 (void *)&cmd_tx_vlan_set_portid,
3394                 (void *)&cmd_tx_vlan_set_vlanid,
3395                 NULL,
3396         },
3397 };
3398
3399 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3400 struct cmd_tx_vlan_set_qinq_result {
3401         cmdline_fixed_string_t tx_vlan;
3402         cmdline_fixed_string_t set;
3403         portid_t port_id;
3404         uint16_t vlan_id;
3405         uint16_t vlan_id_outer;
3406 };
3407
3408 static void
3409 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3410                             __attribute__((unused)) struct cmdline *cl,
3411                             __attribute__((unused)) void *data)
3412 {
3413         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3414
3415         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3416 }
3417
3418 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3419         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3420                 tx_vlan, "tx_vlan");
3421 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3422         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3423                 set, "set");
3424 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3425         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3426                 port_id, UINT16);
3427 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3428         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3429                 vlan_id, UINT16);
3430 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3431         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3432                 vlan_id_outer, UINT16);
3433
3434 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3435         .f = cmd_tx_vlan_set_qinq_parsed,
3436         .data = NULL,
3437         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3438                 "Enable hardware insertion of double VLAN header "
3439                 "with given TAG Identifiers in packets sent on a port",
3440         .tokens = {
3441                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3442                 (void *)&cmd_tx_vlan_set_qinq_set,
3443                 (void *)&cmd_tx_vlan_set_qinq_portid,
3444                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3445                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3446                 NULL,
3447         },
3448 };
3449
3450 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3451 struct cmd_tx_vlan_set_pvid_result {
3452         cmdline_fixed_string_t tx_vlan;
3453         cmdline_fixed_string_t set;
3454         cmdline_fixed_string_t pvid;
3455         portid_t port_id;
3456         uint16_t vlan_id;
3457         cmdline_fixed_string_t mode;
3458 };
3459
3460 static void
3461 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3462                             __attribute__((unused)) struct cmdline *cl,
3463                             __attribute__((unused)) void *data)
3464 {
3465         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3466
3467         if (strcmp(res->mode, "on") == 0)
3468                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3469         else
3470                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3471 }
3472
3473 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3474         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3475                                  tx_vlan, "tx_vlan");
3476 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3477         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3478                                  set, "set");
3479 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3480         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3481                                  pvid, "pvid");
3482 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3483         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3484                              port_id, UINT16);
3485 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3486         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3487                               vlan_id, UINT16);
3488 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3489         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3490                                  mode, "on#off");
3491
3492 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3493         .f = cmd_tx_vlan_set_pvid_parsed,
3494         .data = NULL,
3495         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3496         .tokens = {
3497                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3498                 (void *)&cmd_tx_vlan_set_pvid_set,
3499                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3500                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3501                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3502                 (void *)&cmd_tx_vlan_set_pvid_mode,
3503                 NULL,
3504         },
3505 };
3506
3507 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3508 struct cmd_tx_vlan_reset_result {
3509         cmdline_fixed_string_t tx_vlan;
3510         cmdline_fixed_string_t reset;
3511         portid_t port_id;
3512 };
3513
3514 static void
3515 cmd_tx_vlan_reset_parsed(void *parsed_result,
3516                          __attribute__((unused)) struct cmdline *cl,
3517                          __attribute__((unused)) void *data)
3518 {
3519         struct cmd_tx_vlan_reset_result *res = parsed_result;
3520
3521         tx_vlan_reset(res->port_id);
3522 }
3523
3524 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3525         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3526                                  tx_vlan, "tx_vlan");
3527 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3528         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3529                                  reset, "reset");
3530 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3531         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3532                               port_id, UINT16);
3533
3534 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3535         .f = cmd_tx_vlan_reset_parsed,
3536         .data = NULL,
3537         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3538                 "VLAN header in packets sent on a port",
3539         .tokens = {
3540                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3541                 (void *)&cmd_tx_vlan_reset_reset,
3542                 (void *)&cmd_tx_vlan_reset_portid,
3543                 NULL,
3544         },
3545 };
3546
3547
3548 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3549 struct cmd_csum_result {
3550         cmdline_fixed_string_t csum;
3551         cmdline_fixed_string_t mode;
3552         cmdline_fixed_string_t proto;
3553         cmdline_fixed_string_t hwsw;
3554         portid_t port_id;
3555 };
3556
3557 static void
3558 csum_show(int port_id)
3559 {
3560         struct rte_eth_dev_info dev_info;
3561         uint16_t ol_flags;
3562
3563         ol_flags = ports[port_id].tx_ol_flags;
3564         printf("Parse tunnel is %s\n",
3565                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3566         printf("IP checksum offload is %s\n",
3567                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3568         printf("UDP checksum offload is %s\n",
3569                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3570         printf("TCP checksum offload is %s\n",
3571                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3572         printf("SCTP checksum offload is %s\n",
3573                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3574         printf("Outer-Ip checksum offload is %s\n",
3575                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3576
3577         /* display warnings if configuration is not supported by the NIC */
3578         rte_eth_dev_info_get(port_id, &dev_info);
3579         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3580                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3581                 printf("Warning: hardware IP checksum enabled but not "
3582                         "supported by port %d\n", port_id);
3583         }
3584         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3585                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3586                 printf("Warning: hardware UDP checksum enabled but not "
3587                         "supported by port %d\n", port_id);
3588         }
3589         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3590                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3591                 printf("Warning: hardware TCP checksum enabled but not "
3592                         "supported by port %d\n", port_id);
3593         }
3594         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3595                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3596                 printf("Warning: hardware SCTP checksum enabled but not "
3597                         "supported by port %d\n", port_id);
3598         }
3599         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3600                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3601                 printf("Warning: hardware outer IP checksum enabled but not "
3602                         "supported by port %d\n", port_id);
3603         }
3604 }
3605
3606 static void
3607 cmd_csum_parsed(void *parsed_result,
3608                        __attribute__((unused)) struct cmdline *cl,
3609                        __attribute__((unused)) void *data)
3610 {
3611         struct cmd_csum_result *res = parsed_result;
3612         int hw = 0;
3613         uint16_t mask = 0;
3614
3615         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3616                 printf("invalid port %d\n", res->port_id);
3617                 return;
3618         }
3619
3620         if (!strcmp(res->mode, "set")) {
3621
3622                 if (!strcmp(res->hwsw, "hw"))
3623                         hw = 1;
3624
3625                 if (!strcmp(res->proto, "ip")) {
3626                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3627                 } else if (!strcmp(res->proto, "udp")) {
3628                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3629                 } else if (!strcmp(res->proto, "tcp")) {
3630                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3631                 } else if (!strcmp(res->proto, "sctp")) {
3632                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3633                 } else if (!strcmp(res->proto, "outer-ip")) {
3634                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3635                 }
3636
3637                 if (hw)
3638                         ports[res->port_id].tx_ol_flags |= mask;
3639                 else
3640                         ports[res->port_id].tx_ol_flags &= (~mask);
3641         }
3642         csum_show(res->port_id);
3643 }
3644
3645 cmdline_parse_token_string_t cmd_csum_csum =
3646         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3647                                 csum, "csum");
3648 cmdline_parse_token_string_t cmd_csum_mode =
3649         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3650                                 mode, "set");
3651 cmdline_parse_token_string_t cmd_csum_proto =
3652         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3653                                 proto, "ip#tcp#udp#sctp#outer-ip");
3654 cmdline_parse_token_string_t cmd_csum_hwsw =
3655         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3656                                 hwsw, "hw#sw");
3657 cmdline_parse_token_num_t cmd_csum_portid =
3658         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3659                                 port_id, UINT16);
3660
3661 cmdline_parse_inst_t cmd_csum_set = {
3662         .f = cmd_csum_parsed,
3663         .data = NULL,
3664         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3665                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3666                 "using csum forward engine",
3667         .tokens = {
3668                 (void *)&cmd_csum_csum,
3669                 (void *)&cmd_csum_mode,
3670                 (void *)&cmd_csum_proto,
3671                 (void *)&cmd_csum_hwsw,
3672                 (void *)&cmd_csum_portid,
3673                 NULL,
3674         },
3675 };
3676
3677 cmdline_parse_token_string_t cmd_csum_mode_show =
3678         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3679                                 mode, "show");
3680
3681 cmdline_parse_inst_t cmd_csum_show = {
3682         .f = cmd_csum_parsed,
3683         .data = NULL,
3684         .help_str = "csum show <port_id>: Show checksum offload configuration",
3685         .tokens = {
3686                 (void *)&cmd_csum_csum,
3687                 (void *)&cmd_csum_mode_show,
3688                 (void *)&cmd_csum_portid,
3689                 NULL,
3690         },
3691 };
3692
3693 /* Enable/disable tunnel parsing */
3694 struct cmd_csum_tunnel_result {
3695         cmdline_fixed_string_t csum;
3696         cmdline_fixed_string_t parse;
3697         cmdline_fixed_string_t onoff;
3698         portid_t port_id;
3699 };
3700
3701 static void
3702 cmd_csum_tunnel_parsed(void *parsed_result,
3703                        __attribute__((unused)) struct cmdline *cl,
3704                        __attribute__((unused)) void *data)
3705 {
3706         struct cmd_csum_tunnel_result *res = parsed_result;
3707
3708         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3709                 return;
3710
3711         if (!strcmp(res->onoff, "on"))
3712                 ports[res->port_id].tx_ol_flags |=
3713                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3714         else
3715                 ports[res->port_id].tx_ol_flags &=
3716                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3717
3718         csum_show(res->port_id);
3719 }
3720
3721 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3722         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3723                                 csum, "csum");
3724 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3725         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3726                                 parse, "parse_tunnel");
3727 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3728         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3729                                 onoff, "on#off");
3730 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3731         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3732                                 port_id, UINT16);
3733
3734 cmdline_parse_inst_t cmd_csum_tunnel = {
3735         .f = cmd_csum_tunnel_parsed,
3736         .data = NULL,
3737         .help_str = "csum parse_tunnel on|off <port_id>: "
3738                 "Enable/Disable parsing of tunnels for csum engine",
3739         .tokens = {
3740                 (void *)&cmd_csum_tunnel_csum,
3741                 (void *)&cmd_csum_tunnel_parse,
3742                 (void *)&cmd_csum_tunnel_onoff,
3743                 (void *)&cmd_csum_tunnel_portid,
3744                 NULL,
3745         },
3746 };
3747
3748 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3749 struct cmd_tso_set_result {
3750         cmdline_fixed_string_t tso;
3751         cmdline_fixed_string_t mode;
3752         uint16_t tso_segsz;
3753         portid_t port_id;
3754 };
3755
3756 static void
3757 cmd_tso_set_parsed(void *parsed_result,
3758                        __attribute__((unused)) struct cmdline *cl,
3759                        __attribute__((unused)) void *data)
3760 {
3761         struct cmd_tso_set_result *res = parsed_result;
3762         struct rte_eth_dev_info dev_info;
3763
3764         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3765                 return;
3766
3767         if (!strcmp(res->mode, "set"))
3768                 ports[res->port_id].tso_segsz = res->tso_segsz;
3769
3770         if (ports[res->port_id].tso_segsz == 0)
3771                 printf("TSO for non-tunneled packets is disabled\n");
3772         else
3773                 printf("TSO segment size for non-tunneled packets is %d\n",
3774                         ports[res->port_id].tso_segsz);
3775
3776         /* display warnings if configuration is not supported by the NIC */
3777         rte_eth_dev_info_get(res->port_id, &dev_info);
3778         if ((ports[res->port_id].tso_segsz != 0) &&
3779                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3780                 printf("Warning: TSO enabled but not "
3781                         "supported by port %d\n", res->port_id);
3782         }
3783 }
3784
3785 cmdline_parse_token_string_t cmd_tso_set_tso =
3786         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3787                                 tso, "tso");
3788 cmdline_parse_token_string_t cmd_tso_set_mode =
3789         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3790                                 mode, "set");
3791 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3792         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3793                                 tso_segsz, UINT16);
3794 cmdline_parse_token_num_t cmd_tso_set_portid =
3795         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3796                                 port_id, UINT16);
3797
3798 cmdline_parse_inst_t cmd_tso_set = {
3799         .f = cmd_tso_set_parsed,
3800         .data = NULL,
3801         .help_str = "tso set <tso_segsz> <port_id>: "
3802                 "Set TSO segment size of non-tunneled packets for csum engine "
3803                 "(0 to disable)",
3804         .tokens = {
3805                 (void *)&cmd_tso_set_tso,
3806                 (void *)&cmd_tso_set_mode,
3807                 (void *)&cmd_tso_set_tso_segsz,
3808                 (void *)&cmd_tso_set_portid,
3809                 NULL,
3810         },
3811 };
3812
3813 cmdline_parse_token_string_t cmd_tso_show_mode =
3814         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3815                                 mode, "show");
3816
3817
3818 cmdline_parse_inst_t cmd_tso_show = {
3819         .f = cmd_tso_set_parsed,
3820         .data = NULL,
3821         .help_str = "tso show <port_id>: "
3822                 "Show TSO segment size of non-tunneled packets for csum engine",
3823         .tokens = {
3824                 (void *)&cmd_tso_set_tso,
3825                 (void *)&cmd_tso_show_mode,
3826                 (void *)&cmd_tso_set_portid,
3827                 NULL,
3828         },
3829 };
3830
3831 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3832 struct cmd_tunnel_tso_set_result {
3833         cmdline_fixed_string_t tso;
3834         cmdline_fixed_string_t mode;
3835         uint16_t tso_segsz;
3836         portid_t port_id;
3837 };
3838
3839 static void
3840 check_tunnel_tso_nic_support(portid_t port_id)
3841 {
3842         struct rte_eth_dev_info dev_info;
3843
3844         rte_eth_dev_info_get(port_id, &dev_info);
3845         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3846                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3847                        "supported by port %d\n", port_id);
3848         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3849                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3850                         "supported by port %d\n", port_id);
3851         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3852                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3853                        "supported by port %d\n", port_id);
3854         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3855                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3856                        "supported by port %d\n", port_id);
3857 }
3858
3859 static void
3860 cmd_tunnel_tso_set_parsed(void *parsed_result,
3861                           __attribute__((unused)) struct cmdline *cl,
3862                           __attribute__((unused)) void *data)
3863 {
3864         struct cmd_tunnel_tso_set_result *res = parsed_result;
3865
3866         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3867                 return;
3868
3869         if (!strcmp(res->mode, "set"))
3870                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3871
3872         if (ports[res->port_id].tunnel_tso_segsz == 0)
3873                 printf("TSO for tunneled packets is disabled\n");
3874         else {
3875                 printf("TSO segment size for tunneled packets is %d\n",
3876                         ports[res->port_id].tunnel_tso_segsz);
3877
3878                 /* Below conditions are needed to make it work:
3879                  * (1) tunnel TSO is supported by the NIC;
3880                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3881                  * are recognized;
3882                  * (3) for tunneled pkts with outer L3 of IPv4,
3883                  * "csum set outer-ip" must be set to hw, because after tso,
3884                  * total_len of outer IP header is changed, and the checksum
3885                  * of outer IP header calculated by sw should be wrong; that
3886                  * is not necessary for IPv6 tunneled pkts because there's no
3887                  * checksum in IP header anymore.
3888                  */
3889                 check_tunnel_tso_nic_support(res->port_id);
3890
3891                 if (!(ports[res->port_id].tx_ol_flags &
3892                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3893                         printf("Warning: csum parse_tunnel must be set "
3894                                 "so that tunneled packets are recognized\n");
3895                 if (!(ports[res->port_id].tx_ol_flags &
3896                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3897                         printf("Warning: csum set outer-ip must be set to hw "
3898                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3899         }
3900 }
3901
3902 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3903         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3904                                 tso, "tunnel_tso");
3905 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3906         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3907                                 mode, "set");
3908 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3909         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3910                                 tso_segsz, UINT16);
3911 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3912         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3913                                 port_id, UINT16);
3914
3915 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3916         .f = cmd_tunnel_tso_set_parsed,
3917         .data = NULL,
3918         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3919                 "Set TSO segment size of tunneled packets for csum engine "
3920                 "(0 to disable)",
3921         .tokens = {
3922                 (void *)&cmd_tunnel_tso_set_tso,
3923                 (void *)&cmd_tunnel_tso_set_mode,
3924                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3925                 (void *)&cmd_tunnel_tso_set_portid,
3926                 NULL,
3927         },
3928 };
3929
3930 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3931         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3932                                 mode, "show");
3933
3934
3935 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3936         .f = cmd_tunnel_tso_set_parsed,
3937         .data = NULL,
3938         .help_str = "tunnel_tso show <port_id> "
3939                 "Show TSO segment size of tunneled packets for csum engine",
3940         .tokens = {
3941                 (void *)&cmd_tunnel_tso_set_tso,
3942                 (void *)&cmd_tunnel_tso_show_mode,
3943                 (void *)&cmd_tunnel_tso_set_portid,
3944                 NULL,
3945         },
3946 };
3947
3948 /* *** SET GRO FOR A PORT *** */
3949 struct cmd_gro_enable_result {
3950         cmdline_fixed_string_t cmd_set;
3951         cmdline_fixed_string_t cmd_port;
3952         cmdline_fixed_string_t cmd_keyword;
3953         cmdline_fixed_string_t cmd_onoff;
3954         portid_t cmd_pid;
3955 };
3956
3957 static void
3958 cmd_gro_enable_parsed(void *parsed_result,
3959                 __attribute__((unused)) struct cmdline *cl,
3960                 __attribute__((unused)) void *data)
3961 {
3962         struct cmd_gro_enable_result *res;
3963
3964         res = parsed_result;
3965         if (!strcmp(res->cmd_keyword, "gro"))
3966                 setup_gro(res->cmd_onoff, res->cmd_pid);
3967 }
3968
3969 cmdline_parse_token_string_t cmd_gro_enable_set =
3970         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3971                         cmd_set, "set");
3972 cmdline_parse_token_string_t cmd_gro_enable_port =
3973         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3974                         cmd_keyword, "port");
3975 cmdline_parse_token_num_t cmd_gro_enable_pid =
3976         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3977                         cmd_pid, UINT16);
3978 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3979         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3980                         cmd_keyword, "gro");
3981 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3982         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3983                         cmd_onoff, "on#off");
3984
3985 cmdline_parse_inst_t cmd_gro_enable = {
3986         .f = cmd_gro_enable_parsed,
3987         .data = NULL,
3988         .help_str = "set port <port_id> gro on|off",
3989         .tokens = {
3990                 (void *)&cmd_gro_enable_set,
3991                 (void *)&cmd_gro_enable_port,
3992                 (void *)&cmd_gro_enable_pid,
3993                 (void *)&cmd_gro_enable_keyword,
3994                 (void *)&cmd_gro_enable_onoff,
3995                 NULL,
3996         },
3997 };
3998
3999 /* *** DISPLAY GRO CONFIGURATION *** */
4000 struct cmd_gro_show_result {
4001         cmdline_fixed_string_t cmd_show;
4002         cmdline_fixed_string_t cmd_port;
4003         cmdline_fixed_string_t cmd_keyword;
4004         portid_t cmd_pid;
4005 };
4006
4007 static void
4008 cmd_gro_show_parsed(void *parsed_result,
4009                 __attribute__((unused)) struct cmdline *cl,
4010                 __attribute__((unused)) void *data)
4011 {
4012         struct cmd_gro_show_result *res;
4013
4014         res = parsed_result;
4015         if (!strcmp(res->cmd_keyword, "gro"))
4016                 show_gro(res->cmd_pid);
4017 }
4018
4019 cmdline_parse_token_string_t cmd_gro_show_show =
4020         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4021                         cmd_show, "show");
4022 cmdline_parse_token_string_t cmd_gro_show_port =
4023         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4024                         cmd_port, "port");
4025 cmdline_parse_token_num_t cmd_gro_show_pid =
4026         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4027                         cmd_pid, UINT16);
4028 cmdline_parse_token_string_t cmd_gro_show_keyword =
4029         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4030                         cmd_keyword, "gro");
4031
4032 cmdline_parse_inst_t cmd_gro_show = {
4033         .f = cmd_gro_show_parsed,
4034         .data = NULL,
4035         .help_str = "show port <port_id> gro",
4036         .tokens = {
4037                 (void *)&cmd_gro_show_show,
4038                 (void *)&cmd_gro_show_port,
4039                 (void *)&cmd_gro_show_pid,
4040                 (void *)&cmd_gro_show_keyword,
4041                 NULL,
4042         },
4043 };
4044
4045 /* *** SET FLUSH CYCLES FOR GRO *** */
4046 struct cmd_gro_flush_result {
4047         cmdline_fixed_string_t cmd_set;
4048         cmdline_fixed_string_t cmd_keyword;
4049         cmdline_fixed_string_t cmd_flush;
4050         uint8_t cmd_cycles;
4051 };
4052
4053 static void
4054 cmd_gro_flush_parsed(void *parsed_result,
4055                 __attribute__((unused)) struct cmdline *cl,
4056                 __attribute__((unused)) void *data)
4057 {
4058         struct cmd_gro_flush_result *res;
4059
4060         res = parsed_result;
4061         if ((!strcmp(res->cmd_keyword, "gro")) &&
4062                         (!strcmp(res->cmd_flush, "flush")))
4063                 setup_gro_flush_cycles(res->cmd_cycles);
4064 }
4065
4066 cmdline_parse_token_string_t cmd_gro_flush_set =
4067         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4068                         cmd_set, "set");
4069 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4070         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4071                         cmd_keyword, "gro");
4072 cmdline_parse_token_string_t cmd_gro_flush_flush =
4073         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4074                         cmd_flush, "flush");
4075 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4076         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4077                         cmd_cycles, UINT8);
4078
4079 cmdline_parse_inst_t cmd_gro_flush = {
4080         .f = cmd_gro_flush_parsed,
4081         .data = NULL,
4082         .help_str = "set gro flush <cycles>",
4083         .tokens = {
4084                 (void *)&cmd_gro_flush_set,
4085                 (void *)&cmd_gro_flush_keyword,
4086                 (void *)&cmd_gro_flush_flush,
4087                 (void *)&cmd_gro_flush_cycles,
4088                 NULL,
4089         },
4090 };
4091
4092 /* *** ENABLE/DISABLE GSO *** */
4093 struct cmd_gso_enable_result {
4094         cmdline_fixed_string_t cmd_set;
4095         cmdline_fixed_string_t cmd_port;
4096         cmdline_fixed_string_t cmd_keyword;
4097         cmdline_fixed_string_t cmd_mode;
4098         portid_t cmd_pid;
4099 };
4100
4101 static void
4102 cmd_gso_enable_parsed(void *parsed_result,
4103                 __attribute__((unused)) struct cmdline *cl,
4104                 __attribute__((unused)) void *data)
4105 {
4106         struct cmd_gso_enable_result *res;
4107
4108         res = parsed_result;
4109         if (!strcmp(res->cmd_keyword, "gso"))
4110                 setup_gso(res->cmd_mode, res->cmd_pid);
4111 }
4112
4113 cmdline_parse_token_string_t cmd_gso_enable_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4115                         cmd_set, "set");
4116 cmdline_parse_token_string_t cmd_gso_enable_port =
4117         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4118                         cmd_port, "port");
4119 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4120         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4121                         cmd_keyword, "gso");
4122 cmdline_parse_token_string_t cmd_gso_enable_mode =
4123         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4124                         cmd_mode, "on#off");
4125 cmdline_parse_token_num_t cmd_gso_enable_pid =
4126         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4127                         cmd_pid, UINT16);
4128
4129 cmdline_parse_inst_t cmd_gso_enable = {
4130         .f = cmd_gso_enable_parsed,
4131         .data = NULL,
4132         .help_str = "set port <port_id> gso on|off",
4133         .tokens = {
4134                 (void *)&cmd_gso_enable_set,
4135                 (void *)&cmd_gso_enable_port,
4136                 (void *)&cmd_gso_enable_pid,
4137                 (void *)&cmd_gso_enable_keyword,
4138                 (void *)&cmd_gso_enable_mode,
4139                 NULL,
4140         },
4141 };
4142
4143 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4144 struct cmd_gso_size_result {
4145         cmdline_fixed_string_t cmd_set;
4146         cmdline_fixed_string_t cmd_keyword;
4147         cmdline_fixed_string_t cmd_segsz;
4148         uint16_t cmd_size;
4149 };
4150
4151 static void
4152 cmd_gso_size_parsed(void *parsed_result,
4153                        __attribute__((unused)) struct cmdline *cl,
4154                        __attribute__((unused)) void *data)
4155 {
4156         struct cmd_gso_size_result *res = parsed_result;
4157
4158         if (test_done == 0) {
4159                 printf("Before setting GSO segsz, please first"
4160                                 " stop fowarding\n");
4161                 return;
4162         }
4163
4164         if (!strcmp(res->cmd_keyword, "gso") &&
4165                         !strcmp(res->cmd_segsz, "segsz")) {
4166                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4167                         printf("gso_size should be larger than %zu."
4168                                         " Please input a legal value\n",
4169                                         RTE_GSO_SEG_SIZE_MIN);
4170                 else
4171                         gso_max_segment_size = res->cmd_size;
4172         }
4173 }
4174
4175 cmdline_parse_token_string_t cmd_gso_size_set =
4176         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4177                                 cmd_set, "set");
4178 cmdline_parse_token_string_t cmd_gso_size_keyword =
4179         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4180                                 cmd_keyword, "gso");
4181 cmdline_parse_token_string_t cmd_gso_size_segsz =
4182         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4183                                 cmd_segsz, "segsz");
4184 cmdline_parse_token_num_t cmd_gso_size_size =
4185         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4186                                 cmd_size, UINT16);
4187
4188 cmdline_parse_inst_t cmd_gso_size = {
4189         .f = cmd_gso_size_parsed,
4190         .data = NULL,
4191         .help_str = "set gso segsz <length>",
4192         .tokens = {
4193                 (void *)&cmd_gso_size_set,
4194                 (void *)&cmd_gso_size_keyword,
4195                 (void *)&cmd_gso_size_segsz,
4196                 (void *)&cmd_gso_size_size,
4197                 NULL,
4198         },
4199 };
4200
4201 /* *** SHOW GSO CONFIGURATION *** */
4202 struct cmd_gso_show_result {
4203         cmdline_fixed_string_t cmd_show;
4204         cmdline_fixed_string_t cmd_port;
4205         cmdline_fixed_string_t cmd_keyword;
4206         portid_t cmd_pid;
4207 };
4208
4209 static void
4210 cmd_gso_show_parsed(void *parsed_result,
4211                        __attribute__((unused)) struct cmdline *cl,
4212                        __attribute__((unused)) void *data)
4213 {
4214         struct cmd_gso_show_result *res = parsed_result;
4215
4216         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4217                 printf("invalid port id %u\n", res->cmd_pid);
4218                 return;
4219         }
4220         if (!strcmp(res->cmd_keyword, "gso")) {
4221                 if (gso_ports[res->cmd_pid].enable) {
4222                         printf("Max GSO'd packet size: %uB\n"
4223                                         "Supported GSO types: TCP/IPv4, "
4224                                         "VxLAN with inner TCP/IPv4 packet, "
4225                                         "GRE with inner TCP/IPv4  packet\n",
4226                                         gso_max_segment_size);
4227                 } else
4228                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4229         }
4230 }
4231
4232 cmdline_parse_token_string_t cmd_gso_show_show =
4233 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4234                 cmd_show, "show");
4235 cmdline_parse_token_string_t cmd_gso_show_port =
4236 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4237                 cmd_port, "port");
4238 cmdline_parse_token_string_t cmd_gso_show_keyword =
4239         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4240                                 cmd_keyword, "gso");
4241 cmdline_parse_token_num_t cmd_gso_show_pid =
4242         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4243                                 cmd_pid, UINT16);
4244
4245 cmdline_parse_inst_t cmd_gso_show = {
4246         .f = cmd_gso_show_parsed,
4247         .data = NULL,
4248         .help_str = "show port <port_id> gso",
4249         .tokens = {
4250                 (void *)&cmd_gso_show_show,
4251                 (void *)&cmd_gso_show_port,
4252                 (void *)&cmd_gso_show_pid,
4253                 (void *)&cmd_gso_show_keyword,
4254                 NULL,
4255         },
4256 };
4257
4258 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4259 struct cmd_set_flush_rx {
4260         cmdline_fixed_string_t set;
4261         cmdline_fixed_string_t flush_rx;
4262         cmdline_fixed_string_t mode;
4263 };
4264
4265 static void
4266 cmd_set_flush_rx_parsed(void *parsed_result,
4267                 __attribute__((unused)) struct cmdline *cl,
4268                 __attribute__((unused)) void *data)
4269 {
4270         struct cmd_set_flush_rx *res = parsed_result;
4271         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4272 }
4273
4274 cmdline_parse_token_string_t cmd_setflushrx_set =
4275         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4276                         set, "set");
4277 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4278         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4279                         flush_rx, "flush_rx");
4280 cmdline_parse_token_string_t cmd_setflushrx_mode =
4281         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4282                         mode, "on#off");
4283
4284
4285 cmdline_parse_inst_t cmd_set_flush_rx = {
4286         .f = cmd_set_flush_rx_parsed,
4287         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4288         .data = NULL,
4289         .tokens = {
4290                 (void *)&cmd_setflushrx_set,
4291                 (void *)&cmd_setflushrx_flush_rx,
4292                 (void *)&cmd_setflushrx_mode,
4293                 NULL,
4294         },
4295 };
4296
4297 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4298 struct cmd_set_link_check {
4299         cmdline_fixed_string_t set;
4300         cmdline_fixed_string_t link_check;
4301         cmdline_fixed_string_t mode;
4302 };
4303
4304 static void
4305 cmd_set_link_check_parsed(void *parsed_result,
4306                 __attribute__((unused)) struct cmdline *cl,
4307                 __attribute__((unused)) void *data)
4308 {
4309         struct cmd_set_link_check *res = parsed_result;
4310         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4311 }
4312
4313 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4314         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4315                         set, "set");
4316 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4317         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4318                         link_check, "link_check");
4319 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4320         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4321                         mode, "on#off");
4322
4323
4324 cmdline_parse_inst_t cmd_set_link_check = {
4325         .f = cmd_set_link_check_parsed,
4326         .help_str = "set link_check on|off: Enable/Disable link status check "
4327                     "when starting/stopping a port",
4328         .data = NULL,
4329         .tokens = {
4330                 (void *)&cmd_setlinkcheck_set,
4331                 (void *)&cmd_setlinkcheck_link_check,
4332                 (void *)&cmd_setlinkcheck_mode,
4333                 NULL,
4334         },
4335 };
4336
4337 /* *** SET NIC BYPASS MODE *** */
4338 struct cmd_set_bypass_mode_result {
4339         cmdline_fixed_string_t set;
4340         cmdline_fixed_string_t bypass;
4341         cmdline_fixed_string_t mode;
4342         cmdline_fixed_string_t value;
4343         portid_t port_id;
4344 };
4345
4346 static void
4347 cmd_set_bypass_mode_parsed(void *parsed_result,
4348                 __attribute__((unused)) struct cmdline *cl,
4349                 __attribute__((unused)) void *data)
4350 {
4351         struct cmd_set_bypass_mode_result *res = parsed_result;
4352         portid_t port_id = res->port_id;
4353         int32_t rc = -EINVAL;
4354
4355 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4356         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4357
4358         if (!strcmp(res->value, "bypass"))
4359                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4360         else if (!strcmp(res->value, "isolate"))
4361                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4362         else
4363                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4364
4365         /* Set the bypass mode for the relevant port. */
4366         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4367 #endif
4368         if (rc != 0)
4369                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4370 }
4371
4372 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4374                         set, "set");
4375 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4377                         bypass, "bypass");
4378 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4379         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4380                         mode, "mode");
4381 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4382         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4383                         value, "normal#bypass#isolate");
4384 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4385         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4386                                 port_id, UINT16);
4387
4388 cmdline_parse_inst_t cmd_set_bypass_mode = {
4389         .f = cmd_set_bypass_mode_parsed,
4390         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4391                     "Set the NIC bypass mode for port_id",
4392         .data = NULL,
4393         .tokens = {
4394                 (void *)&cmd_setbypass_mode_set,
4395                 (void *)&cmd_setbypass_mode_bypass,
4396                 (void *)&cmd_setbypass_mode_mode,
4397                 (void *)&cmd_setbypass_mode_value,
4398                 (void *)&cmd_setbypass_mode_port,
4399                 NULL,
4400         },
4401 };
4402
4403 /* *** SET NIC BYPASS EVENT *** */
4404 struct cmd_set_bypass_event_result {
4405         cmdline_fixed_string_t set;
4406         cmdline_fixed_string_t bypass;
4407         cmdline_fixed_string_t event;
4408         cmdline_fixed_string_t event_value;
4409         cmdline_fixed_string_t mode;
4410         cmdline_fixed_string_t mode_value;
4411         portid_t port_id;
4412 };
4413
4414 static void
4415 cmd_set_bypass_event_parsed(void *parsed_result,
4416                 __attribute__((unused)) struct cmdline *cl,
4417                 __attribute__((unused)) void *data)
4418 {
4419         int32_t rc = -EINVAL;
4420         struct cmd_set_bypass_event_result *res = parsed_result;
4421         portid_t port_id = res->port_id;
4422
4423 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4424         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4425         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4426
4427         if (!strcmp(res->event_value, "timeout"))
4428                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4429         else if (!strcmp(res->event_value, "os_on"))
4430                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4431         else if (!strcmp(res->event_value, "os_off"))
4432                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4433         else if (!strcmp(res->event_value, "power_on"))
4434                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4435         else if (!strcmp(res->event_value, "power_off"))
4436                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4437         else
4438                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4439
4440         if (!strcmp(res->mode_value, "bypass"))
4441                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4442         else if (!strcmp(res->mode_value, "isolate"))
4443                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4444         else
4445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4446
4447         /* Set the watchdog timeout. */
4448         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4449
4450                 rc = -EINVAL;
4451                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4452                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4453                                                            bypass_timeout);
4454                 }
4455                 if (rc != 0) {
4456                         printf("Failed to set timeout value %u "
4457                         "for port %d, errto code: %d.\n",
4458                         bypass_timeout, port_id, rc);
4459                 }
4460         }
4461
4462         /* Set the bypass event to transition to bypass mode. */
4463         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4464                                               bypass_mode);
4465 #endif
4466
4467         if (rc != 0)
4468                 printf("\t Failed to set bypass event for port = %d.\n",
4469                        port_id);
4470 }
4471
4472 cmdline_parse_token_string_t cmd_setbypass_event_set =
4473         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4474                         set, "set");
4475 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4476         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4477                         bypass, "bypass");
4478 cmdline_parse_token_string_t cmd_setbypass_event_event =
4479         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4480                         event, "event");
4481 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4482         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4483                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4484 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4485         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4486                         mode, "mode");
4487 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4488         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4489                         mode_value, "normal#bypass#isolate");
4490 cmdline_parse_token_num_t cmd_setbypass_event_port =
4491         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4492                                 port_id, UINT16);
4493
4494 cmdline_parse_inst_t cmd_set_bypass_event = {
4495         .f = cmd_set_bypass_event_parsed,
4496         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4497                 "power_off mode normal|bypass|isolate <port_id>: "
4498                 "Set the NIC bypass event mode for port_id",
4499         .data = NULL,
4500         .tokens = {
4501                 (void *)&cmd_setbypass_event_set,
4502                 (void *)&cmd_setbypass_event_bypass,
4503                 (void *)&cmd_setbypass_event_event,
4504                 (void *)&cmd_setbypass_event_event_value,
4505                 (void *)&cmd_setbypass_event_mode,
4506                 (void *)&cmd_setbypass_event_mode_value,
4507                 (void *)&cmd_setbypass_event_port,
4508                 NULL,
4509         },
4510 };
4511
4512
4513 /* *** SET NIC BYPASS TIMEOUT *** */
4514 struct cmd_set_bypass_timeout_result {
4515         cmdline_fixed_string_t set;
4516         cmdline_fixed_string_t bypass;
4517         cmdline_fixed_string_t timeout;
4518         cmdline_fixed_string_t value;
4519 };
4520
4521 static void
4522 cmd_set_bypass_timeout_parsed(void *parsed_result,
4523                 __attribute__((unused)) struct cmdline *cl,
4524                 __attribute__((unused)) void *data)
4525 {
4526         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4527
4528 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4529         if (!strcmp(res->value, "1.5"))
4530                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4531         else if (!strcmp(res->value, "2"))
4532                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4533         else if (!strcmp(res->value, "3"))
4534                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4535         else if (!strcmp(res->value, "4"))
4536                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4537         else if (!strcmp(res->value, "8"))
4538                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4539         else if (!strcmp(res->value, "16"))
4540                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4541         else if (!strcmp(res->value, "32"))
4542                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4543         else
4544                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4545 #endif
4546 }
4547
4548 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4550                         set, "set");
4551 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4553                         bypass, "bypass");
4554 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4556                         timeout, "timeout");
4557 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4559                         value, "0#1.5#2#3#4#8#16#32");
4560
4561 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4562         .f = cmd_set_bypass_timeout_parsed,
4563         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4564                 "Set the NIC bypass watchdog timeout in seconds",
4565         .data = NULL,
4566         .tokens = {
4567                 (void *)&cmd_setbypass_timeout_set,
4568                 (void *)&cmd_setbypass_timeout_bypass,
4569                 (void *)&cmd_setbypass_timeout_timeout,
4570                 (void *)&cmd_setbypass_timeout_value,
4571                 NULL,
4572         },
4573 };
4574
4575 /* *** SHOW NIC BYPASS MODE *** */
4576 struct cmd_show_bypass_config_result {
4577         cmdline_fixed_string_t show;
4578         cmdline_fixed_string_t bypass;
4579         cmdline_fixed_string_t config;
4580         portid_t port_id;
4581 };
4582
4583 static void
4584 cmd_show_bypass_config_parsed(void *parsed_result,
4585                 __attribute__((unused)) struct cmdline *cl,
4586                 __attribute__((unused)) void *data)
4587 {
4588         struct cmd_show_bypass_config_result *res = parsed_result;
4589         portid_t port_id = res->port_id;
4590         int rc = -EINVAL;
4591 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4592         uint32_t event_mode;
4593         uint32_t bypass_mode;
4594         uint32_t timeout = bypass_timeout;
4595         int i;
4596
4597         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4598                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4599         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4600                 {"UNKNOWN", "normal", "bypass", "isolate"};
4601         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4602                 "NONE",
4603                 "OS/board on",
4604                 "power supply on",
4605                 "OS/board off",
4606                 "power supply off",
4607                 "timeout"};
4608         int num_events = (sizeof events) / (sizeof events[0]);
4609
4610         /* Display the bypass mode.*/
4611         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4612                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4613                 return;
4614         }
4615         else {
4616                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4617                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4618
4619                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4620         }
4621
4622         /* Display the bypass timeout.*/
4623         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4624                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4625
4626         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4627
4628         /* Display the bypass events and associated modes. */
4629         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4630
4631                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4632                         printf("\tFailed to get bypass mode for event = %s\n",
4633                                 events[i]);
4634                 } else {
4635                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4636                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4637
4638                         printf("\tbypass event: %-16s = %s\n", events[i],
4639                                 modes[event_mode]);
4640                 }
4641         }
4642 #endif
4643         if (rc != 0)
4644                 printf("\tFailed to get bypass configuration for port = %d\n",
4645                        port_id);
4646 }
4647
4648 cmdline_parse_token_string_t cmd_showbypass_config_show =
4649         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4650                         show, "show");
4651 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4652         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4653                         bypass, "bypass");
4654 cmdline_parse_token_string_t cmd_showbypass_config_config =
4655         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4656                         config, "config");
4657 cmdline_parse_token_num_t cmd_showbypass_config_port =
4658         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4659                                 port_id, UINT16);
4660
4661 cmdline_parse_inst_t cmd_show_bypass_config = {
4662         .f = cmd_show_bypass_config_parsed,
4663         .help_str = "show bypass config <port_id>: "
4664                     "Show the NIC bypass config for port_id",
4665         .data = NULL,
4666         .tokens = {
4667                 (void *)&cmd_showbypass_config_show,
4668                 (void *)&cmd_showbypass_config_bypass,
4669                 (void *)&cmd_showbypass_config_config,
4670                 (void *)&cmd_showbypass_config_port,
4671                 NULL,
4672         },
4673 };
4674
4675 #ifdef RTE_LIBRTE_PMD_BOND
4676 /* *** SET BONDING MODE *** */
4677 struct cmd_set_bonding_mode_result {
4678         cmdline_fixed_string_t set;
4679         cmdline_fixed_string_t bonding;
4680         cmdline_fixed_string_t mode;
4681         uint8_t value;
4682         portid_t port_id;
4683 };
4684
4685 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4686                 __attribute__((unused))  struct cmdline *cl,
4687                 __attribute__((unused)) void *data)
4688 {
4689         struct cmd_set_bonding_mode_result *res = parsed_result;
4690         portid_t port_id = res->port_id;
4691
4692         /* Set the bonding mode for the relevant port. */
4693         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4694                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4695 }
4696
4697 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4698 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4699                 set, "set");
4700 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4701 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4702                 bonding, "bonding");
4703 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4704 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4705                 mode, "mode");
4706 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4707 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4708                 value, UINT8);
4709 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4710 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4711                 port_id, UINT16);
4712
4713 cmdline_parse_inst_t cmd_set_bonding_mode = {
4714                 .f = cmd_set_bonding_mode_parsed,
4715                 .help_str = "set bonding mode <mode_value> <port_id>: "
4716                         "Set the bonding mode for port_id",
4717                 .data = NULL,
4718                 .tokens = {
4719                                 (void *) &cmd_setbonding_mode_set,
4720                                 (void *) &cmd_setbonding_mode_bonding,
4721                                 (void *) &cmd_setbonding_mode_mode,
4722                                 (void *) &cmd_setbonding_mode_value,
4723                                 (void *) &cmd_setbonding_mode_port,
4724                                 NULL
4725                 }
4726 };
4727
4728 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4729 struct cmd_set_bonding_lacp_dedicated_queues_result {
4730         cmdline_fixed_string_t set;
4731         cmdline_fixed_string_t bonding;
4732         cmdline_fixed_string_t lacp;
4733         cmdline_fixed_string_t dedicated_queues;
4734         portid_t port_id;
4735         cmdline_fixed_string_t mode;
4736 };
4737
4738 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4739                 __attribute__((unused))  struct cmdline *cl,
4740                 __attribute__((unused)) void *data)
4741 {
4742         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4743         portid_t port_id = res->port_id;
4744         struct rte_port *port;
4745
4746         port = &ports[port_id];
4747
4748         /** Check if the port is not started **/
4749         if (port->port_status != RTE_PORT_STOPPED) {
4750                 printf("Please stop port %d first\n", port_id);
4751                 return;
4752         }
4753
4754         if (!strcmp(res->mode, "enable")) {
4755                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4756                         printf("Dedicate queues for LACP control packets"
4757                                         " enabled\n");
4758                 else
4759                         printf("Enabling dedicate queues for LACP control "
4760                                         "packets on port %d failed\n", port_id);
4761         } else if (!strcmp(res->mode, "disable")) {
4762                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4763                         printf("Dedicated queues for LACP control packets "
4764                                         "disabled\n");
4765                 else
4766                         printf("Disabling dedicated queues for LACP control "
4767                                         "traffic on port %d failed\n", port_id);
4768         }
4769 }
4770
4771 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4772 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4773                 set, "set");
4774 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4775 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4776                 bonding, "bonding");
4777 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4778 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4779                 lacp, "lacp");
4780 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4781 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4782                 dedicated_queues, "dedicated_queues");
4783 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4784 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4785                 port_id, UINT16);
4786 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4787 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4788                 mode, "enable#disable");
4789
4790 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4791                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4792                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4793                         "enable|disable: "
4794                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4795                 .data = NULL,
4796                 .tokens = {
4797                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4798                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4799                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4800                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4801                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4802                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4803                         NULL
4804                 }
4805 };
4806
4807 /* *** SET BALANCE XMIT POLICY *** */
4808 struct cmd_set_bonding_balance_xmit_policy_result {
4809         cmdline_fixed_string_t set;
4810         cmdline_fixed_string_t bonding;
4811         cmdline_fixed_string_t balance_xmit_policy;
4812         portid_t port_id;
4813         cmdline_fixed_string_t policy;
4814 };
4815
4816 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4817                 __attribute__((unused))  struct cmdline *cl,
4818                 __attribute__((unused)) void *data)
4819 {
4820         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4821         portid_t port_id = res->port_id;
4822         uint8_t policy;
4823
4824         if (!strcmp(res->policy, "l2")) {
4825                 policy = BALANCE_XMIT_POLICY_LAYER2;
4826         } else if (!strcmp(res->policy, "l23")) {
4827                 policy = BALANCE_XMIT_POLICY_LAYER23;
4828         } else if (!strcmp(res->policy, "l34")) {
4829                 policy = BALANCE_XMIT_POLICY_LAYER34;
4830         } else {
4831                 printf("\t Invalid xmit policy selection");
4832                 return;
4833         }
4834
4835         /* Set the bonding mode for the relevant port. */
4836         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4837                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4838                                 port_id);
4839         }
4840 }
4841
4842 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4843 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4844                 set, "set");
4845 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4847                 bonding, "bonding");
4848 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4849 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4850                 balance_xmit_policy, "balance_xmit_policy");
4851 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4852 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4853                 port_id, UINT16);
4854 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4855 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4856                 policy, "l2#l23#l34");
4857
4858 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4859                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4860                 .help_str = "set bonding balance_xmit_policy <port_id> "
4861                         "l2|l23|l34: "
4862                         "Set the bonding balance_xmit_policy for port_id",
4863                 .data = NULL,
4864                 .tokens = {
4865                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4866                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4867                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4868                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4869                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4870                                 NULL
4871                 }
4872 };
4873
4874 /* *** SHOW NIC BONDING CONFIGURATION *** */
4875 struct cmd_show_bonding_config_result {
4876         cmdline_fixed_string_t show;
4877         cmdline_fixed_string_t bonding;
4878         cmdline_fixed_string_t config;
4879         portid_t port_id;
4880 };
4881
4882 static void cmd_show_bonding_config_parsed(void *parsed_result,
4883                 __attribute__((unused))  struct cmdline *cl,
4884                 __attribute__((unused)) void *data)
4885 {
4886         struct cmd_show_bonding_config_result *res = parsed_result;
4887         int bonding_mode, agg_mode;
4888         portid_t slaves[RTE_MAX_ETHPORTS];
4889         int num_slaves, num_active_slaves;
4890         int primary_id;
4891         int i;
4892         portid_t port_id = res->port_id;
4893
4894         /* Display the bonding mode.*/
4895         bonding_mode = rte_eth_bond_mode_get(port_id);
4896         if (bonding_mode < 0) {
4897                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4898                 return;
4899         } else
4900                 printf("\tBonding mode: %d\n", bonding_mode);
4901
4902         if (bonding_mode == BONDING_MODE_BALANCE) {
4903                 int balance_xmit_policy;
4904
4905                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4906                 if (balance_xmit_policy < 0) {
4907                         printf("\tFailed to get balance xmit policy for port = %d\n",
4908                                         port_id);
4909                         return;
4910                 } else {
4911                         printf("\tBalance Xmit Policy: ");
4912
4913                         switch (balance_xmit_policy) {
4914                         case BALANCE_XMIT_POLICY_LAYER2:
4915                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4916                                 break;
4917                         case BALANCE_XMIT_POLICY_LAYER23:
4918                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4919                                 break;
4920                         case BALANCE_XMIT_POLICY_LAYER34:
4921                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4922                                 break;
4923                         }
4924                         printf("\n");
4925                 }
4926         }
4927
4928         if (bonding_mode == BONDING_MODE_8023AD) {
4929                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4930                 printf("\tIEEE802.3AD Aggregator Mode: ");
4931                 switch (agg_mode) {
4932                 case AGG_BANDWIDTH:
4933                         printf("bandwidth");
4934                         break;
4935                 case AGG_STABLE:
4936                         printf("stable");
4937                         break;
4938                 case AGG_COUNT:
4939                         printf("count");
4940                         break;
4941                 }
4942                 printf("\n");
4943         }
4944
4945         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4946
4947         if (num_slaves < 0) {
4948                 printf("\tFailed to get slave list for port = %d\n", port_id);
4949                 return;
4950         }
4951         if (num_slaves > 0) {
4952                 printf("\tSlaves (%d): [", num_slaves);
4953                 for (i = 0; i < num_slaves - 1; i++)
4954                         printf("%d ", slaves[i]);
4955
4956                 printf("%d]\n", slaves[num_slaves - 1]);
4957         } else {
4958                 printf("\tSlaves: []\n");
4959
4960         }
4961
4962         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4963                         RTE_MAX_ETHPORTS);
4964
4965         if (num_active_slaves < 0) {
4966                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4967                 return;
4968         }
4969         if (num_active_slaves > 0) {
4970                 printf("\tActive Slaves (%d): [", num_active_slaves);
4971                 for (i = 0; i < num_active_slaves - 1; i++)
4972                         printf("%d ", slaves[i]);
4973
4974                 printf("%d]\n", slaves[num_active_slaves - 1]);
4975
4976         } else {
4977                 printf("\tActive Slaves: []\n");
4978
4979         }
4980
4981         primary_id = rte_eth_bond_primary_get(port_id);
4982         if (primary_id < 0) {
4983                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4984                 return;
4985         } else
4986                 printf("\tPrimary: [%d]\n", primary_id);
4987
4988 }
4989
4990 cmdline_parse_token_string_t cmd_showbonding_config_show =
4991 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4992                 show, "show");
4993 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4994 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4995                 bonding, "bonding");
4996 cmdline_parse_token_string_t cmd_showbonding_config_config =
4997 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4998                 config, "config");
4999 cmdline_parse_token_num_t cmd_showbonding_config_port =
5000 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5001                 port_id, UINT16);
5002
5003 cmdline_parse_inst_t cmd_show_bonding_config = {
5004                 .f = cmd_show_bonding_config_parsed,
5005                 .help_str = "show bonding config <port_id>: "
5006                         "Show the bonding config for port_id",
5007                 .data = NULL,
5008                 .tokens = {
5009                                 (void *)&cmd_showbonding_config_show,
5010                                 (void *)&cmd_showbonding_config_bonding,
5011                                 (void *)&cmd_showbonding_config_config,
5012                                 (void *)&cmd_showbonding_config_port,
5013                                 NULL
5014                 }
5015 };
5016
5017 /* *** SET BONDING PRIMARY *** */
5018 struct cmd_set_bonding_primary_result {
5019         cmdline_fixed_string_t set;
5020         cmdline_fixed_string_t bonding;
5021         cmdline_fixed_string_t primary;
5022         portid_t slave_id;
5023         portid_t port_id;
5024 };
5025
5026 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5027                 __attribute__((unused))  struct cmdline *cl,
5028                 __attribute__((unused)) void *data)
5029 {
5030         struct cmd_set_bonding_primary_result *res = parsed_result;
5031         portid_t master_port_id = res->port_id;
5032         portid_t slave_port_id = res->slave_id;
5033
5034         /* Set the primary slave for a bonded device. */
5035         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5036                 printf("\t Failed to set primary slave for port = %d.\n",
5037                                 master_port_id);
5038                 return;
5039         }
5040         init_port_config();
5041 }
5042
5043 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5044 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5045                 set, "set");
5046 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5048                 bonding, "bonding");
5049 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5051                 primary, "primary");
5052 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5053 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5054                 slave_id, UINT16);
5055 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5056 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5057                 port_id, UINT16);
5058
5059 cmdline_parse_inst_t cmd_set_bonding_primary = {
5060                 .f = cmd_set_bonding_primary_parsed,
5061                 .help_str = "set bonding primary <slave_id> <port_id>: "
5062                         "Set the primary slave for port_id",
5063                 .data = NULL,
5064                 .tokens = {
5065                                 (void *)&cmd_setbonding_primary_set,
5066                                 (void *)&cmd_setbonding_primary_bonding,
5067                                 (void *)&cmd_setbonding_primary_primary,
5068                                 (void *)&cmd_setbonding_primary_slave,
5069                                 (void *)&cmd_setbonding_primary_port,
5070                                 NULL
5071                 }
5072 };
5073
5074 /* *** ADD SLAVE *** */
5075 struct cmd_add_bonding_slave_result {
5076         cmdline_fixed_string_t add;
5077         cmdline_fixed_string_t bonding;
5078         cmdline_fixed_string_t slave;
5079         portid_t slave_id;
5080         portid_t port_id;
5081 };
5082
5083 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5084                 __attribute__((unused))  struct cmdline *cl,
5085                 __attribute__((unused)) void *data)
5086 {
5087         struct cmd_add_bonding_slave_result *res = parsed_result;
5088         portid_t master_port_id = res->port_id;
5089         portid_t slave_port_id = res->slave_id;
5090
5091         /* add the slave for a bonded device. */
5092         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5093                 printf("\t Failed to add slave %d to master port = %d.\n",
5094                                 slave_port_id, master_port_id);
5095                 return;
5096         }
5097         init_port_config();
5098         set_port_slave_flag(slave_port_id);
5099 }
5100
5101 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5102 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5103                 add, "add");
5104 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5105 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5106                 bonding, "bonding");
5107 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5108 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5109                 slave, "slave");
5110 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5111 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5112                 slave_id, UINT16);
5113 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5114 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5115                 port_id, UINT16);
5116
5117 cmdline_parse_inst_t cmd_add_bonding_slave = {
5118                 .f = cmd_add_bonding_slave_parsed,
5119                 .help_str = "add bonding slave <slave_id> <port_id>: "
5120                         "Add a slave device to a bonded device",
5121                 .data = NULL,
5122                 .tokens = {
5123                                 (void *)&cmd_addbonding_slave_add,
5124                                 (void *)&cmd_addbonding_slave_bonding,
5125                                 (void *)&cmd_addbonding_slave_slave,
5126                                 (void *)&cmd_addbonding_slave_slaveid,
5127                                 (void *)&cmd_addbonding_slave_port,
5128                                 NULL
5129                 }
5130 };
5131
5132 /* *** REMOVE SLAVE *** */
5133 struct cmd_remove_bonding_slave_result {
5134         cmdline_fixed_string_t remove;
5135         cmdline_fixed_string_t bonding;
5136         cmdline_fixed_string_t slave;
5137         portid_t slave_id;
5138         portid_t port_id;
5139 };
5140
5141 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5142                 __attribute__((unused))  struct cmdline *cl,
5143                 __attribute__((unused)) void *data)
5144 {
5145         struct cmd_remove_bonding_slave_result *res = parsed_result;
5146         portid_t master_port_id = res->port_id;
5147         portid_t slave_port_id = res->slave_id;
5148
5149         /* remove the slave from a bonded device. */
5150         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5151                 printf("\t Failed to remove slave %d from master port = %d.\n",
5152                                 slave_port_id, master_port_id);
5153                 return;
5154         }
5155         init_port_config();
5156         clear_port_slave_flag(slave_port_id);
5157 }
5158
5159 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5160                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5161                                 remove, "remove");
5162 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5163                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5164                                 bonding, "bonding");
5165 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5166                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5167                                 slave, "slave");
5168 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5169                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5170                                 slave_id, UINT16);
5171 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5172                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5173                                 port_id, UINT16);
5174
5175 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5176                 .f = cmd_remove_bonding_slave_parsed,
5177                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5178                         "Remove a slave device from a bonded device",
5179                 .data = NULL,
5180                 .tokens = {
5181                                 (void *)&cmd_removebonding_slave_remove,
5182                                 (void *)&cmd_removebonding_slave_bonding,
5183                                 (void *)&cmd_removebonding_slave_slave,
5184                                 (void *)&cmd_removebonding_slave_slaveid,
5185                                 (void *)&cmd_removebonding_slave_port,
5186                                 NULL
5187                 }
5188 };
5189
5190 /* *** CREATE BONDED DEVICE *** */
5191 struct cmd_create_bonded_device_result {
5192         cmdline_fixed_string_t create;
5193         cmdline_fixed_string_t bonded;
5194         cmdline_fixed_string_t device;
5195         uint8_t mode;
5196         uint8_t socket;
5197 };
5198
5199 static int bond_dev_num = 0;
5200
5201 static void cmd_create_bonded_device_parsed(void *parsed_result,
5202                 __attribute__((unused))  struct cmdline *cl,
5203                 __attribute__((unused)) void *data)
5204 {
5205         struct cmd_create_bonded_device_result *res = parsed_result;
5206         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5207         int port_id;
5208
5209         if (test_done == 0) {
5210                 printf("Please stop forwarding first\n");
5211                 return;
5212         }
5213
5214         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5215                         bond_dev_num++);
5216
5217         /* Create a new bonded device. */
5218         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5219         if (port_id < 0) {
5220                 printf("\t Failed to create bonded device.\n");
5221                 return;
5222         } else {
5223                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5224                                 port_id);
5225
5226                 /* Update number of ports */
5227                 nb_ports = rte_eth_dev_count();
5228                 reconfig(port_id, res->socket);
5229                 rte_eth_promiscuous_enable(port_id);
5230         }
5231
5232 }
5233
5234 cmdline_parse_token_string_t cmd_createbonded_device_create =
5235                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5236                                 create, "create");
5237 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5238                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5239                                 bonded, "bonded");
5240 cmdline_parse_token_string_t cmd_createbonded_device_device =
5241                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5242                                 device, "device");
5243 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5244                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5245                                 mode, UINT8);
5246 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5247                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5248                                 socket, UINT8);
5249
5250 cmdline_parse_inst_t cmd_create_bonded_device = {
5251                 .f = cmd_create_bonded_device_parsed,
5252                 .help_str = "create bonded device <mode> <socket>: "
5253                         "Create a new bonded device with specific bonding mode and socket",
5254                 .data = NULL,
5255                 .tokens = {
5256                                 (void *)&cmd_createbonded_device_create,
5257                                 (void *)&cmd_createbonded_device_bonded,
5258                                 (void *)&cmd_createbonded_device_device,
5259                                 (void *)&cmd_createbonded_device_mode,
5260                                 (void *)&cmd_createbonded_device_socket,
5261                                 NULL
5262                 }
5263 };
5264
5265 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5266 struct cmd_set_bond_mac_addr_result {
5267         cmdline_fixed_string_t set;
5268         cmdline_fixed_string_t bonding;
5269         cmdline_fixed_string_t mac_addr;
5270         uint16_t port_num;
5271         struct ether_addr address;
5272 };
5273
5274 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5275                 __attribute__((unused))  struct cmdline *cl,
5276                 __attribute__((unused)) void *data)
5277 {
5278         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5279         int ret;
5280
5281         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5282                 return;
5283
5284         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5285
5286         /* check the return value and print it if is < 0 */
5287         if (ret < 0)
5288                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5289 }
5290
5291 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5292                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5293 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5294                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5295                                 "bonding");
5296 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5297                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5298                                 "mac_addr");
5299 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5300                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5301                                 port_num, UINT16);
5302 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5303                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5304
5305 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5306                 .f = cmd_set_bond_mac_addr_parsed,
5307                 .data = (void *) 0,
5308                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5309                 .tokens = {
5310                                 (void *)&cmd_set_bond_mac_addr_set,
5311                                 (void *)&cmd_set_bond_mac_addr_bonding,
5312                                 (void *)&cmd_set_bond_mac_addr_mac,
5313                                 (void *)&cmd_set_bond_mac_addr_portnum,
5314                                 (void *)&cmd_set_bond_mac_addr_addr,
5315                                 NULL
5316                 }
5317 };
5318
5319
5320 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5321 struct cmd_set_bond_mon_period_result {
5322         cmdline_fixed_string_t set;
5323         cmdline_fixed_string_t bonding;
5324         cmdline_fixed_string_t mon_period;
5325         uint16_t port_num;
5326         uint32_t period_ms;
5327 };
5328
5329 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5330                 __attribute__((unused))  struct cmdline *cl,
5331                 __attribute__((unused)) void *data)
5332 {
5333         struct cmd_set_bond_mon_period_result *res = parsed_result;
5334         int ret;
5335
5336         if (res->port_num >= nb_ports) {
5337                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5338                 return;
5339         }
5340
5341         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5342
5343         /* check the return value and print it if is < 0 */
5344         if (ret < 0)
5345                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5346 }
5347
5348 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5349                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5350                                 set, "set");
5351 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5352                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5353                                 bonding, "bonding");
5354 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5355                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5356                                 mon_period,     "mon_period");
5357 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5358                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5359                                 port_num, UINT16);
5360 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5361                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5362                                 period_ms, UINT32);
5363
5364 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5365                 .f = cmd_set_bond_mon_period_parsed,
5366                 .data = (void *) 0,
5367                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5368                 .tokens = {
5369                                 (void *)&cmd_set_bond_mon_period_set,
5370                                 (void *)&cmd_set_bond_mon_period_bonding,
5371                                 (void *)&cmd_set_bond_mon_period_mon_period,
5372                                 (void *)&cmd_set_bond_mon_period_portnum,
5373                                 (void *)&cmd_set_bond_mon_period_period_ms,
5374                                 NULL
5375                 }
5376 };
5377
5378
5379
5380 struct cmd_set_bonding_agg_mode_policy_result {
5381         cmdline_fixed_string_t set;
5382         cmdline_fixed_string_t bonding;
5383         cmdline_fixed_string_t agg_mode;
5384         uint16_t port_num;
5385         cmdline_fixed_string_t policy;
5386 };
5387
5388
5389 static void
5390 cmd_set_bonding_agg_mode(void *parsed_result,
5391                 __attribute__((unused)) struct cmdline *cl,
5392                 __attribute__((unused)) void *data)
5393 {
5394         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5395         uint8_t policy = AGG_BANDWIDTH;
5396
5397         if (res->port_num >= nb_ports) {
5398                 printf("Port id %d must be less than %d\n",
5399                                 res->port_num, nb_ports);
5400                 return;
5401         }
5402
5403         if (!strcmp(res->policy, "bandwidth"))
5404                 policy = AGG_BANDWIDTH;
5405         else if (!strcmp(res->policy, "stable"))
5406                 policy = AGG_STABLE;
5407         else if (!strcmp(res->policy, "count"))
5408                 policy = AGG_COUNT;
5409
5410         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5411 }
5412
5413
5414 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5415         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5416                                 set, "set");
5417 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5418         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5419                                 bonding, "bonding");
5420
5421 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5422         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5423                                 agg_mode, "agg_mode");
5424
5425 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5426         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5427                                 port_num, UINT16);
5428
5429 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5430         TOKEN_STRING_INITIALIZER(
5431                         struct cmd_set_bonding_balance_xmit_policy_result,
5432                 policy, "stable#bandwidth#count");
5433
5434 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5435         .f = cmd_set_bonding_agg_mode,
5436         .data = (void *) 0,
5437         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5438         .tokens = {
5439                         (void *)&cmd_set_bonding_agg_mode_set,
5440                         (void *)&cmd_set_bonding_agg_mode_bonding,
5441                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5442                         (void *)&cmd_set_bonding_agg_mode_portnum,
5443                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5444                         NULL
5445                 }
5446 };
5447
5448
5449 #endif /* RTE_LIBRTE_PMD_BOND */
5450
5451 /* *** SET FORWARDING MODE *** */
5452 struct cmd_set_fwd_mode_result {
5453         cmdline_fixed_string_t set;
5454         cmdline_fixed_string_t fwd;
5455         cmdline_fixed_string_t mode;
5456 };
5457
5458 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5459                                     __attribute__((unused)) struct cmdline *cl,
5460                                     __attribute__((unused)) void *data)
5461 {
5462         struct cmd_set_fwd_mode_result *res = parsed_result;
5463
5464         retry_enabled = 0;
5465         set_pkt_forwarding_mode(res->mode);
5466 }
5467
5468 cmdline_parse_token_string_t cmd_setfwd_set =
5469         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5470 cmdline_parse_token_string_t cmd_setfwd_fwd =
5471         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5472 cmdline_parse_token_string_t cmd_setfwd_mode =
5473         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5474                 "" /* defined at init */);
5475
5476 cmdline_parse_inst_t cmd_set_fwd_mode = {
5477         .f = cmd_set_fwd_mode_parsed,
5478         .data = NULL,
5479         .help_str = NULL, /* defined at init */
5480         .tokens = {
5481                 (void *)&cmd_setfwd_set,
5482                 (void *)&cmd_setfwd_fwd,
5483                 (void *)&cmd_setfwd_mode,
5484                 NULL,
5485         },
5486 };
5487
5488 static void cmd_set_fwd_mode_init(void)
5489 {
5490         char *modes, *c;
5491         static char token[128];
5492         static char help[256];
5493         cmdline_parse_token_string_t *token_struct;
5494
5495         modes = list_pkt_forwarding_modes();
5496         snprintf(help, sizeof(help), "set fwd %s: "
5497                 "Set packet forwarding mode", modes);
5498         cmd_set_fwd_mode.help_str = help;
5499
5500         /* string token separator is # */
5501         for (c = token; *modes != '\0'; modes++)
5502                 if (*modes == '|')
5503                         *c++ = '#';
5504                 else
5505                         *c++ = *modes;
5506         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5507         token_struct->string_data.str = token;
5508 }
5509
5510 /* *** SET RETRY FORWARDING MODE *** */
5511 struct cmd_set_fwd_retry_mode_result {
5512         cmdline_fixed_string_t set;
5513         cmdline_fixed_string_t fwd;
5514         cmdline_fixed_string_t mode;
5515         cmdline_fixed_string_t retry;
5516 };
5517
5518 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5519                             __attribute__((unused)) struct cmdline *cl,
5520                             __attribute__((unused)) void *data)
5521 {
5522         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5523
5524         retry_enabled = 1;
5525         set_pkt_forwarding_mode(res->mode);
5526 }
5527
5528 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5530                         set, "set");
5531 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5532         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5533                         fwd, "fwd");
5534 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5535         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5536                         mode,
5537                 "" /* defined at init */);
5538 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5539         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5540                         retry, "retry");
5541
5542 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5543         .f = cmd_set_fwd_retry_mode_parsed,
5544         .data = NULL,
5545         .help_str = NULL, /* defined at init */
5546         .tokens = {
5547                 (void *)&cmd_setfwd_retry_set,
5548                 (void *)&cmd_setfwd_retry_fwd,
5549                 (void *)&cmd_setfwd_retry_mode,
5550                 (void *)&cmd_setfwd_retry_retry,
5551                 NULL,
5552         },
5553 };
5554
5555 static void cmd_set_fwd_retry_mode_init(void)
5556 {
5557         char *modes, *c;
5558         static char token[128];
5559         static char help[256];
5560         cmdline_parse_token_string_t *token_struct;
5561
5562         modes = list_pkt_forwarding_retry_modes();
5563         snprintf(help, sizeof(help), "set fwd %s retry: "
5564                 "Set packet forwarding mode with retry", modes);
5565         cmd_set_fwd_retry_mode.help_str = help;
5566
5567         /* string token separator is # */
5568         for (c = token; *modes != '\0'; modes++)
5569                 if (*modes == '|')
5570                         *c++ = '#';
5571                 else
5572                         *c++ = *modes;
5573         token_struct = (cmdline_parse_token_string_t *)
5574                 cmd_set_fwd_retry_mode.tokens[2];
5575         token_struct->string_data.str = token;
5576 }
5577
5578 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5579 struct cmd_set_burst_tx_retry_result {
5580         cmdline_fixed_string_t set;
5581         cmdline_fixed_string_t burst;
5582         cmdline_fixed_string_t tx;
5583         cmdline_fixed_string_t delay;
5584         uint32_t time;
5585         cmdline_fixed_string_t retry;
5586         uint32_t retry_num;
5587 };
5588
5589 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5590                                         __attribute__((unused)) struct cmdline *cl,
5591                                         __attribute__((unused)) void *data)
5592 {
5593         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5594
5595         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5596                 && !strcmp(res->tx, "tx")) {
5597                 if (!strcmp(res->delay, "delay"))
5598                         burst_tx_delay_time = res->time;
5599                 if (!strcmp(res->retry, "retry"))
5600                         burst_tx_retry_num = res->retry_num;
5601         }
5602
5603 }
5604
5605 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5606         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5607 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5608         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5609                                  "burst");
5610 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5611         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5612 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5614 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5615         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5616 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5617         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5618 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5619         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5620
5621 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5622         .f = cmd_set_burst_tx_retry_parsed,
5623         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5624         .tokens = {
5625                 (void *)&cmd_set_burst_tx_retry_set,
5626                 (void *)&cmd_set_burst_tx_retry_burst,
5627                 (void *)&cmd_set_burst_tx_retry_tx,
5628                 (void *)&cmd_set_burst_tx_retry_delay,
5629                 (void *)&cmd_set_burst_tx_retry_time,
5630                 (void *)&cmd_set_burst_tx_retry_retry,
5631                 (void *)&cmd_set_burst_tx_retry_retry_num,
5632                 NULL,
5633         },
5634 };
5635
5636 /* *** SET PROMISC MODE *** */
5637 struct cmd_set_promisc_mode_result {
5638         cmdline_fixed_string_t set;
5639         cmdline_fixed_string_t promisc;
5640         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5641         uint16_t port_num;               /* valid if "allports" argument == 0 */
5642         cmdline_fixed_string_t mode;
5643 };
5644
5645 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5646                                         __attribute__((unused)) struct cmdline *cl,
5647                                         void *allports)
5648 {
5649         struct cmd_set_promisc_mode_result *res = parsed_result;
5650         int enable;
5651         portid_t i;
5652
5653         if (!strcmp(res->mode, "on"))
5654                 enable = 1;
5655         else
5656                 enable = 0;
5657
5658         /* all ports */
5659         if (allports) {
5660                 RTE_ETH_FOREACH_DEV(i) {
5661                         if (enable)
5662                                 rte_eth_promiscuous_enable(i);
5663                         else
5664                                 rte_eth_promiscuous_disable(i);
5665                 }
5666         }
5667         else {
5668                 if (enable)
5669                         rte_eth_promiscuous_enable(res->port_num);
5670                 else
5671                         rte_eth_promiscuous_disable(res->port_num);
5672         }
5673 }
5674
5675 cmdline_parse_token_string_t cmd_setpromisc_set =
5676         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5677 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5678         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5679                                  "promisc");
5680 cmdline_parse_token_string_t cmd_setpromisc_portall =
5681         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5682                                  "all");
5683 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5684         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5685                               UINT8);
5686 cmdline_parse_token_string_t cmd_setpromisc_mode =
5687         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5688                                  "on#off");
5689
5690 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5691         .f = cmd_set_promisc_mode_parsed,
5692         .data = (void *)1,
5693         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5694         .tokens = {
5695                 (void *)&cmd_setpromisc_set,
5696                 (void *)&cmd_setpromisc_promisc,
5697                 (void *)&cmd_setpromisc_portall,
5698                 (void *)&cmd_setpromisc_mode,
5699                 NULL,
5700         },
5701 };
5702
5703 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5704         .f = cmd_set_promisc_mode_parsed,
5705         .data = (void *)0,
5706         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5707         .tokens = {
5708                 (void *)&cmd_setpromisc_set,
5709                 (void *)&cmd_setpromisc_promisc,
5710                 (void *)&cmd_setpromisc_portnum,
5711                 (void *)&cmd_setpromisc_mode,
5712                 NULL,
5713         },
5714 };
5715
5716 /* *** SET ALLMULTI MODE *** */
5717 struct cmd_set_allmulti_mode_result {
5718         cmdline_fixed_string_t set;
5719         cmdline_fixed_string_t allmulti;
5720         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5721         uint16_t port_num;               /* valid if "allports" argument == 0 */
5722         cmdline_fixed_string_t mode;
5723 };
5724
5725 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5726                                         __attribute__((unused)) struct cmdline *cl,
5727                                         void *allports)
5728 {
5729         struct cmd_set_allmulti_mode_result *res = parsed_result;
5730         int enable;
5731         portid_t i;
5732
5733         if (!strcmp(res->mode, "on"))
5734                 enable = 1;
5735         else
5736                 enable = 0;
5737
5738         /* all ports */
5739         if (allports) {
5740                 RTE_ETH_FOREACH_DEV(i) {
5741                         if (enable)
5742                                 rte_eth_allmulticast_enable(i);
5743                         else
5744                                 rte_eth_allmulticast_disable(i);
5745                 }
5746         }
5747         else {
5748                 if (enable)
5749                         rte_eth_allmulticast_enable(res->port_num);
5750                 else
5751                         rte_eth_allmulticast_disable(res->port_num);
5752         }
5753 }
5754
5755 cmdline_parse_token_string_t cmd_setallmulti_set =
5756         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5757 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5758         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5759                                  "allmulti");
5760 cmdline_parse_token_string_t cmd_setallmulti_portall =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5762                                  "all");
5763 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5764         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5765                               UINT16);
5766 cmdline_parse_token_string_t cmd_setallmulti_mode =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5768                                  "on#off");
5769
5770 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5771         .f = cmd_set_allmulti_mode_parsed,
5772         .data = (void *)1,
5773         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5774         .tokens = {
5775                 (void *)&cmd_setallmulti_set,
5776                 (void *)&cmd_setallmulti_allmulti,
5777                 (void *)&cmd_setallmulti_portall,
5778                 (void *)&cmd_setallmulti_mode,
5779                 NULL,
5780         },
5781 };
5782
5783 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5784         .f = cmd_set_allmulti_mode_parsed,
5785         .data = (void *)0,
5786         .help_str = "set allmulti <port_id> on|off: "
5787                 "Set allmulti mode on port_id",
5788         .tokens = {
5789                 (void *)&cmd_setallmulti_set,
5790                 (void *)&cmd_setallmulti_allmulti,
5791                 (void *)&cmd_setallmulti_portnum,
5792                 (void *)&cmd_setallmulti_mode,
5793                 NULL,
5794         },
5795 };
5796
5797 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5798 struct cmd_link_flow_ctrl_set_result {
5799         cmdline_fixed_string_t set;
5800         cmdline_fixed_string_t flow_ctrl;
5801         cmdline_fixed_string_t rx;
5802         cmdline_fixed_string_t rx_lfc_mode;
5803         cmdline_fixed_string_t tx;
5804         cmdline_fixed_string_t tx_lfc_mode;
5805         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5806         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5807         cmdline_fixed_string_t autoneg_str;
5808         cmdline_fixed_string_t autoneg;
5809         cmdline_fixed_string_t hw_str;
5810         uint32_t high_water;
5811         cmdline_fixed_string_t lw_str;
5812         uint32_t low_water;
5813         cmdline_fixed_string_t pt_str;
5814         uint16_t pause_time;
5815         cmdline_fixed_string_t xon_str;
5816         uint16_t send_xon;
5817         portid_t port_id;
5818 };
5819
5820 cmdline_parse_token_string_t cmd_lfc_set_set =
5821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5822                                 set, "set");
5823 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5824         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5825                                 flow_ctrl, "flow_ctrl");
5826 cmdline_parse_token_string_t cmd_lfc_set_rx =
5827         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5828                                 rx, "rx");
5829 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5830         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5831                                 rx_lfc_mode, "on#off");
5832 cmdline_parse_token_string_t cmd_lfc_set_tx =
5833         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5834                                 tx, "tx");
5835 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5836         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5837                                 tx_lfc_mode, "on#off");
5838 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5839         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5840                                 hw_str, "high_water");
5841 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5842         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5843                                 high_water, UINT32);
5844 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5845         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5846                                 lw_str, "low_water");
5847 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5848         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5849                                 low_water, UINT32);
5850 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5851         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5852                                 pt_str, "pause_time");
5853 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5854         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5855                                 pause_time, UINT16);
5856 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5857         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5858                                 xon_str, "send_xon");
5859 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5860         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5861                                 send_xon, UINT16);
5862 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5863         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5864                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5865 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5866         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5867                                 mac_ctrl_frame_fwd_mode, "on#off");
5868 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5869         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5870                                 autoneg_str, "autoneg");
5871 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5873                                 autoneg, "on#off");
5874 cmdline_parse_token_num_t cmd_lfc_set_portid =
5875         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5876                                 port_id, UINT16);
5877
5878 /* forward declaration */
5879 static void
5880 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5881                               void *data);
5882
5883 cmdline_parse_inst_t cmd_link_flow_control_set = {
5884         .f = cmd_link_flow_ctrl_set_parsed,
5885         .data = NULL,
5886         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5887                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5888                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5889         .tokens = {
5890                 (void *)&cmd_lfc_set_set,
5891                 (void *)&cmd_lfc_set_flow_ctrl,
5892                 (void *)&cmd_lfc_set_rx,
5893                 (void *)&cmd_lfc_set_rx_mode,
5894                 (void *)&cmd_lfc_set_tx,
5895                 (void *)&cmd_lfc_set_tx_mode,
5896                 (void *)&cmd_lfc_set_high_water,
5897                 (void *)&cmd_lfc_set_low_water,
5898                 (void *)&cmd_lfc_set_pause_time,
5899                 (void *)&cmd_lfc_set_send_xon,
5900                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5901                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5902                 (void *)&cmd_lfc_set_autoneg_str,
5903                 (void *)&cmd_lfc_set_autoneg,
5904                 (void *)&cmd_lfc_set_portid,
5905                 NULL,
5906         },
5907 };
5908
5909 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5910         .f = cmd_link_flow_ctrl_set_parsed,
5911         .data = (void *)&cmd_link_flow_control_set_rx,
5912         .help_str = "set flow_ctrl rx on|off <port_id>: "
5913                 "Change rx flow control parameter",
5914         .tokens = {
5915                 (void *)&cmd_lfc_set_set,
5916                 (void *)&cmd_lfc_set_flow_ctrl,
5917                 (void *)&cmd_lfc_set_rx,
5918                 (void *)&cmd_lfc_set_rx_mode,
5919                 (void *)&cmd_lfc_set_portid,
5920                 NULL,
5921         },
5922 };
5923
5924 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5925         .f = cmd_link_flow_ctrl_set_parsed,
5926         .data = (void *)&cmd_link_flow_control_set_tx,
5927         .help_str = "set flow_ctrl tx on|off <port_id>: "
5928                 "Change tx flow control parameter",
5929         .tokens = {
5930                 (void *)&cmd_lfc_set_set,
5931                 (void *)&cmd_lfc_set_flow_ctrl,
5932                 (void *)&cmd_lfc_set_tx,
5933                 (void *)&cmd_lfc_set_tx_mode,
5934                 (void *)&cmd_lfc_set_portid,
5935                 NULL,
5936         },
5937 };
5938
5939 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5940         .f = cmd_link_flow_ctrl_set_parsed,
5941         .data = (void *)&cmd_link_flow_control_set_hw,
5942         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5943                 "Change high water flow control parameter",
5944         .tokens = {
5945                 (void *)&cmd_lfc_set_set,
5946                 (void *)&cmd_lfc_set_flow_ctrl,
5947                 (void *)&cmd_lfc_set_high_water_str,
5948                 (void *)&cmd_lfc_set_high_water,
5949                 (void *)&cmd_lfc_set_portid,
5950                 NULL,
5951         },
5952 };
5953
5954 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5955         .f = cmd_link_flow_ctrl_set_parsed,
5956         .data = (void *)&cmd_link_flow_control_set_lw,
5957         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5958                 "Change low water flow control parameter",
5959         .tokens = {
5960                 (void *)&cmd_lfc_set_set,
5961                 (void *)&cmd_lfc_set_flow_ctrl,
5962                 (void *)&cmd_lfc_set_low_water_str,
5963                 (void *)&cmd_lfc_set_low_water,
5964                 (void *)&cmd_lfc_set_portid,
5965                 NULL,
5966         },
5967 };
5968
5969 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5970         .f = cmd_link_flow_ctrl_set_parsed,
5971         .data = (void *)&cmd_link_flow_control_set_pt,
5972         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5973                 "Change pause time flow control parameter",
5974         .tokens = {
5975                 (void *)&cmd_lfc_set_set,
5976                 (void *)&cmd_lfc_set_flow_ctrl,
5977                 (void *)&cmd_lfc_set_pause_time_str,
5978                 (void *)&cmd_lfc_set_pause_time,
5979                 (void *)&cmd_lfc_set_portid,
5980                 NULL,
5981         },
5982 };
5983
5984 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5985         .f = cmd_link_flow_ctrl_set_parsed,
5986         .data = (void *)&cmd_link_flow_control_set_xon,
5987         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5988                 "Change send_xon flow control parameter",
5989         .tokens = {
5990                 (void *)&cmd_lfc_set_set,
5991                 (void *)&cmd_lfc_set_flow_ctrl,
5992                 (void *)&cmd_lfc_set_send_xon_str,
5993                 (void *)&cmd_lfc_set_send_xon,
5994                 (void *)&cmd_lfc_set_portid,
5995                 NULL,
5996         },
5997 };
5998
5999 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6000         .f = cmd_link_flow_ctrl_set_parsed,
6001         .data = (void *)&cmd_link_flow_control_set_macfwd,
6002         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6003                 "Change mac ctrl fwd flow control parameter",
6004         .tokens = {
6005                 (void *)&cmd_lfc_set_set,
6006                 (void *)&cmd_lfc_set_flow_ctrl,
6007                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6008                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6009                 (void *)&cmd_lfc_set_portid,
6010                 NULL,
6011         },
6012 };
6013
6014 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6015         .f = cmd_link_flow_ctrl_set_parsed,
6016         .data = (void *)&cmd_link_flow_control_set_autoneg,
6017         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6018                 "Change autoneg flow control parameter",
6019         .tokens = {
6020                 (void *)&cmd_lfc_set_set,
6021                 (void *)&cmd_lfc_set_flow_ctrl,
6022                 (void *)&cmd_lfc_set_autoneg_str,
6023                 (void *)&cmd_lfc_set_autoneg,
6024                 (void *)&cmd_lfc_set_portid,
6025                 NULL,
6026         },
6027 };
6028
6029 static void
6030 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6031                               __attribute__((unused)) struct cmdline *cl,
6032                               void *data)
6033 {
6034         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6035         cmdline_parse_inst_t *cmd = data;
6036         struct rte_eth_fc_conf fc_conf;
6037         int rx_fc_en = 0;
6038         int tx_fc_en = 0;
6039         int ret;
6040
6041         /*
6042          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6043          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6044          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6045          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6046          */
6047         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6048                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6049         };
6050
6051         /* Partial command line, retrieve current configuration */
6052         if (cmd) {
6053                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6054                 if (ret != 0) {
6055                         printf("cannot get current flow ctrl parameters, return"
6056                                "code = %d\n", ret);
6057                         return;
6058                 }
6059
6060                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6061                     (fc_conf.mode == RTE_FC_FULL))
6062                         rx_fc_en = 1;
6063                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6064                     (fc_conf.mode == RTE_FC_FULL))
6065                         tx_fc_en = 1;
6066         }
6067
6068         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6069                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6070
6071         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6072                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6073
6074         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6075
6076         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6077                 fc_conf.high_water = res->high_water;
6078
6079         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6080                 fc_conf.low_water = res->low_water;
6081
6082         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6083                 fc_conf.pause_time = res->pause_time;
6084
6085         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6086                 fc_conf.send_xon = res->send_xon;
6087
6088         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6089                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6090                         fc_conf.mac_ctrl_frame_fwd = 1;
6091                 else
6092                         fc_conf.mac_ctrl_frame_fwd = 0;
6093         }
6094
6095         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6096                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6097
6098         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6099         if (ret != 0)
6100                 printf("bad flow contrl parameter, return code = %d \n", ret);
6101 }
6102
6103 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6104 struct cmd_priority_flow_ctrl_set_result {
6105         cmdline_fixed_string_t set;
6106         cmdline_fixed_string_t pfc_ctrl;
6107         cmdline_fixed_string_t rx;
6108         cmdline_fixed_string_t rx_pfc_mode;
6109         cmdline_fixed_string_t tx;
6110         cmdline_fixed_string_t tx_pfc_mode;
6111         uint32_t high_water;
6112         uint32_t low_water;
6113         uint16_t pause_time;
6114         uint8_t  priority;
6115         portid_t port_id;
6116 };
6117
6118 static void
6119 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6120                        __attribute__((unused)) struct cmdline *cl,
6121                        __attribute__((unused)) void *data)
6122 {
6123         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6124         struct rte_eth_pfc_conf pfc_conf;
6125         int rx_fc_enable, tx_fc_enable;
6126         int ret;
6127
6128         /*
6129          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6130          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6131          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6132          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6133          */
6134         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6135                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6136         };
6137
6138         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6139         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6140         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6141         pfc_conf.fc.high_water = res->high_water;
6142         pfc_conf.fc.low_water  = res->low_water;
6143         pfc_conf.fc.pause_time = res->pause_time;
6144         pfc_conf.priority      = res->priority;
6145
6146         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6147         if (ret != 0)
6148                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6149 }
6150
6151 cmdline_parse_token_string_t cmd_pfc_set_set =
6152         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6153                                 set, "set");
6154 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6155         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6156                                 pfc_ctrl, "pfc_ctrl");
6157 cmdline_parse_token_string_t cmd_pfc_set_rx =
6158         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6159                                 rx, "rx");
6160 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6161         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6162                                 rx_pfc_mode, "on#off");
6163 cmdline_parse_token_string_t cmd_pfc_set_tx =
6164         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6165                                 tx, "tx");
6166 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6167         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6168                                 tx_pfc_mode, "on#off");
6169 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6170         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6171                                 high_water, UINT32);
6172 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6173         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6174                                 low_water, UINT32);
6175 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6176         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6177                                 pause_time, UINT16);
6178 cmdline_parse_token_num_t cmd_pfc_set_priority =
6179         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6180                                 priority, UINT8);
6181 cmdline_parse_token_num_t cmd_pfc_set_portid =
6182         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6183                                 port_id, UINT16);
6184
6185 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6186         .f = cmd_priority_flow_ctrl_set_parsed,
6187         .data = NULL,
6188         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6189                 "<pause_time> <priority> <port_id>: "
6190                 "Configure the Ethernet priority flow control",
6191         .tokens = {
6192                 (void *)&cmd_pfc_set_set,
6193                 (void *)&cmd_pfc_set_flow_ctrl,
6194                 (void *)&cmd_pfc_set_rx,
6195                 (void *)&cmd_pfc_set_rx_mode,
6196                 (void *)&cmd_pfc_set_tx,
6197                 (void *)&cmd_pfc_set_tx_mode,
6198                 (void *)&cmd_pfc_set_high_water,
6199                 (void *)&cmd_pfc_set_low_water,
6200                 (void *)&cmd_pfc_set_pause_time,
6201                 (void *)&cmd_pfc_set_priority,
6202                 (void *)&cmd_pfc_set_portid,
6203                 NULL,
6204         },
6205 };
6206
6207 /* *** RESET CONFIGURATION *** */
6208 struct cmd_reset_result {
6209         cmdline_fixed_string_t reset;
6210         cmdline_fixed_string_t def;
6211 };
6212
6213 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6214                              struct cmdline *cl,
6215                              __attribute__((unused)) void *data)
6216 {
6217         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6218         set_def_fwd_config();
6219 }
6220
6221 cmdline_parse_token_string_t cmd_reset_set =
6222         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6223 cmdline_parse_token_string_t cmd_reset_def =
6224         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6225                                  "default");
6226
6227 cmdline_parse_inst_t cmd_reset = {
6228         .f = cmd_reset_parsed,
6229         .data = NULL,
6230         .help_str = "set default: Reset default forwarding configuration",
6231         .tokens = {
6232                 (void *)&cmd_reset_set,
6233                 (void *)&cmd_reset_def,
6234                 NULL,
6235         },
6236 };
6237
6238 /* *** START FORWARDING *** */
6239 struct cmd_start_result {
6240         cmdline_fixed_string_t start;
6241 };
6242
6243 cmdline_parse_token_string_t cmd_start_start =
6244         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6245
6246 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6247                              __attribute__((unused)) struct cmdline *cl,
6248                              __attribute__((unused)) void *data)
6249 {
6250         start_packet_forwarding(0);
6251 }
6252
6253 cmdline_parse_inst_t cmd_start = {
6254         .f = cmd_start_parsed,
6255         .data = NULL,
6256         .help_str = "start: Start packet forwarding",
6257         .tokens = {
6258                 (void *)&cmd_start_start,
6259                 NULL,
6260         },
6261 };
6262
6263 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6264 struct cmd_start_tx_first_result {
6265         cmdline_fixed_string_t start;
6266         cmdline_fixed_string_t tx_first;
6267 };
6268
6269 static void
6270 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6271                           __attribute__((unused)) struct cmdline *cl,
6272                           __attribute__((unused)) void *data)
6273 {
6274         start_packet_forwarding(1);
6275 }
6276
6277 cmdline_parse_token_string_t cmd_start_tx_first_start =
6278         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6279                                  "start");
6280 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6281         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6282                                  tx_first, "tx_first");
6283
6284 cmdline_parse_inst_t cmd_start_tx_first = {
6285         .f = cmd_start_tx_first_parsed,
6286         .data = NULL,
6287         .help_str = "start tx_first: Start packet forwarding, "
6288                 "after sending 1 burst of packets",
6289         .tokens = {
6290                 (void *)&cmd_start_tx_first_start,
6291                 (void *)&cmd_start_tx_first_tx_first,
6292                 NULL,
6293         },
6294 };
6295
6296 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6297 struct cmd_start_tx_first_n_result {
6298         cmdline_fixed_string_t start;
6299         cmdline_fixed_string_t tx_first;
6300         uint32_t tx_num;
6301 };
6302
6303 static void
6304 cmd_start_tx_first_n_parsed(void *parsed_result,
6305                           __attribute__((unused)) struct cmdline *cl,
6306                           __attribute__((unused)) void *data)
6307 {
6308         struct cmd_start_tx_first_n_result *res = parsed_result;
6309
6310         start_packet_forwarding(res->tx_num);
6311 }
6312
6313 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6314         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6315                         start, "start");
6316 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6317         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6318                         tx_first, "tx_first");
6319 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6320         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6321                         tx_num, UINT32);
6322
6323 cmdline_parse_inst_t cmd_start_tx_first_n = {
6324         .f = cmd_start_tx_first_n_parsed,
6325         .data = NULL,
6326         .help_str = "start tx_first <num>: "
6327                 "packet forwarding, after sending <num> bursts of packets",
6328         .tokens = {
6329                 (void *)&cmd_start_tx_first_n_start,
6330                 (void *)&cmd_start_tx_first_n_tx_first,
6331                 (void *)&cmd_start_tx_first_n_tx_num,
6332                 NULL,
6333         },
6334 };
6335
6336 /* *** SET LINK UP *** */
6337 struct cmd_set_link_up_result {
6338         cmdline_fixed_string_t set;
6339         cmdline_fixed_string_t link_up;
6340         cmdline_fixed_string_t port;
6341         portid_t port_id;
6342 };
6343
6344 cmdline_parse_token_string_t cmd_set_link_up_set =
6345         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6346 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6347         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6348                                 "link-up");
6349 cmdline_parse_token_string_t cmd_set_link_up_port =
6350         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6351 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6352         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6353
6354 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6355                              __attribute__((unused)) struct cmdline *cl,
6356                              __attribute__((unused)) void *data)
6357 {
6358         struct cmd_set_link_up_result *res = parsed_result;
6359         dev_set_link_up(res->port_id);
6360 }
6361
6362 cmdline_parse_inst_t cmd_set_link_up = {
6363         .f = cmd_set_link_up_parsed,
6364         .data = NULL,
6365         .help_str = "set link-up port <port id>",
6366         .tokens = {
6367                 (void *)&cmd_set_link_up_set,
6368                 (void *)&cmd_set_link_up_link_up,
6369                 (void *)&cmd_set_link_up_port,
6370                 (void *)&cmd_set_link_up_port_id,
6371                 NULL,
6372         },
6373 };
6374
6375 /* *** SET LINK DOWN *** */
6376 struct cmd_set_link_down_result {
6377         cmdline_fixed_string_t set;
6378         cmdline_fixed_string_t link_down;
6379         cmdline_fixed_string_t port;
6380         portid_t port_id;
6381 };
6382
6383 cmdline_parse_token_string_t cmd_set_link_down_set =
6384         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6385 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6386         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6387                                 "link-down");
6388 cmdline_parse_token_string_t cmd_set_link_down_port =
6389         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6390 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6391         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6392
6393 static void cmd_set_link_down_parsed(
6394                                 __attribute__((unused)) void *parsed_result,
6395                                 __attribute__((unused)) struct cmdline *cl,
6396                                 __attribute__((unused)) void *data)
6397 {
6398         struct cmd_set_link_down_result *res = parsed_result;
6399         dev_set_link_down(res->port_id);
6400 }
6401
6402 cmdline_parse_inst_t cmd_set_link_down = {
6403         .f = cmd_set_link_down_parsed,
6404         .data = NULL,
6405         .help_str = "set link-down port <port id>",
6406         .tokens = {
6407                 (void *)&cmd_set_link_down_set,
6408                 (void *)&cmd_set_link_down_link_down,
6409                 (void *)&cmd_set_link_down_port,
6410                 (void *)&cmd_set_link_down_port_id,
6411                 NULL,
6412         },
6413 };
6414
6415 /* *** SHOW CFG *** */
6416 struct cmd_showcfg_result {
6417         cmdline_fixed_string_t show;
6418         cmdline_fixed_string_t cfg;
6419         cmdline_fixed_string_t what;
6420 };
6421
6422 static void cmd_showcfg_parsed(void *parsed_result,
6423                                __attribute__((unused)) struct cmdline *cl,
6424                                __attribute__((unused)) void *data)
6425 {
6426         struct cmd_showcfg_result *res = parsed_result;
6427         if (!strcmp(res->what, "rxtx"))
6428                 rxtx_config_display();
6429         else if (!strcmp(res->what, "cores"))
6430                 fwd_lcores_config_display();
6431         else if (!strcmp(res->what, "fwd"))
6432                 pkt_fwd_config_display(&cur_fwd_config);
6433         else if (!strcmp(res->what, "txpkts"))
6434                 show_tx_pkt_segments();
6435 }
6436
6437 cmdline_parse_token_string_t cmd_showcfg_show =
6438         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6439 cmdline_parse_token_string_t cmd_showcfg_port =
6440         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6441 cmdline_parse_token_string_t cmd_showcfg_what =
6442         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6443                                  "rxtx#cores#fwd#txpkts");
6444
6445 cmdline_parse_inst_t cmd_showcfg = {
6446         .f = cmd_showcfg_parsed,
6447         .data = NULL,
6448         .help_str = "show config rxtx|cores|fwd|txpkts",
6449         .tokens = {
6450                 (void *)&cmd_showcfg_show,
6451                 (void *)&cmd_showcfg_port,
6452                 (void *)&cmd_showcfg_what,
6453                 NULL,
6454         },
6455 };
6456
6457 /* *** SHOW ALL PORT INFO *** */
6458 struct cmd_showportall_result {
6459         cmdline_fixed_string_t show;
6460         cmdline_fixed_string_t port;
6461         cmdline_fixed_string_t what;
6462         cmdline_fixed_string_t all;
6463 };
6464
6465 static void cmd_showportall_parsed(void *parsed_result,
6466                                 __attribute__((unused)) struct cmdline *cl,
6467                                 __attribute__((unused)) void *data)
6468 {
6469         portid_t i;
6470
6471         struct cmd_showportall_result *res = parsed_result;
6472         if (!strcmp(res->show, "clear")) {
6473                 if (!strcmp(res->what, "stats"))
6474                         RTE_ETH_FOREACH_DEV(i)
6475                                 nic_stats_clear(i);
6476                 else if (!strcmp(res->what, "xstats"))
6477                         RTE_ETH_FOREACH_DEV(i)
6478                                 nic_xstats_clear(i);
6479         } else if (!strcmp(res->what, "info"))
6480                 RTE_ETH_FOREACH_DEV(i)
6481                         port_infos_display(i);
6482         else if (!strcmp(res->what, "stats"))
6483                 RTE_ETH_FOREACH_DEV(i)
6484                         nic_stats_display(i);
6485         else if (!strcmp(res->what, "xstats"))
6486                 RTE_ETH_FOREACH_DEV(i)
6487                         nic_xstats_display(i);
6488         else if (!strcmp(res->what, "fdir"))
6489                 RTE_ETH_FOREACH_DEV(i)
6490                         fdir_get_infos(i);
6491         else if (!strcmp(res->what, "stat_qmap"))
6492                 RTE_ETH_FOREACH_DEV(i)
6493                         nic_stats_mapping_display(i);
6494         else if (!strcmp(res->what, "dcb_tc"))
6495                 RTE_ETH_FOREACH_DEV(i)
6496                         port_dcb_info_display(i);
6497         else if (!strcmp(res->what, "cap"))
6498                 RTE_ETH_FOREACH_DEV(i)
6499                         port_offload_cap_display(i);
6500 }
6501
6502 cmdline_parse_token_string_t cmd_showportall_show =
6503         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6504                                  "show#clear");
6505 cmdline_parse_token_string_t cmd_showportall_port =
6506         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6507 cmdline_parse_token_string_t cmd_showportall_what =
6508         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6509                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6510 cmdline_parse_token_string_t cmd_showportall_all =
6511         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6512 cmdline_parse_inst_t cmd_showportall = {
6513         .f = cmd_showportall_parsed,
6514         .data = NULL,
6515         .help_str = "show|clear port "
6516                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6517         .tokens = {
6518                 (void *)&cmd_showportall_show,
6519                 (void *)&cmd_showportall_port,
6520                 (void *)&cmd_showportall_what,
6521                 (void *)&cmd_showportall_all,
6522                 NULL,
6523         },
6524 };
6525
6526 /* *** SHOW PORT INFO *** */
6527 struct cmd_showport_result {
6528         cmdline_fixed_string_t show;
6529         cmdline_fixed_string_t port;
6530         cmdline_fixed_string_t what;
6531         uint16_t portnum;
6532 };
6533
6534 static void cmd_showport_parsed(void *parsed_result,
6535                                 __attribute__((unused)) struct cmdline *cl,
6536                                 __attribute__((unused)) void *data)
6537 {
6538         struct cmd_showport_result *res = parsed_result;
6539         if (!strcmp(res->show, "clear")) {
6540                 if (!strcmp(res->what, "stats"))
6541                         nic_stats_clear(res->portnum);
6542                 else if (!strcmp(res->what, "xstats"))
6543                         nic_xstats_clear(res->portnum);
6544         } else if (!strcmp(res->what, "info"))
6545                 port_infos_display(res->portnum);
6546         else if (!strcmp(res->what, "stats"))
6547                 nic_stats_display(res->portnum);
6548         else if (!strcmp(res->what, "xstats"))
6549                 nic_xstats_display(res->portnum);
6550         else if (!strcmp(res->what, "fdir"))
6551                  fdir_get_infos(res->portnum);
6552         else if (!strcmp(res->what, "stat_qmap"))
6553                 nic_stats_mapping_display(res->portnum);
6554         else if (!strcmp(res->what, "dcb_tc"))
6555                 port_dcb_info_display(res->portnum);
6556         else if (!strcmp(res->what, "cap"))
6557                 port_offload_cap_display(res->portnum);
6558 }
6559
6560 cmdline_parse_token_string_t cmd_showport_show =
6561         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6562                                  "show#clear");
6563 cmdline_parse_token_string_t cmd_showport_port =
6564         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6565 cmdline_parse_token_string_t cmd_showport_what =
6566         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6567                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6568 cmdline_parse_token_num_t cmd_showport_portnum =
6569         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6570
6571 cmdline_parse_inst_t cmd_showport = {
6572         .f = cmd_showport_parsed,
6573         .data = NULL,
6574         .help_str = "show|clear port "
6575                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6576                 "<port_id>",
6577         .tokens = {
6578                 (void *)&cmd_showport_show,
6579                 (void *)&cmd_showport_port,
6580                 (void *)&cmd_showport_what,
6581                 (void *)&cmd_showport_portnum,
6582                 NULL,
6583         },
6584 };
6585
6586 /* *** SHOW QUEUE INFO *** */
6587 struct cmd_showqueue_result {
6588         cmdline_fixed_string_t show;
6589         cmdline_fixed_string_t type;
6590         cmdline_fixed_string_t what;
6591         uint16_t portnum;
6592         uint16_t queuenum;
6593 };
6594
6595 static void
6596 cmd_showqueue_parsed(void *parsed_result,
6597         __attribute__((unused)) struct cmdline *cl,
6598         __attribute__((unused)) void *data)
6599 {
6600         struct cmd_showqueue_result *res = parsed_result;
6601
6602         if (!strcmp(res->type, "rxq"))
6603                 rx_queue_infos_display(res->portnum, res->queuenum);
6604         else if (!strcmp(res->type, "txq"))
6605                 tx_queue_infos_display(res->portnum, res->queuenum);
6606 }
6607
6608 cmdline_parse_token_string_t cmd_showqueue_show =
6609         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6610 cmdline_parse_token_string_t cmd_showqueue_type =
6611         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6612 cmdline_parse_token_string_t cmd_showqueue_what =
6613         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6614 cmdline_parse_token_num_t cmd_showqueue_portnum =
6615         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6616 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6617         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6618
6619 cmdline_parse_inst_t cmd_showqueue = {
6620         .f = cmd_showqueue_parsed,
6621         .data = NULL,
6622         .help_str = "show rxq|txq info <port_id> <queue_id>",
6623         .tokens = {
6624                 (void *)&cmd_showqueue_show,
6625                 (void *)&cmd_showqueue_type,
6626                 (void *)&cmd_showqueue_what,
6627                 (void *)&cmd_showqueue_portnum,
6628                 (void *)&cmd_showqueue_queuenum,
6629                 NULL,
6630         },
6631 };
6632
6633 /* *** READ PORT REGISTER *** */
6634 struct cmd_read_reg_result {
6635         cmdline_fixed_string_t read;
6636         cmdline_fixed_string_t reg;
6637         portid_t port_id;
6638         uint32_t reg_off;
6639 };
6640
6641 static void
6642 cmd_read_reg_parsed(void *parsed_result,
6643                     __attribute__((unused)) struct cmdline *cl,
6644                     __attribute__((unused)) void *data)
6645 {
6646         struct cmd_read_reg_result *res = parsed_result;
6647         port_reg_display(res->port_id, res->reg_off);
6648 }
6649
6650 cmdline_parse_token_string_t cmd_read_reg_read =
6651         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6652 cmdline_parse_token_string_t cmd_read_reg_reg =
6653         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6654 cmdline_parse_token_num_t cmd_read_reg_port_id =
6655         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6656 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6657         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6658
6659 cmdline_parse_inst_t cmd_read_reg = {
6660         .f = cmd_read_reg_parsed,
6661         .data = NULL,
6662         .help_str = "read reg <port_id> <reg_off>",
6663         .tokens = {
6664                 (void *)&cmd_read_reg_read,
6665                 (void *)&cmd_read_reg_reg,
6666                 (void *)&cmd_read_reg_port_id,
6667                 (void *)&cmd_read_reg_reg_off,
6668                 NULL,
6669         },
6670 };
6671
6672 /* *** READ PORT REGISTER BIT FIELD *** */
6673 struct cmd_read_reg_bit_field_result {
6674         cmdline_fixed_string_t read;
6675         cmdline_fixed_string_t regfield;
6676         portid_t port_id;
6677         uint32_t reg_off;
6678         uint8_t bit1_pos;
6679         uint8_t bit2_pos;
6680 };
6681
6682 static void
6683 cmd_read_reg_bit_field_parsed(void *parsed_result,
6684                               __attribute__((unused)) struct cmdline *cl,
6685                               __attribute__((unused)) void *data)
6686 {
6687         struct cmd_read_reg_bit_field_result *res = parsed_result;
6688         port_reg_bit_field_display(res->port_id, res->reg_off,
6689                                    res->bit1_pos, res->bit2_pos);
6690 }
6691
6692 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6693         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6694                                  "read");
6695 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6696         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6697                                  regfield, "regfield");
6698 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6699         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6700                               UINT16);
6701 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6702         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6703                               UINT32);
6704 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6705         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6706                               UINT8);
6707 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6708         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6709                               UINT8);
6710
6711 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6712         .f = cmd_read_reg_bit_field_parsed,
6713         .data = NULL,
6714         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6715         "Read register bit field between bit_x and bit_y included",
6716         .tokens = {
6717                 (void *)&cmd_read_reg_bit_field_read,
6718                 (void *)&cmd_read_reg_bit_field_regfield,
6719                 (void *)&cmd_read_reg_bit_field_port_id,
6720                 (void *)&cmd_read_reg_bit_field_reg_off,
6721                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6722                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6723                 NULL,
6724         },
6725 };
6726
6727 /* *** READ PORT REGISTER BIT *** */
6728 struct cmd_read_reg_bit_result {
6729         cmdline_fixed_string_t read;
6730         cmdline_fixed_string_t regbit;
6731         portid_t port_id;
6732         uint32_t reg_off;
6733         uint8_t bit_pos;
6734 };
6735
6736 static void
6737 cmd_read_reg_bit_parsed(void *parsed_result,
6738                         __attribute__((unused)) struct cmdline *cl,
6739                         __attribute__((unused)) void *data)
6740 {
6741         struct cmd_read_reg_bit_result *res = parsed_result;
6742         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6743 }
6744
6745 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6746         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6747 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6748         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6749                                  regbit, "regbit");
6750 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6751         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6752 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6753         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6754 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6755         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6756
6757 cmdline_parse_inst_t cmd_read_reg_bit = {
6758         .f = cmd_read_reg_bit_parsed,
6759         .data = NULL,
6760         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6761         .tokens = {
6762                 (void *)&cmd_read_reg_bit_read,
6763                 (void *)&cmd_read_reg_bit_regbit,
6764                 (void *)&cmd_read_reg_bit_port_id,
6765                 (void *)&cmd_read_reg_bit_reg_off,
6766                 (void *)&cmd_read_reg_bit_bit_pos,
6767                 NULL,
6768         },
6769 };
6770
6771 /* *** WRITE PORT REGISTER *** */
6772 struct cmd_write_reg_result {
6773         cmdline_fixed_string_t write;
6774         cmdline_fixed_string_t reg;
6775         portid_t port_id;
6776         uint32_t reg_off;
6777         uint32_t value;
6778 };
6779
6780 static void
6781 cmd_write_reg_parsed(void *parsed_result,
6782                      __attribute__((unused)) struct cmdline *cl,
6783                      __attribute__((unused)) void *data)
6784 {
6785         struct cmd_write_reg_result *res = parsed_result;
6786         port_reg_set(res->port_id, res->reg_off, res->value);
6787 }
6788
6789 cmdline_parse_token_string_t cmd_write_reg_write =
6790         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6791 cmdline_parse_token_string_t cmd_write_reg_reg =
6792         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6793 cmdline_parse_token_num_t cmd_write_reg_port_id =
6794         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6795 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6796         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6797 cmdline_parse_token_num_t cmd_write_reg_value =
6798         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6799
6800 cmdline_parse_inst_t cmd_write_reg = {
6801         .f = cmd_write_reg_parsed,
6802         .data = NULL,
6803         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6804         .tokens = {
6805                 (void *)&cmd_write_reg_write,
6806                 (void *)&cmd_write_reg_reg,
6807                 (void *)&cmd_write_reg_port_id,
6808                 (void *)&cmd_write_reg_reg_off,
6809                 (void *)&cmd_write_reg_value,
6810                 NULL,
6811         },
6812 };
6813
6814 /* *** WRITE PORT REGISTER BIT FIELD *** */
6815 struct cmd_write_reg_bit_field_result {
6816         cmdline_fixed_string_t write;
6817         cmdline_fixed_string_t regfield;
6818         portid_t port_id;
6819         uint32_t reg_off;
6820         uint8_t bit1_pos;
6821         uint8_t bit2_pos;
6822         uint32_t value;
6823 };
6824
6825 static void
6826 cmd_write_reg_bit_field_parsed(void *parsed_result,
6827                                __attribute__((unused)) struct cmdline *cl,
6828                                __attribute__((unused)) void *data)
6829 {
6830         struct cmd_write_reg_bit_field_result *res = parsed_result;
6831         port_reg_bit_field_set(res->port_id, res->reg_off,
6832                           res->bit1_pos, res->bit2_pos, res->value);
6833 }
6834
6835 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6836         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6837                                  "write");
6838 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6839         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6840                                  regfield, "regfield");
6841 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6842         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6843                               UINT16);
6844 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6845         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6846                               UINT32);
6847 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6848         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6849                               UINT8);
6850 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6851         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6852                               UINT8);
6853 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6854         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6855                               UINT32);
6856
6857 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6858         .f = cmd_write_reg_bit_field_parsed,
6859         .data = NULL,
6860         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6861                 "<reg_value>: "
6862                 "Set register bit field between bit_x and bit_y included",
6863         .tokens = {
6864                 (void *)&cmd_write_reg_bit_field_write,
6865                 (void *)&cmd_write_reg_bit_field_regfield,
6866                 (void *)&cmd_write_reg_bit_field_port_id,
6867                 (void *)&cmd_write_reg_bit_field_reg_off,
6868                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6869                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6870                 (void *)&cmd_write_reg_bit_field_value,
6871                 NULL,
6872         },
6873 };
6874
6875 /* *** WRITE PORT REGISTER BIT *** */
6876 struct cmd_write_reg_bit_result {
6877         cmdline_fixed_string_t write;
6878         cmdline_fixed_string_t regbit;
6879         portid_t port_id;
6880         uint32_t reg_off;
6881         uint8_t bit_pos;
6882         uint8_t value;
6883 };
6884
6885 static void
6886 cmd_write_reg_bit_parsed(void *parsed_result,
6887                          __attribute__((unused)) struct cmdline *cl,
6888                          __attribute__((unused)) void *data)
6889 {
6890         struct cmd_write_reg_bit_result *res = parsed_result;
6891         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6892 }
6893
6894 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6895         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6896                                  "write");
6897 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6898         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6899                                  regbit, "regbit");
6900 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6901         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6902 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6903         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6904 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6905         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6906 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6907         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6908
6909 cmdline_parse_inst_t cmd_write_reg_bit = {
6910         .f = cmd_write_reg_bit_parsed,
6911         .data = NULL,
6912         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6913                 "0 <= bit_x <= 31",
6914         .tokens = {
6915                 (void *)&cmd_write_reg_bit_write,
6916                 (void *)&cmd_write_reg_bit_regbit,
6917                 (void *)&cmd_write_reg_bit_port_id,
6918                 (void *)&cmd_write_reg_bit_reg_off,
6919                 (void *)&cmd_write_reg_bit_bit_pos,
6920                 (void *)&cmd_write_reg_bit_value,
6921                 NULL,
6922         },
6923 };
6924
6925 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6926 struct cmd_read_rxd_txd_result {
6927         cmdline_fixed_string_t read;
6928         cmdline_fixed_string_t rxd_txd;
6929         portid_t port_id;
6930         uint16_t queue_id;
6931         uint16_t desc_id;
6932 };
6933
6934 static void
6935 cmd_read_rxd_txd_parsed(void *parsed_result,
6936                         __attribute__((unused)) struct cmdline *cl,
6937                         __attribute__((unused)) void *data)
6938 {
6939         struct cmd_read_rxd_txd_result *res = parsed_result;
6940
6941         if (!strcmp(res->rxd_txd, "rxd"))
6942                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6943         else if (!strcmp(res->rxd_txd, "txd"))
6944                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6945 }
6946
6947 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6948         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6949 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6950         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6951                                  "rxd#txd");
6952 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6953         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
6954 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6955         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6956 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6957         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6958
6959 cmdline_parse_inst_t cmd_read_rxd_txd = {
6960         .f = cmd_read_rxd_txd_parsed,
6961         .data = NULL,
6962         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6963         .tokens = {
6964                 (void *)&cmd_read_rxd_txd_read,
6965                 (void *)&cmd_read_rxd_txd_rxd_txd,
6966                 (void *)&cmd_read_rxd_txd_port_id,
6967                 (void *)&cmd_read_rxd_txd_queue_id,
6968                 (void *)&cmd_read_rxd_txd_desc_id,
6969                 NULL,
6970         },
6971 };
6972
6973 /* *** QUIT *** */
6974 struct cmd_quit_result {
6975         cmdline_fixed_string_t quit;
6976 };
6977
6978 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6979                             struct cmdline *cl,
6980                             __attribute__((unused)) void *data)
6981 {
6982         pmd_test_exit();
6983         cmdline_quit(cl);
6984 }
6985
6986 cmdline_parse_token_string_t cmd_quit_quit =
6987         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6988
6989 cmdline_parse_inst_t cmd_quit = {
6990         .f = cmd_quit_parsed,
6991         .data = NULL,
6992         .help_str = "quit: Exit application",
6993         .tokens = {
6994                 (void *)&cmd_quit_quit,
6995                 NULL,
6996         },
6997 };
6998
6999 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7000 struct cmd_mac_addr_result {
7001         cmdline_fixed_string_t mac_addr_cmd;
7002         cmdline_fixed_string_t what;
7003         uint16_t port_num;
7004         struct ether_addr address;
7005 };
7006
7007 static void cmd_mac_addr_parsed(void *parsed_result,
7008                 __attribute__((unused)) struct cmdline *cl,
7009                 __attribute__((unused)) void *data)
7010 {
7011         struct cmd_mac_addr_result *res = parsed_result;
7012         int ret;
7013
7014         if (strcmp(res->what, "add") == 0)
7015                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7016         else if (strcmp(res->what, "set") == 0)
7017                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7018                                                        &res->address);
7019         else
7020                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7021
7022         /* check the return value and print it if is < 0 */
7023         if(ret < 0)
7024                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7025
7026 }
7027
7028 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7029         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7030                                 "mac_addr");
7031 cmdline_parse_token_string_t cmd_mac_addr_what =
7032         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7033                                 "add#remove#set");
7034 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7035                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7036                                         UINT16);
7037 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7038                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7039
7040 cmdline_parse_inst_t cmd_mac_addr = {
7041         .f = cmd_mac_addr_parsed,
7042         .data = (void *)0,
7043         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7044                         "Add/Remove/Set MAC address on port_id",
7045         .tokens = {
7046                 (void *)&cmd_mac_addr_cmd,
7047                 (void *)&cmd_mac_addr_what,
7048                 (void *)&cmd_mac_addr_portnum,
7049                 (void *)&cmd_mac_addr_addr,
7050                 NULL,
7051         },
7052 };
7053
7054
7055 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7056 struct cmd_set_qmap_result {
7057         cmdline_fixed_string_t set;
7058         cmdline_fixed_string_t qmap;
7059         cmdline_fixed_string_t what;
7060         portid_t port_id;
7061         uint16_t queue_id;
7062         uint8_t map_value;
7063 };
7064
7065 static void
7066 cmd_set_qmap_parsed(void *parsed_result,
7067                        __attribute__((unused)) struct cmdline *cl,
7068                        __attribute__((unused)) void *data)
7069 {
7070         struct cmd_set_qmap_result *res = parsed_result;
7071         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7072
7073         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7074 }
7075
7076 cmdline_parse_token_string_t cmd_setqmap_set =
7077         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7078                                  set, "set");
7079 cmdline_parse_token_string_t cmd_setqmap_qmap =
7080         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7081                                  qmap, "stat_qmap");
7082 cmdline_parse_token_string_t cmd_setqmap_what =
7083         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7084                                  what, "tx#rx");
7085 cmdline_parse_token_num_t cmd_setqmap_portid =
7086         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7087                               port_id, UINT16);
7088 cmdline_parse_token_num_t cmd_setqmap_queueid =
7089         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7090                               queue_id, UINT16);
7091 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7092         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7093                               map_value, UINT8);
7094
7095 cmdline_parse_inst_t cmd_set_qmap = {
7096         .f = cmd_set_qmap_parsed,
7097         .data = NULL,
7098         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7099                 "Set statistics mapping value on tx|rx queue_id of port_id",
7100         .tokens = {
7101                 (void *)&cmd_setqmap_set,
7102                 (void *)&cmd_setqmap_qmap,
7103                 (void *)&cmd_setqmap_what,
7104                 (void *)&cmd_setqmap_portid,
7105                 (void *)&cmd_setqmap_queueid,
7106                 (void *)&cmd_setqmap_mapvalue,
7107                 NULL,
7108         },
7109 };
7110
7111 /* *** CONFIGURE UNICAST HASH TABLE *** */
7112 struct cmd_set_uc_hash_table {
7113         cmdline_fixed_string_t set;
7114         cmdline_fixed_string_t port;
7115         portid_t port_id;
7116         cmdline_fixed_string_t what;
7117         struct ether_addr address;
7118         cmdline_fixed_string_t mode;
7119 };
7120
7121 static void
7122 cmd_set_uc_hash_parsed(void *parsed_result,
7123                        __attribute__((unused)) struct cmdline *cl,
7124                        __attribute__((unused)) void *data)
7125 {
7126         int ret=0;
7127         struct cmd_set_uc_hash_table *res = parsed_result;
7128
7129         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7130
7131         if (strcmp(res->what, "uta") == 0)
7132                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7133                                                 &res->address,(uint8_t)is_on);
7134         if (ret < 0)
7135                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7136
7137 }
7138
7139 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7140         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7141                                  set, "set");
7142 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7143         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7144                                  port, "port");
7145 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7146         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7147                               port_id, UINT16);
7148 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7149         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7150                                  what, "uta");
7151 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7152         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7153                                 address);
7154 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7155         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7156                                  mode, "on#off");
7157
7158 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7159         .f = cmd_set_uc_hash_parsed,
7160         .data = NULL,
7161         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7162         .tokens = {
7163                 (void *)&cmd_set_uc_hash_set,
7164                 (void *)&cmd_set_uc_hash_port,
7165                 (void *)&cmd_set_uc_hash_portid,
7166                 (void *)&cmd_set_uc_hash_what,
7167                 (void *)&cmd_set_uc_hash_mac,
7168                 (void *)&cmd_set_uc_hash_mode,
7169                 NULL,
7170         },
7171 };
7172
7173 struct cmd_set_uc_all_hash_table {
7174         cmdline_fixed_string_t set;
7175         cmdline_fixed_string_t port;
7176         portid_t port_id;
7177         cmdline_fixed_string_t what;
7178         cmdline_fixed_string_t value;
7179         cmdline_fixed_string_t mode;
7180 };
7181
7182 static void
7183 cmd_set_uc_all_hash_parsed(void *parsed_result,
7184                        __attribute__((unused)) struct cmdline *cl,
7185                        __attribute__((unused)) void *data)
7186 {
7187         int ret=0;
7188         struct cmd_set_uc_all_hash_table *res = parsed_result;
7189
7190         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7191
7192         if ((strcmp(res->what, "uta") == 0) &&
7193                 (strcmp(res->value, "all") == 0))
7194                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7195         if (ret < 0)
7196                 printf("bad unicast hash table parameter,"
7197                         "return code = %d \n", ret);
7198 }
7199
7200 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7201         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7202                                  set, "set");
7203 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7204         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7205                                  port, "port");
7206 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7207         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7208                               port_id, UINT16);
7209 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7210         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7211                                  what, "uta");
7212 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7213         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7214                                 value,"all");
7215 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7216         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7217                                  mode, "on#off");
7218
7219 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7220         .f = cmd_set_uc_all_hash_parsed,
7221         .data = NULL,
7222         .help_str = "set port <port_id> uta all on|off",
7223         .tokens = {
7224                 (void *)&cmd_set_uc_all_hash_set,
7225                 (void *)&cmd_set_uc_all_hash_port,
7226                 (void *)&cmd_set_uc_all_hash_portid,
7227                 (void *)&cmd_set_uc_all_hash_what,
7228                 (void *)&cmd_set_uc_all_hash_value,
7229                 (void *)&cmd_set_uc_all_hash_mode,
7230                 NULL,
7231         },
7232 };
7233
7234 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7235 struct cmd_set_vf_macvlan_filter {
7236         cmdline_fixed_string_t set;
7237         cmdline_fixed_string_t port;
7238         portid_t port_id;
7239         cmdline_fixed_string_t vf;
7240         uint8_t vf_id;
7241         struct ether_addr address;
7242         cmdline_fixed_string_t filter_type;
7243         cmdline_fixed_string_t mode;
7244 };
7245
7246 static void
7247 cmd_set_vf_macvlan_parsed(void *parsed_result,
7248                        __attribute__((unused)) struct cmdline *cl,
7249                        __attribute__((unused)) void *data)
7250 {
7251         int is_on, ret = 0;
7252         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7253         struct rte_eth_mac_filter filter;
7254
7255         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7256
7257         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7258
7259         /* set VF MAC filter */
7260         filter.is_vf = 1;
7261
7262         /* set VF ID */
7263         filter.dst_id = res->vf_id;
7264
7265         if (!strcmp(res->filter_type, "exact-mac"))
7266                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7267         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7268                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7269         else if (!strcmp(res->filter_type, "hashmac"))
7270                 filter.filter_type = RTE_MAC_HASH_MATCH;
7271         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7272                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7273
7274         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7275
7276         if (is_on)
7277                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7278                                         RTE_ETH_FILTER_MACVLAN,
7279                                         RTE_ETH_FILTER_ADD,
7280                                          &filter);
7281         else
7282                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7283                                         RTE_ETH_FILTER_MACVLAN,
7284                                         RTE_ETH_FILTER_DELETE,
7285                                         &filter);
7286
7287         if (ret < 0)
7288                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7289
7290 }
7291
7292 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7293         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7294                                  set, "set");
7295 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7296         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7297                                  port, "port");
7298 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7299         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7300                               port_id, UINT16);
7301 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7302         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7303                                  vf, "vf");
7304 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7305         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7306                                 vf_id, UINT8);
7307 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7308         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7309                                 address);
7310 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7311         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7312                                 filter_type, "exact-mac#exact-mac-vlan"
7313                                 "#hashmac#hashmac-vlan");
7314 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7315         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7316                                  mode, "on#off");
7317
7318 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7319         .f = cmd_set_vf_macvlan_parsed,
7320         .data = NULL,
7321         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7322                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7323                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7324                 "hash match rule: hash match of MAC and exact match of VLAN",
7325         .tokens = {
7326                 (void *)&cmd_set_vf_macvlan_set,
7327                 (void *)&cmd_set_vf_macvlan_port,
7328                 (void *)&cmd_set_vf_macvlan_portid,
7329                 (void *)&cmd_set_vf_macvlan_vf,
7330                 (void *)&cmd_set_vf_macvlan_vf_id,
7331                 (void *)&cmd_set_vf_macvlan_mac,
7332                 (void *)&cmd_set_vf_macvlan_filter_type,
7333                 (void *)&cmd_set_vf_macvlan_mode,
7334                 NULL,
7335         },
7336 };
7337
7338 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7339 struct cmd_set_vf_traffic {
7340         cmdline_fixed_string_t set;
7341         cmdline_fixed_string_t port;
7342         portid_t port_id;
7343         cmdline_fixed_string_t vf;
7344         uint8_t vf_id;
7345         cmdline_fixed_string_t what;
7346         cmdline_fixed_string_t mode;
7347 };
7348
7349 static void
7350 cmd_set_vf_traffic_parsed(void *parsed_result,
7351                        __attribute__((unused)) struct cmdline *cl,
7352                        __attribute__((unused)) void *data)
7353 {
7354         struct cmd_set_vf_traffic *res = parsed_result;
7355         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7356         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7357
7358         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7359 }
7360
7361 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7362         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7363                                  set, "set");
7364 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7365         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7366                                  port, "port");
7367 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7368         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7369                               port_id, UINT16);
7370 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7371         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7372                                  vf, "vf");
7373 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7374         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7375                               vf_id, UINT8);
7376 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7378                                  what, "tx#rx");
7379 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7380         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7381                                  mode, "on#off");
7382
7383 cmdline_parse_inst_t cmd_set_vf_traffic = {
7384         .f = cmd_set_vf_traffic_parsed,
7385         .data = NULL,
7386         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7387         .tokens = {
7388                 (void *)&cmd_setvf_traffic_set,
7389                 (void *)&cmd_setvf_traffic_port,
7390                 (void *)&cmd_setvf_traffic_portid,
7391                 (void *)&cmd_setvf_traffic_vf,
7392                 (void *)&cmd_setvf_traffic_vfid,
7393                 (void *)&cmd_setvf_traffic_what,
7394                 (void *)&cmd_setvf_traffic_mode,
7395                 NULL,
7396         },
7397 };
7398
7399 /* *** CONFIGURE VF RECEIVE MODE *** */
7400 struct cmd_set_vf_rxmode {
7401         cmdline_fixed_string_t set;
7402         cmdline_fixed_string_t port;
7403         portid_t port_id;
7404         cmdline_fixed_string_t vf;
7405         uint8_t vf_id;
7406         cmdline_fixed_string_t what;
7407         cmdline_fixed_string_t mode;
7408         cmdline_fixed_string_t on;
7409 };
7410
7411 static void
7412 cmd_set_vf_rxmode_parsed(void *parsed_result,
7413                        __attribute__((unused)) struct cmdline *cl,
7414                        __attribute__((unused)) void *data)
7415 {
7416         int ret = -ENOTSUP;
7417         uint16_t rx_mode = 0;
7418         struct cmd_set_vf_rxmode *res = parsed_result;
7419
7420         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7421         if (!strcmp(res->what,"rxmode")) {
7422                 if (!strcmp(res->mode, "AUPE"))
7423                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7424                 else if (!strcmp(res->mode, "ROPE"))
7425                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7426                 else if (!strcmp(res->mode, "BAM"))
7427                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7428                 else if (!strncmp(res->mode, "MPE",3))
7429                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7430         }
7431
7432 #ifdef RTE_LIBRTE_IXGBE_PMD
7433         if (ret == -ENOTSUP)
7434                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7435                                                   rx_mode, (uint8_t)is_on);
7436 #endif
7437 #ifdef RTE_LIBRTE_BNXT_PMD
7438         if (ret == -ENOTSUP)
7439                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7440                                                  rx_mode, (uint8_t)is_on);
7441 #endif
7442         if (ret < 0)
7443                 printf("bad VF receive mode parameter, return code = %d \n",
7444                 ret);
7445 }
7446
7447 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7448         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7449                                  set, "set");
7450 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7451         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7452                                  port, "port");
7453 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7454         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7455                               port_id, UINT16);
7456 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7457         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7458                                  vf, "vf");
7459 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7460         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7461                               vf_id, UINT8);
7462 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7463         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7464                                  what, "rxmode");
7465 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7466         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7467                                  mode, "AUPE#ROPE#BAM#MPE");
7468 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7469         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7470                                  on, "on#off");
7471
7472 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7473         .f = cmd_set_vf_rxmode_parsed,
7474         .data = NULL,
7475         .help_str = "set port <port_id> vf <vf_id> rxmode "
7476                 "AUPE|ROPE|BAM|MPE on|off",
7477         .tokens = {
7478                 (void *)&cmd_set_vf_rxmode_set,
7479                 (void *)&cmd_set_vf_rxmode_port,
7480                 (void *)&cmd_set_vf_rxmode_portid,
7481                 (void *)&cmd_set_vf_rxmode_vf,
7482                 (void *)&cmd_set_vf_rxmode_vfid,
7483                 (void *)&cmd_set_vf_rxmode_what,
7484                 (void *)&cmd_set_vf_rxmode_mode,
7485                 (void *)&cmd_set_vf_rxmode_on,
7486                 NULL,
7487         },
7488 };
7489
7490 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7491 struct cmd_vf_mac_addr_result {
7492         cmdline_fixed_string_t mac_addr_cmd;
7493         cmdline_fixed_string_t what;
7494         cmdline_fixed_string_t port;
7495         uint16_t port_num;
7496         cmdline_fixed_string_t vf;
7497         uint8_t vf_num;
7498         struct ether_addr address;
7499 };
7500
7501 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7502                 __attribute__((unused)) struct cmdline *cl,
7503                 __attribute__((unused)) void *data)
7504 {
7505         struct cmd_vf_mac_addr_result *res = parsed_result;
7506         int ret = -ENOTSUP;
7507
7508         if (strcmp(res->what, "add") != 0)
7509                 return;
7510
7511 #ifdef RTE_LIBRTE_I40E_PMD
7512         if (ret == -ENOTSUP)
7513                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7514                                                    &res->address);
7515 #endif
7516 #ifdef RTE_LIBRTE_BNXT_PMD
7517         if (ret == -ENOTSUP)
7518                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7519                                                 res->vf_num);
7520 #endif
7521
7522         if(ret < 0)
7523                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7524
7525 }
7526
7527 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7528         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7529                                 mac_addr_cmd,"mac_addr");
7530 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7531         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7532                                 what,"add");
7533 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7534         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7535                                 port,"port");
7536 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7537         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7538                                 port_num, UINT16);
7539 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7540         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7541                                 vf,"vf");
7542 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7543         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7544                                 vf_num, UINT8);
7545 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7546         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7547                                 address);
7548
7549 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7550         .f = cmd_vf_mac_addr_parsed,
7551         .data = (void *)0,
7552         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7553                 "Add MAC address filtering for a VF on port_id",
7554         .tokens = {
7555                 (void *)&cmd_vf_mac_addr_cmd,
7556                 (void *)&cmd_vf_mac_addr_what,
7557                 (void *)&cmd_vf_mac_addr_port,
7558                 (void *)&cmd_vf_mac_addr_portnum,
7559                 (void *)&cmd_vf_mac_addr_vf,
7560                 (void *)&cmd_vf_mac_addr_vfnum,
7561                 (void *)&cmd_vf_mac_addr_addr,
7562                 NULL,
7563         },
7564 };
7565
7566 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7567 struct cmd_vf_rx_vlan_filter {
7568         cmdline_fixed_string_t rx_vlan;
7569         cmdline_fixed_string_t what;
7570         uint16_t vlan_id;
7571         cmdline_fixed_string_t port;
7572         portid_t port_id;
7573         cmdline_fixed_string_t vf;
7574         uint64_t vf_mask;
7575 };
7576
7577 static void
7578 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7579                           __attribute__((unused)) struct cmdline *cl,
7580                           __attribute__((unused)) void *data)
7581 {
7582         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7583         int ret = -ENOTSUP;
7584
7585         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7586
7587 #ifdef RTE_LIBRTE_IXGBE_PMD
7588         if (ret == -ENOTSUP)
7589                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7590                                 res->vlan_id, res->vf_mask, is_add);
7591 #endif
7592 #ifdef RTE_LIBRTE_I40E_PMD
7593         if (ret == -ENOTSUP)
7594                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7595                                 res->vlan_id, res->vf_mask, is_add);
7596 #endif
7597 #ifdef RTE_LIBRTE_BNXT_PMD
7598         if (ret == -ENOTSUP)
7599                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7600                                 res->vlan_id, res->vf_mask, is_add);
7601 #endif
7602
7603         switch (ret) {
7604         case 0:
7605                 break;
7606         case -EINVAL:
7607                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7608                                 res->vlan_id, res->vf_mask);
7609                 break;
7610         case -ENODEV:
7611                 printf("invalid port_id %d\n", res->port_id);
7612                 break;
7613         case -ENOTSUP:
7614                 printf("function not implemented or supported\n");
7615                 break;
7616         default:
7617                 printf("programming error: (%s)\n", strerror(-ret));
7618         }
7619 }
7620
7621 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7622         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7623                                  rx_vlan, "rx_vlan");
7624 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7625         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7626                                  what, "add#rm");
7627 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7628         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7629                               vlan_id, UINT16);
7630 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7631         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7632                                  port, "port");
7633 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7634         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7635                               port_id, UINT16);
7636 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7637         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7638                                  vf, "vf");
7639 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7640         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7641                               vf_mask, UINT64);
7642
7643 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7644         .f = cmd_vf_rx_vlan_filter_parsed,
7645         .data = NULL,
7646         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7647                 "(vf_mask = hexadecimal VF mask)",
7648         .tokens = {
7649                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7650                 (void *)&cmd_vf_rx_vlan_filter_what,
7651                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7652                 (void *)&cmd_vf_rx_vlan_filter_port,
7653                 (void *)&cmd_vf_rx_vlan_filter_portid,
7654                 (void *)&cmd_vf_rx_vlan_filter_vf,
7655                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7656                 NULL,
7657         },
7658 };
7659
7660 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7661 struct cmd_queue_rate_limit_result {
7662         cmdline_fixed_string_t set;
7663         cmdline_fixed_string_t port;
7664         uint16_t port_num;
7665         cmdline_fixed_string_t queue;
7666         uint8_t queue_num;
7667         cmdline_fixed_string_t rate;
7668         uint16_t rate_num;
7669 };
7670
7671 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7672                 __attribute__((unused)) struct cmdline *cl,
7673                 __attribute__((unused)) void *data)
7674 {
7675         struct cmd_queue_rate_limit_result *res = parsed_result;
7676         int ret = 0;
7677
7678         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7679                 && (strcmp(res->queue, "queue") == 0)
7680                 && (strcmp(res->rate, "rate") == 0))
7681                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7682                                         res->rate_num);
7683         if (ret < 0)
7684                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7685
7686 }
7687
7688 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7689         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7690                                 set, "set");
7691 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7692         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7693                                 port, "port");
7694 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7695         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7696                                 port_num, UINT16);
7697 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7698         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7699                                 queue, "queue");
7700 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7701         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7702                                 queue_num, UINT8);
7703 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7704         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7705                                 rate, "rate");
7706 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7707         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7708                                 rate_num, UINT16);
7709
7710 cmdline_parse_inst_t cmd_queue_rate_limit = {
7711         .f = cmd_queue_rate_limit_parsed,
7712         .data = (void *)0,
7713         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7714                 "Set rate limit for a queue on port_id",
7715         .tokens = {
7716                 (void *)&cmd_queue_rate_limit_set,
7717                 (void *)&cmd_queue_rate_limit_port,
7718                 (void *)&cmd_queue_rate_limit_portnum,
7719                 (void *)&cmd_queue_rate_limit_queue,
7720                 (void *)&cmd_queue_rate_limit_queuenum,
7721                 (void *)&cmd_queue_rate_limit_rate,
7722                 (void *)&cmd_queue_rate_limit_ratenum,
7723                 NULL,
7724         },
7725 };
7726
7727 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7728 struct cmd_vf_rate_limit_result {
7729         cmdline_fixed_string_t set;
7730         cmdline_fixed_string_t port;
7731         uint16_t port_num;
7732         cmdline_fixed_string_t vf;
7733         uint8_t vf_num;
7734         cmdline_fixed_string_t rate;
7735         uint16_t rate_num;
7736         cmdline_fixed_string_t q_msk;
7737         uint64_t q_msk_val;
7738 };
7739
7740 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7741                 __attribute__((unused)) struct cmdline *cl,
7742                 __attribute__((unused)) void *data)
7743 {
7744         struct cmd_vf_rate_limit_result *res = parsed_result;
7745         int ret = 0;
7746
7747         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7748                 && (strcmp(res->vf, "vf") == 0)
7749                 && (strcmp(res->rate, "rate") == 0)
7750                 && (strcmp(res->q_msk, "queue_mask") == 0))
7751                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7752                                         res->rate_num, res->q_msk_val);
7753         if (ret < 0)
7754                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7755
7756 }
7757
7758 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7759         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7760                                 set, "set");
7761 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7762         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7763                                 port, "port");
7764 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7765         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7766                                 port_num, UINT16);
7767 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7768         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7769                                 vf, "vf");
7770 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7771         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7772                                 vf_num, UINT8);
7773 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7774         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7775                                 rate, "rate");
7776 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7777         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7778                                 rate_num, UINT16);
7779 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7780         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7781                                 q_msk, "queue_mask");
7782 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7783         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7784                                 q_msk_val, UINT64);
7785
7786 cmdline_parse_inst_t cmd_vf_rate_limit = {
7787         .f = cmd_vf_rate_limit_parsed,
7788         .data = (void *)0,
7789         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7790                 "queue_mask <queue_mask_value>: "
7791                 "Set rate limit for queues of VF on port_id",
7792         .tokens = {
7793                 (void *)&cmd_vf_rate_limit_set,
7794                 (void *)&cmd_vf_rate_limit_port,
7795                 (void *)&cmd_vf_rate_limit_portnum,
7796                 (void *)&cmd_vf_rate_limit_vf,
7797                 (void *)&cmd_vf_rate_limit_vfnum,
7798                 (void *)&cmd_vf_rate_limit_rate,
7799                 (void *)&cmd_vf_rate_limit_ratenum,
7800                 (void *)&cmd_vf_rate_limit_q_msk,
7801                 (void *)&cmd_vf_rate_limit_q_msk_val,
7802                 NULL,
7803         },
7804 };
7805
7806 /* *** ADD TUNNEL FILTER OF A PORT *** */
7807 struct cmd_tunnel_filter_result {
7808         cmdline_fixed_string_t cmd;
7809         cmdline_fixed_string_t what;
7810         portid_t port_id;
7811         struct ether_addr outer_mac;
7812         struct ether_addr inner_mac;
7813         cmdline_ipaddr_t ip_value;
7814         uint16_t inner_vlan;
7815         cmdline_fixed_string_t tunnel_type;
7816         cmdline_fixed_string_t filter_type;
7817         uint32_t tenant_id;
7818         uint16_t queue_num;
7819 };
7820
7821 static void
7822 cmd_tunnel_filter_parsed(void *parsed_result,
7823                           __attribute__((unused)) struct cmdline *cl,
7824                           __attribute__((unused)) void *data)
7825 {
7826         struct cmd_tunnel_filter_result *res = parsed_result;
7827         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7828         int ret = 0;
7829
7830         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7831
7832         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7833         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7834         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7835
7836         if (res->ip_value.family == AF_INET) {
7837                 tunnel_filter_conf.ip_addr.ipv4_addr =
7838                         res->ip_value.addr.ipv4.s_addr;
7839                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7840         } else {
7841                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7842                         &(res->ip_value.addr.ipv6),
7843                         sizeof(struct in6_addr));
7844                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7845         }
7846
7847         if (!strcmp(res->filter_type, "imac-ivlan"))
7848                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7849         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7850                 tunnel_filter_conf.filter_type =
7851                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7852         else if (!strcmp(res->filter_type, "imac-tenid"))
7853                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7854         else if (!strcmp(res->filter_type, "imac"))
7855                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7856         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7857                 tunnel_filter_conf.filter_type =
7858                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7859         else if (!strcmp(res->filter_type, "oip"))
7860                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7861         else if (!strcmp(res->filter_type, "iip"))
7862                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7863         else {
7864                 printf("The filter type is not supported");
7865                 return;
7866         }
7867
7868         if (!strcmp(res->tunnel_type, "vxlan"))
7869                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7870         else if (!strcmp(res->tunnel_type, "nvgre"))
7871                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7872         else if (!strcmp(res->tunnel_type, "ipingre"))
7873                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7874         else {
7875                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7876                 return;
7877         }
7878
7879         tunnel_filter_conf.tenant_id = res->tenant_id;
7880         tunnel_filter_conf.queue_id = res->queue_num;
7881         if (!strcmp(res->what, "add"))
7882                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7883                                         RTE_ETH_FILTER_TUNNEL,
7884                                         RTE_ETH_FILTER_ADD,
7885                                         &tunnel_filter_conf);
7886         else
7887                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7888                                         RTE_ETH_FILTER_TUNNEL,
7889                                         RTE_ETH_FILTER_DELETE,
7890                                         &tunnel_filter_conf);
7891         if (ret < 0)
7892                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7893                                 strerror(-ret));
7894
7895 }
7896 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7897         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7898         cmd, "tunnel_filter");
7899 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7900         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7901         what, "add#rm");
7902 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7903         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7904         port_id, UINT16);
7905 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7906         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7907         outer_mac);
7908 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7909         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7910         inner_mac);
7911 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7912         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7913         inner_vlan, UINT16);
7914 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7915         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7916         ip_value);
7917 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7918         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7919         tunnel_type, "vxlan#nvgre#ipingre");
7920
7921 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7922         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7923         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7924                 "imac#omac-imac-tenid");
7925 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7926         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7927         tenant_id, UINT32);
7928 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7929         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7930         queue_num, UINT16);
7931
7932 cmdline_parse_inst_t cmd_tunnel_filter = {
7933         .f = cmd_tunnel_filter_parsed,
7934         .data = (void *)0,
7935         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7936                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7937                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7938                 "<queue_id>: Add/Rm tunnel filter of a port",
7939         .tokens = {
7940                 (void *)&cmd_tunnel_filter_cmd,
7941                 (void *)&cmd_tunnel_filter_what,
7942                 (void *)&cmd_tunnel_filter_port_id,
7943                 (void *)&cmd_tunnel_filter_outer_mac,
7944                 (void *)&cmd_tunnel_filter_inner_mac,
7945                 (void *)&cmd_tunnel_filter_ip_value,
7946                 (void *)&cmd_tunnel_filter_innner_vlan,
7947                 (void *)&cmd_tunnel_filter_tunnel_type,
7948                 (void *)&cmd_tunnel_filter_filter_type,
7949                 (void *)&cmd_tunnel_filter_tenant_id,
7950                 (void *)&cmd_tunnel_filter_queue_num,
7951                 NULL,
7952         },
7953 };
7954
7955 /* *** CONFIGURE TUNNEL UDP PORT *** */
7956 struct cmd_tunnel_udp_config {
7957         cmdline_fixed_string_t cmd;
7958         cmdline_fixed_string_t what;
7959         uint16_t udp_port;
7960         portid_t port_id;
7961 };
7962
7963 static void
7964 cmd_tunnel_udp_config_parsed(void *parsed_result,
7965                           __attribute__((unused)) struct cmdline *cl,
7966                           __attribute__((unused)) void *data)
7967 {
7968         struct cmd_tunnel_udp_config *res = parsed_result;
7969         struct rte_eth_udp_tunnel tunnel_udp;
7970         int ret;
7971
7972         tunnel_udp.udp_port = res->udp_port;
7973
7974         if (!strcmp(res->cmd, "rx_vxlan_port"))
7975                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7976
7977         if (!strcmp(res->what, "add"))
7978                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7979                                                       &tunnel_udp);
7980         else
7981                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7982                                                          &tunnel_udp);
7983
7984         if (ret < 0)
7985                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7986 }
7987
7988 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7989         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7990                                 cmd, "rx_vxlan_port");
7991 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7992         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7993                                 what, "add#rm");
7994 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7995         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7996                                 udp_port, UINT16);
7997 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7998         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7999                                 port_id, UINT16);
8000
8001 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8002         .f = cmd_tunnel_udp_config_parsed,
8003         .data = (void *)0,
8004         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8005                 "Add/Remove a tunneling UDP port filter",
8006         .tokens = {
8007                 (void *)&cmd_tunnel_udp_config_cmd,
8008                 (void *)&cmd_tunnel_udp_config_what,
8009                 (void *)&cmd_tunnel_udp_config_udp_port,
8010                 (void *)&cmd_tunnel_udp_config_port_id,
8011                 NULL,
8012         },
8013 };
8014
8015 /* *** GLOBAL CONFIG *** */
8016 struct cmd_global_config_result {
8017         cmdline_fixed_string_t cmd;
8018         portid_t port_id;
8019         cmdline_fixed_string_t cfg_type;
8020         uint8_t len;
8021 };
8022
8023 static void
8024 cmd_global_config_parsed(void *parsed_result,
8025                          __attribute__((unused)) struct cmdline *cl,
8026                          __attribute__((unused)) void *data)
8027 {
8028         struct cmd_global_config_result *res = parsed_result;
8029         struct rte_eth_global_cfg conf;
8030         int ret;
8031
8032         memset(&conf, 0, sizeof(conf));
8033         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8034         conf.cfg.gre_key_len = res->len;
8035         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8036                                       RTE_ETH_FILTER_SET, &conf);
8037         if (ret != 0)
8038                 printf("Global config error\n");
8039 }
8040
8041 cmdline_parse_token_string_t cmd_global_config_cmd =
8042         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8043                 "global_config");
8044 cmdline_parse_token_num_t cmd_global_config_port_id =
8045         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8046                                UINT16);
8047 cmdline_parse_token_string_t cmd_global_config_type =
8048         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8049                 cfg_type, "gre-key-len");
8050 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8051         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8052                 len, UINT8);
8053
8054 cmdline_parse_inst_t cmd_global_config = {
8055         .f = cmd_global_config_parsed,
8056         .data = (void *)NULL,
8057         .help_str = "global_config <port_id> gre-key-len <key_len>",
8058         .tokens = {
8059                 (void *)&cmd_global_config_cmd,
8060                 (void *)&cmd_global_config_port_id,
8061                 (void *)&cmd_global_config_type,
8062                 (void *)&cmd_global_config_gre_key_len,
8063                 NULL,
8064         },
8065 };
8066
8067 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8068 struct cmd_set_mirror_mask_result {
8069         cmdline_fixed_string_t set;
8070         cmdline_fixed_string_t port;
8071         portid_t port_id;
8072         cmdline_fixed_string_t mirror;
8073         uint8_t rule_id;
8074         cmdline_fixed_string_t what;
8075         cmdline_fixed_string_t value;
8076         cmdline_fixed_string_t dstpool;
8077         uint8_t dstpool_id;
8078         cmdline_fixed_string_t on;
8079 };
8080
8081 cmdline_parse_token_string_t cmd_mirror_mask_set =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8083                                 set, "set");
8084 cmdline_parse_token_string_t cmd_mirror_mask_port =
8085         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8086                                 port, "port");
8087 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8088         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8089                                 port_id, UINT16);
8090 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8091         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8092                                 mirror, "mirror-rule");
8093 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8094         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8095                                 rule_id, UINT8);
8096 cmdline_parse_token_string_t cmd_mirror_mask_what =
8097         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8098                                 what, "pool-mirror-up#pool-mirror-down"
8099                                       "#vlan-mirror");
8100 cmdline_parse_token_string_t cmd_mirror_mask_value =
8101         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8102                                 value, NULL);
8103 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8104         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8105                                 dstpool, "dst-pool");
8106 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8107         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8108                                 dstpool_id, UINT8);
8109 cmdline_parse_token_string_t cmd_mirror_mask_on =
8110         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8111                                 on, "on#off");
8112
8113 static void
8114 cmd_set_mirror_mask_parsed(void *parsed_result,
8115                        __attribute__((unused)) struct cmdline *cl,
8116                        __attribute__((unused)) void *data)
8117 {
8118         int ret,nb_item,i;
8119         struct cmd_set_mirror_mask_result *res = parsed_result;
8120         struct rte_eth_mirror_conf mr_conf;
8121
8122         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8123
8124         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8125
8126         mr_conf.dst_pool = res->dstpool_id;
8127
8128         if (!strcmp(res->what, "pool-mirror-up")) {
8129                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8130                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8131         } else if (!strcmp(res->what, "pool-mirror-down")) {
8132                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8133                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8134         } else if (!strcmp(res->what, "vlan-mirror")) {
8135                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8136                 nb_item = parse_item_list(res->value, "vlan",
8137                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8138                 if (nb_item <= 0)
8139                         return;
8140
8141                 for (i = 0; i < nb_item; i++) {
8142                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8143                                 printf("Invalid vlan_id: must be < 4096\n");
8144                                 return;
8145                         }
8146
8147                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8148                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8149                 }
8150         }
8151
8152         if (!strcmp(res->on, "on"))
8153                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8154                                                 res->rule_id, 1);
8155         else
8156                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8157                                                 res->rule_id, 0);
8158         if (ret < 0)
8159                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8160 }
8161
8162 cmdline_parse_inst_t cmd_set_mirror_mask = {
8163                 .f = cmd_set_mirror_mask_parsed,
8164                 .data = NULL,
8165                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8166                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8167                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8168                 .tokens = {
8169                         (void *)&cmd_mirror_mask_set,
8170                         (void *)&cmd_mirror_mask_port,
8171                         (void *)&cmd_mirror_mask_portid,
8172                         (void *)&cmd_mirror_mask_mirror,
8173                         (void *)&cmd_mirror_mask_ruleid,
8174                         (void *)&cmd_mirror_mask_what,
8175                         (void *)&cmd_mirror_mask_value,
8176                         (void *)&cmd_mirror_mask_dstpool,
8177                         (void *)&cmd_mirror_mask_poolid,
8178                         (void *)&cmd_mirror_mask_on,
8179                         NULL,
8180                 },
8181 };
8182
8183 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8184 struct cmd_set_mirror_link_result {
8185         cmdline_fixed_string_t set;
8186         cmdline_fixed_string_t port;
8187         portid_t port_id;
8188         cmdline_fixed_string_t mirror;
8189         uint8_t rule_id;
8190         cmdline_fixed_string_t what;
8191         cmdline_fixed_string_t dstpool;
8192         uint8_t dstpool_id;
8193         cmdline_fixed_string_t on;
8194 };
8195
8196 cmdline_parse_token_string_t cmd_mirror_link_set =
8197         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8198                                  set, "set");
8199 cmdline_parse_token_string_t cmd_mirror_link_port =
8200         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8201                                 port, "port");
8202 cmdline_parse_token_num_t cmd_mirror_link_portid =
8203         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8204                                 port_id, UINT16);
8205 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8206         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8207                                 mirror, "mirror-rule");
8208 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8209         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8210                             rule_id, UINT8);
8211 cmdline_parse_token_string_t cmd_mirror_link_what =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8213                                 what, "uplink-mirror#downlink-mirror");
8214 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8216                                 dstpool, "dst-pool");
8217 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8218         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8219                                 dstpool_id, UINT8);
8220 cmdline_parse_token_string_t cmd_mirror_link_on =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8222                                 on, "on#off");
8223
8224 static void
8225 cmd_set_mirror_link_parsed(void *parsed_result,
8226                        __attribute__((unused)) struct cmdline *cl,
8227                        __attribute__((unused)) void *data)
8228 {
8229         int ret;
8230         struct cmd_set_mirror_link_result *res = parsed_result;
8231         struct rte_eth_mirror_conf mr_conf;
8232
8233         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8234         if (!strcmp(res->what, "uplink-mirror"))
8235                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8236         else
8237                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8238
8239         mr_conf.dst_pool = res->dstpool_id;
8240
8241         if (!strcmp(res->on, "on"))
8242                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8243                                                 res->rule_id, 1);
8244         else
8245                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8246                                                 res->rule_id, 0);
8247
8248         /* check the return value and print it if is < 0 */
8249         if (ret < 0)
8250                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8251
8252 }
8253
8254 cmdline_parse_inst_t cmd_set_mirror_link = {
8255                 .f = cmd_set_mirror_link_parsed,
8256                 .data = NULL,
8257                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8258                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8259                 .tokens = {
8260                         (void *)&cmd_mirror_link_set,
8261                         (void *)&cmd_mirror_link_port,
8262                         (void *)&cmd_mirror_link_portid,
8263                         (void *)&cmd_mirror_link_mirror,
8264                         (void *)&cmd_mirror_link_ruleid,
8265                         (void *)&cmd_mirror_link_what,
8266                         (void *)&cmd_mirror_link_dstpool,
8267                         (void *)&cmd_mirror_link_poolid,
8268                         (void *)&cmd_mirror_link_on,
8269                         NULL,
8270                 },
8271 };
8272
8273 /* *** RESET VM MIRROR RULE *** */
8274 struct cmd_rm_mirror_rule_result {
8275         cmdline_fixed_string_t reset;
8276         cmdline_fixed_string_t port;
8277         portid_t port_id;
8278         cmdline_fixed_string_t mirror;
8279         uint8_t rule_id;
8280 };
8281
8282 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8283         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8284                                  reset, "reset");
8285 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8286         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8287                                 port, "port");
8288 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8289         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8290                                 port_id, UINT16);
8291 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8292         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8293                                 mirror, "mirror-rule");
8294 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8295         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8296                                 rule_id, UINT8);
8297
8298 static void
8299 cmd_reset_mirror_rule_parsed(void *parsed_result,
8300                        __attribute__((unused)) struct cmdline *cl,
8301                        __attribute__((unused)) void *data)
8302 {
8303         int ret;
8304         struct cmd_set_mirror_link_result *res = parsed_result;
8305         /* check rule_id */
8306         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8307         if(ret < 0)
8308                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8309 }
8310
8311 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8312                 .f = cmd_reset_mirror_rule_parsed,
8313                 .data = NULL,
8314                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8315                 .tokens = {
8316                         (void *)&cmd_rm_mirror_rule_reset,
8317                         (void *)&cmd_rm_mirror_rule_port,
8318                         (void *)&cmd_rm_mirror_rule_portid,
8319                         (void *)&cmd_rm_mirror_rule_mirror,
8320                         (void *)&cmd_rm_mirror_rule_ruleid,
8321                         NULL,
8322                 },
8323 };
8324
8325 /* ******************************************************************************** */
8326
8327 struct cmd_dump_result {
8328         cmdline_fixed_string_t dump;
8329 };
8330
8331 static void
8332 dump_struct_sizes(void)
8333 {
8334 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8335         DUMP_SIZE(struct rte_mbuf);
8336         DUMP_SIZE(struct rte_mempool);
8337         DUMP_SIZE(struct rte_ring);
8338 #undef DUMP_SIZE
8339 }
8340
8341 static void cmd_dump_parsed(void *parsed_result,
8342                             __attribute__((unused)) struct cmdline *cl,
8343                             __attribute__((unused)) void *data)
8344 {
8345         struct cmd_dump_result *res = parsed_result;
8346
8347         if (!strcmp(res->dump, "dump_physmem"))
8348                 rte_dump_physmem_layout(stdout);
8349         else if (!strcmp(res->dump, "dump_memzone"))
8350                 rte_memzone_dump(stdout);
8351         else if (!strcmp(res->dump, "dump_struct_sizes"))
8352                 dump_struct_sizes();
8353         else if (!strcmp(res->dump, "dump_ring"))
8354                 rte_ring_list_dump(stdout);
8355         else if (!strcmp(res->dump, "dump_mempool"))
8356                 rte_mempool_list_dump(stdout);
8357         else if (!strcmp(res->dump, "dump_devargs"))
8358                 rte_eal_devargs_dump(stdout);
8359         else if (!strcmp(res->dump, "dump_log_types"))
8360                 rte_log_dump(stdout);
8361 }
8362
8363 cmdline_parse_token_string_t cmd_dump_dump =
8364         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8365                 "dump_physmem#"
8366                 "dump_memzone#"
8367                 "dump_struct_sizes#"
8368                 "dump_ring#"
8369                 "dump_mempool#"
8370                 "dump_devargs#"
8371                 "dump_log_types");
8372
8373 cmdline_parse_inst_t cmd_dump = {
8374         .f = cmd_dump_parsed,  /* function to call */
8375         .data = NULL,      /* 2nd arg of func */
8376         .help_str = "Dump status",
8377         .tokens = {        /* token list, NULL terminated */
8378                 (void *)&cmd_dump_dump,
8379                 NULL,
8380         },
8381 };
8382
8383 /* ******************************************************************************** */
8384
8385 struct cmd_dump_one_result {
8386         cmdline_fixed_string_t dump;
8387         cmdline_fixed_string_t name;
8388 };
8389
8390 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8391                                 __attribute__((unused)) void *data)
8392 {
8393         struct cmd_dump_one_result *res = parsed_result;
8394
8395         if (!strcmp(res->dump, "dump_ring")) {
8396                 struct rte_ring *r;
8397                 r = rte_ring_lookup(res->name);
8398                 if (r == NULL) {
8399                         cmdline_printf(cl, "Cannot find ring\n");
8400                         return;
8401                 }
8402                 rte_ring_dump(stdout, r);
8403         } else if (!strcmp(res->dump, "dump_mempool")) {
8404                 struct rte_mempool *mp;
8405                 mp = rte_mempool_lookup(res->name);
8406                 if (mp == NULL) {
8407                         cmdline_printf(cl, "Cannot find mempool\n");
8408                         return;
8409                 }
8410                 rte_mempool_dump(stdout, mp);
8411         }
8412 }
8413
8414 cmdline_parse_token_string_t cmd_dump_one_dump =
8415         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8416                                  "dump_ring#dump_mempool");
8417
8418 cmdline_parse_token_string_t cmd_dump_one_name =
8419         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8420
8421 cmdline_parse_inst_t cmd_dump_one = {
8422         .f = cmd_dump_one_parsed,  /* function to call */
8423         .data = NULL,      /* 2nd arg of func */
8424         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8425         .tokens = {        /* token list, NULL terminated */
8426                 (void *)&cmd_dump_one_dump,
8427                 (void *)&cmd_dump_one_name,
8428                 NULL,
8429         },
8430 };
8431
8432 /* *** Add/Del syn filter *** */
8433 struct cmd_syn_filter_result {
8434         cmdline_fixed_string_t filter;
8435         portid_t port_id;
8436         cmdline_fixed_string_t ops;
8437         cmdline_fixed_string_t priority;
8438         cmdline_fixed_string_t high;
8439         cmdline_fixed_string_t queue;
8440         uint16_t queue_id;
8441 };
8442
8443 static void
8444 cmd_syn_filter_parsed(void *parsed_result,
8445                         __attribute__((unused)) struct cmdline *cl,
8446                         __attribute__((unused)) void *data)
8447 {
8448         struct cmd_syn_filter_result *res = parsed_result;
8449         struct rte_eth_syn_filter syn_filter;
8450         int ret = 0;
8451
8452         ret = rte_eth_dev_filter_supported(res->port_id,
8453                                         RTE_ETH_FILTER_SYN);
8454         if (ret < 0) {
8455                 printf("syn filter is not supported on port %u.\n",
8456                                 res->port_id);
8457                 return;
8458         }
8459
8460         memset(&syn_filter, 0, sizeof(syn_filter));
8461
8462         if (!strcmp(res->ops, "add")) {
8463                 if (!strcmp(res->high, "high"))
8464                         syn_filter.hig_pri = 1;
8465                 else
8466                         syn_filter.hig_pri = 0;
8467
8468                 syn_filter.queue = res->queue_id;
8469                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8470                                                 RTE_ETH_FILTER_SYN,
8471                                                 RTE_ETH_FILTER_ADD,
8472                                                 &syn_filter);
8473         } else
8474                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8475                                                 RTE_ETH_FILTER_SYN,
8476                                                 RTE_ETH_FILTER_DELETE,
8477                                                 &syn_filter);
8478
8479         if (ret < 0)
8480                 printf("syn filter programming error: (%s)\n",
8481                                 strerror(-ret));
8482 }
8483
8484 cmdline_parse_token_string_t cmd_syn_filter_filter =
8485         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8486         filter, "syn_filter");
8487 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8488         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8489         port_id, UINT16);
8490 cmdline_parse_token_string_t cmd_syn_filter_ops =
8491         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8492         ops, "add#del");
8493 cmdline_parse_token_string_t cmd_syn_filter_priority =
8494         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8495                                 priority, "priority");
8496 cmdline_parse_token_string_t cmd_syn_filter_high =
8497         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8498                                 high, "high#low");
8499 cmdline_parse_token_string_t cmd_syn_filter_queue =
8500         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8501                                 queue, "queue");
8502 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8503         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8504                                 queue_id, UINT16);
8505
8506 cmdline_parse_inst_t cmd_syn_filter = {
8507         .f = cmd_syn_filter_parsed,
8508         .data = NULL,
8509         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8510                 "<queue_id>: Add/Delete syn filter",
8511         .tokens = {
8512                 (void *)&cmd_syn_filter_filter,
8513                 (void *)&cmd_syn_filter_port_id,
8514                 (void *)&cmd_syn_filter_ops,
8515                 (void *)&cmd_syn_filter_priority,
8516                 (void *)&cmd_syn_filter_high,
8517                 (void *)&cmd_syn_filter_queue,
8518                 (void *)&cmd_syn_filter_queue_id,
8519                 NULL,
8520         },
8521 };
8522
8523 /* *** queue region set *** */
8524 struct cmd_queue_region_result {
8525         cmdline_fixed_string_t set;
8526         cmdline_fixed_string_t port;
8527         portid_t port_id;
8528         cmdline_fixed_string_t cmd;
8529         cmdline_fixed_string_t region;
8530         uint8_t  region_id;
8531         cmdline_fixed_string_t queue_start_index;
8532         uint8_t  queue_id;
8533         cmdline_fixed_string_t queue_num;
8534         uint8_t  queue_num_value;
8535 };
8536
8537 static void
8538 cmd_queue_region_parsed(void *parsed_result,
8539                         __attribute__((unused)) struct cmdline *cl,
8540                         __attribute__((unused)) void *data)
8541 {
8542         struct cmd_queue_region_result *res = parsed_result;
8543         int ret = -ENOTSUP;
8544 #ifdef RTE_LIBRTE_I40E_PMD
8545         struct rte_pmd_i40e_queue_region_conf region_conf;
8546         enum rte_pmd_i40e_queue_region_op op_type;
8547 #endif
8548
8549         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8550                 return;
8551
8552 #ifdef RTE_LIBRTE_I40E_PMD
8553         memset(&region_conf, 0, sizeof(region_conf));
8554         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8555         region_conf.region_id = res->region_id;
8556         region_conf.queue_num = res->queue_num_value;
8557         region_conf.queue_start_index = res->queue_id;
8558
8559         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8560                                 op_type, &region_conf);
8561 #endif
8562
8563         switch (ret) {
8564         case 0:
8565                 break;
8566         case -ENOTSUP:
8567                 printf("function not implemented or supported\n");
8568                 break;
8569         default:
8570                 printf("queue region config error: (%s)\n", strerror(-ret));
8571         }
8572 }
8573
8574 cmdline_parse_token_string_t cmd_queue_region_set =
8575 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8576                 set, "set");
8577 cmdline_parse_token_string_t cmd_queue_region_port =
8578         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8579 cmdline_parse_token_num_t cmd_queue_region_port_id =
8580         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8581                                 port_id, UINT16);
8582 cmdline_parse_token_string_t cmd_queue_region_cmd =
8583         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8584                                  cmd, "queue-region");
8585 cmdline_parse_token_string_t cmd_queue_region_id =
8586         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8587                                 region, "region_id");
8588 cmdline_parse_token_num_t cmd_queue_region_index =
8589         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8590                                 region_id, UINT8);
8591 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8592         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8593                                 queue_start_index, "queue_start_index");
8594 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8595         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8596                                 queue_id, UINT8);
8597 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8598         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8599                                 queue_num, "queue_num");
8600 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8601         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8602                                 queue_num_value, UINT8);
8603
8604 cmdline_parse_inst_t cmd_queue_region = {
8605         .f = cmd_queue_region_parsed,
8606         .data = NULL,
8607         .help_str = "set port <port_id> queue-region region_id <value> "
8608                 "queue_start_index <value> queue_num <value>: Set a queue region",
8609         .tokens = {
8610                 (void *)&cmd_queue_region_set,
8611                 (void *)&cmd_queue_region_port,
8612                 (void *)&cmd_queue_region_port_id,
8613                 (void *)&cmd_queue_region_cmd,
8614                 (void *)&cmd_queue_region_id,
8615                 (void *)&cmd_queue_region_index,
8616                 (void *)&cmd_queue_region_queue_start_index,
8617                 (void *)&cmd_queue_region_queue_id,
8618                 (void *)&cmd_queue_region_queue_num,
8619                 (void *)&cmd_queue_region_queue_num_value,
8620                 NULL,
8621         },
8622 };
8623
8624 /* *** queue region and flowtype set *** */
8625 struct cmd_region_flowtype_result {
8626         cmdline_fixed_string_t set;
8627         cmdline_fixed_string_t port;
8628         portid_t port_id;
8629         cmdline_fixed_string_t cmd;
8630         cmdline_fixed_string_t region;
8631         uint8_t  region_id;
8632         cmdline_fixed_string_t flowtype;
8633         uint8_t  flowtype_id;
8634 };
8635
8636 static void
8637 cmd_region_flowtype_parsed(void *parsed_result,
8638                         __attribute__((unused)) struct cmdline *cl,
8639                         __attribute__((unused)) void *data)
8640 {
8641         struct cmd_region_flowtype_result *res = parsed_result;
8642         int ret = -ENOTSUP;
8643 #ifdef RTE_LIBRTE_I40E_PMD
8644         struct rte_pmd_i40e_queue_region_conf region_conf;
8645         enum rte_pmd_i40e_queue_region_op op_type;
8646 #endif
8647
8648         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8649                 return;
8650
8651 #ifdef RTE_LIBRTE_I40E_PMD
8652         memset(&region_conf, 0, sizeof(region_conf));
8653
8654         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8655         region_conf.region_id = res->region_id;
8656         region_conf.hw_flowtype = res->flowtype_id;
8657
8658         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8659                         op_type, &region_conf);
8660 #endif
8661
8662         switch (ret) {
8663         case 0:
8664                 break;
8665         case -ENOTSUP:
8666                 printf("function not implemented or supported\n");
8667                 break;
8668         default:
8669                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8670         }
8671 }
8672
8673 cmdline_parse_token_string_t cmd_region_flowtype_set =
8674 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8675                                 set, "set");
8676 cmdline_parse_token_string_t cmd_region_flowtype_port =
8677         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8678                                 port, "port");
8679 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8680         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8681                                 port_id, UINT16);
8682 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8683         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8684                                 cmd, "queue-region");
8685 cmdline_parse_token_string_t cmd_region_flowtype_index =
8686         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8687                                 region, "region_id");
8688 cmdline_parse_token_num_t cmd_region_flowtype_id =
8689         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8690                                 region_id, UINT8);
8691 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8692         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8693                                 flowtype, "flowtype");
8694 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8695         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8696                                 flowtype_id, UINT8);
8697 cmdline_parse_inst_t cmd_region_flowtype = {
8698         .f = cmd_region_flowtype_parsed,
8699         .data = NULL,
8700         .help_str = "set port <port_id> queue-region region_id <value> "
8701                 "flowtype <value>: Set a flowtype region index",
8702         .tokens = {
8703                 (void *)&cmd_region_flowtype_set,
8704                 (void *)&cmd_region_flowtype_port,
8705                 (void *)&cmd_region_flowtype_port_index,
8706                 (void *)&cmd_region_flowtype_cmd,
8707                 (void *)&cmd_region_flowtype_index,
8708                 (void *)&cmd_region_flowtype_id,
8709                 (void *)&cmd_region_flowtype_flow_index,
8710                 (void *)&cmd_region_flowtype_flow_id,
8711                 NULL,
8712         },
8713 };
8714
8715 /* *** User Priority (UP) to queue region (region_id) set *** */
8716 struct cmd_user_priority_region_result {
8717         cmdline_fixed_string_t set;
8718         cmdline_fixed_string_t port;
8719         portid_t port_id;
8720         cmdline_fixed_string_t cmd;
8721         cmdline_fixed_string_t user_priority;
8722         uint8_t  user_priority_id;
8723         cmdline_fixed_string_t region;
8724         uint8_t  region_id;
8725 };
8726
8727 static void
8728 cmd_user_priority_region_parsed(void *parsed_result,
8729                         __attribute__((unused)) struct cmdline *cl,
8730                         __attribute__((unused)) void *data)
8731 {
8732         struct cmd_user_priority_region_result *res = parsed_result;
8733         int ret = -ENOTSUP;
8734 #ifdef RTE_LIBRTE_I40E_PMD
8735         struct rte_pmd_i40e_queue_region_conf region_conf;
8736         enum rte_pmd_i40e_queue_region_op op_type;
8737 #endif
8738
8739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8740                 return;
8741
8742 #ifdef RTE_LIBRTE_I40E_PMD
8743         memset(&region_conf, 0, sizeof(region_conf));
8744         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8745         region_conf.user_priority = res->user_priority_id;
8746         region_conf.region_id = res->region_id;
8747
8748         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8749                                 op_type, &region_conf);
8750 #endif
8751
8752         switch (ret) {
8753         case 0:
8754                 break;
8755         case -ENOTSUP:
8756                 printf("function not implemented or supported\n");
8757                 break;
8758         default:
8759                 printf("user_priority region config error: (%s)\n",
8760                                 strerror(-ret));
8761         }
8762 }
8763
8764 cmdline_parse_token_string_t cmd_user_priority_region_set =
8765         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8766                                 set, "set");
8767 cmdline_parse_token_string_t cmd_user_priority_region_port =
8768         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8769                                 port, "port");
8770 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8771         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8772                                 port_id, UINT16);
8773 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8774         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8775                                 cmd, "queue-region");
8776 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8777         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8778                                 user_priority, "UP");
8779 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8780         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8781                                 user_priority_id, UINT8);
8782 cmdline_parse_token_string_t cmd_user_priority_region_region =
8783         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8784                                 region, "region_id");
8785 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8786         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8787                                 region_id, UINT8);
8788
8789 cmdline_parse_inst_t cmd_user_priority_region = {
8790         .f = cmd_user_priority_region_parsed,
8791         .data = NULL,
8792         .help_str = "set port <port_id> queue-region UP <value> "
8793                 "region_id <value>: Set the mapping of User Priority (UP) "
8794                 "to queue region (region_id) ",
8795         .tokens = {
8796                 (void *)&cmd_user_priority_region_set,
8797                 (void *)&cmd_user_priority_region_port,
8798                 (void *)&cmd_user_priority_region_port_index,
8799                 (void *)&cmd_user_priority_region_cmd,
8800                 (void *)&cmd_user_priority_region_UP,
8801                 (void *)&cmd_user_priority_region_UP_id,
8802                 (void *)&cmd_user_priority_region_region,
8803                 (void *)&cmd_user_priority_region_region_id,
8804                 NULL,
8805         },
8806 };
8807
8808 /* *** flush all queue region related configuration *** */
8809 struct cmd_flush_queue_region_result {
8810         cmdline_fixed_string_t set;
8811         cmdline_fixed_string_t port;
8812         portid_t port_id;
8813         cmdline_fixed_string_t cmd;
8814         cmdline_fixed_string_t flush;
8815         cmdline_fixed_string_t what;
8816 };
8817
8818 static void
8819 cmd_flush_queue_region_parsed(void *parsed_result,
8820                         __attribute__((unused)) struct cmdline *cl,
8821                         __attribute__((unused)) void *data)
8822 {
8823         struct cmd_flush_queue_region_result *res = parsed_result;
8824         int ret = -ENOTSUP;
8825 #ifdef RTE_LIBRTE_I40E_PMD
8826         struct rte_pmd_i40e_queue_region_conf region_conf;
8827         enum rte_pmd_i40e_queue_region_op op_type;
8828 #endif
8829
8830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8831                 return;
8832
8833 #ifdef RTE_LIBRTE_I40E_PMD
8834         memset(&region_conf, 0, sizeof(region_conf));
8835
8836         if (strcmp(res->what, "on") == 0)
8837                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8838         else
8839                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8840
8841         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8842                                 op_type, &region_conf);
8843 #endif
8844
8845         switch (ret) {
8846         case 0:
8847                 break;
8848         case -ENOTSUP:
8849                 printf("function not implemented or supported\n");
8850                 break;
8851         default:
8852                 printf("queue region config flush error: (%s)\n",
8853                                 strerror(-ret));
8854         }
8855 }
8856
8857 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8858         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8859                                 set, "set");
8860 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8861         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8862                                 port, "port");
8863 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8864         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8865                                 port_id, UINT16);
8866 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8867         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8868                                 cmd, "queue-region");
8869 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8870         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8871                                 flush, "flush");
8872 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8873         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8874                                 what, "on#off");
8875
8876 cmdline_parse_inst_t cmd_flush_queue_region = {
8877         .f = cmd_flush_queue_region_parsed,
8878         .data = NULL,
8879         .help_str = "set port <port_id> queue-region flush on|off"
8880                 ": flush all queue region related configuration",
8881         .tokens = {
8882                 (void *)&cmd_flush_queue_region_set,
8883                 (void *)&cmd_flush_queue_region_port,
8884                 (void *)&cmd_flush_queue_region_port_index,
8885                 (void *)&cmd_flush_queue_region_cmd,
8886                 (void *)&cmd_flush_queue_region_flush,
8887                 (void *)&cmd_flush_queue_region_what,
8888                 NULL,
8889         },
8890 };
8891
8892 /* *** get all queue region related configuration info *** */
8893 struct cmd_show_queue_region_info {
8894         cmdline_fixed_string_t show;
8895         cmdline_fixed_string_t port;
8896         portid_t port_id;
8897         cmdline_fixed_string_t cmd;
8898 };
8899
8900 static void
8901 cmd_show_queue_region_info_parsed(void *parsed_result,
8902                         __attribute__((unused)) struct cmdline *cl,
8903                         __attribute__((unused)) void *data)
8904 {
8905         struct cmd_show_queue_region_info *res = parsed_result;
8906         int ret = -ENOTSUP;
8907 #ifdef RTE_LIBRTE_I40E_PMD
8908         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8909         enum rte_pmd_i40e_queue_region_op op_type;
8910 #endif
8911
8912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8913                 return;
8914
8915 #ifdef RTE_LIBRTE_I40E_PMD
8916         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8917
8918         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8919
8920         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8921                                         op_type, &rte_pmd_regions);
8922
8923         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8924 #endif
8925
8926         switch (ret) {
8927         case 0:
8928                 break;
8929         case -ENOTSUP:
8930                 printf("function not implemented or supported\n");
8931                 break;
8932         default:
8933                 printf("queue region config info show error: (%s)\n",
8934                                 strerror(-ret));
8935         }
8936 }
8937
8938 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
8939 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8940                                 show, "show");
8941 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
8942         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8943                                 port, "port");
8944 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
8945         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
8946                                 port_id, UINT16);
8947 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
8948         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
8949                                 cmd, "queue-region");
8950
8951 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
8952         .f = cmd_show_queue_region_info_parsed,
8953         .data = NULL,
8954         .help_str = "show port <port_id> queue-region"
8955                 ": show all queue region related configuration info",
8956         .tokens = {
8957                 (void *)&cmd_show_queue_region_info_get,
8958                 (void *)&cmd_show_queue_region_info_port,
8959                 (void *)&cmd_show_queue_region_info_port_index,
8960                 (void *)&cmd_show_queue_region_info_cmd,
8961                 NULL,
8962         },
8963 };
8964
8965 /* *** ADD/REMOVE A 2tuple FILTER *** */
8966 struct cmd_2tuple_filter_result {
8967         cmdline_fixed_string_t filter;
8968         portid_t port_id;
8969         cmdline_fixed_string_t ops;
8970         cmdline_fixed_string_t dst_port;
8971         uint16_t dst_port_value;
8972         cmdline_fixed_string_t protocol;
8973         uint8_t protocol_value;
8974         cmdline_fixed_string_t mask;
8975         uint8_t  mask_value;
8976         cmdline_fixed_string_t tcp_flags;
8977         uint8_t tcp_flags_value;
8978         cmdline_fixed_string_t priority;
8979         uint8_t  priority_value;
8980         cmdline_fixed_string_t queue;
8981         uint16_t  queue_id;
8982 };
8983
8984 static void
8985 cmd_2tuple_filter_parsed(void *parsed_result,
8986                         __attribute__((unused)) struct cmdline *cl,
8987                         __attribute__((unused)) void *data)
8988 {
8989         struct rte_eth_ntuple_filter filter;
8990         struct cmd_2tuple_filter_result *res = parsed_result;
8991         int ret = 0;
8992
8993         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8994         if (ret < 0) {
8995                 printf("ntuple filter is not supported on port %u.\n",
8996                         res->port_id);
8997                 return;
8998         }
8999
9000         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9001
9002         filter.flags = RTE_2TUPLE_FLAGS;
9003         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9004         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9005         filter.proto = res->protocol_value;
9006         filter.priority = res->priority_value;
9007         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9008                 printf("nonzero tcp_flags is only meaningful"
9009                         " when protocol is TCP.\n");
9010                 return;
9011         }
9012         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9013                 printf("invalid TCP flags.\n");
9014                 return;
9015         }
9016
9017         if (res->tcp_flags_value != 0) {
9018                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9019                 filter.tcp_flags = res->tcp_flags_value;
9020         }
9021
9022         /* need convert to big endian. */
9023         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9024         filter.queue = res->queue_id;
9025
9026         if (!strcmp(res->ops, "add"))
9027                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9028                                 RTE_ETH_FILTER_NTUPLE,
9029                                 RTE_ETH_FILTER_ADD,
9030                                 &filter);
9031         else
9032                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9033                                 RTE_ETH_FILTER_NTUPLE,
9034                                 RTE_ETH_FILTER_DELETE,
9035                                 &filter);
9036         if (ret < 0)
9037                 printf("2tuple filter programming error: (%s)\n",
9038                         strerror(-ret));
9039
9040 }
9041
9042 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9043         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9044                                  filter, "2tuple_filter");
9045 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9046         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9047                                 port_id, UINT16);
9048 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9049         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9050                                  ops, "add#del");
9051 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9052         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9053                                 dst_port, "dst_port");
9054 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9055         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9056                                 dst_port_value, UINT16);
9057 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9058         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9059                                 protocol, "protocol");
9060 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9061         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9062                                 protocol_value, UINT8);
9063 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9064         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9065                                 mask, "mask");
9066 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9067         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9068                                 mask_value, INT8);
9069 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9070         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9071                                 tcp_flags, "tcp_flags");
9072 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9073         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9074                                 tcp_flags_value, UINT8);
9075 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9076         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9077                                 priority, "priority");
9078 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9079         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9080                                 priority_value, UINT8);
9081 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9082         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9083                                 queue, "queue");
9084 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9085         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9086                                 queue_id, UINT16);
9087
9088 cmdline_parse_inst_t cmd_2tuple_filter = {
9089         .f = cmd_2tuple_filter_parsed,
9090         .data = NULL,
9091         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9092                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9093                 "<queue_id>: Add a 2tuple filter",
9094         .tokens = {
9095                 (void *)&cmd_2tuple_filter_filter,
9096                 (void *)&cmd_2tuple_filter_port_id,
9097                 (void *)&cmd_2tuple_filter_ops,
9098                 (void *)&cmd_2tuple_filter_dst_port,
9099                 (void *)&cmd_2tuple_filter_dst_port_value,
9100                 (void *)&cmd_2tuple_filter_protocol,
9101                 (void *)&cmd_2tuple_filter_protocol_value,
9102                 (void *)&cmd_2tuple_filter_mask,
9103                 (void *)&cmd_2tuple_filter_mask_value,
9104                 (void *)&cmd_2tuple_filter_tcp_flags,
9105                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9106                 (void *)&cmd_2tuple_filter_priority,
9107                 (void *)&cmd_2tuple_filter_priority_value,
9108                 (void *)&cmd_2tuple_filter_queue,
9109                 (void *)&cmd_2tuple_filter_queue_id,
9110                 NULL,
9111         },
9112 };
9113
9114 /* *** ADD/REMOVE A 5tuple FILTER *** */
9115 struct cmd_5tuple_filter_result {
9116         cmdline_fixed_string_t filter;
9117         portid_t port_id;
9118         cmdline_fixed_string_t ops;
9119         cmdline_fixed_string_t dst_ip;
9120         cmdline_ipaddr_t dst_ip_value;
9121         cmdline_fixed_string_t src_ip;
9122         cmdline_ipaddr_t src_ip_value;
9123         cmdline_fixed_string_t dst_port;
9124         uint16_t dst_port_value;
9125         cmdline_fixed_string_t src_port;
9126         uint16_t src_port_value;
9127         cmdline_fixed_string_t protocol;
9128         uint8_t protocol_value;
9129         cmdline_fixed_string_t mask;
9130         uint8_t  mask_value;
9131         cmdline_fixed_string_t tcp_flags;
9132         uint8_t tcp_flags_value;
9133         cmdline_fixed_string_t priority;
9134         uint8_t  priority_value;
9135         cmdline_fixed_string_t queue;
9136         uint16_t  queue_id;
9137 };
9138
9139 static void
9140 cmd_5tuple_filter_parsed(void *parsed_result,
9141                         __attribute__((unused)) struct cmdline *cl,
9142                         __attribute__((unused)) void *data)
9143 {
9144         struct rte_eth_ntuple_filter filter;
9145         struct cmd_5tuple_filter_result *res = parsed_result;
9146         int ret = 0;
9147
9148         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9149         if (ret < 0) {
9150                 printf("ntuple filter is not supported on port %u.\n",
9151                         res->port_id);
9152                 return;
9153         }
9154
9155         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9156
9157         filter.flags = RTE_5TUPLE_FLAGS;
9158         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9159         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9160         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9161         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9162         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9163         filter.proto = res->protocol_value;
9164         filter.priority = res->priority_value;
9165         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9166                 printf("nonzero tcp_flags is only meaningful"
9167                         " when protocol is TCP.\n");
9168                 return;
9169         }
9170         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9171                 printf("invalid TCP flags.\n");
9172                 return;
9173         }
9174
9175         if (res->tcp_flags_value != 0) {
9176                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9177                 filter.tcp_flags = res->tcp_flags_value;
9178         }
9179
9180         if (res->dst_ip_value.family == AF_INET)
9181                 /* no need to convert, already big endian. */
9182                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9183         else {
9184                 if (filter.dst_ip_mask == 0) {
9185                         printf("can not support ipv6 involved compare.\n");
9186                         return;
9187                 }
9188                 filter.dst_ip = 0;
9189         }
9190
9191         if (res->src_ip_value.family == AF_INET)
9192                 /* no need to convert, already big endian. */
9193                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9194         else {
9195                 if (filter.src_ip_mask == 0) {
9196                         printf("can not support ipv6 involved compare.\n");
9197                         return;
9198                 }
9199                 filter.src_ip = 0;
9200         }
9201         /* need convert to big endian. */
9202         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9203         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9204         filter.queue = res->queue_id;
9205
9206         if (!strcmp(res->ops, "add"))
9207                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9208                                 RTE_ETH_FILTER_NTUPLE,
9209                                 RTE_ETH_FILTER_ADD,
9210                                 &filter);
9211         else
9212                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9213                                 RTE_ETH_FILTER_NTUPLE,
9214                                 RTE_ETH_FILTER_DELETE,
9215                                 &filter);
9216         if (ret < 0)
9217                 printf("5tuple filter programming error: (%s)\n",
9218                         strerror(-ret));
9219 }
9220
9221 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9222         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9223                                  filter, "5tuple_filter");
9224 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9225         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9226                                 port_id, UINT16);
9227 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9228         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9229                                  ops, "add#del");
9230 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9231         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9232                                 dst_ip, "dst_ip");
9233 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9234         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9235                                 dst_ip_value);
9236 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9237         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9238                                 src_ip, "src_ip");
9239 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9240         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9241                                 src_ip_value);
9242 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9243         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9244                                 dst_port, "dst_port");
9245 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9246         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9247                                 dst_port_value, UINT16);
9248 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9249         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9250                                 src_port, "src_port");
9251 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9252         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9253                                 src_port_value, UINT16);
9254 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9255         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9256                                 protocol, "protocol");
9257 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9258         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9259                                 protocol_value, UINT8);
9260 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9261         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9262                                 mask, "mask");
9263 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9264         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9265                                 mask_value, INT8);
9266 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9267         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9268                                 tcp_flags, "tcp_flags");
9269 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9270         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9271                                 tcp_flags_value, UINT8);
9272 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9273         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9274                                 priority, "priority");
9275 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9276         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9277                                 priority_value, UINT8);
9278 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9279         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9280                                 queue, "queue");
9281 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9282         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9283                                 queue_id, UINT16);
9284
9285 cmdline_parse_inst_t cmd_5tuple_filter = {
9286         .f = cmd_5tuple_filter_parsed,
9287         .data = NULL,
9288         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9289                 "src_ip <value> dst_port <value> src_port <value> "
9290                 "protocol <value>  mask <value> tcp_flags <value> "
9291                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9292         .tokens = {
9293                 (void *)&cmd_5tuple_filter_filter,
9294                 (void *)&cmd_5tuple_filter_port_id,
9295                 (void *)&cmd_5tuple_filter_ops,
9296                 (void *)&cmd_5tuple_filter_dst_ip,
9297                 (void *)&cmd_5tuple_filter_dst_ip_value,
9298                 (void *)&cmd_5tuple_filter_src_ip,
9299                 (void *)&cmd_5tuple_filter_src_ip_value,
9300                 (void *)&cmd_5tuple_filter_dst_port,
9301                 (void *)&cmd_5tuple_filter_dst_port_value,
9302                 (void *)&cmd_5tuple_filter_src_port,
9303                 (void *)&cmd_5tuple_filter_src_port_value,
9304                 (void *)&cmd_5tuple_filter_protocol,
9305                 (void *)&cmd_5tuple_filter_protocol_value,
9306                 (void *)&cmd_5tuple_filter_mask,
9307                 (void *)&cmd_5tuple_filter_mask_value,
9308                 (void *)&cmd_5tuple_filter_tcp_flags,
9309                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9310                 (void *)&cmd_5tuple_filter_priority,
9311                 (void *)&cmd_5tuple_filter_priority_value,
9312                 (void *)&cmd_5tuple_filter_queue,
9313                 (void *)&cmd_5tuple_filter_queue_id,
9314                 NULL,
9315         },
9316 };
9317
9318 /* *** ADD/REMOVE A flex FILTER *** */
9319 struct cmd_flex_filter_result {
9320         cmdline_fixed_string_t filter;
9321         cmdline_fixed_string_t ops;
9322         portid_t port_id;
9323         cmdline_fixed_string_t len;
9324         uint8_t len_value;
9325         cmdline_fixed_string_t bytes;
9326         cmdline_fixed_string_t bytes_value;
9327         cmdline_fixed_string_t mask;
9328         cmdline_fixed_string_t mask_value;
9329         cmdline_fixed_string_t priority;
9330         uint8_t priority_value;
9331         cmdline_fixed_string_t queue;
9332         uint16_t queue_id;
9333 };
9334
9335 static int xdigit2val(unsigned char c)
9336 {
9337         int val;
9338         if (isdigit(c))
9339                 val = c - '0';
9340         else if (isupper(c))
9341                 val = c - 'A' + 10;
9342         else
9343                 val = c - 'a' + 10;
9344         return val;
9345 }
9346
9347 static void
9348 cmd_flex_filter_parsed(void *parsed_result,
9349                           __attribute__((unused)) struct cmdline *cl,
9350                           __attribute__((unused)) void *data)
9351 {
9352         int ret = 0;
9353         struct rte_eth_flex_filter filter;
9354         struct cmd_flex_filter_result *res = parsed_result;
9355         char *bytes_ptr, *mask_ptr;
9356         uint16_t len, i, j = 0;
9357         char c;
9358         int val;
9359         uint8_t byte = 0;
9360
9361         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9362                 printf("the len exceed the max length 128\n");
9363                 return;
9364         }
9365         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9366         filter.len = res->len_value;
9367         filter.priority = res->priority_value;
9368         filter.queue = res->queue_id;
9369         bytes_ptr = res->bytes_value;
9370         mask_ptr = res->mask_value;
9371
9372          /* translate bytes string to array. */
9373         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9374                 (bytes_ptr[1] == 'X')))
9375                 bytes_ptr += 2;
9376         len = strnlen(bytes_ptr, res->len_value * 2);
9377         if (len == 0 || (len % 8 != 0)) {
9378                 printf("please check len and bytes input\n");
9379                 return;
9380         }
9381         for (i = 0; i < len; i++) {
9382                 c = bytes_ptr[i];
9383                 if (isxdigit(c) == 0) {
9384                         /* invalid characters. */
9385                         printf("invalid input\n");
9386                         return;
9387                 }
9388                 val = xdigit2val(c);
9389                 if (i % 2) {
9390                         byte |= val;
9391                         filter.bytes[j] = byte;
9392                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9393                         j++;
9394                         byte = 0;
9395                 } else
9396                         byte |= val << 4;
9397         }
9398         printf("\n");
9399          /* translate mask string to uint8_t array. */
9400         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9401                 (mask_ptr[1] == 'X')))
9402                 mask_ptr += 2;
9403         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9404         if (len == 0) {
9405                 printf("invalid input\n");
9406                 return;
9407         }
9408         j = 0;
9409         byte = 0;
9410         for (i = 0; i < len; i++) {
9411                 c = mask_ptr[i];
9412                 if (isxdigit(c) == 0) {
9413                         /* invalid characters. */
9414                         printf("invalid input\n");
9415                         return;
9416                 }
9417                 val = xdigit2val(c);
9418                 if (i % 2) {
9419                         byte |= val;
9420                         filter.mask[j] = byte;
9421                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9422                         j++;
9423                         byte = 0;
9424                 } else
9425                         byte |= val << 4;
9426         }
9427         printf("\n");
9428
9429         if (!strcmp(res->ops, "add"))
9430                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9431                                 RTE_ETH_FILTER_FLEXIBLE,
9432                                 RTE_ETH_FILTER_ADD,
9433                                 &filter);
9434         else
9435                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9436                                 RTE_ETH_FILTER_FLEXIBLE,
9437                                 RTE_ETH_FILTER_DELETE,
9438                                 &filter);
9439
9440         if (ret < 0)
9441                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9442 }
9443
9444 cmdline_parse_token_string_t cmd_flex_filter_filter =
9445         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9446                                 filter, "flex_filter");
9447 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9448         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9449                                 port_id, UINT16);
9450 cmdline_parse_token_string_t cmd_flex_filter_ops =
9451         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9452                                 ops, "add#del");
9453 cmdline_parse_token_string_t cmd_flex_filter_len =
9454         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9455                                 len, "len");
9456 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9457         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9458                                 len_value, UINT8);
9459 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9460         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9461                                 bytes, "bytes");
9462 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9463         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9464                                 bytes_value, NULL);
9465 cmdline_parse_token_string_t cmd_flex_filter_mask =
9466         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9467                                 mask, "mask");
9468 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9469         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9470                                 mask_value, NULL);
9471 cmdline_parse_token_string_t cmd_flex_filter_priority =
9472         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9473                                 priority, "priority");
9474 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9475         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9476                                 priority_value, UINT8);
9477 cmdline_parse_token_string_t cmd_flex_filter_queue =
9478         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9479                                 queue, "queue");
9480 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9481         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9482                                 queue_id, UINT16);
9483 cmdline_parse_inst_t cmd_flex_filter = {
9484         .f = cmd_flex_filter_parsed,
9485         .data = NULL,
9486         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9487                 "<value> mask <value> priority <value> queue <queue_id>: "
9488                 "Add/Del a flex filter",
9489         .tokens = {
9490                 (void *)&cmd_flex_filter_filter,
9491                 (void *)&cmd_flex_filter_port_id,
9492                 (void *)&cmd_flex_filter_ops,
9493                 (void *)&cmd_flex_filter_len,
9494                 (void *)&cmd_flex_filter_len_value,
9495                 (void *)&cmd_flex_filter_bytes,
9496                 (void *)&cmd_flex_filter_bytes_value,
9497                 (void *)&cmd_flex_filter_mask,
9498                 (void *)&cmd_flex_filter_mask_value,
9499                 (void *)&cmd_flex_filter_priority,
9500                 (void *)&cmd_flex_filter_priority_value,
9501                 (void *)&cmd_flex_filter_queue,
9502                 (void *)&cmd_flex_filter_queue_id,
9503                 NULL,
9504         },
9505 };
9506
9507 /* *** Filters Control *** */
9508
9509 /* *** deal with ethertype filter *** */
9510 struct cmd_ethertype_filter_result {
9511         cmdline_fixed_string_t filter;
9512         portid_t port_id;
9513         cmdline_fixed_string_t ops;
9514         cmdline_fixed_string_t mac;
9515         struct ether_addr mac_addr;
9516         cmdline_fixed_string_t ethertype;
9517         uint16_t ethertype_value;
9518         cmdline_fixed_string_t drop;
9519         cmdline_fixed_string_t queue;
9520         uint16_t  queue_id;
9521 };
9522
9523 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9524         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9525                                  filter, "ethertype_filter");
9526 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9527         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9528                               port_id, UINT16);
9529 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9530         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9531                                  ops, "add#del");
9532 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9533         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9534                                  mac, "mac_addr#mac_ignr");
9535 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9536         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9537                                      mac_addr);
9538 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9539         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9540                                  ethertype, "ethertype");
9541 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9542         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9543                               ethertype_value, UINT16);
9544 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9545         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9546                                  drop, "drop#fwd");
9547 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9548         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9549                                  queue, "queue");
9550 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9551         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9552                               queue_id, UINT16);
9553
9554 static void
9555 cmd_ethertype_filter_parsed(void *parsed_result,
9556                           __attribute__((unused)) struct cmdline *cl,
9557                           __attribute__((unused)) void *data)
9558 {
9559         struct cmd_ethertype_filter_result *res = parsed_result;
9560         struct rte_eth_ethertype_filter filter;
9561         int ret = 0;
9562
9563         ret = rte_eth_dev_filter_supported(res->port_id,
9564                         RTE_ETH_FILTER_ETHERTYPE);
9565         if (ret < 0) {
9566                 printf("ethertype filter is not supported on port %u.\n",
9567                         res->port_id);
9568                 return;
9569         }
9570
9571         memset(&filter, 0, sizeof(filter));
9572         if (!strcmp(res->mac, "mac_addr")) {
9573                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9574                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9575                         sizeof(struct ether_addr));
9576         }
9577         if (!strcmp(res->drop, "drop"))
9578                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9579         filter.ether_type = res->ethertype_value;
9580         filter.queue = res->queue_id;
9581
9582         if (!strcmp(res->ops, "add"))
9583                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9584                                 RTE_ETH_FILTER_ETHERTYPE,
9585                                 RTE_ETH_FILTER_ADD,
9586                                 &filter);
9587         else
9588                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9589                                 RTE_ETH_FILTER_ETHERTYPE,
9590                                 RTE_ETH_FILTER_DELETE,
9591                                 &filter);
9592         if (ret < 0)
9593                 printf("ethertype filter programming error: (%s)\n",
9594                         strerror(-ret));
9595 }
9596
9597 cmdline_parse_inst_t cmd_ethertype_filter = {
9598         .f = cmd_ethertype_filter_parsed,
9599         .data = NULL,
9600         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9601                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9602                 "Add or delete an ethertype filter entry",
9603         .tokens = {
9604                 (void *)&cmd_ethertype_filter_filter,
9605                 (void *)&cmd_ethertype_filter_port_id,
9606                 (void *)&cmd_ethertype_filter_ops,
9607                 (void *)&cmd_ethertype_filter_mac,
9608                 (void *)&cmd_ethertype_filter_mac_addr,
9609                 (void *)&cmd_ethertype_filter_ethertype,
9610                 (void *)&cmd_ethertype_filter_ethertype_value,
9611                 (void *)&cmd_ethertype_filter_drop,
9612                 (void *)&cmd_ethertype_filter_queue,
9613                 (void *)&cmd_ethertype_filter_queue_id,
9614                 NULL,
9615         },
9616 };
9617
9618 /* *** deal with flow director filter *** */
9619 struct cmd_flow_director_result {
9620         cmdline_fixed_string_t flow_director_filter;
9621         portid_t port_id;
9622         cmdline_fixed_string_t mode;
9623         cmdline_fixed_string_t mode_value;
9624         cmdline_fixed_string_t ops;
9625         cmdline_fixed_string_t flow;
9626         cmdline_fixed_string_t flow_type;
9627         cmdline_fixed_string_t ether;
9628         uint16_t ether_type;
9629         cmdline_fixed_string_t src;
9630         cmdline_ipaddr_t ip_src;
9631         uint16_t port_src;
9632         cmdline_fixed_string_t dst;
9633         cmdline_ipaddr_t ip_dst;
9634         uint16_t port_dst;
9635         cmdline_fixed_string_t verify_tag;
9636         uint32_t verify_tag_value;
9637         cmdline_ipaddr_t tos;
9638         uint8_t tos_value;
9639         cmdline_ipaddr_t proto;
9640         uint8_t proto_value;
9641         cmdline_ipaddr_t ttl;
9642         uint8_t ttl_value;
9643         cmdline_fixed_string_t vlan;
9644         uint16_t vlan_value;
9645         cmdline_fixed_string_t flexbytes;
9646         cmdline_fixed_string_t flexbytes_value;
9647         cmdline_fixed_string_t pf_vf;
9648         cmdline_fixed_string_t drop;
9649         cmdline_fixed_string_t queue;
9650         uint16_t  queue_id;
9651         cmdline_fixed_string_t fd_id;
9652         uint32_t  fd_id_value;
9653         cmdline_fixed_string_t mac;
9654         struct ether_addr mac_addr;
9655         cmdline_fixed_string_t tunnel;
9656         cmdline_fixed_string_t tunnel_type;
9657         cmdline_fixed_string_t tunnel_id;
9658         uint32_t tunnel_id_value;
9659 };
9660
9661 static inline int
9662 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9663 {
9664         char s[256];
9665         const char *p, *p0 = q_arg;
9666         char *end;
9667         unsigned long int_fld;
9668         char *str_fld[max_num];
9669         int i;
9670         unsigned size;
9671         int ret = -1;
9672
9673         p = strchr(p0, '(');
9674         if (p == NULL)
9675                 return -1;
9676         ++p;
9677         p0 = strchr(p, ')');
9678         if (p0 == NULL)
9679                 return -1;
9680
9681         size = p0 - p;
9682         if (size >= sizeof(s))
9683                 return -1;
9684
9685         snprintf(s, sizeof(s), "%.*s", size, p);
9686         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9687         if (ret < 0 || ret > max_num)
9688                 return -1;
9689         for (i = 0; i < ret; i++) {
9690                 errno = 0;
9691                 int_fld = strtoul(str_fld[i], &end, 0);
9692                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9693                         return -1;
9694                 flexbytes[i] = (uint8_t)int_fld;
9695         }
9696         return ret;
9697 }
9698
9699 static uint16_t
9700 str2flowtype(char *string)
9701 {
9702         uint8_t i = 0;
9703         static const struct {
9704                 char str[32];
9705                 uint16_t type;
9706         } flowtype_str[] = {
9707                 {"raw", RTE_ETH_FLOW_RAW},
9708                 {"ipv4", RTE_ETH_FLOW_IPV4},
9709                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9710                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9711                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9712                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9713                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9714                 {"ipv6", RTE_ETH_FLOW_IPV6},
9715                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9716                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9717                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9718                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9719                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9720                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9721         };
9722
9723         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9724                 if (!strcmp(flowtype_str[i].str, string))
9725                         return flowtype_str[i].type;
9726         }
9727
9728         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9729                 return (uint16_t)atoi(string);
9730
9731         return RTE_ETH_FLOW_UNKNOWN;
9732 }
9733
9734 static enum rte_eth_fdir_tunnel_type
9735 str2fdir_tunneltype(char *string)
9736 {
9737         uint8_t i = 0;
9738
9739         static const struct {
9740                 char str[32];
9741                 enum rte_eth_fdir_tunnel_type type;
9742         } tunneltype_str[] = {
9743                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9744                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9745         };
9746
9747         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9748                 if (!strcmp(tunneltype_str[i].str, string))
9749                         return tunneltype_str[i].type;
9750         }
9751         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9752 }
9753
9754 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9755 do { \
9756         if ((ip_addr).family == AF_INET) \
9757                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9758         else { \
9759                 printf("invalid parameter.\n"); \
9760                 return; \
9761         } \
9762 } while (0)
9763
9764 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9765 do { \
9766         if ((ip_addr).family == AF_INET6) \
9767                 rte_memcpy(&(ip), \
9768                                  &((ip_addr).addr.ipv6), \
9769                                  sizeof(struct in6_addr)); \
9770         else { \
9771                 printf("invalid parameter.\n"); \
9772                 return; \
9773         } \
9774 } while (0)
9775
9776 static void
9777 cmd_flow_director_filter_parsed(void *parsed_result,
9778                           __attribute__((unused)) struct cmdline *cl,
9779                           __attribute__((unused)) void *data)
9780 {
9781         struct cmd_flow_director_result *res = parsed_result;
9782         struct rte_eth_fdir_filter entry;
9783         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9784         char *end;
9785         unsigned long vf_id;
9786         int ret = 0;
9787
9788         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9789         if (ret < 0) {
9790                 printf("flow director is not supported on port %u.\n",
9791                         res->port_id);
9792                 return;
9793         }
9794         memset(flexbytes, 0, sizeof(flexbytes));
9795         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9796
9797         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9798                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9799                         printf("Please set mode to MAC-VLAN.\n");
9800                         return;
9801                 }
9802         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9803                 if (strcmp(res->mode_value, "Tunnel")) {
9804                         printf("Please set mode to Tunnel.\n");
9805                         return;
9806                 }
9807         } else {
9808                 if (strcmp(res->mode_value, "IP")) {
9809                         printf("Please set mode to IP.\n");
9810                         return;
9811                 }
9812                 entry.input.flow_type = str2flowtype(res->flow_type);
9813         }
9814
9815         ret = parse_flexbytes(res->flexbytes_value,
9816                                         flexbytes,
9817                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9818         if (ret < 0) {
9819                 printf("error: Cannot parse flexbytes input.\n");
9820                 return;
9821         }
9822
9823         switch (entry.input.flow_type) {
9824         case RTE_ETH_FLOW_FRAG_IPV4:
9825         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9826                 entry.input.flow.ip4_flow.proto = res->proto_value;
9827                 /* fall-through */
9828         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9829         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9830                 IPV4_ADDR_TO_UINT(res->ip_dst,
9831                         entry.input.flow.ip4_flow.dst_ip);
9832                 IPV4_ADDR_TO_UINT(res->ip_src,
9833                         entry.input.flow.ip4_flow.src_ip);
9834                 entry.input.flow.ip4_flow.tos = res->tos_value;
9835                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9836                 /* need convert to big endian. */
9837                 entry.input.flow.udp4_flow.dst_port =
9838                                 rte_cpu_to_be_16(res->port_dst);
9839                 entry.input.flow.udp4_flow.src_port =
9840                                 rte_cpu_to_be_16(res->port_src);
9841                 break;
9842         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9843                 IPV4_ADDR_TO_UINT(res->ip_dst,
9844                         entry.input.flow.sctp4_flow.ip.dst_ip);
9845                 IPV4_ADDR_TO_UINT(res->ip_src,
9846                         entry.input.flow.sctp4_flow.ip.src_ip);
9847                 entry.input.flow.ip4_flow.tos = res->tos_value;
9848                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9849                 /* need convert to big endian. */
9850                 entry.input.flow.sctp4_flow.dst_port =
9851                                 rte_cpu_to_be_16(res->port_dst);
9852                 entry.input.flow.sctp4_flow.src_port =
9853                                 rte_cpu_to_be_16(res->port_src);
9854                 entry.input.flow.sctp4_flow.verify_tag =
9855                                 rte_cpu_to_be_32(res->verify_tag_value);
9856                 break;
9857         case RTE_ETH_FLOW_FRAG_IPV6:
9858         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9859                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9860                 /* fall-through */
9861         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9862         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9863                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9864                         entry.input.flow.ipv6_flow.dst_ip);
9865                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9866                         entry.input.flow.ipv6_flow.src_ip);
9867                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9868                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9869                 /* need convert to big endian. */
9870                 entry.input.flow.udp6_flow.dst_port =
9871                                 rte_cpu_to_be_16(res->port_dst);
9872                 entry.input.flow.udp6_flow.src_port =
9873                                 rte_cpu_to_be_16(res->port_src);
9874                 break;
9875         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9876                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9877                         entry.input.flow.sctp6_flow.ip.dst_ip);
9878                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9879                         entry.input.flow.sctp6_flow.ip.src_ip);
9880                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9881                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9882                 /* need convert to big endian. */
9883                 entry.input.flow.sctp6_flow.dst_port =
9884                                 rte_cpu_to_be_16(res->port_dst);
9885                 entry.input.flow.sctp6_flow.src_port =
9886                                 rte_cpu_to_be_16(res->port_src);
9887                 entry.input.flow.sctp6_flow.verify_tag =
9888                                 rte_cpu_to_be_32(res->verify_tag_value);
9889                 break;
9890         case RTE_ETH_FLOW_L2_PAYLOAD:
9891                 entry.input.flow.l2_flow.ether_type =
9892                         rte_cpu_to_be_16(res->ether_type);
9893                 break;
9894         default:
9895                 break;
9896         }
9897
9898         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9899                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9900                                  &res->mac_addr,
9901                                  sizeof(struct ether_addr));
9902
9903         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9904                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9905                                  &res->mac_addr,
9906                                  sizeof(struct ether_addr));
9907                 entry.input.flow.tunnel_flow.tunnel_type =
9908                         str2fdir_tunneltype(res->tunnel_type);
9909                 entry.input.flow.tunnel_flow.tunnel_id =
9910                         rte_cpu_to_be_32(res->tunnel_id_value);
9911         }
9912
9913         rte_memcpy(entry.input.flow_ext.flexbytes,
9914                    flexbytes,
9915                    RTE_ETH_FDIR_MAX_FLEXLEN);
9916
9917         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9918
9919         entry.action.flex_off = 0;  /*use 0 by default */
9920         if (!strcmp(res->drop, "drop"))
9921                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9922         else
9923                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9924
9925         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9926             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9927                 if (!strcmp(res->pf_vf, "pf"))
9928                         entry.input.flow_ext.is_vf = 0;
9929                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9930                         struct rte_eth_dev_info dev_info;
9931
9932                         memset(&dev_info, 0, sizeof(dev_info));
9933                         rte_eth_dev_info_get(res->port_id, &dev_info);
9934                         errno = 0;
9935                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9936                         if (errno != 0 || *end != '\0' ||
9937                             vf_id >= dev_info.max_vfs) {
9938                                 printf("invalid parameter %s.\n", res->pf_vf);
9939                                 return;
9940                         }
9941                         entry.input.flow_ext.is_vf = 1;
9942                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9943                 } else {
9944                         printf("invalid parameter %s.\n", res->pf_vf);
9945                         return;
9946                 }
9947         }
9948
9949         /* set to report FD ID by default */
9950         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9951         entry.action.rx_queue = res->queue_id;
9952         entry.soft_id = res->fd_id_value;
9953         if (!strcmp(res->ops, "add"))
9954                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9955                                              RTE_ETH_FILTER_ADD, &entry);
9956         else if (!strcmp(res->ops, "del"))
9957                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9958                                              RTE_ETH_FILTER_DELETE, &entry);
9959         else
9960                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9961                                              RTE_ETH_FILTER_UPDATE, &entry);
9962         if (ret < 0)
9963                 printf("flow director programming error: (%s)\n",
9964                         strerror(-ret));
9965 }
9966
9967 cmdline_parse_token_string_t cmd_flow_director_filter =
9968         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9969                                  flow_director_filter, "flow_director_filter");
9970 cmdline_parse_token_num_t cmd_flow_director_port_id =
9971         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9972                               port_id, UINT16);
9973 cmdline_parse_token_string_t cmd_flow_director_ops =
9974         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9975                                  ops, "add#del#update");
9976 cmdline_parse_token_string_t cmd_flow_director_flow =
9977         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9978                                  flow, "flow");
9979 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9981                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9982                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9983 cmdline_parse_token_string_t cmd_flow_director_ether =
9984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9985                                  ether, "ether");
9986 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9987         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9988                               ether_type, UINT16);
9989 cmdline_parse_token_string_t cmd_flow_director_src =
9990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9991                                  src, "src");
9992 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9993         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9994                                  ip_src);
9995 cmdline_parse_token_num_t cmd_flow_director_port_src =
9996         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9997                               port_src, UINT16);
9998 cmdline_parse_token_string_t cmd_flow_director_dst =
9999         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10000                                  dst, "dst");
10001 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10002         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10003                                  ip_dst);
10004 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10005         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10006                               port_dst, UINT16);
10007 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10008         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10009                                   verify_tag, "verify_tag");
10010 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10011         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10012                               verify_tag_value, UINT32);
10013 cmdline_parse_token_string_t cmd_flow_director_tos =
10014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10015                                  tos, "tos");
10016 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10017         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10018                               tos_value, UINT8);
10019 cmdline_parse_token_string_t cmd_flow_director_proto =
10020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10021                                  proto, "proto");
10022 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10023         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10024                               proto_value, UINT8);
10025 cmdline_parse_token_string_t cmd_flow_director_ttl =
10026         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10027                                  ttl, "ttl");
10028 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10029         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10030                               ttl_value, UINT8);
10031 cmdline_parse_token_string_t cmd_flow_director_vlan =
10032         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10033                                  vlan, "vlan");
10034 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10035         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10036                               vlan_value, UINT16);
10037 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10038         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10039                                  flexbytes, "flexbytes");
10040 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10041         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10042                               flexbytes_value, NULL);
10043 cmdline_parse_token_string_t cmd_flow_director_drop =
10044         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10045                                  drop, "drop#fwd");
10046 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10048                               pf_vf, NULL);
10049 cmdline_parse_token_string_t cmd_flow_director_queue =
10050         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10051                                  queue, "queue");
10052 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10053         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10054                               queue_id, UINT16);
10055 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10056         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10057                                  fd_id, "fd_id");
10058 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10059         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10060                               fd_id_value, UINT32);
10061
10062 cmdline_parse_token_string_t cmd_flow_director_mode =
10063         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10064                                  mode, "mode");
10065 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10066         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10067                                  mode_value, "IP");
10068 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10069         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10070                                  mode_value, "MAC-VLAN");
10071 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10072         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10073                                  mode_value, "Tunnel");
10074 cmdline_parse_token_string_t cmd_flow_director_mac =
10075         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10076                                  mac, "mac");
10077 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10078         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10079                                     mac_addr);
10080 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10081         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10082                                  tunnel, "tunnel");
10083 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10084         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10085                                  tunnel_type, "NVGRE#VxLAN");
10086 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10088                                  tunnel_id, "tunnel-id");
10089 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10090         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10091                               tunnel_id_value, UINT32);
10092
10093 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10094         .f = cmd_flow_director_filter_parsed,
10095         .data = NULL,
10096         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10097                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10098                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10099                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10100                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10101                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10102                 "fd_id <fd_id_value>: "
10103                 "Add or delete an ip flow director entry on NIC",
10104         .tokens = {
10105                 (void *)&cmd_flow_director_filter,
10106                 (void *)&cmd_flow_director_port_id,
10107                 (void *)&cmd_flow_director_mode,
10108                 (void *)&cmd_flow_director_mode_ip,
10109                 (void *)&cmd_flow_director_ops,
10110                 (void *)&cmd_flow_director_flow,
10111                 (void *)&cmd_flow_director_flow_type,
10112                 (void *)&cmd_flow_director_src,
10113                 (void *)&cmd_flow_director_ip_src,
10114                 (void *)&cmd_flow_director_dst,
10115                 (void *)&cmd_flow_director_ip_dst,
10116                 (void *)&cmd_flow_director_tos,
10117                 (void *)&cmd_flow_director_tos_value,
10118                 (void *)&cmd_flow_director_proto,
10119                 (void *)&cmd_flow_director_proto_value,
10120                 (void *)&cmd_flow_director_ttl,
10121                 (void *)&cmd_flow_director_ttl_value,
10122                 (void *)&cmd_flow_director_vlan,
10123                 (void *)&cmd_flow_director_vlan_value,
10124                 (void *)&cmd_flow_director_flexbytes,
10125                 (void *)&cmd_flow_director_flexbytes_value,
10126                 (void *)&cmd_flow_director_drop,
10127                 (void *)&cmd_flow_director_pf_vf,
10128                 (void *)&cmd_flow_director_queue,
10129                 (void *)&cmd_flow_director_queue_id,
10130                 (void *)&cmd_flow_director_fd_id,
10131                 (void *)&cmd_flow_director_fd_id_value,
10132                 NULL,
10133         },
10134 };
10135
10136 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10137         .f = cmd_flow_director_filter_parsed,
10138         .data = NULL,
10139         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10140                 "director entry on NIC",
10141         .tokens = {
10142                 (void *)&cmd_flow_director_filter,
10143                 (void *)&cmd_flow_director_port_id,
10144                 (void *)&cmd_flow_director_mode,
10145                 (void *)&cmd_flow_director_mode_ip,
10146                 (void *)&cmd_flow_director_ops,
10147                 (void *)&cmd_flow_director_flow,
10148                 (void *)&cmd_flow_director_flow_type,
10149                 (void *)&cmd_flow_director_src,
10150                 (void *)&cmd_flow_director_ip_src,
10151                 (void *)&cmd_flow_director_port_src,
10152                 (void *)&cmd_flow_director_dst,
10153                 (void *)&cmd_flow_director_ip_dst,
10154                 (void *)&cmd_flow_director_port_dst,
10155                 (void *)&cmd_flow_director_tos,
10156                 (void *)&cmd_flow_director_tos_value,
10157                 (void *)&cmd_flow_director_ttl,
10158                 (void *)&cmd_flow_director_ttl_value,
10159                 (void *)&cmd_flow_director_vlan,
10160                 (void *)&cmd_flow_director_vlan_value,
10161                 (void *)&cmd_flow_director_flexbytes,
10162                 (void *)&cmd_flow_director_flexbytes_value,
10163                 (void *)&cmd_flow_director_drop,
10164                 (void *)&cmd_flow_director_pf_vf,
10165                 (void *)&cmd_flow_director_queue,
10166                 (void *)&cmd_flow_director_queue_id,
10167                 (void *)&cmd_flow_director_fd_id,
10168                 (void *)&cmd_flow_director_fd_id_value,
10169                 NULL,
10170         },
10171 };
10172
10173 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10174         .f = cmd_flow_director_filter_parsed,
10175         .data = NULL,
10176         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10177                 "director entry on NIC",
10178         .tokens = {
10179                 (void *)&cmd_flow_director_filter,
10180                 (void *)&cmd_flow_director_port_id,
10181                 (void *)&cmd_flow_director_mode,
10182                 (void *)&cmd_flow_director_mode_ip,
10183                 (void *)&cmd_flow_director_ops,
10184                 (void *)&cmd_flow_director_flow,
10185                 (void *)&cmd_flow_director_flow_type,
10186                 (void *)&cmd_flow_director_src,
10187                 (void *)&cmd_flow_director_ip_src,
10188                 (void *)&cmd_flow_director_port_dst,
10189                 (void *)&cmd_flow_director_dst,
10190                 (void *)&cmd_flow_director_ip_dst,
10191                 (void *)&cmd_flow_director_port_dst,
10192                 (void *)&cmd_flow_director_verify_tag,
10193                 (void *)&cmd_flow_director_verify_tag_value,
10194                 (void *)&cmd_flow_director_tos,
10195                 (void *)&cmd_flow_director_tos_value,
10196                 (void *)&cmd_flow_director_ttl,
10197                 (void *)&cmd_flow_director_ttl_value,
10198                 (void *)&cmd_flow_director_vlan,
10199                 (void *)&cmd_flow_director_vlan_value,
10200                 (void *)&cmd_flow_director_flexbytes,
10201                 (void *)&cmd_flow_director_flexbytes_value,
10202                 (void *)&cmd_flow_director_drop,
10203                 (void *)&cmd_flow_director_pf_vf,
10204                 (void *)&cmd_flow_director_queue,
10205                 (void *)&cmd_flow_director_queue_id,
10206                 (void *)&cmd_flow_director_fd_id,
10207                 (void *)&cmd_flow_director_fd_id_value,
10208                 NULL,
10209         },
10210 };
10211
10212 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10213         .f = cmd_flow_director_filter_parsed,
10214         .data = NULL,
10215         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10216                 "director entry on NIC",
10217         .tokens = {
10218                 (void *)&cmd_flow_director_filter,
10219                 (void *)&cmd_flow_director_port_id,
10220                 (void *)&cmd_flow_director_mode,
10221                 (void *)&cmd_flow_director_mode_ip,
10222                 (void *)&cmd_flow_director_ops,
10223                 (void *)&cmd_flow_director_flow,
10224                 (void *)&cmd_flow_director_flow_type,
10225                 (void *)&cmd_flow_director_ether,
10226                 (void *)&cmd_flow_director_ether_type,
10227                 (void *)&cmd_flow_director_flexbytes,
10228                 (void *)&cmd_flow_director_flexbytes_value,
10229                 (void *)&cmd_flow_director_drop,
10230                 (void *)&cmd_flow_director_pf_vf,
10231                 (void *)&cmd_flow_director_queue,
10232                 (void *)&cmd_flow_director_queue_id,
10233                 (void *)&cmd_flow_director_fd_id,
10234                 (void *)&cmd_flow_director_fd_id_value,
10235                 NULL,
10236         },
10237 };
10238
10239 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10240         .f = cmd_flow_director_filter_parsed,
10241         .data = NULL,
10242         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10243                 "director entry on NIC",
10244         .tokens = {
10245                 (void *)&cmd_flow_director_filter,
10246                 (void *)&cmd_flow_director_port_id,
10247                 (void *)&cmd_flow_director_mode,
10248                 (void *)&cmd_flow_director_mode_mac_vlan,
10249                 (void *)&cmd_flow_director_ops,
10250                 (void *)&cmd_flow_director_mac,
10251                 (void *)&cmd_flow_director_mac_addr,
10252                 (void *)&cmd_flow_director_vlan,
10253                 (void *)&cmd_flow_director_vlan_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 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10266         .f = cmd_flow_director_filter_parsed,
10267         .data = NULL,
10268         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10269                 "director entry on NIC",
10270         .tokens = {
10271                 (void *)&cmd_flow_director_filter,
10272                 (void *)&cmd_flow_director_port_id,
10273                 (void *)&cmd_flow_director_mode,
10274                 (void *)&cmd_flow_director_mode_tunnel,
10275                 (void *)&cmd_flow_director_ops,
10276                 (void *)&cmd_flow_director_mac,
10277                 (void *)&cmd_flow_director_mac_addr,
10278                 (void *)&cmd_flow_director_vlan,
10279                 (void *)&cmd_flow_director_vlan_value,
10280                 (void *)&cmd_flow_director_tunnel,
10281                 (void *)&cmd_flow_director_tunnel_type,
10282                 (void *)&cmd_flow_director_tunnel_id,
10283                 (void *)&cmd_flow_director_tunnel_id_value,
10284                 (void *)&cmd_flow_director_flexbytes,
10285                 (void *)&cmd_flow_director_flexbytes_value,
10286                 (void *)&cmd_flow_director_drop,
10287                 (void *)&cmd_flow_director_queue,
10288                 (void *)&cmd_flow_director_queue_id,
10289                 (void *)&cmd_flow_director_fd_id,
10290                 (void *)&cmd_flow_director_fd_id_value,
10291                 NULL,
10292         },
10293 };
10294
10295 struct cmd_flush_flow_director_result {
10296         cmdline_fixed_string_t flush_flow_director;
10297         portid_t port_id;
10298 };
10299
10300 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10301         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10302                                  flush_flow_director, "flush_flow_director");
10303 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10304         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10305                               port_id, UINT16);
10306
10307 static void
10308 cmd_flush_flow_director_parsed(void *parsed_result,
10309                           __attribute__((unused)) struct cmdline *cl,
10310                           __attribute__((unused)) void *data)
10311 {
10312         struct cmd_flow_director_result *res = parsed_result;
10313         int ret = 0;
10314
10315         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10316         if (ret < 0) {
10317                 printf("flow director is not supported on port %u.\n",
10318                         res->port_id);
10319                 return;
10320         }
10321
10322         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10323                         RTE_ETH_FILTER_FLUSH, NULL);
10324         if (ret < 0)
10325                 printf("flow director table flushing error: (%s)\n",
10326                         strerror(-ret));
10327 }
10328
10329 cmdline_parse_inst_t cmd_flush_flow_director = {
10330         .f = cmd_flush_flow_director_parsed,
10331         .data = NULL,
10332         .help_str = "flush_flow_director <port_id>: "
10333                 "Flush all flow director entries of a device on NIC",
10334         .tokens = {
10335                 (void *)&cmd_flush_flow_director_flush,
10336                 (void *)&cmd_flush_flow_director_port_id,
10337                 NULL,
10338         },
10339 };
10340
10341 /* *** deal with flow director mask *** */
10342 struct cmd_flow_director_mask_result {
10343         cmdline_fixed_string_t flow_director_mask;
10344         portid_t port_id;
10345         cmdline_fixed_string_t mode;
10346         cmdline_fixed_string_t mode_value;
10347         cmdline_fixed_string_t vlan;
10348         uint16_t vlan_mask;
10349         cmdline_fixed_string_t src_mask;
10350         cmdline_ipaddr_t ipv4_src;
10351         cmdline_ipaddr_t ipv6_src;
10352         uint16_t port_src;
10353         cmdline_fixed_string_t dst_mask;
10354         cmdline_ipaddr_t ipv4_dst;
10355         cmdline_ipaddr_t ipv6_dst;
10356         uint16_t port_dst;
10357         cmdline_fixed_string_t mac;
10358         uint8_t mac_addr_byte_mask;
10359         cmdline_fixed_string_t tunnel_id;
10360         uint32_t tunnel_id_mask;
10361         cmdline_fixed_string_t tunnel_type;
10362         uint8_t tunnel_type_mask;
10363 };
10364
10365 static void
10366 cmd_flow_director_mask_parsed(void *parsed_result,
10367                           __attribute__((unused)) struct cmdline *cl,
10368                           __attribute__((unused)) void *data)
10369 {
10370         struct cmd_flow_director_mask_result *res = parsed_result;
10371         struct rte_eth_fdir_masks *mask;
10372         struct rte_port *port;
10373
10374         if (res->port_id > nb_ports) {
10375                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10376                 return;
10377         }
10378
10379         port = &ports[res->port_id];
10380         /** Check if the port is not started **/
10381         if (port->port_status != RTE_PORT_STOPPED) {
10382                 printf("Please stop port %d first\n", res->port_id);
10383                 return;
10384         }
10385
10386         mask = &port->dev_conf.fdir_conf.mask;
10387
10388         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10389                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10390                         printf("Please set mode to MAC-VLAN.\n");
10391                         return;
10392                 }
10393
10394                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10395         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10396                 if (strcmp(res->mode_value, "Tunnel")) {
10397                         printf("Please set mode to Tunnel.\n");
10398                         return;
10399                 }
10400
10401                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10402                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10403                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10404                 mask->tunnel_type_mask = res->tunnel_type_mask;
10405         } else {
10406                 if (strcmp(res->mode_value, "IP")) {
10407                         printf("Please set mode to IP.\n");
10408                         return;
10409                 }
10410
10411                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10412                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10413                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10414                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10415                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10416                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10417                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10418         }
10419
10420         cmd_reconfig_device_queue(res->port_id, 1, 1);
10421 }
10422
10423 cmdline_parse_token_string_t cmd_flow_director_mask =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  flow_director_mask, "flow_director_mask");
10426 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10427         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10428                               port_id, UINT16);
10429 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10431                                  vlan, "vlan");
10432 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10434                               vlan_mask, UINT16);
10435 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10437                                  src_mask, "src_mask");
10438 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10439         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10440                                  ipv4_src);
10441 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10442         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10443                                  ipv6_src);
10444 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10446                               port_src, UINT16);
10447 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10449                                  dst_mask, "dst_mask");
10450 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10451         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10452                                  ipv4_dst);
10453 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10454         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10455                                  ipv6_dst);
10456 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10458                               port_dst, UINT16);
10459
10460 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10461         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10462                                  mode, "mode");
10463 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10464         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10465                                  mode_value, "IP");
10466 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10468                                  mode_value, "MAC-VLAN");
10469 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10471                                  mode_value, "Tunnel");
10472 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10474                                  mac, "mac");
10475 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10476         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10477                               mac_addr_byte_mask, UINT8);
10478 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10479         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10480                                  tunnel_type, "tunnel-type");
10481 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10482         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10483                               tunnel_type_mask, UINT8);
10484 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10485         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10486                                  tunnel_id, "tunnel-id");
10487 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10489                               tunnel_id_mask, UINT32);
10490
10491 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10492         .f = cmd_flow_director_mask_parsed,
10493         .data = NULL,
10494         .help_str = "flow_director_mask ... : "
10495                 "Set IP mode flow director's mask on NIC",
10496         .tokens = {
10497                 (void *)&cmd_flow_director_mask,
10498                 (void *)&cmd_flow_director_mask_port_id,
10499                 (void *)&cmd_flow_director_mask_mode,
10500                 (void *)&cmd_flow_director_mask_mode_ip,
10501                 (void *)&cmd_flow_director_mask_vlan,
10502                 (void *)&cmd_flow_director_mask_vlan_value,
10503                 (void *)&cmd_flow_director_mask_src,
10504                 (void *)&cmd_flow_director_mask_ipv4_src,
10505                 (void *)&cmd_flow_director_mask_ipv6_src,
10506                 (void *)&cmd_flow_director_mask_port_src,
10507                 (void *)&cmd_flow_director_mask_dst,
10508                 (void *)&cmd_flow_director_mask_ipv4_dst,
10509                 (void *)&cmd_flow_director_mask_ipv6_dst,
10510                 (void *)&cmd_flow_director_mask_port_dst,
10511                 NULL,
10512         },
10513 };
10514
10515 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10516         .f = cmd_flow_director_mask_parsed,
10517         .data = NULL,
10518         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10519                 "flow director's mask on NIC",
10520         .tokens = {
10521                 (void *)&cmd_flow_director_mask,
10522                 (void *)&cmd_flow_director_mask_port_id,
10523                 (void *)&cmd_flow_director_mask_mode,
10524                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10525                 (void *)&cmd_flow_director_mask_vlan,
10526                 (void *)&cmd_flow_director_mask_vlan_value,
10527                 NULL,
10528         },
10529 };
10530
10531 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10532         .f = cmd_flow_director_mask_parsed,
10533         .data = NULL,
10534         .help_str = "flow_director_mask ... : Set tunnel mode "
10535                 "flow director's mask on NIC",
10536         .tokens = {
10537                 (void *)&cmd_flow_director_mask,
10538                 (void *)&cmd_flow_director_mask_port_id,
10539                 (void *)&cmd_flow_director_mask_mode,
10540                 (void *)&cmd_flow_director_mask_mode_tunnel,
10541                 (void *)&cmd_flow_director_mask_vlan,
10542                 (void *)&cmd_flow_director_mask_vlan_value,
10543                 (void *)&cmd_flow_director_mask_mac,
10544                 (void *)&cmd_flow_director_mask_mac_value,
10545                 (void *)&cmd_flow_director_mask_tunnel_type,
10546                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10547                 (void *)&cmd_flow_director_mask_tunnel_id,
10548                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10549                 NULL,
10550         },
10551 };
10552
10553 /* *** deal with flow director mask on flexible payload *** */
10554 struct cmd_flow_director_flex_mask_result {
10555         cmdline_fixed_string_t flow_director_flexmask;
10556         portid_t port_id;
10557         cmdline_fixed_string_t flow;
10558         cmdline_fixed_string_t flow_type;
10559         cmdline_fixed_string_t mask;
10560 };
10561
10562 static void
10563 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10564                           __attribute__((unused)) struct cmdline *cl,
10565                           __attribute__((unused)) void *data)
10566 {
10567         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10568         struct rte_eth_fdir_info fdir_info;
10569         struct rte_eth_fdir_flex_mask flex_mask;
10570         struct rte_port *port;
10571         uint32_t flow_type_mask;
10572         uint16_t i;
10573         int ret;
10574
10575         if (res->port_id > nb_ports) {
10576                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10577                 return;
10578         }
10579
10580         port = &ports[res->port_id];
10581         /** Check if the port is not started **/
10582         if (port->port_status != RTE_PORT_STOPPED) {
10583                 printf("Please stop port %d first\n", res->port_id);
10584                 return;
10585         }
10586
10587         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10588         ret = parse_flexbytes(res->mask,
10589                         flex_mask.mask,
10590                         RTE_ETH_FDIR_MAX_FLEXLEN);
10591         if (ret < 0) {
10592                 printf("error: Cannot parse mask input.\n");
10593                 return;
10594         }
10595
10596         memset(&fdir_info, 0, sizeof(fdir_info));
10597         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10598                                 RTE_ETH_FILTER_INFO, &fdir_info);
10599         if (ret < 0) {
10600                 printf("Cannot get FDir filter info\n");
10601                 return;
10602         }
10603
10604         if (!strcmp(res->flow_type, "none")) {
10605                 /* means don't specify the flow type */
10606                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10607                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10608                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10609                                0, sizeof(struct rte_eth_fdir_flex_mask));
10610                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10611                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10612                                  &flex_mask,
10613                                  sizeof(struct rte_eth_fdir_flex_mask));
10614                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10615                 return;
10616         }
10617         flow_type_mask = fdir_info.flow_types_mask[0];
10618         if (!strcmp(res->flow_type, "all")) {
10619                 if (!flow_type_mask) {
10620                         printf("No flow type supported\n");
10621                         return;
10622                 }
10623                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10624                         if (flow_type_mask & (1 << i)) {
10625                                 flex_mask.flow_type = i;
10626                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10627                         }
10628                 }
10629                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10630                 return;
10631         }
10632         flex_mask.flow_type = str2flowtype(res->flow_type);
10633         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10634                 printf("Flow type %s not supported on port %d\n",
10635                                 res->flow_type, res->port_id);
10636                 return;
10637         }
10638         fdir_set_flex_mask(res->port_id, &flex_mask);
10639         cmd_reconfig_device_queue(res->port_id, 1, 1);
10640 }
10641
10642 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10643         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10644                                  flow_director_flexmask,
10645                                  "flow_director_flex_mask");
10646 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10647         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10648                               port_id, UINT16);
10649 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10650         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10651                                  flow, "flow");
10652 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10654                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10655                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10656 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10657         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10658                                  mask, NULL);
10659
10660 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10661         .f = cmd_flow_director_flex_mask_parsed,
10662         .data = NULL,
10663         .help_str = "flow_director_flex_mask ... : "
10664                 "Set flow director's flex mask on NIC",
10665         .tokens = {
10666                 (void *)&cmd_flow_director_flexmask,
10667                 (void *)&cmd_flow_director_flexmask_port_id,
10668                 (void *)&cmd_flow_director_flexmask_flow,
10669                 (void *)&cmd_flow_director_flexmask_flow_type,
10670                 (void *)&cmd_flow_director_flexmask_mask,
10671                 NULL,
10672         },
10673 };
10674
10675 /* *** deal with flow director flexible payload configuration *** */
10676 struct cmd_flow_director_flexpayload_result {
10677         cmdline_fixed_string_t flow_director_flexpayload;
10678         portid_t port_id;
10679         cmdline_fixed_string_t payload_layer;
10680         cmdline_fixed_string_t payload_cfg;
10681 };
10682
10683 static inline int
10684 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10685 {
10686         char s[256];
10687         const char *p, *p0 = q_arg;
10688         char *end;
10689         unsigned long int_fld;
10690         char *str_fld[max_num];
10691         int i;
10692         unsigned size;
10693         int ret = -1;
10694
10695         p = strchr(p0, '(');
10696         if (p == NULL)
10697                 return -1;
10698         ++p;
10699         p0 = strchr(p, ')');
10700         if (p0 == NULL)
10701                 return -1;
10702
10703         size = p0 - p;
10704         if (size >= sizeof(s))
10705                 return -1;
10706
10707         snprintf(s, sizeof(s), "%.*s", size, p);
10708         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10709         if (ret < 0 || ret > max_num)
10710                 return -1;
10711         for (i = 0; i < ret; i++) {
10712                 errno = 0;
10713                 int_fld = strtoul(str_fld[i], &end, 0);
10714                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10715                         return -1;
10716                 offsets[i] = (uint16_t)int_fld;
10717         }
10718         return ret;
10719 }
10720
10721 static void
10722 cmd_flow_director_flxpld_parsed(void *parsed_result,
10723                           __attribute__((unused)) struct cmdline *cl,
10724                           __attribute__((unused)) void *data)
10725 {
10726         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10727         struct rte_eth_flex_payload_cfg flex_cfg;
10728         struct rte_port *port;
10729         int ret = 0;
10730
10731         if (res->port_id > nb_ports) {
10732                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10733                 return;
10734         }
10735
10736         port = &ports[res->port_id];
10737         /** Check if the port is not started **/
10738         if (port->port_status != RTE_PORT_STOPPED) {
10739                 printf("Please stop port %d first\n", res->port_id);
10740                 return;
10741         }
10742
10743         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10744
10745         if (!strcmp(res->payload_layer, "raw"))
10746                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10747         else if (!strcmp(res->payload_layer, "l2"))
10748                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10749         else if (!strcmp(res->payload_layer, "l3"))
10750                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10751         else if (!strcmp(res->payload_layer, "l4"))
10752                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10753
10754         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10755                             RTE_ETH_FDIR_MAX_FLEXLEN);
10756         if (ret < 0) {
10757                 printf("error: Cannot parse flex payload input.\n");
10758                 return;
10759         }
10760
10761         fdir_set_flex_payload(res->port_id, &flex_cfg);
10762         cmd_reconfig_device_queue(res->port_id, 1, 1);
10763 }
10764
10765 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10767                                  flow_director_flexpayload,
10768                                  "flow_director_flex_payload");
10769 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10770         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10771                               port_id, UINT16);
10772 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10773         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10774                                  payload_layer, "raw#l2#l3#l4");
10775 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10776         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10777                                  payload_cfg, NULL);
10778
10779 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10780         .f = cmd_flow_director_flxpld_parsed,
10781         .data = NULL,
10782         .help_str = "flow_director_flexpayload ... : "
10783                 "Set flow director's flex payload on NIC",
10784         .tokens = {
10785                 (void *)&cmd_flow_director_flexpayload,
10786                 (void *)&cmd_flow_director_flexpayload_port_id,
10787                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10788                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10789                 NULL,
10790         },
10791 };
10792
10793 /* Generic flow interface command. */
10794 extern cmdline_parse_inst_t cmd_flow;
10795
10796 /* *** Classification Filters Control *** */
10797 /* *** Get symmetric hash enable per port *** */
10798 struct cmd_get_sym_hash_ena_per_port_result {
10799         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10800         portid_t port_id;
10801 };
10802
10803 static void
10804 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10805                                  __rte_unused struct cmdline *cl,
10806                                  __rte_unused void *data)
10807 {
10808         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10809         struct rte_eth_hash_filter_info info;
10810         int ret;
10811
10812         if (rte_eth_dev_filter_supported(res->port_id,
10813                                 RTE_ETH_FILTER_HASH) < 0) {
10814                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10815                                                         res->port_id);
10816                 return;
10817         }
10818
10819         memset(&info, 0, sizeof(info));
10820         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10821         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10822                                                 RTE_ETH_FILTER_GET, &info);
10823
10824         if (ret < 0) {
10825                 printf("Cannot get symmetric hash enable per port "
10826                                         "on port %u\n", res->port_id);
10827                 return;
10828         }
10829
10830         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10831                                 "enabled" : "disabled", res->port_id);
10832 }
10833
10834 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10835         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10836                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10837 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10838         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10839                 port_id, UINT16);
10840
10841 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10842         .f = cmd_get_sym_hash_per_port_parsed,
10843         .data = NULL,
10844         .help_str = "get_sym_hash_ena_per_port <port_id>",
10845         .tokens = {
10846                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10847                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10848                 NULL,
10849         },
10850 };
10851
10852 /* *** Set symmetric hash enable per port *** */
10853 struct cmd_set_sym_hash_ena_per_port_result {
10854         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10855         cmdline_fixed_string_t enable;
10856         portid_t port_id;
10857 };
10858
10859 static void
10860 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10861                                  __rte_unused struct cmdline *cl,
10862                                  __rte_unused void *data)
10863 {
10864         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10865         struct rte_eth_hash_filter_info info;
10866         int ret;
10867
10868         if (rte_eth_dev_filter_supported(res->port_id,
10869                                 RTE_ETH_FILTER_HASH) < 0) {
10870                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10871                                                         res->port_id);
10872                 return;
10873         }
10874
10875         memset(&info, 0, sizeof(info));
10876         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10877         if (!strcmp(res->enable, "enable"))
10878                 info.info.enable = 1;
10879         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10880                                         RTE_ETH_FILTER_SET, &info);
10881         if (ret < 0) {
10882                 printf("Cannot set symmetric hash enable per port on "
10883                                         "port %u\n", res->port_id);
10884                 return;
10885         }
10886         printf("Symmetric hash has been set to %s on port %u\n",
10887                                         res->enable, res->port_id);
10888 }
10889
10890 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10891         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10892                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10893 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10894         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10895                 port_id, UINT16);
10896 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10897         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10898                 enable, "enable#disable");
10899
10900 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10901         .f = cmd_set_sym_hash_per_port_parsed,
10902         .data = NULL,
10903         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10904         .tokens = {
10905                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10906                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10907                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10908                 NULL,
10909         },
10910 };
10911
10912 /* Get global config of hash function */
10913 struct cmd_get_hash_global_config_result {
10914         cmdline_fixed_string_t get_hash_global_config;
10915         portid_t port_id;
10916 };
10917
10918 static char *
10919 flowtype_to_str(uint16_t ftype)
10920 {
10921         uint16_t i;
10922         static struct {
10923                 char str[16];
10924                 uint16_t ftype;
10925         } ftype_table[] = {
10926                 {"ipv4", RTE_ETH_FLOW_IPV4},
10927                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10928                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10929                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10930                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10931                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10932                 {"ipv6", RTE_ETH_FLOW_IPV6},
10933                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10934                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10935                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10936                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10937                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10938                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10939                 {"port", RTE_ETH_FLOW_PORT},
10940                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10941                 {"geneve", RTE_ETH_FLOW_GENEVE},
10942                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10943         };
10944
10945         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10946                 if (ftype_table[i].ftype == ftype)
10947                         return ftype_table[i].str;
10948         }
10949
10950         return NULL;
10951 }
10952
10953 static void
10954 cmd_get_hash_global_config_parsed(void *parsed_result,
10955                                   __rte_unused struct cmdline *cl,
10956                                   __rte_unused void *data)
10957 {
10958         struct cmd_get_hash_global_config_result *res = parsed_result;
10959         struct rte_eth_hash_filter_info info;
10960         uint32_t idx, offset;
10961         uint16_t i;
10962         char *str;
10963         int ret;
10964
10965         if (rte_eth_dev_filter_supported(res->port_id,
10966                         RTE_ETH_FILTER_HASH) < 0) {
10967                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10968                                                         res->port_id);
10969                 return;
10970         }
10971
10972         memset(&info, 0, sizeof(info));
10973         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10974         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10975                                         RTE_ETH_FILTER_GET, &info);
10976         if (ret < 0) {
10977                 printf("Cannot get hash global configurations by port %d\n",
10978                                                         res->port_id);
10979                 return;
10980         }
10981
10982         switch (info.info.global_conf.hash_func) {
10983         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10984                 printf("Hash function is Toeplitz\n");
10985                 break;
10986         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10987                 printf("Hash function is Simple XOR\n");
10988                 break;
10989         default:
10990                 printf("Unknown hash function\n");
10991                 break;
10992         }
10993
10994         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10995                 idx = i / UINT32_BIT;
10996                 offset = i % UINT32_BIT;
10997                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10998                                                 (1UL << offset)))
10999                         continue;
11000                 str = flowtype_to_str(i);
11001                 if (!str)
11002                         continue;
11003                 printf("Symmetric hash is %s globally for flow type %s "
11004                                                         "by port %d\n",
11005                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11006                         (1UL << offset)) ? "enabled" : "disabled"), str,
11007                                                         res->port_id);
11008         }
11009 }
11010
11011 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11012         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11013                 get_hash_global_config, "get_hash_global_config");
11014 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11015         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11016                 port_id, UINT16);
11017
11018 cmdline_parse_inst_t cmd_get_hash_global_config = {
11019         .f = cmd_get_hash_global_config_parsed,
11020         .data = NULL,
11021         .help_str = "get_hash_global_config <port_id>",
11022         .tokens = {
11023                 (void *)&cmd_get_hash_global_config_all,
11024                 (void *)&cmd_get_hash_global_config_port_id,
11025                 NULL,
11026         },
11027 };
11028
11029 /* Set global config of hash function */
11030 struct cmd_set_hash_global_config_result {
11031         cmdline_fixed_string_t set_hash_global_config;
11032         portid_t port_id;
11033         cmdline_fixed_string_t hash_func;
11034         cmdline_fixed_string_t flow_type;
11035         cmdline_fixed_string_t enable;
11036 };
11037
11038 static void
11039 cmd_set_hash_global_config_parsed(void *parsed_result,
11040                                   __rte_unused struct cmdline *cl,
11041                                   __rte_unused void *data)
11042 {
11043         struct cmd_set_hash_global_config_result *res = parsed_result;
11044         struct rte_eth_hash_filter_info info;
11045         uint32_t ftype, idx, offset;
11046         int ret;
11047
11048         if (rte_eth_dev_filter_supported(res->port_id,
11049                                 RTE_ETH_FILTER_HASH) < 0) {
11050                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11051                                                         res->port_id);
11052                 return;
11053         }
11054         memset(&info, 0, sizeof(info));
11055         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11056         if (!strcmp(res->hash_func, "toeplitz"))
11057                 info.info.global_conf.hash_func =
11058                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11059         else if (!strcmp(res->hash_func, "simple_xor"))
11060                 info.info.global_conf.hash_func =
11061                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11062         else if (!strcmp(res->hash_func, "default"))
11063                 info.info.global_conf.hash_func =
11064                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11065
11066         ftype = str2flowtype(res->flow_type);
11067         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11068         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11069         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11070         if (!strcmp(res->enable, "enable"))
11071                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11072                                                 (1UL << offset);
11073         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11074                                         RTE_ETH_FILTER_SET, &info);
11075         if (ret < 0)
11076                 printf("Cannot set global hash configurations by port %d\n",
11077                                                         res->port_id);
11078         else
11079                 printf("Global hash configurations have been set "
11080                         "succcessfully by port %d\n", res->port_id);
11081 }
11082
11083 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11084         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11085                 set_hash_global_config, "set_hash_global_config");
11086 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11087         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11088                 port_id, UINT16);
11089 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11090         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11091                 hash_func, "toeplitz#simple_xor#default");
11092 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11093         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11094                 flow_type,
11095                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11096                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11097 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11098         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11099                 enable, "enable#disable");
11100
11101 cmdline_parse_inst_t cmd_set_hash_global_config = {
11102         .f = cmd_set_hash_global_config_parsed,
11103         .data = NULL,
11104         .help_str = "set_hash_global_config <port_id> "
11105                 "toeplitz|simple_xor|default "
11106                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11107                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11108                 "l2_payload enable|disable",
11109         .tokens = {
11110                 (void *)&cmd_set_hash_global_config_all,
11111                 (void *)&cmd_set_hash_global_config_port_id,
11112                 (void *)&cmd_set_hash_global_config_hash_func,
11113                 (void *)&cmd_set_hash_global_config_flow_type,
11114                 (void *)&cmd_set_hash_global_config_enable,
11115                 NULL,
11116         },
11117 };
11118
11119 /* Set hash input set */
11120 struct cmd_set_hash_input_set_result {
11121         cmdline_fixed_string_t set_hash_input_set;
11122         portid_t port_id;
11123         cmdline_fixed_string_t flow_type;
11124         cmdline_fixed_string_t inset_field;
11125         cmdline_fixed_string_t select;
11126 };
11127
11128 static enum rte_eth_input_set_field
11129 str2inset(char *string)
11130 {
11131         uint16_t i;
11132
11133         static const struct {
11134                 char str[32];
11135                 enum rte_eth_input_set_field inset;
11136         } inset_table[] = {
11137                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11138                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11139                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11140                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11141                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11142                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11143                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11144                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11145                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11146                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11147                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11148                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11149                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11150                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11151                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11152                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11153                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11154                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11155                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11156                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11157                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11158                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11159                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11160                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11161                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11162                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11163                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11164                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11165                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11166                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11167                 {"none", RTE_ETH_INPUT_SET_NONE},
11168         };
11169
11170         for (i = 0; i < RTE_DIM(inset_table); i++) {
11171                 if (!strcmp(string, inset_table[i].str))
11172                         return inset_table[i].inset;
11173         }
11174
11175         return RTE_ETH_INPUT_SET_UNKNOWN;
11176 }
11177
11178 static void
11179 cmd_set_hash_input_set_parsed(void *parsed_result,
11180                               __rte_unused struct cmdline *cl,
11181                               __rte_unused void *data)
11182 {
11183         struct cmd_set_hash_input_set_result *res = parsed_result;
11184         struct rte_eth_hash_filter_info info;
11185
11186         memset(&info, 0, sizeof(info));
11187         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11188         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11189         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11190         info.info.input_set_conf.inset_size = 1;
11191         if (!strcmp(res->select, "select"))
11192                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11193         else if (!strcmp(res->select, "add"))
11194                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11195         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11196                                 RTE_ETH_FILTER_SET, &info);
11197 }
11198
11199 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11200         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11201                 set_hash_input_set, "set_hash_input_set");
11202 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11203         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11204                 port_id, UINT16);
11205 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11206         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11207                 flow_type, NULL);
11208 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11209         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11210                 inset_field,
11211                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11212                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11213                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11214                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11215                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11216                 "fld-8th#none");
11217 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11218         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11219                 select, "select#add");
11220
11221 cmdline_parse_inst_t cmd_set_hash_input_set = {
11222         .f = cmd_set_hash_input_set_parsed,
11223         .data = NULL,
11224         .help_str = "set_hash_input_set <port_id> "
11225         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11226         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11227         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11228         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11229         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11230         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11231         "fld-7th|fld-8th|none select|add",
11232         .tokens = {
11233                 (void *)&cmd_set_hash_input_set_cmd,
11234                 (void *)&cmd_set_hash_input_set_port_id,
11235                 (void *)&cmd_set_hash_input_set_flow_type,
11236                 (void *)&cmd_set_hash_input_set_field,
11237                 (void *)&cmd_set_hash_input_set_select,
11238                 NULL,
11239         },
11240 };
11241
11242 /* Set flow director input set */
11243 struct cmd_set_fdir_input_set_result {
11244         cmdline_fixed_string_t set_fdir_input_set;
11245         portid_t port_id;
11246         cmdline_fixed_string_t flow_type;
11247         cmdline_fixed_string_t inset_field;
11248         cmdline_fixed_string_t select;
11249 };
11250
11251 static void
11252 cmd_set_fdir_input_set_parsed(void *parsed_result,
11253         __rte_unused struct cmdline *cl,
11254         __rte_unused void *data)
11255 {
11256         struct cmd_set_fdir_input_set_result *res = parsed_result;
11257         struct rte_eth_fdir_filter_info info;
11258
11259         memset(&info, 0, sizeof(info));
11260         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11261         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11262         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11263         info.info.input_set_conf.inset_size = 1;
11264         if (!strcmp(res->select, "select"))
11265                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11266         else if (!strcmp(res->select, "add"))
11267                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11268         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11269                 RTE_ETH_FILTER_SET, &info);
11270 }
11271
11272 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11273         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11274         set_fdir_input_set, "set_fdir_input_set");
11275 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11276         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11277         port_id, UINT16);
11278 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11279         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11280         flow_type,
11281         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11282         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11283 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11284         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11285         inset_field,
11286         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11287         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11288         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11289         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11290         "sctp-veri-tag#none");
11291 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11292         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11293         select, "select#add");
11294
11295 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11296         .f = cmd_set_fdir_input_set_parsed,
11297         .data = NULL,
11298         .help_str = "set_fdir_input_set <port_id> "
11299         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11300         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11301         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11302         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11303         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11304         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11305         "sctp-veri-tag|none select|add",
11306         .tokens = {
11307                 (void *)&cmd_set_fdir_input_set_cmd,
11308                 (void *)&cmd_set_fdir_input_set_port_id,
11309                 (void *)&cmd_set_fdir_input_set_flow_type,
11310                 (void *)&cmd_set_fdir_input_set_field,
11311                 (void *)&cmd_set_fdir_input_set_select,
11312                 NULL,
11313         },
11314 };
11315
11316 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11317 struct cmd_mcast_addr_result {
11318         cmdline_fixed_string_t mcast_addr_cmd;
11319         cmdline_fixed_string_t what;
11320         uint16_t port_num;
11321         struct ether_addr mc_addr;
11322 };
11323
11324 static void cmd_mcast_addr_parsed(void *parsed_result,
11325                 __attribute__((unused)) struct cmdline *cl,
11326                 __attribute__((unused)) void *data)
11327 {
11328         struct cmd_mcast_addr_result *res = parsed_result;
11329
11330         if (!is_multicast_ether_addr(&res->mc_addr)) {
11331                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11332                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11333                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11334                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11335                 return;
11336         }
11337         if (strcmp(res->what, "add") == 0)
11338                 mcast_addr_add(res->port_num, &res->mc_addr);
11339         else
11340                 mcast_addr_remove(res->port_num, &res->mc_addr);
11341 }
11342
11343 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11344         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11345                                  mcast_addr_cmd, "mcast_addr");
11346 cmdline_parse_token_string_t cmd_mcast_addr_what =
11347         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11348                                  "add#remove");
11349 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11350         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11351 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11352         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11353
11354 cmdline_parse_inst_t cmd_mcast_addr = {
11355         .f = cmd_mcast_addr_parsed,
11356         .data = (void *)0,
11357         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11358                 "Add/Remove multicast MAC address on port_id",
11359         .tokens = {
11360                 (void *)&cmd_mcast_addr_cmd,
11361                 (void *)&cmd_mcast_addr_what,
11362                 (void *)&cmd_mcast_addr_portnum,
11363                 (void *)&cmd_mcast_addr_addr,
11364                 NULL,
11365         },
11366 };
11367
11368 /* l2 tunnel config
11369  * only support E-tag now.
11370  */
11371
11372 /* Ether type config */
11373 struct cmd_config_l2_tunnel_eth_type_result {
11374         cmdline_fixed_string_t port;
11375         cmdline_fixed_string_t config;
11376         cmdline_fixed_string_t all;
11377         uint8_t id;
11378         cmdline_fixed_string_t l2_tunnel;
11379         cmdline_fixed_string_t l2_tunnel_type;
11380         cmdline_fixed_string_t eth_type;
11381         uint16_t eth_type_val;
11382 };
11383
11384 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11385         TOKEN_STRING_INITIALIZER
11386                 (struct cmd_config_l2_tunnel_eth_type_result,
11387                  port, "port");
11388 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11389         TOKEN_STRING_INITIALIZER
11390                 (struct cmd_config_l2_tunnel_eth_type_result,
11391                  config, "config");
11392 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11393         TOKEN_STRING_INITIALIZER
11394                 (struct cmd_config_l2_tunnel_eth_type_result,
11395                  all, "all");
11396 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11397         TOKEN_NUM_INITIALIZER
11398                 (struct cmd_config_l2_tunnel_eth_type_result,
11399                  id, UINT8);
11400 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11401         TOKEN_STRING_INITIALIZER
11402                 (struct cmd_config_l2_tunnel_eth_type_result,
11403                  l2_tunnel, "l2-tunnel");
11404 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11405         TOKEN_STRING_INITIALIZER
11406                 (struct cmd_config_l2_tunnel_eth_type_result,
11407                  l2_tunnel_type, "E-tag");
11408 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11409         TOKEN_STRING_INITIALIZER
11410                 (struct cmd_config_l2_tunnel_eth_type_result,
11411                  eth_type, "ether-type");
11412 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11413         TOKEN_NUM_INITIALIZER
11414                 (struct cmd_config_l2_tunnel_eth_type_result,
11415                  eth_type_val, UINT16);
11416
11417 static enum rte_eth_tunnel_type
11418 str2fdir_l2_tunnel_type(char *string)
11419 {
11420         uint32_t i = 0;
11421
11422         static const struct {
11423                 char str[32];
11424                 enum rte_eth_tunnel_type type;
11425         } l2_tunnel_type_str[] = {
11426                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11427         };
11428
11429         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11430                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11431                         return l2_tunnel_type_str[i].type;
11432         }
11433         return RTE_TUNNEL_TYPE_NONE;
11434 }
11435
11436 /* ether type config for all ports */
11437 static void
11438 cmd_config_l2_tunnel_eth_type_all_parsed
11439         (void *parsed_result,
11440          __attribute__((unused)) struct cmdline *cl,
11441          __attribute__((unused)) void *data)
11442 {
11443         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11444         struct rte_eth_l2_tunnel_conf entry;
11445         portid_t pid;
11446
11447         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11448         entry.ether_type = res->eth_type_val;
11449
11450         RTE_ETH_FOREACH_DEV(pid) {
11451                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11452         }
11453 }
11454
11455 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11456         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11457         .data = NULL,
11458         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11459         .tokens = {
11460                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11461                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11462                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11463                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11464                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11465                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11466                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11467                 NULL,
11468         },
11469 };
11470
11471 /* ether type config for a specific port */
11472 static void
11473 cmd_config_l2_tunnel_eth_type_specific_parsed(
11474         void *parsed_result,
11475         __attribute__((unused)) struct cmdline *cl,
11476         __attribute__((unused)) void *data)
11477 {
11478         struct cmd_config_l2_tunnel_eth_type_result *res =
11479                  parsed_result;
11480         struct rte_eth_l2_tunnel_conf entry;
11481
11482         if (port_id_is_invalid(res->id, ENABLED_WARN))
11483                 return;
11484
11485         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11486         entry.ether_type = res->eth_type_val;
11487
11488         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11489 }
11490
11491 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11492         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11493         .data = NULL,
11494         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11495         .tokens = {
11496                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11497                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11498                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11499                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11500                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11501                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11502                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11503                 NULL,
11504         },
11505 };
11506
11507 /* Enable/disable l2 tunnel */
11508 struct cmd_config_l2_tunnel_en_dis_result {
11509         cmdline_fixed_string_t port;
11510         cmdline_fixed_string_t config;
11511         cmdline_fixed_string_t all;
11512         uint8_t id;
11513         cmdline_fixed_string_t l2_tunnel;
11514         cmdline_fixed_string_t l2_tunnel_type;
11515         cmdline_fixed_string_t en_dis;
11516 };
11517
11518 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11519         TOKEN_STRING_INITIALIZER
11520                 (struct cmd_config_l2_tunnel_en_dis_result,
11521                  port, "port");
11522 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11523         TOKEN_STRING_INITIALIZER
11524                 (struct cmd_config_l2_tunnel_en_dis_result,
11525                  config, "config");
11526 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11527         TOKEN_STRING_INITIALIZER
11528                 (struct cmd_config_l2_tunnel_en_dis_result,
11529                  all, "all");
11530 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11531         TOKEN_NUM_INITIALIZER
11532                 (struct cmd_config_l2_tunnel_en_dis_result,
11533                  id, UINT8);
11534 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_config_l2_tunnel_en_dis_result,
11537                  l2_tunnel, "l2-tunnel");
11538 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11539         TOKEN_STRING_INITIALIZER
11540                 (struct cmd_config_l2_tunnel_en_dis_result,
11541                  l2_tunnel_type, "E-tag");
11542 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11543         TOKEN_STRING_INITIALIZER
11544                 (struct cmd_config_l2_tunnel_en_dis_result,
11545                  en_dis, "enable#disable");
11546
11547 /* enable/disable l2 tunnel for all ports */
11548 static void
11549 cmd_config_l2_tunnel_en_dis_all_parsed(
11550         void *parsed_result,
11551         __attribute__((unused)) struct cmdline *cl,
11552         __attribute__((unused)) void *data)
11553 {
11554         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11555         struct rte_eth_l2_tunnel_conf entry;
11556         portid_t pid;
11557         uint8_t en;
11558
11559         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11560
11561         if (!strcmp("enable", res->en_dis))
11562                 en = 1;
11563         else
11564                 en = 0;
11565
11566         RTE_ETH_FOREACH_DEV(pid) {
11567                 rte_eth_dev_l2_tunnel_offload_set(pid,
11568                                                   &entry,
11569                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11570                                                   en);
11571         }
11572 }
11573
11574 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11575         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11576         .data = NULL,
11577         .help_str = "port config all l2-tunnel E-tag enable|disable",
11578         .tokens = {
11579                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11580                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11581                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11582                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11583                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11584                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11585                 NULL,
11586         },
11587 };
11588
11589 /* enable/disable l2 tunnel for a port */
11590 static void
11591 cmd_config_l2_tunnel_en_dis_specific_parsed(
11592         void *parsed_result,
11593         __attribute__((unused)) struct cmdline *cl,
11594         __attribute__((unused)) void *data)
11595 {
11596         struct cmd_config_l2_tunnel_en_dis_result *res =
11597                 parsed_result;
11598         struct rte_eth_l2_tunnel_conf entry;
11599
11600         if (port_id_is_invalid(res->id, ENABLED_WARN))
11601                 return;
11602
11603         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11604
11605         if (!strcmp("enable", res->en_dis))
11606                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11607                                                   &entry,
11608                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11609                                                   1);
11610         else
11611                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11612                                                   &entry,
11613                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11614                                                   0);
11615 }
11616
11617 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11618         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11619         .data = NULL,
11620         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11621         .tokens = {
11622                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11623                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11624                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11625                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11626                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11627                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11628                 NULL,
11629         },
11630 };
11631
11632 /* E-tag configuration */
11633
11634 /* Common result structure for all E-tag configuration */
11635 struct cmd_config_e_tag_result {
11636         cmdline_fixed_string_t e_tag;
11637         cmdline_fixed_string_t set;
11638         cmdline_fixed_string_t insertion;
11639         cmdline_fixed_string_t stripping;
11640         cmdline_fixed_string_t forwarding;
11641         cmdline_fixed_string_t filter;
11642         cmdline_fixed_string_t add;
11643         cmdline_fixed_string_t del;
11644         cmdline_fixed_string_t on;
11645         cmdline_fixed_string_t off;
11646         cmdline_fixed_string_t on_off;
11647         cmdline_fixed_string_t port_tag_id;
11648         uint32_t port_tag_id_val;
11649         cmdline_fixed_string_t e_tag_id;
11650         uint16_t e_tag_id_val;
11651         cmdline_fixed_string_t dst_pool;
11652         uint8_t dst_pool_val;
11653         cmdline_fixed_string_t port;
11654         portid_t port_id;
11655         cmdline_fixed_string_t vf;
11656         uint8_t vf_id;
11657 };
11658
11659 /* Common CLI fields for all E-tag configuration */
11660 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11661         TOKEN_STRING_INITIALIZER
11662                 (struct cmd_config_e_tag_result,
11663                  e_tag, "E-tag");
11664 cmdline_parse_token_string_t cmd_config_e_tag_set =
11665         TOKEN_STRING_INITIALIZER
11666                 (struct cmd_config_e_tag_result,
11667                  set, "set");
11668 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11669         TOKEN_STRING_INITIALIZER
11670                 (struct cmd_config_e_tag_result,
11671                  insertion, "insertion");
11672 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11673         TOKEN_STRING_INITIALIZER
11674                 (struct cmd_config_e_tag_result,
11675                  stripping, "stripping");
11676 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11677         TOKEN_STRING_INITIALIZER
11678                 (struct cmd_config_e_tag_result,
11679                  forwarding, "forwarding");
11680 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11681         TOKEN_STRING_INITIALIZER
11682                 (struct cmd_config_e_tag_result,
11683                  filter, "filter");
11684 cmdline_parse_token_string_t cmd_config_e_tag_add =
11685         TOKEN_STRING_INITIALIZER
11686                 (struct cmd_config_e_tag_result,
11687                  add, "add");
11688 cmdline_parse_token_string_t cmd_config_e_tag_del =
11689         TOKEN_STRING_INITIALIZER
11690                 (struct cmd_config_e_tag_result,
11691                  del, "del");
11692 cmdline_parse_token_string_t cmd_config_e_tag_on =
11693         TOKEN_STRING_INITIALIZER
11694                 (struct cmd_config_e_tag_result,
11695                  on, "on");
11696 cmdline_parse_token_string_t cmd_config_e_tag_off =
11697         TOKEN_STRING_INITIALIZER
11698                 (struct cmd_config_e_tag_result,
11699                  off, "off");
11700 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_config_e_tag_result,
11703                  on_off, "on#off");
11704 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_config_e_tag_result,
11707                  port_tag_id, "port-tag-id");
11708 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11709         TOKEN_NUM_INITIALIZER
11710                 (struct cmd_config_e_tag_result,
11711                  port_tag_id_val, UINT32);
11712 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11713         TOKEN_STRING_INITIALIZER
11714                 (struct cmd_config_e_tag_result,
11715                  e_tag_id, "e-tag-id");
11716 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11717         TOKEN_NUM_INITIALIZER
11718                 (struct cmd_config_e_tag_result,
11719                  e_tag_id_val, UINT16);
11720 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11721         TOKEN_STRING_INITIALIZER
11722                 (struct cmd_config_e_tag_result,
11723                  dst_pool, "dst-pool");
11724 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11725         TOKEN_NUM_INITIALIZER
11726                 (struct cmd_config_e_tag_result,
11727                  dst_pool_val, UINT8);
11728 cmdline_parse_token_string_t cmd_config_e_tag_port =
11729         TOKEN_STRING_INITIALIZER
11730                 (struct cmd_config_e_tag_result,
11731                  port, "port");
11732 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11733         TOKEN_NUM_INITIALIZER
11734                 (struct cmd_config_e_tag_result,
11735                  port_id, UINT16);
11736 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11737         TOKEN_STRING_INITIALIZER
11738                 (struct cmd_config_e_tag_result,
11739                  vf, "vf");
11740 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11741         TOKEN_NUM_INITIALIZER
11742                 (struct cmd_config_e_tag_result,
11743                  vf_id, UINT8);
11744
11745 /* E-tag insertion configuration */
11746 static void
11747 cmd_config_e_tag_insertion_en_parsed(
11748         void *parsed_result,
11749         __attribute__((unused)) struct cmdline *cl,
11750         __attribute__((unused)) void *data)
11751 {
11752         struct cmd_config_e_tag_result *res =
11753                 parsed_result;
11754         struct rte_eth_l2_tunnel_conf entry;
11755
11756         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11757                 return;
11758
11759         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11760         entry.tunnel_id = res->port_tag_id_val;
11761         entry.vf_id = res->vf_id;
11762         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11763                                           &entry,
11764                                           ETH_L2_TUNNEL_INSERTION_MASK,
11765                                           1);
11766 }
11767
11768 static void
11769 cmd_config_e_tag_insertion_dis_parsed(
11770         void *parsed_result,
11771         __attribute__((unused)) struct cmdline *cl,
11772         __attribute__((unused)) void *data)
11773 {
11774         struct cmd_config_e_tag_result *res =
11775                 parsed_result;
11776         struct rte_eth_l2_tunnel_conf entry;
11777
11778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11779                 return;
11780
11781         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11782         entry.vf_id = res->vf_id;
11783
11784         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11785                                           &entry,
11786                                           ETH_L2_TUNNEL_INSERTION_MASK,
11787                                           0);
11788 }
11789
11790 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11791         .f = cmd_config_e_tag_insertion_en_parsed,
11792         .data = NULL,
11793         .help_str = "E-tag ... : E-tag insertion enable",
11794         .tokens = {
11795                 (void *)&cmd_config_e_tag_e_tag,
11796                 (void *)&cmd_config_e_tag_set,
11797                 (void *)&cmd_config_e_tag_insertion,
11798                 (void *)&cmd_config_e_tag_on,
11799                 (void *)&cmd_config_e_tag_port_tag_id,
11800                 (void *)&cmd_config_e_tag_port_tag_id_val,
11801                 (void *)&cmd_config_e_tag_port,
11802                 (void *)&cmd_config_e_tag_port_id,
11803                 (void *)&cmd_config_e_tag_vf,
11804                 (void *)&cmd_config_e_tag_vf_id,
11805                 NULL,
11806         },
11807 };
11808
11809 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11810         .f = cmd_config_e_tag_insertion_dis_parsed,
11811         .data = NULL,
11812         .help_str = "E-tag ... : E-tag insertion disable",
11813         .tokens = {
11814                 (void *)&cmd_config_e_tag_e_tag,
11815                 (void *)&cmd_config_e_tag_set,
11816                 (void *)&cmd_config_e_tag_insertion,
11817                 (void *)&cmd_config_e_tag_off,
11818                 (void *)&cmd_config_e_tag_port,
11819                 (void *)&cmd_config_e_tag_port_id,
11820                 (void *)&cmd_config_e_tag_vf,
11821                 (void *)&cmd_config_e_tag_vf_id,
11822                 NULL,
11823         },
11824 };
11825
11826 /* E-tag stripping configuration */
11827 static void
11828 cmd_config_e_tag_stripping_parsed(
11829         void *parsed_result,
11830         __attribute__((unused)) struct cmdline *cl,
11831         __attribute__((unused)) void *data)
11832 {
11833         struct cmd_config_e_tag_result *res =
11834                 parsed_result;
11835         struct rte_eth_l2_tunnel_conf entry;
11836
11837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11838                 return;
11839
11840         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11841
11842         if (!strcmp(res->on_off, "on"))
11843                 rte_eth_dev_l2_tunnel_offload_set
11844                         (res->port_id,
11845                          &entry,
11846                          ETH_L2_TUNNEL_STRIPPING_MASK,
11847                          1);
11848         else
11849                 rte_eth_dev_l2_tunnel_offload_set
11850                         (res->port_id,
11851                          &entry,
11852                          ETH_L2_TUNNEL_STRIPPING_MASK,
11853                          0);
11854 }
11855
11856 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11857         .f = cmd_config_e_tag_stripping_parsed,
11858         .data = NULL,
11859         .help_str = "E-tag ... : E-tag stripping enable/disable",
11860         .tokens = {
11861                 (void *)&cmd_config_e_tag_e_tag,
11862                 (void *)&cmd_config_e_tag_set,
11863                 (void *)&cmd_config_e_tag_stripping,
11864                 (void *)&cmd_config_e_tag_on_off,
11865                 (void *)&cmd_config_e_tag_port,
11866                 (void *)&cmd_config_e_tag_port_id,
11867                 NULL,
11868         },
11869 };
11870
11871 /* E-tag forwarding configuration */
11872 static void
11873 cmd_config_e_tag_forwarding_parsed(
11874         void *parsed_result,
11875         __attribute__((unused)) struct cmdline *cl,
11876         __attribute__((unused)) void *data)
11877 {
11878         struct cmd_config_e_tag_result *res = parsed_result;
11879         struct rte_eth_l2_tunnel_conf entry;
11880
11881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11882                 return;
11883
11884         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11885
11886         if (!strcmp(res->on_off, "on"))
11887                 rte_eth_dev_l2_tunnel_offload_set
11888                         (res->port_id,
11889                          &entry,
11890                          ETH_L2_TUNNEL_FORWARDING_MASK,
11891                          1);
11892         else
11893                 rte_eth_dev_l2_tunnel_offload_set
11894                         (res->port_id,
11895                          &entry,
11896                          ETH_L2_TUNNEL_FORWARDING_MASK,
11897                          0);
11898 }
11899
11900 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11901         .f = cmd_config_e_tag_forwarding_parsed,
11902         .data = NULL,
11903         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11904         .tokens = {
11905                 (void *)&cmd_config_e_tag_e_tag,
11906                 (void *)&cmd_config_e_tag_set,
11907                 (void *)&cmd_config_e_tag_forwarding,
11908                 (void *)&cmd_config_e_tag_on_off,
11909                 (void *)&cmd_config_e_tag_port,
11910                 (void *)&cmd_config_e_tag_port_id,
11911                 NULL,
11912         },
11913 };
11914
11915 /* E-tag filter configuration */
11916 static void
11917 cmd_config_e_tag_filter_add_parsed(
11918         void *parsed_result,
11919         __attribute__((unused)) struct cmdline *cl,
11920         __attribute__((unused)) void *data)
11921 {
11922         struct cmd_config_e_tag_result *res = parsed_result;
11923         struct rte_eth_l2_tunnel_conf entry;
11924         int ret = 0;
11925
11926         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11927                 return;
11928
11929         if (res->e_tag_id_val > 0x3fff) {
11930                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11931                 return;
11932         }
11933
11934         ret = rte_eth_dev_filter_supported(res->port_id,
11935                                            RTE_ETH_FILTER_L2_TUNNEL);
11936         if (ret < 0) {
11937                 printf("E-tag filter is not supported on port %u.\n",
11938                        res->port_id);
11939                 return;
11940         }
11941
11942         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11943         entry.tunnel_id = res->e_tag_id_val;
11944         entry.pool = res->dst_pool_val;
11945
11946         ret = rte_eth_dev_filter_ctrl(res->port_id,
11947                                       RTE_ETH_FILTER_L2_TUNNEL,
11948                                       RTE_ETH_FILTER_ADD,
11949                                       &entry);
11950         if (ret < 0)
11951                 printf("E-tag filter programming error: (%s)\n",
11952                        strerror(-ret));
11953 }
11954
11955 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11956         .f = cmd_config_e_tag_filter_add_parsed,
11957         .data = NULL,
11958         .help_str = "E-tag ... : E-tag filter add",
11959         .tokens = {
11960                 (void *)&cmd_config_e_tag_e_tag,
11961                 (void *)&cmd_config_e_tag_set,
11962                 (void *)&cmd_config_e_tag_filter,
11963                 (void *)&cmd_config_e_tag_add,
11964                 (void *)&cmd_config_e_tag_e_tag_id,
11965                 (void *)&cmd_config_e_tag_e_tag_id_val,
11966                 (void *)&cmd_config_e_tag_dst_pool,
11967                 (void *)&cmd_config_e_tag_dst_pool_val,
11968                 (void *)&cmd_config_e_tag_port,
11969                 (void *)&cmd_config_e_tag_port_id,
11970                 NULL,
11971         },
11972 };
11973
11974 static void
11975 cmd_config_e_tag_filter_del_parsed(
11976         void *parsed_result,
11977         __attribute__((unused)) struct cmdline *cl,
11978         __attribute__((unused)) void *data)
11979 {
11980         struct cmd_config_e_tag_result *res = parsed_result;
11981         struct rte_eth_l2_tunnel_conf entry;
11982         int ret = 0;
11983
11984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11985                 return;
11986
11987         if (res->e_tag_id_val > 0x3fff) {
11988                 printf("e-tag-id must be less than 0x3fff.\n");
11989                 return;
11990         }
11991
11992         ret = rte_eth_dev_filter_supported(res->port_id,
11993                                            RTE_ETH_FILTER_L2_TUNNEL);
11994         if (ret < 0) {
11995                 printf("E-tag filter is not supported on port %u.\n",
11996                        res->port_id);
11997                 return;
11998         }
11999
12000         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12001         entry.tunnel_id = res->e_tag_id_val;
12002
12003         ret = rte_eth_dev_filter_ctrl(res->port_id,
12004                                       RTE_ETH_FILTER_L2_TUNNEL,
12005                                       RTE_ETH_FILTER_DELETE,
12006                                       &entry);
12007         if (ret < 0)
12008                 printf("E-tag filter programming error: (%s)\n",
12009                        strerror(-ret));
12010 }
12011
12012 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12013         .f = cmd_config_e_tag_filter_del_parsed,
12014         .data = NULL,
12015         .help_str = "E-tag ... : E-tag filter delete",
12016         .tokens = {
12017                 (void *)&cmd_config_e_tag_e_tag,
12018                 (void *)&cmd_config_e_tag_set,
12019                 (void *)&cmd_config_e_tag_filter,
12020                 (void *)&cmd_config_e_tag_del,
12021                 (void *)&cmd_config_e_tag_e_tag_id,
12022                 (void *)&cmd_config_e_tag_e_tag_id_val,
12023                 (void *)&cmd_config_e_tag_port,
12024                 (void *)&cmd_config_e_tag_port_id,
12025                 NULL,
12026         },
12027 };
12028
12029 /* vf vlan anti spoof configuration */
12030
12031 /* Common result structure for vf vlan anti spoof */
12032 struct cmd_vf_vlan_anti_spoof_result {
12033         cmdline_fixed_string_t set;
12034         cmdline_fixed_string_t vf;
12035         cmdline_fixed_string_t vlan;
12036         cmdline_fixed_string_t antispoof;
12037         portid_t port_id;
12038         uint32_t vf_id;
12039         cmdline_fixed_string_t on_off;
12040 };
12041
12042 /* Common CLI fields for vf vlan anti spoof enable disable */
12043 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12044         TOKEN_STRING_INITIALIZER
12045                 (struct cmd_vf_vlan_anti_spoof_result,
12046                  set, "set");
12047 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12048         TOKEN_STRING_INITIALIZER
12049                 (struct cmd_vf_vlan_anti_spoof_result,
12050                  vf, "vf");
12051 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12052         TOKEN_STRING_INITIALIZER
12053                 (struct cmd_vf_vlan_anti_spoof_result,
12054                  vlan, "vlan");
12055 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12056         TOKEN_STRING_INITIALIZER
12057                 (struct cmd_vf_vlan_anti_spoof_result,
12058                  antispoof, "antispoof");
12059 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12060         TOKEN_NUM_INITIALIZER
12061                 (struct cmd_vf_vlan_anti_spoof_result,
12062                  port_id, UINT16);
12063 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12064         TOKEN_NUM_INITIALIZER
12065                 (struct cmd_vf_vlan_anti_spoof_result,
12066                  vf_id, UINT32);
12067 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_vf_vlan_anti_spoof_result,
12070                  on_off, "on#off");
12071
12072 static void
12073 cmd_set_vf_vlan_anti_spoof_parsed(
12074         void *parsed_result,
12075         __attribute__((unused)) struct cmdline *cl,
12076         __attribute__((unused)) void *data)
12077 {
12078         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12079         int ret = -ENOTSUP;
12080
12081         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12082
12083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12084                 return;
12085
12086 #ifdef RTE_LIBRTE_IXGBE_PMD
12087         if (ret == -ENOTSUP)
12088                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12089                                 res->vf_id, is_on);
12090 #endif
12091 #ifdef RTE_LIBRTE_I40E_PMD
12092         if (ret == -ENOTSUP)
12093                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12094                                 res->vf_id, is_on);
12095 #endif
12096 #ifdef RTE_LIBRTE_BNXT_PMD
12097         if (ret == -ENOTSUP)
12098                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12099                                 res->vf_id, is_on);
12100 #endif
12101
12102         switch (ret) {
12103         case 0:
12104                 break;
12105         case -EINVAL:
12106                 printf("invalid vf_id %d\n", res->vf_id);
12107                 break;
12108         case -ENODEV:
12109                 printf("invalid port_id %d\n", res->port_id);
12110                 break;
12111         case -ENOTSUP:
12112                 printf("function not implemented\n");
12113                 break;
12114         default:
12115                 printf("programming error: (%s)\n", strerror(-ret));
12116         }
12117 }
12118
12119 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12120         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12121         .data = NULL,
12122         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12123         .tokens = {
12124                 (void *)&cmd_vf_vlan_anti_spoof_set,
12125                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12126                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12127                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12128                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12129                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12130                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12131                 NULL,
12132         },
12133 };
12134
12135 /* vf mac anti spoof configuration */
12136
12137 /* Common result structure for vf mac anti spoof */
12138 struct cmd_vf_mac_anti_spoof_result {
12139         cmdline_fixed_string_t set;
12140         cmdline_fixed_string_t vf;
12141         cmdline_fixed_string_t mac;
12142         cmdline_fixed_string_t antispoof;
12143         portid_t port_id;
12144         uint32_t vf_id;
12145         cmdline_fixed_string_t on_off;
12146 };
12147
12148 /* Common CLI fields for vf mac anti spoof enable disable */
12149 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12150         TOKEN_STRING_INITIALIZER
12151                 (struct cmd_vf_mac_anti_spoof_result,
12152                  set, "set");
12153 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12154         TOKEN_STRING_INITIALIZER
12155                 (struct cmd_vf_mac_anti_spoof_result,
12156                  vf, "vf");
12157 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12158         TOKEN_STRING_INITIALIZER
12159                 (struct cmd_vf_mac_anti_spoof_result,
12160                  mac, "mac");
12161 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12162         TOKEN_STRING_INITIALIZER
12163                 (struct cmd_vf_mac_anti_spoof_result,
12164                  antispoof, "antispoof");
12165 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12166         TOKEN_NUM_INITIALIZER
12167                 (struct cmd_vf_mac_anti_spoof_result,
12168                  port_id, UINT16);
12169 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12170         TOKEN_NUM_INITIALIZER
12171                 (struct cmd_vf_mac_anti_spoof_result,
12172                  vf_id, UINT32);
12173 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_vf_mac_anti_spoof_result,
12176                  on_off, "on#off");
12177
12178 static void
12179 cmd_set_vf_mac_anti_spoof_parsed(
12180         void *parsed_result,
12181         __attribute__((unused)) struct cmdline *cl,
12182         __attribute__((unused)) void *data)
12183 {
12184         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12185         int ret = -ENOTSUP;
12186
12187         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12188
12189         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12190                 return;
12191
12192 #ifdef RTE_LIBRTE_IXGBE_PMD
12193         if (ret == -ENOTSUP)
12194                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12195                         res->vf_id, is_on);
12196 #endif
12197 #ifdef RTE_LIBRTE_I40E_PMD
12198         if (ret == -ENOTSUP)
12199                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12200                         res->vf_id, is_on);
12201 #endif
12202 #ifdef RTE_LIBRTE_BNXT_PMD
12203         if (ret == -ENOTSUP)
12204                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12205                         res->vf_id, is_on);
12206 #endif
12207
12208         switch (ret) {
12209         case 0:
12210                 break;
12211         case -EINVAL:
12212                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12213                 break;
12214         case -ENODEV:
12215                 printf("invalid port_id %d\n", res->port_id);
12216                 break;
12217         case -ENOTSUP:
12218                 printf("function not implemented\n");
12219                 break;
12220         default:
12221                 printf("programming error: (%s)\n", strerror(-ret));
12222         }
12223 }
12224
12225 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12226         .f = cmd_set_vf_mac_anti_spoof_parsed,
12227         .data = NULL,
12228         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12229         .tokens = {
12230                 (void *)&cmd_vf_mac_anti_spoof_set,
12231                 (void *)&cmd_vf_mac_anti_spoof_vf,
12232                 (void *)&cmd_vf_mac_anti_spoof_mac,
12233                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12234                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12235                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12236                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12237                 NULL,
12238         },
12239 };
12240
12241 /* vf vlan strip queue configuration */
12242
12243 /* Common result structure for vf mac anti spoof */
12244 struct cmd_vf_vlan_stripq_result {
12245         cmdline_fixed_string_t set;
12246         cmdline_fixed_string_t vf;
12247         cmdline_fixed_string_t vlan;
12248         cmdline_fixed_string_t stripq;
12249         portid_t port_id;
12250         uint16_t vf_id;
12251         cmdline_fixed_string_t on_off;
12252 };
12253
12254 /* Common CLI fields for vf vlan strip enable disable */
12255 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12256         TOKEN_STRING_INITIALIZER
12257                 (struct cmd_vf_vlan_stripq_result,
12258                  set, "set");
12259 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12260         TOKEN_STRING_INITIALIZER
12261                 (struct cmd_vf_vlan_stripq_result,
12262                  vf, "vf");
12263 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12264         TOKEN_STRING_INITIALIZER
12265                 (struct cmd_vf_vlan_stripq_result,
12266                  vlan, "vlan");
12267 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_vf_vlan_stripq_result,
12270                  stripq, "stripq");
12271 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12272         TOKEN_NUM_INITIALIZER
12273                 (struct cmd_vf_vlan_stripq_result,
12274                  port_id, UINT16);
12275 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12276         TOKEN_NUM_INITIALIZER
12277                 (struct cmd_vf_vlan_stripq_result,
12278                  vf_id, UINT16);
12279 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_vf_vlan_stripq_result,
12282                  on_off, "on#off");
12283
12284 static void
12285 cmd_set_vf_vlan_stripq_parsed(
12286         void *parsed_result,
12287         __attribute__((unused)) struct cmdline *cl,
12288         __attribute__((unused)) void *data)
12289 {
12290         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12291         int ret = -ENOTSUP;
12292
12293         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12294
12295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12296                 return;
12297
12298 #ifdef RTE_LIBRTE_IXGBE_PMD
12299         if (ret == -ENOTSUP)
12300                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12301                         res->vf_id, is_on);
12302 #endif
12303 #ifdef RTE_LIBRTE_I40E_PMD
12304         if (ret == -ENOTSUP)
12305                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12306                         res->vf_id, is_on);
12307 #endif
12308 #ifdef RTE_LIBRTE_BNXT_PMD
12309         if (ret == -ENOTSUP)
12310                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12311                         res->vf_id, is_on);
12312 #endif
12313
12314         switch (ret) {
12315         case 0:
12316                 break;
12317         case -EINVAL:
12318                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12319                 break;
12320         case -ENODEV:
12321                 printf("invalid port_id %d\n", res->port_id);
12322                 break;
12323         case -ENOTSUP:
12324                 printf("function not implemented\n");
12325                 break;
12326         default:
12327                 printf("programming error: (%s)\n", strerror(-ret));
12328         }
12329 }
12330
12331 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12332         .f = cmd_set_vf_vlan_stripq_parsed,
12333         .data = NULL,
12334         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12335         .tokens = {
12336                 (void *)&cmd_vf_vlan_stripq_set,
12337                 (void *)&cmd_vf_vlan_stripq_vf,
12338                 (void *)&cmd_vf_vlan_stripq_vlan,
12339                 (void *)&cmd_vf_vlan_stripq_stripq,
12340                 (void *)&cmd_vf_vlan_stripq_port_id,
12341                 (void *)&cmd_vf_vlan_stripq_vf_id,
12342                 (void *)&cmd_vf_vlan_stripq_on_off,
12343                 NULL,
12344         },
12345 };
12346
12347 /* vf vlan insert configuration */
12348
12349 /* Common result structure for vf vlan insert */
12350 struct cmd_vf_vlan_insert_result {
12351         cmdline_fixed_string_t set;
12352         cmdline_fixed_string_t vf;
12353         cmdline_fixed_string_t vlan;
12354         cmdline_fixed_string_t insert;
12355         portid_t port_id;
12356         uint16_t vf_id;
12357         uint16_t vlan_id;
12358 };
12359
12360 /* Common CLI fields for vf vlan insert enable disable */
12361 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12362         TOKEN_STRING_INITIALIZER
12363                 (struct cmd_vf_vlan_insert_result,
12364                  set, "set");
12365 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12366         TOKEN_STRING_INITIALIZER
12367                 (struct cmd_vf_vlan_insert_result,
12368                  vf, "vf");
12369 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12370         TOKEN_STRING_INITIALIZER
12371                 (struct cmd_vf_vlan_insert_result,
12372                  vlan, "vlan");
12373 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_vf_vlan_insert_result,
12376                  insert, "insert");
12377 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12378         TOKEN_NUM_INITIALIZER
12379                 (struct cmd_vf_vlan_insert_result,
12380                  port_id, UINT16);
12381 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12382         TOKEN_NUM_INITIALIZER
12383                 (struct cmd_vf_vlan_insert_result,
12384                  vf_id, UINT16);
12385 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12386         TOKEN_NUM_INITIALIZER
12387                 (struct cmd_vf_vlan_insert_result,
12388                  vlan_id, UINT16);
12389
12390 static void
12391 cmd_set_vf_vlan_insert_parsed(
12392         void *parsed_result,
12393         __attribute__((unused)) struct cmdline *cl,
12394         __attribute__((unused)) void *data)
12395 {
12396         struct cmd_vf_vlan_insert_result *res = parsed_result;
12397         int ret = -ENOTSUP;
12398
12399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12400                 return;
12401
12402 #ifdef RTE_LIBRTE_IXGBE_PMD
12403         if (ret == -ENOTSUP)
12404                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12405                         res->vlan_id);
12406 #endif
12407 #ifdef RTE_LIBRTE_I40E_PMD
12408         if (ret == -ENOTSUP)
12409                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12410                         res->vlan_id);
12411 #endif
12412 #ifdef RTE_LIBRTE_BNXT_PMD
12413         if (ret == -ENOTSUP)
12414                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12415                         res->vlan_id);
12416 #endif
12417
12418         switch (ret) {
12419         case 0:
12420                 break;
12421         case -EINVAL:
12422                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12423                 break;
12424         case -ENODEV:
12425                 printf("invalid port_id %d\n", res->port_id);
12426                 break;
12427         case -ENOTSUP:
12428                 printf("function not implemented\n");
12429                 break;
12430         default:
12431                 printf("programming error: (%s)\n", strerror(-ret));
12432         }
12433 }
12434
12435 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12436         .f = cmd_set_vf_vlan_insert_parsed,
12437         .data = NULL,
12438         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12439         .tokens = {
12440                 (void *)&cmd_vf_vlan_insert_set,
12441                 (void *)&cmd_vf_vlan_insert_vf,
12442                 (void *)&cmd_vf_vlan_insert_vlan,
12443                 (void *)&cmd_vf_vlan_insert_insert,
12444                 (void *)&cmd_vf_vlan_insert_port_id,
12445                 (void *)&cmd_vf_vlan_insert_vf_id,
12446                 (void *)&cmd_vf_vlan_insert_vlan_id,
12447                 NULL,
12448         },
12449 };
12450
12451 /* tx loopback configuration */
12452
12453 /* Common result structure for tx loopback */
12454 struct cmd_tx_loopback_result {
12455         cmdline_fixed_string_t set;
12456         cmdline_fixed_string_t tx;
12457         cmdline_fixed_string_t loopback;
12458         portid_t port_id;
12459         cmdline_fixed_string_t on_off;
12460 };
12461
12462 /* Common CLI fields for tx loopback enable disable */
12463 cmdline_parse_token_string_t cmd_tx_loopback_set =
12464         TOKEN_STRING_INITIALIZER
12465                 (struct cmd_tx_loopback_result,
12466                  set, "set");
12467 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12468         TOKEN_STRING_INITIALIZER
12469                 (struct cmd_tx_loopback_result,
12470                  tx, "tx");
12471 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12472         TOKEN_STRING_INITIALIZER
12473                 (struct cmd_tx_loopback_result,
12474                  loopback, "loopback");
12475 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12476         TOKEN_NUM_INITIALIZER
12477                 (struct cmd_tx_loopback_result,
12478                  port_id, UINT16);
12479 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_tx_loopback_result,
12482                  on_off, "on#off");
12483
12484 static void
12485 cmd_set_tx_loopback_parsed(
12486         void *parsed_result,
12487         __attribute__((unused)) struct cmdline *cl,
12488         __attribute__((unused)) void *data)
12489 {
12490         struct cmd_tx_loopback_result *res = parsed_result;
12491         int ret = -ENOTSUP;
12492
12493         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12494
12495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12496                 return;
12497
12498 #ifdef RTE_LIBRTE_IXGBE_PMD
12499         if (ret == -ENOTSUP)
12500                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12501 #endif
12502 #ifdef RTE_LIBRTE_I40E_PMD
12503         if (ret == -ENOTSUP)
12504                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12505 #endif
12506 #ifdef RTE_LIBRTE_BNXT_PMD
12507         if (ret == -ENOTSUP)
12508                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12509 #endif
12510
12511         switch (ret) {
12512         case 0:
12513                 break;
12514         case -EINVAL:
12515                 printf("invalid is_on %d\n", is_on);
12516                 break;
12517         case -ENODEV:
12518                 printf("invalid port_id %d\n", res->port_id);
12519                 break;
12520         case -ENOTSUP:
12521                 printf("function not implemented\n");
12522                 break;
12523         default:
12524                 printf("programming error: (%s)\n", strerror(-ret));
12525         }
12526 }
12527
12528 cmdline_parse_inst_t cmd_set_tx_loopback = {
12529         .f = cmd_set_tx_loopback_parsed,
12530         .data = NULL,
12531         .help_str = "set tx loopback <port_id> on|off",
12532         .tokens = {
12533                 (void *)&cmd_tx_loopback_set,
12534                 (void *)&cmd_tx_loopback_tx,
12535                 (void *)&cmd_tx_loopback_loopback,
12536                 (void *)&cmd_tx_loopback_port_id,
12537                 (void *)&cmd_tx_loopback_on_off,
12538                 NULL,
12539         },
12540 };
12541
12542 /* all queues drop enable configuration */
12543
12544 /* Common result structure for all queues drop enable */
12545 struct cmd_all_queues_drop_en_result {
12546         cmdline_fixed_string_t set;
12547         cmdline_fixed_string_t all;
12548         cmdline_fixed_string_t queues;
12549         cmdline_fixed_string_t drop;
12550         portid_t port_id;
12551         cmdline_fixed_string_t on_off;
12552 };
12553
12554 /* Common CLI fields for tx loopback enable disable */
12555 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12556         TOKEN_STRING_INITIALIZER
12557                 (struct cmd_all_queues_drop_en_result,
12558                  set, "set");
12559 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12560         TOKEN_STRING_INITIALIZER
12561                 (struct cmd_all_queues_drop_en_result,
12562                  all, "all");
12563 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12564         TOKEN_STRING_INITIALIZER
12565                 (struct cmd_all_queues_drop_en_result,
12566                  queues, "queues");
12567 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12568         TOKEN_STRING_INITIALIZER
12569                 (struct cmd_all_queues_drop_en_result,
12570                  drop, "drop");
12571 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12572         TOKEN_NUM_INITIALIZER
12573                 (struct cmd_all_queues_drop_en_result,
12574                  port_id, UINT16);
12575 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12576         TOKEN_STRING_INITIALIZER
12577                 (struct cmd_all_queues_drop_en_result,
12578                  on_off, "on#off");
12579
12580 static void
12581 cmd_set_all_queues_drop_en_parsed(
12582         void *parsed_result,
12583         __attribute__((unused)) struct cmdline *cl,
12584         __attribute__((unused)) void *data)
12585 {
12586         struct cmd_all_queues_drop_en_result *res = parsed_result;
12587         int ret = -ENOTSUP;
12588         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12589
12590         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12591                 return;
12592
12593 #ifdef RTE_LIBRTE_IXGBE_PMD
12594         if (ret == -ENOTSUP)
12595                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12596 #endif
12597 #ifdef RTE_LIBRTE_BNXT_PMD
12598         if (ret == -ENOTSUP)
12599                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12600 #endif
12601         switch (ret) {
12602         case 0:
12603                 break;
12604         case -EINVAL:
12605                 printf("invalid is_on %d\n", is_on);
12606                 break;
12607         case -ENODEV:
12608                 printf("invalid port_id %d\n", res->port_id);
12609                 break;
12610         case -ENOTSUP:
12611                 printf("function not implemented\n");
12612                 break;
12613         default:
12614                 printf("programming error: (%s)\n", strerror(-ret));
12615         }
12616 }
12617
12618 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12619         .f = cmd_set_all_queues_drop_en_parsed,
12620         .data = NULL,
12621         .help_str = "set all queues drop <port_id> on|off",
12622         .tokens = {
12623                 (void *)&cmd_all_queues_drop_en_set,
12624                 (void *)&cmd_all_queues_drop_en_all,
12625                 (void *)&cmd_all_queues_drop_en_queues,
12626                 (void *)&cmd_all_queues_drop_en_drop,
12627                 (void *)&cmd_all_queues_drop_en_port_id,
12628                 (void *)&cmd_all_queues_drop_en_on_off,
12629                 NULL,
12630         },
12631 };
12632
12633 /* vf split drop enable configuration */
12634
12635 /* Common result structure for vf split drop enable */
12636 struct cmd_vf_split_drop_en_result {
12637         cmdline_fixed_string_t set;
12638         cmdline_fixed_string_t vf;
12639         cmdline_fixed_string_t split;
12640         cmdline_fixed_string_t drop;
12641         portid_t port_id;
12642         uint16_t vf_id;
12643         cmdline_fixed_string_t on_off;
12644 };
12645
12646 /* Common CLI fields for vf split drop enable disable */
12647 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12648         TOKEN_STRING_INITIALIZER
12649                 (struct cmd_vf_split_drop_en_result,
12650                  set, "set");
12651 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12652         TOKEN_STRING_INITIALIZER
12653                 (struct cmd_vf_split_drop_en_result,
12654                  vf, "vf");
12655 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12656         TOKEN_STRING_INITIALIZER
12657                 (struct cmd_vf_split_drop_en_result,
12658                  split, "split");
12659 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12660         TOKEN_STRING_INITIALIZER
12661                 (struct cmd_vf_split_drop_en_result,
12662                  drop, "drop");
12663 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12664         TOKEN_NUM_INITIALIZER
12665                 (struct cmd_vf_split_drop_en_result,
12666                  port_id, UINT16);
12667 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12668         TOKEN_NUM_INITIALIZER
12669                 (struct cmd_vf_split_drop_en_result,
12670                  vf_id, UINT16);
12671 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_vf_split_drop_en_result,
12674                  on_off, "on#off");
12675
12676 static void
12677 cmd_set_vf_split_drop_en_parsed(
12678         void *parsed_result,
12679         __attribute__((unused)) struct cmdline *cl,
12680         __attribute__((unused)) void *data)
12681 {
12682         struct cmd_vf_split_drop_en_result *res = parsed_result;
12683         int ret = -ENOTSUP;
12684         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12685
12686         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12687                 return;
12688
12689 #ifdef RTE_LIBRTE_IXGBE_PMD
12690         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12691                         is_on);
12692 #endif
12693         switch (ret) {
12694         case 0:
12695                 break;
12696         case -EINVAL:
12697                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12698                 break;
12699         case -ENODEV:
12700                 printf("invalid port_id %d\n", res->port_id);
12701                 break;
12702         case -ENOTSUP:
12703                 printf("not supported on port %d\n", res->port_id);
12704                 break;
12705         default:
12706                 printf("programming error: (%s)\n", strerror(-ret));
12707         }
12708 }
12709
12710 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12711         .f = cmd_set_vf_split_drop_en_parsed,
12712         .data = NULL,
12713         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12714         .tokens = {
12715                 (void *)&cmd_vf_split_drop_en_set,
12716                 (void *)&cmd_vf_split_drop_en_vf,
12717                 (void *)&cmd_vf_split_drop_en_split,
12718                 (void *)&cmd_vf_split_drop_en_drop,
12719                 (void *)&cmd_vf_split_drop_en_port_id,
12720                 (void *)&cmd_vf_split_drop_en_vf_id,
12721                 (void *)&cmd_vf_split_drop_en_on_off,
12722                 NULL,
12723         },
12724 };
12725
12726 /* vf mac address configuration */
12727
12728 /* Common result structure for vf mac address */
12729 struct cmd_set_vf_mac_addr_result {
12730         cmdline_fixed_string_t set;
12731         cmdline_fixed_string_t vf;
12732         cmdline_fixed_string_t mac;
12733         cmdline_fixed_string_t addr;
12734         portid_t port_id;
12735         uint16_t vf_id;
12736         struct ether_addr mac_addr;
12737
12738 };
12739
12740 /* Common CLI fields for vf split drop enable disable */
12741 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_set_vf_mac_addr_result,
12744                  set, "set");
12745 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_set_vf_mac_addr_result,
12748                  vf, "vf");
12749 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12750         TOKEN_STRING_INITIALIZER
12751                 (struct cmd_set_vf_mac_addr_result,
12752                  mac, "mac");
12753 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12754         TOKEN_STRING_INITIALIZER
12755                 (struct cmd_set_vf_mac_addr_result,
12756                  addr, "addr");
12757 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12758         TOKEN_NUM_INITIALIZER
12759                 (struct cmd_set_vf_mac_addr_result,
12760                  port_id, UINT16);
12761 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12762         TOKEN_NUM_INITIALIZER
12763                 (struct cmd_set_vf_mac_addr_result,
12764                  vf_id, UINT16);
12765 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12766         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12767                  mac_addr);
12768
12769 static void
12770 cmd_set_vf_mac_addr_parsed(
12771         void *parsed_result,
12772         __attribute__((unused)) struct cmdline *cl,
12773         __attribute__((unused)) void *data)
12774 {
12775         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12776         int ret = -ENOTSUP;
12777
12778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12779                 return;
12780
12781 #ifdef RTE_LIBRTE_IXGBE_PMD
12782         if (ret == -ENOTSUP)
12783                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12784                                 &res->mac_addr);
12785 #endif
12786 #ifdef RTE_LIBRTE_I40E_PMD
12787         if (ret == -ENOTSUP)
12788                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12789                                 &res->mac_addr);
12790 #endif
12791 #ifdef RTE_LIBRTE_BNXT_PMD
12792         if (ret == -ENOTSUP)
12793                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12794                                 &res->mac_addr);
12795 #endif
12796
12797         switch (ret) {
12798         case 0:
12799                 break;
12800         case -EINVAL:
12801                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12802                 break;
12803         case -ENODEV:
12804                 printf("invalid port_id %d\n", res->port_id);
12805                 break;
12806         case -ENOTSUP:
12807                 printf("function not implemented\n");
12808                 break;
12809         default:
12810                 printf("programming error: (%s)\n", strerror(-ret));
12811         }
12812 }
12813
12814 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12815         .f = cmd_set_vf_mac_addr_parsed,
12816         .data = NULL,
12817         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12818         .tokens = {
12819                 (void *)&cmd_set_vf_mac_addr_set,
12820                 (void *)&cmd_set_vf_mac_addr_vf,
12821                 (void *)&cmd_set_vf_mac_addr_mac,
12822                 (void *)&cmd_set_vf_mac_addr_addr,
12823                 (void *)&cmd_set_vf_mac_addr_port_id,
12824                 (void *)&cmd_set_vf_mac_addr_vf_id,
12825                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12826                 NULL,
12827         },
12828 };
12829
12830 /* MACsec configuration */
12831
12832 /* Common result structure for MACsec offload enable */
12833 struct cmd_macsec_offload_on_result {
12834         cmdline_fixed_string_t set;
12835         cmdline_fixed_string_t macsec;
12836         cmdline_fixed_string_t offload;
12837         portid_t port_id;
12838         cmdline_fixed_string_t on;
12839         cmdline_fixed_string_t encrypt;
12840         cmdline_fixed_string_t en_on_off;
12841         cmdline_fixed_string_t replay_protect;
12842         cmdline_fixed_string_t rp_on_off;
12843 };
12844
12845 /* Common CLI fields for MACsec offload disable */
12846 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_macsec_offload_on_result,
12849                  set, "set");
12850 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12851         TOKEN_STRING_INITIALIZER
12852                 (struct cmd_macsec_offload_on_result,
12853                  macsec, "macsec");
12854 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12855         TOKEN_STRING_INITIALIZER
12856                 (struct cmd_macsec_offload_on_result,
12857                  offload, "offload");
12858 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12859         TOKEN_NUM_INITIALIZER
12860                 (struct cmd_macsec_offload_on_result,
12861                  port_id, UINT16);
12862 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_macsec_offload_on_result,
12865                  on, "on");
12866 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_macsec_offload_on_result,
12869                  encrypt, "encrypt");
12870 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_macsec_offload_on_result,
12873                  en_on_off, "on#off");
12874 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12875         TOKEN_STRING_INITIALIZER
12876                 (struct cmd_macsec_offload_on_result,
12877                  replay_protect, "replay-protect");
12878 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12879         TOKEN_STRING_INITIALIZER
12880                 (struct cmd_macsec_offload_on_result,
12881                  rp_on_off, "on#off");
12882
12883 static void
12884 cmd_set_macsec_offload_on_parsed(
12885         void *parsed_result,
12886         __attribute__((unused)) struct cmdline *cl,
12887         __attribute__((unused)) void *data)
12888 {
12889         struct cmd_macsec_offload_on_result *res = parsed_result;
12890         int ret = -ENOTSUP;
12891         portid_t port_id = res->port_id;
12892         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12893         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12894
12895         if (port_id_is_invalid(port_id, ENABLED_WARN))
12896                 return;
12897
12898         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12899 #ifdef RTE_LIBRTE_IXGBE_PMD
12900         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12901 #endif
12902         RTE_SET_USED(en);
12903         RTE_SET_USED(rp);
12904
12905         switch (ret) {
12906         case 0:
12907                 break;
12908         case -ENODEV:
12909                 printf("invalid port_id %d\n", port_id);
12910                 break;
12911         case -ENOTSUP:
12912                 printf("not supported on port %d\n", port_id);
12913                 break;
12914         default:
12915                 printf("programming error: (%s)\n", strerror(-ret));
12916         }
12917 }
12918
12919 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12920         .f = cmd_set_macsec_offload_on_parsed,
12921         .data = NULL,
12922         .help_str = "set macsec offload <port_id> on "
12923                 "encrypt on|off replay-protect on|off",
12924         .tokens = {
12925                 (void *)&cmd_macsec_offload_on_set,
12926                 (void *)&cmd_macsec_offload_on_macsec,
12927                 (void *)&cmd_macsec_offload_on_offload,
12928                 (void *)&cmd_macsec_offload_on_port_id,
12929                 (void *)&cmd_macsec_offload_on_on,
12930                 (void *)&cmd_macsec_offload_on_encrypt,
12931                 (void *)&cmd_macsec_offload_on_en_on_off,
12932                 (void *)&cmd_macsec_offload_on_replay_protect,
12933                 (void *)&cmd_macsec_offload_on_rp_on_off,
12934                 NULL,
12935         },
12936 };
12937
12938 /* Common result structure for MACsec offload disable */
12939 struct cmd_macsec_offload_off_result {
12940         cmdline_fixed_string_t set;
12941         cmdline_fixed_string_t macsec;
12942         cmdline_fixed_string_t offload;
12943         portid_t port_id;
12944         cmdline_fixed_string_t off;
12945 };
12946
12947 /* Common CLI fields for MACsec offload disable */
12948 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12949         TOKEN_STRING_INITIALIZER
12950                 (struct cmd_macsec_offload_off_result,
12951                  set, "set");
12952 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12953         TOKEN_STRING_INITIALIZER
12954                 (struct cmd_macsec_offload_off_result,
12955                  macsec, "macsec");
12956 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12957         TOKEN_STRING_INITIALIZER
12958                 (struct cmd_macsec_offload_off_result,
12959                  offload, "offload");
12960 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12961         TOKEN_NUM_INITIALIZER
12962                 (struct cmd_macsec_offload_off_result,
12963                  port_id, UINT16);
12964 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_macsec_offload_off_result,
12967                  off, "off");
12968
12969 static void
12970 cmd_set_macsec_offload_off_parsed(
12971         void *parsed_result,
12972         __attribute__((unused)) struct cmdline *cl,
12973         __attribute__((unused)) void *data)
12974 {
12975         struct cmd_macsec_offload_off_result *res = parsed_result;
12976         int ret = -ENOTSUP;
12977         portid_t port_id = res->port_id;
12978
12979         if (port_id_is_invalid(port_id, ENABLED_WARN))
12980                 return;
12981
12982         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12983 #ifdef RTE_LIBRTE_IXGBE_PMD
12984         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12985 #endif
12986
12987         switch (ret) {
12988         case 0:
12989                 break;
12990         case -ENODEV:
12991                 printf("invalid port_id %d\n", port_id);
12992                 break;
12993         case -ENOTSUP:
12994                 printf("not supported on port %d\n", port_id);
12995                 break;
12996         default:
12997                 printf("programming error: (%s)\n", strerror(-ret));
12998         }
12999 }
13000
13001 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13002         .f = cmd_set_macsec_offload_off_parsed,
13003         .data = NULL,
13004         .help_str = "set macsec offload <port_id> off",
13005         .tokens = {
13006                 (void *)&cmd_macsec_offload_off_set,
13007                 (void *)&cmd_macsec_offload_off_macsec,
13008                 (void *)&cmd_macsec_offload_off_offload,
13009                 (void *)&cmd_macsec_offload_off_port_id,
13010                 (void *)&cmd_macsec_offload_off_off,
13011                 NULL,
13012         },
13013 };
13014
13015 /* Common result structure for MACsec secure connection configure */
13016 struct cmd_macsec_sc_result {
13017         cmdline_fixed_string_t set;
13018         cmdline_fixed_string_t macsec;
13019         cmdline_fixed_string_t sc;
13020         cmdline_fixed_string_t tx_rx;
13021         portid_t port_id;
13022         struct ether_addr mac;
13023         uint16_t pi;
13024 };
13025
13026 /* Common CLI fields for MACsec secure connection configure */
13027 cmdline_parse_token_string_t cmd_macsec_sc_set =
13028         TOKEN_STRING_INITIALIZER
13029                 (struct cmd_macsec_sc_result,
13030                  set, "set");
13031 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13032         TOKEN_STRING_INITIALIZER
13033                 (struct cmd_macsec_sc_result,
13034                  macsec, "macsec");
13035 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13036         TOKEN_STRING_INITIALIZER
13037                 (struct cmd_macsec_sc_result,
13038                  sc, "sc");
13039 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13040         TOKEN_STRING_INITIALIZER
13041                 (struct cmd_macsec_sc_result,
13042                  tx_rx, "tx#rx");
13043 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13044         TOKEN_NUM_INITIALIZER
13045                 (struct cmd_macsec_sc_result,
13046                  port_id, UINT16);
13047 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13048         TOKEN_ETHERADDR_INITIALIZER
13049                 (struct cmd_macsec_sc_result,
13050                  mac);
13051 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13052         TOKEN_NUM_INITIALIZER
13053                 (struct cmd_macsec_sc_result,
13054                  pi, UINT16);
13055
13056 static void
13057 cmd_set_macsec_sc_parsed(
13058         void *parsed_result,
13059         __attribute__((unused)) struct cmdline *cl,
13060         __attribute__((unused)) void *data)
13061 {
13062         struct cmd_macsec_sc_result *res = parsed_result;
13063         int ret = -ENOTSUP;
13064         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13065
13066 #ifdef RTE_LIBRTE_IXGBE_PMD
13067         ret = is_tx ?
13068                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13069                                 res->mac.addr_bytes) :
13070                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13071                                 res->mac.addr_bytes, res->pi);
13072 #endif
13073         RTE_SET_USED(is_tx);
13074
13075         switch (ret) {
13076         case 0:
13077                 break;
13078         case -ENODEV:
13079                 printf("invalid port_id %d\n", res->port_id);
13080                 break;
13081         case -ENOTSUP:
13082                 printf("not supported on port %d\n", res->port_id);
13083                 break;
13084         default:
13085                 printf("programming error: (%s)\n", strerror(-ret));
13086         }
13087 }
13088
13089 cmdline_parse_inst_t cmd_set_macsec_sc = {
13090         .f = cmd_set_macsec_sc_parsed,
13091         .data = NULL,
13092         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13093         .tokens = {
13094                 (void *)&cmd_macsec_sc_set,
13095                 (void *)&cmd_macsec_sc_macsec,
13096                 (void *)&cmd_macsec_sc_sc,
13097                 (void *)&cmd_macsec_sc_tx_rx,
13098                 (void *)&cmd_macsec_sc_port_id,
13099                 (void *)&cmd_macsec_sc_mac,
13100                 (void *)&cmd_macsec_sc_pi,
13101                 NULL,
13102         },
13103 };
13104
13105 /* Common result structure for MACsec secure connection configure */
13106 struct cmd_macsec_sa_result {
13107         cmdline_fixed_string_t set;
13108         cmdline_fixed_string_t macsec;
13109         cmdline_fixed_string_t sa;
13110         cmdline_fixed_string_t tx_rx;
13111         portid_t port_id;
13112         uint8_t idx;
13113         uint8_t an;
13114         uint32_t pn;
13115         cmdline_fixed_string_t key;
13116 };
13117
13118 /* Common CLI fields for MACsec secure connection configure */
13119 cmdline_parse_token_string_t cmd_macsec_sa_set =
13120         TOKEN_STRING_INITIALIZER
13121                 (struct cmd_macsec_sa_result,
13122                  set, "set");
13123 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13124         TOKEN_STRING_INITIALIZER
13125                 (struct cmd_macsec_sa_result,
13126                  macsec, "macsec");
13127 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13128         TOKEN_STRING_INITIALIZER
13129                 (struct cmd_macsec_sa_result,
13130                  sa, "sa");
13131 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13132         TOKEN_STRING_INITIALIZER
13133                 (struct cmd_macsec_sa_result,
13134                  tx_rx, "tx#rx");
13135 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13136         TOKEN_NUM_INITIALIZER
13137                 (struct cmd_macsec_sa_result,
13138                  port_id, UINT16);
13139 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13140         TOKEN_NUM_INITIALIZER
13141                 (struct cmd_macsec_sa_result,
13142                  idx, UINT8);
13143 cmdline_parse_token_num_t cmd_macsec_sa_an =
13144         TOKEN_NUM_INITIALIZER
13145                 (struct cmd_macsec_sa_result,
13146                  an, UINT8);
13147 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13148         TOKEN_NUM_INITIALIZER
13149                 (struct cmd_macsec_sa_result,
13150                  pn, UINT32);
13151 cmdline_parse_token_string_t cmd_macsec_sa_key =
13152         TOKEN_STRING_INITIALIZER
13153                 (struct cmd_macsec_sa_result,
13154                  key, NULL);
13155
13156 static void
13157 cmd_set_macsec_sa_parsed(
13158         void *parsed_result,
13159         __attribute__((unused)) struct cmdline *cl,
13160         __attribute__((unused)) void *data)
13161 {
13162         struct cmd_macsec_sa_result *res = parsed_result;
13163         int ret = -ENOTSUP;
13164         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13165         uint8_t key[16] = { 0 };
13166         uint8_t xdgt0;
13167         uint8_t xdgt1;
13168         int key_len;
13169         int i;
13170
13171         key_len = strlen(res->key) / 2;
13172         if (key_len > 16)
13173                 key_len = 16;
13174
13175         for (i = 0; i < key_len; i++) {
13176                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13177                 if (xdgt0 == 0xFF)
13178                         return;
13179                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13180                 if (xdgt1 == 0xFF)
13181                         return;
13182                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13183         }
13184
13185 #ifdef RTE_LIBRTE_IXGBE_PMD
13186         ret = is_tx ?
13187                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13188                         res->idx, res->an, res->pn, key) :
13189                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13190                         res->idx, res->an, res->pn, key);
13191 #endif
13192         RTE_SET_USED(is_tx);
13193         RTE_SET_USED(key);
13194
13195         switch (ret) {
13196         case 0:
13197                 break;
13198         case -EINVAL:
13199                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13200                 break;
13201         case -ENODEV:
13202                 printf("invalid port_id %d\n", res->port_id);
13203                 break;
13204         case -ENOTSUP:
13205                 printf("not supported on port %d\n", res->port_id);
13206                 break;
13207         default:
13208                 printf("programming error: (%s)\n", strerror(-ret));
13209         }
13210 }
13211
13212 cmdline_parse_inst_t cmd_set_macsec_sa = {
13213         .f = cmd_set_macsec_sa_parsed,
13214         .data = NULL,
13215         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13216         .tokens = {
13217                 (void *)&cmd_macsec_sa_set,
13218                 (void *)&cmd_macsec_sa_macsec,
13219                 (void *)&cmd_macsec_sa_sa,
13220                 (void *)&cmd_macsec_sa_tx_rx,
13221                 (void *)&cmd_macsec_sa_port_id,
13222                 (void *)&cmd_macsec_sa_idx,
13223                 (void *)&cmd_macsec_sa_an,
13224                 (void *)&cmd_macsec_sa_pn,
13225                 (void *)&cmd_macsec_sa_key,
13226                 NULL,
13227         },
13228 };
13229
13230 /* VF unicast promiscuous mode configuration */
13231
13232 /* Common result structure for VF unicast promiscuous mode */
13233 struct cmd_vf_promisc_result {
13234         cmdline_fixed_string_t set;
13235         cmdline_fixed_string_t vf;
13236         cmdline_fixed_string_t promisc;
13237         portid_t port_id;
13238         uint32_t vf_id;
13239         cmdline_fixed_string_t on_off;
13240 };
13241
13242 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13243 cmdline_parse_token_string_t cmd_vf_promisc_set =
13244         TOKEN_STRING_INITIALIZER
13245                 (struct cmd_vf_promisc_result,
13246                  set, "set");
13247 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13248         TOKEN_STRING_INITIALIZER
13249                 (struct cmd_vf_promisc_result,
13250                  vf, "vf");
13251 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13252         TOKEN_STRING_INITIALIZER
13253                 (struct cmd_vf_promisc_result,
13254                  promisc, "promisc");
13255 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13256         TOKEN_NUM_INITIALIZER
13257                 (struct cmd_vf_promisc_result,
13258                  port_id, UINT16);
13259 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13260         TOKEN_NUM_INITIALIZER
13261                 (struct cmd_vf_promisc_result,
13262                  vf_id, UINT32);
13263 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13264         TOKEN_STRING_INITIALIZER
13265                 (struct cmd_vf_promisc_result,
13266                  on_off, "on#off");
13267
13268 static void
13269 cmd_set_vf_promisc_parsed(
13270         void *parsed_result,
13271         __attribute__((unused)) struct cmdline *cl,
13272         __attribute__((unused)) void *data)
13273 {
13274         struct cmd_vf_promisc_result *res = parsed_result;
13275         int ret = -ENOTSUP;
13276
13277         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13278
13279         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13280                 return;
13281
13282 #ifdef RTE_LIBRTE_I40E_PMD
13283         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13284                                                   res->vf_id, is_on);
13285 #endif
13286
13287         switch (ret) {
13288         case 0:
13289                 break;
13290         case -EINVAL:
13291                 printf("invalid vf_id %d\n", res->vf_id);
13292                 break;
13293         case -ENODEV:
13294                 printf("invalid port_id %d\n", res->port_id);
13295                 break;
13296         case -ENOTSUP:
13297                 printf("function not implemented\n");
13298                 break;
13299         default:
13300                 printf("programming error: (%s)\n", strerror(-ret));
13301         }
13302 }
13303
13304 cmdline_parse_inst_t cmd_set_vf_promisc = {
13305         .f = cmd_set_vf_promisc_parsed,
13306         .data = NULL,
13307         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13308                 "Set unicast promiscuous mode for a VF from the PF",
13309         .tokens = {
13310                 (void *)&cmd_vf_promisc_set,
13311                 (void *)&cmd_vf_promisc_vf,
13312                 (void *)&cmd_vf_promisc_promisc,
13313                 (void *)&cmd_vf_promisc_port_id,
13314                 (void *)&cmd_vf_promisc_vf_id,
13315                 (void *)&cmd_vf_promisc_on_off,
13316                 NULL,
13317         },
13318 };
13319
13320 /* VF multicast promiscuous mode configuration */
13321
13322 /* Common result structure for VF multicast promiscuous mode */
13323 struct cmd_vf_allmulti_result {
13324         cmdline_fixed_string_t set;
13325         cmdline_fixed_string_t vf;
13326         cmdline_fixed_string_t allmulti;
13327         portid_t port_id;
13328         uint32_t vf_id;
13329         cmdline_fixed_string_t on_off;
13330 };
13331
13332 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13333 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13334         TOKEN_STRING_INITIALIZER
13335                 (struct cmd_vf_allmulti_result,
13336                  set, "set");
13337 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13338         TOKEN_STRING_INITIALIZER
13339                 (struct cmd_vf_allmulti_result,
13340                  vf, "vf");
13341 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13342         TOKEN_STRING_INITIALIZER
13343                 (struct cmd_vf_allmulti_result,
13344                  allmulti, "allmulti");
13345 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13346         TOKEN_NUM_INITIALIZER
13347                 (struct cmd_vf_allmulti_result,
13348                  port_id, UINT16);
13349 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13350         TOKEN_NUM_INITIALIZER
13351                 (struct cmd_vf_allmulti_result,
13352                  vf_id, UINT32);
13353 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13354         TOKEN_STRING_INITIALIZER
13355                 (struct cmd_vf_allmulti_result,
13356                  on_off, "on#off");
13357
13358 static void
13359 cmd_set_vf_allmulti_parsed(
13360         void *parsed_result,
13361         __attribute__((unused)) struct cmdline *cl,
13362         __attribute__((unused)) void *data)
13363 {
13364         struct cmd_vf_allmulti_result *res = parsed_result;
13365         int ret = -ENOTSUP;
13366
13367         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13368
13369         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13370                 return;
13371
13372 #ifdef RTE_LIBRTE_I40E_PMD
13373         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13374                                                     res->vf_id, is_on);
13375 #endif
13376
13377         switch (ret) {
13378         case 0:
13379                 break;
13380         case -EINVAL:
13381                 printf("invalid vf_id %d\n", res->vf_id);
13382                 break;
13383         case -ENODEV:
13384                 printf("invalid port_id %d\n", res->port_id);
13385                 break;
13386         case -ENOTSUP:
13387                 printf("function not implemented\n");
13388                 break;
13389         default:
13390                 printf("programming error: (%s)\n", strerror(-ret));
13391         }
13392 }
13393
13394 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13395         .f = cmd_set_vf_allmulti_parsed,
13396         .data = NULL,
13397         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13398                 "Set multicast promiscuous mode for a VF from the PF",
13399         .tokens = {
13400                 (void *)&cmd_vf_allmulti_set,
13401                 (void *)&cmd_vf_allmulti_vf,
13402                 (void *)&cmd_vf_allmulti_allmulti,
13403                 (void *)&cmd_vf_allmulti_port_id,
13404                 (void *)&cmd_vf_allmulti_vf_id,
13405                 (void *)&cmd_vf_allmulti_on_off,
13406                 NULL,
13407         },
13408 };
13409
13410 /* vf broadcast mode configuration */
13411
13412 /* Common result structure for vf broadcast */
13413 struct cmd_set_vf_broadcast_result {
13414         cmdline_fixed_string_t set;
13415         cmdline_fixed_string_t vf;
13416         cmdline_fixed_string_t broadcast;
13417         portid_t port_id;
13418         uint16_t vf_id;
13419         cmdline_fixed_string_t on_off;
13420 };
13421
13422 /* Common CLI fields for vf broadcast enable disable */
13423 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13424         TOKEN_STRING_INITIALIZER
13425                 (struct cmd_set_vf_broadcast_result,
13426                  set, "set");
13427 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13428         TOKEN_STRING_INITIALIZER
13429                 (struct cmd_set_vf_broadcast_result,
13430                  vf, "vf");
13431 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_set_vf_broadcast_result,
13434                  broadcast, "broadcast");
13435 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13436         TOKEN_NUM_INITIALIZER
13437                 (struct cmd_set_vf_broadcast_result,
13438                  port_id, UINT16);
13439 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13440         TOKEN_NUM_INITIALIZER
13441                 (struct cmd_set_vf_broadcast_result,
13442                  vf_id, UINT16);
13443 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_set_vf_broadcast_result,
13446                  on_off, "on#off");
13447
13448 static void
13449 cmd_set_vf_broadcast_parsed(
13450         void *parsed_result,
13451         __attribute__((unused)) struct cmdline *cl,
13452         __attribute__((unused)) void *data)
13453 {
13454         struct cmd_set_vf_broadcast_result *res = parsed_result;
13455         int ret = -ENOTSUP;
13456
13457         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13458
13459         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13460                 return;
13461
13462 #ifdef RTE_LIBRTE_I40E_PMD
13463         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13464                                             res->vf_id, is_on);
13465 #endif
13466
13467         switch (ret) {
13468         case 0:
13469                 break;
13470         case -EINVAL:
13471                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13472                 break;
13473         case -ENODEV:
13474                 printf("invalid port_id %d\n", res->port_id);
13475                 break;
13476         case -ENOTSUP:
13477                 printf("function not implemented\n");
13478                 break;
13479         default:
13480                 printf("programming error: (%s)\n", strerror(-ret));
13481         }
13482 }
13483
13484 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13485         .f = cmd_set_vf_broadcast_parsed,
13486         .data = NULL,
13487         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13488         .tokens = {
13489                 (void *)&cmd_set_vf_broadcast_set,
13490                 (void *)&cmd_set_vf_broadcast_vf,
13491                 (void *)&cmd_set_vf_broadcast_broadcast,
13492                 (void *)&cmd_set_vf_broadcast_port_id,
13493                 (void *)&cmd_set_vf_broadcast_vf_id,
13494                 (void *)&cmd_set_vf_broadcast_on_off,
13495                 NULL,
13496         },
13497 };
13498
13499 /* vf vlan tag configuration */
13500
13501 /* Common result structure for vf vlan tag */
13502 struct cmd_set_vf_vlan_tag_result {
13503         cmdline_fixed_string_t set;
13504         cmdline_fixed_string_t vf;
13505         cmdline_fixed_string_t vlan;
13506         cmdline_fixed_string_t tag;
13507         portid_t port_id;
13508         uint16_t vf_id;
13509         cmdline_fixed_string_t on_off;
13510 };
13511
13512 /* Common CLI fields for vf vlan tag enable disable */
13513 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13514         TOKEN_STRING_INITIALIZER
13515                 (struct cmd_set_vf_vlan_tag_result,
13516                  set, "set");
13517 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13518         TOKEN_STRING_INITIALIZER
13519                 (struct cmd_set_vf_vlan_tag_result,
13520                  vf, "vf");
13521 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13522         TOKEN_STRING_INITIALIZER
13523                 (struct cmd_set_vf_vlan_tag_result,
13524                  vlan, "vlan");
13525 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13526         TOKEN_STRING_INITIALIZER
13527                 (struct cmd_set_vf_vlan_tag_result,
13528                  tag, "tag");
13529 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13530         TOKEN_NUM_INITIALIZER
13531                 (struct cmd_set_vf_vlan_tag_result,
13532                  port_id, UINT16);
13533 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13534         TOKEN_NUM_INITIALIZER
13535                 (struct cmd_set_vf_vlan_tag_result,
13536                  vf_id, UINT16);
13537 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_set_vf_vlan_tag_result,
13540                  on_off, "on#off");
13541
13542 static void
13543 cmd_set_vf_vlan_tag_parsed(
13544         void *parsed_result,
13545         __attribute__((unused)) struct cmdline *cl,
13546         __attribute__((unused)) void *data)
13547 {
13548         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13549         int ret = -ENOTSUP;
13550
13551         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13552
13553         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13554                 return;
13555
13556 #ifdef RTE_LIBRTE_I40E_PMD
13557         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13558                                            res->vf_id, is_on);
13559 #endif
13560
13561         switch (ret) {
13562         case 0:
13563                 break;
13564         case -EINVAL:
13565                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13566                 break;
13567         case -ENODEV:
13568                 printf("invalid port_id %d\n", res->port_id);
13569                 break;
13570         case -ENOTSUP:
13571                 printf("function not implemented\n");
13572                 break;
13573         default:
13574                 printf("programming error: (%s)\n", strerror(-ret));
13575         }
13576 }
13577
13578 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13579         .f = cmd_set_vf_vlan_tag_parsed,
13580         .data = NULL,
13581         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13582         .tokens = {
13583                 (void *)&cmd_set_vf_vlan_tag_set,
13584                 (void *)&cmd_set_vf_vlan_tag_vf,
13585                 (void *)&cmd_set_vf_vlan_tag_vlan,
13586                 (void *)&cmd_set_vf_vlan_tag_tag,
13587                 (void *)&cmd_set_vf_vlan_tag_port_id,
13588                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13589                 (void *)&cmd_set_vf_vlan_tag_on_off,
13590                 NULL,
13591         },
13592 };
13593
13594 /* Common definition of VF and TC TX bandwidth configuration */
13595 struct cmd_vf_tc_bw_result {
13596         cmdline_fixed_string_t set;
13597         cmdline_fixed_string_t vf;
13598         cmdline_fixed_string_t tc;
13599         cmdline_fixed_string_t tx;
13600         cmdline_fixed_string_t min_bw;
13601         cmdline_fixed_string_t max_bw;
13602         cmdline_fixed_string_t strict_link_prio;
13603         portid_t port_id;
13604         uint16_t vf_id;
13605         uint8_t tc_no;
13606         uint32_t bw;
13607         cmdline_fixed_string_t bw_list;
13608         uint8_t tc_map;
13609 };
13610
13611 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13612         TOKEN_STRING_INITIALIZER
13613                 (struct cmd_vf_tc_bw_result,
13614                  set, "set");
13615 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13616         TOKEN_STRING_INITIALIZER
13617                 (struct cmd_vf_tc_bw_result,
13618                  vf, "vf");
13619 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13620         TOKEN_STRING_INITIALIZER
13621                 (struct cmd_vf_tc_bw_result,
13622                  tc, "tc");
13623 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13624         TOKEN_STRING_INITIALIZER
13625                 (struct cmd_vf_tc_bw_result,
13626                  tx, "tx");
13627 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13628         TOKEN_STRING_INITIALIZER
13629                 (struct cmd_vf_tc_bw_result,
13630                  strict_link_prio, "strict-link-priority");
13631 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_vf_tc_bw_result,
13634                  min_bw, "min-bandwidth");
13635 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13636         TOKEN_STRING_INITIALIZER
13637                 (struct cmd_vf_tc_bw_result,
13638                  max_bw, "max-bandwidth");
13639 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13640         TOKEN_NUM_INITIALIZER
13641                 (struct cmd_vf_tc_bw_result,
13642                  port_id, UINT16);
13643 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13644         TOKEN_NUM_INITIALIZER
13645                 (struct cmd_vf_tc_bw_result,
13646                  vf_id, UINT16);
13647 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13648         TOKEN_NUM_INITIALIZER
13649                 (struct cmd_vf_tc_bw_result,
13650                  tc_no, UINT8);
13651 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13652         TOKEN_NUM_INITIALIZER
13653                 (struct cmd_vf_tc_bw_result,
13654                  bw, UINT32);
13655 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13656         TOKEN_STRING_INITIALIZER
13657                 (struct cmd_vf_tc_bw_result,
13658                  bw_list, NULL);
13659 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13660         TOKEN_NUM_INITIALIZER
13661                 (struct cmd_vf_tc_bw_result,
13662                  tc_map, UINT8);
13663
13664 /* VF max bandwidth setting */
13665 static void
13666 cmd_vf_max_bw_parsed(
13667         void *parsed_result,
13668         __attribute__((unused)) struct cmdline *cl,
13669         __attribute__((unused)) void *data)
13670 {
13671         struct cmd_vf_tc_bw_result *res = parsed_result;
13672         int ret = -ENOTSUP;
13673
13674         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13675                 return;
13676
13677 #ifdef RTE_LIBRTE_I40E_PMD
13678         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13679                                          res->vf_id, res->bw);
13680 #endif
13681
13682         switch (ret) {
13683         case 0:
13684                 break;
13685         case -EINVAL:
13686                 printf("invalid vf_id %d or bandwidth %d\n",
13687                        res->vf_id, res->bw);
13688                 break;
13689         case -ENODEV:
13690                 printf("invalid port_id %d\n", res->port_id);
13691                 break;
13692         case -ENOTSUP:
13693                 printf("function not implemented\n");
13694                 break;
13695         default:
13696                 printf("programming error: (%s)\n", strerror(-ret));
13697         }
13698 }
13699
13700 cmdline_parse_inst_t cmd_vf_max_bw = {
13701         .f = cmd_vf_max_bw_parsed,
13702         .data = NULL,
13703         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13704         .tokens = {
13705                 (void *)&cmd_vf_tc_bw_set,
13706                 (void *)&cmd_vf_tc_bw_vf,
13707                 (void *)&cmd_vf_tc_bw_tx,
13708                 (void *)&cmd_vf_tc_bw_max_bw,
13709                 (void *)&cmd_vf_tc_bw_port_id,
13710                 (void *)&cmd_vf_tc_bw_vf_id,
13711                 (void *)&cmd_vf_tc_bw_bw,
13712                 NULL,
13713         },
13714 };
13715
13716 static int
13717 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13718                            uint8_t *tc_num,
13719                            char *str)
13720 {
13721         uint32_t size;
13722         const char *p, *p0 = str;
13723         char s[256];
13724         char *end;
13725         char *str_fld[16];
13726         uint16_t i;
13727         int ret;
13728
13729         p = strchr(p0, '(');
13730         if (p == NULL) {
13731                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13732                 return -1;
13733         }
13734         p++;
13735         p0 = strchr(p, ')');
13736         if (p0 == NULL) {
13737                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13738                 return -1;
13739         }
13740         size = p0 - p;
13741         if (size >= sizeof(s)) {
13742                 printf("The string size exceeds the internal buffer size\n");
13743                 return -1;
13744         }
13745         snprintf(s, sizeof(s), "%.*s", size, p);
13746         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13747         if (ret <= 0) {
13748                 printf("Failed to get the bandwidth list. ");
13749                 return -1;
13750         }
13751         *tc_num = ret;
13752         for (i = 0; i < ret; i++)
13753                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13754
13755         return 0;
13756 }
13757
13758 /* TC min bandwidth setting */
13759 static void
13760 cmd_vf_tc_min_bw_parsed(
13761         void *parsed_result,
13762         __attribute__((unused)) struct cmdline *cl,
13763         __attribute__((unused)) void *data)
13764 {
13765         struct cmd_vf_tc_bw_result *res = parsed_result;
13766         uint8_t tc_num;
13767         uint8_t bw[16];
13768         int ret = -ENOTSUP;
13769
13770         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13771                 return;
13772
13773         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13774         if (ret)
13775                 return;
13776
13777 #ifdef RTE_LIBRTE_I40E_PMD
13778         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13779                                               tc_num, bw);
13780 #endif
13781
13782         switch (ret) {
13783         case 0:
13784                 break;
13785         case -EINVAL:
13786                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13787                 break;
13788         case -ENODEV:
13789                 printf("invalid port_id %d\n", res->port_id);
13790                 break;
13791         case -ENOTSUP:
13792                 printf("function not implemented\n");
13793                 break;
13794         default:
13795                 printf("programming error: (%s)\n", strerror(-ret));
13796         }
13797 }
13798
13799 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13800         .f = cmd_vf_tc_min_bw_parsed,
13801         .data = NULL,
13802         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13803                     " <bw1, bw2, ...>",
13804         .tokens = {
13805                 (void *)&cmd_vf_tc_bw_set,
13806                 (void *)&cmd_vf_tc_bw_vf,
13807                 (void *)&cmd_vf_tc_bw_tc,
13808                 (void *)&cmd_vf_tc_bw_tx,
13809                 (void *)&cmd_vf_tc_bw_min_bw,
13810                 (void *)&cmd_vf_tc_bw_port_id,
13811                 (void *)&cmd_vf_tc_bw_vf_id,
13812                 (void *)&cmd_vf_tc_bw_bw_list,
13813                 NULL,
13814         },
13815 };
13816
13817 static void
13818 cmd_tc_min_bw_parsed(
13819         void *parsed_result,
13820         __attribute__((unused)) struct cmdline *cl,
13821         __attribute__((unused)) void *data)
13822 {
13823         struct cmd_vf_tc_bw_result *res = parsed_result;
13824         struct rte_port *port;
13825         uint8_t tc_num;
13826         uint8_t bw[16];
13827         int ret = -ENOTSUP;
13828
13829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13830                 return;
13831
13832         port = &ports[res->port_id];
13833         /** Check if the port is not started **/
13834         if (port->port_status != RTE_PORT_STOPPED) {
13835                 printf("Please stop port %d first\n", res->port_id);
13836                 return;
13837         }
13838
13839         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13840         if (ret)
13841                 return;
13842
13843 #ifdef RTE_LIBRTE_IXGBE_PMD
13844         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13845 #endif
13846
13847         switch (ret) {
13848         case 0:
13849                 break;
13850         case -EINVAL:
13851                 printf("invalid bandwidth\n");
13852                 break;
13853         case -ENODEV:
13854                 printf("invalid port_id %d\n", res->port_id);
13855                 break;
13856         case -ENOTSUP:
13857                 printf("function not implemented\n");
13858                 break;
13859         default:
13860                 printf("programming error: (%s)\n", strerror(-ret));
13861         }
13862 }
13863
13864 cmdline_parse_inst_t cmd_tc_min_bw = {
13865         .f = cmd_tc_min_bw_parsed,
13866         .data = NULL,
13867         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13868         .tokens = {
13869                 (void *)&cmd_vf_tc_bw_set,
13870                 (void *)&cmd_vf_tc_bw_tc,
13871                 (void *)&cmd_vf_tc_bw_tx,
13872                 (void *)&cmd_vf_tc_bw_min_bw,
13873                 (void *)&cmd_vf_tc_bw_port_id,
13874                 (void *)&cmd_vf_tc_bw_bw_list,
13875                 NULL,
13876         },
13877 };
13878
13879 /* TC max bandwidth setting */
13880 static void
13881 cmd_vf_tc_max_bw_parsed(
13882         void *parsed_result,
13883         __attribute__((unused)) struct cmdline *cl,
13884         __attribute__((unused)) void *data)
13885 {
13886         struct cmd_vf_tc_bw_result *res = parsed_result;
13887         int ret = -ENOTSUP;
13888
13889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13890                 return;
13891
13892 #ifdef RTE_LIBRTE_I40E_PMD
13893         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13894                                             res->tc_no, res->bw);
13895 #endif
13896
13897         switch (ret) {
13898         case 0:
13899                 break;
13900         case -EINVAL:
13901                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13902                        res->vf_id, res->tc_no, res->bw);
13903                 break;
13904         case -ENODEV:
13905                 printf("invalid port_id %d\n", res->port_id);
13906                 break;
13907         case -ENOTSUP:
13908                 printf("function not implemented\n");
13909                 break;
13910         default:
13911                 printf("programming error: (%s)\n", strerror(-ret));
13912         }
13913 }
13914
13915 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13916         .f = cmd_vf_tc_max_bw_parsed,
13917         .data = NULL,
13918         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13919                     " <bandwidth>",
13920         .tokens = {
13921                 (void *)&cmd_vf_tc_bw_set,
13922                 (void *)&cmd_vf_tc_bw_vf,
13923                 (void *)&cmd_vf_tc_bw_tc,
13924                 (void *)&cmd_vf_tc_bw_tx,
13925                 (void *)&cmd_vf_tc_bw_max_bw,
13926                 (void *)&cmd_vf_tc_bw_port_id,
13927                 (void *)&cmd_vf_tc_bw_vf_id,
13928                 (void *)&cmd_vf_tc_bw_tc_no,
13929                 (void *)&cmd_vf_tc_bw_bw,
13930                 NULL,
13931         },
13932 };
13933
13934
13935 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13936
13937 /* *** Set Port default Traffic Management Hierarchy *** */
13938 struct cmd_set_port_tm_hierarchy_default_result {
13939         cmdline_fixed_string_t set;
13940         cmdline_fixed_string_t port;
13941         cmdline_fixed_string_t tm;
13942         cmdline_fixed_string_t hierarchy;
13943         cmdline_fixed_string_t def;
13944         portid_t port_id;
13945 };
13946
13947 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13948         TOKEN_STRING_INITIALIZER(
13949                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13950 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13951         TOKEN_STRING_INITIALIZER(
13952                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13953 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13954         TOKEN_STRING_INITIALIZER(
13955                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13956 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
13957         TOKEN_STRING_INITIALIZER(
13958                 struct cmd_set_port_tm_hierarchy_default_result,
13959                         hierarchy, "hierarchy");
13960 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
13961         TOKEN_STRING_INITIALIZER(
13962                 struct cmd_set_port_tm_hierarchy_default_result,
13963                         def, "default");
13964 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
13965         TOKEN_NUM_INITIALIZER(
13966                 struct cmd_set_port_tm_hierarchy_default_result,
13967                         port_id, UINT16);
13968
13969 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
13970         __attribute__((unused)) struct cmdline *cl,
13971         __attribute__((unused)) void *data)
13972 {
13973         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
13974         struct rte_port *p;
13975         portid_t port_id = res->port_id;
13976
13977         if (port_id_is_invalid(port_id, ENABLED_WARN))
13978                 return;
13979
13980         p = &ports[port_id];
13981
13982         /* Port tm flag */
13983         if (p->softport.tm_flag == 0) {
13984                 printf("  tm not enabled on port %u (error)\n", port_id);
13985                 return;
13986         }
13987
13988         /* Forward mode: tm */
13989         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
13990                 printf("  tm mode not enabled(error)\n");
13991                 return;
13992         }
13993
13994         /* Set the default tm hierarchy */
13995         p->softport.tm.default_hierarchy_enable = 1;
13996 }
13997
13998 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
13999         .f = cmd_set_port_tm_hierarchy_default_parsed,
14000         .data = NULL,
14001         .help_str = "set port tm hierarchy default <port_id>",
14002         .tokens = {
14003                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14004                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14005                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14006                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14007                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14008                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14009                 NULL,
14010         },
14011 };
14012 #endif
14013
14014 /* Strict link priority scheduling mode setting */
14015 static void
14016 cmd_strict_link_prio_parsed(
14017         void *parsed_result,
14018         __attribute__((unused)) struct cmdline *cl,
14019         __attribute__((unused)) void *data)
14020 {
14021         struct cmd_vf_tc_bw_result *res = parsed_result;
14022         int ret = -ENOTSUP;
14023
14024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14025                 return;
14026
14027 #ifdef RTE_LIBRTE_I40E_PMD
14028         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14029 #endif
14030
14031         switch (ret) {
14032         case 0:
14033                 break;
14034         case -EINVAL:
14035                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14036                 break;
14037         case -ENODEV:
14038                 printf("invalid port_id %d\n", res->port_id);
14039                 break;
14040         case -ENOTSUP:
14041                 printf("function not implemented\n");
14042                 break;
14043         default:
14044                 printf("programming error: (%s)\n", strerror(-ret));
14045         }
14046 }
14047
14048 cmdline_parse_inst_t cmd_strict_link_prio = {
14049         .f = cmd_strict_link_prio_parsed,
14050         .data = NULL,
14051         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14052         .tokens = {
14053                 (void *)&cmd_vf_tc_bw_set,
14054                 (void *)&cmd_vf_tc_bw_tx,
14055                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14056                 (void *)&cmd_vf_tc_bw_port_id,
14057                 (void *)&cmd_vf_tc_bw_tc_map,
14058                 NULL,
14059         },
14060 };
14061
14062 /* Load dynamic device personalization*/
14063 struct cmd_ddp_add_result {
14064         cmdline_fixed_string_t ddp;
14065         cmdline_fixed_string_t add;
14066         portid_t port_id;
14067         char filepath[];
14068 };
14069
14070 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14071         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14072 cmdline_parse_token_string_t cmd_ddp_add_add =
14073         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14074 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14075         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14076 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14077         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14078
14079 static void
14080 cmd_ddp_add_parsed(
14081         void *parsed_result,
14082         __attribute__((unused)) struct cmdline *cl,
14083         __attribute__((unused)) void *data)
14084 {
14085         struct cmd_ddp_add_result *res = parsed_result;
14086         uint8_t *buff;
14087         uint32_t size;
14088         char *filepath;
14089         char *file_fld[2];
14090         int file_num;
14091         int ret = -ENOTSUP;
14092
14093         if (res->port_id > nb_ports) {
14094                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14095                 return;
14096         }
14097
14098         if (!all_ports_stopped()) {
14099                 printf("Please stop all ports first\n");
14100                 return;
14101         }
14102
14103         filepath = strdup(res->filepath);
14104         if (filepath == NULL) {
14105                 printf("Failed to allocate memory\n");
14106                 return;
14107         }
14108         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14109
14110         buff = open_ddp_package_file(file_fld[0], &size);
14111         if (!buff) {
14112                 free((void *)filepath);
14113                 return;
14114         }
14115
14116 #ifdef RTE_LIBRTE_I40E_PMD
14117         if (ret == -ENOTSUP)
14118                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14119                                                buff, size,
14120                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14121 #endif
14122
14123         if (ret == -EEXIST)
14124                 printf("Profile has already existed.\n");
14125         else if (ret < 0)
14126                 printf("Failed to load profile.\n");
14127         else if (file_num == 2)
14128                 save_ddp_package_file(file_fld[1], buff, size);
14129
14130         close_ddp_package_file(buff);
14131         free((void *)filepath);
14132 }
14133
14134 cmdline_parse_inst_t cmd_ddp_add = {
14135         .f = cmd_ddp_add_parsed,
14136         .data = NULL,
14137         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14138         .tokens = {
14139                 (void *)&cmd_ddp_add_ddp,
14140                 (void *)&cmd_ddp_add_add,
14141                 (void *)&cmd_ddp_add_port_id,
14142                 (void *)&cmd_ddp_add_filepath,
14143                 NULL,
14144         },
14145 };
14146
14147 /* Delete dynamic device personalization*/
14148 struct cmd_ddp_del_result {
14149         cmdline_fixed_string_t ddp;
14150         cmdline_fixed_string_t del;
14151         portid_t port_id;
14152         char filepath[];
14153 };
14154
14155 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14156         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14157 cmdline_parse_token_string_t cmd_ddp_del_del =
14158         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14159 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14160         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14161 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14162         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14163
14164 static void
14165 cmd_ddp_del_parsed(
14166         void *parsed_result,
14167         __attribute__((unused)) struct cmdline *cl,
14168         __attribute__((unused)) void *data)
14169 {
14170         struct cmd_ddp_del_result *res = parsed_result;
14171         uint8_t *buff;
14172         uint32_t size;
14173         int ret = -ENOTSUP;
14174
14175         if (res->port_id > nb_ports) {
14176                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14177                 return;
14178         }
14179
14180         if (!all_ports_stopped()) {
14181                 printf("Please stop all ports first\n");
14182                 return;
14183         }
14184
14185         buff = open_ddp_package_file(res->filepath, &size);
14186         if (!buff)
14187                 return;
14188
14189 #ifdef RTE_LIBRTE_I40E_PMD
14190         if (ret == -ENOTSUP)
14191                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14192                                                buff, size,
14193                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14194 #endif
14195
14196         if (ret == -EACCES)
14197                 printf("Profile does not exist.\n");
14198         else if (ret < 0)
14199                 printf("Failed to delete profile.\n");
14200
14201         close_ddp_package_file(buff);
14202 }
14203
14204 cmdline_parse_inst_t cmd_ddp_del = {
14205         .f = cmd_ddp_del_parsed,
14206         .data = NULL,
14207         .help_str = "ddp del <port_id> <profile_path>",
14208         .tokens = {
14209                 (void *)&cmd_ddp_del_ddp,
14210                 (void *)&cmd_ddp_del_del,
14211                 (void *)&cmd_ddp_del_port_id,
14212                 (void *)&cmd_ddp_del_filepath,
14213                 NULL,
14214         },
14215 };
14216
14217 /* Get dynamic device personalization profile info */
14218 struct cmd_ddp_info_result {
14219         cmdline_fixed_string_t ddp;
14220         cmdline_fixed_string_t get;
14221         cmdline_fixed_string_t info;
14222         char filepath[];
14223 };
14224
14225 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14226         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14227 cmdline_parse_token_string_t cmd_ddp_info_get =
14228         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14229 cmdline_parse_token_string_t cmd_ddp_info_info =
14230         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14231 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14232         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14233
14234 static void
14235 cmd_ddp_info_parsed(
14236         void *parsed_result,
14237         __attribute__((unused)) struct cmdline *cl,
14238         __attribute__((unused)) void *data)
14239 {
14240         struct cmd_ddp_info_result *res = parsed_result;
14241         uint8_t *pkg;
14242         uint32_t pkg_size;
14243         int ret = -ENOTSUP;
14244 #ifdef RTE_LIBRTE_I40E_PMD
14245         uint32_t i, j, n;
14246         uint8_t *buff;
14247         uint32_t buff_size = 0;
14248         struct rte_pmd_i40e_profile_info info;
14249         uint32_t dev_num = 0;
14250         struct rte_pmd_i40e_ddp_device_id *devs;
14251         uint32_t proto_num = 0;
14252         struct rte_pmd_i40e_proto_info *proto;
14253         uint32_t pctype_num = 0;
14254         struct rte_pmd_i40e_ptype_info *pctype;
14255         uint32_t ptype_num = 0;
14256         struct rte_pmd_i40e_ptype_info *ptype;
14257         uint8_t proto_id;
14258
14259 #endif
14260
14261         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14262         if (!pkg)
14263                 return;
14264
14265 #ifdef RTE_LIBRTE_I40E_PMD
14266         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14267                                 (uint8_t *)&info, sizeof(info),
14268                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14269         if (!ret) {
14270                 printf("Global Track id:       0x%x\n", info.track_id);
14271                 printf("Global Version:        %d.%d.%d.%d\n",
14272                         info.version.major,
14273                         info.version.minor,
14274                         info.version.update,
14275                         info.version.draft);
14276                 printf("Global Package name:   %s\n\n", info.name);
14277         }
14278
14279         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14280                                 (uint8_t *)&info, sizeof(info),
14281                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14282         if (!ret) {
14283                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14284                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14285                         info.version.major,
14286                         info.version.minor,
14287                         info.version.update,
14288                         info.version.draft);
14289                 printf("i40e Profile name:     %s\n\n", info.name);
14290         }
14291
14292         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14293                                 (uint8_t *)&buff_size, sizeof(buff_size),
14294                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14295         if (!ret && buff_size) {
14296                 buff = (uint8_t *)malloc(buff_size);
14297                 if (buff) {
14298                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14299                                                 buff, buff_size,
14300                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14301                         if (!ret)
14302                                 printf("Package Notes:\n%s\n\n", buff);
14303                         free(buff);
14304                 }
14305         }
14306
14307         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14308                                 (uint8_t *)&dev_num, sizeof(dev_num),
14309                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14310         if (!ret && dev_num) {
14311                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14312                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14313                 if (devs) {
14314                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14315                                                 (uint8_t *)devs, buff_size,
14316                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14317                         if (!ret) {
14318                                 printf("List of supported devices:\n");
14319                                 for (i = 0; i < dev_num; i++) {
14320                                         printf("  %04X:%04X %04X:%04X\n",
14321                                                 devs[i].vendor_dev_id >> 16,
14322                                                 devs[i].vendor_dev_id & 0xFFFF,
14323                                                 devs[i].sub_vendor_dev_id >> 16,
14324                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14325                                 }
14326                                 printf("\n");
14327                         }
14328                         free(devs);
14329                 }
14330         }
14331
14332         /* get information about protocols and packet types */
14333         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14334                 (uint8_t *)&proto_num, sizeof(proto_num),
14335                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14336         if (ret || !proto_num)
14337                 goto no_print_return;
14338
14339         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14340         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14341         if (!proto)
14342                 goto no_print_return;
14343
14344         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14345                                         buff_size,
14346                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14347         if (!ret) {
14348                 printf("List of used protocols:\n");
14349                 for (i = 0; i < proto_num; i++)
14350                         printf("  %2u: %s\n", proto[i].proto_id,
14351                                proto[i].name);
14352                 printf("\n");
14353         }
14354         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14355                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14356                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14357         if (ret || !pctype_num)
14358                 goto no_print_pctypes;
14359
14360         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14361         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14362         if (!pctype)
14363                 goto no_print_pctypes;
14364
14365         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14366                                         buff_size,
14367                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14368         if (ret) {
14369                 free(pctype);
14370                 goto no_print_pctypes;
14371         }
14372
14373         printf("List of defined packet classification types:\n");
14374         for (i = 0; i < pctype_num; i++) {
14375                 printf("  %2u:", pctype[i].ptype_id);
14376                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14377                         proto_id = pctype[i].protocols[j];
14378                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14379                                 for (n = 0; n < proto_num; n++) {
14380                                         if (proto[n].proto_id == proto_id) {
14381                                                 printf(" %s", proto[n].name);
14382                                                 break;
14383                                         }
14384                                 }
14385                         }
14386                 }
14387                 printf("\n");
14388         }
14389         printf("\n");
14390         free(pctype);
14391
14392 no_print_pctypes:
14393
14394         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14395                                         sizeof(ptype_num),
14396                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14397         if (ret || !ptype_num)
14398                 goto no_print_return;
14399
14400         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14401         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14402         if (!ptype)
14403                 goto no_print_return;
14404
14405         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14406                                         buff_size,
14407                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14408         if (ret) {
14409                 free(ptype);
14410                 goto no_print_return;
14411         }
14412         printf("List of defined packet types:\n");
14413         for (i = 0; i < ptype_num; i++) {
14414                 printf("  %2u:", ptype[i].ptype_id);
14415                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14416                         proto_id = ptype[i].protocols[j];
14417                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14418                                 for (n = 0; n < proto_num; n++) {
14419                                         if (proto[n].proto_id == proto_id) {
14420                                                 printf(" %s", proto[n].name);
14421                                                 break;
14422                                         }
14423                                 }
14424                         }
14425                 }
14426                 printf("\n");
14427         }
14428         free(ptype);
14429         printf("\n");
14430
14431         free(proto);
14432         ret = 0;
14433 no_print_return:
14434 #endif
14435         if (ret == -ENOTSUP)
14436                 printf("Function not supported in PMD driver\n");
14437         close_ddp_package_file(pkg);
14438 }
14439
14440 cmdline_parse_inst_t cmd_ddp_get_info = {
14441         .f = cmd_ddp_info_parsed,
14442         .data = NULL,
14443         .help_str = "ddp get info <profile_path>",
14444         .tokens = {
14445                 (void *)&cmd_ddp_info_ddp,
14446                 (void *)&cmd_ddp_info_get,
14447                 (void *)&cmd_ddp_info_info,
14448                 (void *)&cmd_ddp_info_filepath,
14449                 NULL,
14450         },
14451 };
14452
14453 /* Get dynamic device personalization profile info list*/
14454 #define PROFILE_INFO_SIZE 48
14455 #define MAX_PROFILE_NUM 16
14456
14457 struct cmd_ddp_get_list_result {
14458         cmdline_fixed_string_t ddp;
14459         cmdline_fixed_string_t get;
14460         cmdline_fixed_string_t list;
14461         portid_t port_id;
14462 };
14463
14464 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14465         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14466 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14467         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14468 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14469         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14470 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14471         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14472
14473 static void
14474 cmd_ddp_get_list_parsed(
14475         void *parsed_result,
14476         __attribute__((unused)) struct cmdline *cl,
14477         __attribute__((unused)) void *data)
14478 {
14479         struct cmd_ddp_get_list_result *res = parsed_result;
14480 #ifdef RTE_LIBRTE_I40E_PMD
14481         struct rte_pmd_i40e_profile_list *p_list;
14482         struct rte_pmd_i40e_profile_info *p_info;
14483         uint32_t p_num;
14484         uint32_t size;
14485         uint32_t i;
14486 #endif
14487         int ret = -ENOTSUP;
14488
14489         if (res->port_id > nb_ports) {
14490                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14491                 return;
14492         }
14493
14494 #ifdef RTE_LIBRTE_I40E_PMD
14495         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14496         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14497         if (!p_list)
14498                 printf("%s: Failed to malloc buffer\n", __func__);
14499
14500         if (ret == -ENOTSUP)
14501                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14502                                                 (uint8_t *)p_list, size);
14503
14504         if (!ret) {
14505                 p_num = p_list->p_count;
14506                 printf("Profile number is: %d\n\n", p_num);
14507
14508                 for (i = 0; i < p_num; i++) {
14509                         p_info = &p_list->p_info[i];
14510                         printf("Profile %d:\n", i);
14511                         printf("Track id:     0x%x\n", p_info->track_id);
14512                         printf("Version:      %d.%d.%d.%d\n",
14513                                p_info->version.major,
14514                                p_info->version.minor,
14515                                p_info->version.update,
14516                                p_info->version.draft);
14517                         printf("Profile name: %s\n\n", p_info->name);
14518                 }
14519         }
14520
14521         free(p_list);
14522 #endif
14523
14524         if (ret < 0)
14525                 printf("Failed to get ddp list\n");
14526 }
14527
14528 cmdline_parse_inst_t cmd_ddp_get_list = {
14529         .f = cmd_ddp_get_list_parsed,
14530         .data = NULL,
14531         .help_str = "ddp get list <port_id>",
14532         .tokens = {
14533                 (void *)&cmd_ddp_get_list_ddp,
14534                 (void *)&cmd_ddp_get_list_get,
14535                 (void *)&cmd_ddp_get_list_list,
14536                 (void *)&cmd_ddp_get_list_port_id,
14537                 NULL,
14538         },
14539 };
14540
14541 /* show vf stats */
14542
14543 /* Common result structure for show vf stats */
14544 struct cmd_show_vf_stats_result {
14545         cmdline_fixed_string_t show;
14546         cmdline_fixed_string_t vf;
14547         cmdline_fixed_string_t stats;
14548         portid_t port_id;
14549         uint16_t vf_id;
14550 };
14551
14552 /* Common CLI fields show vf stats*/
14553 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14554         TOKEN_STRING_INITIALIZER
14555                 (struct cmd_show_vf_stats_result,
14556                  show, "show");
14557 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14558         TOKEN_STRING_INITIALIZER
14559                 (struct cmd_show_vf_stats_result,
14560                  vf, "vf");
14561 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14562         TOKEN_STRING_INITIALIZER
14563                 (struct cmd_show_vf_stats_result,
14564                  stats, "stats");
14565 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14566         TOKEN_NUM_INITIALIZER
14567                 (struct cmd_show_vf_stats_result,
14568                  port_id, UINT16);
14569 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14570         TOKEN_NUM_INITIALIZER
14571                 (struct cmd_show_vf_stats_result,
14572                  vf_id, UINT16);
14573
14574 static void
14575 cmd_show_vf_stats_parsed(
14576         void *parsed_result,
14577         __attribute__((unused)) struct cmdline *cl,
14578         __attribute__((unused)) void *data)
14579 {
14580         struct cmd_show_vf_stats_result *res = parsed_result;
14581         struct rte_eth_stats stats;
14582         int ret = -ENOTSUP;
14583         static const char *nic_stats_border = "########################";
14584
14585         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14586                 return;
14587
14588         memset(&stats, 0, sizeof(stats));
14589
14590 #ifdef RTE_LIBRTE_I40E_PMD
14591         if (ret == -ENOTSUP)
14592                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14593                                                 res->vf_id,
14594                                                 &stats);
14595 #endif
14596 #ifdef RTE_LIBRTE_BNXT_PMD
14597         if (ret == -ENOTSUP)
14598                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14599                                                 res->vf_id,
14600                                                 &stats);
14601 #endif
14602
14603         switch (ret) {
14604         case 0:
14605                 break;
14606         case -EINVAL:
14607                 printf("invalid vf_id %d\n", res->vf_id);
14608                 break;
14609         case -ENODEV:
14610                 printf("invalid port_id %d\n", res->port_id);
14611                 break;
14612         case -ENOTSUP:
14613                 printf("function not implemented\n");
14614                 break;
14615         default:
14616                 printf("programming error: (%s)\n", strerror(-ret));
14617         }
14618
14619         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14620                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14621
14622         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14623                "%-"PRIu64"\n",
14624                stats.ipackets, stats.imissed, stats.ibytes);
14625         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14626         printf("  RX-nombuf:  %-10"PRIu64"\n",
14627                stats.rx_nombuf);
14628         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14629                "%-"PRIu64"\n",
14630                stats.opackets, stats.oerrors, stats.obytes);
14631
14632         printf("  %s############################%s\n",
14633                                nic_stats_border, nic_stats_border);
14634 }
14635
14636 cmdline_parse_inst_t cmd_show_vf_stats = {
14637         .f = cmd_show_vf_stats_parsed,
14638         .data = NULL,
14639         .help_str = "show vf stats <port_id> <vf_id>",
14640         .tokens = {
14641                 (void *)&cmd_show_vf_stats_show,
14642                 (void *)&cmd_show_vf_stats_vf,
14643                 (void *)&cmd_show_vf_stats_stats,
14644                 (void *)&cmd_show_vf_stats_port_id,
14645                 (void *)&cmd_show_vf_stats_vf_id,
14646                 NULL,
14647         },
14648 };
14649
14650 /* clear vf stats */
14651
14652 /* Common result structure for clear vf stats */
14653 struct cmd_clear_vf_stats_result {
14654         cmdline_fixed_string_t clear;
14655         cmdline_fixed_string_t vf;
14656         cmdline_fixed_string_t stats;
14657         portid_t port_id;
14658         uint16_t vf_id;
14659 };
14660
14661 /* Common CLI fields clear vf stats*/
14662 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14663         TOKEN_STRING_INITIALIZER
14664                 (struct cmd_clear_vf_stats_result,
14665                  clear, "clear");
14666 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14667         TOKEN_STRING_INITIALIZER
14668                 (struct cmd_clear_vf_stats_result,
14669                  vf, "vf");
14670 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14671         TOKEN_STRING_INITIALIZER
14672                 (struct cmd_clear_vf_stats_result,
14673                  stats, "stats");
14674 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14675         TOKEN_NUM_INITIALIZER
14676                 (struct cmd_clear_vf_stats_result,
14677                  port_id, UINT16);
14678 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14679         TOKEN_NUM_INITIALIZER
14680                 (struct cmd_clear_vf_stats_result,
14681                  vf_id, UINT16);
14682
14683 static void
14684 cmd_clear_vf_stats_parsed(
14685         void *parsed_result,
14686         __attribute__((unused)) struct cmdline *cl,
14687         __attribute__((unused)) void *data)
14688 {
14689         struct cmd_clear_vf_stats_result *res = parsed_result;
14690         int ret = -ENOTSUP;
14691
14692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14693                 return;
14694
14695 #ifdef RTE_LIBRTE_I40E_PMD
14696         if (ret == -ENOTSUP)
14697                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14698                                                   res->vf_id);
14699 #endif
14700 #ifdef RTE_LIBRTE_BNXT_PMD
14701         if (ret == -ENOTSUP)
14702                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14703                                                   res->vf_id);
14704 #endif
14705
14706         switch (ret) {
14707         case 0:
14708                 break;
14709         case -EINVAL:
14710                 printf("invalid vf_id %d\n", res->vf_id);
14711                 break;
14712         case -ENODEV:
14713                 printf("invalid port_id %d\n", res->port_id);
14714                 break;
14715         case -ENOTSUP:
14716                 printf("function not implemented\n");
14717                 break;
14718         default:
14719                 printf("programming error: (%s)\n", strerror(-ret));
14720         }
14721 }
14722
14723 cmdline_parse_inst_t cmd_clear_vf_stats = {
14724         .f = cmd_clear_vf_stats_parsed,
14725         .data = NULL,
14726         .help_str = "clear vf stats <port_id> <vf_id>",
14727         .tokens = {
14728                 (void *)&cmd_clear_vf_stats_clear,
14729                 (void *)&cmd_clear_vf_stats_vf,
14730                 (void *)&cmd_clear_vf_stats_stats,
14731                 (void *)&cmd_clear_vf_stats_port_id,
14732                 (void *)&cmd_clear_vf_stats_vf_id,
14733                 NULL,
14734         },
14735 };
14736
14737 /* port config pctype mapping reset */
14738
14739 /* Common result structure for port config pctype mapping reset */
14740 struct cmd_pctype_mapping_reset_result {
14741         cmdline_fixed_string_t port;
14742         cmdline_fixed_string_t config;
14743         portid_t port_id;
14744         cmdline_fixed_string_t pctype;
14745         cmdline_fixed_string_t mapping;
14746         cmdline_fixed_string_t reset;
14747 };
14748
14749 /* Common CLI fields for port config pctype mapping reset*/
14750 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14751         TOKEN_STRING_INITIALIZER
14752                 (struct cmd_pctype_mapping_reset_result,
14753                  port, "port");
14754 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14755         TOKEN_STRING_INITIALIZER
14756                 (struct cmd_pctype_mapping_reset_result,
14757                  config, "config");
14758 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14759         TOKEN_NUM_INITIALIZER
14760                 (struct cmd_pctype_mapping_reset_result,
14761                  port_id, UINT16);
14762 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14763         TOKEN_STRING_INITIALIZER
14764                 (struct cmd_pctype_mapping_reset_result,
14765                  pctype, "pctype");
14766 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14767         TOKEN_STRING_INITIALIZER
14768                 (struct cmd_pctype_mapping_reset_result,
14769                  mapping, "mapping");
14770 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_pctype_mapping_reset_result,
14773                  reset, "reset");
14774
14775 static void
14776 cmd_pctype_mapping_reset_parsed(
14777         void *parsed_result,
14778         __attribute__((unused)) struct cmdline *cl,
14779         __attribute__((unused)) void *data)
14780 {
14781         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14782         int ret = -ENOTSUP;
14783
14784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14785                 return;
14786
14787 #ifdef RTE_LIBRTE_I40E_PMD
14788         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14789 #endif
14790
14791         switch (ret) {
14792         case 0:
14793                 break;
14794         case -ENODEV:
14795                 printf("invalid port_id %d\n", res->port_id);
14796                 break;
14797         case -ENOTSUP:
14798                 printf("function not implemented\n");
14799                 break;
14800         default:
14801                 printf("programming error: (%s)\n", strerror(-ret));
14802         }
14803 }
14804
14805 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14806         .f = cmd_pctype_mapping_reset_parsed,
14807         .data = NULL,
14808         .help_str = "port config <port_id> pctype mapping reset",
14809         .tokens = {
14810                 (void *)&cmd_pctype_mapping_reset_port,
14811                 (void *)&cmd_pctype_mapping_reset_config,
14812                 (void *)&cmd_pctype_mapping_reset_port_id,
14813                 (void *)&cmd_pctype_mapping_reset_pctype,
14814                 (void *)&cmd_pctype_mapping_reset_mapping,
14815                 (void *)&cmd_pctype_mapping_reset_reset,
14816                 NULL,
14817         },
14818 };
14819
14820 /* show port pctype mapping */
14821
14822 /* Common result structure for show port pctype mapping */
14823 struct cmd_pctype_mapping_get_result {
14824         cmdline_fixed_string_t show;
14825         cmdline_fixed_string_t port;
14826         portid_t port_id;
14827         cmdline_fixed_string_t pctype;
14828         cmdline_fixed_string_t mapping;
14829 };
14830
14831 /* Common CLI fields for pctype mapping get */
14832 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14833         TOKEN_STRING_INITIALIZER
14834                 (struct cmd_pctype_mapping_get_result,
14835                  show, "show");
14836 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14837         TOKEN_STRING_INITIALIZER
14838                 (struct cmd_pctype_mapping_get_result,
14839                  port, "port");
14840 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14841         TOKEN_NUM_INITIALIZER
14842                 (struct cmd_pctype_mapping_get_result,
14843                  port_id, UINT16);
14844 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14845         TOKEN_STRING_INITIALIZER
14846                 (struct cmd_pctype_mapping_get_result,
14847                  pctype, "pctype");
14848 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14849         TOKEN_STRING_INITIALIZER
14850                 (struct cmd_pctype_mapping_get_result,
14851                  mapping, "mapping");
14852
14853 static void
14854 cmd_pctype_mapping_get_parsed(
14855         void *parsed_result,
14856         __attribute__((unused)) struct cmdline *cl,
14857         __attribute__((unused)) void *data)
14858 {
14859         struct cmd_pctype_mapping_get_result *res = parsed_result;
14860         int ret = -ENOTSUP;
14861 #ifdef RTE_LIBRTE_I40E_PMD
14862         struct rte_pmd_i40e_flow_type_mapping
14863                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14864         int i, j, first_pctype;
14865 #endif
14866
14867         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14868                 return;
14869
14870 #ifdef RTE_LIBRTE_I40E_PMD
14871         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14872 #endif
14873
14874         switch (ret) {
14875         case 0:
14876                 break;
14877         case -ENODEV:
14878                 printf("invalid port_id %d\n", res->port_id);
14879                 return;
14880         case -ENOTSUP:
14881                 printf("function not implemented\n");
14882                 return;
14883         default:
14884                 printf("programming error: (%s)\n", strerror(-ret));
14885                 return;
14886         }
14887
14888 #ifdef RTE_LIBRTE_I40E_PMD
14889         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14890                 if (mapping[i].pctype != 0ULL) {
14891                         first_pctype = 1;
14892
14893                         printf("pctype: ");
14894                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14895                                 if (mapping[i].pctype & (1ULL << j)) {
14896                                         printf(first_pctype ?
14897                                                "%02d" : ",%02d", j);
14898                                         first_pctype = 0;
14899                                 }
14900                         }
14901                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14902                 }
14903         }
14904 #endif
14905 }
14906
14907 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14908         .f = cmd_pctype_mapping_get_parsed,
14909         .data = NULL,
14910         .help_str = "show port <port_id> pctype mapping",
14911         .tokens = {
14912                 (void *)&cmd_pctype_mapping_get_show,
14913                 (void *)&cmd_pctype_mapping_get_port,
14914                 (void *)&cmd_pctype_mapping_get_port_id,
14915                 (void *)&cmd_pctype_mapping_get_pctype,
14916                 (void *)&cmd_pctype_mapping_get_mapping,
14917                 NULL,
14918         },
14919 };
14920
14921 /* port config pctype mapping update */
14922
14923 /* Common result structure for port config pctype mapping update */
14924 struct cmd_pctype_mapping_update_result {
14925         cmdline_fixed_string_t port;
14926         cmdline_fixed_string_t config;
14927         portid_t port_id;
14928         cmdline_fixed_string_t pctype;
14929         cmdline_fixed_string_t mapping;
14930         cmdline_fixed_string_t update;
14931         cmdline_fixed_string_t pctype_list;
14932         uint16_t flow_type;
14933 };
14934
14935 /* Common CLI fields for pctype mapping update*/
14936 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14937         TOKEN_STRING_INITIALIZER
14938                 (struct cmd_pctype_mapping_update_result,
14939                  port, "port");
14940 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14941         TOKEN_STRING_INITIALIZER
14942                 (struct cmd_pctype_mapping_update_result,
14943                  config, "config");
14944 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14945         TOKEN_NUM_INITIALIZER
14946                 (struct cmd_pctype_mapping_update_result,
14947                  port_id, UINT16);
14948 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14949         TOKEN_STRING_INITIALIZER
14950                 (struct cmd_pctype_mapping_update_result,
14951                  pctype, "pctype");
14952 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14953         TOKEN_STRING_INITIALIZER
14954                 (struct cmd_pctype_mapping_update_result,
14955                  mapping, "mapping");
14956 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14957         TOKEN_STRING_INITIALIZER
14958                 (struct cmd_pctype_mapping_update_result,
14959                  update, "update");
14960 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14961         TOKEN_STRING_INITIALIZER
14962                 (struct cmd_pctype_mapping_update_result,
14963                  pctype_list, NULL);
14964 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14965         TOKEN_NUM_INITIALIZER
14966                 (struct cmd_pctype_mapping_update_result,
14967                  flow_type, UINT16);
14968
14969 static void
14970 cmd_pctype_mapping_update_parsed(
14971         void *parsed_result,
14972         __attribute__((unused)) struct cmdline *cl,
14973         __attribute__((unused)) void *data)
14974 {
14975         struct cmd_pctype_mapping_update_result *res = parsed_result;
14976         int ret = -ENOTSUP;
14977 #ifdef RTE_LIBRTE_I40E_PMD
14978         struct rte_pmd_i40e_flow_type_mapping mapping;
14979         unsigned int i;
14980         unsigned int nb_item;
14981         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14982 #endif
14983
14984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14985                 return;
14986
14987 #ifdef RTE_LIBRTE_I40E_PMD
14988         nb_item = parse_item_list(res->pctype_list, "pctypes",
14989                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14990         mapping.flow_type = res->flow_type;
14991         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14992                 mapping.pctype |= (1ULL << pctype_list[i]);
14993         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14994                                                 &mapping,
14995                                                 1,
14996                                                 0);
14997 #endif
14998
14999         switch (ret) {
15000         case 0:
15001                 break;
15002         case -EINVAL:
15003                 printf("invalid pctype or flow type\n");
15004                 break;
15005         case -ENODEV:
15006                 printf("invalid port_id %d\n", res->port_id);
15007                 break;
15008         case -ENOTSUP:
15009                 printf("function not implemented\n");
15010                 break;
15011         default:
15012                 printf("programming error: (%s)\n", strerror(-ret));
15013         }
15014 }
15015
15016 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15017         .f = cmd_pctype_mapping_update_parsed,
15018         .data = NULL,
15019         .help_str = "port config <port_id> pctype mapping update"
15020         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15021         .tokens = {
15022                 (void *)&cmd_pctype_mapping_update_port,
15023                 (void *)&cmd_pctype_mapping_update_config,
15024                 (void *)&cmd_pctype_mapping_update_port_id,
15025                 (void *)&cmd_pctype_mapping_update_pctype,
15026                 (void *)&cmd_pctype_mapping_update_mapping,
15027                 (void *)&cmd_pctype_mapping_update_update,
15028                 (void *)&cmd_pctype_mapping_update_pc_type,
15029                 (void *)&cmd_pctype_mapping_update_flow_type,
15030                 NULL,
15031         },
15032 };
15033
15034 /* ptype mapping get */
15035
15036 /* Common result structure for ptype mapping get */
15037 struct cmd_ptype_mapping_get_result {
15038         cmdline_fixed_string_t ptype;
15039         cmdline_fixed_string_t mapping;
15040         cmdline_fixed_string_t get;
15041         portid_t port_id;
15042         uint8_t valid_only;
15043 };
15044
15045 /* Common CLI fields for ptype mapping get */
15046 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15047         TOKEN_STRING_INITIALIZER
15048                 (struct cmd_ptype_mapping_get_result,
15049                  ptype, "ptype");
15050 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15051         TOKEN_STRING_INITIALIZER
15052                 (struct cmd_ptype_mapping_get_result,
15053                  mapping, "mapping");
15054 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15055         TOKEN_STRING_INITIALIZER
15056                 (struct cmd_ptype_mapping_get_result,
15057                  get, "get");
15058 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15059         TOKEN_NUM_INITIALIZER
15060                 (struct cmd_ptype_mapping_get_result,
15061                  port_id, UINT16);
15062 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15063         TOKEN_NUM_INITIALIZER
15064                 (struct cmd_ptype_mapping_get_result,
15065                  valid_only, UINT8);
15066
15067 static void
15068 cmd_ptype_mapping_get_parsed(
15069         void *parsed_result,
15070         __attribute__((unused)) struct cmdline *cl,
15071         __attribute__((unused)) void *data)
15072 {
15073         struct cmd_ptype_mapping_get_result *res = parsed_result;
15074         int ret = -ENOTSUP;
15075 #ifdef RTE_LIBRTE_I40E_PMD
15076         int max_ptype_num = 256;
15077         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15078         uint16_t count;
15079         int i;
15080 #endif
15081
15082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15083                 return;
15084
15085 #ifdef RTE_LIBRTE_I40E_PMD
15086         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15087                                         mapping,
15088                                         max_ptype_num,
15089                                         &count,
15090                                         res->valid_only);
15091 #endif
15092
15093         switch (ret) {
15094         case 0:
15095                 break;
15096         case -ENODEV:
15097                 printf("invalid port_id %d\n", res->port_id);
15098                 break;
15099         case -ENOTSUP:
15100                 printf("function not implemented\n");
15101                 break;
15102         default:
15103                 printf("programming error: (%s)\n", strerror(-ret));
15104         }
15105
15106 #ifdef RTE_LIBRTE_I40E_PMD
15107         if (!ret) {
15108                 for (i = 0; i < count; i++)
15109                         printf("%3d\t0x%08x\n",
15110                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15111         }
15112 #endif
15113 }
15114
15115 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15116         .f = cmd_ptype_mapping_get_parsed,
15117         .data = NULL,
15118         .help_str = "ptype mapping get <port_id> <valid_only>",
15119         .tokens = {
15120                 (void *)&cmd_ptype_mapping_get_ptype,
15121                 (void *)&cmd_ptype_mapping_get_mapping,
15122                 (void *)&cmd_ptype_mapping_get_get,
15123                 (void *)&cmd_ptype_mapping_get_port_id,
15124                 (void *)&cmd_ptype_mapping_get_valid_only,
15125                 NULL,
15126         },
15127 };
15128
15129 /* ptype mapping replace */
15130
15131 /* Common result structure for ptype mapping replace */
15132 struct cmd_ptype_mapping_replace_result {
15133         cmdline_fixed_string_t ptype;
15134         cmdline_fixed_string_t mapping;
15135         cmdline_fixed_string_t replace;
15136         portid_t port_id;
15137         uint32_t target;
15138         uint8_t mask;
15139         uint32_t pkt_type;
15140 };
15141
15142 /* Common CLI fields for ptype mapping replace */
15143 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_ptype_mapping_replace_result,
15146                  ptype, "ptype");
15147 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15148         TOKEN_STRING_INITIALIZER
15149                 (struct cmd_ptype_mapping_replace_result,
15150                  mapping, "mapping");
15151 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15152         TOKEN_STRING_INITIALIZER
15153                 (struct cmd_ptype_mapping_replace_result,
15154                  replace, "replace");
15155 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15156         TOKEN_NUM_INITIALIZER
15157                 (struct cmd_ptype_mapping_replace_result,
15158                  port_id, UINT16);
15159 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15160         TOKEN_NUM_INITIALIZER
15161                 (struct cmd_ptype_mapping_replace_result,
15162                  target, UINT32);
15163 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15164         TOKEN_NUM_INITIALIZER
15165                 (struct cmd_ptype_mapping_replace_result,
15166                  mask, UINT8);
15167 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15168         TOKEN_NUM_INITIALIZER
15169                 (struct cmd_ptype_mapping_replace_result,
15170                  pkt_type, UINT32);
15171
15172 static void
15173 cmd_ptype_mapping_replace_parsed(
15174         void *parsed_result,
15175         __attribute__((unused)) struct cmdline *cl,
15176         __attribute__((unused)) void *data)
15177 {
15178         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15179         int ret = -ENOTSUP;
15180
15181         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15182                 return;
15183
15184 #ifdef RTE_LIBRTE_I40E_PMD
15185         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15186                                         res->target,
15187                                         res->mask,
15188                                         res->pkt_type);
15189 #endif
15190
15191         switch (ret) {
15192         case 0:
15193                 break;
15194         case -EINVAL:
15195                 printf("invalid ptype 0x%8x or 0x%8x\n",
15196                                 res->target, res->pkt_type);
15197                 break;
15198         case -ENODEV:
15199                 printf("invalid port_id %d\n", res->port_id);
15200                 break;
15201         case -ENOTSUP:
15202                 printf("function not implemented\n");
15203                 break;
15204         default:
15205                 printf("programming error: (%s)\n", strerror(-ret));
15206         }
15207 }
15208
15209 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15210         .f = cmd_ptype_mapping_replace_parsed,
15211         .data = NULL,
15212         .help_str =
15213                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15214         .tokens = {
15215                 (void *)&cmd_ptype_mapping_replace_ptype,
15216                 (void *)&cmd_ptype_mapping_replace_mapping,
15217                 (void *)&cmd_ptype_mapping_replace_replace,
15218                 (void *)&cmd_ptype_mapping_replace_port_id,
15219                 (void *)&cmd_ptype_mapping_replace_target,
15220                 (void *)&cmd_ptype_mapping_replace_mask,
15221                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15222                 NULL,
15223         },
15224 };
15225
15226 /* ptype mapping reset */
15227
15228 /* Common result structure for ptype mapping reset */
15229 struct cmd_ptype_mapping_reset_result {
15230         cmdline_fixed_string_t ptype;
15231         cmdline_fixed_string_t mapping;
15232         cmdline_fixed_string_t reset;
15233         portid_t port_id;
15234 };
15235
15236 /* Common CLI fields for ptype mapping reset*/
15237 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15238         TOKEN_STRING_INITIALIZER
15239                 (struct cmd_ptype_mapping_reset_result,
15240                  ptype, "ptype");
15241 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15242         TOKEN_STRING_INITIALIZER
15243                 (struct cmd_ptype_mapping_reset_result,
15244                  mapping, "mapping");
15245 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15246         TOKEN_STRING_INITIALIZER
15247                 (struct cmd_ptype_mapping_reset_result,
15248                  reset, "reset");
15249 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15250         TOKEN_NUM_INITIALIZER
15251                 (struct cmd_ptype_mapping_reset_result,
15252                  port_id, UINT16);
15253
15254 static void
15255 cmd_ptype_mapping_reset_parsed(
15256         void *parsed_result,
15257         __attribute__((unused)) struct cmdline *cl,
15258         __attribute__((unused)) void *data)
15259 {
15260         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15261         int ret = -ENOTSUP;
15262
15263         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15264                 return;
15265
15266 #ifdef RTE_LIBRTE_I40E_PMD
15267         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15268 #endif
15269
15270         switch (ret) {
15271         case 0:
15272                 break;
15273         case -ENODEV:
15274                 printf("invalid port_id %d\n", res->port_id);
15275                 break;
15276         case -ENOTSUP:
15277                 printf("function not implemented\n");
15278                 break;
15279         default:
15280                 printf("programming error: (%s)\n", strerror(-ret));
15281         }
15282 }
15283
15284 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15285         .f = cmd_ptype_mapping_reset_parsed,
15286         .data = NULL,
15287         .help_str = "ptype mapping reset <port_id>",
15288         .tokens = {
15289                 (void *)&cmd_ptype_mapping_reset_ptype,
15290                 (void *)&cmd_ptype_mapping_reset_mapping,
15291                 (void *)&cmd_ptype_mapping_reset_reset,
15292                 (void *)&cmd_ptype_mapping_reset_port_id,
15293                 NULL,
15294         },
15295 };
15296
15297 /* ptype mapping update */
15298
15299 /* Common result structure for ptype mapping update */
15300 struct cmd_ptype_mapping_update_result {
15301         cmdline_fixed_string_t ptype;
15302         cmdline_fixed_string_t mapping;
15303         cmdline_fixed_string_t reset;
15304         portid_t port_id;
15305         uint8_t hw_ptype;
15306         uint32_t sw_ptype;
15307 };
15308
15309 /* Common CLI fields for ptype mapping update*/
15310 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15311         TOKEN_STRING_INITIALIZER
15312                 (struct cmd_ptype_mapping_update_result,
15313                  ptype, "ptype");
15314 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15315         TOKEN_STRING_INITIALIZER
15316                 (struct cmd_ptype_mapping_update_result,
15317                  mapping, "mapping");
15318 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15319         TOKEN_STRING_INITIALIZER
15320                 (struct cmd_ptype_mapping_update_result,
15321                  reset, "update");
15322 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15323         TOKEN_NUM_INITIALIZER
15324                 (struct cmd_ptype_mapping_update_result,
15325                  port_id, UINT16);
15326 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15327         TOKEN_NUM_INITIALIZER
15328                 (struct cmd_ptype_mapping_update_result,
15329                  hw_ptype, UINT8);
15330 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15331         TOKEN_NUM_INITIALIZER
15332                 (struct cmd_ptype_mapping_update_result,
15333                  sw_ptype, UINT32);
15334
15335 static void
15336 cmd_ptype_mapping_update_parsed(
15337         void *parsed_result,
15338         __attribute__((unused)) struct cmdline *cl,
15339         __attribute__((unused)) void *data)
15340 {
15341         struct cmd_ptype_mapping_update_result *res = parsed_result;
15342         int ret = -ENOTSUP;
15343 #ifdef RTE_LIBRTE_I40E_PMD
15344         struct rte_pmd_i40e_ptype_mapping mapping;
15345 #endif
15346         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15347                 return;
15348
15349 #ifdef RTE_LIBRTE_I40E_PMD
15350         mapping.hw_ptype = res->hw_ptype;
15351         mapping.sw_ptype = res->sw_ptype;
15352         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15353                                                 &mapping,
15354                                                 1,
15355                                                 0);
15356 #endif
15357
15358         switch (ret) {
15359         case 0:
15360                 break;
15361         case -EINVAL:
15362                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15363                 break;
15364         case -ENODEV:
15365                 printf("invalid port_id %d\n", res->port_id);
15366                 break;
15367         case -ENOTSUP:
15368                 printf("function not implemented\n");
15369                 break;
15370         default:
15371                 printf("programming error: (%s)\n", strerror(-ret));
15372         }
15373 }
15374
15375 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15376         .f = cmd_ptype_mapping_update_parsed,
15377         .data = NULL,
15378         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15379         .tokens = {
15380                 (void *)&cmd_ptype_mapping_update_ptype,
15381                 (void *)&cmd_ptype_mapping_update_mapping,
15382                 (void *)&cmd_ptype_mapping_update_update,
15383                 (void *)&cmd_ptype_mapping_update_port_id,
15384                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15385                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15386                 NULL,
15387         },
15388 };
15389
15390 /* Common result structure for file commands */
15391 struct cmd_cmdfile_result {
15392         cmdline_fixed_string_t load;
15393         cmdline_fixed_string_t filename;
15394 };
15395
15396 /* Common CLI fields for file commands */
15397 cmdline_parse_token_string_t cmd_load_cmdfile =
15398         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15399 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15400         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15401
15402 static void
15403 cmd_load_from_file_parsed(
15404         void *parsed_result,
15405         __attribute__((unused)) struct cmdline *cl,
15406         __attribute__((unused)) void *data)
15407 {
15408         struct cmd_cmdfile_result *res = parsed_result;
15409
15410         cmdline_read_from_file(res->filename);
15411 }
15412
15413 cmdline_parse_inst_t cmd_load_from_file = {
15414         .f = cmd_load_from_file_parsed,
15415         .data = NULL,
15416         .help_str = "load <filename>",
15417         .tokens = {
15418                 (void *)&cmd_load_cmdfile,
15419                 (void *)&cmd_load_cmdfile_filename,
15420                 NULL,
15421         },
15422 };
15423
15424 /* ******************************************************************************** */
15425
15426 /* list of instructions */
15427 cmdline_parse_ctx_t main_ctx[] = {
15428         (cmdline_parse_inst_t *)&cmd_help_brief,
15429         (cmdline_parse_inst_t *)&cmd_help_long,
15430         (cmdline_parse_inst_t *)&cmd_quit,
15431         (cmdline_parse_inst_t *)&cmd_load_from_file,
15432         (cmdline_parse_inst_t *)&cmd_showport,
15433         (cmdline_parse_inst_t *)&cmd_showqueue,
15434         (cmdline_parse_inst_t *)&cmd_showportall,
15435         (cmdline_parse_inst_t *)&cmd_showcfg,
15436         (cmdline_parse_inst_t *)&cmd_start,
15437         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15438         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15439         (cmdline_parse_inst_t *)&cmd_set_link_up,
15440         (cmdline_parse_inst_t *)&cmd_set_link_down,
15441         (cmdline_parse_inst_t *)&cmd_reset,
15442         (cmdline_parse_inst_t *)&cmd_set_numbers,
15443         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15444         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15445         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15446         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15447         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15448         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15449         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15450         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15451         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15452         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15453         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15454         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15455         (cmdline_parse_inst_t *)&cmd_set_link_check,
15456         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15457         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15458         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15459         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15460 #ifdef RTE_LIBRTE_PMD_BOND
15461         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15462         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15463         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15464         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15465         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15466         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15467         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15468         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15469         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15470         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15471         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15472 #endif
15473         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15474         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15475         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15476         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15477         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15478         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15479         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15480         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15481         (cmdline_parse_inst_t *)&cmd_csum_set,
15482         (cmdline_parse_inst_t *)&cmd_csum_show,
15483         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15484         (cmdline_parse_inst_t *)&cmd_tso_set,
15485         (cmdline_parse_inst_t *)&cmd_tso_show,
15486         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15487         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15488         (cmdline_parse_inst_t *)&cmd_gro_enable,
15489         (cmdline_parse_inst_t *)&cmd_gro_flush,
15490         (cmdline_parse_inst_t *)&cmd_gro_show,
15491         (cmdline_parse_inst_t *)&cmd_gso_enable,
15492         (cmdline_parse_inst_t *)&cmd_gso_size,
15493         (cmdline_parse_inst_t *)&cmd_gso_show,
15494         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15495         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15496         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15497         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15498         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15499         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15500         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15501         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15502         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15503         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15504         (cmdline_parse_inst_t *)&cmd_config_dcb,
15505         (cmdline_parse_inst_t *)&cmd_read_reg,
15506         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15507         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15508         (cmdline_parse_inst_t *)&cmd_write_reg,
15509         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15510         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15511         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15512         (cmdline_parse_inst_t *)&cmd_stop,
15513         (cmdline_parse_inst_t *)&cmd_mac_addr,
15514         (cmdline_parse_inst_t *)&cmd_set_qmap,
15515         (cmdline_parse_inst_t *)&cmd_operate_port,
15516         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15517         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15518         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15519         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15520         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15521         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15522         (cmdline_parse_inst_t *)&cmd_config_mtu,
15523         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15524         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15525         (cmdline_parse_inst_t *)&cmd_config_rss,
15526         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15527         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15528         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15529         (cmdline_parse_inst_t *)&cmd_showport_reta,
15530         (cmdline_parse_inst_t *)&cmd_config_burst,
15531         (cmdline_parse_inst_t *)&cmd_config_thresh,
15532         (cmdline_parse_inst_t *)&cmd_config_threshold,
15533         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15534         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15535         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15536         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15537         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15538         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15539         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15540         (cmdline_parse_inst_t *)&cmd_global_config,
15541         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15542         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15543         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15544         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15545         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15546         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15547         (cmdline_parse_inst_t *)&cmd_dump,
15548         (cmdline_parse_inst_t *)&cmd_dump_one,
15549         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15550         (cmdline_parse_inst_t *)&cmd_syn_filter,
15551         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15552         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15553         (cmdline_parse_inst_t *)&cmd_flex_filter,
15554         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15555         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15556         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15557         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15558         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15559         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15560         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15561         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15562         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15563         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15564         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15565         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15566         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15567         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15568         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15569         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15570         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15571         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15572         (cmdline_parse_inst_t *)&cmd_flow,
15573         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15574         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15575         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15576         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15577         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15578         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15579         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15580         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15581         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15582         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15583         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15584         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15585         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15586         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15587         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15588         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15589         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15590         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15591         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15592         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15593         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15594         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15595         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15596         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15597         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15598         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15599         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15600         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15601         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15602         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15603         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15604         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15605         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15606         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15607         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15608         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15609         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15610         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15611         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15612         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15613         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15614         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15615         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15616         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15617         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15618 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15619         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15620 #endif
15621         (cmdline_parse_inst_t *)&cmd_ddp_add,
15622         (cmdline_parse_inst_t *)&cmd_ddp_del,
15623         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15624         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15625         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15626         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15627         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15628         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15629         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15630         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15631
15632         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15633         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15634         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15635         (cmdline_parse_inst_t *)&cmd_queue_region,
15636         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15637         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15638         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15639         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15640         NULL,
15641 };
15642
15643 /* read cmdline commands from file */
15644 void
15645 cmdline_read_from_file(const char *filename)
15646 {
15647         struct cmdline *cl;
15648
15649         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15650         if (cl == NULL) {
15651                 printf("Failed to create file based cmdline context: %s\n",
15652                        filename);
15653                 return;
15654         }
15655
15656         cmdline_interact(cl);
15657         cmdline_quit(cl);
15658
15659         cmdline_free(cl);
15660
15661         printf("Read CLI commands from %s\n", filename);
15662 }
15663
15664 /* prompt function, called from main on MASTER lcore */
15665 void
15666 prompt(void)
15667 {
15668         /* initialize non-constant commands */
15669         cmd_set_fwd_mode_init();
15670         cmd_set_fwd_retry_mode_init();
15671
15672         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15673         if (testpmd_cl == NULL)
15674                 return;
15675         cmdline_interact(testpmd_cl);
15676         cmdline_stdin_exit(testpmd_cl);
15677 }
15678
15679 void
15680 prompt_exit(void)
15681 {
15682         if (testpmd_cl != NULL)
15683                 cmdline_quit(testpmd_cl);
15684 }
15685
15686 static void
15687 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15688 {
15689         if (id == (portid_t)RTE_PORT_ALL) {
15690                 portid_t pid;
15691
15692                 RTE_ETH_FOREACH_DEV(pid) {
15693                         /* check if need_reconfig has been set to 1 */
15694                         if (ports[pid].need_reconfig == 0)
15695                                 ports[pid].need_reconfig = dev;
15696                         /* check if need_reconfig_queues has been set to 1 */
15697                         if (ports[pid].need_reconfig_queues == 0)
15698                                 ports[pid].need_reconfig_queues = queue;
15699                 }
15700         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15701                 /* check if need_reconfig has been set to 1 */
15702                 if (ports[id].need_reconfig == 0)
15703                         ports[id].need_reconfig = dev;
15704                 /* check if need_reconfig_queues has been set to 1 */
15705                 if (ports[id].need_reconfig_queues == 0)
15706                         ports[id].need_reconfig_queues = queue;
15707         }
15708 }