122f7051f257327d327131b64067c3eb7851a561
[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_DPAA_PMD
93 #include <rte_pmd_dpaa.h>
94 #endif
95 #ifdef RTE_LIBRTE_IXGBE_PMD
96 #include <rte_pmd_ixgbe.h>
97 #endif
98 #ifdef RTE_LIBRTE_I40E_PMD
99 #include <rte_pmd_i40e.h>
100 #endif
101 #ifdef RTE_LIBRTE_BNXT_PMD
102 #include <rte_pmd_bnxt.h>
103 #endif
104 #include "testpmd.h"
105 #include "cmdline_mtr.h"
106 #include "cmdline_tm.h"
107
108 static struct cmdline *testpmd_cl;
109
110 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
111
112 /* *** Help command with introduction. *** */
113 struct cmd_help_brief_result {
114         cmdline_fixed_string_t help;
115 };
116
117 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
118                                   struct cmdline *cl,
119                                   __attribute__((unused)) void *data)
120 {
121         cmdline_printf(
122                 cl,
123                 "\n"
124                 "Help is available for the following sections:\n\n"
125                 "    help control    : Start and stop forwarding.\n"
126                 "    help display    : Displaying port, stats and config "
127                 "information.\n"
128                 "    help config     : Configuration information.\n"
129                 "    help ports      : Configuring ports.\n"
130                 "    help registers  : Reading and setting port registers.\n"
131                 "    help filters    : Filters configuration help.\n"
132                 "    help all        : All of the above sections.\n\n"
133         );
134
135 }
136
137 cmdline_parse_token_string_t cmd_help_brief_help =
138         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
139
140 cmdline_parse_inst_t cmd_help_brief = {
141         .f = cmd_help_brief_parsed,
142         .data = NULL,
143         .help_str = "help: Show help",
144         .tokens = {
145                 (void *)&cmd_help_brief_help,
146                 NULL,
147         },
148 };
149
150 /* *** Help command with help sections. *** */
151 struct cmd_help_long_result {
152         cmdline_fixed_string_t help;
153         cmdline_fixed_string_t section;
154 };
155
156 static void cmd_help_long_parsed(void *parsed_result,
157                                  struct cmdline *cl,
158                                  __attribute__((unused)) void *data)
159 {
160         int show_all = 0;
161         struct cmd_help_long_result *res = parsed_result;
162
163         if (!strcmp(res->section, "all"))
164                 show_all = 1;
165
166         if (show_all || !strcmp(res->section, "control")) {
167
168                 cmdline_printf(
169                         cl,
170                         "\n"
171                         "Control forwarding:\n"
172                         "-------------------\n\n"
173
174                         "start\n"
175                         "    Start packet forwarding with current configuration.\n\n"
176
177                         "start tx_first\n"
178                         "    Start packet forwarding with current config"
179                         " after sending one burst of packets.\n\n"
180
181                         "stop\n"
182                         "    Stop packet forwarding, and display accumulated"
183                         " statistics.\n\n"
184
185                         "quit\n"
186                         "    Quit to prompt.\n\n"
187                 );
188         }
189
190         if (show_all || !strcmp(res->section, "display")) {
191
192                 cmdline_printf(
193                         cl,
194                         "\n"
195                         "Display:\n"
196                         "--------\n\n"
197
198                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
199                         "    Display information for port_id, or all.\n\n"
200
201                         "show port X rss reta (size) (mask0,mask1,...)\n"
202                         "    Display the rss redirection table entry indicated"
203                         " by masks on port X. size is used to indicate the"
204                         " hardware supported reta size\n\n"
205
206                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
207                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
208                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
209                         "    Display the RSS hash functions and RSS hash key"
210                         " of port X\n\n"
211
212                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
213                         "    Clear information for port_id, or all.\n\n"
214
215                         "show (rxq|txq) info (port_id) (queue_id)\n"
216                         "    Display information for configured RX/TX queue.\n\n"
217
218                         "show config (rxtx|cores|fwd|txpkts)\n"
219                         "    Display the given configuration.\n\n"
220
221                         "read rxd (port_id) (queue_id) (rxd_id)\n"
222                         "    Display an RX descriptor of a port RX queue.\n\n"
223
224                         "read txd (port_id) (queue_id) (txd_id)\n"
225                         "    Display a TX descriptor of a port TX queue.\n\n"
226
227                         "ddp get list (port_id)\n"
228                         "    Get ddp profile info list\n\n"
229
230                         "ddp get info (profile_path)\n"
231                         "    Get ddp profile information.\n\n"
232
233                         "show vf stats (port_id) (vf_id)\n"
234                         "    Display a VF's statistics.\n\n"
235
236                         "clear vf stats (port_id) (vf_id)\n"
237                         "    Reset a VF's statistics.\n\n"
238
239                         "show port (port_id) pctype mapping\n"
240                         "    Get flow ptype to pctype mapping on a port\n\n"
241
242                         "show port meter stats (port_id) (meter_id) (clear)\n"
243                         "    Get meter stats on a port\n\n"
244                         "show port tm cap (port_id)\n"
245                         "       Display the port TM capability.\n\n"
246
247                         "show port tm level cap (port_id) (level_id)\n"
248                         "       Display the port TM hierarchical level capability.\n\n"
249
250                         "show port tm node cap (port_id) (node_id)\n"
251                         "       Display the port TM node capability.\n\n"
252
253                         "show port tm node type (port_id) (node_id)\n"
254                         "       Display the port TM node type.\n\n"
255
256                         "show port tm node stats (port_id) (node_id) (clear)\n"
257                         "       Display the port TM node stats.\n\n"
258
259                 );
260         }
261
262         if (show_all || !strcmp(res->section, "config")) {
263                 cmdline_printf(
264                         cl,
265                         "\n"
266                         "Configuration:\n"
267                         "--------------\n"
268                         "Configuration changes only become active when"
269                         " forwarding is started/restarted.\n\n"
270
271                         "set default\n"
272                         "    Reset forwarding to the default configuration.\n\n"
273
274                         "set verbose (level)\n"
275                         "    Set the debug verbosity level X.\n\n"
276
277                         "set nbport (num)\n"
278                         "    Set number of ports.\n\n"
279
280                         "set nbcore (num)\n"
281                         "    Set number of cores.\n\n"
282
283                         "set coremask (mask)\n"
284                         "    Set the forwarding cores hexadecimal mask.\n\n"
285
286                         "set portmask (mask)\n"
287                         "    Set the forwarding ports hexadecimal mask.\n\n"
288
289                         "set burst (num)\n"
290                         "    Set number of packets per burst.\n\n"
291
292                         "set burst tx delay (microseconds) retry (num)\n"
293                         "    Set the transmit delay time and number of retries,"
294                         " effective when retry is enabled.\n\n"
295
296                         "set txpkts (x[,y]*)\n"
297                         "    Set the length of each segment of TXONLY"
298                         " and optionally CSUM packets.\n\n"
299
300                         "set txsplit (off|on|rand)\n"
301                         "    Set the split policy for the TX packets."
302                         " Right now only applicable for CSUM and TXONLY"
303                         " modes\n\n"
304
305                         "set corelist (x[,y]*)\n"
306                         "    Set the list of forwarding cores.\n\n"
307
308                         "set portlist (x[,y]*)\n"
309                         "    Set the list of forwarding ports.\n\n"
310
311                         "set tx loopback (port_id) (on|off)\n"
312                         "    Enable or disable tx loopback.\n\n"
313
314                         "set all queues drop (port_id) (on|off)\n"
315                         "    Set drop enable bit for all queues.\n\n"
316
317                         "set vf split drop (port_id) (vf_id) (on|off)\n"
318                         "    Set split drop enable bit for a VF from the PF.\n\n"
319
320                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
321                         "    Set MAC antispoof for a VF from the PF.\n\n"
322
323                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
324                         "    Enable MACsec offload.\n\n"
325
326                         "set macsec offload (port_id) off\n"
327                         "    Disable MACsec offload.\n\n"
328
329                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
330                         "    Configure MACsec secure connection (SC).\n\n"
331
332                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
333                         "    Configure MACsec secure association (SA).\n\n"
334
335                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
336                         "    Set VF broadcast for a VF from the PF.\n\n"
337
338                         "vlan set strip (on|off) (port_id)\n"
339                         "    Set the VLAN strip on a port.\n\n"
340
341                         "vlan set stripq (on|off) (port_id,queue_id)\n"
342                         "    Set the VLAN strip for a queue on a port.\n\n"
343
344                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
345                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
346
347                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
348                         "    Set VLAN insert for a VF from the PF.\n\n"
349
350                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN antispoof for a VF from the PF.\n\n"
352
353                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
354                         "    Set VLAN tag for a VF from the PF.\n\n"
355
356                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
357                         "    Set a VF's max bandwidth(Mbps).\n\n"
358
359                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
360                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
361
362                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
363                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
364
365                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
366                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
367
368                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
369                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
370
371                         "vlan set filter (on|off) (port_id)\n"
372                         "    Set the VLAN filter on a port.\n\n"
373
374                         "vlan set qinq (on|off) (port_id)\n"
375                         "    Set the VLAN QinQ (extended queue in queue)"
376                         " on a port.\n\n"
377
378                         "vlan set (inner|outer) tpid (value) (port_id)\n"
379                         "    Set the VLAN TPID for Packet Filtering on"
380                         " a port\n\n"
381
382                         "rx_vlan add (vlan_id|all) (port_id)\n"
383                         "    Add a vlan_id, or all identifiers, to the set"
384                         " of VLAN identifiers filtered by port_id.\n\n"
385
386                         "rx_vlan rm (vlan_id|all) (port_id)\n"
387                         "    Remove a vlan_id, or all identifiers, from the set"
388                         " of VLAN identifiers filtered by port_id.\n\n"
389
390                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
391                         "    Add a vlan_id, to the set of VLAN identifiers"
392                         "filtered for VF(s) from port_id.\n\n"
393
394                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
395                         "    Remove a vlan_id, to the set of VLAN identifiers"
396                         "filtered for VF(s) from port_id.\n\n"
397
398                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
399                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
400                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
401                         "   add a tunnel filter of a port.\n\n"
402
403                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
404                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
405                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
406                         "   remove a tunnel filter of a port.\n\n"
407
408                         "rx_vxlan_port add (udp_port) (port_id)\n"
409                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "rx_vxlan_port rm (udp_port) (port_id)\n"
412                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
415                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
416                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
417
418                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
419                         "    Set port based TX VLAN insertion.\n\n"
420
421                         "tx_vlan reset (port_id)\n"
422                         "    Disable hardware insertion of a VLAN header in"
423                         " packets sent on a port.\n\n"
424
425                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
426                         "    Select hardware or software calculation of the"
427                         " checksum when transmitting a packet using the"
428                         " csum forward engine.\n"
429                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
430                         "    outer-ip concerns the outer IP layer in"
431                         " case the packet is recognized as a tunnel packet by"
432                         " the forward engine (vxlan, gre and ipip are supported)\n"
433                         "    Please check the NIC datasheet for HW limits.\n\n"
434
435                         "csum parse-tunnel (on|off) (tx_port_id)\n"
436                         "    If disabled, treat tunnel packets as non-tunneled"
437                         " packets (treat inner headers as payload). The port\n"
438                         "    argument is the port used for TX in csum forward"
439                         " engine.\n\n"
440
441                         "csum show (port_id)\n"
442                         "    Display tx checksum offload configuration\n\n"
443
444                         "tso set (segsize) (portid)\n"
445                         "    Enable TCP Segmentation Offload in csum forward"
446                         " engine.\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "tso show (portid)"
450                         "    Display the status of TCP Segmentation Offload.\n\n"
451
452                         "set port (port_id) gro on|off\n"
453                         "    Enable or disable Generic Receive Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "show port (port_id) gro\n"
457                         "    Display GRO configuration.\n\n"
458
459                         "set gro flush (cycles)\n"
460                         "    Set the cycle to flush GROed packets from"
461                         " reassembly tables.\n\n"
462
463                         "set port (port_id) gso (on|off)"
464                         "    Enable or disable Generic Segmentation Offload in"
465                         " csum forwarding engine.\n\n"
466
467                         "set gso segsz (length)\n"
468                         "    Set max packet length for output GSO segments,"
469                         " including packet header and payload.\n\n"
470
471                         "show port (port_id) gso\n"
472                         "    Show GSO configuration.\n\n"
473
474                         "set fwd (%s)\n"
475                         "    Set packet forwarding mode.\n\n"
476
477                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Add a MAC address on port_id.\n\n"
479
480                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Remove a MAC address from port_id.\n\n"
482
483                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
484                         "    Set the default MAC address for port_id.\n\n"
485
486                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
487                         "    Add a MAC address for a VF on the port.\n\n"
488
489                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
490                         "    Set the MAC address for a VF from the PF.\n\n"
491
492                         "set eth-peer (port_id) (peer_addr)\n"
493                         "    set the peer address for certain port.\n\n"
494
495                         "set port (port_id) uta (mac_address|all) (on|off)\n"
496                         "    Add/Remove a or all unicast hash filter(s)"
497                         "from port X.\n\n"
498
499                         "set promisc (port_id|all) (on|off)\n"
500                         "    Set the promiscuous mode on port_id, or all.\n\n"
501
502                         "set allmulti (port_id|all) (on|off)\n"
503                         "    Set the allmulti mode on port_id, or all.\n\n"
504
505                         "set vf promisc (port_id) (vf_id) (on|off)\n"
506                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
507
508                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
509                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
510
511                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
513                         " (on|off) autoneg (on|off) (port_id)\n"
514                         "set flow_ctrl rx (on|off) (portid)\n"
515                         "set flow_ctrl tx (on|off) (portid)\n"
516                         "set flow_ctrl high_water (high_water) (portid)\n"
517                         "set flow_ctrl low_water (low_water) (portid)\n"
518                         "set flow_ctrl pause_time (pause_time) (portid)\n"
519                         "set flow_ctrl send_xon (send_xon) (portid)\n"
520                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
521                         "set flow_ctrl autoneg (on|off) (port_id)\n"
522                         "    Set the link flow control parameter on a port.\n\n"
523
524                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
525                         " (low_water) (pause_time) (priority) (port_id)\n"
526                         "    Set the priority flow control parameter on a"
527                         " port.\n\n"
528
529                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
530                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
531                         " queue on port.\n"
532                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
533                         " on port 0 to mapping 5.\n\n"
534
535                         "set xstats-hide-zero on|off\n"
536                         "    Set the option to hide the zero values"
537                         " for xstats display.\n"
538
539                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
540                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
541
542                         "set port (port_id) vf (vf_id) (mac_addr)"
543                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
544                         "   Add/Remove unicast or multicast MAC addr filter"
545                         " for a VF.\n\n"
546
547                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
548                         "|MPE) (on|off)\n"
549                         "    AUPE:accepts untagged VLAN;"
550                         "ROPE:accept unicast hash\n\n"
551                         "    BAM:accepts broadcast packets;"
552                         "MPE:accepts all multicast packets\n\n"
553                         "    Enable/Disable a VF receive mode of a port\n\n"
554
555                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
556                         "    Set rate limit for a queue of a port\n\n"
557
558                         "set port (port_id) vf (vf_id) rate (rate_num) "
559                         "queue_mask (queue_mask_value)\n"
560                         "    Set rate limit for queues in VF of a port\n\n"
561
562                         "set port (port_id) mirror-rule (rule_id)"
563                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
564                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
565                         "   Set pool or vlan type mirror rule on a port.\n"
566                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
567                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
568                         " to pool 0.\n\n"
569
570                         "set port (port_id) mirror-rule (rule_id)"
571                         " (uplink-mirror|downlink-mirror) dst-pool"
572                         " (pool_id) (on|off)\n"
573                         "   Set uplink or downlink type mirror rule on a port.\n"
574                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
575                         " 0 on' enable mirror income traffic to pool 0.\n\n"
576
577                         "reset port (port_id) mirror-rule (rule_id)\n"
578                         "   Reset a mirror rule.\n\n"
579
580                         "set flush_rx (on|off)\n"
581                         "   Flush (default) or don't flush RX streams before"
582                         " forwarding. Mainly used with PCAP drivers.\n\n"
583
584                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
585                         "   Set the bypass mode for the lowest port on bypass enabled"
586                         " NIC.\n\n"
587
588                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
589                         "mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the event required to initiate specified bypass mode for"
591                         " the lowest port on a bypass enabled NIC where:\n"
592                         "       timeout   = enable bypass after watchdog timeout.\n"
593                         "       os_on     = enable bypass when OS/board is powered on.\n"
594                         "       os_off    = enable bypass when OS/board is powered off.\n"
595                         "       power_on  = enable bypass when power supply is turned on.\n"
596                         "       power_off = enable bypass when power supply is turned off."
597                         "\n\n"
598
599                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
600                         "   Set the bypass watchdog timeout to 'n' seconds"
601                         " where 0 = instant.\n\n"
602
603                         "show bypass config (port_id)\n"
604                         "   Show the bypass configuration for a bypass enabled NIC"
605                         " using the lowest port on the NIC.\n\n"
606
607 #ifdef RTE_LIBRTE_PMD_BOND
608                         "create bonded device (mode) (socket)\n"
609                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
610
611                         "add bonding slave (slave_id) (port_id)\n"
612                         "       Add a slave device to a bonded device.\n\n"
613
614                         "remove bonding slave (slave_id) (port_id)\n"
615                         "       Remove a slave device from a bonded device.\n\n"
616
617                         "set bonding mode (value) (port_id)\n"
618                         "       Set the bonding mode on a bonded device.\n\n"
619
620                         "set bonding primary (slave_id) (port_id)\n"
621                         "       Set the primary slave for a bonded device.\n\n"
622
623                         "show bonding config (port_id)\n"
624                         "       Show the bonding config for port_id.\n\n"
625
626                         "set bonding mac_addr (port_id) (address)\n"
627                         "       Set the MAC address of a bonded device.\n\n"
628
629                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
630                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
631
632                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
633                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
634
635                         "set bonding mon_period (port_id) (value)\n"
636                         "       Set the bonding link status monitoring polling period in ms.\n\n"
637
638                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
639                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
640
641 #endif
642                         "set link-up port (port_id)\n"
643                         "       Set link up for a port.\n\n"
644
645                         "set link-down port (port_id)\n"
646                         "       Set link down for a port.\n\n"
647
648                         "E-tag set insertion on port-tag-id (value)"
649                         " port (port_id) vf (vf_id)\n"
650                         "    Enable E-tag insertion for a VF on a port\n\n"
651
652                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
653                         "    Disable E-tag insertion for a VF on a port\n\n"
654
655                         "E-tag set stripping (on|off) port (port_id)\n"
656                         "    Enable/disable E-tag stripping on a port\n\n"
657
658                         "E-tag set forwarding (on|off) port (port_id)\n"
659                         "    Enable/disable E-tag based forwarding"
660                         " on a port\n\n"
661
662                         "E-tag set filter add e-tag-id (value) dst-pool"
663                         " (pool_id) port (port_id)\n"
664                         "    Add an E-tag forwarding filter on a port\n\n"
665
666                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
667                         "    Delete an E-tag forwarding filter on a port\n\n"
668
669 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
670                         "set port tm hierarchy default (port_id)\n"
671                         "       Set default traffic Management hierarchy on a port\n\n"
672
673 #endif
674                         "ddp add (port_id) (profile_path[,output_path])\n"
675                         "    Load a profile package on a port\n\n"
676
677                         "ddp del (port_id) (profile_path)\n"
678                         "    Delete a profile package from a port\n\n"
679
680                         "ptype mapping get (port_id) (valid_only)\n"
681                         "    Get ptype mapping on a port\n\n"
682
683                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
684                         "    Replace target with the pkt_type in ptype mapping\n\n"
685
686                         "ptype mapping reset (port_id)\n"
687                         "    Reset ptype mapping on a port\n\n"
688
689                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
690                         "    Update a ptype mapping item on a port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "queue_start_index (value) queue_num (value)\n"
694                         "    Set a queue region on a port\n\n"
695
696                         "set port (port_id) queue-region region_id (value) "
697                         "flowtype (value)\n"
698                         "    Set a flowtype region index on a port\n\n"
699
700                         "set port (port_id) queue-region UP (value) region_id (value)\n"
701                         "    Set the mapping of User Priority to "
702                         "queue region on a port\n\n"
703
704                         "set port (port_id) queue-region flush (on|off)\n"
705                         "    flush all queue region related configuration\n\n"
706
707                         "show port meter cap (port_id)\n"
708                         "    Show port meter capability information\n\n"
709
710                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
711                         "    meter profile add - srtcm rfc 2697\n\n"
712
713                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
714                         "    meter profile add - trtcm rfc 2698\n\n"
715
716                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
717                         "    meter profile add - trtcm rfc 4115\n\n"
718
719                         "del port meter profile (port_id) (profile_id)\n"
720                         "    meter profile delete\n\n"
721
722                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
723                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
724                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
725                         "(dscp_tbl_entry63)]\n"
726                         "    meter create\n\n"
727
728                         "enable port meter (port_id) (mtr_id)\n"
729                         "    meter enable\n\n"
730
731                         "disable port meter (port_id) (mtr_id)\n"
732                         "    meter disable\n\n"
733
734                         "del port meter (port_id) (mtr_id)\n"
735                         "    meter delete\n\n"
736
737                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
738                         "    meter update meter profile\n\n"
739
740                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
741                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
742                         "    update meter dscp table entries\n\n"
743
744                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
745                         "(action0) [(action1) (action2)]\n"
746                         "    meter update policer action\n\n"
747
748                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
749                         "    meter update stats\n\n"
750
751                         "show port (port_id) queue-region\n"
752                         "    show all queue region related configuration info\n\n"
753
754                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
755                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
756                         "       Add port tm node private shaper profile.\n\n"
757
758                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
759                         "       Delete port tm node private shaper profile.\n\n"
760
761                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
762                         " (shaper_profile_id)\n"
763                         "       Add/update port tm node shared shaper.\n\n"
764
765                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
766                         "       Delete port tm node shared shaper.\n\n"
767
768                         "set port tm node shaper profile (port_id) (node_id)"
769                         " (shaper_profile_id)\n"
770                         "       Set port tm node shaper profile.\n\n"
771
772                         "add port tm node wred profile (port_id) (wred_profile_id)"
773                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
774                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
775                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
776                         "       Add port tm node wred profile.\n\n"
777
778                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
779                         "       Delete port tm node wred profile.\n\n"
780
781                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm nonleaf node.\n\n"
786
787                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
788                         " (priority) (weight) (level_id) (shaper_profile_id)"
789                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
790                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
791                         "       Add port tm leaf node.\n\n"
792
793                         "del port tm node (port_id) (node_id)\n"
794                         "       Delete port tm node.\n\n"
795
796                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
797                         " (priority) (weight)\n"
798                         "       Set port tm node parent.\n\n"
799
800                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
801                         "       Commit tm hierarchy.\n\n"
802
803                         , list_pkt_forwarding_modes()
804                 );
805         }
806
807         if (show_all || !strcmp(res->section, "ports")) {
808
809                 cmdline_printf(
810                         cl,
811                         "\n"
812                         "Port Operations:\n"
813                         "----------------\n\n"
814
815                         "port start (port_id|all)\n"
816                         "    Start all ports or port_id.\n\n"
817
818                         "port stop (port_id|all)\n"
819                         "    Stop all ports or port_id.\n\n"
820
821                         "port close (port_id|all)\n"
822                         "    Close all ports or port_id.\n\n"
823
824                         "port attach (ident)\n"
825                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
826
827                         "port detach (port_id)\n"
828                         "    Detach physical or virtual dev by port_id\n\n"
829
830                         "port config (port_id|all)"
831                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
832                         " duplex (half|full|auto)\n"
833                         "    Set speed and duplex for all ports or port_id\n\n"
834
835                         "port config all (rxq|txq|rxd|txd) (value)\n"
836                         "    Set number for rxq/txq/rxd/txd.\n\n"
837
838                         "port config all max-pkt-len (value)\n"
839                         "    Set the max packet length.\n\n"
840
841                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
842                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
843                         " (on|off)\n"
844                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
845                         " for ports.\n\n"
846
847                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
848                         "geneve|nvgre|none|<flowtype_id>)\n"
849                         "    Set the RSS mode.\n\n"
850
851                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
852                         "    Set the RSS redirection table.\n\n"
853
854                         "port config (port_id) dcb vt (on|off) (traffic_class)"
855                         " pfc (on|off)\n"
856                         "    Set the DCB mode.\n\n"
857
858                         "port config all burst (value)\n"
859                         "    Set the number of packets per burst.\n\n"
860
861                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
862                         " (value)\n"
863                         "    Set the ring prefetch/host/writeback threshold"
864                         " for tx/rx queue.\n\n"
865
866                         "port config all (txfreet|txrst|rxfreet) (value)\n"
867                         "    Set free threshold for rx/tx, or set"
868                         " tx rs bit threshold.\n\n"
869                         "port config mtu X value\n"
870                         "    Set the MTU of port X to a given value\n\n"
871
872                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
873                         "    Start/stop a rx/tx queue of port X. Only take effect"
874                         " when port X is started\n\n"
875
876                         "port config (port_id|all) l2-tunnel E-tag ether-type"
877                         " (value)\n"
878                         "    Set the value of E-tag ether-type.\n\n"
879
880                         "port config (port_id|all) l2-tunnel E-tag"
881                         " (enable|disable)\n"
882                         "    Enable/disable the E-tag support.\n\n"
883
884                         "port config (port_id) pctype mapping reset\n"
885                         "    Reset flow type to pctype mapping on a port\n\n"
886
887                         "port config (port_id) pctype mapping update"
888                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
889                         "    Update a flow type to pctype mapping item on a port\n\n"
890
891                         "port config (port_id) pctype (pctype_id) hash_inset|"
892                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
893                         " (field_idx)\n"
894                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
895
896                         "port config (port_id) pctype (pctype_id) hash_inset|"
897                         "fdir_inset|fdir_flx_inset clear all"
898                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
899                 );
900         }
901
902         if (show_all || !strcmp(res->section, "registers")) {
903
904                 cmdline_printf(
905                         cl,
906                         "\n"
907                         "Registers:\n"
908                         "----------\n\n"
909
910                         "read reg (port_id) (address)\n"
911                         "    Display value of a port register.\n\n"
912
913                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
914                         "    Display a port register bit field.\n\n"
915
916                         "read regbit (port_id) (address) (bit_x)\n"
917                         "    Display a single port register bit.\n\n"
918
919                         "write reg (port_id) (address) (value)\n"
920                         "    Set value of a port register.\n\n"
921
922                         "write regfield (port_id) (address) (bit_x) (bit_y)"
923                         " (value)\n"
924                         "    Set bit field of a port register.\n\n"
925
926                         "write regbit (port_id) (address) (bit_x) (value)\n"
927                         "    Set single bit value of a port register.\n\n"
928                 );
929         }
930         if (show_all || !strcmp(res->section, "filters")) {
931
932                 cmdline_printf(
933                         cl,
934                         "\n"
935                         "filters:\n"
936                         "--------\n\n"
937
938                         "ethertype_filter (port_id) (add|del)"
939                         " (mac_addr|mac_ignr) (mac_address) ethertype"
940                         " (ether_type) (drop|fwd) queue (queue_id)\n"
941                         "    Add/Del an ethertype filter.\n\n"
942
943                         "2tuple_filter (port_id) (add|del)"
944                         " dst_port (dst_port_value) protocol (protocol_value)"
945                         " mask (mask_value) tcp_flags (tcp_flags_value)"
946                         " priority (prio_value) queue (queue_id)\n"
947                         "    Add/Del a 2tuple filter.\n\n"
948
949                         "5tuple_filter (port_id) (add|del)"
950                         " dst_ip (dst_address) src_ip (src_address)"
951                         " dst_port (dst_port_value) src_port (src_port_value)"
952                         " protocol (protocol_value)"
953                         " mask (mask_value) tcp_flags (tcp_flags_value)"
954                         " priority (prio_value) queue (queue_id)\n"
955                         "    Add/Del a 5tuple filter.\n\n"
956
957                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
958                         "    Add/Del syn filter.\n\n"
959
960                         "flex_filter (port_id) (add|del) len (len_value)"
961                         " bytes (bytes_value) mask (mask_value)"
962                         " priority (prio_value) queue (queue_id)\n"
963                         "    Add/Del a flex filter.\n\n"
964
965                         "flow_director_filter (port_id) mode IP (add|del|update)"
966                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
967                         " src (src_ip_address) dst (dst_ip_address)"
968                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
969                         " vlan (vlan_value) flexbytes (flexbytes_value)"
970                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
971                         " fd_id (fd_id_value)\n"
972                         "    Add/Del an IP type flow director filter.\n\n"
973
974                         "flow_director_filter (port_id) mode IP (add|del|update)"
975                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
976                         " src (src_ip_address) (src_port)"
977                         " dst (dst_ip_address) (dst_port)"
978                         " tos (tos_value) ttl (ttl_value)"
979                         " vlan (vlan_value) flexbytes (flexbytes_value)"
980                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
981                         " fd_id (fd_id_value)\n"
982                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
983
984                         "flow_director_filter (port_id) mode IP (add|del|update)"
985                         " flow (ipv4-sctp|ipv6-sctp)"
986                         " src (src_ip_address) (src_port)"
987                         " dst (dst_ip_address) (dst_port)"
988                         " tag (verification_tag) "
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value)"
991                         " flexbytes (flexbytes_value) (drop|fwd)"
992                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
993                         "    Add/Del a SCTP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow l2_payload ether (ethertype)"
997                         " flexbytes (flexbytes_value) (drop|fwd)"
998                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
999                         "    Add/Del a l2 payload type flow director filter.\n\n"
1000
1001                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1002                         " mac (mac_address) vlan (vlan_value)"
1003                         " flexbytes (flexbytes_value) (drop|fwd)"
1004                         " queue (queue_id) fd_id (fd_id_value)\n"
1005                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1006
1007                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1008                         " mac (mac_address) vlan (vlan_value)"
1009                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1010                         " flexbytes (flexbytes_value) (drop|fwd)"
1011                         " queue (queue_id) fd_id (fd_id_value)\n"
1012                         "    Add/Del a Tunnel flow director filter.\n\n"
1013
1014                         "flow_director_filter (port_id) mode raw (add|del|update)"
1015                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1016                         " fd_id (fd_id_value) packet (packet file name)\n"
1017                         "    Add/Del a raw type flow director filter.\n\n"
1018
1019                         "flush_flow_director (port_id)\n"
1020                         "    Flush all flow director entries of a device.\n\n"
1021
1022                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1023                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1024                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1025                         "    Set flow director IP mask.\n\n"
1026
1027                         "flow_director_mask (port_id) mode MAC-VLAN"
1028                         " vlan (vlan_value)\n"
1029                         "    Set flow director MAC-VLAN mask.\n\n"
1030
1031                         "flow_director_mask (port_id) mode Tunnel"
1032                         " vlan (vlan_value) mac (mac_value)"
1033                         " tunnel-type (tunnel_type_value)"
1034                         " tunnel-id (tunnel_id_value)\n"
1035                         "    Set flow director Tunnel mask.\n\n"
1036
1037                         "flow_director_flex_mask (port_id)"
1038                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1039                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1040                         " (mask)\n"
1041                         "    Configure mask of flex payload.\n\n"
1042
1043                         "flow_director_flex_payload (port_id)"
1044                         " (raw|l2|l3|l4) (config)\n"
1045                         "    Configure flex payload selection.\n\n"
1046
1047                         "get_sym_hash_ena_per_port (port_id)\n"
1048                         "    get symmetric hash enable configuration per port.\n\n"
1049
1050                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1051                         "    set symmetric hash enable configuration per port"
1052                         " to enable or disable.\n\n"
1053
1054                         "get_hash_global_config (port_id)\n"
1055                         "    Get the global configurations of hash filters.\n\n"
1056
1057                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1058                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1059                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1060                         " (enable|disable)\n"
1061                         "    Set the global configurations of hash filters.\n\n"
1062
1063                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1064                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1065                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1066                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1067                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1068                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1069                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1070                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1071                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1072                         "fld-8th|none) (select|add)\n"
1073                         "    Set the input set for hash.\n\n"
1074
1075                         "set_fdir_input_set (port_id) "
1076                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1077                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1078                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1079                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1080                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1081                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1082                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1083                         " (select|add)\n"
1084                         "    Set the input set for FDir.\n\n"
1085
1086                         "flow validate {port_id}"
1087                         " [group {group_id}] [priority {level}]"
1088                         " [ingress] [egress]"
1089                         " pattern {item} [/ {item} [...]] / end"
1090                         " actions {action} [/ {action} [...]] / end\n"
1091                         "    Check whether a flow rule can be created.\n\n"
1092
1093                         "flow create {port_id}"
1094                         " [group {group_id}] [priority {level}]"
1095                         " [ingress] [egress]"
1096                         " pattern {item} [/ {item} [...]] / end"
1097                         " actions {action} [/ {action} [...]] / end\n"
1098                         "    Create a flow rule.\n\n"
1099
1100                         "flow destroy {port_id} rule {rule_id} [...]\n"
1101                         "    Destroy specific flow rules.\n\n"
1102
1103                         "flow flush {port_id}\n"
1104                         "    Destroy all flow rules.\n\n"
1105
1106                         "flow query {port_id} {rule_id} {action}\n"
1107                         "    Query an existing flow rule.\n\n"
1108
1109                         "flow list {port_id} [group {group_id}] [...]\n"
1110                         "    List existing flow rules sorted by priority,"
1111                         " filtered by group identifiers.\n\n"
1112
1113                         "flow isolate {port_id} {boolean}\n"
1114                         "    Restrict ingress traffic to the defined"
1115                         " flow rules\n\n"
1116                 );
1117         }
1118 }
1119
1120 cmdline_parse_token_string_t cmd_help_long_help =
1121         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1122
1123 cmdline_parse_token_string_t cmd_help_long_section =
1124         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1125                         "all#control#display#config#"
1126                         "ports#registers#filters");
1127
1128 cmdline_parse_inst_t cmd_help_long = {
1129         .f = cmd_help_long_parsed,
1130         .data = NULL,
1131         .help_str = "help all|control|display|config|ports|register|filters: "
1132                 "Show help",
1133         .tokens = {
1134                 (void *)&cmd_help_long_help,
1135                 (void *)&cmd_help_long_section,
1136                 NULL,
1137         },
1138 };
1139
1140
1141 /* *** start/stop/close all ports *** */
1142 struct cmd_operate_port_result {
1143         cmdline_fixed_string_t keyword;
1144         cmdline_fixed_string_t name;
1145         cmdline_fixed_string_t value;
1146 };
1147
1148 static void cmd_operate_port_parsed(void *parsed_result,
1149                                 __attribute__((unused)) struct cmdline *cl,
1150                                 __attribute__((unused)) void *data)
1151 {
1152         struct cmd_operate_port_result *res = parsed_result;
1153
1154         if (!strcmp(res->name, "start"))
1155                 start_port(RTE_PORT_ALL);
1156         else if (!strcmp(res->name, "stop"))
1157                 stop_port(RTE_PORT_ALL);
1158         else if (!strcmp(res->name, "close"))
1159                 close_port(RTE_PORT_ALL);
1160         else if (!strcmp(res->name, "reset"))
1161                 reset_port(RTE_PORT_ALL);
1162         else
1163                 printf("Unknown parameter\n");
1164 }
1165
1166 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1167         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1168                                                                 "port");
1169 cmdline_parse_token_string_t cmd_operate_port_all_port =
1170         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1171                                                 "start#stop#close#reset");
1172 cmdline_parse_token_string_t cmd_operate_port_all_all =
1173         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1174
1175 cmdline_parse_inst_t cmd_operate_port = {
1176         .f = cmd_operate_port_parsed,
1177         .data = NULL,
1178         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1179         .tokens = {
1180                 (void *)&cmd_operate_port_all_cmd,
1181                 (void *)&cmd_operate_port_all_port,
1182                 (void *)&cmd_operate_port_all_all,
1183                 NULL,
1184         },
1185 };
1186
1187 /* *** start/stop/close specific port *** */
1188 struct cmd_operate_specific_port_result {
1189         cmdline_fixed_string_t keyword;
1190         cmdline_fixed_string_t name;
1191         uint8_t value;
1192 };
1193
1194 static void cmd_operate_specific_port_parsed(void *parsed_result,
1195                         __attribute__((unused)) struct cmdline *cl,
1196                                 __attribute__((unused)) void *data)
1197 {
1198         struct cmd_operate_specific_port_result *res = parsed_result;
1199
1200         if (!strcmp(res->name, "start"))
1201                 start_port(res->value);
1202         else if (!strcmp(res->name, "stop"))
1203                 stop_port(res->value);
1204         else if (!strcmp(res->name, "close"))
1205                 close_port(res->value);
1206         else if (!strcmp(res->name, "reset"))
1207                 reset_port(res->value);
1208         else
1209                 printf("Unknown parameter\n");
1210 }
1211
1212 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1213         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1214                                                         keyword, "port");
1215 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1217                                                 name, "start#stop#close#reset");
1218 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1219         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1220                                                         value, UINT8);
1221
1222 cmdline_parse_inst_t cmd_operate_specific_port = {
1223         .f = cmd_operate_specific_port_parsed,
1224         .data = NULL,
1225         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1226         .tokens = {
1227                 (void *)&cmd_operate_specific_port_cmd,
1228                 (void *)&cmd_operate_specific_port_port,
1229                 (void *)&cmd_operate_specific_port_id,
1230                 NULL,
1231         },
1232 };
1233
1234 /* *** attach a specified port *** */
1235 struct cmd_operate_attach_port_result {
1236         cmdline_fixed_string_t port;
1237         cmdline_fixed_string_t keyword;
1238         cmdline_fixed_string_t identifier;
1239 };
1240
1241 static void cmd_operate_attach_port_parsed(void *parsed_result,
1242                                 __attribute__((unused)) struct cmdline *cl,
1243                                 __attribute__((unused)) void *data)
1244 {
1245         struct cmd_operate_attach_port_result *res = parsed_result;
1246
1247         if (!strcmp(res->keyword, "attach"))
1248                 attach_port(res->identifier);
1249         else
1250                 printf("Unknown parameter\n");
1251 }
1252
1253 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1254         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1255                         port, "port");
1256 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1257         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1258                         keyword, "attach");
1259 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1260         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1261                         identifier, NULL);
1262
1263 cmdline_parse_inst_t cmd_operate_attach_port = {
1264         .f = cmd_operate_attach_port_parsed,
1265         .data = NULL,
1266         .help_str = "port attach <identifier>: "
1267                 "(identifier: pci address or virtual dev name)",
1268         .tokens = {
1269                 (void *)&cmd_operate_attach_port_port,
1270                 (void *)&cmd_operate_attach_port_keyword,
1271                 (void *)&cmd_operate_attach_port_identifier,
1272                 NULL,
1273         },
1274 };
1275
1276 /* *** detach a specified port *** */
1277 struct cmd_operate_detach_port_result {
1278         cmdline_fixed_string_t port;
1279         cmdline_fixed_string_t keyword;
1280         portid_t port_id;
1281 };
1282
1283 static void cmd_operate_detach_port_parsed(void *parsed_result,
1284                                 __attribute__((unused)) struct cmdline *cl,
1285                                 __attribute__((unused)) void *data)
1286 {
1287         struct cmd_operate_detach_port_result *res = parsed_result;
1288
1289         if (!strcmp(res->keyword, "detach"))
1290                 detach_port(res->port_id);
1291         else
1292                 printf("Unknown parameter\n");
1293 }
1294
1295 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1296         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1297                         port, "port");
1298 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1299         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1300                         keyword, "detach");
1301 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1302         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1303                         port_id, UINT16);
1304
1305 cmdline_parse_inst_t cmd_operate_detach_port = {
1306         .f = cmd_operate_detach_port_parsed,
1307         .data = NULL,
1308         .help_str = "port detach <port_id>",
1309         .tokens = {
1310                 (void *)&cmd_operate_detach_port_port,
1311                 (void *)&cmd_operate_detach_port_keyword,
1312                 (void *)&cmd_operate_detach_port_port_id,
1313                 NULL,
1314         },
1315 };
1316
1317 /* *** configure speed for all ports *** */
1318 struct cmd_config_speed_all {
1319         cmdline_fixed_string_t port;
1320         cmdline_fixed_string_t keyword;
1321         cmdline_fixed_string_t all;
1322         cmdline_fixed_string_t item1;
1323         cmdline_fixed_string_t item2;
1324         cmdline_fixed_string_t value1;
1325         cmdline_fixed_string_t value2;
1326 };
1327
1328 static int
1329 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1330 {
1331
1332         int duplex;
1333
1334         if (!strcmp(duplexstr, "half")) {
1335                 duplex = ETH_LINK_HALF_DUPLEX;
1336         } else if (!strcmp(duplexstr, "full")) {
1337                 duplex = ETH_LINK_FULL_DUPLEX;
1338         } else if (!strcmp(duplexstr, "auto")) {
1339                 duplex = ETH_LINK_FULL_DUPLEX;
1340         } else {
1341                 printf("Unknown duplex parameter\n");
1342                 return -1;
1343         }
1344
1345         if (!strcmp(speedstr, "10")) {
1346                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1347                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1348         } else if (!strcmp(speedstr, "100")) {
1349                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1350                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1351         } else {
1352                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1353                         printf("Invalid speed/duplex parameters\n");
1354                         return -1;
1355                 }
1356                 if (!strcmp(speedstr, "1000")) {
1357                         *speed = ETH_LINK_SPEED_1G;
1358                 } else if (!strcmp(speedstr, "10000")) {
1359                         *speed = ETH_LINK_SPEED_10G;
1360                 } else if (!strcmp(speedstr, "25000")) {
1361                         *speed = ETH_LINK_SPEED_25G;
1362                 } else if (!strcmp(speedstr, "40000")) {
1363                         *speed = ETH_LINK_SPEED_40G;
1364                 } else if (!strcmp(speedstr, "50000")) {
1365                         *speed = ETH_LINK_SPEED_50G;
1366                 } else if (!strcmp(speedstr, "100000")) {
1367                         *speed = ETH_LINK_SPEED_100G;
1368                 } else if (!strcmp(speedstr, "auto")) {
1369                         *speed = ETH_LINK_SPEED_AUTONEG;
1370                 } else {
1371                         printf("Unknown speed parameter\n");
1372                         return -1;
1373                 }
1374         }
1375
1376         return 0;
1377 }
1378
1379 static void
1380 cmd_config_speed_all_parsed(void *parsed_result,
1381                         __attribute__((unused)) struct cmdline *cl,
1382                         __attribute__((unused)) void *data)
1383 {
1384         struct cmd_config_speed_all *res = parsed_result;
1385         uint32_t link_speed;
1386         portid_t pid;
1387
1388         if (!all_ports_stopped()) {
1389                 printf("Please stop all ports first\n");
1390                 return;
1391         }
1392
1393         if (parse_and_check_speed_duplex(res->value1, res->value2,
1394                         &link_speed) < 0)
1395                 return;
1396
1397         RTE_ETH_FOREACH_DEV(pid) {
1398                 ports[pid].dev_conf.link_speeds = link_speed;
1399         }
1400
1401         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1402 }
1403
1404 cmdline_parse_token_string_t cmd_config_speed_all_port =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1406 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1408                                                         "config");
1409 cmdline_parse_token_string_t cmd_config_speed_all_all =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1411 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1412         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1413 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1415                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1416 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1418 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1419         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1420                                                 "half#full#auto");
1421
1422 cmdline_parse_inst_t cmd_config_speed_all = {
1423         .f = cmd_config_speed_all_parsed,
1424         .data = NULL,
1425         .help_str = "port config all speed "
1426                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1427                                                         "half|full|auto",
1428         .tokens = {
1429                 (void *)&cmd_config_speed_all_port,
1430                 (void *)&cmd_config_speed_all_keyword,
1431                 (void *)&cmd_config_speed_all_all,
1432                 (void *)&cmd_config_speed_all_item1,
1433                 (void *)&cmd_config_speed_all_value1,
1434                 (void *)&cmd_config_speed_all_item2,
1435                 (void *)&cmd_config_speed_all_value2,
1436                 NULL,
1437         },
1438 };
1439
1440 /* *** configure speed for specific port *** */
1441 struct cmd_config_speed_specific {
1442         cmdline_fixed_string_t port;
1443         cmdline_fixed_string_t keyword;
1444         uint8_t id;
1445         cmdline_fixed_string_t item1;
1446         cmdline_fixed_string_t item2;
1447         cmdline_fixed_string_t value1;
1448         cmdline_fixed_string_t value2;
1449 };
1450
1451 static void
1452 cmd_config_speed_specific_parsed(void *parsed_result,
1453                                 __attribute__((unused)) struct cmdline *cl,
1454                                 __attribute__((unused)) void *data)
1455 {
1456         struct cmd_config_speed_specific *res = parsed_result;
1457         uint32_t link_speed;
1458
1459         if (!all_ports_stopped()) {
1460                 printf("Please stop all ports first\n");
1461                 return;
1462         }
1463
1464         if (port_id_is_invalid(res->id, ENABLED_WARN))
1465                 return;
1466
1467         if (parse_and_check_speed_duplex(res->value1, res->value2,
1468                         &link_speed) < 0)
1469                 return;
1470
1471         ports[res->id].dev_conf.link_speeds = link_speed;
1472
1473         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1474 }
1475
1476
1477 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1478         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1479                                                                 "port");
1480 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1482                                                                 "config");
1483 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1484         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1485 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1486         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1487                                                                 "speed");
1488 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1490                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1491 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1493                                                                 "duplex");
1494 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1495         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1496                                                         "half#full#auto");
1497
1498 cmdline_parse_inst_t cmd_config_speed_specific = {
1499         .f = cmd_config_speed_specific_parsed,
1500         .data = NULL,
1501         .help_str = "port config <port_id> speed "
1502                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1503                                                         "half|full|auto",
1504         .tokens = {
1505                 (void *)&cmd_config_speed_specific_port,
1506                 (void *)&cmd_config_speed_specific_keyword,
1507                 (void *)&cmd_config_speed_specific_id,
1508                 (void *)&cmd_config_speed_specific_item1,
1509                 (void *)&cmd_config_speed_specific_value1,
1510                 (void *)&cmd_config_speed_specific_item2,
1511                 (void *)&cmd_config_speed_specific_value2,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** configure txq/rxq, txd/rxd *** */
1517 struct cmd_config_rx_tx {
1518         cmdline_fixed_string_t port;
1519         cmdline_fixed_string_t keyword;
1520         cmdline_fixed_string_t all;
1521         cmdline_fixed_string_t name;
1522         uint16_t value;
1523 };
1524
1525 static void
1526 cmd_config_rx_tx_parsed(void *parsed_result,
1527                         __attribute__((unused)) struct cmdline *cl,
1528                         __attribute__((unused)) void *data)
1529 {
1530         struct cmd_config_rx_tx *res = parsed_result;
1531
1532         if (!all_ports_stopped()) {
1533                 printf("Please stop all ports first\n");
1534                 return;
1535         }
1536         if (!strcmp(res->name, "rxq")) {
1537                 if (!res->value && !nb_txq) {
1538                         printf("Warning: Either rx or tx queues should be non zero\n");
1539                         return;
1540                 }
1541                 if (check_nb_rxq(res->value) != 0)
1542                         return;
1543                 nb_rxq = res->value;
1544         }
1545         else if (!strcmp(res->name, "txq")) {
1546                 if (!res->value && !nb_rxq) {
1547                         printf("Warning: Either rx or tx queues should be non zero\n");
1548                         return;
1549                 }
1550                 nb_txq = res->value;
1551         }
1552         else if (!strcmp(res->name, "rxd")) {
1553                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1554                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1555                                         res->value, RTE_TEST_RX_DESC_MAX);
1556                         return;
1557                 }
1558                 nb_rxd = res->value;
1559         } else if (!strcmp(res->name, "txd")) {
1560                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1561                         printf("txd %d invalid - must be > 0 && <= %d\n",
1562                                         res->value, RTE_TEST_TX_DESC_MAX);
1563                         return;
1564                 }
1565                 nb_txd = res->value;
1566         } else {
1567                 printf("Unknown parameter\n");
1568                 return;
1569         }
1570
1571         fwd_config_setup();
1572
1573         init_port_config();
1574
1575         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1576 }
1577
1578 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1579         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1580 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1582 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1584 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1585         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1586                                                 "rxq#txq#rxd#txd");
1587 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1588         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1589
1590 cmdline_parse_inst_t cmd_config_rx_tx = {
1591         .f = cmd_config_rx_tx_parsed,
1592         .data = NULL,
1593         .help_str = "port config all rxq|txq|rxd|txd <value>",
1594         .tokens = {
1595                 (void *)&cmd_config_rx_tx_port,
1596                 (void *)&cmd_config_rx_tx_keyword,
1597                 (void *)&cmd_config_rx_tx_all,
1598                 (void *)&cmd_config_rx_tx_name,
1599                 (void *)&cmd_config_rx_tx_value,
1600                 NULL,
1601         },
1602 };
1603
1604 /* *** config max packet length *** */
1605 struct cmd_config_max_pkt_len_result {
1606         cmdline_fixed_string_t port;
1607         cmdline_fixed_string_t keyword;
1608         cmdline_fixed_string_t all;
1609         cmdline_fixed_string_t name;
1610         uint32_t value;
1611 };
1612
1613 static void
1614 cmd_config_max_pkt_len_parsed(void *parsed_result,
1615                                 __attribute__((unused)) struct cmdline *cl,
1616                                 __attribute__((unused)) void *data)
1617 {
1618         struct cmd_config_max_pkt_len_result *res = parsed_result;
1619         portid_t pid;
1620
1621         if (!all_ports_stopped()) {
1622                 printf("Please stop all ports first\n");
1623                 return;
1624         }
1625
1626         RTE_ETH_FOREACH_DEV(pid) {
1627                 struct rte_port *port = &ports[pid];
1628                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1629
1630                 if (!strcmp(res->name, "max-pkt-len")) {
1631                         if (res->value < ETHER_MIN_LEN) {
1632                                 printf("max-pkt-len can not be less than %d\n",
1633                                                 ETHER_MIN_LEN);
1634                                 return;
1635                         }
1636                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1637                                 return;
1638
1639                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1640                         if (res->value > ETHER_MAX_LEN)
1641                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1642                         else
1643                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1644                         port->dev_conf.rxmode.offloads = rx_offloads;
1645                 } else {
1646                         printf("Unknown parameter\n");
1647                         return;
1648                 }
1649         }
1650
1651         init_port_config();
1652
1653         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1654 }
1655
1656 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1658                                                                 "port");
1659 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1661                                                                 "config");
1662 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1663         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1664                                                                 "all");
1665 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1667                                                                 "max-pkt-len");
1668 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1669         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1670                                                                 UINT32);
1671
1672 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1673         .f = cmd_config_max_pkt_len_parsed,
1674         .data = NULL,
1675         .help_str = "port config all max-pkt-len <value>",
1676         .tokens = {
1677                 (void *)&cmd_config_max_pkt_len_port,
1678                 (void *)&cmd_config_max_pkt_len_keyword,
1679                 (void *)&cmd_config_max_pkt_len_all,
1680                 (void *)&cmd_config_max_pkt_len_name,
1681                 (void *)&cmd_config_max_pkt_len_value,
1682                 NULL,
1683         },
1684 };
1685
1686 /* *** configure port MTU *** */
1687 struct cmd_config_mtu_result {
1688         cmdline_fixed_string_t port;
1689         cmdline_fixed_string_t keyword;
1690         cmdline_fixed_string_t mtu;
1691         portid_t port_id;
1692         uint16_t value;
1693 };
1694
1695 static void
1696 cmd_config_mtu_parsed(void *parsed_result,
1697                       __attribute__((unused)) struct cmdline *cl,
1698                       __attribute__((unused)) void *data)
1699 {
1700         struct cmd_config_mtu_result *res = parsed_result;
1701
1702         if (res->value < ETHER_MIN_LEN) {
1703                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1704                 return;
1705         }
1706         port_mtu_set(res->port_id, res->value);
1707 }
1708
1709 cmdline_parse_token_string_t cmd_config_mtu_port =
1710         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1711                                  "port");
1712 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1714                                  "config");
1715 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1717                                  "mtu");
1718 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1719         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1720 cmdline_parse_token_num_t cmd_config_mtu_value =
1721         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1722
1723 cmdline_parse_inst_t cmd_config_mtu = {
1724         .f = cmd_config_mtu_parsed,
1725         .data = NULL,
1726         .help_str = "port config mtu <port_id> <value>",
1727         .tokens = {
1728                 (void *)&cmd_config_mtu_port,
1729                 (void *)&cmd_config_mtu_keyword,
1730                 (void *)&cmd_config_mtu_mtu,
1731                 (void *)&cmd_config_mtu_port_id,
1732                 (void *)&cmd_config_mtu_value,
1733                 NULL,
1734         },
1735 };
1736
1737 /* *** configure rx mode *** */
1738 struct cmd_config_rx_mode_flag {
1739         cmdline_fixed_string_t port;
1740         cmdline_fixed_string_t keyword;
1741         cmdline_fixed_string_t all;
1742         cmdline_fixed_string_t name;
1743         cmdline_fixed_string_t value;
1744 };
1745
1746 static void
1747 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1748                                 __attribute__((unused)) struct cmdline *cl,
1749                                 __attribute__((unused)) void *data)
1750 {
1751         struct cmd_config_rx_mode_flag *res = parsed_result;
1752         portid_t pid;
1753
1754         if (!all_ports_stopped()) {
1755                 printf("Please stop all ports first\n");
1756                 return;
1757         }
1758
1759         RTE_ETH_FOREACH_DEV(pid) {
1760                 struct rte_port *port;
1761                 uint64_t rx_offloads;
1762
1763                 port = &ports[pid];
1764                 rx_offloads = port->dev_conf.rxmode.offloads;
1765                 if (!strcmp(res->name, "crc-strip")) {
1766                         if (!strcmp(res->value, "on"))
1767                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1768                         else if (!strcmp(res->value, "off"))
1769                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1770                         else {
1771                                 printf("Unknown parameter\n");
1772                                 return;
1773                         }
1774                 } else if (!strcmp(res->name, "scatter")) {
1775                         if (!strcmp(res->value, "on")) {
1776                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1777                         } else if (!strcmp(res->value, "off")) {
1778                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1779                         } else {
1780                                 printf("Unknown parameter\n");
1781                                 return;
1782                         }
1783                 } else if (!strcmp(res->name, "rx-cksum")) {
1784                         if (!strcmp(res->value, "on"))
1785                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1786                         else if (!strcmp(res->value, "off"))
1787                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1788                         else {
1789                                 printf("Unknown parameter\n");
1790                                 return;
1791                         }
1792                 } else if (!strcmp(res->name, "rx-timestamp")) {
1793                         if (!strcmp(res->value, "on"))
1794                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1795                         else if (!strcmp(res->value, "off"))
1796                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1797                         else {
1798                                 printf("Unknown parameter\n");
1799                                 return;
1800                         }
1801                 } else if (!strcmp(res->name, "hw-vlan")) {
1802                         if (!strcmp(res->value, "on")) {
1803                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1804                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1805                         } else if (!strcmp(res->value, "off")) {
1806                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1807                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1808                         } else {
1809                                 printf("Unknown parameter\n");
1810                                 return;
1811                         }
1812                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1813                         if (!strcmp(res->value, "on"))
1814                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1815                         else if (!strcmp(res->value, "off"))
1816                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1817                         else {
1818                                 printf("Unknown parameter\n");
1819                                 return;
1820                         }
1821                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1822                         if (!strcmp(res->value, "on"))
1823                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1824                         else if (!strcmp(res->value, "off"))
1825                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1826                         else {
1827                                 printf("Unknown parameter\n");
1828                                 return;
1829                         }
1830                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1831                         if (!strcmp(res->value, "on"))
1832                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1833                         else if (!strcmp(res->value, "off"))
1834                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1835                         else {
1836                                 printf("Unknown parameter\n");
1837                                 return;
1838                         }
1839                 } else if (!strcmp(res->name, "drop-en")) {
1840                         if (!strcmp(res->value, "on"))
1841                                 rx_drop_en = 1;
1842                         else if (!strcmp(res->value, "off"))
1843                                 rx_drop_en = 0;
1844                         else {
1845                                 printf("Unknown parameter\n");
1846                                 return;
1847                         }
1848                 } else {
1849                         printf("Unknown parameter\n");
1850                         return;
1851                 }
1852                 port->dev_conf.rxmode.offloads = rx_offloads;
1853         }
1854
1855         init_port_config();
1856
1857         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1858 }
1859
1860 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1862 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1864                                                                 "config");
1865 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1867 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1868         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1869                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1870                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1871 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1873                                                         "on#off");
1874
1875 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1876         .f = cmd_config_rx_mode_flag_parsed,
1877         .data = NULL,
1878         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1879                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1880         .tokens = {
1881                 (void *)&cmd_config_rx_mode_flag_port,
1882                 (void *)&cmd_config_rx_mode_flag_keyword,
1883                 (void *)&cmd_config_rx_mode_flag_all,
1884                 (void *)&cmd_config_rx_mode_flag_name,
1885                 (void *)&cmd_config_rx_mode_flag_value,
1886                 NULL,
1887         },
1888 };
1889
1890 /* *** configure rss *** */
1891 struct cmd_config_rss {
1892         cmdline_fixed_string_t port;
1893         cmdline_fixed_string_t keyword;
1894         cmdline_fixed_string_t all;
1895         cmdline_fixed_string_t name;
1896         cmdline_fixed_string_t value;
1897 };
1898
1899 static void
1900 cmd_config_rss_parsed(void *parsed_result,
1901                         __attribute__((unused)) struct cmdline *cl,
1902                         __attribute__((unused)) void *data)
1903 {
1904         struct cmd_config_rss *res = parsed_result;
1905         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1906         int diag;
1907         uint8_t i;
1908
1909         if (!strcmp(res->value, "all"))
1910                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1911                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1912                                         ETH_RSS_L2_PAYLOAD;
1913         else if (!strcmp(res->value, "ip"))
1914                 rss_conf.rss_hf = ETH_RSS_IP;
1915         else if (!strcmp(res->value, "udp"))
1916                 rss_conf.rss_hf = ETH_RSS_UDP;
1917         else if (!strcmp(res->value, "tcp"))
1918                 rss_conf.rss_hf = ETH_RSS_TCP;
1919         else if (!strcmp(res->value, "sctp"))
1920                 rss_conf.rss_hf = ETH_RSS_SCTP;
1921         else if (!strcmp(res->value, "ether"))
1922                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1923         else if (!strcmp(res->value, "port"))
1924                 rss_conf.rss_hf = ETH_RSS_PORT;
1925         else if (!strcmp(res->value, "vxlan"))
1926                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1927         else if (!strcmp(res->value, "geneve"))
1928                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1929         else if (!strcmp(res->value, "nvgre"))
1930                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1931         else if (!strcmp(res->value, "none"))
1932                 rss_conf.rss_hf = 0;
1933         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1934                                                 atoi(res->value) < 64)
1935                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1936         else {
1937                 printf("Unknown parameter\n");
1938                 return;
1939         }
1940         rss_conf.rss_key = NULL;
1941         for (i = 0; i < rte_eth_dev_count(); i++) {
1942                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1943                 if (diag < 0)
1944                         printf("Configuration of RSS hash at ethernet port %d "
1945                                 "failed with error (%d): %s.\n",
1946                                 i, -diag, strerror(-diag));
1947         }
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rss_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rss_keyword =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1954 cmdline_parse_token_string_t cmd_config_rss_all =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1956 cmdline_parse_token_string_t cmd_config_rss_name =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1958 cmdline_parse_token_string_t cmd_config_rss_value =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1960
1961 cmdline_parse_inst_t cmd_config_rss = {
1962         .f = cmd_config_rss_parsed,
1963         .data = NULL,
1964         .help_str = "port config all rss "
1965                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1966         .tokens = {
1967                 (void *)&cmd_config_rss_port,
1968                 (void *)&cmd_config_rss_keyword,
1969                 (void *)&cmd_config_rss_all,
1970                 (void *)&cmd_config_rss_name,
1971                 (void *)&cmd_config_rss_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** configure rss hash key *** */
1977 struct cmd_config_rss_hash_key {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t config;
1980         portid_t port_id;
1981         cmdline_fixed_string_t rss_hash_key;
1982         cmdline_fixed_string_t rss_type;
1983         cmdline_fixed_string_t key;
1984 };
1985
1986 static uint8_t
1987 hexa_digit_to_value(char hexa_digit)
1988 {
1989         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1990                 return (uint8_t) (hexa_digit - '0');
1991         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1992                 return (uint8_t) ((hexa_digit - 'a') + 10);
1993         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1994                 return (uint8_t) ((hexa_digit - 'A') + 10);
1995         /* Invalid hexa digit */
1996         return 0xFF;
1997 }
1998
1999 static uint8_t
2000 parse_and_check_key_hexa_digit(char *key, int idx)
2001 {
2002         uint8_t hexa_v;
2003
2004         hexa_v = hexa_digit_to_value(key[idx]);
2005         if (hexa_v == 0xFF)
2006                 printf("invalid key: character %c at position %d is not a "
2007                        "valid hexa digit\n", key[idx], idx);
2008         return hexa_v;
2009 }
2010
2011 static void
2012 cmd_config_rss_hash_key_parsed(void *parsed_result,
2013                                __attribute__((unused)) struct cmdline *cl,
2014                                __attribute__((unused)) void *data)
2015 {
2016         struct cmd_config_rss_hash_key *res = parsed_result;
2017         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2018         uint8_t xdgt0;
2019         uint8_t xdgt1;
2020         int i;
2021         struct rte_eth_dev_info dev_info;
2022         uint8_t hash_key_size;
2023         uint32_t key_len;
2024
2025         memset(&dev_info, 0, sizeof(dev_info));
2026         rte_eth_dev_info_get(res->port_id, &dev_info);
2027         if (dev_info.hash_key_size > 0 &&
2028                         dev_info.hash_key_size <= sizeof(hash_key))
2029                 hash_key_size = dev_info.hash_key_size;
2030         else {
2031                 printf("dev_info did not provide a valid hash key size\n");
2032                 return;
2033         }
2034         /* Check the length of the RSS hash key */
2035         key_len = strlen(res->key);
2036         if (key_len != (hash_key_size * 2)) {
2037                 printf("key length: %d invalid - key must be a string of %d"
2038                            " hexa-decimal numbers\n",
2039                            (int) key_len, hash_key_size * 2);
2040                 return;
2041         }
2042         /* Translate RSS hash key into binary representation */
2043         for (i = 0; i < hash_key_size; i++) {
2044                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2045                 if (xdgt0 == 0xFF)
2046                         return;
2047                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2048                 if (xdgt1 == 0xFF)
2049                         return;
2050                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2051         }
2052         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2053                         hash_key_size);
2054 }
2055
2056 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2058 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2060                                  "config");
2061 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2062         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2063 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2065                                  rss_hash_key, "rss-hash-key");
2066 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2068                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2069                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2070                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2071                                  "ipv6-tcp-ex#ipv6-udp-ex");
2072 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2073         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2074
2075 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2076         .f = cmd_config_rss_hash_key_parsed,
2077         .data = NULL,
2078         .help_str = "port config <port_id> rss-hash-key "
2079                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2080                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2081                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2082                 "<string of hex digits (variable length, NIC dependent)>",
2083         .tokens = {
2084                 (void *)&cmd_config_rss_hash_key_port,
2085                 (void *)&cmd_config_rss_hash_key_config,
2086                 (void *)&cmd_config_rss_hash_key_port_id,
2087                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2088                 (void *)&cmd_config_rss_hash_key_rss_type,
2089                 (void *)&cmd_config_rss_hash_key_value,
2090                 NULL,
2091         },
2092 };
2093
2094 /* *** configure port rxq/txq start/stop *** */
2095 struct cmd_config_rxtx_queue {
2096         cmdline_fixed_string_t port;
2097         portid_t portid;
2098         cmdline_fixed_string_t rxtxq;
2099         uint16_t qid;
2100         cmdline_fixed_string_t opname;
2101 };
2102
2103 static void
2104 cmd_config_rxtx_queue_parsed(void *parsed_result,
2105                         __attribute__((unused)) struct cmdline *cl,
2106                         __attribute__((unused)) void *data)
2107 {
2108         struct cmd_config_rxtx_queue *res = parsed_result;
2109         uint8_t isrx;
2110         uint8_t isstart;
2111         int ret = 0;
2112
2113         if (test_done == 0) {
2114                 printf("Please stop forwarding first\n");
2115                 return;
2116         }
2117
2118         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2119                 return;
2120
2121         if (port_is_started(res->portid) != 1) {
2122                 printf("Please start port %u first\n", res->portid);
2123                 return;
2124         }
2125
2126         if (!strcmp(res->rxtxq, "rxq"))
2127                 isrx = 1;
2128         else if (!strcmp(res->rxtxq, "txq"))
2129                 isrx = 0;
2130         else {
2131                 printf("Unknown parameter\n");
2132                 return;
2133         }
2134
2135         if (isrx && rx_queue_id_is_invalid(res->qid))
2136                 return;
2137         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2138                 return;
2139
2140         if (!strcmp(res->opname, "start"))
2141                 isstart = 1;
2142         else if (!strcmp(res->opname, "stop"))
2143                 isstart = 0;
2144         else {
2145                 printf("Unknown parameter\n");
2146                 return;
2147         }
2148
2149         if (isstart && isrx)
2150                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2151         else if (!isstart && isrx)
2152                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2153         else if (isstart && !isrx)
2154                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2155         else
2156                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2157
2158         if (ret == -ENOTSUP)
2159                 printf("Function not supported in PMD driver\n");
2160 }
2161
2162 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2163         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2164 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2165         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2166 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2167         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2168 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2169         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2170 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2171         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2172                                                 "start#stop");
2173
2174 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2175         .f = cmd_config_rxtx_queue_parsed,
2176         .data = NULL,
2177         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2178         .tokens = {
2179                 (void *)&cmd_config_speed_all_port,
2180                 (void *)&cmd_config_rxtx_queue_portid,
2181                 (void *)&cmd_config_rxtx_queue_rxtxq,
2182                 (void *)&cmd_config_rxtx_queue_qid,
2183                 (void *)&cmd_config_rxtx_queue_opname,
2184                 NULL,
2185         },
2186 };
2187
2188 /* *** Configure RSS RETA *** */
2189 struct cmd_config_rss_reta {
2190         cmdline_fixed_string_t port;
2191         cmdline_fixed_string_t keyword;
2192         portid_t port_id;
2193         cmdline_fixed_string_t name;
2194         cmdline_fixed_string_t list_name;
2195         cmdline_fixed_string_t list_of_items;
2196 };
2197
2198 static int
2199 parse_reta_config(const char *str,
2200                   struct rte_eth_rss_reta_entry64 *reta_conf,
2201                   uint16_t nb_entries)
2202 {
2203         int i;
2204         unsigned size;
2205         uint16_t hash_index, idx, shift;
2206         uint16_t nb_queue;
2207         char s[256];
2208         const char *p, *p0 = str;
2209         char *end;
2210         enum fieldnames {
2211                 FLD_HASH_INDEX = 0,
2212                 FLD_QUEUE,
2213                 _NUM_FLD
2214         };
2215         unsigned long int_fld[_NUM_FLD];
2216         char *str_fld[_NUM_FLD];
2217
2218         while ((p = strchr(p0,'(')) != NULL) {
2219                 ++p;
2220                 if((p0 = strchr(p,')')) == NULL)
2221                         return -1;
2222
2223                 size = p0 - p;
2224                 if(size >= sizeof(s))
2225                         return -1;
2226
2227                 snprintf(s, sizeof(s), "%.*s", size, p);
2228                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2229                         return -1;
2230                 for (i = 0; i < _NUM_FLD; i++) {
2231                         errno = 0;
2232                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2233                         if (errno != 0 || end == str_fld[i] ||
2234                                         int_fld[i] > 65535)
2235                                 return -1;
2236                 }
2237
2238                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2239                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2240
2241                 if (hash_index >= nb_entries) {
2242                         printf("Invalid RETA hash index=%d\n", hash_index);
2243                         return -1;
2244                 }
2245
2246                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2247                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2248                 reta_conf[idx].mask |= (1ULL << shift);
2249                 reta_conf[idx].reta[shift] = nb_queue;
2250         }
2251
2252         return 0;
2253 }
2254
2255 static void
2256 cmd_set_rss_reta_parsed(void *parsed_result,
2257                         __attribute__((unused)) struct cmdline *cl,
2258                         __attribute__((unused)) void *data)
2259 {
2260         int ret;
2261         struct rte_eth_dev_info dev_info;
2262         struct rte_eth_rss_reta_entry64 reta_conf[8];
2263         struct cmd_config_rss_reta *res = parsed_result;
2264
2265         memset(&dev_info, 0, sizeof(dev_info));
2266         rte_eth_dev_info_get(res->port_id, &dev_info);
2267         if (dev_info.reta_size == 0) {
2268                 printf("Redirection table size is 0 which is "
2269                                         "invalid for RSS\n");
2270                 return;
2271         } else
2272                 printf("The reta size of port %d is %u\n",
2273                         res->port_id, dev_info.reta_size);
2274         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2275                 printf("Currently do not support more than %u entries of "
2276                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2277                 return;
2278         }
2279
2280         memset(reta_conf, 0, sizeof(reta_conf));
2281         if (!strcmp(res->list_name, "reta")) {
2282                 if (parse_reta_config(res->list_of_items, reta_conf,
2283                                                 dev_info.reta_size)) {
2284                         printf("Invalid RSS Redirection Table "
2285                                         "config entered\n");
2286                         return;
2287                 }
2288                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2289                                 reta_conf, dev_info.reta_size);
2290                 if (ret != 0)
2291                         printf("Bad redirection table parameter, "
2292                                         "return code = %d \n", ret);
2293         }
2294 }
2295
2296 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2298 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2300 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2301         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2302 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2304 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2306 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2307         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2308                                  NULL);
2309 cmdline_parse_inst_t cmd_config_rss_reta = {
2310         .f = cmd_set_rss_reta_parsed,
2311         .data = NULL,
2312         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2313         .tokens = {
2314                 (void *)&cmd_config_rss_reta_port,
2315                 (void *)&cmd_config_rss_reta_keyword,
2316                 (void *)&cmd_config_rss_reta_port_id,
2317                 (void *)&cmd_config_rss_reta_name,
2318                 (void *)&cmd_config_rss_reta_list_name,
2319                 (void *)&cmd_config_rss_reta_list_of_items,
2320                 NULL,
2321         },
2322 };
2323
2324 /* *** SHOW PORT RETA INFO *** */
2325 struct cmd_showport_reta {
2326         cmdline_fixed_string_t show;
2327         cmdline_fixed_string_t port;
2328         portid_t port_id;
2329         cmdline_fixed_string_t rss;
2330         cmdline_fixed_string_t reta;
2331         uint16_t size;
2332         cmdline_fixed_string_t list_of_items;
2333 };
2334
2335 static int
2336 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2337                            uint16_t nb_entries,
2338                            char *str)
2339 {
2340         uint32_t size;
2341         const char *p, *p0 = str;
2342         char s[256];
2343         char *end;
2344         char *str_fld[8];
2345         uint16_t i;
2346         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2347                         RTE_RETA_GROUP_SIZE;
2348         int ret;
2349
2350         p = strchr(p0, '(');
2351         if (p == NULL)
2352                 return -1;
2353         p++;
2354         p0 = strchr(p, ')');
2355         if (p0 == NULL)
2356                 return -1;
2357         size = p0 - p;
2358         if (size >= sizeof(s)) {
2359                 printf("The string size exceeds the internal buffer size\n");
2360                 return -1;
2361         }
2362         snprintf(s, sizeof(s), "%.*s", size, p);
2363         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2364         if (ret <= 0 || ret != num) {
2365                 printf("The bits of masks do not match the number of "
2366                                         "reta entries: %u\n", num);
2367                 return -1;
2368         }
2369         for (i = 0; i < ret; i++)
2370                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2371
2372         return 0;
2373 }
2374
2375 static void
2376 cmd_showport_reta_parsed(void *parsed_result,
2377                          __attribute__((unused)) struct cmdline *cl,
2378                          __attribute__((unused)) void *data)
2379 {
2380         struct cmd_showport_reta *res = parsed_result;
2381         struct rte_eth_rss_reta_entry64 reta_conf[8];
2382         struct rte_eth_dev_info dev_info;
2383         uint16_t max_reta_size;
2384
2385         memset(&dev_info, 0, sizeof(dev_info));
2386         rte_eth_dev_info_get(res->port_id, &dev_info);
2387         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2388         if (res->size == 0 || res->size > max_reta_size) {
2389                 printf("Invalid redirection table size: %u (1-%u)\n",
2390                         res->size, max_reta_size);
2391                 return;
2392         }
2393
2394         memset(reta_conf, 0, sizeof(reta_conf));
2395         if (showport_parse_reta_config(reta_conf, res->size,
2396                                 res->list_of_items) < 0) {
2397                 printf("Invalid string: %s for reta masks\n",
2398                                         res->list_of_items);
2399                 return;
2400         }
2401         port_rss_reta_info(res->port_id, reta_conf, res->size);
2402 }
2403
2404 cmdline_parse_token_string_t cmd_showport_reta_show =
2405         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2406 cmdline_parse_token_string_t cmd_showport_reta_port =
2407         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2408 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2409         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2410 cmdline_parse_token_string_t cmd_showport_reta_rss =
2411         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2412 cmdline_parse_token_string_t cmd_showport_reta_reta =
2413         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2414 cmdline_parse_token_num_t cmd_showport_reta_size =
2415         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2416 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2417         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2418                                         list_of_items, NULL);
2419
2420 cmdline_parse_inst_t cmd_showport_reta = {
2421         .f = cmd_showport_reta_parsed,
2422         .data = NULL,
2423         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2424         .tokens = {
2425                 (void *)&cmd_showport_reta_show,
2426                 (void *)&cmd_showport_reta_port,
2427                 (void *)&cmd_showport_reta_port_id,
2428                 (void *)&cmd_showport_reta_rss,
2429                 (void *)&cmd_showport_reta_reta,
2430                 (void *)&cmd_showport_reta_size,
2431                 (void *)&cmd_showport_reta_list_of_items,
2432                 NULL,
2433         },
2434 };
2435
2436 /* *** Show RSS hash configuration *** */
2437 struct cmd_showport_rss_hash {
2438         cmdline_fixed_string_t show;
2439         cmdline_fixed_string_t port;
2440         portid_t port_id;
2441         cmdline_fixed_string_t rss_hash;
2442         cmdline_fixed_string_t rss_type;
2443         cmdline_fixed_string_t key; /* optional argument */
2444 };
2445
2446 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2447                                 __attribute__((unused)) struct cmdline *cl,
2448                                 void *show_rss_key)
2449 {
2450         struct cmd_showport_rss_hash *res = parsed_result;
2451
2452         port_rss_hash_conf_show(res->port_id, res->rss_type,
2453                                 show_rss_key != NULL);
2454 }
2455
2456 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2457         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2458 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2459         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2460 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2461         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2462 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2463         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2464                                  "rss-hash");
2465 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2466         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2467                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2468                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2469                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2470                                  "ipv6-tcp-ex#ipv6-udp-ex");
2471 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2472         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2473
2474 cmdline_parse_inst_t cmd_showport_rss_hash = {
2475         .f = cmd_showport_rss_hash_parsed,
2476         .data = NULL,
2477         .help_str = "show port <port_id> rss-hash "
2478                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2479                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2480                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2481         .tokens = {
2482                 (void *)&cmd_showport_rss_hash_show,
2483                 (void *)&cmd_showport_rss_hash_port,
2484                 (void *)&cmd_showport_rss_hash_port_id,
2485                 (void *)&cmd_showport_rss_hash_rss_hash,
2486                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2487                 NULL,
2488         },
2489 };
2490
2491 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2492         .f = cmd_showport_rss_hash_parsed,
2493         .data = (void *)1,
2494         .help_str = "show port <port_id> rss-hash "
2495                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2496                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2497                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2498         .tokens = {
2499                 (void *)&cmd_showport_rss_hash_show,
2500                 (void *)&cmd_showport_rss_hash_port,
2501                 (void *)&cmd_showport_rss_hash_port_id,
2502                 (void *)&cmd_showport_rss_hash_rss_hash,
2503                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2504                 (void *)&cmd_showport_rss_hash_rss_key,
2505                 NULL,
2506         },
2507 };
2508
2509 /* *** Configure DCB *** */
2510 struct cmd_config_dcb {
2511         cmdline_fixed_string_t port;
2512         cmdline_fixed_string_t config;
2513         portid_t port_id;
2514         cmdline_fixed_string_t dcb;
2515         cmdline_fixed_string_t vt;
2516         cmdline_fixed_string_t vt_en;
2517         uint8_t num_tcs;
2518         cmdline_fixed_string_t pfc;
2519         cmdline_fixed_string_t pfc_en;
2520 };
2521
2522 static void
2523 cmd_config_dcb_parsed(void *parsed_result,
2524                         __attribute__((unused)) struct cmdline *cl,
2525                         __attribute__((unused)) void *data)
2526 {
2527         struct cmd_config_dcb *res = parsed_result;
2528         portid_t port_id = res->port_id;
2529         struct rte_port *port;
2530         uint8_t pfc_en;
2531         int ret;
2532
2533         port = &ports[port_id];
2534         /** Check if the port is not started **/
2535         if (port->port_status != RTE_PORT_STOPPED) {
2536                 printf("Please stop port %d first\n", port_id);
2537                 return;
2538         }
2539
2540         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2541                 printf("The invalid number of traffic class,"
2542                         " only 4 or 8 allowed.\n");
2543                 return;
2544         }
2545
2546         if (nb_fwd_lcores < res->num_tcs) {
2547                 printf("nb_cores shouldn't be less than number of TCs.\n");
2548                 return;
2549         }
2550         if (!strncmp(res->pfc_en, "on", 2))
2551                 pfc_en = 1;
2552         else
2553                 pfc_en = 0;
2554
2555         /* DCB in VT mode */
2556         if (!strncmp(res->vt_en, "on", 2))
2557                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2558                                 (enum rte_eth_nb_tcs)res->num_tcs,
2559                                 pfc_en);
2560         else
2561                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2562                                 (enum rte_eth_nb_tcs)res->num_tcs,
2563                                 pfc_en);
2564
2565
2566         if (ret != 0) {
2567                 printf("Cannot initialize network ports.\n");
2568                 return;
2569         }
2570
2571         cmd_reconfig_device_queue(port_id, 1, 1);
2572 }
2573
2574 cmdline_parse_token_string_t cmd_config_dcb_port =
2575         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2576 cmdline_parse_token_string_t cmd_config_dcb_config =
2577         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2578 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2579         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2580 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2581         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2582 cmdline_parse_token_string_t cmd_config_dcb_vt =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2584 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2585         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2586 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2587         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2588 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2589         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2590 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2591         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2592
2593 cmdline_parse_inst_t cmd_config_dcb = {
2594         .f = cmd_config_dcb_parsed,
2595         .data = NULL,
2596         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2597         .tokens = {
2598                 (void *)&cmd_config_dcb_port,
2599                 (void *)&cmd_config_dcb_config,
2600                 (void *)&cmd_config_dcb_port_id,
2601                 (void *)&cmd_config_dcb_dcb,
2602                 (void *)&cmd_config_dcb_vt,
2603                 (void *)&cmd_config_dcb_vt_en,
2604                 (void *)&cmd_config_dcb_num_tcs,
2605                 (void *)&cmd_config_dcb_pfc,
2606                 (void *)&cmd_config_dcb_pfc_en,
2607                 NULL,
2608         },
2609 };
2610
2611 /* *** configure number of packets per burst *** */
2612 struct cmd_config_burst {
2613         cmdline_fixed_string_t port;
2614         cmdline_fixed_string_t keyword;
2615         cmdline_fixed_string_t all;
2616         cmdline_fixed_string_t name;
2617         uint16_t value;
2618 };
2619
2620 static void
2621 cmd_config_burst_parsed(void *parsed_result,
2622                         __attribute__((unused)) struct cmdline *cl,
2623                         __attribute__((unused)) void *data)
2624 {
2625         struct cmd_config_burst *res = parsed_result;
2626
2627         if (!all_ports_stopped()) {
2628                 printf("Please stop all ports first\n");
2629                 return;
2630         }
2631
2632         if (!strcmp(res->name, "burst")) {
2633                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2634                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2635                         return;
2636                 }
2637                 nb_pkt_per_burst = res->value;
2638         } else {
2639                 printf("Unknown parameter\n");
2640                 return;
2641         }
2642
2643         init_port_config();
2644
2645         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2646 }
2647
2648 cmdline_parse_token_string_t cmd_config_burst_port =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2650 cmdline_parse_token_string_t cmd_config_burst_keyword =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2652 cmdline_parse_token_string_t cmd_config_burst_all =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2654 cmdline_parse_token_string_t cmd_config_burst_name =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2656 cmdline_parse_token_num_t cmd_config_burst_value =
2657         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2658
2659 cmdline_parse_inst_t cmd_config_burst = {
2660         .f = cmd_config_burst_parsed,
2661         .data = NULL,
2662         .help_str = "port config all burst <value>",
2663         .tokens = {
2664                 (void *)&cmd_config_burst_port,
2665                 (void *)&cmd_config_burst_keyword,
2666                 (void *)&cmd_config_burst_all,
2667                 (void *)&cmd_config_burst_name,
2668                 (void *)&cmd_config_burst_value,
2669                 NULL,
2670         },
2671 };
2672
2673 /* *** configure rx/tx queues *** */
2674 struct cmd_config_thresh {
2675         cmdline_fixed_string_t port;
2676         cmdline_fixed_string_t keyword;
2677         cmdline_fixed_string_t all;
2678         cmdline_fixed_string_t name;
2679         uint8_t value;
2680 };
2681
2682 static void
2683 cmd_config_thresh_parsed(void *parsed_result,
2684                         __attribute__((unused)) struct cmdline *cl,
2685                         __attribute__((unused)) void *data)
2686 {
2687         struct cmd_config_thresh *res = parsed_result;
2688
2689         if (!all_ports_stopped()) {
2690                 printf("Please stop all ports first\n");
2691                 return;
2692         }
2693
2694         if (!strcmp(res->name, "txpt"))
2695                 tx_pthresh = res->value;
2696         else if(!strcmp(res->name, "txht"))
2697                 tx_hthresh = res->value;
2698         else if(!strcmp(res->name, "txwt"))
2699                 tx_wthresh = res->value;
2700         else if(!strcmp(res->name, "rxpt"))
2701                 rx_pthresh = res->value;
2702         else if(!strcmp(res->name, "rxht"))
2703                 rx_hthresh = res->value;
2704         else if(!strcmp(res->name, "rxwt"))
2705                 rx_wthresh = res->value;
2706         else {
2707                 printf("Unknown parameter\n");
2708                 return;
2709         }
2710
2711         init_port_config();
2712
2713         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2714 }
2715
2716 cmdline_parse_token_string_t cmd_config_thresh_port =
2717         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2718 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2720 cmdline_parse_token_string_t cmd_config_thresh_all =
2721         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2722 cmdline_parse_token_string_t cmd_config_thresh_name =
2723         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2724                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2725 cmdline_parse_token_num_t cmd_config_thresh_value =
2726         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2727
2728 cmdline_parse_inst_t cmd_config_thresh = {
2729         .f = cmd_config_thresh_parsed,
2730         .data = NULL,
2731         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2732         .tokens = {
2733                 (void *)&cmd_config_thresh_port,
2734                 (void *)&cmd_config_thresh_keyword,
2735                 (void *)&cmd_config_thresh_all,
2736                 (void *)&cmd_config_thresh_name,
2737                 (void *)&cmd_config_thresh_value,
2738                 NULL,
2739         },
2740 };
2741
2742 /* *** configure free/rs threshold *** */
2743 struct cmd_config_threshold {
2744         cmdline_fixed_string_t port;
2745         cmdline_fixed_string_t keyword;
2746         cmdline_fixed_string_t all;
2747         cmdline_fixed_string_t name;
2748         uint16_t value;
2749 };
2750
2751 static void
2752 cmd_config_threshold_parsed(void *parsed_result,
2753                         __attribute__((unused)) struct cmdline *cl,
2754                         __attribute__((unused)) void *data)
2755 {
2756         struct cmd_config_threshold *res = parsed_result;
2757
2758         if (!all_ports_stopped()) {
2759                 printf("Please stop all ports first\n");
2760                 return;
2761         }
2762
2763         if (!strcmp(res->name, "txfreet"))
2764                 tx_free_thresh = res->value;
2765         else if (!strcmp(res->name, "txrst"))
2766                 tx_rs_thresh = res->value;
2767         else if (!strcmp(res->name, "rxfreet"))
2768                 rx_free_thresh = res->value;
2769         else {
2770                 printf("Unknown parameter\n");
2771                 return;
2772         }
2773
2774         init_port_config();
2775
2776         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2777 }
2778
2779 cmdline_parse_token_string_t cmd_config_threshold_port =
2780         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2781 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2782         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2783                                                                 "config");
2784 cmdline_parse_token_string_t cmd_config_threshold_all =
2785         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2786 cmdline_parse_token_string_t cmd_config_threshold_name =
2787         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2788                                                 "txfreet#txrst#rxfreet");
2789 cmdline_parse_token_num_t cmd_config_threshold_value =
2790         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2791
2792 cmdline_parse_inst_t cmd_config_threshold = {
2793         .f = cmd_config_threshold_parsed,
2794         .data = NULL,
2795         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2796         .tokens = {
2797                 (void *)&cmd_config_threshold_port,
2798                 (void *)&cmd_config_threshold_keyword,
2799                 (void *)&cmd_config_threshold_all,
2800                 (void *)&cmd_config_threshold_name,
2801                 (void *)&cmd_config_threshold_value,
2802                 NULL,
2803         },
2804 };
2805
2806 /* *** stop *** */
2807 struct cmd_stop_result {
2808         cmdline_fixed_string_t stop;
2809 };
2810
2811 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2812                             __attribute__((unused)) struct cmdline *cl,
2813                             __attribute__((unused)) void *data)
2814 {
2815         stop_packet_forwarding();
2816 }
2817
2818 cmdline_parse_token_string_t cmd_stop_stop =
2819         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2820
2821 cmdline_parse_inst_t cmd_stop = {
2822         .f = cmd_stop_parsed,
2823         .data = NULL,
2824         .help_str = "stop: Stop packet forwarding",
2825         .tokens = {
2826                 (void *)&cmd_stop_stop,
2827                 NULL,
2828         },
2829 };
2830
2831 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2832
2833 unsigned int
2834 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2835                 unsigned int *parsed_items, int check_unique_values)
2836 {
2837         unsigned int nb_item;
2838         unsigned int value;
2839         unsigned int i;
2840         unsigned int j;
2841         int value_ok;
2842         char c;
2843
2844         /*
2845          * First parse all items in the list and store their value.
2846          */
2847         value = 0;
2848         nb_item = 0;
2849         value_ok = 0;
2850         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2851                 c = str[i];
2852                 if ((c >= '0') && (c <= '9')) {
2853                         value = (unsigned int) (value * 10 + (c - '0'));
2854                         value_ok = 1;
2855                         continue;
2856                 }
2857                 if (c != ',') {
2858                         printf("character %c is not a decimal digit\n", c);
2859                         return 0;
2860                 }
2861                 if (! value_ok) {
2862                         printf("No valid value before comma\n");
2863                         return 0;
2864                 }
2865                 if (nb_item < max_items) {
2866                         parsed_items[nb_item] = value;
2867                         value_ok = 0;
2868                         value = 0;
2869                 }
2870                 nb_item++;
2871         }
2872         if (nb_item >= max_items) {
2873                 printf("Number of %s = %u > %u (maximum items)\n",
2874                        item_name, nb_item + 1, max_items);
2875                 return 0;
2876         }
2877         parsed_items[nb_item++] = value;
2878         if (! check_unique_values)
2879                 return nb_item;
2880
2881         /*
2882          * Then, check that all values in the list are differents.
2883          * No optimization here...
2884          */
2885         for (i = 0; i < nb_item; i++) {
2886                 for (j = i + 1; j < nb_item; j++) {
2887                         if (parsed_items[j] == parsed_items[i]) {
2888                                 printf("duplicated %s %u at index %u and %u\n",
2889                                        item_name, parsed_items[i], i, j);
2890                                 return 0;
2891                         }
2892                 }
2893         }
2894         return nb_item;
2895 }
2896
2897 struct cmd_set_list_result {
2898         cmdline_fixed_string_t cmd_keyword;
2899         cmdline_fixed_string_t list_name;
2900         cmdline_fixed_string_t list_of_items;
2901 };
2902
2903 static void cmd_set_list_parsed(void *parsed_result,
2904                                 __attribute__((unused)) struct cmdline *cl,
2905                                 __attribute__((unused)) void *data)
2906 {
2907         struct cmd_set_list_result *res;
2908         union {
2909                 unsigned int lcorelist[RTE_MAX_LCORE];
2910                 unsigned int portlist[RTE_MAX_ETHPORTS];
2911         } parsed_items;
2912         unsigned int nb_item;
2913
2914         if (test_done == 0) {
2915                 printf("Please stop forwarding first\n");
2916                 return;
2917         }
2918
2919         res = parsed_result;
2920         if (!strcmp(res->list_name, "corelist")) {
2921                 nb_item = parse_item_list(res->list_of_items, "core",
2922                                           RTE_MAX_LCORE,
2923                                           parsed_items.lcorelist, 1);
2924                 if (nb_item > 0) {
2925                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2926                         fwd_config_setup();
2927                 }
2928                 return;
2929         }
2930         if (!strcmp(res->list_name, "portlist")) {
2931                 nb_item = parse_item_list(res->list_of_items, "port",
2932                                           RTE_MAX_ETHPORTS,
2933                                           parsed_items.portlist, 1);
2934                 if (nb_item > 0) {
2935                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2936                         fwd_config_setup();
2937                 }
2938         }
2939 }
2940
2941 cmdline_parse_token_string_t cmd_set_list_keyword =
2942         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2943                                  "set");
2944 cmdline_parse_token_string_t cmd_set_list_name =
2945         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2946                                  "corelist#portlist");
2947 cmdline_parse_token_string_t cmd_set_list_of_items =
2948         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2949                                  NULL);
2950
2951 cmdline_parse_inst_t cmd_set_fwd_list = {
2952         .f = cmd_set_list_parsed,
2953         .data = NULL,
2954         .help_str = "set corelist|portlist <list0[,list1]*>",
2955         .tokens = {
2956                 (void *)&cmd_set_list_keyword,
2957                 (void *)&cmd_set_list_name,
2958                 (void *)&cmd_set_list_of_items,
2959                 NULL,
2960         },
2961 };
2962
2963 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2964
2965 struct cmd_setmask_result {
2966         cmdline_fixed_string_t set;
2967         cmdline_fixed_string_t mask;
2968         uint64_t hexavalue;
2969 };
2970
2971 static void cmd_set_mask_parsed(void *parsed_result,
2972                                 __attribute__((unused)) struct cmdline *cl,
2973                                 __attribute__((unused)) void *data)
2974 {
2975         struct cmd_setmask_result *res = parsed_result;
2976
2977         if (test_done == 0) {
2978                 printf("Please stop forwarding first\n");
2979                 return;
2980         }
2981         if (!strcmp(res->mask, "coremask")) {
2982                 set_fwd_lcores_mask(res->hexavalue);
2983                 fwd_config_setup();
2984         } else if (!strcmp(res->mask, "portmask")) {
2985                 set_fwd_ports_mask(res->hexavalue);
2986                 fwd_config_setup();
2987         }
2988 }
2989
2990 cmdline_parse_token_string_t cmd_setmask_set =
2991         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2992 cmdline_parse_token_string_t cmd_setmask_mask =
2993         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2994                                  "coremask#portmask");
2995 cmdline_parse_token_num_t cmd_setmask_value =
2996         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2997
2998 cmdline_parse_inst_t cmd_set_fwd_mask = {
2999         .f = cmd_set_mask_parsed,
3000         .data = NULL,
3001         .help_str = "set coremask|portmask <hexadecimal value>",
3002         .tokens = {
3003                 (void *)&cmd_setmask_set,
3004                 (void *)&cmd_setmask_mask,
3005                 (void *)&cmd_setmask_value,
3006                 NULL,
3007         },
3008 };
3009
3010 /*
3011  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3012  */
3013 struct cmd_set_result {
3014         cmdline_fixed_string_t set;
3015         cmdline_fixed_string_t what;
3016         uint16_t value;
3017 };
3018
3019 static void cmd_set_parsed(void *parsed_result,
3020                            __attribute__((unused)) struct cmdline *cl,
3021                            __attribute__((unused)) void *data)
3022 {
3023         struct cmd_set_result *res = parsed_result;
3024         if (!strcmp(res->what, "nbport")) {
3025                 set_fwd_ports_number(res->value);
3026                 fwd_config_setup();
3027         } else if (!strcmp(res->what, "nbcore")) {
3028                 set_fwd_lcores_number(res->value);
3029                 fwd_config_setup();
3030         } else if (!strcmp(res->what, "burst"))
3031                 set_nb_pkt_per_burst(res->value);
3032         else if (!strcmp(res->what, "verbose"))
3033                 set_verbose_level(res->value);
3034 }
3035
3036 cmdline_parse_token_string_t cmd_set_set =
3037         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3038 cmdline_parse_token_string_t cmd_set_what =
3039         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3040                                  "nbport#nbcore#burst#verbose");
3041 cmdline_parse_token_num_t cmd_set_value =
3042         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3043
3044 cmdline_parse_inst_t cmd_set_numbers = {
3045         .f = cmd_set_parsed,
3046         .data = NULL,
3047         .help_str = "set nbport|nbcore|burst|verbose <value>",
3048         .tokens = {
3049                 (void *)&cmd_set_set,
3050                 (void *)&cmd_set_what,
3051                 (void *)&cmd_set_value,
3052                 NULL,
3053         },
3054 };
3055
3056 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3057
3058 struct cmd_set_txpkts_result {
3059         cmdline_fixed_string_t cmd_keyword;
3060         cmdline_fixed_string_t txpkts;
3061         cmdline_fixed_string_t seg_lengths;
3062 };
3063
3064 static void
3065 cmd_set_txpkts_parsed(void *parsed_result,
3066                       __attribute__((unused)) struct cmdline *cl,
3067                       __attribute__((unused)) void *data)
3068 {
3069         struct cmd_set_txpkts_result *res;
3070         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3071         unsigned int nb_segs;
3072
3073         res = parsed_result;
3074         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3075                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3076         if (nb_segs > 0)
3077                 set_tx_pkt_segments(seg_lengths, nb_segs);
3078 }
3079
3080 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3081         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3082                                  cmd_keyword, "set");
3083 cmdline_parse_token_string_t cmd_set_txpkts_name =
3084         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3085                                  txpkts, "txpkts");
3086 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3087         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3088                                  seg_lengths, NULL);
3089
3090 cmdline_parse_inst_t cmd_set_txpkts = {
3091         .f = cmd_set_txpkts_parsed,
3092         .data = NULL,
3093         .help_str = "set txpkts <len0[,len1]*>",
3094         .tokens = {
3095                 (void *)&cmd_set_txpkts_keyword,
3096                 (void *)&cmd_set_txpkts_name,
3097                 (void *)&cmd_set_txpkts_lengths,
3098                 NULL,
3099         },
3100 };
3101
3102 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3103
3104 struct cmd_set_txsplit_result {
3105         cmdline_fixed_string_t cmd_keyword;
3106         cmdline_fixed_string_t txsplit;
3107         cmdline_fixed_string_t mode;
3108 };
3109
3110 static void
3111 cmd_set_txsplit_parsed(void *parsed_result,
3112                       __attribute__((unused)) struct cmdline *cl,
3113                       __attribute__((unused)) void *data)
3114 {
3115         struct cmd_set_txsplit_result *res;
3116
3117         res = parsed_result;
3118         set_tx_pkt_split(res->mode);
3119 }
3120
3121 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3122         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3123                                  cmd_keyword, "set");
3124 cmdline_parse_token_string_t cmd_set_txsplit_name =
3125         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3126                                  txsplit, "txsplit");
3127 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3128         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3129                                  mode, NULL);
3130
3131 cmdline_parse_inst_t cmd_set_txsplit = {
3132         .f = cmd_set_txsplit_parsed,
3133         .data = NULL,
3134         .help_str = "set txsplit on|off|rand",
3135         .tokens = {
3136                 (void *)&cmd_set_txsplit_keyword,
3137                 (void *)&cmd_set_txsplit_name,
3138                 (void *)&cmd_set_txsplit_mode,
3139                 NULL,
3140         },
3141 };
3142
3143 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3144 struct cmd_rx_vlan_filter_all_result {
3145         cmdline_fixed_string_t rx_vlan;
3146         cmdline_fixed_string_t what;
3147         cmdline_fixed_string_t all;
3148         portid_t port_id;
3149 };
3150
3151 static void
3152 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3153                               __attribute__((unused)) struct cmdline *cl,
3154                               __attribute__((unused)) void *data)
3155 {
3156         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3157
3158         if (!strcmp(res->what, "add"))
3159                 rx_vlan_all_filter_set(res->port_id, 1);
3160         else
3161                 rx_vlan_all_filter_set(res->port_id, 0);
3162 }
3163
3164 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3165         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3166                                  rx_vlan, "rx_vlan");
3167 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3168         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3169                                  what, "add#rm");
3170 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3172                                  all, "all");
3173 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3174         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3175                               port_id, UINT16);
3176
3177 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3178         .f = cmd_rx_vlan_filter_all_parsed,
3179         .data = NULL,
3180         .help_str = "rx_vlan add|rm all <port_id>: "
3181                 "Add/Remove all identifiers to/from the set of VLAN "
3182                 "identifiers filtered by a port",
3183         .tokens = {
3184                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3185                 (void *)&cmd_rx_vlan_filter_all_what,
3186                 (void *)&cmd_rx_vlan_filter_all_all,
3187                 (void *)&cmd_rx_vlan_filter_all_portid,
3188                 NULL,
3189         },
3190 };
3191
3192 /* *** VLAN OFFLOAD SET ON A PORT *** */
3193 struct cmd_vlan_offload_result {
3194         cmdline_fixed_string_t vlan;
3195         cmdline_fixed_string_t set;
3196         cmdline_fixed_string_t vlan_type;
3197         cmdline_fixed_string_t what;
3198         cmdline_fixed_string_t on;
3199         cmdline_fixed_string_t port_id;
3200 };
3201
3202 static void
3203 cmd_vlan_offload_parsed(void *parsed_result,
3204                           __attribute__((unused)) struct cmdline *cl,
3205                           __attribute__((unused)) void *data)
3206 {
3207         int on;
3208         struct cmd_vlan_offload_result *res = parsed_result;
3209         char *str;
3210         int i, len = 0;
3211         portid_t port_id = 0;
3212         unsigned int tmp;
3213
3214         str = res->port_id;
3215         len = strnlen(str, STR_TOKEN_SIZE);
3216         i = 0;
3217         /* Get port_id first */
3218         while(i < len){
3219                 if(str[i] == ',')
3220                         break;
3221
3222                 i++;
3223         }
3224         str[i]='\0';
3225         tmp = strtoul(str, NULL, 0);
3226         /* If port_id greater that what portid_t can represent, return */
3227         if(tmp >= RTE_MAX_ETHPORTS)
3228                 return;
3229         port_id = (portid_t)tmp;
3230
3231         if (!strcmp(res->on, "on"))
3232                 on = 1;
3233         else
3234                 on = 0;
3235
3236         if (!strcmp(res->what, "strip"))
3237                 rx_vlan_strip_set(port_id,  on);
3238         else if(!strcmp(res->what, "stripq")){
3239                 uint16_t queue_id = 0;
3240
3241                 /* No queue_id, return */
3242                 if(i + 1 >= len) {
3243                         printf("must specify (port,queue_id)\n");
3244                         return;
3245                 }
3246                 tmp = strtoul(str + i + 1, NULL, 0);
3247                 /* If queue_id greater that what 16-bits can represent, return */
3248                 if(tmp > 0xffff)
3249                         return;
3250
3251                 queue_id = (uint16_t)tmp;
3252                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3253         }
3254         else if (!strcmp(res->what, "filter"))
3255                 rx_vlan_filter_set(port_id, on);
3256         else
3257                 vlan_extend_set(port_id, on);
3258
3259         return;
3260 }
3261
3262 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3263         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3264                                  vlan, "vlan");
3265 cmdline_parse_token_string_t cmd_vlan_offload_set =
3266         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3267                                  set, "set");
3268 cmdline_parse_token_string_t cmd_vlan_offload_what =
3269         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3270                                  what, "strip#filter#qinq#stripq");
3271 cmdline_parse_token_string_t cmd_vlan_offload_on =
3272         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3273                               on, "on#off");
3274 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3275         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3276                               port_id, NULL);
3277
3278 cmdline_parse_inst_t cmd_vlan_offload = {
3279         .f = cmd_vlan_offload_parsed,
3280         .data = NULL,
3281         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3282                 "<port_id[,queue_id]>: "
3283                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3284         .tokens = {
3285                 (void *)&cmd_vlan_offload_vlan,
3286                 (void *)&cmd_vlan_offload_set,
3287                 (void *)&cmd_vlan_offload_what,
3288                 (void *)&cmd_vlan_offload_on,
3289                 (void *)&cmd_vlan_offload_portid,
3290                 NULL,
3291         },
3292 };
3293
3294 /* *** VLAN TPID SET ON A PORT *** */
3295 struct cmd_vlan_tpid_result {
3296         cmdline_fixed_string_t vlan;
3297         cmdline_fixed_string_t set;
3298         cmdline_fixed_string_t vlan_type;
3299         cmdline_fixed_string_t what;
3300         uint16_t tp_id;
3301         portid_t port_id;
3302 };
3303
3304 static void
3305 cmd_vlan_tpid_parsed(void *parsed_result,
3306                           __attribute__((unused)) struct cmdline *cl,
3307                           __attribute__((unused)) void *data)
3308 {
3309         struct cmd_vlan_tpid_result *res = parsed_result;
3310         enum rte_vlan_type vlan_type;
3311
3312         if (!strcmp(res->vlan_type, "inner"))
3313                 vlan_type = ETH_VLAN_TYPE_INNER;
3314         else if (!strcmp(res->vlan_type, "outer"))
3315                 vlan_type = ETH_VLAN_TYPE_OUTER;
3316         else {
3317                 printf("Unknown vlan type\n");
3318                 return;
3319         }
3320         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3321 }
3322
3323 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3324         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3325                                  vlan, "vlan");
3326 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3327         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3328                                  set, "set");
3329 cmdline_parse_token_string_t cmd_vlan_type =
3330         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3331                                  vlan_type, "inner#outer");
3332 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3333         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3334                                  what, "tpid");
3335 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3336         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3337                               tp_id, UINT16);
3338 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3339         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3340                               port_id, UINT16);
3341
3342 cmdline_parse_inst_t cmd_vlan_tpid = {
3343         .f = cmd_vlan_tpid_parsed,
3344         .data = NULL,
3345         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3346                 "Set the VLAN Ether type",
3347         .tokens = {
3348                 (void *)&cmd_vlan_tpid_vlan,
3349                 (void *)&cmd_vlan_tpid_set,
3350                 (void *)&cmd_vlan_type,
3351                 (void *)&cmd_vlan_tpid_what,
3352                 (void *)&cmd_vlan_tpid_tpid,
3353                 (void *)&cmd_vlan_tpid_portid,
3354                 NULL,
3355         },
3356 };
3357
3358 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3359 struct cmd_rx_vlan_filter_result {
3360         cmdline_fixed_string_t rx_vlan;
3361         cmdline_fixed_string_t what;
3362         uint16_t vlan_id;
3363         portid_t port_id;
3364 };
3365
3366 static void
3367 cmd_rx_vlan_filter_parsed(void *parsed_result,
3368                           __attribute__((unused)) struct cmdline *cl,
3369                           __attribute__((unused)) void *data)
3370 {
3371         struct cmd_rx_vlan_filter_result *res = parsed_result;
3372
3373         if (!strcmp(res->what, "add"))
3374                 rx_vft_set(res->port_id, res->vlan_id, 1);
3375         else
3376                 rx_vft_set(res->port_id, res->vlan_id, 0);
3377 }
3378
3379 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3380         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3381                                  rx_vlan, "rx_vlan");
3382 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3383         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3384                                  what, "add#rm");
3385 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3386         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3387                               vlan_id, UINT16);
3388 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3389         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3390                               port_id, UINT16);
3391
3392 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3393         .f = cmd_rx_vlan_filter_parsed,
3394         .data = NULL,
3395         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3396                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3397                 "identifiers filtered by a port",
3398         .tokens = {
3399                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3400                 (void *)&cmd_rx_vlan_filter_what,
3401                 (void *)&cmd_rx_vlan_filter_vlanid,
3402                 (void *)&cmd_rx_vlan_filter_portid,
3403                 NULL,
3404         },
3405 };
3406
3407 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3408 struct cmd_tx_vlan_set_result {
3409         cmdline_fixed_string_t tx_vlan;
3410         cmdline_fixed_string_t set;
3411         portid_t port_id;
3412         uint16_t vlan_id;
3413 };
3414
3415 static void
3416 cmd_tx_vlan_set_parsed(void *parsed_result,
3417                        __attribute__((unused)) struct cmdline *cl,
3418                        __attribute__((unused)) void *data)
3419 {
3420         struct cmd_tx_vlan_set_result *res = parsed_result;
3421
3422         if (!port_is_stopped(res->port_id)) {
3423                 printf("Please stop port %d first\n", res->port_id);
3424                 return;
3425         }
3426
3427         tx_vlan_set(res->port_id, res->vlan_id);
3428
3429         cmd_reconfig_device_queue(res->port_id, 1, 1);
3430 }
3431
3432 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3433         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3434                                  tx_vlan, "tx_vlan");
3435 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3436         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3437                                  set, "set");
3438 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3439         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3440                               port_id, UINT16);
3441 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3442         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3443                               vlan_id, UINT16);
3444
3445 cmdline_parse_inst_t cmd_tx_vlan_set = {
3446         .f = cmd_tx_vlan_set_parsed,
3447         .data = NULL,
3448         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3449                 "Enable hardware insertion of a single VLAN header "
3450                 "with a given TAG Identifier in packets sent on a port",
3451         .tokens = {
3452                 (void *)&cmd_tx_vlan_set_tx_vlan,
3453                 (void *)&cmd_tx_vlan_set_set,
3454                 (void *)&cmd_tx_vlan_set_portid,
3455                 (void *)&cmd_tx_vlan_set_vlanid,
3456                 NULL,
3457         },
3458 };
3459
3460 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3461 struct cmd_tx_vlan_set_qinq_result {
3462         cmdline_fixed_string_t tx_vlan;
3463         cmdline_fixed_string_t set;
3464         portid_t port_id;
3465         uint16_t vlan_id;
3466         uint16_t vlan_id_outer;
3467 };
3468
3469 static void
3470 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3471                             __attribute__((unused)) struct cmdline *cl,
3472                             __attribute__((unused)) void *data)
3473 {
3474         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3475
3476         if (!port_is_stopped(res->port_id)) {
3477                 printf("Please stop port %d first\n", res->port_id);
3478                 return;
3479         }
3480
3481         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3482
3483         cmd_reconfig_device_queue(res->port_id, 1, 1);
3484 }
3485
3486 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3488                 tx_vlan, "tx_vlan");
3489 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3490         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3491                 set, "set");
3492 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3494                 port_id, UINT16);
3495 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3497                 vlan_id, UINT16);
3498 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3499         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3500                 vlan_id_outer, UINT16);
3501
3502 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3503         .f = cmd_tx_vlan_set_qinq_parsed,
3504         .data = NULL,
3505         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3506                 "Enable hardware insertion of double VLAN header "
3507                 "with given TAG Identifiers in packets sent on a port",
3508         .tokens = {
3509                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3510                 (void *)&cmd_tx_vlan_set_qinq_set,
3511                 (void *)&cmd_tx_vlan_set_qinq_portid,
3512                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3513                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3514                 NULL,
3515         },
3516 };
3517
3518 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3519 struct cmd_tx_vlan_set_pvid_result {
3520         cmdline_fixed_string_t tx_vlan;
3521         cmdline_fixed_string_t set;
3522         cmdline_fixed_string_t pvid;
3523         portid_t port_id;
3524         uint16_t vlan_id;
3525         cmdline_fixed_string_t mode;
3526 };
3527
3528 static void
3529 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3530                             __attribute__((unused)) struct cmdline *cl,
3531                             __attribute__((unused)) void *data)
3532 {
3533         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3534
3535         if (strcmp(res->mode, "on") == 0)
3536                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3537         else
3538                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3539 }
3540
3541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3543                                  tx_vlan, "tx_vlan");
3544 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3546                                  set, "set");
3547 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3548         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3549                                  pvid, "pvid");
3550 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3551         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3552                              port_id, UINT16);
3553 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3554         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3555                               vlan_id, UINT16);
3556 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3557         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3558                                  mode, "on#off");
3559
3560 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3561         .f = cmd_tx_vlan_set_pvid_parsed,
3562         .data = NULL,
3563         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3564         .tokens = {
3565                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3566                 (void *)&cmd_tx_vlan_set_pvid_set,
3567                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3568                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3569                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3570                 (void *)&cmd_tx_vlan_set_pvid_mode,
3571                 NULL,
3572         },
3573 };
3574
3575 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3576 struct cmd_tx_vlan_reset_result {
3577         cmdline_fixed_string_t tx_vlan;
3578         cmdline_fixed_string_t reset;
3579         portid_t port_id;
3580 };
3581
3582 static void
3583 cmd_tx_vlan_reset_parsed(void *parsed_result,
3584                          __attribute__((unused)) struct cmdline *cl,
3585                          __attribute__((unused)) void *data)
3586 {
3587         struct cmd_tx_vlan_reset_result *res = parsed_result;
3588
3589         if (!port_is_stopped(res->port_id)) {
3590                 printf("Please stop port %d first\n", res->port_id);
3591                 return;
3592         }
3593
3594         tx_vlan_reset(res->port_id);
3595
3596         cmd_reconfig_device_queue(res->port_id, 1, 1);
3597 }
3598
3599 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3600         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3601                                  tx_vlan, "tx_vlan");
3602 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3603         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3604                                  reset, "reset");
3605 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3606         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3607                               port_id, UINT16);
3608
3609 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3610         .f = cmd_tx_vlan_reset_parsed,
3611         .data = NULL,
3612         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3613                 "VLAN header in packets sent on a port",
3614         .tokens = {
3615                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3616                 (void *)&cmd_tx_vlan_reset_reset,
3617                 (void *)&cmd_tx_vlan_reset_portid,
3618                 NULL,
3619         },
3620 };
3621
3622
3623 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3624 struct cmd_csum_result {
3625         cmdline_fixed_string_t csum;
3626         cmdline_fixed_string_t mode;
3627         cmdline_fixed_string_t proto;
3628         cmdline_fixed_string_t hwsw;
3629         portid_t port_id;
3630 };
3631
3632 static void
3633 csum_show(int port_id)
3634 {
3635         struct rte_eth_dev_info dev_info;
3636         uint64_t tx_offloads;
3637
3638         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3639         printf("Parse tunnel is %s\n",
3640                 (ports[port_id].parse_tunnel) ? "on" : "off");
3641         printf("IP checksum offload is %s\n",
3642                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3643         printf("UDP checksum offload is %s\n",
3644                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3645         printf("TCP checksum offload is %s\n",
3646                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3647         printf("SCTP checksum offload is %s\n",
3648                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3649         printf("Outer-Ip checksum offload is %s\n",
3650                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3651
3652         /* display warnings if configuration is not supported by the NIC */
3653         rte_eth_dev_info_get(port_id, &dev_info);
3654         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3655                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3656                 printf("Warning: hardware IP checksum enabled but not "
3657                         "supported by port %d\n", port_id);
3658         }
3659         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3660                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3661                 printf("Warning: hardware UDP checksum enabled but not "
3662                         "supported by port %d\n", port_id);
3663         }
3664         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3665                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3666                 printf("Warning: hardware TCP checksum enabled but not "
3667                         "supported by port %d\n", port_id);
3668         }
3669         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3670                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3671                 printf("Warning: hardware SCTP checksum enabled but not "
3672                         "supported by port %d\n", port_id);
3673         }
3674         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3675                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3676                 printf("Warning: hardware outer IP checksum enabled but not "
3677                         "supported by port %d\n", port_id);
3678         }
3679 }
3680
3681 static void
3682 cmd_csum_parsed(void *parsed_result,
3683                        __attribute__((unused)) struct cmdline *cl,
3684                        __attribute__((unused)) void *data)
3685 {
3686         struct cmd_csum_result *res = parsed_result;
3687         int hw = 0;
3688         uint64_t csum_offloads = 0;
3689         struct rte_eth_dev_info dev_info;
3690
3691         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3692                 printf("invalid port %d\n", res->port_id);
3693                 return;
3694         }
3695         if (!port_is_stopped(res->port_id)) {
3696                 printf("Please stop port %d first\n", res->port_id);
3697                 return;
3698         }
3699
3700         rte_eth_dev_info_get(res->port_id, &dev_info);
3701         if (!strcmp(res->mode, "set")) {
3702
3703                 if (!strcmp(res->hwsw, "hw"))
3704                         hw = 1;
3705
3706                 if (!strcmp(res->proto, "ip")) {
3707                         if (dev_info.tx_offload_capa &
3708                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3709                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3710                         } else {
3711                                 printf("IP checksum offload is not supported "
3712                                        "by port %u\n", res->port_id);
3713                         }
3714                 } else if (!strcmp(res->proto, "udp")) {
3715                         if (dev_info.tx_offload_capa &
3716                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3717                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3718                         } else {
3719                                 printf("UDP checksum offload is not supported "
3720                                        "by port %u\n", res->port_id);
3721                         }
3722                 } else if (!strcmp(res->proto, "tcp")) {
3723                         if (dev_info.tx_offload_capa &
3724                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3725                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3726                         } else {
3727                                 printf("TCP checksum offload is not supported "
3728                                        "by port %u\n", res->port_id);
3729                         }
3730                 } else if (!strcmp(res->proto, "sctp")) {
3731                         if (dev_info.tx_offload_capa &
3732                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3733                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3734                         } else {
3735                                 printf("SCTP checksum offload is not supported "
3736                                        "by port %u\n", res->port_id);
3737                         }
3738                 } else if (!strcmp(res->proto, "outer-ip")) {
3739                         if (dev_info.tx_offload_capa &
3740                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3741                                 csum_offloads |=
3742                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3743                         } else {
3744                                 printf("Outer IP checksum offload is not "
3745                                        "supported by port %u\n", res->port_id);
3746                         }
3747                 }
3748
3749                 if (hw) {
3750                         ports[res->port_id].dev_conf.txmode.offloads |=
3751                                                         csum_offloads;
3752                 } else {
3753                         ports[res->port_id].dev_conf.txmode.offloads &=
3754                                                         (~csum_offloads);
3755                 }
3756         }
3757         csum_show(res->port_id);
3758
3759         cmd_reconfig_device_queue(res->port_id, 1, 1);
3760 }
3761
3762 cmdline_parse_token_string_t cmd_csum_csum =
3763         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3764                                 csum, "csum");
3765 cmdline_parse_token_string_t cmd_csum_mode =
3766         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3767                                 mode, "set");
3768 cmdline_parse_token_string_t cmd_csum_proto =
3769         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3770                                 proto, "ip#tcp#udp#sctp#outer-ip");
3771 cmdline_parse_token_string_t cmd_csum_hwsw =
3772         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3773                                 hwsw, "hw#sw");
3774 cmdline_parse_token_num_t cmd_csum_portid =
3775         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3776                                 port_id, UINT16);
3777
3778 cmdline_parse_inst_t cmd_csum_set = {
3779         .f = cmd_csum_parsed,
3780         .data = NULL,
3781         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3782                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3783                 "using csum forward engine",
3784         .tokens = {
3785                 (void *)&cmd_csum_csum,
3786                 (void *)&cmd_csum_mode,
3787                 (void *)&cmd_csum_proto,
3788                 (void *)&cmd_csum_hwsw,
3789                 (void *)&cmd_csum_portid,
3790                 NULL,
3791         },
3792 };
3793
3794 cmdline_parse_token_string_t cmd_csum_mode_show =
3795         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3796                                 mode, "show");
3797
3798 cmdline_parse_inst_t cmd_csum_show = {
3799         .f = cmd_csum_parsed,
3800         .data = NULL,
3801         .help_str = "csum show <port_id>: Show checksum offload configuration",
3802         .tokens = {
3803                 (void *)&cmd_csum_csum,
3804                 (void *)&cmd_csum_mode_show,
3805                 (void *)&cmd_csum_portid,
3806                 NULL,
3807         },
3808 };
3809
3810 /* Enable/disable tunnel parsing */
3811 struct cmd_csum_tunnel_result {
3812         cmdline_fixed_string_t csum;
3813         cmdline_fixed_string_t parse;
3814         cmdline_fixed_string_t onoff;
3815         portid_t port_id;
3816 };
3817
3818 static void
3819 cmd_csum_tunnel_parsed(void *parsed_result,
3820                        __attribute__((unused)) struct cmdline *cl,
3821                        __attribute__((unused)) void *data)
3822 {
3823         struct cmd_csum_tunnel_result *res = parsed_result;
3824
3825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3826                 return;
3827
3828         if (!strcmp(res->onoff, "on"))
3829                 ports[res->port_id].parse_tunnel = 1;
3830         else
3831                 ports[res->port_id].parse_tunnel = 0;
3832
3833         csum_show(res->port_id);
3834 }
3835
3836 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3837         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3838                                 csum, "csum");
3839 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3840         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3841                                 parse, "parse_tunnel");
3842 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3843         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3844                                 onoff, "on#off");
3845 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3846         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3847                                 port_id, UINT16);
3848
3849 cmdline_parse_inst_t cmd_csum_tunnel = {
3850         .f = cmd_csum_tunnel_parsed,
3851         .data = NULL,
3852         .help_str = "csum parse_tunnel on|off <port_id>: "
3853                 "Enable/Disable parsing of tunnels for csum engine",
3854         .tokens = {
3855                 (void *)&cmd_csum_tunnel_csum,
3856                 (void *)&cmd_csum_tunnel_parse,
3857                 (void *)&cmd_csum_tunnel_onoff,
3858                 (void *)&cmd_csum_tunnel_portid,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3864 struct cmd_tso_set_result {
3865         cmdline_fixed_string_t tso;
3866         cmdline_fixed_string_t mode;
3867         uint16_t tso_segsz;
3868         portid_t port_id;
3869 };
3870
3871 static void
3872 cmd_tso_set_parsed(void *parsed_result,
3873                        __attribute__((unused)) struct cmdline *cl,
3874                        __attribute__((unused)) void *data)
3875 {
3876         struct cmd_tso_set_result *res = parsed_result;
3877         struct rte_eth_dev_info dev_info;
3878
3879         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3880                 return;
3881         if (!port_is_stopped(res->port_id)) {
3882                 printf("Please stop port %d first\n", res->port_id);
3883                 return;
3884         }
3885
3886         if (!strcmp(res->mode, "set"))
3887                 ports[res->port_id].tso_segsz = res->tso_segsz;
3888
3889         rte_eth_dev_info_get(res->port_id, &dev_info);
3890         if ((ports[res->port_id].tso_segsz != 0) &&
3891                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3892                 printf("Error: TSO is not supported by port %d\n",
3893                        res->port_id);
3894                 return;
3895         }
3896
3897         if (ports[res->port_id].tso_segsz == 0) {
3898                 ports[res->port_id].dev_conf.txmode.offloads &=
3899                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3900                 printf("TSO for non-tunneled packets is disabled\n");
3901         } else {
3902                 ports[res->port_id].dev_conf.txmode.offloads |=
3903                                                 DEV_TX_OFFLOAD_TCP_TSO;
3904                 printf("TSO segment size for non-tunneled packets is %d\n",
3905                         ports[res->port_id].tso_segsz);
3906         }
3907
3908         /* display warnings if configuration is not supported by the NIC */
3909         rte_eth_dev_info_get(res->port_id, &dev_info);
3910         if ((ports[res->port_id].tso_segsz != 0) &&
3911                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3912                 printf("Warning: TSO enabled but not "
3913                         "supported by port %d\n", res->port_id);
3914         }
3915
3916         cmd_reconfig_device_queue(res->port_id, 1, 1);
3917 }
3918
3919 cmdline_parse_token_string_t cmd_tso_set_tso =
3920         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3921                                 tso, "tso");
3922 cmdline_parse_token_string_t cmd_tso_set_mode =
3923         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3924                                 mode, "set");
3925 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3926         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3927                                 tso_segsz, UINT16);
3928 cmdline_parse_token_num_t cmd_tso_set_portid =
3929         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3930                                 port_id, UINT16);
3931
3932 cmdline_parse_inst_t cmd_tso_set = {
3933         .f = cmd_tso_set_parsed,
3934         .data = NULL,
3935         .help_str = "tso set <tso_segsz> <port_id>: "
3936                 "Set TSO segment size of non-tunneled packets for csum engine "
3937                 "(0 to disable)",
3938         .tokens = {
3939                 (void *)&cmd_tso_set_tso,
3940                 (void *)&cmd_tso_set_mode,
3941                 (void *)&cmd_tso_set_tso_segsz,
3942                 (void *)&cmd_tso_set_portid,
3943                 NULL,
3944         },
3945 };
3946
3947 cmdline_parse_token_string_t cmd_tso_show_mode =
3948         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3949                                 mode, "show");
3950
3951
3952 cmdline_parse_inst_t cmd_tso_show = {
3953         .f = cmd_tso_set_parsed,
3954         .data = NULL,
3955         .help_str = "tso show <port_id>: "
3956                 "Show TSO segment size of non-tunneled packets for csum engine",
3957         .tokens = {
3958                 (void *)&cmd_tso_set_tso,
3959                 (void *)&cmd_tso_show_mode,
3960                 (void *)&cmd_tso_set_portid,
3961                 NULL,
3962         },
3963 };
3964
3965 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3966 struct cmd_tunnel_tso_set_result {
3967         cmdline_fixed_string_t tso;
3968         cmdline_fixed_string_t mode;
3969         uint16_t tso_segsz;
3970         portid_t port_id;
3971 };
3972
3973 static struct rte_eth_dev_info
3974 check_tunnel_tso_nic_support(portid_t port_id)
3975 {
3976         struct rte_eth_dev_info dev_info;
3977
3978         rte_eth_dev_info_get(port_id, &dev_info);
3979         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3980                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3981                        "not enabled for port %d\n", port_id);
3982         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3983                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3984                        "not enabled for port %d\n", port_id);
3985         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3986                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3987                        "not enabled for port %d\n", port_id);
3988         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3989                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3990                        "not enabled for port %d\n", port_id);
3991         return dev_info;
3992 }
3993
3994 static void
3995 cmd_tunnel_tso_set_parsed(void *parsed_result,
3996                           __attribute__((unused)) struct cmdline *cl,
3997                           __attribute__((unused)) void *data)
3998 {
3999         struct cmd_tunnel_tso_set_result *res = parsed_result;
4000         struct rte_eth_dev_info dev_info;
4001
4002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4003                 return;
4004         if (!port_is_stopped(res->port_id)) {
4005                 printf("Please stop port %d first\n", res->port_id);
4006                 return;
4007         }
4008
4009         if (!strcmp(res->mode, "set"))
4010                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4011
4012         dev_info = check_tunnel_tso_nic_support(res->port_id);
4013         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4014                 ports[res->port_id].dev_conf.txmode.offloads &=
4015                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4016                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4017                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4018                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4019                 printf("TSO for tunneled packets is disabled\n");
4020         } else {
4021                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4022                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4023                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4024                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4025
4026                 ports[res->port_id].dev_conf.txmode.offloads |=
4027                         (tso_offloads & dev_info.tx_offload_capa);
4028                 printf("TSO segment size for tunneled packets is %d\n",
4029                         ports[res->port_id].tunnel_tso_segsz);
4030
4031                 /* Below conditions are needed to make it work:
4032                  * (1) tunnel TSO is supported by the NIC;
4033                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4034                  * are recognized;
4035                  * (3) for tunneled pkts with outer L3 of IPv4,
4036                  * "csum set outer-ip" must be set to hw, because after tso,
4037                  * total_len of outer IP header is changed, and the checksum
4038                  * of outer IP header calculated by sw should be wrong; that
4039                  * is not necessary for IPv6 tunneled pkts because there's no
4040                  * checksum in IP header anymore.
4041                  */
4042
4043                 if (!ports[res->port_id].parse_tunnel)
4044                         printf("Warning: csum parse_tunnel must be set "
4045                                 "so that tunneled packets are recognized\n");
4046                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4047                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4048                         printf("Warning: csum set outer-ip must be set to hw "
4049                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4050         }
4051
4052         cmd_reconfig_device_queue(res->port_id, 1, 1);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4056         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4057                                 tso, "tunnel_tso");
4058 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4059         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4060                                 mode, "set");
4061 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4062         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4063                                 tso_segsz, UINT16);
4064 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4066                                 port_id, UINT16);
4067
4068 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4069         .f = cmd_tunnel_tso_set_parsed,
4070         .data = NULL,
4071         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4072                 "Set TSO segment size of tunneled packets for csum engine "
4073                 "(0 to disable)",
4074         .tokens = {
4075                 (void *)&cmd_tunnel_tso_set_tso,
4076                 (void *)&cmd_tunnel_tso_set_mode,
4077                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4078                 (void *)&cmd_tunnel_tso_set_portid,
4079                 NULL,
4080         },
4081 };
4082
4083 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4084         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4085                                 mode, "show");
4086
4087
4088 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4089         .f = cmd_tunnel_tso_set_parsed,
4090         .data = NULL,
4091         .help_str = "tunnel_tso show <port_id> "
4092                 "Show TSO segment size of tunneled packets for csum engine",
4093         .tokens = {
4094                 (void *)&cmd_tunnel_tso_set_tso,
4095                 (void *)&cmd_tunnel_tso_show_mode,
4096                 (void *)&cmd_tunnel_tso_set_portid,
4097                 NULL,
4098         },
4099 };
4100
4101 /* *** SET GRO FOR A PORT *** */
4102 struct cmd_gro_enable_result {
4103         cmdline_fixed_string_t cmd_set;
4104         cmdline_fixed_string_t cmd_port;
4105         cmdline_fixed_string_t cmd_keyword;
4106         cmdline_fixed_string_t cmd_onoff;
4107         portid_t cmd_pid;
4108 };
4109
4110 static void
4111 cmd_gro_enable_parsed(void *parsed_result,
4112                 __attribute__((unused)) struct cmdline *cl,
4113                 __attribute__((unused)) void *data)
4114 {
4115         struct cmd_gro_enable_result *res;
4116
4117         res = parsed_result;
4118         if (!strcmp(res->cmd_keyword, "gro"))
4119                 setup_gro(res->cmd_onoff, res->cmd_pid);
4120 }
4121
4122 cmdline_parse_token_string_t cmd_gro_enable_set =
4123         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4124                         cmd_set, "set");
4125 cmdline_parse_token_string_t cmd_gro_enable_port =
4126         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4127                         cmd_keyword, "port");
4128 cmdline_parse_token_num_t cmd_gro_enable_pid =
4129         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4130                         cmd_pid, UINT16);
4131 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4132         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4133                         cmd_keyword, "gro");
4134 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4135         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4136                         cmd_onoff, "on#off");
4137
4138 cmdline_parse_inst_t cmd_gro_enable = {
4139         .f = cmd_gro_enable_parsed,
4140         .data = NULL,
4141         .help_str = "set port <port_id> gro on|off",
4142         .tokens = {
4143                 (void *)&cmd_gro_enable_set,
4144                 (void *)&cmd_gro_enable_port,
4145                 (void *)&cmd_gro_enable_pid,
4146                 (void *)&cmd_gro_enable_keyword,
4147                 (void *)&cmd_gro_enable_onoff,
4148                 NULL,
4149         },
4150 };
4151
4152 /* *** DISPLAY GRO CONFIGURATION *** */
4153 struct cmd_gro_show_result {
4154         cmdline_fixed_string_t cmd_show;
4155         cmdline_fixed_string_t cmd_port;
4156         cmdline_fixed_string_t cmd_keyword;
4157         portid_t cmd_pid;
4158 };
4159
4160 static void
4161 cmd_gro_show_parsed(void *parsed_result,
4162                 __attribute__((unused)) struct cmdline *cl,
4163                 __attribute__((unused)) void *data)
4164 {
4165         struct cmd_gro_show_result *res;
4166
4167         res = parsed_result;
4168         if (!strcmp(res->cmd_keyword, "gro"))
4169                 show_gro(res->cmd_pid);
4170 }
4171
4172 cmdline_parse_token_string_t cmd_gro_show_show =
4173         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4174                         cmd_show, "show");
4175 cmdline_parse_token_string_t cmd_gro_show_port =
4176         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4177                         cmd_port, "port");
4178 cmdline_parse_token_num_t cmd_gro_show_pid =
4179         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4180                         cmd_pid, UINT16);
4181 cmdline_parse_token_string_t cmd_gro_show_keyword =
4182         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4183                         cmd_keyword, "gro");
4184
4185 cmdline_parse_inst_t cmd_gro_show = {
4186         .f = cmd_gro_show_parsed,
4187         .data = NULL,
4188         .help_str = "show port <port_id> gro",
4189         .tokens = {
4190                 (void *)&cmd_gro_show_show,
4191                 (void *)&cmd_gro_show_port,
4192                 (void *)&cmd_gro_show_pid,
4193                 (void *)&cmd_gro_show_keyword,
4194                 NULL,
4195         },
4196 };
4197
4198 /* *** SET FLUSH CYCLES FOR GRO *** */
4199 struct cmd_gro_flush_result {
4200         cmdline_fixed_string_t cmd_set;
4201         cmdline_fixed_string_t cmd_keyword;
4202         cmdline_fixed_string_t cmd_flush;
4203         uint8_t cmd_cycles;
4204 };
4205
4206 static void
4207 cmd_gro_flush_parsed(void *parsed_result,
4208                 __attribute__((unused)) struct cmdline *cl,
4209                 __attribute__((unused)) void *data)
4210 {
4211         struct cmd_gro_flush_result *res;
4212
4213         res = parsed_result;
4214         if ((!strcmp(res->cmd_keyword, "gro")) &&
4215                         (!strcmp(res->cmd_flush, "flush")))
4216                 setup_gro_flush_cycles(res->cmd_cycles);
4217 }
4218
4219 cmdline_parse_token_string_t cmd_gro_flush_set =
4220         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4221                         cmd_set, "set");
4222 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4223         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4224                         cmd_keyword, "gro");
4225 cmdline_parse_token_string_t cmd_gro_flush_flush =
4226         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4227                         cmd_flush, "flush");
4228 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4229         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4230                         cmd_cycles, UINT8);
4231
4232 cmdline_parse_inst_t cmd_gro_flush = {
4233         .f = cmd_gro_flush_parsed,
4234         .data = NULL,
4235         .help_str = "set gro flush <cycles>",
4236         .tokens = {
4237                 (void *)&cmd_gro_flush_set,
4238                 (void *)&cmd_gro_flush_keyword,
4239                 (void *)&cmd_gro_flush_flush,
4240                 (void *)&cmd_gro_flush_cycles,
4241                 NULL,
4242         },
4243 };
4244
4245 /* *** ENABLE/DISABLE GSO *** */
4246 struct cmd_gso_enable_result {
4247         cmdline_fixed_string_t cmd_set;
4248         cmdline_fixed_string_t cmd_port;
4249         cmdline_fixed_string_t cmd_keyword;
4250         cmdline_fixed_string_t cmd_mode;
4251         portid_t cmd_pid;
4252 };
4253
4254 static void
4255 cmd_gso_enable_parsed(void *parsed_result,
4256                 __attribute__((unused)) struct cmdline *cl,
4257                 __attribute__((unused)) void *data)
4258 {
4259         struct cmd_gso_enable_result *res;
4260
4261         res = parsed_result;
4262         if (!strcmp(res->cmd_keyword, "gso"))
4263                 setup_gso(res->cmd_mode, res->cmd_pid);
4264 }
4265
4266 cmdline_parse_token_string_t cmd_gso_enable_set =
4267         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4268                         cmd_set, "set");
4269 cmdline_parse_token_string_t cmd_gso_enable_port =
4270         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4271                         cmd_port, "port");
4272 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4273         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4274                         cmd_keyword, "gso");
4275 cmdline_parse_token_string_t cmd_gso_enable_mode =
4276         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4277                         cmd_mode, "on#off");
4278 cmdline_parse_token_num_t cmd_gso_enable_pid =
4279         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4280                         cmd_pid, UINT16);
4281
4282 cmdline_parse_inst_t cmd_gso_enable = {
4283         .f = cmd_gso_enable_parsed,
4284         .data = NULL,
4285         .help_str = "set port <port_id> gso on|off",
4286         .tokens = {
4287                 (void *)&cmd_gso_enable_set,
4288                 (void *)&cmd_gso_enable_port,
4289                 (void *)&cmd_gso_enable_pid,
4290                 (void *)&cmd_gso_enable_keyword,
4291                 (void *)&cmd_gso_enable_mode,
4292                 NULL,
4293         },
4294 };
4295
4296 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4297 struct cmd_gso_size_result {
4298         cmdline_fixed_string_t cmd_set;
4299         cmdline_fixed_string_t cmd_keyword;
4300         cmdline_fixed_string_t cmd_segsz;
4301         uint16_t cmd_size;
4302 };
4303
4304 static void
4305 cmd_gso_size_parsed(void *parsed_result,
4306                        __attribute__((unused)) struct cmdline *cl,
4307                        __attribute__((unused)) void *data)
4308 {
4309         struct cmd_gso_size_result *res = parsed_result;
4310
4311         if (test_done == 0) {
4312                 printf("Before setting GSO segsz, please first"
4313                                 " stop fowarding\n");
4314                 return;
4315         }
4316
4317         if (!strcmp(res->cmd_keyword, "gso") &&
4318                         !strcmp(res->cmd_segsz, "segsz")) {
4319                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4320                         printf("gso_size should be larger than %zu."
4321                                         " Please input a legal value\n",
4322                                         RTE_GSO_SEG_SIZE_MIN);
4323                 else
4324                         gso_max_segment_size = res->cmd_size;
4325         }
4326 }
4327
4328 cmdline_parse_token_string_t cmd_gso_size_set =
4329         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4330                                 cmd_set, "set");
4331 cmdline_parse_token_string_t cmd_gso_size_keyword =
4332         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4333                                 cmd_keyword, "gso");
4334 cmdline_parse_token_string_t cmd_gso_size_segsz =
4335         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4336                                 cmd_segsz, "segsz");
4337 cmdline_parse_token_num_t cmd_gso_size_size =
4338         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4339                                 cmd_size, UINT16);
4340
4341 cmdline_parse_inst_t cmd_gso_size = {
4342         .f = cmd_gso_size_parsed,
4343         .data = NULL,
4344         .help_str = "set gso segsz <length>",
4345         .tokens = {
4346                 (void *)&cmd_gso_size_set,
4347                 (void *)&cmd_gso_size_keyword,
4348                 (void *)&cmd_gso_size_segsz,
4349                 (void *)&cmd_gso_size_size,
4350                 NULL,
4351         },
4352 };
4353
4354 /* *** SHOW GSO CONFIGURATION *** */
4355 struct cmd_gso_show_result {
4356         cmdline_fixed_string_t cmd_show;
4357         cmdline_fixed_string_t cmd_port;
4358         cmdline_fixed_string_t cmd_keyword;
4359         portid_t cmd_pid;
4360 };
4361
4362 static void
4363 cmd_gso_show_parsed(void *parsed_result,
4364                        __attribute__((unused)) struct cmdline *cl,
4365                        __attribute__((unused)) void *data)
4366 {
4367         struct cmd_gso_show_result *res = parsed_result;
4368
4369         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4370                 printf("invalid port id %u\n", res->cmd_pid);
4371                 return;
4372         }
4373         if (!strcmp(res->cmd_keyword, "gso")) {
4374                 if (gso_ports[res->cmd_pid].enable) {
4375                         printf("Max GSO'd packet size: %uB\n"
4376                                         "Supported GSO types: TCP/IPv4, "
4377                                         "VxLAN with inner TCP/IPv4 packet, "
4378                                         "GRE with inner TCP/IPv4  packet\n",
4379                                         gso_max_segment_size);
4380                 } else
4381                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4382         }
4383 }
4384
4385 cmdline_parse_token_string_t cmd_gso_show_show =
4386 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4387                 cmd_show, "show");
4388 cmdline_parse_token_string_t cmd_gso_show_port =
4389 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4390                 cmd_port, "port");
4391 cmdline_parse_token_string_t cmd_gso_show_keyword =
4392         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4393                                 cmd_keyword, "gso");
4394 cmdline_parse_token_num_t cmd_gso_show_pid =
4395         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4396                                 cmd_pid, UINT16);
4397
4398 cmdline_parse_inst_t cmd_gso_show = {
4399         .f = cmd_gso_show_parsed,
4400         .data = NULL,
4401         .help_str = "show port <port_id> gso",
4402         .tokens = {
4403                 (void *)&cmd_gso_show_show,
4404                 (void *)&cmd_gso_show_port,
4405                 (void *)&cmd_gso_show_pid,
4406                 (void *)&cmd_gso_show_keyword,
4407                 NULL,
4408         },
4409 };
4410
4411 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4412 struct cmd_set_flush_rx {
4413         cmdline_fixed_string_t set;
4414         cmdline_fixed_string_t flush_rx;
4415         cmdline_fixed_string_t mode;
4416 };
4417
4418 static void
4419 cmd_set_flush_rx_parsed(void *parsed_result,
4420                 __attribute__((unused)) struct cmdline *cl,
4421                 __attribute__((unused)) void *data)
4422 {
4423         struct cmd_set_flush_rx *res = parsed_result;
4424         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4425 }
4426
4427 cmdline_parse_token_string_t cmd_setflushrx_set =
4428         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4429                         set, "set");
4430 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4431         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4432                         flush_rx, "flush_rx");
4433 cmdline_parse_token_string_t cmd_setflushrx_mode =
4434         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4435                         mode, "on#off");
4436
4437
4438 cmdline_parse_inst_t cmd_set_flush_rx = {
4439         .f = cmd_set_flush_rx_parsed,
4440         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4441         .data = NULL,
4442         .tokens = {
4443                 (void *)&cmd_setflushrx_set,
4444                 (void *)&cmd_setflushrx_flush_rx,
4445                 (void *)&cmd_setflushrx_mode,
4446                 NULL,
4447         },
4448 };
4449
4450 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4451 struct cmd_set_link_check {
4452         cmdline_fixed_string_t set;
4453         cmdline_fixed_string_t link_check;
4454         cmdline_fixed_string_t mode;
4455 };
4456
4457 static void
4458 cmd_set_link_check_parsed(void *parsed_result,
4459                 __attribute__((unused)) struct cmdline *cl,
4460                 __attribute__((unused)) void *data)
4461 {
4462         struct cmd_set_link_check *res = parsed_result;
4463         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4464 }
4465
4466 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4467         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4468                         set, "set");
4469 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4470         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4471                         link_check, "link_check");
4472 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4473         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4474                         mode, "on#off");
4475
4476
4477 cmdline_parse_inst_t cmd_set_link_check = {
4478         .f = cmd_set_link_check_parsed,
4479         .help_str = "set link_check on|off: Enable/Disable link status check "
4480                     "when starting/stopping a port",
4481         .data = NULL,
4482         .tokens = {
4483                 (void *)&cmd_setlinkcheck_set,
4484                 (void *)&cmd_setlinkcheck_link_check,
4485                 (void *)&cmd_setlinkcheck_mode,
4486                 NULL,
4487         },
4488 };
4489
4490 /* *** SET NIC BYPASS MODE *** */
4491 struct cmd_set_bypass_mode_result {
4492         cmdline_fixed_string_t set;
4493         cmdline_fixed_string_t bypass;
4494         cmdline_fixed_string_t mode;
4495         cmdline_fixed_string_t value;
4496         portid_t port_id;
4497 };
4498
4499 static void
4500 cmd_set_bypass_mode_parsed(void *parsed_result,
4501                 __attribute__((unused)) struct cmdline *cl,
4502                 __attribute__((unused)) void *data)
4503 {
4504         struct cmd_set_bypass_mode_result *res = parsed_result;
4505         portid_t port_id = res->port_id;
4506         int32_t rc = -EINVAL;
4507
4508 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4509         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4510
4511         if (!strcmp(res->value, "bypass"))
4512                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4513         else if (!strcmp(res->value, "isolate"))
4514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4515         else
4516                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4517
4518         /* Set the bypass mode for the relevant port. */
4519         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4520 #endif
4521         if (rc != 0)
4522                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4523 }
4524
4525 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4526         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4527                         set, "set");
4528 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4529         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4530                         bypass, "bypass");
4531 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4532         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4533                         mode, "mode");
4534 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4535         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4536                         value, "normal#bypass#isolate");
4537 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4538         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4539                                 port_id, UINT16);
4540
4541 cmdline_parse_inst_t cmd_set_bypass_mode = {
4542         .f = cmd_set_bypass_mode_parsed,
4543         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4544                     "Set the NIC bypass mode for port_id",
4545         .data = NULL,
4546         .tokens = {
4547                 (void *)&cmd_setbypass_mode_set,
4548                 (void *)&cmd_setbypass_mode_bypass,
4549                 (void *)&cmd_setbypass_mode_mode,
4550                 (void *)&cmd_setbypass_mode_value,
4551                 (void *)&cmd_setbypass_mode_port,
4552                 NULL,
4553         },
4554 };
4555
4556 /* *** SET NIC BYPASS EVENT *** */
4557 struct cmd_set_bypass_event_result {
4558         cmdline_fixed_string_t set;
4559         cmdline_fixed_string_t bypass;
4560         cmdline_fixed_string_t event;
4561         cmdline_fixed_string_t event_value;
4562         cmdline_fixed_string_t mode;
4563         cmdline_fixed_string_t mode_value;
4564         portid_t port_id;
4565 };
4566
4567 static void
4568 cmd_set_bypass_event_parsed(void *parsed_result,
4569                 __attribute__((unused)) struct cmdline *cl,
4570                 __attribute__((unused)) void *data)
4571 {
4572         int32_t rc = -EINVAL;
4573         struct cmd_set_bypass_event_result *res = parsed_result;
4574         portid_t port_id = res->port_id;
4575
4576 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4577         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4578         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4579
4580         if (!strcmp(res->event_value, "timeout"))
4581                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4582         else if (!strcmp(res->event_value, "os_on"))
4583                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4584         else if (!strcmp(res->event_value, "os_off"))
4585                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4586         else if (!strcmp(res->event_value, "power_on"))
4587                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4588         else if (!strcmp(res->event_value, "power_off"))
4589                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4590         else
4591                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4592
4593         if (!strcmp(res->mode_value, "bypass"))
4594                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4595         else if (!strcmp(res->mode_value, "isolate"))
4596                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4597         else
4598                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4599
4600         /* Set the watchdog timeout. */
4601         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4602
4603                 rc = -EINVAL;
4604                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4605                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4606                                                            bypass_timeout);
4607                 }
4608                 if (rc != 0) {
4609                         printf("Failed to set timeout value %u "
4610                         "for port %d, errto code: %d.\n",
4611                         bypass_timeout, port_id, rc);
4612                 }
4613         }
4614
4615         /* Set the bypass event to transition to bypass mode. */
4616         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4617                                               bypass_mode);
4618 #endif
4619
4620         if (rc != 0)
4621                 printf("\t Failed to set bypass event for port = %d.\n",
4622                        port_id);
4623 }
4624
4625 cmdline_parse_token_string_t cmd_setbypass_event_set =
4626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4627                         set, "set");
4628 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4630                         bypass, "bypass");
4631 cmdline_parse_token_string_t cmd_setbypass_event_event =
4632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4633                         event, "event");
4634 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4636                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4637 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4639                         mode, "mode");
4640 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4642                         mode_value, "normal#bypass#isolate");
4643 cmdline_parse_token_num_t cmd_setbypass_event_port =
4644         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4645                                 port_id, UINT16);
4646
4647 cmdline_parse_inst_t cmd_set_bypass_event = {
4648         .f = cmd_set_bypass_event_parsed,
4649         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4650                 "power_off mode normal|bypass|isolate <port_id>: "
4651                 "Set the NIC bypass event mode for port_id",
4652         .data = NULL,
4653         .tokens = {
4654                 (void *)&cmd_setbypass_event_set,
4655                 (void *)&cmd_setbypass_event_bypass,
4656                 (void *)&cmd_setbypass_event_event,
4657                 (void *)&cmd_setbypass_event_event_value,
4658                 (void *)&cmd_setbypass_event_mode,
4659                 (void *)&cmd_setbypass_event_mode_value,
4660                 (void *)&cmd_setbypass_event_port,
4661                 NULL,
4662         },
4663 };
4664
4665
4666 /* *** SET NIC BYPASS TIMEOUT *** */
4667 struct cmd_set_bypass_timeout_result {
4668         cmdline_fixed_string_t set;
4669         cmdline_fixed_string_t bypass;
4670         cmdline_fixed_string_t timeout;
4671         cmdline_fixed_string_t value;
4672 };
4673
4674 static void
4675 cmd_set_bypass_timeout_parsed(void *parsed_result,
4676                 __attribute__((unused)) struct cmdline *cl,
4677                 __attribute__((unused)) void *data)
4678 {
4679         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4680
4681 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4682         if (!strcmp(res->value, "1.5"))
4683                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4684         else if (!strcmp(res->value, "2"))
4685                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4686         else if (!strcmp(res->value, "3"))
4687                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4688         else if (!strcmp(res->value, "4"))
4689                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4690         else if (!strcmp(res->value, "8"))
4691                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4692         else if (!strcmp(res->value, "16"))
4693                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4694         else if (!strcmp(res->value, "32"))
4695                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4696         else
4697                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4698 #endif
4699 }
4700
4701 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4702         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4703                         set, "set");
4704 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4706                         bypass, "bypass");
4707 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4708         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4709                         timeout, "timeout");
4710 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4711         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4712                         value, "0#1.5#2#3#4#8#16#32");
4713
4714 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4715         .f = cmd_set_bypass_timeout_parsed,
4716         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4717                 "Set the NIC bypass watchdog timeout in seconds",
4718         .data = NULL,
4719         .tokens = {
4720                 (void *)&cmd_setbypass_timeout_set,
4721                 (void *)&cmd_setbypass_timeout_bypass,
4722                 (void *)&cmd_setbypass_timeout_timeout,
4723                 (void *)&cmd_setbypass_timeout_value,
4724                 NULL,
4725         },
4726 };
4727
4728 /* *** SHOW NIC BYPASS MODE *** */
4729 struct cmd_show_bypass_config_result {
4730         cmdline_fixed_string_t show;
4731         cmdline_fixed_string_t bypass;
4732         cmdline_fixed_string_t config;
4733         portid_t port_id;
4734 };
4735
4736 static void
4737 cmd_show_bypass_config_parsed(void *parsed_result,
4738                 __attribute__((unused)) struct cmdline *cl,
4739                 __attribute__((unused)) void *data)
4740 {
4741         struct cmd_show_bypass_config_result *res = parsed_result;
4742         portid_t port_id = res->port_id;
4743         int rc = -EINVAL;
4744 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4745         uint32_t event_mode;
4746         uint32_t bypass_mode;
4747         uint32_t timeout = bypass_timeout;
4748         int i;
4749
4750         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4751                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4752         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4753                 {"UNKNOWN", "normal", "bypass", "isolate"};
4754         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4755                 "NONE",
4756                 "OS/board on",
4757                 "power supply on",
4758                 "OS/board off",
4759                 "power supply off",
4760                 "timeout"};
4761         int num_events = (sizeof events) / (sizeof events[0]);
4762
4763         /* Display the bypass mode.*/
4764         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4765                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4766                 return;
4767         }
4768         else {
4769                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4770                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4771
4772                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4773         }
4774
4775         /* Display the bypass timeout.*/
4776         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4777                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4778
4779         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4780
4781         /* Display the bypass events and associated modes. */
4782         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4783
4784                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4785                         printf("\tFailed to get bypass mode for event = %s\n",
4786                                 events[i]);
4787                 } else {
4788                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4789                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4790
4791                         printf("\tbypass event: %-16s = %s\n", events[i],
4792                                 modes[event_mode]);
4793                 }
4794         }
4795 #endif
4796         if (rc != 0)
4797                 printf("\tFailed to get bypass configuration for port = %d\n",
4798                        port_id);
4799 }
4800
4801 cmdline_parse_token_string_t cmd_showbypass_config_show =
4802         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4803                         show, "show");
4804 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4805         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4806                         bypass, "bypass");
4807 cmdline_parse_token_string_t cmd_showbypass_config_config =
4808         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4809                         config, "config");
4810 cmdline_parse_token_num_t cmd_showbypass_config_port =
4811         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4812                                 port_id, UINT16);
4813
4814 cmdline_parse_inst_t cmd_show_bypass_config = {
4815         .f = cmd_show_bypass_config_parsed,
4816         .help_str = "show bypass config <port_id>: "
4817                     "Show the NIC bypass config for port_id",
4818         .data = NULL,
4819         .tokens = {
4820                 (void *)&cmd_showbypass_config_show,
4821                 (void *)&cmd_showbypass_config_bypass,
4822                 (void *)&cmd_showbypass_config_config,
4823                 (void *)&cmd_showbypass_config_port,
4824                 NULL,
4825         },
4826 };
4827
4828 #ifdef RTE_LIBRTE_PMD_BOND
4829 /* *** SET BONDING MODE *** */
4830 struct cmd_set_bonding_mode_result {
4831         cmdline_fixed_string_t set;
4832         cmdline_fixed_string_t bonding;
4833         cmdline_fixed_string_t mode;
4834         uint8_t value;
4835         portid_t port_id;
4836 };
4837
4838 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4839                 __attribute__((unused))  struct cmdline *cl,
4840                 __attribute__((unused)) void *data)
4841 {
4842         struct cmd_set_bonding_mode_result *res = parsed_result;
4843         portid_t port_id = res->port_id;
4844
4845         /* Set the bonding mode for the relevant port. */
4846         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4847                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4848 }
4849
4850 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4851 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4852                 set, "set");
4853 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4855                 bonding, "bonding");
4856 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4858                 mode, "mode");
4859 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4860 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4861                 value, UINT8);
4862 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4863 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4864                 port_id, UINT16);
4865
4866 cmdline_parse_inst_t cmd_set_bonding_mode = {
4867                 .f = cmd_set_bonding_mode_parsed,
4868                 .help_str = "set bonding mode <mode_value> <port_id>: "
4869                         "Set the bonding mode for port_id",
4870                 .data = NULL,
4871                 .tokens = {
4872                                 (void *) &cmd_setbonding_mode_set,
4873                                 (void *) &cmd_setbonding_mode_bonding,
4874                                 (void *) &cmd_setbonding_mode_mode,
4875                                 (void *) &cmd_setbonding_mode_value,
4876                                 (void *) &cmd_setbonding_mode_port,
4877                                 NULL
4878                 }
4879 };
4880
4881 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4882 struct cmd_set_bonding_lacp_dedicated_queues_result {
4883         cmdline_fixed_string_t set;
4884         cmdline_fixed_string_t bonding;
4885         cmdline_fixed_string_t lacp;
4886         cmdline_fixed_string_t dedicated_queues;
4887         portid_t port_id;
4888         cmdline_fixed_string_t mode;
4889 };
4890
4891 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4892                 __attribute__((unused))  struct cmdline *cl,
4893                 __attribute__((unused)) void *data)
4894 {
4895         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4896         portid_t port_id = res->port_id;
4897         struct rte_port *port;
4898
4899         port = &ports[port_id];
4900
4901         /** Check if the port is not started **/
4902         if (port->port_status != RTE_PORT_STOPPED) {
4903                 printf("Please stop port %d first\n", port_id);
4904                 return;
4905         }
4906
4907         if (!strcmp(res->mode, "enable")) {
4908                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4909                         printf("Dedicate queues for LACP control packets"
4910                                         " enabled\n");
4911                 else
4912                         printf("Enabling dedicate queues for LACP control "
4913                                         "packets on port %d failed\n", port_id);
4914         } else if (!strcmp(res->mode, "disable")) {
4915                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4916                         printf("Dedicated queues for LACP control packets "
4917                                         "disabled\n");
4918                 else
4919                         printf("Disabling dedicated queues for LACP control "
4920                                         "traffic on port %d failed\n", port_id);
4921         }
4922 }
4923
4924 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4926                 set, "set");
4927 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4929                 bonding, "bonding");
4930 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4932                 lacp, "lacp");
4933 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4935                 dedicated_queues, "dedicated_queues");
4936 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4937 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4938                 port_id, UINT16);
4939 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4940 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4941                 mode, "enable#disable");
4942
4943 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4944                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4945                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4946                         "enable|disable: "
4947                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4948                 .data = NULL,
4949                 .tokens = {
4950                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4951                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4952                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4953                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4954                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4955                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4956                         NULL
4957                 }
4958 };
4959
4960 /* *** SET BALANCE XMIT POLICY *** */
4961 struct cmd_set_bonding_balance_xmit_policy_result {
4962         cmdline_fixed_string_t set;
4963         cmdline_fixed_string_t bonding;
4964         cmdline_fixed_string_t balance_xmit_policy;
4965         portid_t port_id;
4966         cmdline_fixed_string_t policy;
4967 };
4968
4969 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4970                 __attribute__((unused))  struct cmdline *cl,
4971                 __attribute__((unused)) void *data)
4972 {
4973         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4974         portid_t port_id = res->port_id;
4975         uint8_t policy;
4976
4977         if (!strcmp(res->policy, "l2")) {
4978                 policy = BALANCE_XMIT_POLICY_LAYER2;
4979         } else if (!strcmp(res->policy, "l23")) {
4980                 policy = BALANCE_XMIT_POLICY_LAYER23;
4981         } else if (!strcmp(res->policy, "l34")) {
4982                 policy = BALANCE_XMIT_POLICY_LAYER34;
4983         } else {
4984                 printf("\t Invalid xmit policy selection");
4985                 return;
4986         }
4987
4988         /* Set the bonding mode for the relevant port. */
4989         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4990                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4991                                 port_id);
4992         }
4993 }
4994
4995 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4996 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4997                 set, "set");
4998 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4999 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5000                 bonding, "bonding");
5001 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5003                 balance_xmit_policy, "balance_xmit_policy");
5004 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5005 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5006                 port_id, UINT16);
5007 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5008 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5009                 policy, "l2#l23#l34");
5010
5011 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5012                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5013                 .help_str = "set bonding balance_xmit_policy <port_id> "
5014                         "l2|l23|l34: "
5015                         "Set the bonding balance_xmit_policy for port_id",
5016                 .data = NULL,
5017                 .tokens = {
5018                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5019                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5020                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5021                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5022                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5023                                 NULL
5024                 }
5025 };
5026
5027 /* *** SHOW NIC BONDING CONFIGURATION *** */
5028 struct cmd_show_bonding_config_result {
5029         cmdline_fixed_string_t show;
5030         cmdline_fixed_string_t bonding;
5031         cmdline_fixed_string_t config;
5032         portid_t port_id;
5033 };
5034
5035 static void cmd_show_bonding_config_parsed(void *parsed_result,
5036                 __attribute__((unused))  struct cmdline *cl,
5037                 __attribute__((unused)) void *data)
5038 {
5039         struct cmd_show_bonding_config_result *res = parsed_result;
5040         int bonding_mode, agg_mode;
5041         portid_t slaves[RTE_MAX_ETHPORTS];
5042         int num_slaves, num_active_slaves;
5043         int primary_id;
5044         int i;
5045         portid_t port_id = res->port_id;
5046
5047         /* Display the bonding mode.*/
5048         bonding_mode = rte_eth_bond_mode_get(port_id);
5049         if (bonding_mode < 0) {
5050                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5051                 return;
5052         } else
5053                 printf("\tBonding mode: %d\n", bonding_mode);
5054
5055         if (bonding_mode == BONDING_MODE_BALANCE) {
5056                 int balance_xmit_policy;
5057
5058                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5059                 if (balance_xmit_policy < 0) {
5060                         printf("\tFailed to get balance xmit policy for port = %d\n",
5061                                         port_id);
5062                         return;
5063                 } else {
5064                         printf("\tBalance Xmit Policy: ");
5065
5066                         switch (balance_xmit_policy) {
5067                         case BALANCE_XMIT_POLICY_LAYER2:
5068                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5069                                 break;
5070                         case BALANCE_XMIT_POLICY_LAYER23:
5071                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5072                                 break;
5073                         case BALANCE_XMIT_POLICY_LAYER34:
5074                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5075                                 break;
5076                         }
5077                         printf("\n");
5078                 }
5079         }
5080
5081         if (bonding_mode == BONDING_MODE_8023AD) {
5082                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5083                 printf("\tIEEE802.3AD Aggregator Mode: ");
5084                 switch (agg_mode) {
5085                 case AGG_BANDWIDTH:
5086                         printf("bandwidth");
5087                         break;
5088                 case AGG_STABLE:
5089                         printf("stable");
5090                         break;
5091                 case AGG_COUNT:
5092                         printf("count");
5093                         break;
5094                 }
5095                 printf("\n");
5096         }
5097
5098         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5099
5100         if (num_slaves < 0) {
5101                 printf("\tFailed to get slave list for port = %d\n", port_id);
5102                 return;
5103         }
5104         if (num_slaves > 0) {
5105                 printf("\tSlaves (%d): [", num_slaves);
5106                 for (i = 0; i < num_slaves - 1; i++)
5107                         printf("%d ", slaves[i]);
5108
5109                 printf("%d]\n", slaves[num_slaves - 1]);
5110         } else {
5111                 printf("\tSlaves: []\n");
5112
5113         }
5114
5115         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5116                         RTE_MAX_ETHPORTS);
5117
5118         if (num_active_slaves < 0) {
5119                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5120                 return;
5121         }
5122         if (num_active_slaves > 0) {
5123                 printf("\tActive Slaves (%d): [", num_active_slaves);
5124                 for (i = 0; i < num_active_slaves - 1; i++)
5125                         printf("%d ", slaves[i]);
5126
5127                 printf("%d]\n", slaves[num_active_slaves - 1]);
5128
5129         } else {
5130                 printf("\tActive Slaves: []\n");
5131
5132         }
5133
5134         primary_id = rte_eth_bond_primary_get(port_id);
5135         if (primary_id < 0) {
5136                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5137                 return;
5138         } else
5139                 printf("\tPrimary: [%d]\n", primary_id);
5140
5141 }
5142
5143 cmdline_parse_token_string_t cmd_showbonding_config_show =
5144 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5145                 show, "show");
5146 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5147 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5148                 bonding, "bonding");
5149 cmdline_parse_token_string_t cmd_showbonding_config_config =
5150 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5151                 config, "config");
5152 cmdline_parse_token_num_t cmd_showbonding_config_port =
5153 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5154                 port_id, UINT16);
5155
5156 cmdline_parse_inst_t cmd_show_bonding_config = {
5157                 .f = cmd_show_bonding_config_parsed,
5158                 .help_str = "show bonding config <port_id>: "
5159                         "Show the bonding config for port_id",
5160                 .data = NULL,
5161                 .tokens = {
5162                                 (void *)&cmd_showbonding_config_show,
5163                                 (void *)&cmd_showbonding_config_bonding,
5164                                 (void *)&cmd_showbonding_config_config,
5165                                 (void *)&cmd_showbonding_config_port,
5166                                 NULL
5167                 }
5168 };
5169
5170 /* *** SET BONDING PRIMARY *** */
5171 struct cmd_set_bonding_primary_result {
5172         cmdline_fixed_string_t set;
5173         cmdline_fixed_string_t bonding;
5174         cmdline_fixed_string_t primary;
5175         portid_t slave_id;
5176         portid_t port_id;
5177 };
5178
5179 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5180                 __attribute__((unused))  struct cmdline *cl,
5181                 __attribute__((unused)) void *data)
5182 {
5183         struct cmd_set_bonding_primary_result *res = parsed_result;
5184         portid_t master_port_id = res->port_id;
5185         portid_t slave_port_id = res->slave_id;
5186
5187         /* Set the primary slave for a bonded device. */
5188         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5189                 printf("\t Failed to set primary slave for port = %d.\n",
5190                                 master_port_id);
5191                 return;
5192         }
5193         init_port_config();
5194 }
5195
5196 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5197 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5198                 set, "set");
5199 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5200 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5201                 bonding, "bonding");
5202 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5203 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5204                 primary, "primary");
5205 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5206 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5207                 slave_id, UINT16);
5208 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5209 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5210                 port_id, UINT16);
5211
5212 cmdline_parse_inst_t cmd_set_bonding_primary = {
5213                 .f = cmd_set_bonding_primary_parsed,
5214                 .help_str = "set bonding primary <slave_id> <port_id>: "
5215                         "Set the primary slave for port_id",
5216                 .data = NULL,
5217                 .tokens = {
5218                                 (void *)&cmd_setbonding_primary_set,
5219                                 (void *)&cmd_setbonding_primary_bonding,
5220                                 (void *)&cmd_setbonding_primary_primary,
5221                                 (void *)&cmd_setbonding_primary_slave,
5222                                 (void *)&cmd_setbonding_primary_port,
5223                                 NULL
5224                 }
5225 };
5226
5227 /* *** ADD SLAVE *** */
5228 struct cmd_add_bonding_slave_result {
5229         cmdline_fixed_string_t add;
5230         cmdline_fixed_string_t bonding;
5231         cmdline_fixed_string_t slave;
5232         portid_t slave_id;
5233         portid_t port_id;
5234 };
5235
5236 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5237                 __attribute__((unused))  struct cmdline *cl,
5238                 __attribute__((unused)) void *data)
5239 {
5240         struct cmd_add_bonding_slave_result *res = parsed_result;
5241         portid_t master_port_id = res->port_id;
5242         portid_t slave_port_id = res->slave_id;
5243
5244         /* add the slave for a bonded device. */
5245         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5246                 printf("\t Failed to add slave %d to master port = %d.\n",
5247                                 slave_port_id, master_port_id);
5248                 return;
5249         }
5250         init_port_config();
5251         set_port_slave_flag(slave_port_id);
5252 }
5253
5254 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5255 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5256                 add, "add");
5257 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5258 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5259                 bonding, "bonding");
5260 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5261 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5262                 slave, "slave");
5263 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5264 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5265                 slave_id, UINT16);
5266 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5267 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5268                 port_id, UINT16);
5269
5270 cmdline_parse_inst_t cmd_add_bonding_slave = {
5271                 .f = cmd_add_bonding_slave_parsed,
5272                 .help_str = "add bonding slave <slave_id> <port_id>: "
5273                         "Add a slave device to a bonded device",
5274                 .data = NULL,
5275                 .tokens = {
5276                                 (void *)&cmd_addbonding_slave_add,
5277                                 (void *)&cmd_addbonding_slave_bonding,
5278                                 (void *)&cmd_addbonding_slave_slave,
5279                                 (void *)&cmd_addbonding_slave_slaveid,
5280                                 (void *)&cmd_addbonding_slave_port,
5281                                 NULL
5282                 }
5283 };
5284
5285 /* *** REMOVE SLAVE *** */
5286 struct cmd_remove_bonding_slave_result {
5287         cmdline_fixed_string_t remove;
5288         cmdline_fixed_string_t bonding;
5289         cmdline_fixed_string_t slave;
5290         portid_t slave_id;
5291         portid_t port_id;
5292 };
5293
5294 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5295                 __attribute__((unused))  struct cmdline *cl,
5296                 __attribute__((unused)) void *data)
5297 {
5298         struct cmd_remove_bonding_slave_result *res = parsed_result;
5299         portid_t master_port_id = res->port_id;
5300         portid_t slave_port_id = res->slave_id;
5301
5302         /* remove the slave from a bonded device. */
5303         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5304                 printf("\t Failed to remove slave %d from master port = %d.\n",
5305                                 slave_port_id, master_port_id);
5306                 return;
5307         }
5308         init_port_config();
5309         clear_port_slave_flag(slave_port_id);
5310 }
5311
5312 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5313                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5314                                 remove, "remove");
5315 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5316                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5317                                 bonding, "bonding");
5318 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5319                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5320                                 slave, "slave");
5321 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5322                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5323                                 slave_id, UINT16);
5324 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5325                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5326                                 port_id, UINT16);
5327
5328 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5329                 .f = cmd_remove_bonding_slave_parsed,
5330                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5331                         "Remove a slave device from a bonded device",
5332                 .data = NULL,
5333                 .tokens = {
5334                                 (void *)&cmd_removebonding_slave_remove,
5335                                 (void *)&cmd_removebonding_slave_bonding,
5336                                 (void *)&cmd_removebonding_slave_slave,
5337                                 (void *)&cmd_removebonding_slave_slaveid,
5338                                 (void *)&cmd_removebonding_slave_port,
5339                                 NULL
5340                 }
5341 };
5342
5343 /* *** CREATE BONDED DEVICE *** */
5344 struct cmd_create_bonded_device_result {
5345         cmdline_fixed_string_t create;
5346         cmdline_fixed_string_t bonded;
5347         cmdline_fixed_string_t device;
5348         uint8_t mode;
5349         uint8_t socket;
5350 };
5351
5352 static int bond_dev_num = 0;
5353
5354 static void cmd_create_bonded_device_parsed(void *parsed_result,
5355                 __attribute__((unused))  struct cmdline *cl,
5356                 __attribute__((unused)) void *data)
5357 {
5358         struct cmd_create_bonded_device_result *res = parsed_result;
5359         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5360         int port_id;
5361
5362         if (test_done == 0) {
5363                 printf("Please stop forwarding first\n");
5364                 return;
5365         }
5366
5367         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5368                         bond_dev_num++);
5369
5370         /* Create a new bonded device. */
5371         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5372         if (port_id < 0) {
5373                 printf("\t Failed to create bonded device.\n");
5374                 return;
5375         } else {
5376                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5377                                 port_id);
5378
5379                 /* Update number of ports */
5380                 nb_ports = rte_eth_dev_count();
5381                 reconfig(port_id, res->socket);
5382                 rte_eth_promiscuous_enable(port_id);
5383         }
5384
5385 }
5386
5387 cmdline_parse_token_string_t cmd_createbonded_device_create =
5388                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5389                                 create, "create");
5390 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5391                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5392                                 bonded, "bonded");
5393 cmdline_parse_token_string_t cmd_createbonded_device_device =
5394                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5395                                 device, "device");
5396 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5397                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5398                                 mode, UINT8);
5399 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5400                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5401                                 socket, UINT8);
5402
5403 cmdline_parse_inst_t cmd_create_bonded_device = {
5404                 .f = cmd_create_bonded_device_parsed,
5405                 .help_str = "create bonded device <mode> <socket>: "
5406                         "Create a new bonded device with specific bonding mode and socket",
5407                 .data = NULL,
5408                 .tokens = {
5409                                 (void *)&cmd_createbonded_device_create,
5410                                 (void *)&cmd_createbonded_device_bonded,
5411                                 (void *)&cmd_createbonded_device_device,
5412                                 (void *)&cmd_createbonded_device_mode,
5413                                 (void *)&cmd_createbonded_device_socket,
5414                                 NULL
5415                 }
5416 };
5417
5418 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5419 struct cmd_set_bond_mac_addr_result {
5420         cmdline_fixed_string_t set;
5421         cmdline_fixed_string_t bonding;
5422         cmdline_fixed_string_t mac_addr;
5423         uint16_t port_num;
5424         struct ether_addr address;
5425 };
5426
5427 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5428                 __attribute__((unused))  struct cmdline *cl,
5429                 __attribute__((unused)) void *data)
5430 {
5431         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5432         int ret;
5433
5434         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5435                 return;
5436
5437         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5438
5439         /* check the return value and print it if is < 0 */
5440         if (ret < 0)
5441                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5442 }
5443
5444 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5445                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5446 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5447                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5448                                 "bonding");
5449 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5450                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5451                                 "mac_addr");
5452 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5453                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5454                                 port_num, UINT16);
5455 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5456                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5457
5458 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5459                 .f = cmd_set_bond_mac_addr_parsed,
5460                 .data = (void *) 0,
5461                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5462                 .tokens = {
5463                                 (void *)&cmd_set_bond_mac_addr_set,
5464                                 (void *)&cmd_set_bond_mac_addr_bonding,
5465                                 (void *)&cmd_set_bond_mac_addr_mac,
5466                                 (void *)&cmd_set_bond_mac_addr_portnum,
5467                                 (void *)&cmd_set_bond_mac_addr_addr,
5468                                 NULL
5469                 }
5470 };
5471
5472
5473 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5474 struct cmd_set_bond_mon_period_result {
5475         cmdline_fixed_string_t set;
5476         cmdline_fixed_string_t bonding;
5477         cmdline_fixed_string_t mon_period;
5478         uint16_t port_num;
5479         uint32_t period_ms;
5480 };
5481
5482 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5483                 __attribute__((unused))  struct cmdline *cl,
5484                 __attribute__((unused)) void *data)
5485 {
5486         struct cmd_set_bond_mon_period_result *res = parsed_result;
5487         int ret;
5488
5489         if (res->port_num >= nb_ports) {
5490                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5491                 return;
5492         }
5493
5494         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5495
5496         /* check the return value and print it if is < 0 */
5497         if (ret < 0)
5498                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5499 }
5500
5501 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5502                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5503                                 set, "set");
5504 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5505                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5506                                 bonding, "bonding");
5507 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5508                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5509                                 mon_period,     "mon_period");
5510 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5511                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5512                                 port_num, UINT16);
5513 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5514                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5515                                 period_ms, UINT32);
5516
5517 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5518                 .f = cmd_set_bond_mon_period_parsed,
5519                 .data = (void *) 0,
5520                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5521                 .tokens = {
5522                                 (void *)&cmd_set_bond_mon_period_set,
5523                                 (void *)&cmd_set_bond_mon_period_bonding,
5524                                 (void *)&cmd_set_bond_mon_period_mon_period,
5525                                 (void *)&cmd_set_bond_mon_period_portnum,
5526                                 (void *)&cmd_set_bond_mon_period_period_ms,
5527                                 NULL
5528                 }
5529 };
5530
5531
5532
5533 struct cmd_set_bonding_agg_mode_policy_result {
5534         cmdline_fixed_string_t set;
5535         cmdline_fixed_string_t bonding;
5536         cmdline_fixed_string_t agg_mode;
5537         uint16_t port_num;
5538         cmdline_fixed_string_t policy;
5539 };
5540
5541
5542 static void
5543 cmd_set_bonding_agg_mode(void *parsed_result,
5544                 __attribute__((unused)) struct cmdline *cl,
5545                 __attribute__((unused)) void *data)
5546 {
5547         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5548         uint8_t policy = AGG_BANDWIDTH;
5549
5550         if (res->port_num >= nb_ports) {
5551                 printf("Port id %d must be less than %d\n",
5552                                 res->port_num, nb_ports);
5553                 return;
5554         }
5555
5556         if (!strcmp(res->policy, "bandwidth"))
5557                 policy = AGG_BANDWIDTH;
5558         else if (!strcmp(res->policy, "stable"))
5559                 policy = AGG_STABLE;
5560         else if (!strcmp(res->policy, "count"))
5561                 policy = AGG_COUNT;
5562
5563         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5564 }
5565
5566
5567 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5569                                 set, "set");
5570 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5572                                 bonding, "bonding");
5573
5574 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5576                                 agg_mode, "agg_mode");
5577
5578 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5579         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5580                                 port_num, UINT16);
5581
5582 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5583         TOKEN_STRING_INITIALIZER(
5584                         struct cmd_set_bonding_balance_xmit_policy_result,
5585                 policy, "stable#bandwidth#count");
5586
5587 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5588         .f = cmd_set_bonding_agg_mode,
5589         .data = (void *) 0,
5590         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5591         .tokens = {
5592                         (void *)&cmd_set_bonding_agg_mode_set,
5593                         (void *)&cmd_set_bonding_agg_mode_bonding,
5594                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5595                         (void *)&cmd_set_bonding_agg_mode_portnum,
5596                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5597                         NULL
5598                 }
5599 };
5600
5601
5602 #endif /* RTE_LIBRTE_PMD_BOND */
5603
5604 /* *** SET FORWARDING MODE *** */
5605 struct cmd_set_fwd_mode_result {
5606         cmdline_fixed_string_t set;
5607         cmdline_fixed_string_t fwd;
5608         cmdline_fixed_string_t mode;
5609 };
5610
5611 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5612                                     __attribute__((unused)) struct cmdline *cl,
5613                                     __attribute__((unused)) void *data)
5614 {
5615         struct cmd_set_fwd_mode_result *res = parsed_result;
5616
5617         retry_enabled = 0;
5618         set_pkt_forwarding_mode(res->mode);
5619 }
5620
5621 cmdline_parse_token_string_t cmd_setfwd_set =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5623 cmdline_parse_token_string_t cmd_setfwd_fwd =
5624         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5625 cmdline_parse_token_string_t cmd_setfwd_mode =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5627                 "" /* defined at init */);
5628
5629 cmdline_parse_inst_t cmd_set_fwd_mode = {
5630         .f = cmd_set_fwd_mode_parsed,
5631         .data = NULL,
5632         .help_str = NULL, /* defined at init */
5633         .tokens = {
5634                 (void *)&cmd_setfwd_set,
5635                 (void *)&cmd_setfwd_fwd,
5636                 (void *)&cmd_setfwd_mode,
5637                 NULL,
5638         },
5639 };
5640
5641 static void cmd_set_fwd_mode_init(void)
5642 {
5643         char *modes, *c;
5644         static char token[128];
5645         static char help[256];
5646         cmdline_parse_token_string_t *token_struct;
5647
5648         modes = list_pkt_forwarding_modes();
5649         snprintf(help, sizeof(help), "set fwd %s: "
5650                 "Set packet forwarding mode", modes);
5651         cmd_set_fwd_mode.help_str = help;
5652
5653         /* string token separator is # */
5654         for (c = token; *modes != '\0'; modes++)
5655                 if (*modes == '|')
5656                         *c++ = '#';
5657                 else
5658                         *c++ = *modes;
5659         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5660         token_struct->string_data.str = token;
5661 }
5662
5663 /* *** SET RETRY FORWARDING MODE *** */
5664 struct cmd_set_fwd_retry_mode_result {
5665         cmdline_fixed_string_t set;
5666         cmdline_fixed_string_t fwd;
5667         cmdline_fixed_string_t mode;
5668         cmdline_fixed_string_t retry;
5669 };
5670
5671 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5672                             __attribute__((unused)) struct cmdline *cl,
5673                             __attribute__((unused)) void *data)
5674 {
5675         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5676
5677         retry_enabled = 1;
5678         set_pkt_forwarding_mode(res->mode);
5679 }
5680
5681 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5682         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5683                         set, "set");
5684 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5686                         fwd, "fwd");
5687 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5689                         mode,
5690                 "" /* defined at init */);
5691 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5692         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5693                         retry, "retry");
5694
5695 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5696         .f = cmd_set_fwd_retry_mode_parsed,
5697         .data = NULL,
5698         .help_str = NULL, /* defined at init */
5699         .tokens = {
5700                 (void *)&cmd_setfwd_retry_set,
5701                 (void *)&cmd_setfwd_retry_fwd,
5702                 (void *)&cmd_setfwd_retry_mode,
5703                 (void *)&cmd_setfwd_retry_retry,
5704                 NULL,
5705         },
5706 };
5707
5708 static void cmd_set_fwd_retry_mode_init(void)
5709 {
5710         char *modes, *c;
5711         static char token[128];
5712         static char help[256];
5713         cmdline_parse_token_string_t *token_struct;
5714
5715         modes = list_pkt_forwarding_retry_modes();
5716         snprintf(help, sizeof(help), "set fwd %s retry: "
5717                 "Set packet forwarding mode with retry", modes);
5718         cmd_set_fwd_retry_mode.help_str = help;
5719
5720         /* string token separator is # */
5721         for (c = token; *modes != '\0'; modes++)
5722                 if (*modes == '|')
5723                         *c++ = '#';
5724                 else
5725                         *c++ = *modes;
5726         token_struct = (cmdline_parse_token_string_t *)
5727                 cmd_set_fwd_retry_mode.tokens[2];
5728         token_struct->string_data.str = token;
5729 }
5730
5731 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5732 struct cmd_set_burst_tx_retry_result {
5733         cmdline_fixed_string_t set;
5734         cmdline_fixed_string_t burst;
5735         cmdline_fixed_string_t tx;
5736         cmdline_fixed_string_t delay;
5737         uint32_t time;
5738         cmdline_fixed_string_t retry;
5739         uint32_t retry_num;
5740 };
5741
5742 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5743                                         __attribute__((unused)) struct cmdline *cl,
5744                                         __attribute__((unused)) void *data)
5745 {
5746         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5747
5748         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5749                 && !strcmp(res->tx, "tx")) {
5750                 if (!strcmp(res->delay, "delay"))
5751                         burst_tx_delay_time = res->time;
5752                 if (!strcmp(res->retry, "retry"))
5753                         burst_tx_retry_num = res->retry_num;
5754         }
5755
5756 }
5757
5758 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5759         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5760 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5762                                  "burst");
5763 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5765 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5766         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5767 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5768         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5769 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5770         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5771 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5772         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5773
5774 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5775         .f = cmd_set_burst_tx_retry_parsed,
5776         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5777         .tokens = {
5778                 (void *)&cmd_set_burst_tx_retry_set,
5779                 (void *)&cmd_set_burst_tx_retry_burst,
5780                 (void *)&cmd_set_burst_tx_retry_tx,
5781                 (void *)&cmd_set_burst_tx_retry_delay,
5782                 (void *)&cmd_set_burst_tx_retry_time,
5783                 (void *)&cmd_set_burst_tx_retry_retry,
5784                 (void *)&cmd_set_burst_tx_retry_retry_num,
5785                 NULL,
5786         },
5787 };
5788
5789 /* *** SET PROMISC MODE *** */
5790 struct cmd_set_promisc_mode_result {
5791         cmdline_fixed_string_t set;
5792         cmdline_fixed_string_t promisc;
5793         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5794         uint16_t port_num;               /* valid if "allports" argument == 0 */
5795         cmdline_fixed_string_t mode;
5796 };
5797
5798 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5799                                         __attribute__((unused)) struct cmdline *cl,
5800                                         void *allports)
5801 {
5802         struct cmd_set_promisc_mode_result *res = parsed_result;
5803         int enable;
5804         portid_t i;
5805
5806         if (!strcmp(res->mode, "on"))
5807                 enable = 1;
5808         else
5809                 enable = 0;
5810
5811         /* all ports */
5812         if (allports) {
5813                 RTE_ETH_FOREACH_DEV(i) {
5814                         if (enable)
5815                                 rte_eth_promiscuous_enable(i);
5816                         else
5817                                 rte_eth_promiscuous_disable(i);
5818                 }
5819         }
5820         else {
5821                 if (enable)
5822                         rte_eth_promiscuous_enable(res->port_num);
5823                 else
5824                         rte_eth_promiscuous_disable(res->port_num);
5825         }
5826 }
5827
5828 cmdline_parse_token_string_t cmd_setpromisc_set =
5829         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5830 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5831         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5832                                  "promisc");
5833 cmdline_parse_token_string_t cmd_setpromisc_portall =
5834         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5835                                  "all");
5836 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5837         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5838                               UINT8);
5839 cmdline_parse_token_string_t cmd_setpromisc_mode =
5840         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5841                                  "on#off");
5842
5843 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5844         .f = cmd_set_promisc_mode_parsed,
5845         .data = (void *)1,
5846         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5847         .tokens = {
5848                 (void *)&cmd_setpromisc_set,
5849                 (void *)&cmd_setpromisc_promisc,
5850                 (void *)&cmd_setpromisc_portall,
5851                 (void *)&cmd_setpromisc_mode,
5852                 NULL,
5853         },
5854 };
5855
5856 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5857         .f = cmd_set_promisc_mode_parsed,
5858         .data = (void *)0,
5859         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5860         .tokens = {
5861                 (void *)&cmd_setpromisc_set,
5862                 (void *)&cmd_setpromisc_promisc,
5863                 (void *)&cmd_setpromisc_portnum,
5864                 (void *)&cmd_setpromisc_mode,
5865                 NULL,
5866         },
5867 };
5868
5869 /* *** SET ALLMULTI MODE *** */
5870 struct cmd_set_allmulti_mode_result {
5871         cmdline_fixed_string_t set;
5872         cmdline_fixed_string_t allmulti;
5873         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5874         uint16_t port_num;               /* valid if "allports" argument == 0 */
5875         cmdline_fixed_string_t mode;
5876 };
5877
5878 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5879                                         __attribute__((unused)) struct cmdline *cl,
5880                                         void *allports)
5881 {
5882         struct cmd_set_allmulti_mode_result *res = parsed_result;
5883         int enable;
5884         portid_t i;
5885
5886         if (!strcmp(res->mode, "on"))
5887                 enable = 1;
5888         else
5889                 enable = 0;
5890
5891         /* all ports */
5892         if (allports) {
5893                 RTE_ETH_FOREACH_DEV(i) {
5894                         if (enable)
5895                                 rte_eth_allmulticast_enable(i);
5896                         else
5897                                 rte_eth_allmulticast_disable(i);
5898                 }
5899         }
5900         else {
5901                 if (enable)
5902                         rte_eth_allmulticast_enable(res->port_num);
5903                 else
5904                         rte_eth_allmulticast_disable(res->port_num);
5905         }
5906 }
5907
5908 cmdline_parse_token_string_t cmd_setallmulti_set =
5909         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5910 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5911         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5912                                  "allmulti");
5913 cmdline_parse_token_string_t cmd_setallmulti_portall =
5914         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5915                                  "all");
5916 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5917         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5918                               UINT16);
5919 cmdline_parse_token_string_t cmd_setallmulti_mode =
5920         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5921                                  "on#off");
5922
5923 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5924         .f = cmd_set_allmulti_mode_parsed,
5925         .data = (void *)1,
5926         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5927         .tokens = {
5928                 (void *)&cmd_setallmulti_set,
5929                 (void *)&cmd_setallmulti_allmulti,
5930                 (void *)&cmd_setallmulti_portall,
5931                 (void *)&cmd_setallmulti_mode,
5932                 NULL,
5933         },
5934 };
5935
5936 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5937         .f = cmd_set_allmulti_mode_parsed,
5938         .data = (void *)0,
5939         .help_str = "set allmulti <port_id> on|off: "
5940                 "Set allmulti mode on port_id",
5941         .tokens = {
5942                 (void *)&cmd_setallmulti_set,
5943                 (void *)&cmd_setallmulti_allmulti,
5944                 (void *)&cmd_setallmulti_portnum,
5945                 (void *)&cmd_setallmulti_mode,
5946                 NULL,
5947         },
5948 };
5949
5950 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5951 struct cmd_link_flow_ctrl_set_result {
5952         cmdline_fixed_string_t set;
5953         cmdline_fixed_string_t flow_ctrl;
5954         cmdline_fixed_string_t rx;
5955         cmdline_fixed_string_t rx_lfc_mode;
5956         cmdline_fixed_string_t tx;
5957         cmdline_fixed_string_t tx_lfc_mode;
5958         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5959         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5960         cmdline_fixed_string_t autoneg_str;
5961         cmdline_fixed_string_t autoneg;
5962         cmdline_fixed_string_t hw_str;
5963         uint32_t high_water;
5964         cmdline_fixed_string_t lw_str;
5965         uint32_t low_water;
5966         cmdline_fixed_string_t pt_str;
5967         uint16_t pause_time;
5968         cmdline_fixed_string_t xon_str;
5969         uint16_t send_xon;
5970         portid_t port_id;
5971 };
5972
5973 cmdline_parse_token_string_t cmd_lfc_set_set =
5974         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5975                                 set, "set");
5976 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5977         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5978                                 flow_ctrl, "flow_ctrl");
5979 cmdline_parse_token_string_t cmd_lfc_set_rx =
5980         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5981                                 rx, "rx");
5982 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5983         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5984                                 rx_lfc_mode, "on#off");
5985 cmdline_parse_token_string_t cmd_lfc_set_tx =
5986         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5987                                 tx, "tx");
5988 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5989         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5990                                 tx_lfc_mode, "on#off");
5991 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5992         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5993                                 hw_str, "high_water");
5994 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5995         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5996                                 high_water, UINT32);
5997 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5998         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5999                                 lw_str, "low_water");
6000 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6001         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6002                                 low_water, UINT32);
6003 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6004         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6005                                 pt_str, "pause_time");
6006 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6007         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6008                                 pause_time, UINT16);
6009 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6010         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6011                                 xon_str, "send_xon");
6012 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6013         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6014                                 send_xon, UINT16);
6015 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6016         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6017                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6018 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6019         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6020                                 mac_ctrl_frame_fwd_mode, "on#off");
6021 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6022         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6023                                 autoneg_str, "autoneg");
6024 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6025         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6026                                 autoneg, "on#off");
6027 cmdline_parse_token_num_t cmd_lfc_set_portid =
6028         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6029                                 port_id, UINT16);
6030
6031 /* forward declaration */
6032 static void
6033 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6034                               void *data);
6035
6036 cmdline_parse_inst_t cmd_link_flow_control_set = {
6037         .f = cmd_link_flow_ctrl_set_parsed,
6038         .data = NULL,
6039         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6040                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6041                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6042         .tokens = {
6043                 (void *)&cmd_lfc_set_set,
6044                 (void *)&cmd_lfc_set_flow_ctrl,
6045                 (void *)&cmd_lfc_set_rx,
6046                 (void *)&cmd_lfc_set_rx_mode,
6047                 (void *)&cmd_lfc_set_tx,
6048                 (void *)&cmd_lfc_set_tx_mode,
6049                 (void *)&cmd_lfc_set_high_water,
6050                 (void *)&cmd_lfc_set_low_water,
6051                 (void *)&cmd_lfc_set_pause_time,
6052                 (void *)&cmd_lfc_set_send_xon,
6053                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6054                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6055                 (void *)&cmd_lfc_set_autoneg_str,
6056                 (void *)&cmd_lfc_set_autoneg,
6057                 (void *)&cmd_lfc_set_portid,
6058                 NULL,
6059         },
6060 };
6061
6062 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6063         .f = cmd_link_flow_ctrl_set_parsed,
6064         .data = (void *)&cmd_link_flow_control_set_rx,
6065         .help_str = "set flow_ctrl rx on|off <port_id>: "
6066                 "Change rx flow control parameter",
6067         .tokens = {
6068                 (void *)&cmd_lfc_set_set,
6069                 (void *)&cmd_lfc_set_flow_ctrl,
6070                 (void *)&cmd_lfc_set_rx,
6071                 (void *)&cmd_lfc_set_rx_mode,
6072                 (void *)&cmd_lfc_set_portid,
6073                 NULL,
6074         },
6075 };
6076
6077 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6078         .f = cmd_link_flow_ctrl_set_parsed,
6079         .data = (void *)&cmd_link_flow_control_set_tx,
6080         .help_str = "set flow_ctrl tx on|off <port_id>: "
6081                 "Change tx flow control parameter",
6082         .tokens = {
6083                 (void *)&cmd_lfc_set_set,
6084                 (void *)&cmd_lfc_set_flow_ctrl,
6085                 (void *)&cmd_lfc_set_tx,
6086                 (void *)&cmd_lfc_set_tx_mode,
6087                 (void *)&cmd_lfc_set_portid,
6088                 NULL,
6089         },
6090 };
6091
6092 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6093         .f = cmd_link_flow_ctrl_set_parsed,
6094         .data = (void *)&cmd_link_flow_control_set_hw,
6095         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6096                 "Change high water flow control parameter",
6097         .tokens = {
6098                 (void *)&cmd_lfc_set_set,
6099                 (void *)&cmd_lfc_set_flow_ctrl,
6100                 (void *)&cmd_lfc_set_high_water_str,
6101                 (void *)&cmd_lfc_set_high_water,
6102                 (void *)&cmd_lfc_set_portid,
6103                 NULL,
6104         },
6105 };
6106
6107 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6108         .f = cmd_link_flow_ctrl_set_parsed,
6109         .data = (void *)&cmd_link_flow_control_set_lw,
6110         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6111                 "Change low water flow control parameter",
6112         .tokens = {
6113                 (void *)&cmd_lfc_set_set,
6114                 (void *)&cmd_lfc_set_flow_ctrl,
6115                 (void *)&cmd_lfc_set_low_water_str,
6116                 (void *)&cmd_lfc_set_low_water,
6117                 (void *)&cmd_lfc_set_portid,
6118                 NULL,
6119         },
6120 };
6121
6122 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6123         .f = cmd_link_flow_ctrl_set_parsed,
6124         .data = (void *)&cmd_link_flow_control_set_pt,
6125         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6126                 "Change pause time flow control parameter",
6127         .tokens = {
6128                 (void *)&cmd_lfc_set_set,
6129                 (void *)&cmd_lfc_set_flow_ctrl,
6130                 (void *)&cmd_lfc_set_pause_time_str,
6131                 (void *)&cmd_lfc_set_pause_time,
6132                 (void *)&cmd_lfc_set_portid,
6133                 NULL,
6134         },
6135 };
6136
6137 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6138         .f = cmd_link_flow_ctrl_set_parsed,
6139         .data = (void *)&cmd_link_flow_control_set_xon,
6140         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6141                 "Change send_xon flow control parameter",
6142         .tokens = {
6143                 (void *)&cmd_lfc_set_set,
6144                 (void *)&cmd_lfc_set_flow_ctrl,
6145                 (void *)&cmd_lfc_set_send_xon_str,
6146                 (void *)&cmd_lfc_set_send_xon,
6147                 (void *)&cmd_lfc_set_portid,
6148                 NULL,
6149         },
6150 };
6151
6152 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6153         .f = cmd_link_flow_ctrl_set_parsed,
6154         .data = (void *)&cmd_link_flow_control_set_macfwd,
6155         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6156                 "Change mac ctrl fwd flow control parameter",
6157         .tokens = {
6158                 (void *)&cmd_lfc_set_set,
6159                 (void *)&cmd_lfc_set_flow_ctrl,
6160                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6161                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6162                 (void *)&cmd_lfc_set_portid,
6163                 NULL,
6164         },
6165 };
6166
6167 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6168         .f = cmd_link_flow_ctrl_set_parsed,
6169         .data = (void *)&cmd_link_flow_control_set_autoneg,
6170         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6171                 "Change autoneg flow control parameter",
6172         .tokens = {
6173                 (void *)&cmd_lfc_set_set,
6174                 (void *)&cmd_lfc_set_flow_ctrl,
6175                 (void *)&cmd_lfc_set_autoneg_str,
6176                 (void *)&cmd_lfc_set_autoneg,
6177                 (void *)&cmd_lfc_set_portid,
6178                 NULL,
6179         },
6180 };
6181
6182 static void
6183 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6184                               __attribute__((unused)) struct cmdline *cl,
6185                               void *data)
6186 {
6187         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6188         cmdline_parse_inst_t *cmd = data;
6189         struct rte_eth_fc_conf fc_conf;
6190         int rx_fc_en = 0;
6191         int tx_fc_en = 0;
6192         int ret;
6193
6194         /*
6195          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6196          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6197          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6198          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6199          */
6200         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6201                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6202         };
6203
6204         /* Partial command line, retrieve current configuration */
6205         if (cmd) {
6206                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6207                 if (ret != 0) {
6208                         printf("cannot get current flow ctrl parameters, return"
6209                                "code = %d\n", ret);
6210                         return;
6211                 }
6212
6213                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6214                     (fc_conf.mode == RTE_FC_FULL))
6215                         rx_fc_en = 1;
6216                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6217                     (fc_conf.mode == RTE_FC_FULL))
6218                         tx_fc_en = 1;
6219         }
6220
6221         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6222                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6223
6224         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6225                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6226
6227         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6228
6229         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6230                 fc_conf.high_water = res->high_water;
6231
6232         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6233                 fc_conf.low_water = res->low_water;
6234
6235         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6236                 fc_conf.pause_time = res->pause_time;
6237
6238         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6239                 fc_conf.send_xon = res->send_xon;
6240
6241         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6242                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6243                         fc_conf.mac_ctrl_frame_fwd = 1;
6244                 else
6245                         fc_conf.mac_ctrl_frame_fwd = 0;
6246         }
6247
6248         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6249                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6250
6251         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6252         if (ret != 0)
6253                 printf("bad flow contrl parameter, return code = %d \n", ret);
6254 }
6255
6256 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6257 struct cmd_priority_flow_ctrl_set_result {
6258         cmdline_fixed_string_t set;
6259         cmdline_fixed_string_t pfc_ctrl;
6260         cmdline_fixed_string_t rx;
6261         cmdline_fixed_string_t rx_pfc_mode;
6262         cmdline_fixed_string_t tx;
6263         cmdline_fixed_string_t tx_pfc_mode;
6264         uint32_t high_water;
6265         uint32_t low_water;
6266         uint16_t pause_time;
6267         uint8_t  priority;
6268         portid_t port_id;
6269 };
6270
6271 static void
6272 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6273                        __attribute__((unused)) struct cmdline *cl,
6274                        __attribute__((unused)) void *data)
6275 {
6276         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6277         struct rte_eth_pfc_conf pfc_conf;
6278         int rx_fc_enable, tx_fc_enable;
6279         int ret;
6280
6281         /*
6282          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6283          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6284          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6285          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6286          */
6287         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6288                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6289         };
6290
6291         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6292         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6293         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6294         pfc_conf.fc.high_water = res->high_water;
6295         pfc_conf.fc.low_water  = res->low_water;
6296         pfc_conf.fc.pause_time = res->pause_time;
6297         pfc_conf.priority      = res->priority;
6298
6299         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6300         if (ret != 0)
6301                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6302 }
6303
6304 cmdline_parse_token_string_t cmd_pfc_set_set =
6305         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6306                                 set, "set");
6307 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6308         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6309                                 pfc_ctrl, "pfc_ctrl");
6310 cmdline_parse_token_string_t cmd_pfc_set_rx =
6311         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6312                                 rx, "rx");
6313 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6314         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6315                                 rx_pfc_mode, "on#off");
6316 cmdline_parse_token_string_t cmd_pfc_set_tx =
6317         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6318                                 tx, "tx");
6319 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6320         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6321                                 tx_pfc_mode, "on#off");
6322 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6323         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6324                                 high_water, UINT32);
6325 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6326         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6327                                 low_water, UINT32);
6328 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6329         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6330                                 pause_time, UINT16);
6331 cmdline_parse_token_num_t cmd_pfc_set_priority =
6332         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6333                                 priority, UINT8);
6334 cmdline_parse_token_num_t cmd_pfc_set_portid =
6335         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6336                                 port_id, UINT16);
6337
6338 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6339         .f = cmd_priority_flow_ctrl_set_parsed,
6340         .data = NULL,
6341         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6342                 "<pause_time> <priority> <port_id>: "
6343                 "Configure the Ethernet priority flow control",
6344         .tokens = {
6345                 (void *)&cmd_pfc_set_set,
6346                 (void *)&cmd_pfc_set_flow_ctrl,
6347                 (void *)&cmd_pfc_set_rx,
6348                 (void *)&cmd_pfc_set_rx_mode,
6349                 (void *)&cmd_pfc_set_tx,
6350                 (void *)&cmd_pfc_set_tx_mode,
6351                 (void *)&cmd_pfc_set_high_water,
6352                 (void *)&cmd_pfc_set_low_water,
6353                 (void *)&cmd_pfc_set_pause_time,
6354                 (void *)&cmd_pfc_set_priority,
6355                 (void *)&cmd_pfc_set_portid,
6356                 NULL,
6357         },
6358 };
6359
6360 /* *** RESET CONFIGURATION *** */
6361 struct cmd_reset_result {
6362         cmdline_fixed_string_t reset;
6363         cmdline_fixed_string_t def;
6364 };
6365
6366 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6367                              struct cmdline *cl,
6368                              __attribute__((unused)) void *data)
6369 {
6370         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6371         set_def_fwd_config();
6372 }
6373
6374 cmdline_parse_token_string_t cmd_reset_set =
6375         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6376 cmdline_parse_token_string_t cmd_reset_def =
6377         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6378                                  "default");
6379
6380 cmdline_parse_inst_t cmd_reset = {
6381         .f = cmd_reset_parsed,
6382         .data = NULL,
6383         .help_str = "set default: Reset default forwarding configuration",
6384         .tokens = {
6385                 (void *)&cmd_reset_set,
6386                 (void *)&cmd_reset_def,
6387                 NULL,
6388         },
6389 };
6390
6391 /* *** START FORWARDING *** */
6392 struct cmd_start_result {
6393         cmdline_fixed_string_t start;
6394 };
6395
6396 cmdline_parse_token_string_t cmd_start_start =
6397         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6398
6399 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6400                              __attribute__((unused)) struct cmdline *cl,
6401                              __attribute__((unused)) void *data)
6402 {
6403         start_packet_forwarding(0);
6404 }
6405
6406 cmdline_parse_inst_t cmd_start = {
6407         .f = cmd_start_parsed,
6408         .data = NULL,
6409         .help_str = "start: Start packet forwarding",
6410         .tokens = {
6411                 (void *)&cmd_start_start,
6412                 NULL,
6413         },
6414 };
6415
6416 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6417 struct cmd_start_tx_first_result {
6418         cmdline_fixed_string_t start;
6419         cmdline_fixed_string_t tx_first;
6420 };
6421
6422 static void
6423 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6424                           __attribute__((unused)) struct cmdline *cl,
6425                           __attribute__((unused)) void *data)
6426 {
6427         start_packet_forwarding(1);
6428 }
6429
6430 cmdline_parse_token_string_t cmd_start_tx_first_start =
6431         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6432                                  "start");
6433 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6434         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6435                                  tx_first, "tx_first");
6436
6437 cmdline_parse_inst_t cmd_start_tx_first = {
6438         .f = cmd_start_tx_first_parsed,
6439         .data = NULL,
6440         .help_str = "start tx_first: Start packet forwarding, "
6441                 "after sending 1 burst of packets",
6442         .tokens = {
6443                 (void *)&cmd_start_tx_first_start,
6444                 (void *)&cmd_start_tx_first_tx_first,
6445                 NULL,
6446         },
6447 };
6448
6449 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6450 struct cmd_start_tx_first_n_result {
6451         cmdline_fixed_string_t start;
6452         cmdline_fixed_string_t tx_first;
6453         uint32_t tx_num;
6454 };
6455
6456 static void
6457 cmd_start_tx_first_n_parsed(void *parsed_result,
6458                           __attribute__((unused)) struct cmdline *cl,
6459                           __attribute__((unused)) void *data)
6460 {
6461         struct cmd_start_tx_first_n_result *res = parsed_result;
6462
6463         start_packet_forwarding(res->tx_num);
6464 }
6465
6466 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6467         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6468                         start, "start");
6469 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6470         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6471                         tx_first, "tx_first");
6472 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6473         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6474                         tx_num, UINT32);
6475
6476 cmdline_parse_inst_t cmd_start_tx_first_n = {
6477         .f = cmd_start_tx_first_n_parsed,
6478         .data = NULL,
6479         .help_str = "start tx_first <num>: "
6480                 "packet forwarding, after sending <num> bursts of packets",
6481         .tokens = {
6482                 (void *)&cmd_start_tx_first_n_start,
6483                 (void *)&cmd_start_tx_first_n_tx_first,
6484                 (void *)&cmd_start_tx_first_n_tx_num,
6485                 NULL,
6486         },
6487 };
6488
6489 /* *** SET LINK UP *** */
6490 struct cmd_set_link_up_result {
6491         cmdline_fixed_string_t set;
6492         cmdline_fixed_string_t link_up;
6493         cmdline_fixed_string_t port;
6494         portid_t port_id;
6495 };
6496
6497 cmdline_parse_token_string_t cmd_set_link_up_set =
6498         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6499 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6501                                 "link-up");
6502 cmdline_parse_token_string_t cmd_set_link_up_port =
6503         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6504 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6505         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6506
6507 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6508                              __attribute__((unused)) struct cmdline *cl,
6509                              __attribute__((unused)) void *data)
6510 {
6511         struct cmd_set_link_up_result *res = parsed_result;
6512         dev_set_link_up(res->port_id);
6513 }
6514
6515 cmdline_parse_inst_t cmd_set_link_up = {
6516         .f = cmd_set_link_up_parsed,
6517         .data = NULL,
6518         .help_str = "set link-up port <port id>",
6519         .tokens = {
6520                 (void *)&cmd_set_link_up_set,
6521                 (void *)&cmd_set_link_up_link_up,
6522                 (void *)&cmd_set_link_up_port,
6523                 (void *)&cmd_set_link_up_port_id,
6524                 NULL,
6525         },
6526 };
6527
6528 /* *** SET LINK DOWN *** */
6529 struct cmd_set_link_down_result {
6530         cmdline_fixed_string_t set;
6531         cmdline_fixed_string_t link_down;
6532         cmdline_fixed_string_t port;
6533         portid_t port_id;
6534 };
6535
6536 cmdline_parse_token_string_t cmd_set_link_down_set =
6537         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6538 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6539         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6540                                 "link-down");
6541 cmdline_parse_token_string_t cmd_set_link_down_port =
6542         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6543 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6544         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6545
6546 static void cmd_set_link_down_parsed(
6547                                 __attribute__((unused)) void *parsed_result,
6548                                 __attribute__((unused)) struct cmdline *cl,
6549                                 __attribute__((unused)) void *data)
6550 {
6551         struct cmd_set_link_down_result *res = parsed_result;
6552         dev_set_link_down(res->port_id);
6553 }
6554
6555 cmdline_parse_inst_t cmd_set_link_down = {
6556         .f = cmd_set_link_down_parsed,
6557         .data = NULL,
6558         .help_str = "set link-down port <port id>",
6559         .tokens = {
6560                 (void *)&cmd_set_link_down_set,
6561                 (void *)&cmd_set_link_down_link_down,
6562                 (void *)&cmd_set_link_down_port,
6563                 (void *)&cmd_set_link_down_port_id,
6564                 NULL,
6565         },
6566 };
6567
6568 /* *** SHOW CFG *** */
6569 struct cmd_showcfg_result {
6570         cmdline_fixed_string_t show;
6571         cmdline_fixed_string_t cfg;
6572         cmdline_fixed_string_t what;
6573 };
6574
6575 static void cmd_showcfg_parsed(void *parsed_result,
6576                                __attribute__((unused)) struct cmdline *cl,
6577                                __attribute__((unused)) void *data)
6578 {
6579         struct cmd_showcfg_result *res = parsed_result;
6580         if (!strcmp(res->what, "rxtx"))
6581                 rxtx_config_display();
6582         else if (!strcmp(res->what, "cores"))
6583                 fwd_lcores_config_display();
6584         else if (!strcmp(res->what, "fwd"))
6585                 pkt_fwd_config_display(&cur_fwd_config);
6586         else if (!strcmp(res->what, "txpkts"))
6587                 show_tx_pkt_segments();
6588 }
6589
6590 cmdline_parse_token_string_t cmd_showcfg_show =
6591         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6592 cmdline_parse_token_string_t cmd_showcfg_port =
6593         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6594 cmdline_parse_token_string_t cmd_showcfg_what =
6595         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6596                                  "rxtx#cores#fwd#txpkts");
6597
6598 cmdline_parse_inst_t cmd_showcfg = {
6599         .f = cmd_showcfg_parsed,
6600         .data = NULL,
6601         .help_str = "show config rxtx|cores|fwd|txpkts",
6602         .tokens = {
6603                 (void *)&cmd_showcfg_show,
6604                 (void *)&cmd_showcfg_port,
6605                 (void *)&cmd_showcfg_what,
6606                 NULL,
6607         },
6608 };
6609
6610 /* *** SHOW ALL PORT INFO *** */
6611 struct cmd_showportall_result {
6612         cmdline_fixed_string_t show;
6613         cmdline_fixed_string_t port;
6614         cmdline_fixed_string_t what;
6615         cmdline_fixed_string_t all;
6616 };
6617
6618 static void cmd_showportall_parsed(void *parsed_result,
6619                                 __attribute__((unused)) struct cmdline *cl,
6620                                 __attribute__((unused)) void *data)
6621 {
6622         portid_t i;
6623
6624         struct cmd_showportall_result *res = parsed_result;
6625         if (!strcmp(res->show, "clear")) {
6626                 if (!strcmp(res->what, "stats"))
6627                         RTE_ETH_FOREACH_DEV(i)
6628                                 nic_stats_clear(i);
6629                 else if (!strcmp(res->what, "xstats"))
6630                         RTE_ETH_FOREACH_DEV(i)
6631                                 nic_xstats_clear(i);
6632         } else if (!strcmp(res->what, "info"))
6633                 RTE_ETH_FOREACH_DEV(i)
6634                         port_infos_display(i);
6635         else if (!strcmp(res->what, "stats"))
6636                 RTE_ETH_FOREACH_DEV(i)
6637                         nic_stats_display(i);
6638         else if (!strcmp(res->what, "xstats"))
6639                 RTE_ETH_FOREACH_DEV(i)
6640                         nic_xstats_display(i);
6641         else if (!strcmp(res->what, "fdir"))
6642                 RTE_ETH_FOREACH_DEV(i)
6643                         fdir_get_infos(i);
6644         else if (!strcmp(res->what, "stat_qmap"))
6645                 RTE_ETH_FOREACH_DEV(i)
6646                         nic_stats_mapping_display(i);
6647         else if (!strcmp(res->what, "dcb_tc"))
6648                 RTE_ETH_FOREACH_DEV(i)
6649                         port_dcb_info_display(i);
6650         else if (!strcmp(res->what, "cap"))
6651                 RTE_ETH_FOREACH_DEV(i)
6652                         port_offload_cap_display(i);
6653 }
6654
6655 cmdline_parse_token_string_t cmd_showportall_show =
6656         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6657                                  "show#clear");
6658 cmdline_parse_token_string_t cmd_showportall_port =
6659         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6660 cmdline_parse_token_string_t cmd_showportall_what =
6661         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6662                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6663 cmdline_parse_token_string_t cmd_showportall_all =
6664         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6665 cmdline_parse_inst_t cmd_showportall = {
6666         .f = cmd_showportall_parsed,
6667         .data = NULL,
6668         .help_str = "show|clear port "
6669                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6670         .tokens = {
6671                 (void *)&cmd_showportall_show,
6672                 (void *)&cmd_showportall_port,
6673                 (void *)&cmd_showportall_what,
6674                 (void *)&cmd_showportall_all,
6675                 NULL,
6676         },
6677 };
6678
6679 /* *** SHOW PORT INFO *** */
6680 struct cmd_showport_result {
6681         cmdline_fixed_string_t show;
6682         cmdline_fixed_string_t port;
6683         cmdline_fixed_string_t what;
6684         uint16_t portnum;
6685 };
6686
6687 static void cmd_showport_parsed(void *parsed_result,
6688                                 __attribute__((unused)) struct cmdline *cl,
6689                                 __attribute__((unused)) void *data)
6690 {
6691         struct cmd_showport_result *res = parsed_result;
6692         if (!strcmp(res->show, "clear")) {
6693                 if (!strcmp(res->what, "stats"))
6694                         nic_stats_clear(res->portnum);
6695                 else if (!strcmp(res->what, "xstats"))
6696                         nic_xstats_clear(res->portnum);
6697         } else if (!strcmp(res->what, "info"))
6698                 port_infos_display(res->portnum);
6699         else if (!strcmp(res->what, "stats"))
6700                 nic_stats_display(res->portnum);
6701         else if (!strcmp(res->what, "xstats"))
6702                 nic_xstats_display(res->portnum);
6703         else if (!strcmp(res->what, "fdir"))
6704                  fdir_get_infos(res->portnum);
6705         else if (!strcmp(res->what, "stat_qmap"))
6706                 nic_stats_mapping_display(res->portnum);
6707         else if (!strcmp(res->what, "dcb_tc"))
6708                 port_dcb_info_display(res->portnum);
6709         else if (!strcmp(res->what, "cap"))
6710                 port_offload_cap_display(res->portnum);
6711 }
6712
6713 cmdline_parse_token_string_t cmd_showport_show =
6714         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6715                                  "show#clear");
6716 cmdline_parse_token_string_t cmd_showport_port =
6717         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6718 cmdline_parse_token_string_t cmd_showport_what =
6719         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6720                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6721 cmdline_parse_token_num_t cmd_showport_portnum =
6722         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6723
6724 cmdline_parse_inst_t cmd_showport = {
6725         .f = cmd_showport_parsed,
6726         .data = NULL,
6727         .help_str = "show|clear port "
6728                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6729                 "<port_id>",
6730         .tokens = {
6731                 (void *)&cmd_showport_show,
6732                 (void *)&cmd_showport_port,
6733                 (void *)&cmd_showport_what,
6734                 (void *)&cmd_showport_portnum,
6735                 NULL,
6736         },
6737 };
6738
6739 /* *** SHOW QUEUE INFO *** */
6740 struct cmd_showqueue_result {
6741         cmdline_fixed_string_t show;
6742         cmdline_fixed_string_t type;
6743         cmdline_fixed_string_t what;
6744         uint16_t portnum;
6745         uint16_t queuenum;
6746 };
6747
6748 static void
6749 cmd_showqueue_parsed(void *parsed_result,
6750         __attribute__((unused)) struct cmdline *cl,
6751         __attribute__((unused)) void *data)
6752 {
6753         struct cmd_showqueue_result *res = parsed_result;
6754
6755         if (!strcmp(res->type, "rxq"))
6756                 rx_queue_infos_display(res->portnum, res->queuenum);
6757         else if (!strcmp(res->type, "txq"))
6758                 tx_queue_infos_display(res->portnum, res->queuenum);
6759 }
6760
6761 cmdline_parse_token_string_t cmd_showqueue_show =
6762         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6763 cmdline_parse_token_string_t cmd_showqueue_type =
6764         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6765 cmdline_parse_token_string_t cmd_showqueue_what =
6766         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6767 cmdline_parse_token_num_t cmd_showqueue_portnum =
6768         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6769 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6770         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6771
6772 cmdline_parse_inst_t cmd_showqueue = {
6773         .f = cmd_showqueue_parsed,
6774         .data = NULL,
6775         .help_str = "show rxq|txq info <port_id> <queue_id>",
6776         .tokens = {
6777                 (void *)&cmd_showqueue_show,
6778                 (void *)&cmd_showqueue_type,
6779                 (void *)&cmd_showqueue_what,
6780                 (void *)&cmd_showqueue_portnum,
6781                 (void *)&cmd_showqueue_queuenum,
6782                 NULL,
6783         },
6784 };
6785
6786 /* *** READ PORT REGISTER *** */
6787 struct cmd_read_reg_result {
6788         cmdline_fixed_string_t read;
6789         cmdline_fixed_string_t reg;
6790         portid_t port_id;
6791         uint32_t reg_off;
6792 };
6793
6794 static void
6795 cmd_read_reg_parsed(void *parsed_result,
6796                     __attribute__((unused)) struct cmdline *cl,
6797                     __attribute__((unused)) void *data)
6798 {
6799         struct cmd_read_reg_result *res = parsed_result;
6800         port_reg_display(res->port_id, res->reg_off);
6801 }
6802
6803 cmdline_parse_token_string_t cmd_read_reg_read =
6804         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6805 cmdline_parse_token_string_t cmd_read_reg_reg =
6806         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6807 cmdline_parse_token_num_t cmd_read_reg_port_id =
6808         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6809 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6810         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6811
6812 cmdline_parse_inst_t cmd_read_reg = {
6813         .f = cmd_read_reg_parsed,
6814         .data = NULL,
6815         .help_str = "read reg <port_id> <reg_off>",
6816         .tokens = {
6817                 (void *)&cmd_read_reg_read,
6818                 (void *)&cmd_read_reg_reg,
6819                 (void *)&cmd_read_reg_port_id,
6820                 (void *)&cmd_read_reg_reg_off,
6821                 NULL,
6822         },
6823 };
6824
6825 /* *** READ PORT REGISTER BIT FIELD *** */
6826 struct cmd_read_reg_bit_field_result {
6827         cmdline_fixed_string_t read;
6828         cmdline_fixed_string_t regfield;
6829         portid_t port_id;
6830         uint32_t reg_off;
6831         uint8_t bit1_pos;
6832         uint8_t bit2_pos;
6833 };
6834
6835 static void
6836 cmd_read_reg_bit_field_parsed(void *parsed_result,
6837                               __attribute__((unused)) struct cmdline *cl,
6838                               __attribute__((unused)) void *data)
6839 {
6840         struct cmd_read_reg_bit_field_result *res = parsed_result;
6841         port_reg_bit_field_display(res->port_id, res->reg_off,
6842                                    res->bit1_pos, res->bit2_pos);
6843 }
6844
6845 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6846         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6847                                  "read");
6848 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6849         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6850                                  regfield, "regfield");
6851 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6852         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6853                               UINT16);
6854 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6855         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6856                               UINT32);
6857 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6858         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6859                               UINT8);
6860 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6861         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6862                               UINT8);
6863
6864 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6865         .f = cmd_read_reg_bit_field_parsed,
6866         .data = NULL,
6867         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6868         "Read register bit field between bit_x and bit_y included",
6869         .tokens = {
6870                 (void *)&cmd_read_reg_bit_field_read,
6871                 (void *)&cmd_read_reg_bit_field_regfield,
6872                 (void *)&cmd_read_reg_bit_field_port_id,
6873                 (void *)&cmd_read_reg_bit_field_reg_off,
6874                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6875                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6876                 NULL,
6877         },
6878 };
6879
6880 /* *** READ PORT REGISTER BIT *** */
6881 struct cmd_read_reg_bit_result {
6882         cmdline_fixed_string_t read;
6883         cmdline_fixed_string_t regbit;
6884         portid_t port_id;
6885         uint32_t reg_off;
6886         uint8_t bit_pos;
6887 };
6888
6889 static void
6890 cmd_read_reg_bit_parsed(void *parsed_result,
6891                         __attribute__((unused)) struct cmdline *cl,
6892                         __attribute__((unused)) void *data)
6893 {
6894         struct cmd_read_reg_bit_result *res = parsed_result;
6895         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6896 }
6897
6898 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6899         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6900 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6901         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6902                                  regbit, "regbit");
6903 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6904         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6905 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6907 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6908         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6909
6910 cmdline_parse_inst_t cmd_read_reg_bit = {
6911         .f = cmd_read_reg_bit_parsed,
6912         .data = NULL,
6913         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6914         .tokens = {
6915                 (void *)&cmd_read_reg_bit_read,
6916                 (void *)&cmd_read_reg_bit_regbit,
6917                 (void *)&cmd_read_reg_bit_port_id,
6918                 (void *)&cmd_read_reg_bit_reg_off,
6919                 (void *)&cmd_read_reg_bit_bit_pos,
6920                 NULL,
6921         },
6922 };
6923
6924 /* *** WRITE PORT REGISTER *** */
6925 struct cmd_write_reg_result {
6926         cmdline_fixed_string_t write;
6927         cmdline_fixed_string_t reg;
6928         portid_t port_id;
6929         uint32_t reg_off;
6930         uint32_t value;
6931 };
6932
6933 static void
6934 cmd_write_reg_parsed(void *parsed_result,
6935                      __attribute__((unused)) struct cmdline *cl,
6936                      __attribute__((unused)) void *data)
6937 {
6938         struct cmd_write_reg_result *res = parsed_result;
6939         port_reg_set(res->port_id, res->reg_off, res->value);
6940 }
6941
6942 cmdline_parse_token_string_t cmd_write_reg_write =
6943         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6944 cmdline_parse_token_string_t cmd_write_reg_reg =
6945         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6946 cmdline_parse_token_num_t cmd_write_reg_port_id =
6947         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6948 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6949         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6950 cmdline_parse_token_num_t cmd_write_reg_value =
6951         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6952
6953 cmdline_parse_inst_t cmd_write_reg = {
6954         .f = cmd_write_reg_parsed,
6955         .data = NULL,
6956         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6957         .tokens = {
6958                 (void *)&cmd_write_reg_write,
6959                 (void *)&cmd_write_reg_reg,
6960                 (void *)&cmd_write_reg_port_id,
6961                 (void *)&cmd_write_reg_reg_off,
6962                 (void *)&cmd_write_reg_value,
6963                 NULL,
6964         },
6965 };
6966
6967 /* *** WRITE PORT REGISTER BIT FIELD *** */
6968 struct cmd_write_reg_bit_field_result {
6969         cmdline_fixed_string_t write;
6970         cmdline_fixed_string_t regfield;
6971         portid_t port_id;
6972         uint32_t reg_off;
6973         uint8_t bit1_pos;
6974         uint8_t bit2_pos;
6975         uint32_t value;
6976 };
6977
6978 static void
6979 cmd_write_reg_bit_field_parsed(void *parsed_result,
6980                                __attribute__((unused)) struct cmdline *cl,
6981                                __attribute__((unused)) void *data)
6982 {
6983         struct cmd_write_reg_bit_field_result *res = parsed_result;
6984         port_reg_bit_field_set(res->port_id, res->reg_off,
6985                           res->bit1_pos, res->bit2_pos, res->value);
6986 }
6987
6988 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6989         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6990                                  "write");
6991 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6992         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6993                                  regfield, "regfield");
6994 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6995         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6996                               UINT16);
6997 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6998         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6999                               UINT32);
7000 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7001         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7002                               UINT8);
7003 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7004         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7005                               UINT8);
7006 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7007         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7008                               UINT32);
7009
7010 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7011         .f = cmd_write_reg_bit_field_parsed,
7012         .data = NULL,
7013         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7014                 "<reg_value>: "
7015                 "Set register bit field between bit_x and bit_y included",
7016         .tokens = {
7017                 (void *)&cmd_write_reg_bit_field_write,
7018                 (void *)&cmd_write_reg_bit_field_regfield,
7019                 (void *)&cmd_write_reg_bit_field_port_id,
7020                 (void *)&cmd_write_reg_bit_field_reg_off,
7021                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7022                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7023                 (void *)&cmd_write_reg_bit_field_value,
7024                 NULL,
7025         },
7026 };
7027
7028 /* *** WRITE PORT REGISTER BIT *** */
7029 struct cmd_write_reg_bit_result {
7030         cmdline_fixed_string_t write;
7031         cmdline_fixed_string_t regbit;
7032         portid_t port_id;
7033         uint32_t reg_off;
7034         uint8_t bit_pos;
7035         uint8_t value;
7036 };
7037
7038 static void
7039 cmd_write_reg_bit_parsed(void *parsed_result,
7040                          __attribute__((unused)) struct cmdline *cl,
7041                          __attribute__((unused)) void *data)
7042 {
7043         struct cmd_write_reg_bit_result *res = parsed_result;
7044         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7045 }
7046
7047 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7048         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7049                                  "write");
7050 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7051         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7052                                  regbit, "regbit");
7053 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7054         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7055 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7056         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7057 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7059 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7060         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7061
7062 cmdline_parse_inst_t cmd_write_reg_bit = {
7063         .f = cmd_write_reg_bit_parsed,
7064         .data = NULL,
7065         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7066                 "0 <= bit_x <= 31",
7067         .tokens = {
7068                 (void *)&cmd_write_reg_bit_write,
7069                 (void *)&cmd_write_reg_bit_regbit,
7070                 (void *)&cmd_write_reg_bit_port_id,
7071                 (void *)&cmd_write_reg_bit_reg_off,
7072                 (void *)&cmd_write_reg_bit_bit_pos,
7073                 (void *)&cmd_write_reg_bit_value,
7074                 NULL,
7075         },
7076 };
7077
7078 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7079 struct cmd_read_rxd_txd_result {
7080         cmdline_fixed_string_t read;
7081         cmdline_fixed_string_t rxd_txd;
7082         portid_t port_id;
7083         uint16_t queue_id;
7084         uint16_t desc_id;
7085 };
7086
7087 static void
7088 cmd_read_rxd_txd_parsed(void *parsed_result,
7089                         __attribute__((unused)) struct cmdline *cl,
7090                         __attribute__((unused)) void *data)
7091 {
7092         struct cmd_read_rxd_txd_result *res = parsed_result;
7093
7094         if (!strcmp(res->rxd_txd, "rxd"))
7095                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7096         else if (!strcmp(res->rxd_txd, "txd"))
7097                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7098 }
7099
7100 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7101         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7102 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7103         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7104                                  "rxd#txd");
7105 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7106         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7107 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7108         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7109 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7110         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7111
7112 cmdline_parse_inst_t cmd_read_rxd_txd = {
7113         .f = cmd_read_rxd_txd_parsed,
7114         .data = NULL,
7115         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7116         .tokens = {
7117                 (void *)&cmd_read_rxd_txd_read,
7118                 (void *)&cmd_read_rxd_txd_rxd_txd,
7119                 (void *)&cmd_read_rxd_txd_port_id,
7120                 (void *)&cmd_read_rxd_txd_queue_id,
7121                 (void *)&cmd_read_rxd_txd_desc_id,
7122                 NULL,
7123         },
7124 };
7125
7126 /* *** QUIT *** */
7127 struct cmd_quit_result {
7128         cmdline_fixed_string_t quit;
7129 };
7130
7131 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7132                             struct cmdline *cl,
7133                             __attribute__((unused)) void *data)
7134 {
7135         pmd_test_exit();
7136         cmdline_quit(cl);
7137 }
7138
7139 cmdline_parse_token_string_t cmd_quit_quit =
7140         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7141
7142 cmdline_parse_inst_t cmd_quit = {
7143         .f = cmd_quit_parsed,
7144         .data = NULL,
7145         .help_str = "quit: Exit application",
7146         .tokens = {
7147                 (void *)&cmd_quit_quit,
7148                 NULL,
7149         },
7150 };
7151
7152 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7153 struct cmd_mac_addr_result {
7154         cmdline_fixed_string_t mac_addr_cmd;
7155         cmdline_fixed_string_t what;
7156         uint16_t port_num;
7157         struct ether_addr address;
7158 };
7159
7160 static void cmd_mac_addr_parsed(void *parsed_result,
7161                 __attribute__((unused)) struct cmdline *cl,
7162                 __attribute__((unused)) void *data)
7163 {
7164         struct cmd_mac_addr_result *res = parsed_result;
7165         int ret;
7166
7167         if (strcmp(res->what, "add") == 0)
7168                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7169         else if (strcmp(res->what, "set") == 0)
7170                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7171                                                        &res->address);
7172         else
7173                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7174
7175         /* check the return value and print it if is < 0 */
7176         if(ret < 0)
7177                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7178
7179 }
7180
7181 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7182         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7183                                 "mac_addr");
7184 cmdline_parse_token_string_t cmd_mac_addr_what =
7185         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7186                                 "add#remove#set");
7187 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7188                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7189                                         UINT16);
7190 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7191                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7192
7193 cmdline_parse_inst_t cmd_mac_addr = {
7194         .f = cmd_mac_addr_parsed,
7195         .data = (void *)0,
7196         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7197                         "Add/Remove/Set MAC address on port_id",
7198         .tokens = {
7199                 (void *)&cmd_mac_addr_cmd,
7200                 (void *)&cmd_mac_addr_what,
7201                 (void *)&cmd_mac_addr_portnum,
7202                 (void *)&cmd_mac_addr_addr,
7203                 NULL,
7204         },
7205 };
7206
7207 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7208 struct cmd_eth_peer_result {
7209         cmdline_fixed_string_t set;
7210         cmdline_fixed_string_t eth_peer;
7211         portid_t port_id;
7212         cmdline_fixed_string_t peer_addr;
7213 };
7214
7215 static void cmd_set_eth_peer_parsed(void *parsed_result,
7216                         __attribute__((unused)) struct cmdline *cl,
7217                         __attribute__((unused)) void *data)
7218 {
7219                 struct cmd_eth_peer_result *res = parsed_result;
7220
7221                 if (test_done == 0) {
7222                         printf("Please stop forwarding first\n");
7223                         return;
7224                 }
7225                 if (!strcmp(res->eth_peer, "eth-peer")) {
7226                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7227                         fwd_config_setup();
7228                 }
7229 }
7230 cmdline_parse_token_string_t cmd_eth_peer_set =
7231         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7232 cmdline_parse_token_string_t cmd_eth_peer =
7233         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7234 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7235         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7236 cmdline_parse_token_string_t cmd_eth_peer_addr =
7237         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7238
7239 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7240         .f = cmd_set_eth_peer_parsed,
7241         .data = NULL,
7242         .help_str = "set eth-peer <port_id> <peer_mac>",
7243         .tokens = {
7244                 (void *)&cmd_eth_peer_set,
7245                 (void *)&cmd_eth_peer,
7246                 (void *)&cmd_eth_peer_port_id,
7247                 (void *)&cmd_eth_peer_addr,
7248                 NULL,
7249         },
7250 };
7251
7252 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7253 struct cmd_set_qmap_result {
7254         cmdline_fixed_string_t set;
7255         cmdline_fixed_string_t qmap;
7256         cmdline_fixed_string_t what;
7257         portid_t port_id;
7258         uint16_t queue_id;
7259         uint8_t map_value;
7260 };
7261
7262 static void
7263 cmd_set_qmap_parsed(void *parsed_result,
7264                        __attribute__((unused)) struct cmdline *cl,
7265                        __attribute__((unused)) void *data)
7266 {
7267         struct cmd_set_qmap_result *res = parsed_result;
7268         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7269
7270         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7271 }
7272
7273 cmdline_parse_token_string_t cmd_setqmap_set =
7274         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7275                                  set, "set");
7276 cmdline_parse_token_string_t cmd_setqmap_qmap =
7277         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7278                                  qmap, "stat_qmap");
7279 cmdline_parse_token_string_t cmd_setqmap_what =
7280         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7281                                  what, "tx#rx");
7282 cmdline_parse_token_num_t cmd_setqmap_portid =
7283         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7284                               port_id, UINT16);
7285 cmdline_parse_token_num_t cmd_setqmap_queueid =
7286         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7287                               queue_id, UINT16);
7288 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7289         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7290                               map_value, UINT8);
7291
7292 cmdline_parse_inst_t cmd_set_qmap = {
7293         .f = cmd_set_qmap_parsed,
7294         .data = NULL,
7295         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7296                 "Set statistics mapping value on tx|rx queue_id of port_id",
7297         .tokens = {
7298                 (void *)&cmd_setqmap_set,
7299                 (void *)&cmd_setqmap_qmap,
7300                 (void *)&cmd_setqmap_what,
7301                 (void *)&cmd_setqmap_portid,
7302                 (void *)&cmd_setqmap_queueid,
7303                 (void *)&cmd_setqmap_mapvalue,
7304                 NULL,
7305         },
7306 };
7307
7308 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7309 struct cmd_set_xstats_hide_zero_result {
7310         cmdline_fixed_string_t keyword;
7311         cmdline_fixed_string_t name;
7312         cmdline_fixed_string_t on_off;
7313 };
7314
7315 static void
7316 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7317                         __attribute__((unused)) struct cmdline *cl,
7318                         __attribute__((unused)) void *data)
7319 {
7320         struct cmd_set_xstats_hide_zero_result *res;
7321         uint16_t on_off = 0;
7322
7323         res = parsed_result;
7324         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7325         set_xstats_hide_zero(on_off);
7326 }
7327
7328 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7329         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7330                                  keyword, "set");
7331 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7332         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7333                                  name, "xstats-hide-zero");
7334 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7335         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7336                                  on_off, "on#off");
7337
7338 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7339         .f = cmd_set_xstats_hide_zero_parsed,
7340         .data = NULL,
7341         .help_str = "set xstats-hide-zero on|off",
7342         .tokens = {
7343                 (void *)&cmd_set_xstats_hide_zero_keyword,
7344                 (void *)&cmd_set_xstats_hide_zero_name,
7345                 (void *)&cmd_set_xstats_hide_zero_on_off,
7346                 NULL,
7347         },
7348 };
7349
7350 /* *** CONFIGURE UNICAST HASH TABLE *** */
7351 struct cmd_set_uc_hash_table {
7352         cmdline_fixed_string_t set;
7353         cmdline_fixed_string_t port;
7354         portid_t port_id;
7355         cmdline_fixed_string_t what;
7356         struct ether_addr address;
7357         cmdline_fixed_string_t mode;
7358 };
7359
7360 static void
7361 cmd_set_uc_hash_parsed(void *parsed_result,
7362                        __attribute__((unused)) struct cmdline *cl,
7363                        __attribute__((unused)) void *data)
7364 {
7365         int ret=0;
7366         struct cmd_set_uc_hash_table *res = parsed_result;
7367
7368         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7369
7370         if (strcmp(res->what, "uta") == 0)
7371                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7372                                                 &res->address,(uint8_t)is_on);
7373         if (ret < 0)
7374                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7375
7376 }
7377
7378 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7379         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7380                                  set, "set");
7381 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7382         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7383                                  port, "port");
7384 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7385         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7386                               port_id, UINT16);
7387 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7388         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7389                                  what, "uta");
7390 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7391         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7392                                 address);
7393 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7394         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7395                                  mode, "on#off");
7396
7397 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7398         .f = cmd_set_uc_hash_parsed,
7399         .data = NULL,
7400         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7401         .tokens = {
7402                 (void *)&cmd_set_uc_hash_set,
7403                 (void *)&cmd_set_uc_hash_port,
7404                 (void *)&cmd_set_uc_hash_portid,
7405                 (void *)&cmd_set_uc_hash_what,
7406                 (void *)&cmd_set_uc_hash_mac,
7407                 (void *)&cmd_set_uc_hash_mode,
7408                 NULL,
7409         },
7410 };
7411
7412 struct cmd_set_uc_all_hash_table {
7413         cmdline_fixed_string_t set;
7414         cmdline_fixed_string_t port;
7415         portid_t port_id;
7416         cmdline_fixed_string_t what;
7417         cmdline_fixed_string_t value;
7418         cmdline_fixed_string_t mode;
7419 };
7420
7421 static void
7422 cmd_set_uc_all_hash_parsed(void *parsed_result,
7423                        __attribute__((unused)) struct cmdline *cl,
7424                        __attribute__((unused)) void *data)
7425 {
7426         int ret=0;
7427         struct cmd_set_uc_all_hash_table *res = parsed_result;
7428
7429         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7430
7431         if ((strcmp(res->what, "uta") == 0) &&
7432                 (strcmp(res->value, "all") == 0))
7433                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7434         if (ret < 0)
7435                 printf("bad unicast hash table parameter,"
7436                         "return code = %d \n", ret);
7437 }
7438
7439 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7440         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7441                                  set, "set");
7442 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7443         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7444                                  port, "port");
7445 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7446         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7447                               port_id, UINT16);
7448 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7449         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7450                                  what, "uta");
7451 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7452         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7453                                 value,"all");
7454 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7455         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7456                                  mode, "on#off");
7457
7458 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7459         .f = cmd_set_uc_all_hash_parsed,
7460         .data = NULL,
7461         .help_str = "set port <port_id> uta all on|off",
7462         .tokens = {
7463                 (void *)&cmd_set_uc_all_hash_set,
7464                 (void *)&cmd_set_uc_all_hash_port,
7465                 (void *)&cmd_set_uc_all_hash_portid,
7466                 (void *)&cmd_set_uc_all_hash_what,
7467                 (void *)&cmd_set_uc_all_hash_value,
7468                 (void *)&cmd_set_uc_all_hash_mode,
7469                 NULL,
7470         },
7471 };
7472
7473 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7474 struct cmd_set_vf_macvlan_filter {
7475         cmdline_fixed_string_t set;
7476         cmdline_fixed_string_t port;
7477         portid_t port_id;
7478         cmdline_fixed_string_t vf;
7479         uint8_t vf_id;
7480         struct ether_addr address;
7481         cmdline_fixed_string_t filter_type;
7482         cmdline_fixed_string_t mode;
7483 };
7484
7485 static void
7486 cmd_set_vf_macvlan_parsed(void *parsed_result,
7487                        __attribute__((unused)) struct cmdline *cl,
7488                        __attribute__((unused)) void *data)
7489 {
7490         int is_on, ret = 0;
7491         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7492         struct rte_eth_mac_filter filter;
7493
7494         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7495
7496         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7497
7498         /* set VF MAC filter */
7499         filter.is_vf = 1;
7500
7501         /* set VF ID */
7502         filter.dst_id = res->vf_id;
7503
7504         if (!strcmp(res->filter_type, "exact-mac"))
7505                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7506         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7507                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7508         else if (!strcmp(res->filter_type, "hashmac"))
7509                 filter.filter_type = RTE_MAC_HASH_MATCH;
7510         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7511                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7512
7513         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7514
7515         if (is_on)
7516                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7517                                         RTE_ETH_FILTER_MACVLAN,
7518                                         RTE_ETH_FILTER_ADD,
7519                                          &filter);
7520         else
7521                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7522                                         RTE_ETH_FILTER_MACVLAN,
7523                                         RTE_ETH_FILTER_DELETE,
7524                                         &filter);
7525
7526         if (ret < 0)
7527                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7528
7529 }
7530
7531 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7532         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7533                                  set, "set");
7534 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7536                                  port, "port");
7537 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7538         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7539                               port_id, UINT16);
7540 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7542                                  vf, "vf");
7543 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7544         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7545                                 vf_id, UINT8);
7546 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7547         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7548                                 address);
7549 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7550         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7551                                 filter_type, "exact-mac#exact-mac-vlan"
7552                                 "#hashmac#hashmac-vlan");
7553 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7554         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7555                                  mode, "on#off");
7556
7557 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7558         .f = cmd_set_vf_macvlan_parsed,
7559         .data = NULL,
7560         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7561                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7562                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7563                 "hash match rule: hash match of MAC and exact match of VLAN",
7564         .tokens = {
7565                 (void *)&cmd_set_vf_macvlan_set,
7566                 (void *)&cmd_set_vf_macvlan_port,
7567                 (void *)&cmd_set_vf_macvlan_portid,
7568                 (void *)&cmd_set_vf_macvlan_vf,
7569                 (void *)&cmd_set_vf_macvlan_vf_id,
7570                 (void *)&cmd_set_vf_macvlan_mac,
7571                 (void *)&cmd_set_vf_macvlan_filter_type,
7572                 (void *)&cmd_set_vf_macvlan_mode,
7573                 NULL,
7574         },
7575 };
7576
7577 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7578 struct cmd_set_vf_traffic {
7579         cmdline_fixed_string_t set;
7580         cmdline_fixed_string_t port;
7581         portid_t port_id;
7582         cmdline_fixed_string_t vf;
7583         uint8_t vf_id;
7584         cmdline_fixed_string_t what;
7585         cmdline_fixed_string_t mode;
7586 };
7587
7588 static void
7589 cmd_set_vf_traffic_parsed(void *parsed_result,
7590                        __attribute__((unused)) struct cmdline *cl,
7591                        __attribute__((unused)) void *data)
7592 {
7593         struct cmd_set_vf_traffic *res = parsed_result;
7594         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7595         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7596
7597         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7598 }
7599
7600 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7601         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7602                                  set, "set");
7603 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7604         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7605                                  port, "port");
7606 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7607         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7608                               port_id, UINT16);
7609 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7610         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7611                                  vf, "vf");
7612 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7613         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7614                               vf_id, UINT8);
7615 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7616         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7617                                  what, "tx#rx");
7618 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7619         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7620                                  mode, "on#off");
7621
7622 cmdline_parse_inst_t cmd_set_vf_traffic = {
7623         .f = cmd_set_vf_traffic_parsed,
7624         .data = NULL,
7625         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7626         .tokens = {
7627                 (void *)&cmd_setvf_traffic_set,
7628                 (void *)&cmd_setvf_traffic_port,
7629                 (void *)&cmd_setvf_traffic_portid,
7630                 (void *)&cmd_setvf_traffic_vf,
7631                 (void *)&cmd_setvf_traffic_vfid,
7632                 (void *)&cmd_setvf_traffic_what,
7633                 (void *)&cmd_setvf_traffic_mode,
7634                 NULL,
7635         },
7636 };
7637
7638 /* *** CONFIGURE VF RECEIVE MODE *** */
7639 struct cmd_set_vf_rxmode {
7640         cmdline_fixed_string_t set;
7641         cmdline_fixed_string_t port;
7642         portid_t port_id;
7643         cmdline_fixed_string_t vf;
7644         uint8_t vf_id;
7645         cmdline_fixed_string_t what;
7646         cmdline_fixed_string_t mode;
7647         cmdline_fixed_string_t on;
7648 };
7649
7650 static void
7651 cmd_set_vf_rxmode_parsed(void *parsed_result,
7652                        __attribute__((unused)) struct cmdline *cl,
7653                        __attribute__((unused)) void *data)
7654 {
7655         int ret = -ENOTSUP;
7656         uint16_t rx_mode = 0;
7657         struct cmd_set_vf_rxmode *res = parsed_result;
7658
7659         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7660         if (!strcmp(res->what,"rxmode")) {
7661                 if (!strcmp(res->mode, "AUPE"))
7662                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7663                 else if (!strcmp(res->mode, "ROPE"))
7664                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7665                 else if (!strcmp(res->mode, "BAM"))
7666                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7667                 else if (!strncmp(res->mode, "MPE",3))
7668                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7669         }
7670
7671         RTE_SET_USED(is_on);
7672
7673 #ifdef RTE_LIBRTE_IXGBE_PMD
7674         if (ret == -ENOTSUP)
7675                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7676                                                   rx_mode, (uint8_t)is_on);
7677 #endif
7678 #ifdef RTE_LIBRTE_BNXT_PMD
7679         if (ret == -ENOTSUP)
7680                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7681                                                  rx_mode, (uint8_t)is_on);
7682 #endif
7683         if (ret < 0)
7684                 printf("bad VF receive mode parameter, return code = %d \n",
7685                 ret);
7686 }
7687
7688 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7689         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7690                                  set, "set");
7691 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7692         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7693                                  port, "port");
7694 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7695         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7696                               port_id, UINT16);
7697 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7698         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7699                                  vf, "vf");
7700 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7701         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7702                               vf_id, UINT8);
7703 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7704         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7705                                  what, "rxmode");
7706 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7707         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7708                                  mode, "AUPE#ROPE#BAM#MPE");
7709 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7710         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7711                                  on, "on#off");
7712
7713 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7714         .f = cmd_set_vf_rxmode_parsed,
7715         .data = NULL,
7716         .help_str = "set port <port_id> vf <vf_id> rxmode "
7717                 "AUPE|ROPE|BAM|MPE on|off",
7718         .tokens = {
7719                 (void *)&cmd_set_vf_rxmode_set,
7720                 (void *)&cmd_set_vf_rxmode_port,
7721                 (void *)&cmd_set_vf_rxmode_portid,
7722                 (void *)&cmd_set_vf_rxmode_vf,
7723                 (void *)&cmd_set_vf_rxmode_vfid,
7724                 (void *)&cmd_set_vf_rxmode_what,
7725                 (void *)&cmd_set_vf_rxmode_mode,
7726                 (void *)&cmd_set_vf_rxmode_on,
7727                 NULL,
7728         },
7729 };
7730
7731 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7732 struct cmd_vf_mac_addr_result {
7733         cmdline_fixed_string_t mac_addr_cmd;
7734         cmdline_fixed_string_t what;
7735         cmdline_fixed_string_t port;
7736         uint16_t port_num;
7737         cmdline_fixed_string_t vf;
7738         uint8_t vf_num;
7739         struct ether_addr address;
7740 };
7741
7742 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7743                 __attribute__((unused)) struct cmdline *cl,
7744                 __attribute__((unused)) void *data)
7745 {
7746         struct cmd_vf_mac_addr_result *res = parsed_result;
7747         int ret = -ENOTSUP;
7748
7749         if (strcmp(res->what, "add") != 0)
7750                 return;
7751
7752 #ifdef RTE_LIBRTE_I40E_PMD
7753         if (ret == -ENOTSUP)
7754                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7755                                                    &res->address);
7756 #endif
7757 #ifdef RTE_LIBRTE_BNXT_PMD
7758         if (ret == -ENOTSUP)
7759                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7760                                                 res->vf_num);
7761 #endif
7762
7763         if(ret < 0)
7764                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7765
7766 }
7767
7768 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7769         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7770                                 mac_addr_cmd,"mac_addr");
7771 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7772         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7773                                 what,"add");
7774 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7775         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7776                                 port,"port");
7777 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7778         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7779                                 port_num, UINT16);
7780 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7781         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7782                                 vf,"vf");
7783 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7784         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7785                                 vf_num, UINT8);
7786 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7787         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7788                                 address);
7789
7790 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7791         .f = cmd_vf_mac_addr_parsed,
7792         .data = (void *)0,
7793         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7794                 "Add MAC address filtering for a VF on port_id",
7795         .tokens = {
7796                 (void *)&cmd_vf_mac_addr_cmd,
7797                 (void *)&cmd_vf_mac_addr_what,
7798                 (void *)&cmd_vf_mac_addr_port,
7799                 (void *)&cmd_vf_mac_addr_portnum,
7800                 (void *)&cmd_vf_mac_addr_vf,
7801                 (void *)&cmd_vf_mac_addr_vfnum,
7802                 (void *)&cmd_vf_mac_addr_addr,
7803                 NULL,
7804         },
7805 };
7806
7807 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7808 struct cmd_vf_rx_vlan_filter {
7809         cmdline_fixed_string_t rx_vlan;
7810         cmdline_fixed_string_t what;
7811         uint16_t vlan_id;
7812         cmdline_fixed_string_t port;
7813         portid_t port_id;
7814         cmdline_fixed_string_t vf;
7815         uint64_t vf_mask;
7816 };
7817
7818 static void
7819 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7820                           __attribute__((unused)) struct cmdline *cl,
7821                           __attribute__((unused)) void *data)
7822 {
7823         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7824         int ret = -ENOTSUP;
7825
7826         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7827
7828 #ifdef RTE_LIBRTE_IXGBE_PMD
7829         if (ret == -ENOTSUP)
7830                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7831                                 res->vlan_id, res->vf_mask, is_add);
7832 #endif
7833 #ifdef RTE_LIBRTE_I40E_PMD
7834         if (ret == -ENOTSUP)
7835                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7836                                 res->vlan_id, res->vf_mask, is_add);
7837 #endif
7838 #ifdef RTE_LIBRTE_BNXT_PMD
7839         if (ret == -ENOTSUP)
7840                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7841                                 res->vlan_id, res->vf_mask, is_add);
7842 #endif
7843
7844         switch (ret) {
7845         case 0:
7846                 break;
7847         case -EINVAL:
7848                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7849                                 res->vlan_id, res->vf_mask);
7850                 break;
7851         case -ENODEV:
7852                 printf("invalid port_id %d\n", res->port_id);
7853                 break;
7854         case -ENOTSUP:
7855                 printf("function not implemented or supported\n");
7856                 break;
7857         default:
7858                 printf("programming error: (%s)\n", strerror(-ret));
7859         }
7860 }
7861
7862 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7863         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7864                                  rx_vlan, "rx_vlan");
7865 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7866         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7867                                  what, "add#rm");
7868 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7869         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7870                               vlan_id, UINT16);
7871 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7872         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7873                                  port, "port");
7874 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7875         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7876                               port_id, UINT16);
7877 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7878         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7879                                  vf, "vf");
7880 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7881         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7882                               vf_mask, UINT64);
7883
7884 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7885         .f = cmd_vf_rx_vlan_filter_parsed,
7886         .data = NULL,
7887         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7888                 "(vf_mask = hexadecimal VF mask)",
7889         .tokens = {
7890                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7891                 (void *)&cmd_vf_rx_vlan_filter_what,
7892                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7893                 (void *)&cmd_vf_rx_vlan_filter_port,
7894                 (void *)&cmd_vf_rx_vlan_filter_portid,
7895                 (void *)&cmd_vf_rx_vlan_filter_vf,
7896                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7897                 NULL,
7898         },
7899 };
7900
7901 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7902 struct cmd_queue_rate_limit_result {
7903         cmdline_fixed_string_t set;
7904         cmdline_fixed_string_t port;
7905         uint16_t port_num;
7906         cmdline_fixed_string_t queue;
7907         uint8_t queue_num;
7908         cmdline_fixed_string_t rate;
7909         uint16_t rate_num;
7910 };
7911
7912 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7913                 __attribute__((unused)) struct cmdline *cl,
7914                 __attribute__((unused)) void *data)
7915 {
7916         struct cmd_queue_rate_limit_result *res = parsed_result;
7917         int ret = 0;
7918
7919         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7920                 && (strcmp(res->queue, "queue") == 0)
7921                 && (strcmp(res->rate, "rate") == 0))
7922                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7923                                         res->rate_num);
7924         if (ret < 0)
7925                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7926
7927 }
7928
7929 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7930         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7931                                 set, "set");
7932 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7933         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7934                                 port, "port");
7935 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7936         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7937                                 port_num, UINT16);
7938 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7939         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7940                                 queue, "queue");
7941 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7942         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7943                                 queue_num, UINT8);
7944 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7945         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7946                                 rate, "rate");
7947 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7948         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7949                                 rate_num, UINT16);
7950
7951 cmdline_parse_inst_t cmd_queue_rate_limit = {
7952         .f = cmd_queue_rate_limit_parsed,
7953         .data = (void *)0,
7954         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7955                 "Set rate limit for a queue on port_id",
7956         .tokens = {
7957                 (void *)&cmd_queue_rate_limit_set,
7958                 (void *)&cmd_queue_rate_limit_port,
7959                 (void *)&cmd_queue_rate_limit_portnum,
7960                 (void *)&cmd_queue_rate_limit_queue,
7961                 (void *)&cmd_queue_rate_limit_queuenum,
7962                 (void *)&cmd_queue_rate_limit_rate,
7963                 (void *)&cmd_queue_rate_limit_ratenum,
7964                 NULL,
7965         },
7966 };
7967
7968 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7969 struct cmd_vf_rate_limit_result {
7970         cmdline_fixed_string_t set;
7971         cmdline_fixed_string_t port;
7972         uint16_t port_num;
7973         cmdline_fixed_string_t vf;
7974         uint8_t vf_num;
7975         cmdline_fixed_string_t rate;
7976         uint16_t rate_num;
7977         cmdline_fixed_string_t q_msk;
7978         uint64_t q_msk_val;
7979 };
7980
7981 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7982                 __attribute__((unused)) struct cmdline *cl,
7983                 __attribute__((unused)) void *data)
7984 {
7985         struct cmd_vf_rate_limit_result *res = parsed_result;
7986         int ret = 0;
7987
7988         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7989                 && (strcmp(res->vf, "vf") == 0)
7990                 && (strcmp(res->rate, "rate") == 0)
7991                 && (strcmp(res->q_msk, "queue_mask") == 0))
7992                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7993                                         res->rate_num, res->q_msk_val);
7994         if (ret < 0)
7995                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7996
7997 }
7998
7999 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8000         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8001                                 set, "set");
8002 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8003         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8004                                 port, "port");
8005 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8006         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8007                                 port_num, UINT16);
8008 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8009         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8010                                 vf, "vf");
8011 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8012         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8013                                 vf_num, UINT8);
8014 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8015         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8016                                 rate, "rate");
8017 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8018         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8019                                 rate_num, UINT16);
8020 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8021         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8022                                 q_msk, "queue_mask");
8023 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8024         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8025                                 q_msk_val, UINT64);
8026
8027 cmdline_parse_inst_t cmd_vf_rate_limit = {
8028         .f = cmd_vf_rate_limit_parsed,
8029         .data = (void *)0,
8030         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8031                 "queue_mask <queue_mask_value>: "
8032                 "Set rate limit for queues of VF on port_id",
8033         .tokens = {
8034                 (void *)&cmd_vf_rate_limit_set,
8035                 (void *)&cmd_vf_rate_limit_port,
8036                 (void *)&cmd_vf_rate_limit_portnum,
8037                 (void *)&cmd_vf_rate_limit_vf,
8038                 (void *)&cmd_vf_rate_limit_vfnum,
8039                 (void *)&cmd_vf_rate_limit_rate,
8040                 (void *)&cmd_vf_rate_limit_ratenum,
8041                 (void *)&cmd_vf_rate_limit_q_msk,
8042                 (void *)&cmd_vf_rate_limit_q_msk_val,
8043                 NULL,
8044         },
8045 };
8046
8047 /* *** ADD TUNNEL FILTER OF A PORT *** */
8048 struct cmd_tunnel_filter_result {
8049         cmdline_fixed_string_t cmd;
8050         cmdline_fixed_string_t what;
8051         portid_t port_id;
8052         struct ether_addr outer_mac;
8053         struct ether_addr inner_mac;
8054         cmdline_ipaddr_t ip_value;
8055         uint16_t inner_vlan;
8056         cmdline_fixed_string_t tunnel_type;
8057         cmdline_fixed_string_t filter_type;
8058         uint32_t tenant_id;
8059         uint16_t queue_num;
8060 };
8061
8062 static void
8063 cmd_tunnel_filter_parsed(void *parsed_result,
8064                           __attribute__((unused)) struct cmdline *cl,
8065                           __attribute__((unused)) void *data)
8066 {
8067         struct cmd_tunnel_filter_result *res = parsed_result;
8068         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8069         int ret = 0;
8070
8071         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8072
8073         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8074         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8075         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8076
8077         if (res->ip_value.family == AF_INET) {
8078                 tunnel_filter_conf.ip_addr.ipv4_addr =
8079                         res->ip_value.addr.ipv4.s_addr;
8080                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8081         } else {
8082                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8083                         &(res->ip_value.addr.ipv6),
8084                         sizeof(struct in6_addr));
8085                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8086         }
8087
8088         if (!strcmp(res->filter_type, "imac-ivlan"))
8089                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8090         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8091                 tunnel_filter_conf.filter_type =
8092                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8093         else if (!strcmp(res->filter_type, "imac-tenid"))
8094                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8095         else if (!strcmp(res->filter_type, "imac"))
8096                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8097         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8098                 tunnel_filter_conf.filter_type =
8099                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8100         else if (!strcmp(res->filter_type, "oip"))
8101                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8102         else if (!strcmp(res->filter_type, "iip"))
8103                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8104         else {
8105                 printf("The filter type is not supported");
8106                 return;
8107         }
8108
8109         if (!strcmp(res->tunnel_type, "vxlan"))
8110                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8111         else if (!strcmp(res->tunnel_type, "nvgre"))
8112                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8113         else if (!strcmp(res->tunnel_type, "ipingre"))
8114                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8115         else {
8116                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8117                 return;
8118         }
8119
8120         tunnel_filter_conf.tenant_id = res->tenant_id;
8121         tunnel_filter_conf.queue_id = res->queue_num;
8122         if (!strcmp(res->what, "add"))
8123                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8124                                         RTE_ETH_FILTER_TUNNEL,
8125                                         RTE_ETH_FILTER_ADD,
8126                                         &tunnel_filter_conf);
8127         else
8128                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8129                                         RTE_ETH_FILTER_TUNNEL,
8130                                         RTE_ETH_FILTER_DELETE,
8131                                         &tunnel_filter_conf);
8132         if (ret < 0)
8133                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8134                                 strerror(-ret));
8135
8136 }
8137 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8138         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8139         cmd, "tunnel_filter");
8140 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8141         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8142         what, "add#rm");
8143 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8144         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8145         port_id, UINT16);
8146 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8147         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8148         outer_mac);
8149 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8150         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8151         inner_mac);
8152 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8153         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8154         inner_vlan, UINT16);
8155 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8156         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8157         ip_value);
8158 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8159         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8160         tunnel_type, "vxlan#nvgre#ipingre");
8161
8162 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8163         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8164         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8165                 "imac#omac-imac-tenid");
8166 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8167         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8168         tenant_id, UINT32);
8169 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8170         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8171         queue_num, UINT16);
8172
8173 cmdline_parse_inst_t cmd_tunnel_filter = {
8174         .f = cmd_tunnel_filter_parsed,
8175         .data = (void *)0,
8176         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8177                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8178                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8179                 "<queue_id>: Add/Rm tunnel filter of a port",
8180         .tokens = {
8181                 (void *)&cmd_tunnel_filter_cmd,
8182                 (void *)&cmd_tunnel_filter_what,
8183                 (void *)&cmd_tunnel_filter_port_id,
8184                 (void *)&cmd_tunnel_filter_outer_mac,
8185                 (void *)&cmd_tunnel_filter_inner_mac,
8186                 (void *)&cmd_tunnel_filter_ip_value,
8187                 (void *)&cmd_tunnel_filter_innner_vlan,
8188                 (void *)&cmd_tunnel_filter_tunnel_type,
8189                 (void *)&cmd_tunnel_filter_filter_type,
8190                 (void *)&cmd_tunnel_filter_tenant_id,
8191                 (void *)&cmd_tunnel_filter_queue_num,
8192                 NULL,
8193         },
8194 };
8195
8196 /* *** CONFIGURE TUNNEL UDP PORT *** */
8197 struct cmd_tunnel_udp_config {
8198         cmdline_fixed_string_t cmd;
8199         cmdline_fixed_string_t what;
8200         uint16_t udp_port;
8201         portid_t port_id;
8202 };
8203
8204 static void
8205 cmd_tunnel_udp_config_parsed(void *parsed_result,
8206                           __attribute__((unused)) struct cmdline *cl,
8207                           __attribute__((unused)) void *data)
8208 {
8209         struct cmd_tunnel_udp_config *res = parsed_result;
8210         struct rte_eth_udp_tunnel tunnel_udp;
8211         int ret;
8212
8213         tunnel_udp.udp_port = res->udp_port;
8214
8215         if (!strcmp(res->cmd, "rx_vxlan_port"))
8216                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8217
8218         if (!strcmp(res->what, "add"))
8219                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8220                                                       &tunnel_udp);
8221         else
8222                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8223                                                          &tunnel_udp);
8224
8225         if (ret < 0)
8226                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8227 }
8228
8229 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8230         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8231                                 cmd, "rx_vxlan_port");
8232 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8233         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8234                                 what, "add#rm");
8235 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8236         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8237                                 udp_port, UINT16);
8238 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8239         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8240                                 port_id, UINT16);
8241
8242 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8243         .f = cmd_tunnel_udp_config_parsed,
8244         .data = (void *)0,
8245         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8246                 "Add/Remove a tunneling UDP port filter",
8247         .tokens = {
8248                 (void *)&cmd_tunnel_udp_config_cmd,
8249                 (void *)&cmd_tunnel_udp_config_what,
8250                 (void *)&cmd_tunnel_udp_config_udp_port,
8251                 (void *)&cmd_tunnel_udp_config_port_id,
8252                 NULL,
8253         },
8254 };
8255
8256 /* *** GLOBAL CONFIG *** */
8257 struct cmd_global_config_result {
8258         cmdline_fixed_string_t cmd;
8259         portid_t port_id;
8260         cmdline_fixed_string_t cfg_type;
8261         uint8_t len;
8262 };
8263
8264 static void
8265 cmd_global_config_parsed(void *parsed_result,
8266                          __attribute__((unused)) struct cmdline *cl,
8267                          __attribute__((unused)) void *data)
8268 {
8269         struct cmd_global_config_result *res = parsed_result;
8270         struct rte_eth_global_cfg conf;
8271         int ret;
8272
8273         memset(&conf, 0, sizeof(conf));
8274         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8275         conf.cfg.gre_key_len = res->len;
8276         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8277                                       RTE_ETH_FILTER_SET, &conf);
8278         if (ret != 0)
8279                 printf("Global config error\n");
8280 }
8281
8282 cmdline_parse_token_string_t cmd_global_config_cmd =
8283         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8284                 "global_config");
8285 cmdline_parse_token_num_t cmd_global_config_port_id =
8286         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8287                                UINT16);
8288 cmdline_parse_token_string_t cmd_global_config_type =
8289         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8290                 cfg_type, "gre-key-len");
8291 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8292         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8293                 len, UINT8);
8294
8295 cmdline_parse_inst_t cmd_global_config = {
8296         .f = cmd_global_config_parsed,
8297         .data = (void *)NULL,
8298         .help_str = "global_config <port_id> gre-key-len <key_len>",
8299         .tokens = {
8300                 (void *)&cmd_global_config_cmd,
8301                 (void *)&cmd_global_config_port_id,
8302                 (void *)&cmd_global_config_type,
8303                 (void *)&cmd_global_config_gre_key_len,
8304                 NULL,
8305         },
8306 };
8307
8308 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8309 struct cmd_set_mirror_mask_result {
8310         cmdline_fixed_string_t set;
8311         cmdline_fixed_string_t port;
8312         portid_t port_id;
8313         cmdline_fixed_string_t mirror;
8314         uint8_t rule_id;
8315         cmdline_fixed_string_t what;
8316         cmdline_fixed_string_t value;
8317         cmdline_fixed_string_t dstpool;
8318         uint8_t dstpool_id;
8319         cmdline_fixed_string_t on;
8320 };
8321
8322 cmdline_parse_token_string_t cmd_mirror_mask_set =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8324                                 set, "set");
8325 cmdline_parse_token_string_t cmd_mirror_mask_port =
8326         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8327                                 port, "port");
8328 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8329         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8330                                 port_id, UINT16);
8331 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8333                                 mirror, "mirror-rule");
8334 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8335         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8336                                 rule_id, UINT8);
8337 cmdline_parse_token_string_t cmd_mirror_mask_what =
8338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8339                                 what, "pool-mirror-up#pool-mirror-down"
8340                                       "#vlan-mirror");
8341 cmdline_parse_token_string_t cmd_mirror_mask_value =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8343                                 value, NULL);
8344 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8346                                 dstpool, "dst-pool");
8347 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8348         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8349                                 dstpool_id, UINT8);
8350 cmdline_parse_token_string_t cmd_mirror_mask_on =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8352                                 on, "on#off");
8353
8354 static void
8355 cmd_set_mirror_mask_parsed(void *parsed_result,
8356                        __attribute__((unused)) struct cmdline *cl,
8357                        __attribute__((unused)) void *data)
8358 {
8359         int ret,nb_item,i;
8360         struct cmd_set_mirror_mask_result *res = parsed_result;
8361         struct rte_eth_mirror_conf mr_conf;
8362
8363         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8364
8365         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8366
8367         mr_conf.dst_pool = res->dstpool_id;
8368
8369         if (!strcmp(res->what, "pool-mirror-up")) {
8370                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8371                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8372         } else if (!strcmp(res->what, "pool-mirror-down")) {
8373                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8374                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8375         } else if (!strcmp(res->what, "vlan-mirror")) {
8376                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8377                 nb_item = parse_item_list(res->value, "vlan",
8378                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8379                 if (nb_item <= 0)
8380                         return;
8381
8382                 for (i = 0; i < nb_item; i++) {
8383                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8384                                 printf("Invalid vlan_id: must be < 4096\n");
8385                                 return;
8386                         }
8387
8388                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8389                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8390                 }
8391         }
8392
8393         if (!strcmp(res->on, "on"))
8394                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8395                                                 res->rule_id, 1);
8396         else
8397                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8398                                                 res->rule_id, 0);
8399         if (ret < 0)
8400                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8401 }
8402
8403 cmdline_parse_inst_t cmd_set_mirror_mask = {
8404                 .f = cmd_set_mirror_mask_parsed,
8405                 .data = NULL,
8406                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8407                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8408                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8409                 .tokens = {
8410                         (void *)&cmd_mirror_mask_set,
8411                         (void *)&cmd_mirror_mask_port,
8412                         (void *)&cmd_mirror_mask_portid,
8413                         (void *)&cmd_mirror_mask_mirror,
8414                         (void *)&cmd_mirror_mask_ruleid,
8415                         (void *)&cmd_mirror_mask_what,
8416                         (void *)&cmd_mirror_mask_value,
8417                         (void *)&cmd_mirror_mask_dstpool,
8418                         (void *)&cmd_mirror_mask_poolid,
8419                         (void *)&cmd_mirror_mask_on,
8420                         NULL,
8421                 },
8422 };
8423
8424 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8425 struct cmd_set_mirror_link_result {
8426         cmdline_fixed_string_t set;
8427         cmdline_fixed_string_t port;
8428         portid_t port_id;
8429         cmdline_fixed_string_t mirror;
8430         uint8_t rule_id;
8431         cmdline_fixed_string_t what;
8432         cmdline_fixed_string_t dstpool;
8433         uint8_t dstpool_id;
8434         cmdline_fixed_string_t on;
8435 };
8436
8437 cmdline_parse_token_string_t cmd_mirror_link_set =
8438         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8439                                  set, "set");
8440 cmdline_parse_token_string_t cmd_mirror_link_port =
8441         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8442                                 port, "port");
8443 cmdline_parse_token_num_t cmd_mirror_link_portid =
8444         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8445                                 port_id, UINT16);
8446 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8447         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8448                                 mirror, "mirror-rule");
8449 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8450         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8451                             rule_id, UINT8);
8452 cmdline_parse_token_string_t cmd_mirror_link_what =
8453         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8454                                 what, "uplink-mirror#downlink-mirror");
8455 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8456         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8457                                 dstpool, "dst-pool");
8458 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8459         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8460                                 dstpool_id, UINT8);
8461 cmdline_parse_token_string_t cmd_mirror_link_on =
8462         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8463                                 on, "on#off");
8464
8465 static void
8466 cmd_set_mirror_link_parsed(void *parsed_result,
8467                        __attribute__((unused)) struct cmdline *cl,
8468                        __attribute__((unused)) void *data)
8469 {
8470         int ret;
8471         struct cmd_set_mirror_link_result *res = parsed_result;
8472         struct rte_eth_mirror_conf mr_conf;
8473
8474         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8475         if (!strcmp(res->what, "uplink-mirror"))
8476                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8477         else
8478                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8479
8480         mr_conf.dst_pool = res->dstpool_id;
8481
8482         if (!strcmp(res->on, "on"))
8483                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8484                                                 res->rule_id, 1);
8485         else
8486                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8487                                                 res->rule_id, 0);
8488
8489         /* check the return value and print it if is < 0 */
8490         if (ret < 0)
8491                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8492
8493 }
8494
8495 cmdline_parse_inst_t cmd_set_mirror_link = {
8496                 .f = cmd_set_mirror_link_parsed,
8497                 .data = NULL,
8498                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8499                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8500                 .tokens = {
8501                         (void *)&cmd_mirror_link_set,
8502                         (void *)&cmd_mirror_link_port,
8503                         (void *)&cmd_mirror_link_portid,
8504                         (void *)&cmd_mirror_link_mirror,
8505                         (void *)&cmd_mirror_link_ruleid,
8506                         (void *)&cmd_mirror_link_what,
8507                         (void *)&cmd_mirror_link_dstpool,
8508                         (void *)&cmd_mirror_link_poolid,
8509                         (void *)&cmd_mirror_link_on,
8510                         NULL,
8511                 },
8512 };
8513
8514 /* *** RESET VM MIRROR RULE *** */
8515 struct cmd_rm_mirror_rule_result {
8516         cmdline_fixed_string_t reset;
8517         cmdline_fixed_string_t port;
8518         portid_t port_id;
8519         cmdline_fixed_string_t mirror;
8520         uint8_t rule_id;
8521 };
8522
8523 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8524         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8525                                  reset, "reset");
8526 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8527         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8528                                 port, "port");
8529 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8530         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8531                                 port_id, UINT16);
8532 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8533         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8534                                 mirror, "mirror-rule");
8535 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8536         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8537                                 rule_id, UINT8);
8538
8539 static void
8540 cmd_reset_mirror_rule_parsed(void *parsed_result,
8541                        __attribute__((unused)) struct cmdline *cl,
8542                        __attribute__((unused)) void *data)
8543 {
8544         int ret;
8545         struct cmd_set_mirror_link_result *res = parsed_result;
8546         /* check rule_id */
8547         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8548         if(ret < 0)
8549                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8550 }
8551
8552 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8553                 .f = cmd_reset_mirror_rule_parsed,
8554                 .data = NULL,
8555                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8556                 .tokens = {
8557                         (void *)&cmd_rm_mirror_rule_reset,
8558                         (void *)&cmd_rm_mirror_rule_port,
8559                         (void *)&cmd_rm_mirror_rule_portid,
8560                         (void *)&cmd_rm_mirror_rule_mirror,
8561                         (void *)&cmd_rm_mirror_rule_ruleid,
8562                         NULL,
8563                 },
8564 };
8565
8566 /* ******************************************************************************** */
8567
8568 struct cmd_dump_result {
8569         cmdline_fixed_string_t dump;
8570 };
8571
8572 static void
8573 dump_struct_sizes(void)
8574 {
8575 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8576         DUMP_SIZE(struct rte_mbuf);
8577         DUMP_SIZE(struct rte_mempool);
8578         DUMP_SIZE(struct rte_ring);
8579 #undef DUMP_SIZE
8580 }
8581
8582 static void cmd_dump_parsed(void *parsed_result,
8583                             __attribute__((unused)) struct cmdline *cl,
8584                             __attribute__((unused)) void *data)
8585 {
8586         struct cmd_dump_result *res = parsed_result;
8587
8588         if (!strcmp(res->dump, "dump_physmem"))
8589                 rte_dump_physmem_layout(stdout);
8590         else if (!strcmp(res->dump, "dump_memzone"))
8591                 rte_memzone_dump(stdout);
8592         else if (!strcmp(res->dump, "dump_struct_sizes"))
8593                 dump_struct_sizes();
8594         else if (!strcmp(res->dump, "dump_ring"))
8595                 rte_ring_list_dump(stdout);
8596         else if (!strcmp(res->dump, "dump_mempool"))
8597                 rte_mempool_list_dump(stdout);
8598         else if (!strcmp(res->dump, "dump_devargs"))
8599                 rte_eal_devargs_dump(stdout);
8600         else if (!strcmp(res->dump, "dump_log_types"))
8601                 rte_log_dump(stdout);
8602 }
8603
8604 cmdline_parse_token_string_t cmd_dump_dump =
8605         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8606                 "dump_physmem#"
8607                 "dump_memzone#"
8608                 "dump_struct_sizes#"
8609                 "dump_ring#"
8610                 "dump_mempool#"
8611                 "dump_devargs#"
8612                 "dump_log_types");
8613
8614 cmdline_parse_inst_t cmd_dump = {
8615         .f = cmd_dump_parsed,  /* function to call */
8616         .data = NULL,      /* 2nd arg of func */
8617         .help_str = "Dump status",
8618         .tokens = {        /* token list, NULL terminated */
8619                 (void *)&cmd_dump_dump,
8620                 NULL,
8621         },
8622 };
8623
8624 /* ******************************************************************************** */
8625
8626 struct cmd_dump_one_result {
8627         cmdline_fixed_string_t dump;
8628         cmdline_fixed_string_t name;
8629 };
8630
8631 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8632                                 __attribute__((unused)) void *data)
8633 {
8634         struct cmd_dump_one_result *res = parsed_result;
8635
8636         if (!strcmp(res->dump, "dump_ring")) {
8637                 struct rte_ring *r;
8638                 r = rte_ring_lookup(res->name);
8639                 if (r == NULL) {
8640                         cmdline_printf(cl, "Cannot find ring\n");
8641                         return;
8642                 }
8643                 rte_ring_dump(stdout, r);
8644         } else if (!strcmp(res->dump, "dump_mempool")) {
8645                 struct rte_mempool *mp;
8646                 mp = rte_mempool_lookup(res->name);
8647                 if (mp == NULL) {
8648                         cmdline_printf(cl, "Cannot find mempool\n");
8649                         return;
8650                 }
8651                 rte_mempool_dump(stdout, mp);
8652         }
8653 }
8654
8655 cmdline_parse_token_string_t cmd_dump_one_dump =
8656         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8657                                  "dump_ring#dump_mempool");
8658
8659 cmdline_parse_token_string_t cmd_dump_one_name =
8660         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8661
8662 cmdline_parse_inst_t cmd_dump_one = {
8663         .f = cmd_dump_one_parsed,  /* function to call */
8664         .data = NULL,      /* 2nd arg of func */
8665         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8666         .tokens = {        /* token list, NULL terminated */
8667                 (void *)&cmd_dump_one_dump,
8668                 (void *)&cmd_dump_one_name,
8669                 NULL,
8670         },
8671 };
8672
8673 /* *** Add/Del syn filter *** */
8674 struct cmd_syn_filter_result {
8675         cmdline_fixed_string_t filter;
8676         portid_t port_id;
8677         cmdline_fixed_string_t ops;
8678         cmdline_fixed_string_t priority;
8679         cmdline_fixed_string_t high;
8680         cmdline_fixed_string_t queue;
8681         uint16_t queue_id;
8682 };
8683
8684 static void
8685 cmd_syn_filter_parsed(void *parsed_result,
8686                         __attribute__((unused)) struct cmdline *cl,
8687                         __attribute__((unused)) void *data)
8688 {
8689         struct cmd_syn_filter_result *res = parsed_result;
8690         struct rte_eth_syn_filter syn_filter;
8691         int ret = 0;
8692
8693         ret = rte_eth_dev_filter_supported(res->port_id,
8694                                         RTE_ETH_FILTER_SYN);
8695         if (ret < 0) {
8696                 printf("syn filter is not supported on port %u.\n",
8697                                 res->port_id);
8698                 return;
8699         }
8700
8701         memset(&syn_filter, 0, sizeof(syn_filter));
8702
8703         if (!strcmp(res->ops, "add")) {
8704                 if (!strcmp(res->high, "high"))
8705                         syn_filter.hig_pri = 1;
8706                 else
8707                         syn_filter.hig_pri = 0;
8708
8709                 syn_filter.queue = res->queue_id;
8710                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8711                                                 RTE_ETH_FILTER_SYN,
8712                                                 RTE_ETH_FILTER_ADD,
8713                                                 &syn_filter);
8714         } else
8715                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8716                                                 RTE_ETH_FILTER_SYN,
8717                                                 RTE_ETH_FILTER_DELETE,
8718                                                 &syn_filter);
8719
8720         if (ret < 0)
8721                 printf("syn filter programming error: (%s)\n",
8722                                 strerror(-ret));
8723 }
8724
8725 cmdline_parse_token_string_t cmd_syn_filter_filter =
8726         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8727         filter, "syn_filter");
8728 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8729         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8730         port_id, UINT16);
8731 cmdline_parse_token_string_t cmd_syn_filter_ops =
8732         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8733         ops, "add#del");
8734 cmdline_parse_token_string_t cmd_syn_filter_priority =
8735         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8736                                 priority, "priority");
8737 cmdline_parse_token_string_t cmd_syn_filter_high =
8738         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8739                                 high, "high#low");
8740 cmdline_parse_token_string_t cmd_syn_filter_queue =
8741         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8742                                 queue, "queue");
8743 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8744         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8745                                 queue_id, UINT16);
8746
8747 cmdline_parse_inst_t cmd_syn_filter = {
8748         .f = cmd_syn_filter_parsed,
8749         .data = NULL,
8750         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8751                 "<queue_id>: Add/Delete syn filter",
8752         .tokens = {
8753                 (void *)&cmd_syn_filter_filter,
8754                 (void *)&cmd_syn_filter_port_id,
8755                 (void *)&cmd_syn_filter_ops,
8756                 (void *)&cmd_syn_filter_priority,
8757                 (void *)&cmd_syn_filter_high,
8758                 (void *)&cmd_syn_filter_queue,
8759                 (void *)&cmd_syn_filter_queue_id,
8760                 NULL,
8761         },
8762 };
8763
8764 /* *** queue region set *** */
8765 struct cmd_queue_region_result {
8766         cmdline_fixed_string_t set;
8767         cmdline_fixed_string_t port;
8768         portid_t port_id;
8769         cmdline_fixed_string_t cmd;
8770         cmdline_fixed_string_t region;
8771         uint8_t  region_id;
8772         cmdline_fixed_string_t queue_start_index;
8773         uint8_t  queue_id;
8774         cmdline_fixed_string_t queue_num;
8775         uint8_t  queue_num_value;
8776 };
8777
8778 static void
8779 cmd_queue_region_parsed(void *parsed_result,
8780                         __attribute__((unused)) struct cmdline *cl,
8781                         __attribute__((unused)) void *data)
8782 {
8783         struct cmd_queue_region_result *res = parsed_result;
8784         int ret = -ENOTSUP;
8785 #ifdef RTE_LIBRTE_I40E_PMD
8786         struct rte_pmd_i40e_queue_region_conf region_conf;
8787         enum rte_pmd_i40e_queue_region_op op_type;
8788 #endif
8789
8790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8791                 return;
8792
8793 #ifdef RTE_LIBRTE_I40E_PMD
8794         memset(&region_conf, 0, sizeof(region_conf));
8795         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8796         region_conf.region_id = res->region_id;
8797         region_conf.queue_num = res->queue_num_value;
8798         region_conf.queue_start_index = res->queue_id;
8799
8800         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8801                                 op_type, &region_conf);
8802 #endif
8803
8804         switch (ret) {
8805         case 0:
8806                 break;
8807         case -ENOTSUP:
8808                 printf("function not implemented or supported\n");
8809                 break;
8810         default:
8811                 printf("queue region config error: (%s)\n", strerror(-ret));
8812         }
8813 }
8814
8815 cmdline_parse_token_string_t cmd_queue_region_set =
8816 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8817                 set, "set");
8818 cmdline_parse_token_string_t cmd_queue_region_port =
8819         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8820 cmdline_parse_token_num_t cmd_queue_region_port_id =
8821         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8822                                 port_id, UINT16);
8823 cmdline_parse_token_string_t cmd_queue_region_cmd =
8824         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8825                                  cmd, "queue-region");
8826 cmdline_parse_token_string_t cmd_queue_region_id =
8827         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8828                                 region, "region_id");
8829 cmdline_parse_token_num_t cmd_queue_region_index =
8830         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8831                                 region_id, UINT8);
8832 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8833         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8834                                 queue_start_index, "queue_start_index");
8835 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8836         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8837                                 queue_id, UINT8);
8838 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8839         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8840                                 queue_num, "queue_num");
8841 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8842         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8843                                 queue_num_value, UINT8);
8844
8845 cmdline_parse_inst_t cmd_queue_region = {
8846         .f = cmd_queue_region_parsed,
8847         .data = NULL,
8848         .help_str = "set port <port_id> queue-region region_id <value> "
8849                 "queue_start_index <value> queue_num <value>: Set a queue region",
8850         .tokens = {
8851                 (void *)&cmd_queue_region_set,
8852                 (void *)&cmd_queue_region_port,
8853                 (void *)&cmd_queue_region_port_id,
8854                 (void *)&cmd_queue_region_cmd,
8855                 (void *)&cmd_queue_region_id,
8856                 (void *)&cmd_queue_region_index,
8857                 (void *)&cmd_queue_region_queue_start_index,
8858                 (void *)&cmd_queue_region_queue_id,
8859                 (void *)&cmd_queue_region_queue_num,
8860                 (void *)&cmd_queue_region_queue_num_value,
8861                 NULL,
8862         },
8863 };
8864
8865 /* *** queue region and flowtype set *** */
8866 struct cmd_region_flowtype_result {
8867         cmdline_fixed_string_t set;
8868         cmdline_fixed_string_t port;
8869         portid_t port_id;
8870         cmdline_fixed_string_t cmd;
8871         cmdline_fixed_string_t region;
8872         uint8_t  region_id;
8873         cmdline_fixed_string_t flowtype;
8874         uint8_t  flowtype_id;
8875 };
8876
8877 static void
8878 cmd_region_flowtype_parsed(void *parsed_result,
8879                         __attribute__((unused)) struct cmdline *cl,
8880                         __attribute__((unused)) void *data)
8881 {
8882         struct cmd_region_flowtype_result *res = parsed_result;
8883         int ret = -ENOTSUP;
8884 #ifdef RTE_LIBRTE_I40E_PMD
8885         struct rte_pmd_i40e_queue_region_conf region_conf;
8886         enum rte_pmd_i40e_queue_region_op op_type;
8887 #endif
8888
8889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8890                 return;
8891
8892 #ifdef RTE_LIBRTE_I40E_PMD
8893         memset(&region_conf, 0, sizeof(region_conf));
8894
8895         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8896         region_conf.region_id = res->region_id;
8897         region_conf.hw_flowtype = res->flowtype_id;
8898
8899         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8900                         op_type, &region_conf);
8901 #endif
8902
8903         switch (ret) {
8904         case 0:
8905                 break;
8906         case -ENOTSUP:
8907                 printf("function not implemented or supported\n");
8908                 break;
8909         default:
8910                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8911         }
8912 }
8913
8914 cmdline_parse_token_string_t cmd_region_flowtype_set =
8915 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8916                                 set, "set");
8917 cmdline_parse_token_string_t cmd_region_flowtype_port =
8918         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8919                                 port, "port");
8920 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8921         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8922                                 port_id, UINT16);
8923 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8924         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8925                                 cmd, "queue-region");
8926 cmdline_parse_token_string_t cmd_region_flowtype_index =
8927         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8928                                 region, "region_id");
8929 cmdline_parse_token_num_t cmd_region_flowtype_id =
8930         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8931                                 region_id, UINT8);
8932 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8933         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8934                                 flowtype, "flowtype");
8935 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8936         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8937                                 flowtype_id, UINT8);
8938 cmdline_parse_inst_t cmd_region_flowtype = {
8939         .f = cmd_region_flowtype_parsed,
8940         .data = NULL,
8941         .help_str = "set port <port_id> queue-region region_id <value> "
8942                 "flowtype <value>: Set a flowtype region index",
8943         .tokens = {
8944                 (void *)&cmd_region_flowtype_set,
8945                 (void *)&cmd_region_flowtype_port,
8946                 (void *)&cmd_region_flowtype_port_index,
8947                 (void *)&cmd_region_flowtype_cmd,
8948                 (void *)&cmd_region_flowtype_index,
8949                 (void *)&cmd_region_flowtype_id,
8950                 (void *)&cmd_region_flowtype_flow_index,
8951                 (void *)&cmd_region_flowtype_flow_id,
8952                 NULL,
8953         },
8954 };
8955
8956 /* *** User Priority (UP) to queue region (region_id) set *** */
8957 struct cmd_user_priority_region_result {
8958         cmdline_fixed_string_t set;
8959         cmdline_fixed_string_t port;
8960         portid_t port_id;
8961         cmdline_fixed_string_t cmd;
8962         cmdline_fixed_string_t user_priority;
8963         uint8_t  user_priority_id;
8964         cmdline_fixed_string_t region;
8965         uint8_t  region_id;
8966 };
8967
8968 static void
8969 cmd_user_priority_region_parsed(void *parsed_result,
8970                         __attribute__((unused)) struct cmdline *cl,
8971                         __attribute__((unused)) void *data)
8972 {
8973         struct cmd_user_priority_region_result *res = parsed_result;
8974         int ret = -ENOTSUP;
8975 #ifdef RTE_LIBRTE_I40E_PMD
8976         struct rte_pmd_i40e_queue_region_conf region_conf;
8977         enum rte_pmd_i40e_queue_region_op op_type;
8978 #endif
8979
8980         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8981                 return;
8982
8983 #ifdef RTE_LIBRTE_I40E_PMD
8984         memset(&region_conf, 0, sizeof(region_conf));
8985         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8986         region_conf.user_priority = res->user_priority_id;
8987         region_conf.region_id = res->region_id;
8988
8989         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8990                                 op_type, &region_conf);
8991 #endif
8992
8993         switch (ret) {
8994         case 0:
8995                 break;
8996         case -ENOTSUP:
8997                 printf("function not implemented or supported\n");
8998                 break;
8999         default:
9000                 printf("user_priority region config error: (%s)\n",
9001                                 strerror(-ret));
9002         }
9003 }
9004
9005 cmdline_parse_token_string_t cmd_user_priority_region_set =
9006         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9007                                 set, "set");
9008 cmdline_parse_token_string_t cmd_user_priority_region_port =
9009         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9010                                 port, "port");
9011 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9012         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9013                                 port_id, UINT16);
9014 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9015         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9016                                 cmd, "queue-region");
9017 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9018         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9019                                 user_priority, "UP");
9020 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9021         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9022                                 user_priority_id, UINT8);
9023 cmdline_parse_token_string_t cmd_user_priority_region_region =
9024         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9025                                 region, "region_id");
9026 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9027         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9028                                 region_id, UINT8);
9029
9030 cmdline_parse_inst_t cmd_user_priority_region = {
9031         .f = cmd_user_priority_region_parsed,
9032         .data = NULL,
9033         .help_str = "set port <port_id> queue-region UP <value> "
9034                 "region_id <value>: Set the mapping of User Priority (UP) "
9035                 "to queue region (region_id) ",
9036         .tokens = {
9037                 (void *)&cmd_user_priority_region_set,
9038                 (void *)&cmd_user_priority_region_port,
9039                 (void *)&cmd_user_priority_region_port_index,
9040                 (void *)&cmd_user_priority_region_cmd,
9041                 (void *)&cmd_user_priority_region_UP,
9042                 (void *)&cmd_user_priority_region_UP_id,
9043                 (void *)&cmd_user_priority_region_region,
9044                 (void *)&cmd_user_priority_region_region_id,
9045                 NULL,
9046         },
9047 };
9048
9049 /* *** flush all queue region related configuration *** */
9050 struct cmd_flush_queue_region_result {
9051         cmdline_fixed_string_t set;
9052         cmdline_fixed_string_t port;
9053         portid_t port_id;
9054         cmdline_fixed_string_t cmd;
9055         cmdline_fixed_string_t flush;
9056         cmdline_fixed_string_t what;
9057 };
9058
9059 static void
9060 cmd_flush_queue_region_parsed(void *parsed_result,
9061                         __attribute__((unused)) struct cmdline *cl,
9062                         __attribute__((unused)) void *data)
9063 {
9064         struct cmd_flush_queue_region_result *res = parsed_result;
9065         int ret = -ENOTSUP;
9066 #ifdef RTE_LIBRTE_I40E_PMD
9067         struct rte_pmd_i40e_queue_region_conf region_conf;
9068         enum rte_pmd_i40e_queue_region_op op_type;
9069 #endif
9070
9071         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9072                 return;
9073
9074 #ifdef RTE_LIBRTE_I40E_PMD
9075         memset(&region_conf, 0, sizeof(region_conf));
9076
9077         if (strcmp(res->what, "on") == 0)
9078                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9079         else
9080                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9081
9082         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9083                                 op_type, &region_conf);
9084 #endif
9085
9086         switch (ret) {
9087         case 0:
9088                 break;
9089         case -ENOTSUP:
9090                 printf("function not implemented or supported\n");
9091                 break;
9092         default:
9093                 printf("queue region config flush error: (%s)\n",
9094                                 strerror(-ret));
9095         }
9096 }
9097
9098 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9099         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9100                                 set, "set");
9101 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9102         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9103                                 port, "port");
9104 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9105         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9106                                 port_id, UINT16);
9107 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9108         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9109                                 cmd, "queue-region");
9110 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9111         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9112                                 flush, "flush");
9113 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9114         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9115                                 what, "on#off");
9116
9117 cmdline_parse_inst_t cmd_flush_queue_region = {
9118         .f = cmd_flush_queue_region_parsed,
9119         .data = NULL,
9120         .help_str = "set port <port_id> queue-region flush on|off"
9121                 ": flush all queue region related configuration",
9122         .tokens = {
9123                 (void *)&cmd_flush_queue_region_set,
9124                 (void *)&cmd_flush_queue_region_port,
9125                 (void *)&cmd_flush_queue_region_port_index,
9126                 (void *)&cmd_flush_queue_region_cmd,
9127                 (void *)&cmd_flush_queue_region_flush,
9128                 (void *)&cmd_flush_queue_region_what,
9129                 NULL,
9130         },
9131 };
9132
9133 /* *** get all queue region related configuration info *** */
9134 struct cmd_show_queue_region_info {
9135         cmdline_fixed_string_t show;
9136         cmdline_fixed_string_t port;
9137         portid_t port_id;
9138         cmdline_fixed_string_t cmd;
9139 };
9140
9141 static void
9142 cmd_show_queue_region_info_parsed(void *parsed_result,
9143                         __attribute__((unused)) struct cmdline *cl,
9144                         __attribute__((unused)) void *data)
9145 {
9146         struct cmd_show_queue_region_info *res = parsed_result;
9147         int ret = -ENOTSUP;
9148 #ifdef RTE_LIBRTE_I40E_PMD
9149         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9150         enum rte_pmd_i40e_queue_region_op op_type;
9151 #endif
9152
9153         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9154                 return;
9155
9156 #ifdef RTE_LIBRTE_I40E_PMD
9157         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9158
9159         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9160
9161         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9162                                         op_type, &rte_pmd_regions);
9163
9164         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9165 #endif
9166
9167         switch (ret) {
9168         case 0:
9169                 break;
9170         case -ENOTSUP:
9171                 printf("function not implemented or supported\n");
9172                 break;
9173         default:
9174                 printf("queue region config info show error: (%s)\n",
9175                                 strerror(-ret));
9176         }
9177 }
9178
9179 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9180 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9181                                 show, "show");
9182 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9183         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9184                                 port, "port");
9185 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9186         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9187                                 port_id, UINT16);
9188 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9189         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9190                                 cmd, "queue-region");
9191
9192 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9193         .f = cmd_show_queue_region_info_parsed,
9194         .data = NULL,
9195         .help_str = "show port <port_id> queue-region"
9196                 ": show all queue region related configuration info",
9197         .tokens = {
9198                 (void *)&cmd_show_queue_region_info_get,
9199                 (void *)&cmd_show_queue_region_info_port,
9200                 (void *)&cmd_show_queue_region_info_port_index,
9201                 (void *)&cmd_show_queue_region_info_cmd,
9202                 NULL,
9203         },
9204 };
9205
9206 /* *** ADD/REMOVE A 2tuple FILTER *** */
9207 struct cmd_2tuple_filter_result {
9208         cmdline_fixed_string_t filter;
9209         portid_t port_id;
9210         cmdline_fixed_string_t ops;
9211         cmdline_fixed_string_t dst_port;
9212         uint16_t dst_port_value;
9213         cmdline_fixed_string_t protocol;
9214         uint8_t protocol_value;
9215         cmdline_fixed_string_t mask;
9216         uint8_t  mask_value;
9217         cmdline_fixed_string_t tcp_flags;
9218         uint8_t tcp_flags_value;
9219         cmdline_fixed_string_t priority;
9220         uint8_t  priority_value;
9221         cmdline_fixed_string_t queue;
9222         uint16_t  queue_id;
9223 };
9224
9225 static void
9226 cmd_2tuple_filter_parsed(void *parsed_result,
9227                         __attribute__((unused)) struct cmdline *cl,
9228                         __attribute__((unused)) void *data)
9229 {
9230         struct rte_eth_ntuple_filter filter;
9231         struct cmd_2tuple_filter_result *res = parsed_result;
9232         int ret = 0;
9233
9234         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9235         if (ret < 0) {
9236                 printf("ntuple filter is not supported on port %u.\n",
9237                         res->port_id);
9238                 return;
9239         }
9240
9241         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9242
9243         filter.flags = RTE_2TUPLE_FLAGS;
9244         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9245         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9246         filter.proto = res->protocol_value;
9247         filter.priority = res->priority_value;
9248         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9249                 printf("nonzero tcp_flags is only meaningful"
9250                         " when protocol is TCP.\n");
9251                 return;
9252         }
9253         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9254                 printf("invalid TCP flags.\n");
9255                 return;
9256         }
9257
9258         if (res->tcp_flags_value != 0) {
9259                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9260                 filter.tcp_flags = res->tcp_flags_value;
9261         }
9262
9263         /* need convert to big endian. */
9264         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9265         filter.queue = res->queue_id;
9266
9267         if (!strcmp(res->ops, "add"))
9268                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9269                                 RTE_ETH_FILTER_NTUPLE,
9270                                 RTE_ETH_FILTER_ADD,
9271                                 &filter);
9272         else
9273                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9274                                 RTE_ETH_FILTER_NTUPLE,
9275                                 RTE_ETH_FILTER_DELETE,
9276                                 &filter);
9277         if (ret < 0)
9278                 printf("2tuple filter programming error: (%s)\n",
9279                         strerror(-ret));
9280
9281 }
9282
9283 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9284         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9285                                  filter, "2tuple_filter");
9286 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9287         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9288                                 port_id, UINT16);
9289 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9290         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9291                                  ops, "add#del");
9292 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9293         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9294                                 dst_port, "dst_port");
9295 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9296         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9297                                 dst_port_value, UINT16);
9298 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9299         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9300                                 protocol, "protocol");
9301 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9302         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9303                                 protocol_value, UINT8);
9304 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9305         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9306                                 mask, "mask");
9307 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9308         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9309                                 mask_value, INT8);
9310 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9311         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9312                                 tcp_flags, "tcp_flags");
9313 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9314         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9315                                 tcp_flags_value, UINT8);
9316 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9317         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9318                                 priority, "priority");
9319 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9320         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9321                                 priority_value, UINT8);
9322 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9323         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9324                                 queue, "queue");
9325 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9326         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9327                                 queue_id, UINT16);
9328
9329 cmdline_parse_inst_t cmd_2tuple_filter = {
9330         .f = cmd_2tuple_filter_parsed,
9331         .data = NULL,
9332         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9333                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9334                 "<queue_id>: Add a 2tuple filter",
9335         .tokens = {
9336                 (void *)&cmd_2tuple_filter_filter,
9337                 (void *)&cmd_2tuple_filter_port_id,
9338                 (void *)&cmd_2tuple_filter_ops,
9339                 (void *)&cmd_2tuple_filter_dst_port,
9340                 (void *)&cmd_2tuple_filter_dst_port_value,
9341                 (void *)&cmd_2tuple_filter_protocol,
9342                 (void *)&cmd_2tuple_filter_protocol_value,
9343                 (void *)&cmd_2tuple_filter_mask,
9344                 (void *)&cmd_2tuple_filter_mask_value,
9345                 (void *)&cmd_2tuple_filter_tcp_flags,
9346                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9347                 (void *)&cmd_2tuple_filter_priority,
9348                 (void *)&cmd_2tuple_filter_priority_value,
9349                 (void *)&cmd_2tuple_filter_queue,
9350                 (void *)&cmd_2tuple_filter_queue_id,
9351                 NULL,
9352         },
9353 };
9354
9355 /* *** ADD/REMOVE A 5tuple FILTER *** */
9356 struct cmd_5tuple_filter_result {
9357         cmdline_fixed_string_t filter;
9358         portid_t port_id;
9359         cmdline_fixed_string_t ops;
9360         cmdline_fixed_string_t dst_ip;
9361         cmdline_ipaddr_t dst_ip_value;
9362         cmdline_fixed_string_t src_ip;
9363         cmdline_ipaddr_t src_ip_value;
9364         cmdline_fixed_string_t dst_port;
9365         uint16_t dst_port_value;
9366         cmdline_fixed_string_t src_port;
9367         uint16_t src_port_value;
9368         cmdline_fixed_string_t protocol;
9369         uint8_t protocol_value;
9370         cmdline_fixed_string_t mask;
9371         uint8_t  mask_value;
9372         cmdline_fixed_string_t tcp_flags;
9373         uint8_t tcp_flags_value;
9374         cmdline_fixed_string_t priority;
9375         uint8_t  priority_value;
9376         cmdline_fixed_string_t queue;
9377         uint16_t  queue_id;
9378 };
9379
9380 static void
9381 cmd_5tuple_filter_parsed(void *parsed_result,
9382                         __attribute__((unused)) struct cmdline *cl,
9383                         __attribute__((unused)) void *data)
9384 {
9385         struct rte_eth_ntuple_filter filter;
9386         struct cmd_5tuple_filter_result *res = parsed_result;
9387         int ret = 0;
9388
9389         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9390         if (ret < 0) {
9391                 printf("ntuple filter is not supported on port %u.\n",
9392                         res->port_id);
9393                 return;
9394         }
9395
9396         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9397
9398         filter.flags = RTE_5TUPLE_FLAGS;
9399         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9400         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9401         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9402         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9403         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9404         filter.proto = res->protocol_value;
9405         filter.priority = res->priority_value;
9406         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9407                 printf("nonzero tcp_flags is only meaningful"
9408                         " when protocol is TCP.\n");
9409                 return;
9410         }
9411         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9412                 printf("invalid TCP flags.\n");
9413                 return;
9414         }
9415
9416         if (res->tcp_flags_value != 0) {
9417                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9418                 filter.tcp_flags = res->tcp_flags_value;
9419         }
9420
9421         if (res->dst_ip_value.family == AF_INET)
9422                 /* no need to convert, already big endian. */
9423                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9424         else {
9425                 if (filter.dst_ip_mask == 0) {
9426                         printf("can not support ipv6 involved compare.\n");
9427                         return;
9428                 }
9429                 filter.dst_ip = 0;
9430         }
9431
9432         if (res->src_ip_value.family == AF_INET)
9433                 /* no need to convert, already big endian. */
9434                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9435         else {
9436                 if (filter.src_ip_mask == 0) {
9437                         printf("can not support ipv6 involved compare.\n");
9438                         return;
9439                 }
9440                 filter.src_ip = 0;
9441         }
9442         /* need convert to big endian. */
9443         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9444         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9445         filter.queue = res->queue_id;
9446
9447         if (!strcmp(res->ops, "add"))
9448                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9449                                 RTE_ETH_FILTER_NTUPLE,
9450                                 RTE_ETH_FILTER_ADD,
9451                                 &filter);
9452         else
9453                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9454                                 RTE_ETH_FILTER_NTUPLE,
9455                                 RTE_ETH_FILTER_DELETE,
9456                                 &filter);
9457         if (ret < 0)
9458                 printf("5tuple filter programming error: (%s)\n",
9459                         strerror(-ret));
9460 }
9461
9462 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9463         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9464                                  filter, "5tuple_filter");
9465 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9466         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9467                                 port_id, UINT16);
9468 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9469         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9470                                  ops, "add#del");
9471 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9472         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9473                                 dst_ip, "dst_ip");
9474 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9475         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9476                                 dst_ip_value);
9477 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9478         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9479                                 src_ip, "src_ip");
9480 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9481         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9482                                 src_ip_value);
9483 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9484         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9485                                 dst_port, "dst_port");
9486 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9487         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9488                                 dst_port_value, UINT16);
9489 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9490         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9491                                 src_port, "src_port");
9492 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9493         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9494                                 src_port_value, UINT16);
9495 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9496         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9497                                 protocol, "protocol");
9498 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9499         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9500                                 protocol_value, UINT8);
9501 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9502         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9503                                 mask, "mask");
9504 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9505         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9506                                 mask_value, INT8);
9507 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9508         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9509                                 tcp_flags, "tcp_flags");
9510 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9511         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9512                                 tcp_flags_value, UINT8);
9513 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9514         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9515                                 priority, "priority");
9516 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9517         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9518                                 priority_value, UINT8);
9519 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9520         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9521                                 queue, "queue");
9522 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9523         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9524                                 queue_id, UINT16);
9525
9526 cmdline_parse_inst_t cmd_5tuple_filter = {
9527         .f = cmd_5tuple_filter_parsed,
9528         .data = NULL,
9529         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9530                 "src_ip <value> dst_port <value> src_port <value> "
9531                 "protocol <value>  mask <value> tcp_flags <value> "
9532                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9533         .tokens = {
9534                 (void *)&cmd_5tuple_filter_filter,
9535                 (void *)&cmd_5tuple_filter_port_id,
9536                 (void *)&cmd_5tuple_filter_ops,
9537                 (void *)&cmd_5tuple_filter_dst_ip,
9538                 (void *)&cmd_5tuple_filter_dst_ip_value,
9539                 (void *)&cmd_5tuple_filter_src_ip,
9540                 (void *)&cmd_5tuple_filter_src_ip_value,
9541                 (void *)&cmd_5tuple_filter_dst_port,
9542                 (void *)&cmd_5tuple_filter_dst_port_value,
9543                 (void *)&cmd_5tuple_filter_src_port,
9544                 (void *)&cmd_5tuple_filter_src_port_value,
9545                 (void *)&cmd_5tuple_filter_protocol,
9546                 (void *)&cmd_5tuple_filter_protocol_value,
9547                 (void *)&cmd_5tuple_filter_mask,
9548                 (void *)&cmd_5tuple_filter_mask_value,
9549                 (void *)&cmd_5tuple_filter_tcp_flags,
9550                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9551                 (void *)&cmd_5tuple_filter_priority,
9552                 (void *)&cmd_5tuple_filter_priority_value,
9553                 (void *)&cmd_5tuple_filter_queue,
9554                 (void *)&cmd_5tuple_filter_queue_id,
9555                 NULL,
9556         },
9557 };
9558
9559 /* *** ADD/REMOVE A flex FILTER *** */
9560 struct cmd_flex_filter_result {
9561         cmdline_fixed_string_t filter;
9562         cmdline_fixed_string_t ops;
9563         portid_t port_id;
9564         cmdline_fixed_string_t len;
9565         uint8_t len_value;
9566         cmdline_fixed_string_t bytes;
9567         cmdline_fixed_string_t bytes_value;
9568         cmdline_fixed_string_t mask;
9569         cmdline_fixed_string_t mask_value;
9570         cmdline_fixed_string_t priority;
9571         uint8_t priority_value;
9572         cmdline_fixed_string_t queue;
9573         uint16_t queue_id;
9574 };
9575
9576 static int xdigit2val(unsigned char c)
9577 {
9578         int val;
9579         if (isdigit(c))
9580                 val = c - '0';
9581         else if (isupper(c))
9582                 val = c - 'A' + 10;
9583         else
9584                 val = c - 'a' + 10;
9585         return val;
9586 }
9587
9588 static void
9589 cmd_flex_filter_parsed(void *parsed_result,
9590                           __attribute__((unused)) struct cmdline *cl,
9591                           __attribute__((unused)) void *data)
9592 {
9593         int ret = 0;
9594         struct rte_eth_flex_filter filter;
9595         struct cmd_flex_filter_result *res = parsed_result;
9596         char *bytes_ptr, *mask_ptr;
9597         uint16_t len, i, j = 0;
9598         char c;
9599         int val;
9600         uint8_t byte = 0;
9601
9602         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9603                 printf("the len exceed the max length 128\n");
9604                 return;
9605         }
9606         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9607         filter.len = res->len_value;
9608         filter.priority = res->priority_value;
9609         filter.queue = res->queue_id;
9610         bytes_ptr = res->bytes_value;
9611         mask_ptr = res->mask_value;
9612
9613          /* translate bytes string to array. */
9614         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9615                 (bytes_ptr[1] == 'X')))
9616                 bytes_ptr += 2;
9617         len = strnlen(bytes_ptr, res->len_value * 2);
9618         if (len == 0 || (len % 8 != 0)) {
9619                 printf("please check len and bytes input\n");
9620                 return;
9621         }
9622         for (i = 0; i < len; i++) {
9623                 c = bytes_ptr[i];
9624                 if (isxdigit(c) == 0) {
9625                         /* invalid characters. */
9626                         printf("invalid input\n");
9627                         return;
9628                 }
9629                 val = xdigit2val(c);
9630                 if (i % 2) {
9631                         byte |= val;
9632                         filter.bytes[j] = byte;
9633                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9634                         j++;
9635                         byte = 0;
9636                 } else
9637                         byte |= val << 4;
9638         }
9639         printf("\n");
9640          /* translate mask string to uint8_t array. */
9641         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9642                 (mask_ptr[1] == 'X')))
9643                 mask_ptr += 2;
9644         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9645         if (len == 0) {
9646                 printf("invalid input\n");
9647                 return;
9648         }
9649         j = 0;
9650         byte = 0;
9651         for (i = 0; i < len; i++) {
9652                 c = mask_ptr[i];
9653                 if (isxdigit(c) == 0) {
9654                         /* invalid characters. */
9655                         printf("invalid input\n");
9656                         return;
9657                 }
9658                 val = xdigit2val(c);
9659                 if (i % 2) {
9660                         byte |= val;
9661                         filter.mask[j] = byte;
9662                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9663                         j++;
9664                         byte = 0;
9665                 } else
9666                         byte |= val << 4;
9667         }
9668         printf("\n");
9669
9670         if (!strcmp(res->ops, "add"))
9671                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9672                                 RTE_ETH_FILTER_FLEXIBLE,
9673                                 RTE_ETH_FILTER_ADD,
9674                                 &filter);
9675         else
9676                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9677                                 RTE_ETH_FILTER_FLEXIBLE,
9678                                 RTE_ETH_FILTER_DELETE,
9679                                 &filter);
9680
9681         if (ret < 0)
9682                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9683 }
9684
9685 cmdline_parse_token_string_t cmd_flex_filter_filter =
9686         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9687                                 filter, "flex_filter");
9688 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9689         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9690                                 port_id, UINT16);
9691 cmdline_parse_token_string_t cmd_flex_filter_ops =
9692         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9693                                 ops, "add#del");
9694 cmdline_parse_token_string_t cmd_flex_filter_len =
9695         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9696                                 len, "len");
9697 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9698         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9699                                 len_value, UINT8);
9700 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9701         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9702                                 bytes, "bytes");
9703 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9704         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9705                                 bytes_value, NULL);
9706 cmdline_parse_token_string_t cmd_flex_filter_mask =
9707         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9708                                 mask, "mask");
9709 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9710         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9711                                 mask_value, NULL);
9712 cmdline_parse_token_string_t cmd_flex_filter_priority =
9713         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9714                                 priority, "priority");
9715 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9716         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9717                                 priority_value, UINT8);
9718 cmdline_parse_token_string_t cmd_flex_filter_queue =
9719         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9720                                 queue, "queue");
9721 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9722         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9723                                 queue_id, UINT16);
9724 cmdline_parse_inst_t cmd_flex_filter = {
9725         .f = cmd_flex_filter_parsed,
9726         .data = NULL,
9727         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9728                 "<value> mask <value> priority <value> queue <queue_id>: "
9729                 "Add/Del a flex filter",
9730         .tokens = {
9731                 (void *)&cmd_flex_filter_filter,
9732                 (void *)&cmd_flex_filter_port_id,
9733                 (void *)&cmd_flex_filter_ops,
9734                 (void *)&cmd_flex_filter_len,
9735                 (void *)&cmd_flex_filter_len_value,
9736                 (void *)&cmd_flex_filter_bytes,
9737                 (void *)&cmd_flex_filter_bytes_value,
9738                 (void *)&cmd_flex_filter_mask,
9739                 (void *)&cmd_flex_filter_mask_value,
9740                 (void *)&cmd_flex_filter_priority,
9741                 (void *)&cmd_flex_filter_priority_value,
9742                 (void *)&cmd_flex_filter_queue,
9743                 (void *)&cmd_flex_filter_queue_id,
9744                 NULL,
9745         },
9746 };
9747
9748 /* *** Filters Control *** */
9749
9750 /* *** deal with ethertype filter *** */
9751 struct cmd_ethertype_filter_result {
9752         cmdline_fixed_string_t filter;
9753         portid_t port_id;
9754         cmdline_fixed_string_t ops;
9755         cmdline_fixed_string_t mac;
9756         struct ether_addr mac_addr;
9757         cmdline_fixed_string_t ethertype;
9758         uint16_t ethertype_value;
9759         cmdline_fixed_string_t drop;
9760         cmdline_fixed_string_t queue;
9761         uint16_t  queue_id;
9762 };
9763
9764 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9765         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9766                                  filter, "ethertype_filter");
9767 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9768         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9769                               port_id, UINT16);
9770 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9771         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9772                                  ops, "add#del");
9773 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9774         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9775                                  mac, "mac_addr#mac_ignr");
9776 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9777         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9778                                      mac_addr);
9779 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9780         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9781                                  ethertype, "ethertype");
9782 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9783         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9784                               ethertype_value, UINT16);
9785 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9786         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9787                                  drop, "drop#fwd");
9788 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9789         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9790                                  queue, "queue");
9791 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9792         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9793                               queue_id, UINT16);
9794
9795 static void
9796 cmd_ethertype_filter_parsed(void *parsed_result,
9797                           __attribute__((unused)) struct cmdline *cl,
9798                           __attribute__((unused)) void *data)
9799 {
9800         struct cmd_ethertype_filter_result *res = parsed_result;
9801         struct rte_eth_ethertype_filter filter;
9802         int ret = 0;
9803
9804         ret = rte_eth_dev_filter_supported(res->port_id,
9805                         RTE_ETH_FILTER_ETHERTYPE);
9806         if (ret < 0) {
9807                 printf("ethertype filter is not supported on port %u.\n",
9808                         res->port_id);
9809                 return;
9810         }
9811
9812         memset(&filter, 0, sizeof(filter));
9813         if (!strcmp(res->mac, "mac_addr")) {
9814                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9815                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9816                         sizeof(struct ether_addr));
9817         }
9818         if (!strcmp(res->drop, "drop"))
9819                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9820         filter.ether_type = res->ethertype_value;
9821         filter.queue = res->queue_id;
9822
9823         if (!strcmp(res->ops, "add"))
9824                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9825                                 RTE_ETH_FILTER_ETHERTYPE,
9826                                 RTE_ETH_FILTER_ADD,
9827                                 &filter);
9828         else
9829                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9830                                 RTE_ETH_FILTER_ETHERTYPE,
9831                                 RTE_ETH_FILTER_DELETE,
9832                                 &filter);
9833         if (ret < 0)
9834                 printf("ethertype filter programming error: (%s)\n",
9835                         strerror(-ret));
9836 }
9837
9838 cmdline_parse_inst_t cmd_ethertype_filter = {
9839         .f = cmd_ethertype_filter_parsed,
9840         .data = NULL,
9841         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9842                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9843                 "Add or delete an ethertype filter entry",
9844         .tokens = {
9845                 (void *)&cmd_ethertype_filter_filter,
9846                 (void *)&cmd_ethertype_filter_port_id,
9847                 (void *)&cmd_ethertype_filter_ops,
9848                 (void *)&cmd_ethertype_filter_mac,
9849                 (void *)&cmd_ethertype_filter_mac_addr,
9850                 (void *)&cmd_ethertype_filter_ethertype,
9851                 (void *)&cmd_ethertype_filter_ethertype_value,
9852                 (void *)&cmd_ethertype_filter_drop,
9853                 (void *)&cmd_ethertype_filter_queue,
9854                 (void *)&cmd_ethertype_filter_queue_id,
9855                 NULL,
9856         },
9857 };
9858
9859 /* *** deal with flow director filter *** */
9860 struct cmd_flow_director_result {
9861         cmdline_fixed_string_t flow_director_filter;
9862         portid_t port_id;
9863         cmdline_fixed_string_t mode;
9864         cmdline_fixed_string_t mode_value;
9865         cmdline_fixed_string_t ops;
9866         cmdline_fixed_string_t flow;
9867         cmdline_fixed_string_t flow_type;
9868         cmdline_fixed_string_t ether;
9869         uint16_t ether_type;
9870         cmdline_fixed_string_t src;
9871         cmdline_ipaddr_t ip_src;
9872         uint16_t port_src;
9873         cmdline_fixed_string_t dst;
9874         cmdline_ipaddr_t ip_dst;
9875         uint16_t port_dst;
9876         cmdline_fixed_string_t verify_tag;
9877         uint32_t verify_tag_value;
9878         cmdline_ipaddr_t tos;
9879         uint8_t tos_value;
9880         cmdline_ipaddr_t proto;
9881         uint8_t proto_value;
9882         cmdline_ipaddr_t ttl;
9883         uint8_t ttl_value;
9884         cmdline_fixed_string_t vlan;
9885         uint16_t vlan_value;
9886         cmdline_fixed_string_t flexbytes;
9887         cmdline_fixed_string_t flexbytes_value;
9888         cmdline_fixed_string_t pf_vf;
9889         cmdline_fixed_string_t drop;
9890         cmdline_fixed_string_t queue;
9891         uint16_t  queue_id;
9892         cmdline_fixed_string_t fd_id;
9893         uint32_t  fd_id_value;
9894         cmdline_fixed_string_t mac;
9895         struct ether_addr mac_addr;
9896         cmdline_fixed_string_t tunnel;
9897         cmdline_fixed_string_t tunnel_type;
9898         cmdline_fixed_string_t tunnel_id;
9899         uint32_t tunnel_id_value;
9900         cmdline_fixed_string_t packet;
9901         char filepath[];
9902 };
9903
9904 static inline int
9905 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9906 {
9907         char s[256];
9908         const char *p, *p0 = q_arg;
9909         char *end;
9910         unsigned long int_fld;
9911         char *str_fld[max_num];
9912         int i;
9913         unsigned size;
9914         int ret = -1;
9915
9916         p = strchr(p0, '(');
9917         if (p == NULL)
9918                 return -1;
9919         ++p;
9920         p0 = strchr(p, ')');
9921         if (p0 == NULL)
9922                 return -1;
9923
9924         size = p0 - p;
9925         if (size >= sizeof(s))
9926                 return -1;
9927
9928         snprintf(s, sizeof(s), "%.*s", size, p);
9929         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9930         if (ret < 0 || ret > max_num)
9931                 return -1;
9932         for (i = 0; i < ret; i++) {
9933                 errno = 0;
9934                 int_fld = strtoul(str_fld[i], &end, 0);
9935                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9936                         return -1;
9937                 flexbytes[i] = (uint8_t)int_fld;
9938         }
9939         return ret;
9940 }
9941
9942 static uint16_t
9943 str2flowtype(char *string)
9944 {
9945         uint8_t i = 0;
9946         static const struct {
9947                 char str[32];
9948                 uint16_t type;
9949         } flowtype_str[] = {
9950                 {"raw", RTE_ETH_FLOW_RAW},
9951                 {"ipv4", RTE_ETH_FLOW_IPV4},
9952                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9953                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9954                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9955                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9956                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9957                 {"ipv6", RTE_ETH_FLOW_IPV6},
9958                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9959                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9960                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9961                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9962                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9963                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9964         };
9965
9966         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9967                 if (!strcmp(flowtype_str[i].str, string))
9968                         return flowtype_str[i].type;
9969         }
9970
9971         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9972                 return (uint16_t)atoi(string);
9973
9974         return RTE_ETH_FLOW_UNKNOWN;
9975 }
9976
9977 static enum rte_eth_fdir_tunnel_type
9978 str2fdir_tunneltype(char *string)
9979 {
9980         uint8_t i = 0;
9981
9982         static const struct {
9983                 char str[32];
9984                 enum rte_eth_fdir_tunnel_type type;
9985         } tunneltype_str[] = {
9986                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9987                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9988         };
9989
9990         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9991                 if (!strcmp(tunneltype_str[i].str, string))
9992                         return tunneltype_str[i].type;
9993         }
9994         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9995 }
9996
9997 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9998 do { \
9999         if ((ip_addr).family == AF_INET) \
10000                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10001         else { \
10002                 printf("invalid parameter.\n"); \
10003                 return; \
10004         } \
10005 } while (0)
10006
10007 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10008 do { \
10009         if ((ip_addr).family == AF_INET6) \
10010                 rte_memcpy(&(ip), \
10011                                  &((ip_addr).addr.ipv6), \
10012                                  sizeof(struct in6_addr)); \
10013         else { \
10014                 printf("invalid parameter.\n"); \
10015                 return; \
10016         } \
10017 } while (0)
10018
10019 static void
10020 cmd_flow_director_filter_parsed(void *parsed_result,
10021                           __attribute__((unused)) struct cmdline *cl,
10022                           __attribute__((unused)) void *data)
10023 {
10024         struct cmd_flow_director_result *res = parsed_result;
10025         struct rte_eth_fdir_filter entry;
10026         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10027         char *end;
10028         unsigned long vf_id;
10029         int ret = 0;
10030
10031         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10032         if (ret < 0) {
10033                 printf("flow director is not supported on port %u.\n",
10034                         res->port_id);
10035                 return;
10036         }
10037         memset(flexbytes, 0, sizeof(flexbytes));
10038         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10039
10040         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10041                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10042                         printf("Please set mode to MAC-VLAN.\n");
10043                         return;
10044                 }
10045         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10046                 if (strcmp(res->mode_value, "Tunnel")) {
10047                         printf("Please set mode to Tunnel.\n");
10048                         return;
10049                 }
10050         } else {
10051                 if (!strcmp(res->mode_value, "raw")) {
10052 #ifdef RTE_LIBRTE_I40E_PMD
10053                         struct rte_pmd_i40e_flow_type_mapping
10054                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10055                         struct rte_pmd_i40e_pkt_template_conf conf;
10056                         uint16_t flow_type = str2flowtype(res->flow_type);
10057                         uint16_t i, port = res->port_id;
10058                         uint8_t add;
10059
10060                         memset(&conf, 0, sizeof(conf));
10061
10062                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10063                                 printf("Invalid flow type specified.\n");
10064                                 return;
10065                         }
10066                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10067                                                                  mapping);
10068                         if (ret)
10069                                 return;
10070                         if (mapping[flow_type].pctype == 0ULL) {
10071                                 printf("Invalid flow type specified.\n");
10072                                 return;
10073                         }
10074                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10075                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10076                                         conf.input.pctype = i;
10077                                         break;
10078                                 }
10079                         }
10080
10081                         conf.input.packet = open_file(res->filepath,
10082                                                 &conf.input.length);
10083                         if (!conf.input.packet)
10084                                 return;
10085                         if (!strcmp(res->drop, "drop"))
10086                                 conf.action.behavior =
10087                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10088                         else
10089                                 conf.action.behavior =
10090                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10091                         conf.action.report_status =
10092                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10093                         conf.action.rx_queue = res->queue_id;
10094                         conf.soft_id = res->fd_id_value;
10095                         add  = strcmp(res->ops, "del") ? 1 : 0;
10096                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10097                                                                         &conf,
10098                                                                         add);
10099                         if (ret < 0)
10100                                 printf("flow director config error: (%s)\n",
10101                                        strerror(-ret));
10102                         close_file(conf.input.packet);
10103 #endif
10104                         return;
10105                 } else if (strcmp(res->mode_value, "IP")) {
10106                         printf("Please set mode to IP or raw.\n");
10107                         return;
10108                 }
10109                 entry.input.flow_type = str2flowtype(res->flow_type);
10110         }
10111
10112         ret = parse_flexbytes(res->flexbytes_value,
10113                                         flexbytes,
10114                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10115         if (ret < 0) {
10116                 printf("error: Cannot parse flexbytes input.\n");
10117                 return;
10118         }
10119
10120         switch (entry.input.flow_type) {
10121         case RTE_ETH_FLOW_FRAG_IPV4:
10122         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10123                 entry.input.flow.ip4_flow.proto = res->proto_value;
10124                 /* fall-through */
10125         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10126         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10127                 IPV4_ADDR_TO_UINT(res->ip_dst,
10128                         entry.input.flow.ip4_flow.dst_ip);
10129                 IPV4_ADDR_TO_UINT(res->ip_src,
10130                         entry.input.flow.ip4_flow.src_ip);
10131                 entry.input.flow.ip4_flow.tos = res->tos_value;
10132                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10133                 /* need convert to big endian. */
10134                 entry.input.flow.udp4_flow.dst_port =
10135                                 rte_cpu_to_be_16(res->port_dst);
10136                 entry.input.flow.udp4_flow.src_port =
10137                                 rte_cpu_to_be_16(res->port_src);
10138                 break;
10139         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10140                 IPV4_ADDR_TO_UINT(res->ip_dst,
10141                         entry.input.flow.sctp4_flow.ip.dst_ip);
10142                 IPV4_ADDR_TO_UINT(res->ip_src,
10143                         entry.input.flow.sctp4_flow.ip.src_ip);
10144                 entry.input.flow.ip4_flow.tos = res->tos_value;
10145                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10146                 /* need convert to big endian. */
10147                 entry.input.flow.sctp4_flow.dst_port =
10148                                 rte_cpu_to_be_16(res->port_dst);
10149                 entry.input.flow.sctp4_flow.src_port =
10150                                 rte_cpu_to_be_16(res->port_src);
10151                 entry.input.flow.sctp4_flow.verify_tag =
10152                                 rte_cpu_to_be_32(res->verify_tag_value);
10153                 break;
10154         case RTE_ETH_FLOW_FRAG_IPV6:
10155         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10156                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10157                 /* fall-through */
10158         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10159         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10160                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10161                         entry.input.flow.ipv6_flow.dst_ip);
10162                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10163                         entry.input.flow.ipv6_flow.src_ip);
10164                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10165                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10166                 /* need convert to big endian. */
10167                 entry.input.flow.udp6_flow.dst_port =
10168                                 rte_cpu_to_be_16(res->port_dst);
10169                 entry.input.flow.udp6_flow.src_port =
10170                                 rte_cpu_to_be_16(res->port_src);
10171                 break;
10172         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10173                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10174                         entry.input.flow.sctp6_flow.ip.dst_ip);
10175                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10176                         entry.input.flow.sctp6_flow.ip.src_ip);
10177                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10178                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10179                 /* need convert to big endian. */
10180                 entry.input.flow.sctp6_flow.dst_port =
10181                                 rte_cpu_to_be_16(res->port_dst);
10182                 entry.input.flow.sctp6_flow.src_port =
10183                                 rte_cpu_to_be_16(res->port_src);
10184                 entry.input.flow.sctp6_flow.verify_tag =
10185                                 rte_cpu_to_be_32(res->verify_tag_value);
10186                 break;
10187         case RTE_ETH_FLOW_L2_PAYLOAD:
10188                 entry.input.flow.l2_flow.ether_type =
10189                         rte_cpu_to_be_16(res->ether_type);
10190                 break;
10191         default:
10192                 break;
10193         }
10194
10195         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10196                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10197                                  &res->mac_addr,
10198                                  sizeof(struct ether_addr));
10199
10200         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10201                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10202                                  &res->mac_addr,
10203                                  sizeof(struct ether_addr));
10204                 entry.input.flow.tunnel_flow.tunnel_type =
10205                         str2fdir_tunneltype(res->tunnel_type);
10206                 entry.input.flow.tunnel_flow.tunnel_id =
10207                         rte_cpu_to_be_32(res->tunnel_id_value);
10208         }
10209
10210         rte_memcpy(entry.input.flow_ext.flexbytes,
10211                    flexbytes,
10212                    RTE_ETH_FDIR_MAX_FLEXLEN);
10213
10214         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10215
10216         entry.action.flex_off = 0;  /*use 0 by default */
10217         if (!strcmp(res->drop, "drop"))
10218                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10219         else
10220                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10221
10222         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10223             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10224                 if (!strcmp(res->pf_vf, "pf"))
10225                         entry.input.flow_ext.is_vf = 0;
10226                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10227                         struct rte_eth_dev_info dev_info;
10228
10229                         memset(&dev_info, 0, sizeof(dev_info));
10230                         rte_eth_dev_info_get(res->port_id, &dev_info);
10231                         errno = 0;
10232                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10233                         if (errno != 0 || *end != '\0' ||
10234                             vf_id >= dev_info.max_vfs) {
10235                                 printf("invalid parameter %s.\n", res->pf_vf);
10236                                 return;
10237                         }
10238                         entry.input.flow_ext.is_vf = 1;
10239                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10240                 } else {
10241                         printf("invalid parameter %s.\n", res->pf_vf);
10242                         return;
10243                 }
10244         }
10245
10246         /* set to report FD ID by default */
10247         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10248         entry.action.rx_queue = res->queue_id;
10249         entry.soft_id = res->fd_id_value;
10250         if (!strcmp(res->ops, "add"))
10251                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10252                                              RTE_ETH_FILTER_ADD, &entry);
10253         else if (!strcmp(res->ops, "del"))
10254                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10255                                              RTE_ETH_FILTER_DELETE, &entry);
10256         else
10257                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10258                                              RTE_ETH_FILTER_UPDATE, &entry);
10259         if (ret < 0)
10260                 printf("flow director programming error: (%s)\n",
10261                         strerror(-ret));
10262 }
10263
10264 cmdline_parse_token_string_t cmd_flow_director_filter =
10265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10266                                  flow_director_filter, "flow_director_filter");
10267 cmdline_parse_token_num_t cmd_flow_director_port_id =
10268         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10269                               port_id, UINT16);
10270 cmdline_parse_token_string_t cmd_flow_director_ops =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10272                                  ops, "add#del#update");
10273 cmdline_parse_token_string_t cmd_flow_director_flow =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10275                                  flow, "flow");
10276 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10278                 flow_type, NULL);
10279 cmdline_parse_token_string_t cmd_flow_director_ether =
10280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10281                                  ether, "ether");
10282 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10283         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10284                               ether_type, UINT16);
10285 cmdline_parse_token_string_t cmd_flow_director_src =
10286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10287                                  src, "src");
10288 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10289         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10290                                  ip_src);
10291 cmdline_parse_token_num_t cmd_flow_director_port_src =
10292         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10293                               port_src, UINT16);
10294 cmdline_parse_token_string_t cmd_flow_director_dst =
10295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10296                                  dst, "dst");
10297 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10298         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10299                                  ip_dst);
10300 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10301         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10302                               port_dst, UINT16);
10303 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10304         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10305                                   verify_tag, "verify_tag");
10306 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10307         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10308                               verify_tag_value, UINT32);
10309 cmdline_parse_token_string_t cmd_flow_director_tos =
10310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10311                                  tos, "tos");
10312 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10313         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10314                               tos_value, UINT8);
10315 cmdline_parse_token_string_t cmd_flow_director_proto =
10316         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10317                                  proto, "proto");
10318 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10319         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10320                               proto_value, UINT8);
10321 cmdline_parse_token_string_t cmd_flow_director_ttl =
10322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10323                                  ttl, "ttl");
10324 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10325         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10326                               ttl_value, UINT8);
10327 cmdline_parse_token_string_t cmd_flow_director_vlan =
10328         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10329                                  vlan, "vlan");
10330 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10331         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10332                               vlan_value, UINT16);
10333 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10334         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10335                                  flexbytes, "flexbytes");
10336 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10337         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10338                               flexbytes_value, NULL);
10339 cmdline_parse_token_string_t cmd_flow_director_drop =
10340         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10341                                  drop, "drop#fwd");
10342 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10343         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10344                               pf_vf, NULL);
10345 cmdline_parse_token_string_t cmd_flow_director_queue =
10346         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10347                                  queue, "queue");
10348 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10349         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10350                               queue_id, UINT16);
10351 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10352         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10353                                  fd_id, "fd_id");
10354 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10355         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10356                               fd_id_value, UINT32);
10357
10358 cmdline_parse_token_string_t cmd_flow_director_mode =
10359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10360                                  mode, "mode");
10361 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10363                                  mode_value, "IP");
10364 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10366                                  mode_value, "MAC-VLAN");
10367 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10368         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10369                                  mode_value, "Tunnel");
10370 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10372                                  mode_value, "raw");
10373 cmdline_parse_token_string_t cmd_flow_director_mac =
10374         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10375                                  mac, "mac");
10376 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10377         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10378                                     mac_addr);
10379 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10381                                  tunnel, "tunnel");
10382 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10384                                  tunnel_type, "NVGRE#VxLAN");
10385 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10387                                  tunnel_id, "tunnel-id");
10388 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10389         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10390                               tunnel_id_value, UINT32);
10391 cmdline_parse_token_string_t cmd_flow_director_packet =
10392         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10393                                  packet, "packet");
10394 cmdline_parse_token_string_t cmd_flow_director_filepath =
10395         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10396                                  filepath, NULL);
10397
10398 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10399         .f = cmd_flow_director_filter_parsed,
10400         .data = NULL,
10401         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10402                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10403                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10404                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10405                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10406                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10407                 "fd_id <fd_id_value>: "
10408                 "Add or delete an ip flow director entry on NIC",
10409         .tokens = {
10410                 (void *)&cmd_flow_director_filter,
10411                 (void *)&cmd_flow_director_port_id,
10412                 (void *)&cmd_flow_director_mode,
10413                 (void *)&cmd_flow_director_mode_ip,
10414                 (void *)&cmd_flow_director_ops,
10415                 (void *)&cmd_flow_director_flow,
10416                 (void *)&cmd_flow_director_flow_type,
10417                 (void *)&cmd_flow_director_src,
10418                 (void *)&cmd_flow_director_ip_src,
10419                 (void *)&cmd_flow_director_dst,
10420                 (void *)&cmd_flow_director_ip_dst,
10421                 (void *)&cmd_flow_director_tos,
10422                 (void *)&cmd_flow_director_tos_value,
10423                 (void *)&cmd_flow_director_proto,
10424                 (void *)&cmd_flow_director_proto_value,
10425                 (void *)&cmd_flow_director_ttl,
10426                 (void *)&cmd_flow_director_ttl_value,
10427                 (void *)&cmd_flow_director_vlan,
10428                 (void *)&cmd_flow_director_vlan_value,
10429                 (void *)&cmd_flow_director_flexbytes,
10430                 (void *)&cmd_flow_director_flexbytes_value,
10431                 (void *)&cmd_flow_director_drop,
10432                 (void *)&cmd_flow_director_pf_vf,
10433                 (void *)&cmd_flow_director_queue,
10434                 (void *)&cmd_flow_director_queue_id,
10435                 (void *)&cmd_flow_director_fd_id,
10436                 (void *)&cmd_flow_director_fd_id_value,
10437                 NULL,
10438         },
10439 };
10440
10441 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10442         .f = cmd_flow_director_filter_parsed,
10443         .data = NULL,
10444         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10445                 "director entry on NIC",
10446         .tokens = {
10447                 (void *)&cmd_flow_director_filter,
10448                 (void *)&cmd_flow_director_port_id,
10449                 (void *)&cmd_flow_director_mode,
10450                 (void *)&cmd_flow_director_mode_ip,
10451                 (void *)&cmd_flow_director_ops,
10452                 (void *)&cmd_flow_director_flow,
10453                 (void *)&cmd_flow_director_flow_type,
10454                 (void *)&cmd_flow_director_src,
10455                 (void *)&cmd_flow_director_ip_src,
10456                 (void *)&cmd_flow_director_port_src,
10457                 (void *)&cmd_flow_director_dst,
10458                 (void *)&cmd_flow_director_ip_dst,
10459                 (void *)&cmd_flow_director_port_dst,
10460                 (void *)&cmd_flow_director_tos,
10461                 (void *)&cmd_flow_director_tos_value,
10462                 (void *)&cmd_flow_director_ttl,
10463                 (void *)&cmd_flow_director_ttl_value,
10464                 (void *)&cmd_flow_director_vlan,
10465                 (void *)&cmd_flow_director_vlan_value,
10466                 (void *)&cmd_flow_director_flexbytes,
10467                 (void *)&cmd_flow_director_flexbytes_value,
10468                 (void *)&cmd_flow_director_drop,
10469                 (void *)&cmd_flow_director_pf_vf,
10470                 (void *)&cmd_flow_director_queue,
10471                 (void *)&cmd_flow_director_queue_id,
10472                 (void *)&cmd_flow_director_fd_id,
10473                 (void *)&cmd_flow_director_fd_id_value,
10474                 NULL,
10475         },
10476 };
10477
10478 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10479         .f = cmd_flow_director_filter_parsed,
10480         .data = NULL,
10481         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10482                 "director entry on NIC",
10483         .tokens = {
10484                 (void *)&cmd_flow_director_filter,
10485                 (void *)&cmd_flow_director_port_id,
10486                 (void *)&cmd_flow_director_mode,
10487                 (void *)&cmd_flow_director_mode_ip,
10488                 (void *)&cmd_flow_director_ops,
10489                 (void *)&cmd_flow_director_flow,
10490                 (void *)&cmd_flow_director_flow_type,
10491                 (void *)&cmd_flow_director_src,
10492                 (void *)&cmd_flow_director_ip_src,
10493                 (void *)&cmd_flow_director_port_dst,
10494                 (void *)&cmd_flow_director_dst,
10495                 (void *)&cmd_flow_director_ip_dst,
10496                 (void *)&cmd_flow_director_port_dst,
10497                 (void *)&cmd_flow_director_verify_tag,
10498                 (void *)&cmd_flow_director_verify_tag_value,
10499                 (void *)&cmd_flow_director_tos,
10500                 (void *)&cmd_flow_director_tos_value,
10501                 (void *)&cmd_flow_director_ttl,
10502                 (void *)&cmd_flow_director_ttl_value,
10503                 (void *)&cmd_flow_director_vlan,
10504                 (void *)&cmd_flow_director_vlan_value,
10505                 (void *)&cmd_flow_director_flexbytes,
10506                 (void *)&cmd_flow_director_flexbytes_value,
10507                 (void *)&cmd_flow_director_drop,
10508                 (void *)&cmd_flow_director_pf_vf,
10509                 (void *)&cmd_flow_director_queue,
10510                 (void *)&cmd_flow_director_queue_id,
10511                 (void *)&cmd_flow_director_fd_id,
10512                 (void *)&cmd_flow_director_fd_id_value,
10513                 NULL,
10514         },
10515 };
10516
10517 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10518         .f = cmd_flow_director_filter_parsed,
10519         .data = NULL,
10520         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10521                 "director entry on NIC",
10522         .tokens = {
10523                 (void *)&cmd_flow_director_filter,
10524                 (void *)&cmd_flow_director_port_id,
10525                 (void *)&cmd_flow_director_mode,
10526                 (void *)&cmd_flow_director_mode_ip,
10527                 (void *)&cmd_flow_director_ops,
10528                 (void *)&cmd_flow_director_flow,
10529                 (void *)&cmd_flow_director_flow_type,
10530                 (void *)&cmd_flow_director_ether,
10531                 (void *)&cmd_flow_director_ether_type,
10532                 (void *)&cmd_flow_director_flexbytes,
10533                 (void *)&cmd_flow_director_flexbytes_value,
10534                 (void *)&cmd_flow_director_drop,
10535                 (void *)&cmd_flow_director_pf_vf,
10536                 (void *)&cmd_flow_director_queue,
10537                 (void *)&cmd_flow_director_queue_id,
10538                 (void *)&cmd_flow_director_fd_id,
10539                 (void *)&cmd_flow_director_fd_id_value,
10540                 NULL,
10541         },
10542 };
10543
10544 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10545         .f = cmd_flow_director_filter_parsed,
10546         .data = NULL,
10547         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10548                 "director entry on NIC",
10549         .tokens = {
10550                 (void *)&cmd_flow_director_filter,
10551                 (void *)&cmd_flow_director_port_id,
10552                 (void *)&cmd_flow_director_mode,
10553                 (void *)&cmd_flow_director_mode_mac_vlan,
10554                 (void *)&cmd_flow_director_ops,
10555                 (void *)&cmd_flow_director_mac,
10556                 (void *)&cmd_flow_director_mac_addr,
10557                 (void *)&cmd_flow_director_vlan,
10558                 (void *)&cmd_flow_director_vlan_value,
10559                 (void *)&cmd_flow_director_flexbytes,
10560                 (void *)&cmd_flow_director_flexbytes_value,
10561                 (void *)&cmd_flow_director_drop,
10562                 (void *)&cmd_flow_director_queue,
10563                 (void *)&cmd_flow_director_queue_id,
10564                 (void *)&cmd_flow_director_fd_id,
10565                 (void *)&cmd_flow_director_fd_id_value,
10566                 NULL,
10567         },
10568 };
10569
10570 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10571         .f = cmd_flow_director_filter_parsed,
10572         .data = NULL,
10573         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10574                 "director entry on NIC",
10575         .tokens = {
10576                 (void *)&cmd_flow_director_filter,
10577                 (void *)&cmd_flow_director_port_id,
10578                 (void *)&cmd_flow_director_mode,
10579                 (void *)&cmd_flow_director_mode_tunnel,
10580                 (void *)&cmd_flow_director_ops,
10581                 (void *)&cmd_flow_director_mac,
10582                 (void *)&cmd_flow_director_mac_addr,
10583                 (void *)&cmd_flow_director_vlan,
10584                 (void *)&cmd_flow_director_vlan_value,
10585                 (void *)&cmd_flow_director_tunnel,
10586                 (void *)&cmd_flow_director_tunnel_type,
10587                 (void *)&cmd_flow_director_tunnel_id,
10588                 (void *)&cmd_flow_director_tunnel_id_value,
10589                 (void *)&cmd_flow_director_flexbytes,
10590                 (void *)&cmd_flow_director_flexbytes_value,
10591                 (void *)&cmd_flow_director_drop,
10592                 (void *)&cmd_flow_director_queue,
10593                 (void *)&cmd_flow_director_queue_id,
10594                 (void *)&cmd_flow_director_fd_id,
10595                 (void *)&cmd_flow_director_fd_id_value,
10596                 NULL,
10597         },
10598 };
10599
10600 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10601         .f = cmd_flow_director_filter_parsed,
10602         .data = NULL,
10603         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10604                 "director entry on NIC",
10605         .tokens = {
10606                 (void *)&cmd_flow_director_filter,
10607                 (void *)&cmd_flow_director_port_id,
10608                 (void *)&cmd_flow_director_mode,
10609                 (void *)&cmd_flow_director_mode_raw,
10610                 (void *)&cmd_flow_director_ops,
10611                 (void *)&cmd_flow_director_flow,
10612                 (void *)&cmd_flow_director_flow_type,
10613                 (void *)&cmd_flow_director_drop,
10614                 (void *)&cmd_flow_director_queue,
10615                 (void *)&cmd_flow_director_queue_id,
10616                 (void *)&cmd_flow_director_fd_id,
10617                 (void *)&cmd_flow_director_fd_id_value,
10618                 (void *)&cmd_flow_director_packet,
10619                 (void *)&cmd_flow_director_filepath,
10620                 NULL,
10621         },
10622 };
10623
10624 struct cmd_flush_flow_director_result {
10625         cmdline_fixed_string_t flush_flow_director;
10626         portid_t port_id;
10627 };
10628
10629 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10630         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10631                                  flush_flow_director, "flush_flow_director");
10632 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10633         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10634                               port_id, UINT16);
10635
10636 static void
10637 cmd_flush_flow_director_parsed(void *parsed_result,
10638                           __attribute__((unused)) struct cmdline *cl,
10639                           __attribute__((unused)) void *data)
10640 {
10641         struct cmd_flow_director_result *res = parsed_result;
10642         int ret = 0;
10643
10644         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10645         if (ret < 0) {
10646                 printf("flow director is not supported on port %u.\n",
10647                         res->port_id);
10648                 return;
10649         }
10650
10651         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10652                         RTE_ETH_FILTER_FLUSH, NULL);
10653         if (ret < 0)
10654                 printf("flow director table flushing error: (%s)\n",
10655                         strerror(-ret));
10656 }
10657
10658 cmdline_parse_inst_t cmd_flush_flow_director = {
10659         .f = cmd_flush_flow_director_parsed,
10660         .data = NULL,
10661         .help_str = "flush_flow_director <port_id>: "
10662                 "Flush all flow director entries of a device on NIC",
10663         .tokens = {
10664                 (void *)&cmd_flush_flow_director_flush,
10665                 (void *)&cmd_flush_flow_director_port_id,
10666                 NULL,
10667         },
10668 };
10669
10670 /* *** deal with flow director mask *** */
10671 struct cmd_flow_director_mask_result {
10672         cmdline_fixed_string_t flow_director_mask;
10673         portid_t port_id;
10674         cmdline_fixed_string_t mode;
10675         cmdline_fixed_string_t mode_value;
10676         cmdline_fixed_string_t vlan;
10677         uint16_t vlan_mask;
10678         cmdline_fixed_string_t src_mask;
10679         cmdline_ipaddr_t ipv4_src;
10680         cmdline_ipaddr_t ipv6_src;
10681         uint16_t port_src;
10682         cmdline_fixed_string_t dst_mask;
10683         cmdline_ipaddr_t ipv4_dst;
10684         cmdline_ipaddr_t ipv6_dst;
10685         uint16_t port_dst;
10686         cmdline_fixed_string_t mac;
10687         uint8_t mac_addr_byte_mask;
10688         cmdline_fixed_string_t tunnel_id;
10689         uint32_t tunnel_id_mask;
10690         cmdline_fixed_string_t tunnel_type;
10691         uint8_t tunnel_type_mask;
10692 };
10693
10694 static void
10695 cmd_flow_director_mask_parsed(void *parsed_result,
10696                           __attribute__((unused)) struct cmdline *cl,
10697                           __attribute__((unused)) void *data)
10698 {
10699         struct cmd_flow_director_mask_result *res = parsed_result;
10700         struct rte_eth_fdir_masks *mask;
10701         struct rte_port *port;
10702
10703         if (res->port_id > nb_ports) {
10704                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10705                 return;
10706         }
10707
10708         port = &ports[res->port_id];
10709         /** Check if the port is not started **/
10710         if (port->port_status != RTE_PORT_STOPPED) {
10711                 printf("Please stop port %d first\n", res->port_id);
10712                 return;
10713         }
10714
10715         mask = &port->dev_conf.fdir_conf.mask;
10716
10717         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10718                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10719                         printf("Please set mode to MAC-VLAN.\n");
10720                         return;
10721                 }
10722
10723                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10724         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10725                 if (strcmp(res->mode_value, "Tunnel")) {
10726                         printf("Please set mode to Tunnel.\n");
10727                         return;
10728                 }
10729
10730                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10731                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10732                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10733                 mask->tunnel_type_mask = res->tunnel_type_mask;
10734         } else {
10735                 if (strcmp(res->mode_value, "IP")) {
10736                         printf("Please set mode to IP.\n");
10737                         return;
10738                 }
10739
10740                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10741                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10742                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10743                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10744                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10745                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10746                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10747         }
10748
10749         cmd_reconfig_device_queue(res->port_id, 1, 1);
10750 }
10751
10752 cmdline_parse_token_string_t cmd_flow_director_mask =
10753         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10754                                  flow_director_mask, "flow_director_mask");
10755 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10756         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10757                               port_id, UINT16);
10758 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10760                                  vlan, "vlan");
10761 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10762         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10763                               vlan_mask, UINT16);
10764 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10765         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10766                                  src_mask, "src_mask");
10767 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10768         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10769                                  ipv4_src);
10770 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10771         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10772                                  ipv6_src);
10773 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10774         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10775                               port_src, UINT16);
10776 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10778                                  dst_mask, "dst_mask");
10779 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10780         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10781                                  ipv4_dst);
10782 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10783         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10784                                  ipv6_dst);
10785 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10786         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10787                               port_dst, UINT16);
10788
10789 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10791                                  mode, "mode");
10792 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10794                                  mode_value, "IP");
10795 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10797                                  mode_value, "MAC-VLAN");
10798 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10800                                  mode_value, "Tunnel");
10801 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10803                                  mac, "mac");
10804 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10806                               mac_addr_byte_mask, UINT8);
10807 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10809                                  tunnel_type, "tunnel-type");
10810 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10811         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10812                               tunnel_type_mask, UINT8);
10813 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10815                                  tunnel_id, "tunnel-id");
10816 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10817         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10818                               tunnel_id_mask, UINT32);
10819
10820 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10821         .f = cmd_flow_director_mask_parsed,
10822         .data = NULL,
10823         .help_str = "flow_director_mask ... : "
10824                 "Set IP mode flow director's mask on NIC",
10825         .tokens = {
10826                 (void *)&cmd_flow_director_mask,
10827                 (void *)&cmd_flow_director_mask_port_id,
10828                 (void *)&cmd_flow_director_mask_mode,
10829                 (void *)&cmd_flow_director_mask_mode_ip,
10830                 (void *)&cmd_flow_director_mask_vlan,
10831                 (void *)&cmd_flow_director_mask_vlan_value,
10832                 (void *)&cmd_flow_director_mask_src,
10833                 (void *)&cmd_flow_director_mask_ipv4_src,
10834                 (void *)&cmd_flow_director_mask_ipv6_src,
10835                 (void *)&cmd_flow_director_mask_port_src,
10836                 (void *)&cmd_flow_director_mask_dst,
10837                 (void *)&cmd_flow_director_mask_ipv4_dst,
10838                 (void *)&cmd_flow_director_mask_ipv6_dst,
10839                 (void *)&cmd_flow_director_mask_port_dst,
10840                 NULL,
10841         },
10842 };
10843
10844 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10845         .f = cmd_flow_director_mask_parsed,
10846         .data = NULL,
10847         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10848                 "flow director's mask on NIC",
10849         .tokens = {
10850                 (void *)&cmd_flow_director_mask,
10851                 (void *)&cmd_flow_director_mask_port_id,
10852                 (void *)&cmd_flow_director_mask_mode,
10853                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10854                 (void *)&cmd_flow_director_mask_vlan,
10855                 (void *)&cmd_flow_director_mask_vlan_value,
10856                 NULL,
10857         },
10858 };
10859
10860 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10861         .f = cmd_flow_director_mask_parsed,
10862         .data = NULL,
10863         .help_str = "flow_director_mask ... : Set tunnel mode "
10864                 "flow director's mask on NIC",
10865         .tokens = {
10866                 (void *)&cmd_flow_director_mask,
10867                 (void *)&cmd_flow_director_mask_port_id,
10868                 (void *)&cmd_flow_director_mask_mode,
10869                 (void *)&cmd_flow_director_mask_mode_tunnel,
10870                 (void *)&cmd_flow_director_mask_vlan,
10871                 (void *)&cmd_flow_director_mask_vlan_value,
10872                 (void *)&cmd_flow_director_mask_mac,
10873                 (void *)&cmd_flow_director_mask_mac_value,
10874                 (void *)&cmd_flow_director_mask_tunnel_type,
10875                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10876                 (void *)&cmd_flow_director_mask_tunnel_id,
10877                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10878                 NULL,
10879         },
10880 };
10881
10882 /* *** deal with flow director mask on flexible payload *** */
10883 struct cmd_flow_director_flex_mask_result {
10884         cmdline_fixed_string_t flow_director_flexmask;
10885         portid_t port_id;
10886         cmdline_fixed_string_t flow;
10887         cmdline_fixed_string_t flow_type;
10888         cmdline_fixed_string_t mask;
10889 };
10890
10891 static void
10892 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10893                           __attribute__((unused)) struct cmdline *cl,
10894                           __attribute__((unused)) void *data)
10895 {
10896         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10897         struct rte_eth_fdir_info fdir_info;
10898         struct rte_eth_fdir_flex_mask flex_mask;
10899         struct rte_port *port;
10900         uint32_t flow_type_mask;
10901         uint16_t i;
10902         int ret;
10903
10904         if (res->port_id > nb_ports) {
10905                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10906                 return;
10907         }
10908
10909         port = &ports[res->port_id];
10910         /** Check if the port is not started **/
10911         if (port->port_status != RTE_PORT_STOPPED) {
10912                 printf("Please stop port %d first\n", res->port_id);
10913                 return;
10914         }
10915
10916         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10917         ret = parse_flexbytes(res->mask,
10918                         flex_mask.mask,
10919                         RTE_ETH_FDIR_MAX_FLEXLEN);
10920         if (ret < 0) {
10921                 printf("error: Cannot parse mask input.\n");
10922                 return;
10923         }
10924
10925         memset(&fdir_info, 0, sizeof(fdir_info));
10926         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10927                                 RTE_ETH_FILTER_INFO, &fdir_info);
10928         if (ret < 0) {
10929                 printf("Cannot get FDir filter info\n");
10930                 return;
10931         }
10932
10933         if (!strcmp(res->flow_type, "none")) {
10934                 /* means don't specify the flow type */
10935                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10936                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10937                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10938                                0, sizeof(struct rte_eth_fdir_flex_mask));
10939                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10940                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10941                                  &flex_mask,
10942                                  sizeof(struct rte_eth_fdir_flex_mask));
10943                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10944                 return;
10945         }
10946         flow_type_mask = fdir_info.flow_types_mask[0];
10947         if (!strcmp(res->flow_type, "all")) {
10948                 if (!flow_type_mask) {
10949                         printf("No flow type supported\n");
10950                         return;
10951                 }
10952                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10953                         if (flow_type_mask & (1 << i)) {
10954                                 flex_mask.flow_type = i;
10955                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10956                         }
10957                 }
10958                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10959                 return;
10960         }
10961         flex_mask.flow_type = str2flowtype(res->flow_type);
10962         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10963                 printf("Flow type %s not supported on port %d\n",
10964                                 res->flow_type, res->port_id);
10965                 return;
10966         }
10967         fdir_set_flex_mask(res->port_id, &flex_mask);
10968         cmd_reconfig_device_queue(res->port_id, 1, 1);
10969 }
10970
10971 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10973                                  flow_director_flexmask,
10974                                  "flow_director_flex_mask");
10975 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10976         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10977                               port_id, UINT16);
10978 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10979         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10980                                  flow, "flow");
10981 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10982         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10983                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10984                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10985 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10986         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10987                                  mask, NULL);
10988
10989 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10990         .f = cmd_flow_director_flex_mask_parsed,
10991         .data = NULL,
10992         .help_str = "flow_director_flex_mask ... : "
10993                 "Set flow director's flex mask on NIC",
10994         .tokens = {
10995                 (void *)&cmd_flow_director_flexmask,
10996                 (void *)&cmd_flow_director_flexmask_port_id,
10997                 (void *)&cmd_flow_director_flexmask_flow,
10998                 (void *)&cmd_flow_director_flexmask_flow_type,
10999                 (void *)&cmd_flow_director_flexmask_mask,
11000                 NULL,
11001         },
11002 };
11003
11004 /* *** deal with flow director flexible payload configuration *** */
11005 struct cmd_flow_director_flexpayload_result {
11006         cmdline_fixed_string_t flow_director_flexpayload;
11007         portid_t port_id;
11008         cmdline_fixed_string_t payload_layer;
11009         cmdline_fixed_string_t payload_cfg;
11010 };
11011
11012 static inline int
11013 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11014 {
11015         char s[256];
11016         const char *p, *p0 = q_arg;
11017         char *end;
11018         unsigned long int_fld;
11019         char *str_fld[max_num];
11020         int i;
11021         unsigned size;
11022         int ret = -1;
11023
11024         p = strchr(p0, '(');
11025         if (p == NULL)
11026                 return -1;
11027         ++p;
11028         p0 = strchr(p, ')');
11029         if (p0 == NULL)
11030                 return -1;
11031
11032         size = p0 - p;
11033         if (size >= sizeof(s))
11034                 return -1;
11035
11036         snprintf(s, sizeof(s), "%.*s", size, p);
11037         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11038         if (ret < 0 || ret > max_num)
11039                 return -1;
11040         for (i = 0; i < ret; i++) {
11041                 errno = 0;
11042                 int_fld = strtoul(str_fld[i], &end, 0);
11043                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11044                         return -1;
11045                 offsets[i] = (uint16_t)int_fld;
11046         }
11047         return ret;
11048 }
11049
11050 static void
11051 cmd_flow_director_flxpld_parsed(void *parsed_result,
11052                           __attribute__((unused)) struct cmdline *cl,
11053                           __attribute__((unused)) void *data)
11054 {
11055         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11056         struct rte_eth_flex_payload_cfg flex_cfg;
11057         struct rte_port *port;
11058         int ret = 0;
11059
11060         if (res->port_id > nb_ports) {
11061                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11062                 return;
11063         }
11064
11065         port = &ports[res->port_id];
11066         /** Check if the port is not started **/
11067         if (port->port_status != RTE_PORT_STOPPED) {
11068                 printf("Please stop port %d first\n", res->port_id);
11069                 return;
11070         }
11071
11072         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11073
11074         if (!strcmp(res->payload_layer, "raw"))
11075                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11076         else if (!strcmp(res->payload_layer, "l2"))
11077                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11078         else if (!strcmp(res->payload_layer, "l3"))
11079                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11080         else if (!strcmp(res->payload_layer, "l4"))
11081                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11082
11083         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11084                             RTE_ETH_FDIR_MAX_FLEXLEN);
11085         if (ret < 0) {
11086                 printf("error: Cannot parse flex payload input.\n");
11087                 return;
11088         }
11089
11090         fdir_set_flex_payload(res->port_id, &flex_cfg);
11091         cmd_reconfig_device_queue(res->port_id, 1, 1);
11092 }
11093
11094 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11095         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11096                                  flow_director_flexpayload,
11097                                  "flow_director_flex_payload");
11098 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11099         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11100                               port_id, UINT16);
11101 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11102         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11103                                  payload_layer, "raw#l2#l3#l4");
11104 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11105         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11106                                  payload_cfg, NULL);
11107
11108 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11109         .f = cmd_flow_director_flxpld_parsed,
11110         .data = NULL,
11111         .help_str = "flow_director_flexpayload ... : "
11112                 "Set flow director's flex payload on NIC",
11113         .tokens = {
11114                 (void *)&cmd_flow_director_flexpayload,
11115                 (void *)&cmd_flow_director_flexpayload_port_id,
11116                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11117                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11118                 NULL,
11119         },
11120 };
11121
11122 /* Generic flow interface command. */
11123 extern cmdline_parse_inst_t cmd_flow;
11124
11125 /* *** Classification Filters Control *** */
11126 /* *** Get symmetric hash enable per port *** */
11127 struct cmd_get_sym_hash_ena_per_port_result {
11128         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11129         portid_t port_id;
11130 };
11131
11132 static void
11133 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11134                                  __rte_unused struct cmdline *cl,
11135                                  __rte_unused void *data)
11136 {
11137         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11138         struct rte_eth_hash_filter_info info;
11139         int ret;
11140
11141         if (rte_eth_dev_filter_supported(res->port_id,
11142                                 RTE_ETH_FILTER_HASH) < 0) {
11143                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11144                                                         res->port_id);
11145                 return;
11146         }
11147
11148         memset(&info, 0, sizeof(info));
11149         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11150         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11151                                                 RTE_ETH_FILTER_GET, &info);
11152
11153         if (ret < 0) {
11154                 printf("Cannot get symmetric hash enable per port "
11155                                         "on port %u\n", res->port_id);
11156                 return;
11157         }
11158
11159         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11160                                 "enabled" : "disabled", res->port_id);
11161 }
11162
11163 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11164         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11165                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11166 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11167         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11168                 port_id, UINT16);
11169
11170 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11171         .f = cmd_get_sym_hash_per_port_parsed,
11172         .data = NULL,
11173         .help_str = "get_sym_hash_ena_per_port <port_id>",
11174         .tokens = {
11175                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11176                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11177                 NULL,
11178         },
11179 };
11180
11181 /* *** Set symmetric hash enable per port *** */
11182 struct cmd_set_sym_hash_ena_per_port_result {
11183         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11184         cmdline_fixed_string_t enable;
11185         portid_t port_id;
11186 };
11187
11188 static void
11189 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11190                                  __rte_unused struct cmdline *cl,
11191                                  __rte_unused void *data)
11192 {
11193         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11194         struct rte_eth_hash_filter_info info;
11195         int ret;
11196
11197         if (rte_eth_dev_filter_supported(res->port_id,
11198                                 RTE_ETH_FILTER_HASH) < 0) {
11199                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11200                                                         res->port_id);
11201                 return;
11202         }
11203
11204         memset(&info, 0, sizeof(info));
11205         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11206         if (!strcmp(res->enable, "enable"))
11207                 info.info.enable = 1;
11208         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11209                                         RTE_ETH_FILTER_SET, &info);
11210         if (ret < 0) {
11211                 printf("Cannot set symmetric hash enable per port on "
11212                                         "port %u\n", res->port_id);
11213                 return;
11214         }
11215         printf("Symmetric hash has been set to %s on port %u\n",
11216                                         res->enable, res->port_id);
11217 }
11218
11219 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11220         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11221                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11222 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11223         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11224                 port_id, UINT16);
11225 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11226         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11227                 enable, "enable#disable");
11228
11229 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11230         .f = cmd_set_sym_hash_per_port_parsed,
11231         .data = NULL,
11232         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11233         .tokens = {
11234                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11235                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11236                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11237                 NULL,
11238         },
11239 };
11240
11241 /* Get global config of hash function */
11242 struct cmd_get_hash_global_config_result {
11243         cmdline_fixed_string_t get_hash_global_config;
11244         portid_t port_id;
11245 };
11246
11247 static char *
11248 flowtype_to_str(uint16_t ftype)
11249 {
11250         uint16_t i;
11251         static struct {
11252                 char str[16];
11253                 uint16_t ftype;
11254         } ftype_table[] = {
11255                 {"ipv4", RTE_ETH_FLOW_IPV4},
11256                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11257                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11258                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11259                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11260                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11261                 {"ipv6", RTE_ETH_FLOW_IPV6},
11262                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11263                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11264                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11265                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11266                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11267                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11268                 {"port", RTE_ETH_FLOW_PORT},
11269                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11270                 {"geneve", RTE_ETH_FLOW_GENEVE},
11271                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11272         };
11273
11274         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11275                 if (ftype_table[i].ftype == ftype)
11276                         return ftype_table[i].str;
11277         }
11278
11279         return NULL;
11280 }
11281
11282 static void
11283 cmd_get_hash_global_config_parsed(void *parsed_result,
11284                                   __rte_unused struct cmdline *cl,
11285                                   __rte_unused void *data)
11286 {
11287         struct cmd_get_hash_global_config_result *res = parsed_result;
11288         struct rte_eth_hash_filter_info info;
11289         uint32_t idx, offset;
11290         uint16_t i;
11291         char *str;
11292         int ret;
11293
11294         if (rte_eth_dev_filter_supported(res->port_id,
11295                         RTE_ETH_FILTER_HASH) < 0) {
11296                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11297                                                         res->port_id);
11298                 return;
11299         }
11300
11301         memset(&info, 0, sizeof(info));
11302         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11303         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11304                                         RTE_ETH_FILTER_GET, &info);
11305         if (ret < 0) {
11306                 printf("Cannot get hash global configurations by port %d\n",
11307                                                         res->port_id);
11308                 return;
11309         }
11310
11311         switch (info.info.global_conf.hash_func) {
11312         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11313                 printf("Hash function is Toeplitz\n");
11314                 break;
11315         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11316                 printf("Hash function is Simple XOR\n");
11317                 break;
11318         default:
11319                 printf("Unknown hash function\n");
11320                 break;
11321         }
11322
11323         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11324                 idx = i / UINT32_BIT;
11325                 offset = i % UINT32_BIT;
11326                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11327                                                 (1UL << offset)))
11328                         continue;
11329                 str = flowtype_to_str(i);
11330                 if (!str)
11331                         continue;
11332                 printf("Symmetric hash is %s globally for flow type %s "
11333                                                         "by port %d\n",
11334                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11335                         (1UL << offset)) ? "enabled" : "disabled"), str,
11336                                                         res->port_id);
11337         }
11338 }
11339
11340 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11341         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11342                 get_hash_global_config, "get_hash_global_config");
11343 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11344         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11345                 port_id, UINT16);
11346
11347 cmdline_parse_inst_t cmd_get_hash_global_config = {
11348         .f = cmd_get_hash_global_config_parsed,
11349         .data = NULL,
11350         .help_str = "get_hash_global_config <port_id>",
11351         .tokens = {
11352                 (void *)&cmd_get_hash_global_config_all,
11353                 (void *)&cmd_get_hash_global_config_port_id,
11354                 NULL,
11355         },
11356 };
11357
11358 /* Set global config of hash function */
11359 struct cmd_set_hash_global_config_result {
11360         cmdline_fixed_string_t set_hash_global_config;
11361         portid_t port_id;
11362         cmdline_fixed_string_t hash_func;
11363         cmdline_fixed_string_t flow_type;
11364         cmdline_fixed_string_t enable;
11365 };
11366
11367 static void
11368 cmd_set_hash_global_config_parsed(void *parsed_result,
11369                                   __rte_unused struct cmdline *cl,
11370                                   __rte_unused void *data)
11371 {
11372         struct cmd_set_hash_global_config_result *res = parsed_result;
11373         struct rte_eth_hash_filter_info info;
11374         uint32_t ftype, idx, offset;
11375         int ret;
11376
11377         if (rte_eth_dev_filter_supported(res->port_id,
11378                                 RTE_ETH_FILTER_HASH) < 0) {
11379                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11380                                                         res->port_id);
11381                 return;
11382         }
11383         memset(&info, 0, sizeof(info));
11384         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11385         if (!strcmp(res->hash_func, "toeplitz"))
11386                 info.info.global_conf.hash_func =
11387                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11388         else if (!strcmp(res->hash_func, "simple_xor"))
11389                 info.info.global_conf.hash_func =
11390                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11391         else if (!strcmp(res->hash_func, "default"))
11392                 info.info.global_conf.hash_func =
11393                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11394
11395         ftype = str2flowtype(res->flow_type);
11396         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11397         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11398         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11399         if (!strcmp(res->enable, "enable"))
11400                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11401                                                 (1UL << offset);
11402         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11403                                         RTE_ETH_FILTER_SET, &info);
11404         if (ret < 0)
11405                 printf("Cannot set global hash configurations by port %d\n",
11406                                                         res->port_id);
11407         else
11408                 printf("Global hash configurations have been set "
11409                         "succcessfully by port %d\n", res->port_id);
11410 }
11411
11412 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11413         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11414                 set_hash_global_config, "set_hash_global_config");
11415 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11416         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11417                 port_id, UINT16);
11418 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11419         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11420                 hash_func, "toeplitz#simple_xor#default");
11421 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11422         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11423                 flow_type,
11424                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11425                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11426 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11427         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11428                 enable, "enable#disable");
11429
11430 cmdline_parse_inst_t cmd_set_hash_global_config = {
11431         .f = cmd_set_hash_global_config_parsed,
11432         .data = NULL,
11433         .help_str = "set_hash_global_config <port_id> "
11434                 "toeplitz|simple_xor|default "
11435                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11436                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11437                 "l2_payload enable|disable",
11438         .tokens = {
11439                 (void *)&cmd_set_hash_global_config_all,
11440                 (void *)&cmd_set_hash_global_config_port_id,
11441                 (void *)&cmd_set_hash_global_config_hash_func,
11442                 (void *)&cmd_set_hash_global_config_flow_type,
11443                 (void *)&cmd_set_hash_global_config_enable,
11444                 NULL,
11445         },
11446 };
11447
11448 /* Set hash input set */
11449 struct cmd_set_hash_input_set_result {
11450         cmdline_fixed_string_t set_hash_input_set;
11451         portid_t port_id;
11452         cmdline_fixed_string_t flow_type;
11453         cmdline_fixed_string_t inset_field;
11454         cmdline_fixed_string_t select;
11455 };
11456
11457 static enum rte_eth_input_set_field
11458 str2inset(char *string)
11459 {
11460         uint16_t i;
11461
11462         static const struct {
11463                 char str[32];
11464                 enum rte_eth_input_set_field inset;
11465         } inset_table[] = {
11466                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11467                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11468                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11469                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11470                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11471                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11472                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11473                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11474                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11475                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11476                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11477                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11478                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11479                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11480                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11481                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11482                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11483                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11484                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11485                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11486                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11487                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11488                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11489                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11490                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11491                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11492                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11493                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11494                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11495                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11496                 {"none", RTE_ETH_INPUT_SET_NONE},
11497         };
11498
11499         for (i = 0; i < RTE_DIM(inset_table); i++) {
11500                 if (!strcmp(string, inset_table[i].str))
11501                         return inset_table[i].inset;
11502         }
11503
11504         return RTE_ETH_INPUT_SET_UNKNOWN;
11505 }
11506
11507 static void
11508 cmd_set_hash_input_set_parsed(void *parsed_result,
11509                               __rte_unused struct cmdline *cl,
11510                               __rte_unused void *data)
11511 {
11512         struct cmd_set_hash_input_set_result *res = parsed_result;
11513         struct rte_eth_hash_filter_info info;
11514
11515         memset(&info, 0, sizeof(info));
11516         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11517         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11518         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11519         info.info.input_set_conf.inset_size = 1;
11520         if (!strcmp(res->select, "select"))
11521                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11522         else if (!strcmp(res->select, "add"))
11523                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11524         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11525                                 RTE_ETH_FILTER_SET, &info);
11526 }
11527
11528 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11529         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11530                 set_hash_input_set, "set_hash_input_set");
11531 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11532         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11533                 port_id, UINT16);
11534 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11535         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11536                 flow_type, NULL);
11537 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11538         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11539                 inset_field,
11540                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11541                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11542                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11543                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11544                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11545                 "fld-8th#none");
11546 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11547         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11548                 select, "select#add");
11549
11550 cmdline_parse_inst_t cmd_set_hash_input_set = {
11551         .f = cmd_set_hash_input_set_parsed,
11552         .data = NULL,
11553         .help_str = "set_hash_input_set <port_id> "
11554         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11555         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11556         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11557         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11558         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11559         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11560         "fld-7th|fld-8th|none select|add",
11561         .tokens = {
11562                 (void *)&cmd_set_hash_input_set_cmd,
11563                 (void *)&cmd_set_hash_input_set_port_id,
11564                 (void *)&cmd_set_hash_input_set_flow_type,
11565                 (void *)&cmd_set_hash_input_set_field,
11566                 (void *)&cmd_set_hash_input_set_select,
11567                 NULL,
11568         },
11569 };
11570
11571 /* Set flow director input set */
11572 struct cmd_set_fdir_input_set_result {
11573         cmdline_fixed_string_t set_fdir_input_set;
11574         portid_t port_id;
11575         cmdline_fixed_string_t flow_type;
11576         cmdline_fixed_string_t inset_field;
11577         cmdline_fixed_string_t select;
11578 };
11579
11580 static void
11581 cmd_set_fdir_input_set_parsed(void *parsed_result,
11582         __rte_unused struct cmdline *cl,
11583         __rte_unused void *data)
11584 {
11585         struct cmd_set_fdir_input_set_result *res = parsed_result;
11586         struct rte_eth_fdir_filter_info info;
11587
11588         memset(&info, 0, sizeof(info));
11589         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11590         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11591         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11592         info.info.input_set_conf.inset_size = 1;
11593         if (!strcmp(res->select, "select"))
11594                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11595         else if (!strcmp(res->select, "add"))
11596                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11597         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11598                 RTE_ETH_FILTER_SET, &info);
11599 }
11600
11601 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11602         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11603         set_fdir_input_set, "set_fdir_input_set");
11604 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11605         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11606         port_id, UINT16);
11607 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11608         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11609         flow_type,
11610         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11611         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11612 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11613         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11614         inset_field,
11615         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11616         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11617         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11618         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11619         "sctp-veri-tag#none");
11620 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11621         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11622         select, "select#add");
11623
11624 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11625         .f = cmd_set_fdir_input_set_parsed,
11626         .data = NULL,
11627         .help_str = "set_fdir_input_set <port_id> "
11628         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11629         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11630         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11631         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11632         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11633         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11634         "sctp-veri-tag|none select|add",
11635         .tokens = {
11636                 (void *)&cmd_set_fdir_input_set_cmd,
11637                 (void *)&cmd_set_fdir_input_set_port_id,
11638                 (void *)&cmd_set_fdir_input_set_flow_type,
11639                 (void *)&cmd_set_fdir_input_set_field,
11640                 (void *)&cmd_set_fdir_input_set_select,
11641                 NULL,
11642         },
11643 };
11644
11645 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11646 struct cmd_mcast_addr_result {
11647         cmdline_fixed_string_t mcast_addr_cmd;
11648         cmdline_fixed_string_t what;
11649         uint16_t port_num;
11650         struct ether_addr mc_addr;
11651 };
11652
11653 static void cmd_mcast_addr_parsed(void *parsed_result,
11654                 __attribute__((unused)) struct cmdline *cl,
11655                 __attribute__((unused)) void *data)
11656 {
11657         struct cmd_mcast_addr_result *res = parsed_result;
11658
11659         if (!is_multicast_ether_addr(&res->mc_addr)) {
11660                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11661                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11662                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11663                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11664                 return;
11665         }
11666         if (strcmp(res->what, "add") == 0)
11667                 mcast_addr_add(res->port_num, &res->mc_addr);
11668         else
11669                 mcast_addr_remove(res->port_num, &res->mc_addr);
11670 }
11671
11672 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11673         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11674                                  mcast_addr_cmd, "mcast_addr");
11675 cmdline_parse_token_string_t cmd_mcast_addr_what =
11676         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11677                                  "add#remove");
11678 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11679         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11680 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11681         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11682
11683 cmdline_parse_inst_t cmd_mcast_addr = {
11684         .f = cmd_mcast_addr_parsed,
11685         .data = (void *)0,
11686         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11687                 "Add/Remove multicast MAC address on port_id",
11688         .tokens = {
11689                 (void *)&cmd_mcast_addr_cmd,
11690                 (void *)&cmd_mcast_addr_what,
11691                 (void *)&cmd_mcast_addr_portnum,
11692                 (void *)&cmd_mcast_addr_addr,
11693                 NULL,
11694         },
11695 };
11696
11697 /* l2 tunnel config
11698  * only support E-tag now.
11699  */
11700
11701 /* Ether type config */
11702 struct cmd_config_l2_tunnel_eth_type_result {
11703         cmdline_fixed_string_t port;
11704         cmdline_fixed_string_t config;
11705         cmdline_fixed_string_t all;
11706         uint8_t id;
11707         cmdline_fixed_string_t l2_tunnel;
11708         cmdline_fixed_string_t l2_tunnel_type;
11709         cmdline_fixed_string_t eth_type;
11710         uint16_t eth_type_val;
11711 };
11712
11713 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11714         TOKEN_STRING_INITIALIZER
11715                 (struct cmd_config_l2_tunnel_eth_type_result,
11716                  port, "port");
11717 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_config_l2_tunnel_eth_type_result,
11720                  config, "config");
11721 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11722         TOKEN_STRING_INITIALIZER
11723                 (struct cmd_config_l2_tunnel_eth_type_result,
11724                  all, "all");
11725 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11726         TOKEN_NUM_INITIALIZER
11727                 (struct cmd_config_l2_tunnel_eth_type_result,
11728                  id, UINT8);
11729 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11730         TOKEN_STRING_INITIALIZER
11731                 (struct cmd_config_l2_tunnel_eth_type_result,
11732                  l2_tunnel, "l2-tunnel");
11733 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11734         TOKEN_STRING_INITIALIZER
11735                 (struct cmd_config_l2_tunnel_eth_type_result,
11736                  l2_tunnel_type, "E-tag");
11737 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11738         TOKEN_STRING_INITIALIZER
11739                 (struct cmd_config_l2_tunnel_eth_type_result,
11740                  eth_type, "ether-type");
11741 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11742         TOKEN_NUM_INITIALIZER
11743                 (struct cmd_config_l2_tunnel_eth_type_result,
11744                  eth_type_val, UINT16);
11745
11746 static enum rte_eth_tunnel_type
11747 str2fdir_l2_tunnel_type(char *string)
11748 {
11749         uint32_t i = 0;
11750
11751         static const struct {
11752                 char str[32];
11753                 enum rte_eth_tunnel_type type;
11754         } l2_tunnel_type_str[] = {
11755                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11756         };
11757
11758         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11759                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11760                         return l2_tunnel_type_str[i].type;
11761         }
11762         return RTE_TUNNEL_TYPE_NONE;
11763 }
11764
11765 /* ether type config for all ports */
11766 static void
11767 cmd_config_l2_tunnel_eth_type_all_parsed
11768         (void *parsed_result,
11769          __attribute__((unused)) struct cmdline *cl,
11770          __attribute__((unused)) void *data)
11771 {
11772         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11773         struct rte_eth_l2_tunnel_conf entry;
11774         portid_t pid;
11775
11776         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11777         entry.ether_type = res->eth_type_val;
11778
11779         RTE_ETH_FOREACH_DEV(pid) {
11780                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11781         }
11782 }
11783
11784 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11785         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11786         .data = NULL,
11787         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11788         .tokens = {
11789                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11790                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11791                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11792                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11793                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11794                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11795                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11796                 NULL,
11797         },
11798 };
11799
11800 /* ether type config for a specific port */
11801 static void
11802 cmd_config_l2_tunnel_eth_type_specific_parsed(
11803         void *parsed_result,
11804         __attribute__((unused)) struct cmdline *cl,
11805         __attribute__((unused)) void *data)
11806 {
11807         struct cmd_config_l2_tunnel_eth_type_result *res =
11808                  parsed_result;
11809         struct rte_eth_l2_tunnel_conf entry;
11810
11811         if (port_id_is_invalid(res->id, ENABLED_WARN))
11812                 return;
11813
11814         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11815         entry.ether_type = res->eth_type_val;
11816
11817         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11818 }
11819
11820 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11821         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11822         .data = NULL,
11823         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11824         .tokens = {
11825                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11826                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11827                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11828                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11829                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11830                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11831                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11832                 NULL,
11833         },
11834 };
11835
11836 /* Enable/disable l2 tunnel */
11837 struct cmd_config_l2_tunnel_en_dis_result {
11838         cmdline_fixed_string_t port;
11839         cmdline_fixed_string_t config;
11840         cmdline_fixed_string_t all;
11841         uint8_t id;
11842         cmdline_fixed_string_t l2_tunnel;
11843         cmdline_fixed_string_t l2_tunnel_type;
11844         cmdline_fixed_string_t en_dis;
11845 };
11846
11847 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_config_l2_tunnel_en_dis_result,
11850                  port, "port");
11851 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11852         TOKEN_STRING_INITIALIZER
11853                 (struct cmd_config_l2_tunnel_en_dis_result,
11854                  config, "config");
11855 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11856         TOKEN_STRING_INITIALIZER
11857                 (struct cmd_config_l2_tunnel_en_dis_result,
11858                  all, "all");
11859 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11860         TOKEN_NUM_INITIALIZER
11861                 (struct cmd_config_l2_tunnel_en_dis_result,
11862                  id, UINT8);
11863 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11864         TOKEN_STRING_INITIALIZER
11865                 (struct cmd_config_l2_tunnel_en_dis_result,
11866                  l2_tunnel, "l2-tunnel");
11867 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11868         TOKEN_STRING_INITIALIZER
11869                 (struct cmd_config_l2_tunnel_en_dis_result,
11870                  l2_tunnel_type, "E-tag");
11871 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_config_l2_tunnel_en_dis_result,
11874                  en_dis, "enable#disable");
11875
11876 /* enable/disable l2 tunnel for all ports */
11877 static void
11878 cmd_config_l2_tunnel_en_dis_all_parsed(
11879         void *parsed_result,
11880         __attribute__((unused)) struct cmdline *cl,
11881         __attribute__((unused)) void *data)
11882 {
11883         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11884         struct rte_eth_l2_tunnel_conf entry;
11885         portid_t pid;
11886         uint8_t en;
11887
11888         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11889
11890         if (!strcmp("enable", res->en_dis))
11891                 en = 1;
11892         else
11893                 en = 0;
11894
11895         RTE_ETH_FOREACH_DEV(pid) {
11896                 rte_eth_dev_l2_tunnel_offload_set(pid,
11897                                                   &entry,
11898                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11899                                                   en);
11900         }
11901 }
11902
11903 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11904         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11905         .data = NULL,
11906         .help_str = "port config all l2-tunnel E-tag enable|disable",
11907         .tokens = {
11908                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11909                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11910                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11911                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11912                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11913                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11914                 NULL,
11915         },
11916 };
11917
11918 /* enable/disable l2 tunnel for a port */
11919 static void
11920 cmd_config_l2_tunnel_en_dis_specific_parsed(
11921         void *parsed_result,
11922         __attribute__((unused)) struct cmdline *cl,
11923         __attribute__((unused)) void *data)
11924 {
11925         struct cmd_config_l2_tunnel_en_dis_result *res =
11926                 parsed_result;
11927         struct rte_eth_l2_tunnel_conf entry;
11928
11929         if (port_id_is_invalid(res->id, ENABLED_WARN))
11930                 return;
11931
11932         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11933
11934         if (!strcmp("enable", res->en_dis))
11935                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11936                                                   &entry,
11937                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11938                                                   1);
11939         else
11940                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11941                                                   &entry,
11942                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11943                                                   0);
11944 }
11945
11946 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11947         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11948         .data = NULL,
11949         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11950         .tokens = {
11951                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11952                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11953                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11954                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11955                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11956                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11957                 NULL,
11958         },
11959 };
11960
11961 /* E-tag configuration */
11962
11963 /* Common result structure for all E-tag configuration */
11964 struct cmd_config_e_tag_result {
11965         cmdline_fixed_string_t e_tag;
11966         cmdline_fixed_string_t set;
11967         cmdline_fixed_string_t insertion;
11968         cmdline_fixed_string_t stripping;
11969         cmdline_fixed_string_t forwarding;
11970         cmdline_fixed_string_t filter;
11971         cmdline_fixed_string_t add;
11972         cmdline_fixed_string_t del;
11973         cmdline_fixed_string_t on;
11974         cmdline_fixed_string_t off;
11975         cmdline_fixed_string_t on_off;
11976         cmdline_fixed_string_t port_tag_id;
11977         uint32_t port_tag_id_val;
11978         cmdline_fixed_string_t e_tag_id;
11979         uint16_t e_tag_id_val;
11980         cmdline_fixed_string_t dst_pool;
11981         uint8_t dst_pool_val;
11982         cmdline_fixed_string_t port;
11983         portid_t port_id;
11984         cmdline_fixed_string_t vf;
11985         uint8_t vf_id;
11986 };
11987
11988 /* Common CLI fields for all E-tag configuration */
11989 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11990         TOKEN_STRING_INITIALIZER
11991                 (struct cmd_config_e_tag_result,
11992                  e_tag, "E-tag");
11993 cmdline_parse_token_string_t cmd_config_e_tag_set =
11994         TOKEN_STRING_INITIALIZER
11995                 (struct cmd_config_e_tag_result,
11996                  set, "set");
11997 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11998         TOKEN_STRING_INITIALIZER
11999                 (struct cmd_config_e_tag_result,
12000                  insertion, "insertion");
12001 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12002         TOKEN_STRING_INITIALIZER
12003                 (struct cmd_config_e_tag_result,
12004                  stripping, "stripping");
12005 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12006         TOKEN_STRING_INITIALIZER
12007                 (struct cmd_config_e_tag_result,
12008                  forwarding, "forwarding");
12009 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12010         TOKEN_STRING_INITIALIZER
12011                 (struct cmd_config_e_tag_result,
12012                  filter, "filter");
12013 cmdline_parse_token_string_t cmd_config_e_tag_add =
12014         TOKEN_STRING_INITIALIZER
12015                 (struct cmd_config_e_tag_result,
12016                  add, "add");
12017 cmdline_parse_token_string_t cmd_config_e_tag_del =
12018         TOKEN_STRING_INITIALIZER
12019                 (struct cmd_config_e_tag_result,
12020                  del, "del");
12021 cmdline_parse_token_string_t cmd_config_e_tag_on =
12022         TOKEN_STRING_INITIALIZER
12023                 (struct cmd_config_e_tag_result,
12024                  on, "on");
12025 cmdline_parse_token_string_t cmd_config_e_tag_off =
12026         TOKEN_STRING_INITIALIZER
12027                 (struct cmd_config_e_tag_result,
12028                  off, "off");
12029 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12030         TOKEN_STRING_INITIALIZER
12031                 (struct cmd_config_e_tag_result,
12032                  on_off, "on#off");
12033 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12034         TOKEN_STRING_INITIALIZER
12035                 (struct cmd_config_e_tag_result,
12036                  port_tag_id, "port-tag-id");
12037 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12038         TOKEN_NUM_INITIALIZER
12039                 (struct cmd_config_e_tag_result,
12040                  port_tag_id_val, UINT32);
12041 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12042         TOKEN_STRING_INITIALIZER
12043                 (struct cmd_config_e_tag_result,
12044                  e_tag_id, "e-tag-id");
12045 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12046         TOKEN_NUM_INITIALIZER
12047                 (struct cmd_config_e_tag_result,
12048                  e_tag_id_val, UINT16);
12049 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12050         TOKEN_STRING_INITIALIZER
12051                 (struct cmd_config_e_tag_result,
12052                  dst_pool, "dst-pool");
12053 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12054         TOKEN_NUM_INITIALIZER
12055                 (struct cmd_config_e_tag_result,
12056                  dst_pool_val, UINT8);
12057 cmdline_parse_token_string_t cmd_config_e_tag_port =
12058         TOKEN_STRING_INITIALIZER
12059                 (struct cmd_config_e_tag_result,
12060                  port, "port");
12061 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12062         TOKEN_NUM_INITIALIZER
12063                 (struct cmd_config_e_tag_result,
12064                  port_id, UINT16);
12065 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12066         TOKEN_STRING_INITIALIZER
12067                 (struct cmd_config_e_tag_result,
12068                  vf, "vf");
12069 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12070         TOKEN_NUM_INITIALIZER
12071                 (struct cmd_config_e_tag_result,
12072                  vf_id, UINT8);
12073
12074 /* E-tag insertion configuration */
12075 static void
12076 cmd_config_e_tag_insertion_en_parsed(
12077         void *parsed_result,
12078         __attribute__((unused)) struct cmdline *cl,
12079         __attribute__((unused)) void *data)
12080 {
12081         struct cmd_config_e_tag_result *res =
12082                 parsed_result;
12083         struct rte_eth_l2_tunnel_conf entry;
12084
12085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12086                 return;
12087
12088         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12089         entry.tunnel_id = res->port_tag_id_val;
12090         entry.vf_id = res->vf_id;
12091         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12092                                           &entry,
12093                                           ETH_L2_TUNNEL_INSERTION_MASK,
12094                                           1);
12095 }
12096
12097 static void
12098 cmd_config_e_tag_insertion_dis_parsed(
12099         void *parsed_result,
12100         __attribute__((unused)) struct cmdline *cl,
12101         __attribute__((unused)) void *data)
12102 {
12103         struct cmd_config_e_tag_result *res =
12104                 parsed_result;
12105         struct rte_eth_l2_tunnel_conf entry;
12106
12107         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12108                 return;
12109
12110         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12111         entry.vf_id = res->vf_id;
12112
12113         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12114                                           &entry,
12115                                           ETH_L2_TUNNEL_INSERTION_MASK,
12116                                           0);
12117 }
12118
12119 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12120         .f = cmd_config_e_tag_insertion_en_parsed,
12121         .data = NULL,
12122         .help_str = "E-tag ... : E-tag insertion enable",
12123         .tokens = {
12124                 (void *)&cmd_config_e_tag_e_tag,
12125                 (void *)&cmd_config_e_tag_set,
12126                 (void *)&cmd_config_e_tag_insertion,
12127                 (void *)&cmd_config_e_tag_on,
12128                 (void *)&cmd_config_e_tag_port_tag_id,
12129                 (void *)&cmd_config_e_tag_port_tag_id_val,
12130                 (void *)&cmd_config_e_tag_port,
12131                 (void *)&cmd_config_e_tag_port_id,
12132                 (void *)&cmd_config_e_tag_vf,
12133                 (void *)&cmd_config_e_tag_vf_id,
12134                 NULL,
12135         },
12136 };
12137
12138 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12139         .f = cmd_config_e_tag_insertion_dis_parsed,
12140         .data = NULL,
12141         .help_str = "E-tag ... : E-tag insertion disable",
12142         .tokens = {
12143                 (void *)&cmd_config_e_tag_e_tag,
12144                 (void *)&cmd_config_e_tag_set,
12145                 (void *)&cmd_config_e_tag_insertion,
12146                 (void *)&cmd_config_e_tag_off,
12147                 (void *)&cmd_config_e_tag_port,
12148                 (void *)&cmd_config_e_tag_port_id,
12149                 (void *)&cmd_config_e_tag_vf,
12150                 (void *)&cmd_config_e_tag_vf_id,
12151                 NULL,
12152         },
12153 };
12154
12155 /* E-tag stripping configuration */
12156 static void
12157 cmd_config_e_tag_stripping_parsed(
12158         void *parsed_result,
12159         __attribute__((unused)) struct cmdline *cl,
12160         __attribute__((unused)) void *data)
12161 {
12162         struct cmd_config_e_tag_result *res =
12163                 parsed_result;
12164         struct rte_eth_l2_tunnel_conf entry;
12165
12166         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12167                 return;
12168
12169         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12170
12171         if (!strcmp(res->on_off, "on"))
12172                 rte_eth_dev_l2_tunnel_offload_set
12173                         (res->port_id,
12174                          &entry,
12175                          ETH_L2_TUNNEL_STRIPPING_MASK,
12176                          1);
12177         else
12178                 rte_eth_dev_l2_tunnel_offload_set
12179                         (res->port_id,
12180                          &entry,
12181                          ETH_L2_TUNNEL_STRIPPING_MASK,
12182                          0);
12183 }
12184
12185 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12186         .f = cmd_config_e_tag_stripping_parsed,
12187         .data = NULL,
12188         .help_str = "E-tag ... : E-tag stripping enable/disable",
12189         .tokens = {
12190                 (void *)&cmd_config_e_tag_e_tag,
12191                 (void *)&cmd_config_e_tag_set,
12192                 (void *)&cmd_config_e_tag_stripping,
12193                 (void *)&cmd_config_e_tag_on_off,
12194                 (void *)&cmd_config_e_tag_port,
12195                 (void *)&cmd_config_e_tag_port_id,
12196                 NULL,
12197         },
12198 };
12199
12200 /* E-tag forwarding configuration */
12201 static void
12202 cmd_config_e_tag_forwarding_parsed(
12203         void *parsed_result,
12204         __attribute__((unused)) struct cmdline *cl,
12205         __attribute__((unused)) void *data)
12206 {
12207         struct cmd_config_e_tag_result *res = parsed_result;
12208         struct rte_eth_l2_tunnel_conf entry;
12209
12210         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12211                 return;
12212
12213         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12214
12215         if (!strcmp(res->on_off, "on"))
12216                 rte_eth_dev_l2_tunnel_offload_set
12217                         (res->port_id,
12218                          &entry,
12219                          ETH_L2_TUNNEL_FORWARDING_MASK,
12220                          1);
12221         else
12222                 rte_eth_dev_l2_tunnel_offload_set
12223                         (res->port_id,
12224                          &entry,
12225                          ETH_L2_TUNNEL_FORWARDING_MASK,
12226                          0);
12227 }
12228
12229 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12230         .f = cmd_config_e_tag_forwarding_parsed,
12231         .data = NULL,
12232         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12233         .tokens = {
12234                 (void *)&cmd_config_e_tag_e_tag,
12235                 (void *)&cmd_config_e_tag_set,
12236                 (void *)&cmd_config_e_tag_forwarding,
12237                 (void *)&cmd_config_e_tag_on_off,
12238                 (void *)&cmd_config_e_tag_port,
12239                 (void *)&cmd_config_e_tag_port_id,
12240                 NULL,
12241         },
12242 };
12243
12244 /* E-tag filter configuration */
12245 static void
12246 cmd_config_e_tag_filter_add_parsed(
12247         void *parsed_result,
12248         __attribute__((unused)) struct cmdline *cl,
12249         __attribute__((unused)) void *data)
12250 {
12251         struct cmd_config_e_tag_result *res = parsed_result;
12252         struct rte_eth_l2_tunnel_conf entry;
12253         int ret = 0;
12254
12255         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12256                 return;
12257
12258         if (res->e_tag_id_val > 0x3fff) {
12259                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12260                 return;
12261         }
12262
12263         ret = rte_eth_dev_filter_supported(res->port_id,
12264                                            RTE_ETH_FILTER_L2_TUNNEL);
12265         if (ret < 0) {
12266                 printf("E-tag filter is not supported on port %u.\n",
12267                        res->port_id);
12268                 return;
12269         }
12270
12271         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12272         entry.tunnel_id = res->e_tag_id_val;
12273         entry.pool = res->dst_pool_val;
12274
12275         ret = rte_eth_dev_filter_ctrl(res->port_id,
12276                                       RTE_ETH_FILTER_L2_TUNNEL,
12277                                       RTE_ETH_FILTER_ADD,
12278                                       &entry);
12279         if (ret < 0)
12280                 printf("E-tag filter programming error: (%s)\n",
12281                        strerror(-ret));
12282 }
12283
12284 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12285         .f = cmd_config_e_tag_filter_add_parsed,
12286         .data = NULL,
12287         .help_str = "E-tag ... : E-tag filter add",
12288         .tokens = {
12289                 (void *)&cmd_config_e_tag_e_tag,
12290                 (void *)&cmd_config_e_tag_set,
12291                 (void *)&cmd_config_e_tag_filter,
12292                 (void *)&cmd_config_e_tag_add,
12293                 (void *)&cmd_config_e_tag_e_tag_id,
12294                 (void *)&cmd_config_e_tag_e_tag_id_val,
12295                 (void *)&cmd_config_e_tag_dst_pool,
12296                 (void *)&cmd_config_e_tag_dst_pool_val,
12297                 (void *)&cmd_config_e_tag_port,
12298                 (void *)&cmd_config_e_tag_port_id,
12299                 NULL,
12300         },
12301 };
12302
12303 static void
12304 cmd_config_e_tag_filter_del_parsed(
12305         void *parsed_result,
12306         __attribute__((unused)) struct cmdline *cl,
12307         __attribute__((unused)) void *data)
12308 {
12309         struct cmd_config_e_tag_result *res = parsed_result;
12310         struct rte_eth_l2_tunnel_conf entry;
12311         int ret = 0;
12312
12313         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12314                 return;
12315
12316         if (res->e_tag_id_val > 0x3fff) {
12317                 printf("e-tag-id must be less than 0x3fff.\n");
12318                 return;
12319         }
12320
12321         ret = rte_eth_dev_filter_supported(res->port_id,
12322                                            RTE_ETH_FILTER_L2_TUNNEL);
12323         if (ret < 0) {
12324                 printf("E-tag filter is not supported on port %u.\n",
12325                        res->port_id);
12326                 return;
12327         }
12328
12329         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12330         entry.tunnel_id = res->e_tag_id_val;
12331
12332         ret = rte_eth_dev_filter_ctrl(res->port_id,
12333                                       RTE_ETH_FILTER_L2_TUNNEL,
12334                                       RTE_ETH_FILTER_DELETE,
12335                                       &entry);
12336         if (ret < 0)
12337                 printf("E-tag filter programming error: (%s)\n",
12338                        strerror(-ret));
12339 }
12340
12341 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12342         .f = cmd_config_e_tag_filter_del_parsed,
12343         .data = NULL,
12344         .help_str = "E-tag ... : E-tag filter delete",
12345         .tokens = {
12346                 (void *)&cmd_config_e_tag_e_tag,
12347                 (void *)&cmd_config_e_tag_set,
12348                 (void *)&cmd_config_e_tag_filter,
12349                 (void *)&cmd_config_e_tag_del,
12350                 (void *)&cmd_config_e_tag_e_tag_id,
12351                 (void *)&cmd_config_e_tag_e_tag_id_val,
12352                 (void *)&cmd_config_e_tag_port,
12353                 (void *)&cmd_config_e_tag_port_id,
12354                 NULL,
12355         },
12356 };
12357
12358 /* vf vlan anti spoof configuration */
12359
12360 /* Common result structure for vf vlan anti spoof */
12361 struct cmd_vf_vlan_anti_spoof_result {
12362         cmdline_fixed_string_t set;
12363         cmdline_fixed_string_t vf;
12364         cmdline_fixed_string_t vlan;
12365         cmdline_fixed_string_t antispoof;
12366         portid_t port_id;
12367         uint32_t vf_id;
12368         cmdline_fixed_string_t on_off;
12369 };
12370
12371 /* Common CLI fields for vf vlan anti spoof enable disable */
12372 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12373         TOKEN_STRING_INITIALIZER
12374                 (struct cmd_vf_vlan_anti_spoof_result,
12375                  set, "set");
12376 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_vf_vlan_anti_spoof_result,
12379                  vf, "vf");
12380 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12381         TOKEN_STRING_INITIALIZER
12382                 (struct cmd_vf_vlan_anti_spoof_result,
12383                  vlan, "vlan");
12384 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12385         TOKEN_STRING_INITIALIZER
12386                 (struct cmd_vf_vlan_anti_spoof_result,
12387                  antispoof, "antispoof");
12388 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12389         TOKEN_NUM_INITIALIZER
12390                 (struct cmd_vf_vlan_anti_spoof_result,
12391                  port_id, UINT16);
12392 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12393         TOKEN_NUM_INITIALIZER
12394                 (struct cmd_vf_vlan_anti_spoof_result,
12395                  vf_id, UINT32);
12396 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12397         TOKEN_STRING_INITIALIZER
12398                 (struct cmd_vf_vlan_anti_spoof_result,
12399                  on_off, "on#off");
12400
12401 static void
12402 cmd_set_vf_vlan_anti_spoof_parsed(
12403         void *parsed_result,
12404         __attribute__((unused)) struct cmdline *cl,
12405         __attribute__((unused)) void *data)
12406 {
12407         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12408         int ret = -ENOTSUP;
12409
12410         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12411
12412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12413                 return;
12414
12415 #ifdef RTE_LIBRTE_IXGBE_PMD
12416         if (ret == -ENOTSUP)
12417                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12418                                 res->vf_id, is_on);
12419 #endif
12420 #ifdef RTE_LIBRTE_I40E_PMD
12421         if (ret == -ENOTSUP)
12422                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12423                                 res->vf_id, is_on);
12424 #endif
12425 #ifdef RTE_LIBRTE_BNXT_PMD
12426         if (ret == -ENOTSUP)
12427                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12428                                 res->vf_id, is_on);
12429 #endif
12430
12431         switch (ret) {
12432         case 0:
12433                 break;
12434         case -EINVAL:
12435                 printf("invalid vf_id %d\n", res->vf_id);
12436                 break;
12437         case -ENODEV:
12438                 printf("invalid port_id %d\n", res->port_id);
12439                 break;
12440         case -ENOTSUP:
12441                 printf("function not implemented\n");
12442                 break;
12443         default:
12444                 printf("programming error: (%s)\n", strerror(-ret));
12445         }
12446 }
12447
12448 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12449         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12450         .data = NULL,
12451         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12452         .tokens = {
12453                 (void *)&cmd_vf_vlan_anti_spoof_set,
12454                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12455                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12456                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12457                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12458                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12459                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12460                 NULL,
12461         },
12462 };
12463
12464 /* vf mac anti spoof configuration */
12465
12466 /* Common result structure for vf mac anti spoof */
12467 struct cmd_vf_mac_anti_spoof_result {
12468         cmdline_fixed_string_t set;
12469         cmdline_fixed_string_t vf;
12470         cmdline_fixed_string_t mac;
12471         cmdline_fixed_string_t antispoof;
12472         portid_t port_id;
12473         uint32_t vf_id;
12474         cmdline_fixed_string_t on_off;
12475 };
12476
12477 /* Common CLI fields for vf mac anti spoof enable disable */
12478 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_vf_mac_anti_spoof_result,
12481                  set, "set");
12482 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_vf_mac_anti_spoof_result,
12485                  vf, "vf");
12486 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_vf_mac_anti_spoof_result,
12489                  mac, "mac");
12490 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_vf_mac_anti_spoof_result,
12493                  antispoof, "antispoof");
12494 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12495         TOKEN_NUM_INITIALIZER
12496                 (struct cmd_vf_mac_anti_spoof_result,
12497                  port_id, UINT16);
12498 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_vf_mac_anti_spoof_result,
12501                  vf_id, UINT32);
12502 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_vf_mac_anti_spoof_result,
12505                  on_off, "on#off");
12506
12507 static void
12508 cmd_set_vf_mac_anti_spoof_parsed(
12509         void *parsed_result,
12510         __attribute__((unused)) struct cmdline *cl,
12511         __attribute__((unused)) void *data)
12512 {
12513         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12514         int ret = -ENOTSUP;
12515
12516         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12517
12518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12519                 return;
12520
12521 #ifdef RTE_LIBRTE_IXGBE_PMD
12522         if (ret == -ENOTSUP)
12523                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12524                         res->vf_id, is_on);
12525 #endif
12526 #ifdef RTE_LIBRTE_I40E_PMD
12527         if (ret == -ENOTSUP)
12528                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12529                         res->vf_id, is_on);
12530 #endif
12531 #ifdef RTE_LIBRTE_BNXT_PMD
12532         if (ret == -ENOTSUP)
12533                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12534                         res->vf_id, is_on);
12535 #endif
12536
12537         switch (ret) {
12538         case 0:
12539                 break;
12540         case -EINVAL:
12541                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12542                 break;
12543         case -ENODEV:
12544                 printf("invalid port_id %d\n", res->port_id);
12545                 break;
12546         case -ENOTSUP:
12547                 printf("function not implemented\n");
12548                 break;
12549         default:
12550                 printf("programming error: (%s)\n", strerror(-ret));
12551         }
12552 }
12553
12554 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12555         .f = cmd_set_vf_mac_anti_spoof_parsed,
12556         .data = NULL,
12557         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12558         .tokens = {
12559                 (void *)&cmd_vf_mac_anti_spoof_set,
12560                 (void *)&cmd_vf_mac_anti_spoof_vf,
12561                 (void *)&cmd_vf_mac_anti_spoof_mac,
12562                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12563                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12564                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12565                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12566                 NULL,
12567         },
12568 };
12569
12570 /* vf vlan strip queue configuration */
12571
12572 /* Common result structure for vf mac anti spoof */
12573 struct cmd_vf_vlan_stripq_result {
12574         cmdline_fixed_string_t set;
12575         cmdline_fixed_string_t vf;
12576         cmdline_fixed_string_t vlan;
12577         cmdline_fixed_string_t stripq;
12578         portid_t port_id;
12579         uint16_t vf_id;
12580         cmdline_fixed_string_t on_off;
12581 };
12582
12583 /* Common CLI fields for vf vlan strip enable disable */
12584 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12585         TOKEN_STRING_INITIALIZER
12586                 (struct cmd_vf_vlan_stripq_result,
12587                  set, "set");
12588 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12589         TOKEN_STRING_INITIALIZER
12590                 (struct cmd_vf_vlan_stripq_result,
12591                  vf, "vf");
12592 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12593         TOKEN_STRING_INITIALIZER
12594                 (struct cmd_vf_vlan_stripq_result,
12595                  vlan, "vlan");
12596 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12597         TOKEN_STRING_INITIALIZER
12598                 (struct cmd_vf_vlan_stripq_result,
12599                  stripq, "stripq");
12600 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12601         TOKEN_NUM_INITIALIZER
12602                 (struct cmd_vf_vlan_stripq_result,
12603                  port_id, UINT16);
12604 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12605         TOKEN_NUM_INITIALIZER
12606                 (struct cmd_vf_vlan_stripq_result,
12607                  vf_id, UINT16);
12608 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12609         TOKEN_STRING_INITIALIZER
12610                 (struct cmd_vf_vlan_stripq_result,
12611                  on_off, "on#off");
12612
12613 static void
12614 cmd_set_vf_vlan_stripq_parsed(
12615         void *parsed_result,
12616         __attribute__((unused)) struct cmdline *cl,
12617         __attribute__((unused)) void *data)
12618 {
12619         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12620         int ret = -ENOTSUP;
12621
12622         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12623
12624         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12625                 return;
12626
12627 #ifdef RTE_LIBRTE_IXGBE_PMD
12628         if (ret == -ENOTSUP)
12629                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12630                         res->vf_id, is_on);
12631 #endif
12632 #ifdef RTE_LIBRTE_I40E_PMD
12633         if (ret == -ENOTSUP)
12634                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12635                         res->vf_id, is_on);
12636 #endif
12637 #ifdef RTE_LIBRTE_BNXT_PMD
12638         if (ret == -ENOTSUP)
12639                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12640                         res->vf_id, is_on);
12641 #endif
12642
12643         switch (ret) {
12644         case 0:
12645                 break;
12646         case -EINVAL:
12647                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12648                 break;
12649         case -ENODEV:
12650                 printf("invalid port_id %d\n", res->port_id);
12651                 break;
12652         case -ENOTSUP:
12653                 printf("function not implemented\n");
12654                 break;
12655         default:
12656                 printf("programming error: (%s)\n", strerror(-ret));
12657         }
12658 }
12659
12660 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12661         .f = cmd_set_vf_vlan_stripq_parsed,
12662         .data = NULL,
12663         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12664         .tokens = {
12665                 (void *)&cmd_vf_vlan_stripq_set,
12666                 (void *)&cmd_vf_vlan_stripq_vf,
12667                 (void *)&cmd_vf_vlan_stripq_vlan,
12668                 (void *)&cmd_vf_vlan_stripq_stripq,
12669                 (void *)&cmd_vf_vlan_stripq_port_id,
12670                 (void *)&cmd_vf_vlan_stripq_vf_id,
12671                 (void *)&cmd_vf_vlan_stripq_on_off,
12672                 NULL,
12673         },
12674 };
12675
12676 /* vf vlan insert configuration */
12677
12678 /* Common result structure for vf vlan insert */
12679 struct cmd_vf_vlan_insert_result {
12680         cmdline_fixed_string_t set;
12681         cmdline_fixed_string_t vf;
12682         cmdline_fixed_string_t vlan;
12683         cmdline_fixed_string_t insert;
12684         portid_t port_id;
12685         uint16_t vf_id;
12686         uint16_t vlan_id;
12687 };
12688
12689 /* Common CLI fields for vf vlan insert enable disable */
12690 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12691         TOKEN_STRING_INITIALIZER
12692                 (struct cmd_vf_vlan_insert_result,
12693                  set, "set");
12694 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12695         TOKEN_STRING_INITIALIZER
12696                 (struct cmd_vf_vlan_insert_result,
12697                  vf, "vf");
12698 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12699         TOKEN_STRING_INITIALIZER
12700                 (struct cmd_vf_vlan_insert_result,
12701                  vlan, "vlan");
12702 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_vf_vlan_insert_result,
12705                  insert, "insert");
12706 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12707         TOKEN_NUM_INITIALIZER
12708                 (struct cmd_vf_vlan_insert_result,
12709                  port_id, UINT16);
12710 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12711         TOKEN_NUM_INITIALIZER
12712                 (struct cmd_vf_vlan_insert_result,
12713                  vf_id, UINT16);
12714 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12715         TOKEN_NUM_INITIALIZER
12716                 (struct cmd_vf_vlan_insert_result,
12717                  vlan_id, UINT16);
12718
12719 static void
12720 cmd_set_vf_vlan_insert_parsed(
12721         void *parsed_result,
12722         __attribute__((unused)) struct cmdline *cl,
12723         __attribute__((unused)) void *data)
12724 {
12725         struct cmd_vf_vlan_insert_result *res = parsed_result;
12726         int ret = -ENOTSUP;
12727
12728         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12729                 return;
12730
12731 #ifdef RTE_LIBRTE_IXGBE_PMD
12732         if (ret == -ENOTSUP)
12733                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12734                         res->vlan_id);
12735 #endif
12736 #ifdef RTE_LIBRTE_I40E_PMD
12737         if (ret == -ENOTSUP)
12738                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12739                         res->vlan_id);
12740 #endif
12741 #ifdef RTE_LIBRTE_BNXT_PMD
12742         if (ret == -ENOTSUP)
12743                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12744                         res->vlan_id);
12745 #endif
12746
12747         switch (ret) {
12748         case 0:
12749                 break;
12750         case -EINVAL:
12751                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12752                 break;
12753         case -ENODEV:
12754                 printf("invalid port_id %d\n", res->port_id);
12755                 break;
12756         case -ENOTSUP:
12757                 printf("function not implemented\n");
12758                 break;
12759         default:
12760                 printf("programming error: (%s)\n", strerror(-ret));
12761         }
12762 }
12763
12764 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12765         .f = cmd_set_vf_vlan_insert_parsed,
12766         .data = NULL,
12767         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12768         .tokens = {
12769                 (void *)&cmd_vf_vlan_insert_set,
12770                 (void *)&cmd_vf_vlan_insert_vf,
12771                 (void *)&cmd_vf_vlan_insert_vlan,
12772                 (void *)&cmd_vf_vlan_insert_insert,
12773                 (void *)&cmd_vf_vlan_insert_port_id,
12774                 (void *)&cmd_vf_vlan_insert_vf_id,
12775                 (void *)&cmd_vf_vlan_insert_vlan_id,
12776                 NULL,
12777         },
12778 };
12779
12780 /* tx loopback configuration */
12781
12782 /* Common result structure for tx loopback */
12783 struct cmd_tx_loopback_result {
12784         cmdline_fixed_string_t set;
12785         cmdline_fixed_string_t tx;
12786         cmdline_fixed_string_t loopback;
12787         portid_t port_id;
12788         cmdline_fixed_string_t on_off;
12789 };
12790
12791 /* Common CLI fields for tx loopback enable disable */
12792 cmdline_parse_token_string_t cmd_tx_loopback_set =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_tx_loopback_result,
12795                  set, "set");
12796 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_tx_loopback_result,
12799                  tx, "tx");
12800 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12801         TOKEN_STRING_INITIALIZER
12802                 (struct cmd_tx_loopback_result,
12803                  loopback, "loopback");
12804 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12805         TOKEN_NUM_INITIALIZER
12806                 (struct cmd_tx_loopback_result,
12807                  port_id, UINT16);
12808 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12809         TOKEN_STRING_INITIALIZER
12810                 (struct cmd_tx_loopback_result,
12811                  on_off, "on#off");
12812
12813 static void
12814 cmd_set_tx_loopback_parsed(
12815         void *parsed_result,
12816         __attribute__((unused)) struct cmdline *cl,
12817         __attribute__((unused)) void *data)
12818 {
12819         struct cmd_tx_loopback_result *res = parsed_result;
12820         int ret = -ENOTSUP;
12821
12822         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12823
12824         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12825                 return;
12826
12827 #ifdef RTE_LIBRTE_IXGBE_PMD
12828         if (ret == -ENOTSUP)
12829                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12830 #endif
12831 #ifdef RTE_LIBRTE_I40E_PMD
12832         if (ret == -ENOTSUP)
12833                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12834 #endif
12835 #ifdef RTE_LIBRTE_BNXT_PMD
12836         if (ret == -ENOTSUP)
12837                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12838 #endif
12839 #ifdef RTE_LIBRTE_DPAA_PMD
12840         if (ret == -ENOTSUP)
12841                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12842 #endif
12843
12844         switch (ret) {
12845         case 0:
12846                 break;
12847         case -EINVAL:
12848                 printf("invalid is_on %d\n", is_on);
12849                 break;
12850         case -ENODEV:
12851                 printf("invalid port_id %d\n", res->port_id);
12852                 break;
12853         case -ENOTSUP:
12854                 printf("function not implemented\n");
12855                 break;
12856         default:
12857                 printf("programming error: (%s)\n", strerror(-ret));
12858         }
12859 }
12860
12861 cmdline_parse_inst_t cmd_set_tx_loopback = {
12862         .f = cmd_set_tx_loopback_parsed,
12863         .data = NULL,
12864         .help_str = "set tx loopback <port_id> on|off",
12865         .tokens = {
12866                 (void *)&cmd_tx_loopback_set,
12867                 (void *)&cmd_tx_loopback_tx,
12868                 (void *)&cmd_tx_loopback_loopback,
12869                 (void *)&cmd_tx_loopback_port_id,
12870                 (void *)&cmd_tx_loopback_on_off,
12871                 NULL,
12872         },
12873 };
12874
12875 /* all queues drop enable configuration */
12876
12877 /* Common result structure for all queues drop enable */
12878 struct cmd_all_queues_drop_en_result {
12879         cmdline_fixed_string_t set;
12880         cmdline_fixed_string_t all;
12881         cmdline_fixed_string_t queues;
12882         cmdline_fixed_string_t drop;
12883         portid_t port_id;
12884         cmdline_fixed_string_t on_off;
12885 };
12886
12887 /* Common CLI fields for tx loopback enable disable */
12888 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_all_queues_drop_en_result,
12891                  set, "set");
12892 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12893         TOKEN_STRING_INITIALIZER
12894                 (struct cmd_all_queues_drop_en_result,
12895                  all, "all");
12896 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12897         TOKEN_STRING_INITIALIZER
12898                 (struct cmd_all_queues_drop_en_result,
12899                  queues, "queues");
12900 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12901         TOKEN_STRING_INITIALIZER
12902                 (struct cmd_all_queues_drop_en_result,
12903                  drop, "drop");
12904 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12905         TOKEN_NUM_INITIALIZER
12906                 (struct cmd_all_queues_drop_en_result,
12907                  port_id, UINT16);
12908 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12909         TOKEN_STRING_INITIALIZER
12910                 (struct cmd_all_queues_drop_en_result,
12911                  on_off, "on#off");
12912
12913 static void
12914 cmd_set_all_queues_drop_en_parsed(
12915         void *parsed_result,
12916         __attribute__((unused)) struct cmdline *cl,
12917         __attribute__((unused)) void *data)
12918 {
12919         struct cmd_all_queues_drop_en_result *res = parsed_result;
12920         int ret = -ENOTSUP;
12921         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12922
12923         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12924                 return;
12925
12926 #ifdef RTE_LIBRTE_IXGBE_PMD
12927         if (ret == -ENOTSUP)
12928                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12929 #endif
12930 #ifdef RTE_LIBRTE_BNXT_PMD
12931         if (ret == -ENOTSUP)
12932                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12933 #endif
12934         switch (ret) {
12935         case 0:
12936                 break;
12937         case -EINVAL:
12938                 printf("invalid is_on %d\n", is_on);
12939                 break;
12940         case -ENODEV:
12941                 printf("invalid port_id %d\n", res->port_id);
12942                 break;
12943         case -ENOTSUP:
12944                 printf("function not implemented\n");
12945                 break;
12946         default:
12947                 printf("programming error: (%s)\n", strerror(-ret));
12948         }
12949 }
12950
12951 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12952         .f = cmd_set_all_queues_drop_en_parsed,
12953         .data = NULL,
12954         .help_str = "set all queues drop <port_id> on|off",
12955         .tokens = {
12956                 (void *)&cmd_all_queues_drop_en_set,
12957                 (void *)&cmd_all_queues_drop_en_all,
12958                 (void *)&cmd_all_queues_drop_en_queues,
12959                 (void *)&cmd_all_queues_drop_en_drop,
12960                 (void *)&cmd_all_queues_drop_en_port_id,
12961                 (void *)&cmd_all_queues_drop_en_on_off,
12962                 NULL,
12963         },
12964 };
12965
12966 /* vf split drop enable configuration */
12967
12968 /* Common result structure for vf split drop enable */
12969 struct cmd_vf_split_drop_en_result {
12970         cmdline_fixed_string_t set;
12971         cmdline_fixed_string_t vf;
12972         cmdline_fixed_string_t split;
12973         cmdline_fixed_string_t drop;
12974         portid_t port_id;
12975         uint16_t vf_id;
12976         cmdline_fixed_string_t on_off;
12977 };
12978
12979 /* Common CLI fields for vf split drop enable disable */
12980 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12981         TOKEN_STRING_INITIALIZER
12982                 (struct cmd_vf_split_drop_en_result,
12983                  set, "set");
12984 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12985         TOKEN_STRING_INITIALIZER
12986                 (struct cmd_vf_split_drop_en_result,
12987                  vf, "vf");
12988 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12989         TOKEN_STRING_INITIALIZER
12990                 (struct cmd_vf_split_drop_en_result,
12991                  split, "split");
12992 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12993         TOKEN_STRING_INITIALIZER
12994                 (struct cmd_vf_split_drop_en_result,
12995                  drop, "drop");
12996 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12997         TOKEN_NUM_INITIALIZER
12998                 (struct cmd_vf_split_drop_en_result,
12999                  port_id, UINT16);
13000 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13001         TOKEN_NUM_INITIALIZER
13002                 (struct cmd_vf_split_drop_en_result,
13003                  vf_id, UINT16);
13004 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13005         TOKEN_STRING_INITIALIZER
13006                 (struct cmd_vf_split_drop_en_result,
13007                  on_off, "on#off");
13008
13009 static void
13010 cmd_set_vf_split_drop_en_parsed(
13011         void *parsed_result,
13012         __attribute__((unused)) struct cmdline *cl,
13013         __attribute__((unused)) void *data)
13014 {
13015         struct cmd_vf_split_drop_en_result *res = parsed_result;
13016         int ret = -ENOTSUP;
13017         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13018
13019         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13020                 return;
13021
13022 #ifdef RTE_LIBRTE_IXGBE_PMD
13023         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13024                         is_on);
13025 #endif
13026         switch (ret) {
13027         case 0:
13028                 break;
13029         case -EINVAL:
13030                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13031                 break;
13032         case -ENODEV:
13033                 printf("invalid port_id %d\n", res->port_id);
13034                 break;
13035         case -ENOTSUP:
13036                 printf("not supported on port %d\n", res->port_id);
13037                 break;
13038         default:
13039                 printf("programming error: (%s)\n", strerror(-ret));
13040         }
13041 }
13042
13043 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13044         .f = cmd_set_vf_split_drop_en_parsed,
13045         .data = NULL,
13046         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13047         .tokens = {
13048                 (void *)&cmd_vf_split_drop_en_set,
13049                 (void *)&cmd_vf_split_drop_en_vf,
13050                 (void *)&cmd_vf_split_drop_en_split,
13051                 (void *)&cmd_vf_split_drop_en_drop,
13052                 (void *)&cmd_vf_split_drop_en_port_id,
13053                 (void *)&cmd_vf_split_drop_en_vf_id,
13054                 (void *)&cmd_vf_split_drop_en_on_off,
13055                 NULL,
13056         },
13057 };
13058
13059 /* vf mac address configuration */
13060
13061 /* Common result structure for vf mac address */
13062 struct cmd_set_vf_mac_addr_result {
13063         cmdline_fixed_string_t set;
13064         cmdline_fixed_string_t vf;
13065         cmdline_fixed_string_t mac;
13066         cmdline_fixed_string_t addr;
13067         portid_t port_id;
13068         uint16_t vf_id;
13069         struct ether_addr mac_addr;
13070
13071 };
13072
13073 /* Common CLI fields for vf split drop enable disable */
13074 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_set_vf_mac_addr_result,
13077                  set, "set");
13078 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_set_vf_mac_addr_result,
13081                  vf, "vf");
13082 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_set_vf_mac_addr_result,
13085                  mac, "mac");
13086 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13087         TOKEN_STRING_INITIALIZER
13088                 (struct cmd_set_vf_mac_addr_result,
13089                  addr, "addr");
13090 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13091         TOKEN_NUM_INITIALIZER
13092                 (struct cmd_set_vf_mac_addr_result,
13093                  port_id, UINT16);
13094 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13095         TOKEN_NUM_INITIALIZER
13096                 (struct cmd_set_vf_mac_addr_result,
13097                  vf_id, UINT16);
13098 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13099         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13100                  mac_addr);
13101
13102 static void
13103 cmd_set_vf_mac_addr_parsed(
13104         void *parsed_result,
13105         __attribute__((unused)) struct cmdline *cl,
13106         __attribute__((unused)) void *data)
13107 {
13108         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13109         int ret = -ENOTSUP;
13110
13111         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13112                 return;
13113
13114 #ifdef RTE_LIBRTE_IXGBE_PMD
13115         if (ret == -ENOTSUP)
13116                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13117                                 &res->mac_addr);
13118 #endif
13119 #ifdef RTE_LIBRTE_I40E_PMD
13120         if (ret == -ENOTSUP)
13121                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13122                                 &res->mac_addr);
13123 #endif
13124 #ifdef RTE_LIBRTE_BNXT_PMD
13125         if (ret == -ENOTSUP)
13126                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13127                                 &res->mac_addr);
13128 #endif
13129
13130         switch (ret) {
13131         case 0:
13132                 break;
13133         case -EINVAL:
13134                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13135                 break;
13136         case -ENODEV:
13137                 printf("invalid port_id %d\n", res->port_id);
13138                 break;
13139         case -ENOTSUP:
13140                 printf("function not implemented\n");
13141                 break;
13142         default:
13143                 printf("programming error: (%s)\n", strerror(-ret));
13144         }
13145 }
13146
13147 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13148         .f = cmd_set_vf_mac_addr_parsed,
13149         .data = NULL,
13150         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13151         .tokens = {
13152                 (void *)&cmd_set_vf_mac_addr_set,
13153                 (void *)&cmd_set_vf_mac_addr_vf,
13154                 (void *)&cmd_set_vf_mac_addr_mac,
13155                 (void *)&cmd_set_vf_mac_addr_addr,
13156                 (void *)&cmd_set_vf_mac_addr_port_id,
13157                 (void *)&cmd_set_vf_mac_addr_vf_id,
13158                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13159                 NULL,
13160         },
13161 };
13162
13163 /* MACsec configuration */
13164
13165 /* Common result structure for MACsec offload enable */
13166 struct cmd_macsec_offload_on_result {
13167         cmdline_fixed_string_t set;
13168         cmdline_fixed_string_t macsec;
13169         cmdline_fixed_string_t offload;
13170         portid_t port_id;
13171         cmdline_fixed_string_t on;
13172         cmdline_fixed_string_t encrypt;
13173         cmdline_fixed_string_t en_on_off;
13174         cmdline_fixed_string_t replay_protect;
13175         cmdline_fixed_string_t rp_on_off;
13176 };
13177
13178 /* Common CLI fields for MACsec offload disable */
13179 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13180         TOKEN_STRING_INITIALIZER
13181                 (struct cmd_macsec_offload_on_result,
13182                  set, "set");
13183 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13184         TOKEN_STRING_INITIALIZER
13185                 (struct cmd_macsec_offload_on_result,
13186                  macsec, "macsec");
13187 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13188         TOKEN_STRING_INITIALIZER
13189                 (struct cmd_macsec_offload_on_result,
13190                  offload, "offload");
13191 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13192         TOKEN_NUM_INITIALIZER
13193                 (struct cmd_macsec_offload_on_result,
13194                  port_id, UINT16);
13195 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13196         TOKEN_STRING_INITIALIZER
13197                 (struct cmd_macsec_offload_on_result,
13198                  on, "on");
13199 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13200         TOKEN_STRING_INITIALIZER
13201                 (struct cmd_macsec_offload_on_result,
13202                  encrypt, "encrypt");
13203 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13204         TOKEN_STRING_INITIALIZER
13205                 (struct cmd_macsec_offload_on_result,
13206                  en_on_off, "on#off");
13207 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13208         TOKEN_STRING_INITIALIZER
13209                 (struct cmd_macsec_offload_on_result,
13210                  replay_protect, "replay-protect");
13211 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13212         TOKEN_STRING_INITIALIZER
13213                 (struct cmd_macsec_offload_on_result,
13214                  rp_on_off, "on#off");
13215
13216 static void
13217 cmd_set_macsec_offload_on_parsed(
13218         void *parsed_result,
13219         __attribute__((unused)) struct cmdline *cl,
13220         __attribute__((unused)) void *data)
13221 {
13222         struct cmd_macsec_offload_on_result *res = parsed_result;
13223         int ret = -ENOTSUP;
13224         portid_t port_id = res->port_id;
13225         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13226         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13227         struct rte_eth_dev_info dev_info;
13228
13229         if (port_id_is_invalid(port_id, ENABLED_WARN))
13230                 return;
13231         if (!port_is_stopped(port_id)) {
13232                 printf("Please stop port %d first\n", port_id);
13233                 return;
13234         }
13235
13236         rte_eth_dev_info_get(port_id, &dev_info);
13237         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13238 #ifdef RTE_LIBRTE_IXGBE_PMD
13239                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13240 #endif
13241         }
13242         RTE_SET_USED(en);
13243         RTE_SET_USED(rp);
13244
13245         switch (ret) {
13246         case 0:
13247                 ports[port_id].dev_conf.txmode.offloads |=
13248                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13249                 cmd_reconfig_device_queue(port_id, 1, 1);
13250                 break;
13251         case -ENODEV:
13252                 printf("invalid port_id %d\n", port_id);
13253                 break;
13254         case -ENOTSUP:
13255                 printf("not supported on port %d\n", port_id);
13256                 break;
13257         default:
13258                 printf("programming error: (%s)\n", strerror(-ret));
13259         }
13260 }
13261
13262 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13263         .f = cmd_set_macsec_offload_on_parsed,
13264         .data = NULL,
13265         .help_str = "set macsec offload <port_id> on "
13266                 "encrypt on|off replay-protect on|off",
13267         .tokens = {
13268                 (void *)&cmd_macsec_offload_on_set,
13269                 (void *)&cmd_macsec_offload_on_macsec,
13270                 (void *)&cmd_macsec_offload_on_offload,
13271                 (void *)&cmd_macsec_offload_on_port_id,
13272                 (void *)&cmd_macsec_offload_on_on,
13273                 (void *)&cmd_macsec_offload_on_encrypt,
13274                 (void *)&cmd_macsec_offload_on_en_on_off,
13275                 (void *)&cmd_macsec_offload_on_replay_protect,
13276                 (void *)&cmd_macsec_offload_on_rp_on_off,
13277                 NULL,
13278         },
13279 };
13280
13281 /* Common result structure for MACsec offload disable */
13282 struct cmd_macsec_offload_off_result {
13283         cmdline_fixed_string_t set;
13284         cmdline_fixed_string_t macsec;
13285         cmdline_fixed_string_t offload;
13286         portid_t port_id;
13287         cmdline_fixed_string_t off;
13288 };
13289
13290 /* Common CLI fields for MACsec offload disable */
13291 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13292         TOKEN_STRING_INITIALIZER
13293                 (struct cmd_macsec_offload_off_result,
13294                  set, "set");
13295 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13296         TOKEN_STRING_INITIALIZER
13297                 (struct cmd_macsec_offload_off_result,
13298                  macsec, "macsec");
13299 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13300         TOKEN_STRING_INITIALIZER
13301                 (struct cmd_macsec_offload_off_result,
13302                  offload, "offload");
13303 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13304         TOKEN_NUM_INITIALIZER
13305                 (struct cmd_macsec_offload_off_result,
13306                  port_id, UINT16);
13307 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13308         TOKEN_STRING_INITIALIZER
13309                 (struct cmd_macsec_offload_off_result,
13310                  off, "off");
13311
13312 static void
13313 cmd_set_macsec_offload_off_parsed(
13314         void *parsed_result,
13315         __attribute__((unused)) struct cmdline *cl,
13316         __attribute__((unused)) void *data)
13317 {
13318         struct cmd_macsec_offload_off_result *res = parsed_result;
13319         int ret = -ENOTSUP;
13320         struct rte_eth_dev_info dev_info;
13321         portid_t port_id = res->port_id;
13322
13323         if (port_id_is_invalid(port_id, ENABLED_WARN))
13324                 return;
13325         if (!port_is_stopped(port_id)) {
13326                 printf("Please stop port %d first\n", port_id);
13327                 return;
13328         }
13329
13330         rte_eth_dev_info_get(port_id, &dev_info);
13331         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13332 #ifdef RTE_LIBRTE_IXGBE_PMD
13333                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13334 #endif
13335         }
13336         switch (ret) {
13337         case 0:
13338                 ports[port_id].dev_conf.txmode.offloads &=
13339                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13340                 cmd_reconfig_device_queue(port_id, 1, 1);
13341                 break;
13342         case -ENODEV:
13343                 printf("invalid port_id %d\n", port_id);
13344                 break;
13345         case -ENOTSUP:
13346                 printf("not supported on port %d\n", port_id);
13347                 break;
13348         default:
13349                 printf("programming error: (%s)\n", strerror(-ret));
13350         }
13351 }
13352
13353 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13354         .f = cmd_set_macsec_offload_off_parsed,
13355         .data = NULL,
13356         .help_str = "set macsec offload <port_id> off",
13357         .tokens = {
13358                 (void *)&cmd_macsec_offload_off_set,
13359                 (void *)&cmd_macsec_offload_off_macsec,
13360                 (void *)&cmd_macsec_offload_off_offload,
13361                 (void *)&cmd_macsec_offload_off_port_id,
13362                 (void *)&cmd_macsec_offload_off_off,
13363                 NULL,
13364         },
13365 };
13366
13367 /* Common result structure for MACsec secure connection configure */
13368 struct cmd_macsec_sc_result {
13369         cmdline_fixed_string_t set;
13370         cmdline_fixed_string_t macsec;
13371         cmdline_fixed_string_t sc;
13372         cmdline_fixed_string_t tx_rx;
13373         portid_t port_id;
13374         struct ether_addr mac;
13375         uint16_t pi;
13376 };
13377
13378 /* Common CLI fields for MACsec secure connection configure */
13379 cmdline_parse_token_string_t cmd_macsec_sc_set =
13380         TOKEN_STRING_INITIALIZER
13381                 (struct cmd_macsec_sc_result,
13382                  set, "set");
13383 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13384         TOKEN_STRING_INITIALIZER
13385                 (struct cmd_macsec_sc_result,
13386                  macsec, "macsec");
13387 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13388         TOKEN_STRING_INITIALIZER
13389                 (struct cmd_macsec_sc_result,
13390                  sc, "sc");
13391 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13392         TOKEN_STRING_INITIALIZER
13393                 (struct cmd_macsec_sc_result,
13394                  tx_rx, "tx#rx");
13395 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13396         TOKEN_NUM_INITIALIZER
13397                 (struct cmd_macsec_sc_result,
13398                  port_id, UINT16);
13399 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13400         TOKEN_ETHERADDR_INITIALIZER
13401                 (struct cmd_macsec_sc_result,
13402                  mac);
13403 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13404         TOKEN_NUM_INITIALIZER
13405                 (struct cmd_macsec_sc_result,
13406                  pi, UINT16);
13407
13408 static void
13409 cmd_set_macsec_sc_parsed(
13410         void *parsed_result,
13411         __attribute__((unused)) struct cmdline *cl,
13412         __attribute__((unused)) void *data)
13413 {
13414         struct cmd_macsec_sc_result *res = parsed_result;
13415         int ret = -ENOTSUP;
13416         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13417
13418 #ifdef RTE_LIBRTE_IXGBE_PMD
13419         ret = is_tx ?
13420                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13421                                 res->mac.addr_bytes) :
13422                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13423                                 res->mac.addr_bytes, res->pi);
13424 #endif
13425         RTE_SET_USED(is_tx);
13426
13427         switch (ret) {
13428         case 0:
13429                 break;
13430         case -ENODEV:
13431                 printf("invalid port_id %d\n", res->port_id);
13432                 break;
13433         case -ENOTSUP:
13434                 printf("not supported on port %d\n", res->port_id);
13435                 break;
13436         default:
13437                 printf("programming error: (%s)\n", strerror(-ret));
13438         }
13439 }
13440
13441 cmdline_parse_inst_t cmd_set_macsec_sc = {
13442         .f = cmd_set_macsec_sc_parsed,
13443         .data = NULL,
13444         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13445         .tokens = {
13446                 (void *)&cmd_macsec_sc_set,
13447                 (void *)&cmd_macsec_sc_macsec,
13448                 (void *)&cmd_macsec_sc_sc,
13449                 (void *)&cmd_macsec_sc_tx_rx,
13450                 (void *)&cmd_macsec_sc_port_id,
13451                 (void *)&cmd_macsec_sc_mac,
13452                 (void *)&cmd_macsec_sc_pi,
13453                 NULL,
13454         },
13455 };
13456
13457 /* Common result structure for MACsec secure connection configure */
13458 struct cmd_macsec_sa_result {
13459         cmdline_fixed_string_t set;
13460         cmdline_fixed_string_t macsec;
13461         cmdline_fixed_string_t sa;
13462         cmdline_fixed_string_t tx_rx;
13463         portid_t port_id;
13464         uint8_t idx;
13465         uint8_t an;
13466         uint32_t pn;
13467         cmdline_fixed_string_t key;
13468 };
13469
13470 /* Common CLI fields for MACsec secure connection configure */
13471 cmdline_parse_token_string_t cmd_macsec_sa_set =
13472         TOKEN_STRING_INITIALIZER
13473                 (struct cmd_macsec_sa_result,
13474                  set, "set");
13475 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13476         TOKEN_STRING_INITIALIZER
13477                 (struct cmd_macsec_sa_result,
13478                  macsec, "macsec");
13479 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13480         TOKEN_STRING_INITIALIZER
13481                 (struct cmd_macsec_sa_result,
13482                  sa, "sa");
13483 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13484         TOKEN_STRING_INITIALIZER
13485                 (struct cmd_macsec_sa_result,
13486                  tx_rx, "tx#rx");
13487 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13488         TOKEN_NUM_INITIALIZER
13489                 (struct cmd_macsec_sa_result,
13490                  port_id, UINT16);
13491 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13492         TOKEN_NUM_INITIALIZER
13493                 (struct cmd_macsec_sa_result,
13494                  idx, UINT8);
13495 cmdline_parse_token_num_t cmd_macsec_sa_an =
13496         TOKEN_NUM_INITIALIZER
13497                 (struct cmd_macsec_sa_result,
13498                  an, UINT8);
13499 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13500         TOKEN_NUM_INITIALIZER
13501                 (struct cmd_macsec_sa_result,
13502                  pn, UINT32);
13503 cmdline_parse_token_string_t cmd_macsec_sa_key =
13504         TOKEN_STRING_INITIALIZER
13505                 (struct cmd_macsec_sa_result,
13506                  key, NULL);
13507
13508 static void
13509 cmd_set_macsec_sa_parsed(
13510         void *parsed_result,
13511         __attribute__((unused)) struct cmdline *cl,
13512         __attribute__((unused)) void *data)
13513 {
13514         struct cmd_macsec_sa_result *res = parsed_result;
13515         int ret = -ENOTSUP;
13516         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13517         uint8_t key[16] = { 0 };
13518         uint8_t xdgt0;
13519         uint8_t xdgt1;
13520         int key_len;
13521         int i;
13522
13523         key_len = strlen(res->key) / 2;
13524         if (key_len > 16)
13525                 key_len = 16;
13526
13527         for (i = 0; i < key_len; i++) {
13528                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13529                 if (xdgt0 == 0xFF)
13530                         return;
13531                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13532                 if (xdgt1 == 0xFF)
13533                         return;
13534                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13535         }
13536
13537 #ifdef RTE_LIBRTE_IXGBE_PMD
13538         ret = is_tx ?
13539                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13540                         res->idx, res->an, res->pn, key) :
13541                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13542                         res->idx, res->an, res->pn, key);
13543 #endif
13544         RTE_SET_USED(is_tx);
13545         RTE_SET_USED(key);
13546
13547         switch (ret) {
13548         case 0:
13549                 break;
13550         case -EINVAL:
13551                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13552                 break;
13553         case -ENODEV:
13554                 printf("invalid port_id %d\n", res->port_id);
13555                 break;
13556         case -ENOTSUP:
13557                 printf("not supported on port %d\n", res->port_id);
13558                 break;
13559         default:
13560                 printf("programming error: (%s)\n", strerror(-ret));
13561         }
13562 }
13563
13564 cmdline_parse_inst_t cmd_set_macsec_sa = {
13565         .f = cmd_set_macsec_sa_parsed,
13566         .data = NULL,
13567         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13568         .tokens = {
13569                 (void *)&cmd_macsec_sa_set,
13570                 (void *)&cmd_macsec_sa_macsec,
13571                 (void *)&cmd_macsec_sa_sa,
13572                 (void *)&cmd_macsec_sa_tx_rx,
13573                 (void *)&cmd_macsec_sa_port_id,
13574                 (void *)&cmd_macsec_sa_idx,
13575                 (void *)&cmd_macsec_sa_an,
13576                 (void *)&cmd_macsec_sa_pn,
13577                 (void *)&cmd_macsec_sa_key,
13578                 NULL,
13579         },
13580 };
13581
13582 /* VF unicast promiscuous mode configuration */
13583
13584 /* Common result structure for VF unicast promiscuous mode */
13585 struct cmd_vf_promisc_result {
13586         cmdline_fixed_string_t set;
13587         cmdline_fixed_string_t vf;
13588         cmdline_fixed_string_t promisc;
13589         portid_t port_id;
13590         uint32_t vf_id;
13591         cmdline_fixed_string_t on_off;
13592 };
13593
13594 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13595 cmdline_parse_token_string_t cmd_vf_promisc_set =
13596         TOKEN_STRING_INITIALIZER
13597                 (struct cmd_vf_promisc_result,
13598                  set, "set");
13599 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13600         TOKEN_STRING_INITIALIZER
13601                 (struct cmd_vf_promisc_result,
13602                  vf, "vf");
13603 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13604         TOKEN_STRING_INITIALIZER
13605                 (struct cmd_vf_promisc_result,
13606                  promisc, "promisc");
13607 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13608         TOKEN_NUM_INITIALIZER
13609                 (struct cmd_vf_promisc_result,
13610                  port_id, UINT16);
13611 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13612         TOKEN_NUM_INITIALIZER
13613                 (struct cmd_vf_promisc_result,
13614                  vf_id, UINT32);
13615 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13616         TOKEN_STRING_INITIALIZER
13617                 (struct cmd_vf_promisc_result,
13618                  on_off, "on#off");
13619
13620 static void
13621 cmd_set_vf_promisc_parsed(
13622         void *parsed_result,
13623         __attribute__((unused)) struct cmdline *cl,
13624         __attribute__((unused)) void *data)
13625 {
13626         struct cmd_vf_promisc_result *res = parsed_result;
13627         int ret = -ENOTSUP;
13628
13629         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13630
13631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13632                 return;
13633
13634 #ifdef RTE_LIBRTE_I40E_PMD
13635         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13636                                                   res->vf_id, is_on);
13637 #endif
13638
13639         switch (ret) {
13640         case 0:
13641                 break;
13642         case -EINVAL:
13643                 printf("invalid vf_id %d\n", res->vf_id);
13644                 break;
13645         case -ENODEV:
13646                 printf("invalid port_id %d\n", res->port_id);
13647                 break;
13648         case -ENOTSUP:
13649                 printf("function not implemented\n");
13650                 break;
13651         default:
13652                 printf("programming error: (%s)\n", strerror(-ret));
13653         }
13654 }
13655
13656 cmdline_parse_inst_t cmd_set_vf_promisc = {
13657         .f = cmd_set_vf_promisc_parsed,
13658         .data = NULL,
13659         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13660                 "Set unicast promiscuous mode for a VF from the PF",
13661         .tokens = {
13662                 (void *)&cmd_vf_promisc_set,
13663                 (void *)&cmd_vf_promisc_vf,
13664                 (void *)&cmd_vf_promisc_promisc,
13665                 (void *)&cmd_vf_promisc_port_id,
13666                 (void *)&cmd_vf_promisc_vf_id,
13667                 (void *)&cmd_vf_promisc_on_off,
13668                 NULL,
13669         },
13670 };
13671
13672 /* VF multicast promiscuous mode configuration */
13673
13674 /* Common result structure for VF multicast promiscuous mode */
13675 struct cmd_vf_allmulti_result {
13676         cmdline_fixed_string_t set;
13677         cmdline_fixed_string_t vf;
13678         cmdline_fixed_string_t allmulti;
13679         portid_t port_id;
13680         uint32_t vf_id;
13681         cmdline_fixed_string_t on_off;
13682 };
13683
13684 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13685 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13686         TOKEN_STRING_INITIALIZER
13687                 (struct cmd_vf_allmulti_result,
13688                  set, "set");
13689 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_vf_allmulti_result,
13692                  vf, "vf");
13693 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13694         TOKEN_STRING_INITIALIZER
13695                 (struct cmd_vf_allmulti_result,
13696                  allmulti, "allmulti");
13697 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13698         TOKEN_NUM_INITIALIZER
13699                 (struct cmd_vf_allmulti_result,
13700                  port_id, UINT16);
13701 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13702         TOKEN_NUM_INITIALIZER
13703                 (struct cmd_vf_allmulti_result,
13704                  vf_id, UINT32);
13705 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13706         TOKEN_STRING_INITIALIZER
13707                 (struct cmd_vf_allmulti_result,
13708                  on_off, "on#off");
13709
13710 static void
13711 cmd_set_vf_allmulti_parsed(
13712         void *parsed_result,
13713         __attribute__((unused)) struct cmdline *cl,
13714         __attribute__((unused)) void *data)
13715 {
13716         struct cmd_vf_allmulti_result *res = parsed_result;
13717         int ret = -ENOTSUP;
13718
13719         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13720
13721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13722                 return;
13723
13724 #ifdef RTE_LIBRTE_I40E_PMD
13725         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13726                                                     res->vf_id, is_on);
13727 #endif
13728
13729         switch (ret) {
13730         case 0:
13731                 break;
13732         case -EINVAL:
13733                 printf("invalid vf_id %d\n", res->vf_id);
13734                 break;
13735         case -ENODEV:
13736                 printf("invalid port_id %d\n", res->port_id);
13737                 break;
13738         case -ENOTSUP:
13739                 printf("function not implemented\n");
13740                 break;
13741         default:
13742                 printf("programming error: (%s)\n", strerror(-ret));
13743         }
13744 }
13745
13746 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13747         .f = cmd_set_vf_allmulti_parsed,
13748         .data = NULL,
13749         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13750                 "Set multicast promiscuous mode for a VF from the PF",
13751         .tokens = {
13752                 (void *)&cmd_vf_allmulti_set,
13753                 (void *)&cmd_vf_allmulti_vf,
13754                 (void *)&cmd_vf_allmulti_allmulti,
13755                 (void *)&cmd_vf_allmulti_port_id,
13756                 (void *)&cmd_vf_allmulti_vf_id,
13757                 (void *)&cmd_vf_allmulti_on_off,
13758                 NULL,
13759         },
13760 };
13761
13762 /* vf broadcast mode configuration */
13763
13764 /* Common result structure for vf broadcast */
13765 struct cmd_set_vf_broadcast_result {
13766         cmdline_fixed_string_t set;
13767         cmdline_fixed_string_t vf;
13768         cmdline_fixed_string_t broadcast;
13769         portid_t port_id;
13770         uint16_t vf_id;
13771         cmdline_fixed_string_t on_off;
13772 };
13773
13774 /* Common CLI fields for vf broadcast enable disable */
13775 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13776         TOKEN_STRING_INITIALIZER
13777                 (struct cmd_set_vf_broadcast_result,
13778                  set, "set");
13779 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13780         TOKEN_STRING_INITIALIZER
13781                 (struct cmd_set_vf_broadcast_result,
13782                  vf, "vf");
13783 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13784         TOKEN_STRING_INITIALIZER
13785                 (struct cmd_set_vf_broadcast_result,
13786                  broadcast, "broadcast");
13787 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13788         TOKEN_NUM_INITIALIZER
13789                 (struct cmd_set_vf_broadcast_result,
13790                  port_id, UINT16);
13791 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13792         TOKEN_NUM_INITIALIZER
13793                 (struct cmd_set_vf_broadcast_result,
13794                  vf_id, UINT16);
13795 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_set_vf_broadcast_result,
13798                  on_off, "on#off");
13799
13800 static void
13801 cmd_set_vf_broadcast_parsed(
13802         void *parsed_result,
13803         __attribute__((unused)) struct cmdline *cl,
13804         __attribute__((unused)) void *data)
13805 {
13806         struct cmd_set_vf_broadcast_result *res = parsed_result;
13807         int ret = -ENOTSUP;
13808
13809         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13810
13811         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13812                 return;
13813
13814 #ifdef RTE_LIBRTE_I40E_PMD
13815         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13816                                             res->vf_id, is_on);
13817 #endif
13818
13819         switch (ret) {
13820         case 0:
13821                 break;
13822         case -EINVAL:
13823                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13824                 break;
13825         case -ENODEV:
13826                 printf("invalid port_id %d\n", res->port_id);
13827                 break;
13828         case -ENOTSUP:
13829                 printf("function not implemented\n");
13830                 break;
13831         default:
13832                 printf("programming error: (%s)\n", strerror(-ret));
13833         }
13834 }
13835
13836 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13837         .f = cmd_set_vf_broadcast_parsed,
13838         .data = NULL,
13839         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13840         .tokens = {
13841                 (void *)&cmd_set_vf_broadcast_set,
13842                 (void *)&cmd_set_vf_broadcast_vf,
13843                 (void *)&cmd_set_vf_broadcast_broadcast,
13844                 (void *)&cmd_set_vf_broadcast_port_id,
13845                 (void *)&cmd_set_vf_broadcast_vf_id,
13846                 (void *)&cmd_set_vf_broadcast_on_off,
13847                 NULL,
13848         },
13849 };
13850
13851 /* vf vlan tag configuration */
13852
13853 /* Common result structure for vf vlan tag */
13854 struct cmd_set_vf_vlan_tag_result {
13855         cmdline_fixed_string_t set;
13856         cmdline_fixed_string_t vf;
13857         cmdline_fixed_string_t vlan;
13858         cmdline_fixed_string_t tag;
13859         portid_t port_id;
13860         uint16_t vf_id;
13861         cmdline_fixed_string_t on_off;
13862 };
13863
13864 /* Common CLI fields for vf vlan tag enable disable */
13865 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13866         TOKEN_STRING_INITIALIZER
13867                 (struct cmd_set_vf_vlan_tag_result,
13868                  set, "set");
13869 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13870         TOKEN_STRING_INITIALIZER
13871                 (struct cmd_set_vf_vlan_tag_result,
13872                  vf, "vf");
13873 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13874         TOKEN_STRING_INITIALIZER
13875                 (struct cmd_set_vf_vlan_tag_result,
13876                  vlan, "vlan");
13877 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13878         TOKEN_STRING_INITIALIZER
13879                 (struct cmd_set_vf_vlan_tag_result,
13880                  tag, "tag");
13881 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13882         TOKEN_NUM_INITIALIZER
13883                 (struct cmd_set_vf_vlan_tag_result,
13884                  port_id, UINT16);
13885 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13886         TOKEN_NUM_INITIALIZER
13887                 (struct cmd_set_vf_vlan_tag_result,
13888                  vf_id, UINT16);
13889 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13890         TOKEN_STRING_INITIALIZER
13891                 (struct cmd_set_vf_vlan_tag_result,
13892                  on_off, "on#off");
13893
13894 static void
13895 cmd_set_vf_vlan_tag_parsed(
13896         void *parsed_result,
13897         __attribute__((unused)) struct cmdline *cl,
13898         __attribute__((unused)) void *data)
13899 {
13900         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13901         int ret = -ENOTSUP;
13902
13903         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13904
13905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13906                 return;
13907
13908 #ifdef RTE_LIBRTE_I40E_PMD
13909         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13910                                            res->vf_id, is_on);
13911 #endif
13912
13913         switch (ret) {
13914         case 0:
13915                 break;
13916         case -EINVAL:
13917                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13918                 break;
13919         case -ENODEV:
13920                 printf("invalid port_id %d\n", res->port_id);
13921                 break;
13922         case -ENOTSUP:
13923                 printf("function not implemented\n");
13924                 break;
13925         default:
13926                 printf("programming error: (%s)\n", strerror(-ret));
13927         }
13928 }
13929
13930 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13931         .f = cmd_set_vf_vlan_tag_parsed,
13932         .data = NULL,
13933         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13934         .tokens = {
13935                 (void *)&cmd_set_vf_vlan_tag_set,
13936                 (void *)&cmd_set_vf_vlan_tag_vf,
13937                 (void *)&cmd_set_vf_vlan_tag_vlan,
13938                 (void *)&cmd_set_vf_vlan_tag_tag,
13939                 (void *)&cmd_set_vf_vlan_tag_port_id,
13940                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13941                 (void *)&cmd_set_vf_vlan_tag_on_off,
13942                 NULL,
13943         },
13944 };
13945
13946 /* Common definition of VF and TC TX bandwidth configuration */
13947 struct cmd_vf_tc_bw_result {
13948         cmdline_fixed_string_t set;
13949         cmdline_fixed_string_t vf;
13950         cmdline_fixed_string_t tc;
13951         cmdline_fixed_string_t tx;
13952         cmdline_fixed_string_t min_bw;
13953         cmdline_fixed_string_t max_bw;
13954         cmdline_fixed_string_t strict_link_prio;
13955         portid_t port_id;
13956         uint16_t vf_id;
13957         uint8_t tc_no;
13958         uint32_t bw;
13959         cmdline_fixed_string_t bw_list;
13960         uint8_t tc_map;
13961 };
13962
13963 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13964         TOKEN_STRING_INITIALIZER
13965                 (struct cmd_vf_tc_bw_result,
13966                  set, "set");
13967 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13968         TOKEN_STRING_INITIALIZER
13969                 (struct cmd_vf_tc_bw_result,
13970                  vf, "vf");
13971 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13972         TOKEN_STRING_INITIALIZER
13973                 (struct cmd_vf_tc_bw_result,
13974                  tc, "tc");
13975 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13976         TOKEN_STRING_INITIALIZER
13977                 (struct cmd_vf_tc_bw_result,
13978                  tx, "tx");
13979 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13980         TOKEN_STRING_INITIALIZER
13981                 (struct cmd_vf_tc_bw_result,
13982                  strict_link_prio, "strict-link-priority");
13983 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13984         TOKEN_STRING_INITIALIZER
13985                 (struct cmd_vf_tc_bw_result,
13986                  min_bw, "min-bandwidth");
13987 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13988         TOKEN_STRING_INITIALIZER
13989                 (struct cmd_vf_tc_bw_result,
13990                  max_bw, "max-bandwidth");
13991 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13992         TOKEN_NUM_INITIALIZER
13993                 (struct cmd_vf_tc_bw_result,
13994                  port_id, UINT16);
13995 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13996         TOKEN_NUM_INITIALIZER
13997                 (struct cmd_vf_tc_bw_result,
13998                  vf_id, UINT16);
13999 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14000         TOKEN_NUM_INITIALIZER
14001                 (struct cmd_vf_tc_bw_result,
14002                  tc_no, UINT8);
14003 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14004         TOKEN_NUM_INITIALIZER
14005                 (struct cmd_vf_tc_bw_result,
14006                  bw, UINT32);
14007 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14008         TOKEN_STRING_INITIALIZER
14009                 (struct cmd_vf_tc_bw_result,
14010                  bw_list, NULL);
14011 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14012         TOKEN_NUM_INITIALIZER
14013                 (struct cmd_vf_tc_bw_result,
14014                  tc_map, UINT8);
14015
14016 /* VF max bandwidth setting */
14017 static void
14018 cmd_vf_max_bw_parsed(
14019         void *parsed_result,
14020         __attribute__((unused)) struct cmdline *cl,
14021         __attribute__((unused)) void *data)
14022 {
14023         struct cmd_vf_tc_bw_result *res = parsed_result;
14024         int ret = -ENOTSUP;
14025
14026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14027                 return;
14028
14029 #ifdef RTE_LIBRTE_I40E_PMD
14030         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14031                                          res->vf_id, res->bw);
14032 #endif
14033
14034         switch (ret) {
14035         case 0:
14036                 break;
14037         case -EINVAL:
14038                 printf("invalid vf_id %d or bandwidth %d\n",
14039                        res->vf_id, res->bw);
14040                 break;
14041         case -ENODEV:
14042                 printf("invalid port_id %d\n", res->port_id);
14043                 break;
14044         case -ENOTSUP:
14045                 printf("function not implemented\n");
14046                 break;
14047         default:
14048                 printf("programming error: (%s)\n", strerror(-ret));
14049         }
14050 }
14051
14052 cmdline_parse_inst_t cmd_vf_max_bw = {
14053         .f = cmd_vf_max_bw_parsed,
14054         .data = NULL,
14055         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14056         .tokens = {
14057                 (void *)&cmd_vf_tc_bw_set,
14058                 (void *)&cmd_vf_tc_bw_vf,
14059                 (void *)&cmd_vf_tc_bw_tx,
14060                 (void *)&cmd_vf_tc_bw_max_bw,
14061                 (void *)&cmd_vf_tc_bw_port_id,
14062                 (void *)&cmd_vf_tc_bw_vf_id,
14063                 (void *)&cmd_vf_tc_bw_bw,
14064                 NULL,
14065         },
14066 };
14067
14068 static int
14069 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14070                            uint8_t *tc_num,
14071                            char *str)
14072 {
14073         uint32_t size;
14074         const char *p, *p0 = str;
14075         char s[256];
14076         char *end;
14077         char *str_fld[16];
14078         uint16_t i;
14079         int ret;
14080
14081         p = strchr(p0, '(');
14082         if (p == NULL) {
14083                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14084                 return -1;
14085         }
14086         p++;
14087         p0 = strchr(p, ')');
14088         if (p0 == NULL) {
14089                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14090                 return -1;
14091         }
14092         size = p0 - p;
14093         if (size >= sizeof(s)) {
14094                 printf("The string size exceeds the internal buffer size\n");
14095                 return -1;
14096         }
14097         snprintf(s, sizeof(s), "%.*s", size, p);
14098         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14099         if (ret <= 0) {
14100                 printf("Failed to get the bandwidth list. ");
14101                 return -1;
14102         }
14103         *tc_num = ret;
14104         for (i = 0; i < ret; i++)
14105                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14106
14107         return 0;
14108 }
14109
14110 /* TC min bandwidth setting */
14111 static void
14112 cmd_vf_tc_min_bw_parsed(
14113         void *parsed_result,
14114         __attribute__((unused)) struct cmdline *cl,
14115         __attribute__((unused)) void *data)
14116 {
14117         struct cmd_vf_tc_bw_result *res = parsed_result;
14118         uint8_t tc_num;
14119         uint8_t bw[16];
14120         int ret = -ENOTSUP;
14121
14122         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14123                 return;
14124
14125         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14126         if (ret)
14127                 return;
14128
14129 #ifdef RTE_LIBRTE_I40E_PMD
14130         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14131                                               tc_num, bw);
14132 #endif
14133
14134         switch (ret) {
14135         case 0:
14136                 break;
14137         case -EINVAL:
14138                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14139                 break;
14140         case -ENODEV:
14141                 printf("invalid port_id %d\n", res->port_id);
14142                 break;
14143         case -ENOTSUP:
14144                 printf("function not implemented\n");
14145                 break;
14146         default:
14147                 printf("programming error: (%s)\n", strerror(-ret));
14148         }
14149 }
14150
14151 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14152         .f = cmd_vf_tc_min_bw_parsed,
14153         .data = NULL,
14154         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14155                     " <bw1, bw2, ...>",
14156         .tokens = {
14157                 (void *)&cmd_vf_tc_bw_set,
14158                 (void *)&cmd_vf_tc_bw_vf,
14159                 (void *)&cmd_vf_tc_bw_tc,
14160                 (void *)&cmd_vf_tc_bw_tx,
14161                 (void *)&cmd_vf_tc_bw_min_bw,
14162                 (void *)&cmd_vf_tc_bw_port_id,
14163                 (void *)&cmd_vf_tc_bw_vf_id,
14164                 (void *)&cmd_vf_tc_bw_bw_list,
14165                 NULL,
14166         },
14167 };
14168
14169 static void
14170 cmd_tc_min_bw_parsed(
14171         void *parsed_result,
14172         __attribute__((unused)) struct cmdline *cl,
14173         __attribute__((unused)) void *data)
14174 {
14175         struct cmd_vf_tc_bw_result *res = parsed_result;
14176         struct rte_port *port;
14177         uint8_t tc_num;
14178         uint8_t bw[16];
14179         int ret = -ENOTSUP;
14180
14181         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14182                 return;
14183
14184         port = &ports[res->port_id];
14185         /** Check if the port is not started **/
14186         if (port->port_status != RTE_PORT_STOPPED) {
14187                 printf("Please stop port %d first\n", res->port_id);
14188                 return;
14189         }
14190
14191         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14192         if (ret)
14193                 return;
14194
14195 #ifdef RTE_LIBRTE_IXGBE_PMD
14196         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14197 #endif
14198
14199         switch (ret) {
14200         case 0:
14201                 break;
14202         case -EINVAL:
14203                 printf("invalid bandwidth\n");
14204                 break;
14205         case -ENODEV:
14206                 printf("invalid port_id %d\n", res->port_id);
14207                 break;
14208         case -ENOTSUP:
14209                 printf("function not implemented\n");
14210                 break;
14211         default:
14212                 printf("programming error: (%s)\n", strerror(-ret));
14213         }
14214 }
14215
14216 cmdline_parse_inst_t cmd_tc_min_bw = {
14217         .f = cmd_tc_min_bw_parsed,
14218         .data = NULL,
14219         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14220         .tokens = {
14221                 (void *)&cmd_vf_tc_bw_set,
14222                 (void *)&cmd_vf_tc_bw_tc,
14223                 (void *)&cmd_vf_tc_bw_tx,
14224                 (void *)&cmd_vf_tc_bw_min_bw,
14225                 (void *)&cmd_vf_tc_bw_port_id,
14226                 (void *)&cmd_vf_tc_bw_bw_list,
14227                 NULL,
14228         },
14229 };
14230
14231 /* TC max bandwidth setting */
14232 static void
14233 cmd_vf_tc_max_bw_parsed(
14234         void *parsed_result,
14235         __attribute__((unused)) struct cmdline *cl,
14236         __attribute__((unused)) void *data)
14237 {
14238         struct cmd_vf_tc_bw_result *res = parsed_result;
14239         int ret = -ENOTSUP;
14240
14241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14242                 return;
14243
14244 #ifdef RTE_LIBRTE_I40E_PMD
14245         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14246                                             res->tc_no, res->bw);
14247 #endif
14248
14249         switch (ret) {
14250         case 0:
14251                 break;
14252         case -EINVAL:
14253                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14254                        res->vf_id, res->tc_no, res->bw);
14255                 break;
14256         case -ENODEV:
14257                 printf("invalid port_id %d\n", res->port_id);
14258                 break;
14259         case -ENOTSUP:
14260                 printf("function not implemented\n");
14261                 break;
14262         default:
14263                 printf("programming error: (%s)\n", strerror(-ret));
14264         }
14265 }
14266
14267 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14268         .f = cmd_vf_tc_max_bw_parsed,
14269         .data = NULL,
14270         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14271                     " <bandwidth>",
14272         .tokens = {
14273                 (void *)&cmd_vf_tc_bw_set,
14274                 (void *)&cmd_vf_tc_bw_vf,
14275                 (void *)&cmd_vf_tc_bw_tc,
14276                 (void *)&cmd_vf_tc_bw_tx,
14277                 (void *)&cmd_vf_tc_bw_max_bw,
14278                 (void *)&cmd_vf_tc_bw_port_id,
14279                 (void *)&cmd_vf_tc_bw_vf_id,
14280                 (void *)&cmd_vf_tc_bw_tc_no,
14281                 (void *)&cmd_vf_tc_bw_bw,
14282                 NULL,
14283         },
14284 };
14285
14286
14287 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14288
14289 /* *** Set Port default Traffic Management Hierarchy *** */
14290 struct cmd_set_port_tm_hierarchy_default_result {
14291         cmdline_fixed_string_t set;
14292         cmdline_fixed_string_t port;
14293         cmdline_fixed_string_t tm;
14294         cmdline_fixed_string_t hierarchy;
14295         cmdline_fixed_string_t def;
14296         portid_t port_id;
14297 };
14298
14299 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14300         TOKEN_STRING_INITIALIZER(
14301                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14302 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14303         TOKEN_STRING_INITIALIZER(
14304                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14305 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14306         TOKEN_STRING_INITIALIZER(
14307                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14308 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14309         TOKEN_STRING_INITIALIZER(
14310                 struct cmd_set_port_tm_hierarchy_default_result,
14311                         hierarchy, "hierarchy");
14312 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14313         TOKEN_STRING_INITIALIZER(
14314                 struct cmd_set_port_tm_hierarchy_default_result,
14315                         def, "default");
14316 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14317         TOKEN_NUM_INITIALIZER(
14318                 struct cmd_set_port_tm_hierarchy_default_result,
14319                         port_id, UINT16);
14320
14321 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14322         __attribute__((unused)) struct cmdline *cl,
14323         __attribute__((unused)) void *data)
14324 {
14325         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14326         struct rte_port *p;
14327         portid_t port_id = res->port_id;
14328
14329         if (port_id_is_invalid(port_id, ENABLED_WARN))
14330                 return;
14331
14332         p = &ports[port_id];
14333
14334         /* Port tm flag */
14335         if (p->softport.tm_flag == 0) {
14336                 printf("  tm not enabled on port %u (error)\n", port_id);
14337                 return;
14338         }
14339
14340         /* Forward mode: tm */
14341         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14342                 printf("  tm mode not enabled(error)\n");
14343                 return;
14344         }
14345
14346         /* Set the default tm hierarchy */
14347         p->softport.tm.default_hierarchy_enable = 1;
14348 }
14349
14350 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14351         .f = cmd_set_port_tm_hierarchy_default_parsed,
14352         .data = NULL,
14353         .help_str = "set port tm hierarchy default <port_id>",
14354         .tokens = {
14355                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14356                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14357                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14358                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14359                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14360                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14361                 NULL,
14362         },
14363 };
14364 #endif
14365
14366 /* Strict link priority scheduling mode setting */
14367 static void
14368 cmd_strict_link_prio_parsed(
14369         void *parsed_result,
14370         __attribute__((unused)) struct cmdline *cl,
14371         __attribute__((unused)) void *data)
14372 {
14373         struct cmd_vf_tc_bw_result *res = parsed_result;
14374         int ret = -ENOTSUP;
14375
14376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14377                 return;
14378
14379 #ifdef RTE_LIBRTE_I40E_PMD
14380         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14381 #endif
14382
14383         switch (ret) {
14384         case 0:
14385                 break;
14386         case -EINVAL:
14387                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14388                 break;
14389         case -ENODEV:
14390                 printf("invalid port_id %d\n", res->port_id);
14391                 break;
14392         case -ENOTSUP:
14393                 printf("function not implemented\n");
14394                 break;
14395         default:
14396                 printf("programming error: (%s)\n", strerror(-ret));
14397         }
14398 }
14399
14400 cmdline_parse_inst_t cmd_strict_link_prio = {
14401         .f = cmd_strict_link_prio_parsed,
14402         .data = NULL,
14403         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14404         .tokens = {
14405                 (void *)&cmd_vf_tc_bw_set,
14406                 (void *)&cmd_vf_tc_bw_tx,
14407                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14408                 (void *)&cmd_vf_tc_bw_port_id,
14409                 (void *)&cmd_vf_tc_bw_tc_map,
14410                 NULL,
14411         },
14412 };
14413
14414 /* Load dynamic device personalization*/
14415 struct cmd_ddp_add_result {
14416         cmdline_fixed_string_t ddp;
14417         cmdline_fixed_string_t add;
14418         portid_t port_id;
14419         char filepath[];
14420 };
14421
14422 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14423         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14424 cmdline_parse_token_string_t cmd_ddp_add_add =
14425         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14426 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14427         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14428 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14429         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14430
14431 static void
14432 cmd_ddp_add_parsed(
14433         void *parsed_result,
14434         __attribute__((unused)) struct cmdline *cl,
14435         __attribute__((unused)) void *data)
14436 {
14437         struct cmd_ddp_add_result *res = parsed_result;
14438         uint8_t *buff;
14439         uint32_t size;
14440         char *filepath;
14441         char *file_fld[2];
14442         int file_num;
14443         int ret = -ENOTSUP;
14444
14445         if (res->port_id > nb_ports) {
14446                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14447                 return;
14448         }
14449
14450         if (!all_ports_stopped()) {
14451                 printf("Please stop all ports first\n");
14452                 return;
14453         }
14454
14455         filepath = strdup(res->filepath);
14456         if (filepath == NULL) {
14457                 printf("Failed to allocate memory\n");
14458                 return;
14459         }
14460         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14461
14462         buff = open_file(file_fld[0], &size);
14463         if (!buff) {
14464                 free((void *)filepath);
14465                 return;
14466         }
14467
14468 #ifdef RTE_LIBRTE_I40E_PMD
14469         if (ret == -ENOTSUP)
14470                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14471                                                buff, size,
14472                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14473 #endif
14474
14475         if (ret == -EEXIST)
14476                 printf("Profile has already existed.\n");
14477         else if (ret < 0)
14478                 printf("Failed to load profile.\n");
14479         else if (file_num == 2)
14480                 save_file(file_fld[1], buff, size);
14481
14482         close_file(buff);
14483         free((void *)filepath);
14484 }
14485
14486 cmdline_parse_inst_t cmd_ddp_add = {
14487         .f = cmd_ddp_add_parsed,
14488         .data = NULL,
14489         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14490         .tokens = {
14491                 (void *)&cmd_ddp_add_ddp,
14492                 (void *)&cmd_ddp_add_add,
14493                 (void *)&cmd_ddp_add_port_id,
14494                 (void *)&cmd_ddp_add_filepath,
14495                 NULL,
14496         },
14497 };
14498
14499 /* Delete dynamic device personalization*/
14500 struct cmd_ddp_del_result {
14501         cmdline_fixed_string_t ddp;
14502         cmdline_fixed_string_t del;
14503         portid_t port_id;
14504         char filepath[];
14505 };
14506
14507 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14509 cmdline_parse_token_string_t cmd_ddp_del_del =
14510         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14511 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14512         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14513 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14514         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14515
14516 static void
14517 cmd_ddp_del_parsed(
14518         void *parsed_result,
14519         __attribute__((unused)) struct cmdline *cl,
14520         __attribute__((unused)) void *data)
14521 {
14522         struct cmd_ddp_del_result *res = parsed_result;
14523         uint8_t *buff;
14524         uint32_t size;
14525         int ret = -ENOTSUP;
14526
14527         if (res->port_id > nb_ports) {
14528                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14529                 return;
14530         }
14531
14532         if (!all_ports_stopped()) {
14533                 printf("Please stop all ports first\n");
14534                 return;
14535         }
14536
14537         buff = open_file(res->filepath, &size);
14538         if (!buff)
14539                 return;
14540
14541 #ifdef RTE_LIBRTE_I40E_PMD
14542         if (ret == -ENOTSUP)
14543                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14544                                                buff, size,
14545                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14546 #endif
14547
14548         if (ret == -EACCES)
14549                 printf("Profile does not exist.\n");
14550         else if (ret < 0)
14551                 printf("Failed to delete profile.\n");
14552
14553         close_file(buff);
14554 }
14555
14556 cmdline_parse_inst_t cmd_ddp_del = {
14557         .f = cmd_ddp_del_parsed,
14558         .data = NULL,
14559         .help_str = "ddp del <port_id> <profile_path>",
14560         .tokens = {
14561                 (void *)&cmd_ddp_del_ddp,
14562                 (void *)&cmd_ddp_del_del,
14563                 (void *)&cmd_ddp_del_port_id,
14564                 (void *)&cmd_ddp_del_filepath,
14565                 NULL,
14566         },
14567 };
14568
14569 /* Get dynamic device personalization profile info */
14570 struct cmd_ddp_info_result {
14571         cmdline_fixed_string_t ddp;
14572         cmdline_fixed_string_t get;
14573         cmdline_fixed_string_t info;
14574         char filepath[];
14575 };
14576
14577 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14578         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14579 cmdline_parse_token_string_t cmd_ddp_info_get =
14580         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14581 cmdline_parse_token_string_t cmd_ddp_info_info =
14582         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14583 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14584         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14585
14586 static void
14587 cmd_ddp_info_parsed(
14588         void *parsed_result,
14589         __attribute__((unused)) struct cmdline *cl,
14590         __attribute__((unused)) void *data)
14591 {
14592         struct cmd_ddp_info_result *res = parsed_result;
14593         uint8_t *pkg;
14594         uint32_t pkg_size;
14595         int ret = -ENOTSUP;
14596 #ifdef RTE_LIBRTE_I40E_PMD
14597         uint32_t i, j, n;
14598         uint8_t *buff;
14599         uint32_t buff_size = 0;
14600         struct rte_pmd_i40e_profile_info info;
14601         uint32_t dev_num = 0;
14602         struct rte_pmd_i40e_ddp_device_id *devs;
14603         uint32_t proto_num = 0;
14604         struct rte_pmd_i40e_proto_info *proto = NULL;
14605         uint32_t pctype_num = 0;
14606         struct rte_pmd_i40e_ptype_info *pctype;
14607         uint32_t ptype_num = 0;
14608         struct rte_pmd_i40e_ptype_info *ptype;
14609         uint8_t proto_id;
14610
14611 #endif
14612
14613         pkg = open_file(res->filepath, &pkg_size);
14614         if (!pkg)
14615                 return;
14616
14617 #ifdef RTE_LIBRTE_I40E_PMD
14618         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14619                                 (uint8_t *)&info, sizeof(info),
14620                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14621         if (!ret) {
14622                 printf("Global Track id:       0x%x\n", info.track_id);
14623                 printf("Global Version:        %d.%d.%d.%d\n",
14624                         info.version.major,
14625                         info.version.minor,
14626                         info.version.update,
14627                         info.version.draft);
14628                 printf("Global Package name:   %s\n\n", info.name);
14629         }
14630
14631         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14632                                 (uint8_t *)&info, sizeof(info),
14633                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14634         if (!ret) {
14635                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14636                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14637                         info.version.major,
14638                         info.version.minor,
14639                         info.version.update,
14640                         info.version.draft);
14641                 printf("i40e Profile name:     %s\n\n", info.name);
14642         }
14643
14644         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14645                                 (uint8_t *)&buff_size, sizeof(buff_size),
14646                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14647         if (!ret && buff_size) {
14648                 buff = (uint8_t *)malloc(buff_size);
14649                 if (buff) {
14650                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14651                                                 buff, buff_size,
14652                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14653                         if (!ret)
14654                                 printf("Package Notes:\n%s\n\n", buff);
14655                         free(buff);
14656                 }
14657         }
14658
14659         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14660                                 (uint8_t *)&dev_num, sizeof(dev_num),
14661                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14662         if (!ret && dev_num) {
14663                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14664                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14665                 if (devs) {
14666                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14667                                                 (uint8_t *)devs, buff_size,
14668                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14669                         if (!ret) {
14670                                 printf("List of supported devices:\n");
14671                                 for (i = 0; i < dev_num; i++) {
14672                                         printf("  %04X:%04X %04X:%04X\n",
14673                                                 devs[i].vendor_dev_id >> 16,
14674                                                 devs[i].vendor_dev_id & 0xFFFF,
14675                                                 devs[i].sub_vendor_dev_id >> 16,
14676                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14677                                 }
14678                                 printf("\n");
14679                         }
14680                         free(devs);
14681                 }
14682         }
14683
14684         /* get information about protocols and packet types */
14685         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14686                 (uint8_t *)&proto_num, sizeof(proto_num),
14687                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14688         if (ret || !proto_num)
14689                 goto no_print_return;
14690
14691         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14692         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14693         if (!proto)
14694                 goto no_print_return;
14695
14696         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14697                                         buff_size,
14698                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14699         if (!ret) {
14700                 printf("List of used protocols:\n");
14701                 for (i = 0; i < proto_num; i++)
14702                         printf("  %2u: %s\n", proto[i].proto_id,
14703                                proto[i].name);
14704                 printf("\n");
14705         }
14706         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14707                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14708                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14709         if (ret || !pctype_num)
14710                 goto no_print_pctypes;
14711
14712         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14713         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14714         if (!pctype)
14715                 goto no_print_pctypes;
14716
14717         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14718                                         buff_size,
14719                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14720         if (ret) {
14721                 free(pctype);
14722                 goto no_print_pctypes;
14723         }
14724
14725         printf("List of defined packet classification types:\n");
14726         for (i = 0; i < pctype_num; i++) {
14727                 printf("  %2u:", pctype[i].ptype_id);
14728                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14729                         proto_id = pctype[i].protocols[j];
14730                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14731                                 for (n = 0; n < proto_num; n++) {
14732                                         if (proto[n].proto_id == proto_id) {
14733                                                 printf(" %s", proto[n].name);
14734                                                 break;
14735                                         }
14736                                 }
14737                         }
14738                 }
14739                 printf("\n");
14740         }
14741         printf("\n");
14742         free(pctype);
14743
14744 no_print_pctypes:
14745
14746         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14747                                         sizeof(ptype_num),
14748                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14749         if (ret || !ptype_num)
14750                 goto no_print_return;
14751
14752         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14753         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14754         if (!ptype)
14755                 goto no_print_return;
14756
14757         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14758                                         buff_size,
14759                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14760         if (ret) {
14761                 free(ptype);
14762                 goto no_print_return;
14763         }
14764         printf("List of defined packet types:\n");
14765         for (i = 0; i < ptype_num; i++) {
14766                 printf("  %2u:", ptype[i].ptype_id);
14767                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14768                         proto_id = ptype[i].protocols[j];
14769                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14770                                 for (n = 0; n < proto_num; n++) {
14771                                         if (proto[n].proto_id == proto_id) {
14772                                                 printf(" %s", proto[n].name);
14773                                                 break;
14774                                         }
14775                                 }
14776                         }
14777                 }
14778                 printf("\n");
14779         }
14780         free(ptype);
14781         printf("\n");
14782
14783         ret = 0;
14784 no_print_return:
14785         if (proto)
14786                 free(proto);
14787 #endif
14788         if (ret == -ENOTSUP)
14789                 printf("Function not supported in PMD driver\n");
14790         close_file(pkg);
14791 }
14792
14793 cmdline_parse_inst_t cmd_ddp_get_info = {
14794         .f = cmd_ddp_info_parsed,
14795         .data = NULL,
14796         .help_str = "ddp get info <profile_path>",
14797         .tokens = {
14798                 (void *)&cmd_ddp_info_ddp,
14799                 (void *)&cmd_ddp_info_get,
14800                 (void *)&cmd_ddp_info_info,
14801                 (void *)&cmd_ddp_info_filepath,
14802                 NULL,
14803         },
14804 };
14805
14806 /* Get dynamic device personalization profile info list*/
14807 #define PROFILE_INFO_SIZE 48
14808 #define MAX_PROFILE_NUM 16
14809
14810 struct cmd_ddp_get_list_result {
14811         cmdline_fixed_string_t ddp;
14812         cmdline_fixed_string_t get;
14813         cmdline_fixed_string_t list;
14814         portid_t port_id;
14815 };
14816
14817 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14818         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14819 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14820         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14821 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14822         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14823 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14824         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14825
14826 static void
14827 cmd_ddp_get_list_parsed(
14828         void *parsed_result,
14829         __attribute__((unused)) struct cmdline *cl,
14830         __attribute__((unused)) void *data)
14831 {
14832         struct cmd_ddp_get_list_result *res = parsed_result;
14833 #ifdef RTE_LIBRTE_I40E_PMD
14834         struct rte_pmd_i40e_profile_list *p_list;
14835         struct rte_pmd_i40e_profile_info *p_info;
14836         uint32_t p_num;
14837         uint32_t size;
14838         uint32_t i;
14839 #endif
14840         int ret = -ENOTSUP;
14841
14842         if (res->port_id > nb_ports) {
14843                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14844                 return;
14845         }
14846
14847 #ifdef RTE_LIBRTE_I40E_PMD
14848         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14849         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14850         if (!p_list)
14851                 printf("%s: Failed to malloc buffer\n", __func__);
14852
14853         if (ret == -ENOTSUP)
14854                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14855                                                 (uint8_t *)p_list, size);
14856
14857         if (!ret) {
14858                 p_num = p_list->p_count;
14859                 printf("Profile number is: %d\n\n", p_num);
14860
14861                 for (i = 0; i < p_num; i++) {
14862                         p_info = &p_list->p_info[i];
14863                         printf("Profile %d:\n", i);
14864                         printf("Track id:     0x%x\n", p_info->track_id);
14865                         printf("Version:      %d.%d.%d.%d\n",
14866                                p_info->version.major,
14867                                p_info->version.minor,
14868                                p_info->version.update,
14869                                p_info->version.draft);
14870                         printf("Profile name: %s\n\n", p_info->name);
14871                 }
14872         }
14873
14874         free(p_list);
14875 #endif
14876
14877         if (ret < 0)
14878                 printf("Failed to get ddp list\n");
14879 }
14880
14881 cmdline_parse_inst_t cmd_ddp_get_list = {
14882         .f = cmd_ddp_get_list_parsed,
14883         .data = NULL,
14884         .help_str = "ddp get list <port_id>",
14885         .tokens = {
14886                 (void *)&cmd_ddp_get_list_ddp,
14887                 (void *)&cmd_ddp_get_list_get,
14888                 (void *)&cmd_ddp_get_list_list,
14889                 (void *)&cmd_ddp_get_list_port_id,
14890                 NULL,
14891         },
14892 };
14893
14894 /* Configure input set */
14895 struct cmd_cfg_input_set_result {
14896         cmdline_fixed_string_t port;
14897         cmdline_fixed_string_t cfg;
14898         portid_t port_id;
14899         cmdline_fixed_string_t pctype;
14900         uint8_t pctype_id;
14901         cmdline_fixed_string_t inset_type;
14902         cmdline_fixed_string_t opt;
14903         cmdline_fixed_string_t field;
14904         uint8_t field_idx;
14905 };
14906
14907 static void
14908 cmd_cfg_input_set_parsed(
14909         void *parsed_result,
14910         __attribute__((unused)) struct cmdline *cl,
14911         __attribute__((unused)) void *data)
14912 {
14913         struct cmd_cfg_input_set_result *res = parsed_result;
14914 #ifdef RTE_LIBRTE_I40E_PMD
14915         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14916         struct rte_pmd_i40e_inset inset;
14917 #endif
14918         int ret = -ENOTSUP;
14919
14920         if (res->port_id > nb_ports) {
14921                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14922                 return;
14923         }
14924
14925         if (!all_ports_stopped()) {
14926                 printf("Please stop all ports first\n");
14927                 return;
14928         }
14929
14930 #ifdef RTE_LIBRTE_I40E_PMD
14931         if (!strcmp(res->inset_type, "hash_inset"))
14932                 inset_type = INSET_HASH;
14933         else if (!strcmp(res->inset_type, "fdir_inset"))
14934                 inset_type = INSET_FDIR;
14935         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14936                 inset_type = INSET_FDIR_FLX;
14937         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14938                                      &inset, inset_type);
14939         if (ret) {
14940                 printf("Failed to get input set.\n");
14941                 return;
14942         }
14943
14944         if (!strcmp(res->opt, "get")) {
14945                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14946                                                    res->field_idx);
14947                 if (ret)
14948                         printf("Field index %d is enabled.\n", res->field_idx);
14949                 else
14950                         printf("Field index %d is disabled.\n", res->field_idx);
14951                 return;
14952         } else if (!strcmp(res->opt, "set"))
14953                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14954                                                    res->field_idx);
14955         else if (!strcmp(res->opt, "clear"))
14956                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14957                                                      res->field_idx);
14958         if (ret) {
14959                 printf("Failed to configure input set field.\n");
14960                 return;
14961         }
14962
14963         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14964                                      &inset, inset_type);
14965         if (ret) {
14966                 printf("Failed to set input set.\n");
14967                 return;
14968         }
14969 #endif
14970
14971         if (ret == -ENOTSUP)
14972                 printf("Function not supported\n");
14973 }
14974
14975 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14976         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14977                                  port, "port");
14978 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14979         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14980                                  cfg, "config");
14981 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14982         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14983                               port_id, UINT16);
14984 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14985         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14986                                  pctype, "pctype");
14987 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14988         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14989                               pctype_id, UINT8);
14990 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14991         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14992                                  inset_type,
14993                                  "hash_inset#fdir_inset#fdir_flx_inset");
14994 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14995         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14996                                  opt, "get#set#clear");
14997 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14998         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14999                                  field, "field");
15000 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15001         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15002                               field_idx, UINT8);
15003
15004 cmdline_parse_inst_t cmd_cfg_input_set = {
15005         .f = cmd_cfg_input_set_parsed,
15006         .data = NULL,
15007         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15008                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15009         .tokens = {
15010                 (void *)&cmd_cfg_input_set_port,
15011                 (void *)&cmd_cfg_input_set_cfg,
15012                 (void *)&cmd_cfg_input_set_port_id,
15013                 (void *)&cmd_cfg_input_set_pctype,
15014                 (void *)&cmd_cfg_input_set_pctype_id,
15015                 (void *)&cmd_cfg_input_set_inset_type,
15016                 (void *)&cmd_cfg_input_set_opt,
15017                 (void *)&cmd_cfg_input_set_field,
15018                 (void *)&cmd_cfg_input_set_field_idx,
15019                 NULL,
15020         },
15021 };
15022
15023 /* Clear input set */
15024 struct cmd_clear_input_set_result {
15025         cmdline_fixed_string_t port;
15026         cmdline_fixed_string_t cfg;
15027         portid_t port_id;
15028         cmdline_fixed_string_t pctype;
15029         uint8_t pctype_id;
15030         cmdline_fixed_string_t inset_type;
15031         cmdline_fixed_string_t clear;
15032         cmdline_fixed_string_t all;
15033 };
15034
15035 static void
15036 cmd_clear_input_set_parsed(
15037         void *parsed_result,
15038         __attribute__((unused)) struct cmdline *cl,
15039         __attribute__((unused)) void *data)
15040 {
15041         struct cmd_clear_input_set_result *res = parsed_result;
15042 #ifdef RTE_LIBRTE_I40E_PMD
15043         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15044         struct rte_pmd_i40e_inset inset;
15045 #endif
15046         int ret = -ENOTSUP;
15047
15048         if (res->port_id > nb_ports) {
15049                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15050                 return;
15051         }
15052
15053         if (!all_ports_stopped()) {
15054                 printf("Please stop all ports first\n");
15055                 return;
15056         }
15057
15058 #ifdef RTE_LIBRTE_I40E_PMD
15059         if (!strcmp(res->inset_type, "hash_inset"))
15060                 inset_type = INSET_HASH;
15061         else if (!strcmp(res->inset_type, "fdir_inset"))
15062                 inset_type = INSET_FDIR;
15063         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15064                 inset_type = INSET_FDIR_FLX;
15065
15066         memset(&inset, 0, sizeof(inset));
15067
15068         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15069                                      &inset, inset_type);
15070         if (ret) {
15071                 printf("Failed to clear input set.\n");
15072                 return;
15073         }
15074
15075 #endif
15076
15077         if (ret == -ENOTSUP)
15078                 printf("Function not supported\n");
15079 }
15080
15081 cmdline_parse_token_string_t cmd_clear_input_set_port =
15082         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15083                                  port, "port");
15084 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15085         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15086                                  cfg, "config");
15087 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15088         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15089                               port_id, UINT16);
15090 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15091         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15092                                  pctype, "pctype");
15093 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15094         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15095                               pctype_id, UINT8);
15096 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15097         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15098                                  inset_type,
15099                                  "hash_inset#fdir_inset#fdir_flx_inset");
15100 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15101         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15102                                  clear, "clear");
15103 cmdline_parse_token_string_t cmd_clear_input_set_all =
15104         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15105                                  all, "all");
15106
15107 cmdline_parse_inst_t cmd_clear_input_set = {
15108         .f = cmd_clear_input_set_parsed,
15109         .data = NULL,
15110         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15111                     "fdir_inset|fdir_flx_inset clear all",
15112         .tokens = {
15113                 (void *)&cmd_clear_input_set_port,
15114                 (void *)&cmd_clear_input_set_cfg,
15115                 (void *)&cmd_clear_input_set_port_id,
15116                 (void *)&cmd_clear_input_set_pctype,
15117                 (void *)&cmd_clear_input_set_pctype_id,
15118                 (void *)&cmd_clear_input_set_inset_type,
15119                 (void *)&cmd_clear_input_set_clear,
15120                 (void *)&cmd_clear_input_set_all,
15121                 NULL,
15122         },
15123 };
15124
15125 /* show vf stats */
15126
15127 /* Common result structure for show vf stats */
15128 struct cmd_show_vf_stats_result {
15129         cmdline_fixed_string_t show;
15130         cmdline_fixed_string_t vf;
15131         cmdline_fixed_string_t stats;
15132         portid_t port_id;
15133         uint16_t vf_id;
15134 };
15135
15136 /* Common CLI fields show vf stats*/
15137 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15138         TOKEN_STRING_INITIALIZER
15139                 (struct cmd_show_vf_stats_result,
15140                  show, "show");
15141 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15142         TOKEN_STRING_INITIALIZER
15143                 (struct cmd_show_vf_stats_result,
15144                  vf, "vf");
15145 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15146         TOKEN_STRING_INITIALIZER
15147                 (struct cmd_show_vf_stats_result,
15148                  stats, "stats");
15149 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15150         TOKEN_NUM_INITIALIZER
15151                 (struct cmd_show_vf_stats_result,
15152                  port_id, UINT16);
15153 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15154         TOKEN_NUM_INITIALIZER
15155                 (struct cmd_show_vf_stats_result,
15156                  vf_id, UINT16);
15157
15158 static void
15159 cmd_show_vf_stats_parsed(
15160         void *parsed_result,
15161         __attribute__((unused)) struct cmdline *cl,
15162         __attribute__((unused)) void *data)
15163 {
15164         struct cmd_show_vf_stats_result *res = parsed_result;
15165         struct rte_eth_stats stats;
15166         int ret = -ENOTSUP;
15167         static const char *nic_stats_border = "########################";
15168
15169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15170                 return;
15171
15172         memset(&stats, 0, sizeof(stats));
15173
15174 #ifdef RTE_LIBRTE_I40E_PMD
15175         if (ret == -ENOTSUP)
15176                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15177                                                 res->vf_id,
15178                                                 &stats);
15179 #endif
15180 #ifdef RTE_LIBRTE_BNXT_PMD
15181         if (ret == -ENOTSUP)
15182                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15183                                                 res->vf_id,
15184                                                 &stats);
15185 #endif
15186
15187         switch (ret) {
15188         case 0:
15189                 break;
15190         case -EINVAL:
15191                 printf("invalid vf_id %d\n", res->vf_id);
15192                 break;
15193         case -ENODEV:
15194                 printf("invalid port_id %d\n", res->port_id);
15195                 break;
15196         case -ENOTSUP:
15197                 printf("function not implemented\n");
15198                 break;
15199         default:
15200                 printf("programming error: (%s)\n", strerror(-ret));
15201         }
15202
15203         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15204                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15205
15206         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15207                "%-"PRIu64"\n",
15208                stats.ipackets, stats.imissed, stats.ibytes);
15209         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15210         printf("  RX-nombuf:  %-10"PRIu64"\n",
15211                stats.rx_nombuf);
15212         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15213                "%-"PRIu64"\n",
15214                stats.opackets, stats.oerrors, stats.obytes);
15215
15216         printf("  %s############################%s\n",
15217                                nic_stats_border, nic_stats_border);
15218 }
15219
15220 cmdline_parse_inst_t cmd_show_vf_stats = {
15221         .f = cmd_show_vf_stats_parsed,
15222         .data = NULL,
15223         .help_str = "show vf stats <port_id> <vf_id>",
15224         .tokens = {
15225                 (void *)&cmd_show_vf_stats_show,
15226                 (void *)&cmd_show_vf_stats_vf,
15227                 (void *)&cmd_show_vf_stats_stats,
15228                 (void *)&cmd_show_vf_stats_port_id,
15229                 (void *)&cmd_show_vf_stats_vf_id,
15230                 NULL,
15231         },
15232 };
15233
15234 /* clear vf stats */
15235
15236 /* Common result structure for clear vf stats */
15237 struct cmd_clear_vf_stats_result {
15238         cmdline_fixed_string_t clear;
15239         cmdline_fixed_string_t vf;
15240         cmdline_fixed_string_t stats;
15241         portid_t port_id;
15242         uint16_t vf_id;
15243 };
15244
15245 /* Common CLI fields clear vf stats*/
15246 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15247         TOKEN_STRING_INITIALIZER
15248                 (struct cmd_clear_vf_stats_result,
15249                  clear, "clear");
15250 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15251         TOKEN_STRING_INITIALIZER
15252                 (struct cmd_clear_vf_stats_result,
15253                  vf, "vf");
15254 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15255         TOKEN_STRING_INITIALIZER
15256                 (struct cmd_clear_vf_stats_result,
15257                  stats, "stats");
15258 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15259         TOKEN_NUM_INITIALIZER
15260                 (struct cmd_clear_vf_stats_result,
15261                  port_id, UINT16);
15262 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15263         TOKEN_NUM_INITIALIZER
15264                 (struct cmd_clear_vf_stats_result,
15265                  vf_id, UINT16);
15266
15267 static void
15268 cmd_clear_vf_stats_parsed(
15269         void *parsed_result,
15270         __attribute__((unused)) struct cmdline *cl,
15271         __attribute__((unused)) void *data)
15272 {
15273         struct cmd_clear_vf_stats_result *res = parsed_result;
15274         int ret = -ENOTSUP;
15275
15276         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15277                 return;
15278
15279 #ifdef RTE_LIBRTE_I40E_PMD
15280         if (ret == -ENOTSUP)
15281                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15282                                                   res->vf_id);
15283 #endif
15284 #ifdef RTE_LIBRTE_BNXT_PMD
15285         if (ret == -ENOTSUP)
15286                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15287                                                   res->vf_id);
15288 #endif
15289
15290         switch (ret) {
15291         case 0:
15292                 break;
15293         case -EINVAL:
15294                 printf("invalid vf_id %d\n", res->vf_id);
15295                 break;
15296         case -ENODEV:
15297                 printf("invalid port_id %d\n", res->port_id);
15298                 break;
15299         case -ENOTSUP:
15300                 printf("function not implemented\n");
15301                 break;
15302         default:
15303                 printf("programming error: (%s)\n", strerror(-ret));
15304         }
15305 }
15306
15307 cmdline_parse_inst_t cmd_clear_vf_stats = {
15308         .f = cmd_clear_vf_stats_parsed,
15309         .data = NULL,
15310         .help_str = "clear vf stats <port_id> <vf_id>",
15311         .tokens = {
15312                 (void *)&cmd_clear_vf_stats_clear,
15313                 (void *)&cmd_clear_vf_stats_vf,
15314                 (void *)&cmd_clear_vf_stats_stats,
15315                 (void *)&cmd_clear_vf_stats_port_id,
15316                 (void *)&cmd_clear_vf_stats_vf_id,
15317                 NULL,
15318         },
15319 };
15320
15321 /* port config pctype mapping reset */
15322
15323 /* Common result structure for port config pctype mapping reset */
15324 struct cmd_pctype_mapping_reset_result {
15325         cmdline_fixed_string_t port;
15326         cmdline_fixed_string_t config;
15327         portid_t port_id;
15328         cmdline_fixed_string_t pctype;
15329         cmdline_fixed_string_t mapping;
15330         cmdline_fixed_string_t reset;
15331 };
15332
15333 /* Common CLI fields for port config pctype mapping reset*/
15334 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15335         TOKEN_STRING_INITIALIZER
15336                 (struct cmd_pctype_mapping_reset_result,
15337                  port, "port");
15338 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15339         TOKEN_STRING_INITIALIZER
15340                 (struct cmd_pctype_mapping_reset_result,
15341                  config, "config");
15342 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15343         TOKEN_NUM_INITIALIZER
15344                 (struct cmd_pctype_mapping_reset_result,
15345                  port_id, UINT16);
15346 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15347         TOKEN_STRING_INITIALIZER
15348                 (struct cmd_pctype_mapping_reset_result,
15349                  pctype, "pctype");
15350 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15351         TOKEN_STRING_INITIALIZER
15352                 (struct cmd_pctype_mapping_reset_result,
15353                  mapping, "mapping");
15354 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15355         TOKEN_STRING_INITIALIZER
15356                 (struct cmd_pctype_mapping_reset_result,
15357                  reset, "reset");
15358
15359 static void
15360 cmd_pctype_mapping_reset_parsed(
15361         void *parsed_result,
15362         __attribute__((unused)) struct cmdline *cl,
15363         __attribute__((unused)) void *data)
15364 {
15365         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15366         int ret = -ENOTSUP;
15367
15368         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15369                 return;
15370
15371 #ifdef RTE_LIBRTE_I40E_PMD
15372         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15373 #endif
15374
15375         switch (ret) {
15376         case 0:
15377                 break;
15378         case -ENODEV:
15379                 printf("invalid port_id %d\n", res->port_id);
15380                 break;
15381         case -ENOTSUP:
15382                 printf("function not implemented\n");
15383                 break;
15384         default:
15385                 printf("programming error: (%s)\n", strerror(-ret));
15386         }
15387 }
15388
15389 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15390         .f = cmd_pctype_mapping_reset_parsed,
15391         .data = NULL,
15392         .help_str = "port config <port_id> pctype mapping reset",
15393         .tokens = {
15394                 (void *)&cmd_pctype_mapping_reset_port,
15395                 (void *)&cmd_pctype_mapping_reset_config,
15396                 (void *)&cmd_pctype_mapping_reset_port_id,
15397                 (void *)&cmd_pctype_mapping_reset_pctype,
15398                 (void *)&cmd_pctype_mapping_reset_mapping,
15399                 (void *)&cmd_pctype_mapping_reset_reset,
15400                 NULL,
15401         },
15402 };
15403
15404 /* show port pctype mapping */
15405
15406 /* Common result structure for show port pctype mapping */
15407 struct cmd_pctype_mapping_get_result {
15408         cmdline_fixed_string_t show;
15409         cmdline_fixed_string_t port;
15410         portid_t port_id;
15411         cmdline_fixed_string_t pctype;
15412         cmdline_fixed_string_t mapping;
15413 };
15414
15415 /* Common CLI fields for pctype mapping get */
15416 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15417         TOKEN_STRING_INITIALIZER
15418                 (struct cmd_pctype_mapping_get_result,
15419                  show, "show");
15420 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15421         TOKEN_STRING_INITIALIZER
15422                 (struct cmd_pctype_mapping_get_result,
15423                  port, "port");
15424 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15425         TOKEN_NUM_INITIALIZER
15426                 (struct cmd_pctype_mapping_get_result,
15427                  port_id, UINT16);
15428 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15429         TOKEN_STRING_INITIALIZER
15430                 (struct cmd_pctype_mapping_get_result,
15431                  pctype, "pctype");
15432 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15433         TOKEN_STRING_INITIALIZER
15434                 (struct cmd_pctype_mapping_get_result,
15435                  mapping, "mapping");
15436
15437 static void
15438 cmd_pctype_mapping_get_parsed(
15439         void *parsed_result,
15440         __attribute__((unused)) struct cmdline *cl,
15441         __attribute__((unused)) void *data)
15442 {
15443         struct cmd_pctype_mapping_get_result *res = parsed_result;
15444         int ret = -ENOTSUP;
15445 #ifdef RTE_LIBRTE_I40E_PMD
15446         struct rte_pmd_i40e_flow_type_mapping
15447                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15448         int i, j, first_pctype;
15449 #endif
15450
15451         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15452                 return;
15453
15454 #ifdef RTE_LIBRTE_I40E_PMD
15455         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15456 #endif
15457
15458         switch (ret) {
15459         case 0:
15460                 break;
15461         case -ENODEV:
15462                 printf("invalid port_id %d\n", res->port_id);
15463                 return;
15464         case -ENOTSUP:
15465                 printf("function not implemented\n");
15466                 return;
15467         default:
15468                 printf("programming error: (%s)\n", strerror(-ret));
15469                 return;
15470         }
15471
15472 #ifdef RTE_LIBRTE_I40E_PMD
15473         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15474                 if (mapping[i].pctype != 0ULL) {
15475                         first_pctype = 1;
15476
15477                         printf("pctype: ");
15478                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15479                                 if (mapping[i].pctype & (1ULL << j)) {
15480                                         printf(first_pctype ?
15481                                                "%02d" : ",%02d", j);
15482                                         first_pctype = 0;
15483                                 }
15484                         }
15485                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15486                 }
15487         }
15488 #endif
15489 }
15490
15491 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15492         .f = cmd_pctype_mapping_get_parsed,
15493         .data = NULL,
15494         .help_str = "show port <port_id> pctype mapping",
15495         .tokens = {
15496                 (void *)&cmd_pctype_mapping_get_show,
15497                 (void *)&cmd_pctype_mapping_get_port,
15498                 (void *)&cmd_pctype_mapping_get_port_id,
15499                 (void *)&cmd_pctype_mapping_get_pctype,
15500                 (void *)&cmd_pctype_mapping_get_mapping,
15501                 NULL,
15502         },
15503 };
15504
15505 /* port config pctype mapping update */
15506
15507 /* Common result structure for port config pctype mapping update */
15508 struct cmd_pctype_mapping_update_result {
15509         cmdline_fixed_string_t port;
15510         cmdline_fixed_string_t config;
15511         portid_t port_id;
15512         cmdline_fixed_string_t pctype;
15513         cmdline_fixed_string_t mapping;
15514         cmdline_fixed_string_t update;
15515         cmdline_fixed_string_t pctype_list;
15516         uint16_t flow_type;
15517 };
15518
15519 /* Common CLI fields for pctype mapping update*/
15520 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15521         TOKEN_STRING_INITIALIZER
15522                 (struct cmd_pctype_mapping_update_result,
15523                  port, "port");
15524 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15525         TOKEN_STRING_INITIALIZER
15526                 (struct cmd_pctype_mapping_update_result,
15527                  config, "config");
15528 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15529         TOKEN_NUM_INITIALIZER
15530                 (struct cmd_pctype_mapping_update_result,
15531                  port_id, UINT16);
15532 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15533         TOKEN_STRING_INITIALIZER
15534                 (struct cmd_pctype_mapping_update_result,
15535                  pctype, "pctype");
15536 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15537         TOKEN_STRING_INITIALIZER
15538                 (struct cmd_pctype_mapping_update_result,
15539                  mapping, "mapping");
15540 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15541         TOKEN_STRING_INITIALIZER
15542                 (struct cmd_pctype_mapping_update_result,
15543                  update, "update");
15544 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15545         TOKEN_STRING_INITIALIZER
15546                 (struct cmd_pctype_mapping_update_result,
15547                  pctype_list, NULL);
15548 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15549         TOKEN_NUM_INITIALIZER
15550                 (struct cmd_pctype_mapping_update_result,
15551                  flow_type, UINT16);
15552
15553 static void
15554 cmd_pctype_mapping_update_parsed(
15555         void *parsed_result,
15556         __attribute__((unused)) struct cmdline *cl,
15557         __attribute__((unused)) void *data)
15558 {
15559         struct cmd_pctype_mapping_update_result *res = parsed_result;
15560         int ret = -ENOTSUP;
15561 #ifdef RTE_LIBRTE_I40E_PMD
15562         struct rte_pmd_i40e_flow_type_mapping mapping;
15563         unsigned int i;
15564         unsigned int nb_item;
15565         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15566 #endif
15567
15568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15569                 return;
15570
15571 #ifdef RTE_LIBRTE_I40E_PMD
15572         nb_item = parse_item_list(res->pctype_list, "pctypes",
15573                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15574         mapping.flow_type = res->flow_type;
15575         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15576                 mapping.pctype |= (1ULL << pctype_list[i]);
15577         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15578                                                 &mapping,
15579                                                 1,
15580                                                 0);
15581 #endif
15582
15583         switch (ret) {
15584         case 0:
15585                 break;
15586         case -EINVAL:
15587                 printf("invalid pctype or flow type\n");
15588                 break;
15589         case -ENODEV:
15590                 printf("invalid port_id %d\n", res->port_id);
15591                 break;
15592         case -ENOTSUP:
15593                 printf("function not implemented\n");
15594                 break;
15595         default:
15596                 printf("programming error: (%s)\n", strerror(-ret));
15597         }
15598 }
15599
15600 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15601         .f = cmd_pctype_mapping_update_parsed,
15602         .data = NULL,
15603         .help_str = "port config <port_id> pctype mapping update"
15604         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15605         .tokens = {
15606                 (void *)&cmd_pctype_mapping_update_port,
15607                 (void *)&cmd_pctype_mapping_update_config,
15608                 (void *)&cmd_pctype_mapping_update_port_id,
15609                 (void *)&cmd_pctype_mapping_update_pctype,
15610                 (void *)&cmd_pctype_mapping_update_mapping,
15611                 (void *)&cmd_pctype_mapping_update_update,
15612                 (void *)&cmd_pctype_mapping_update_pc_type,
15613                 (void *)&cmd_pctype_mapping_update_flow_type,
15614                 NULL,
15615         },
15616 };
15617
15618 /* ptype mapping get */
15619
15620 /* Common result structure for ptype mapping get */
15621 struct cmd_ptype_mapping_get_result {
15622         cmdline_fixed_string_t ptype;
15623         cmdline_fixed_string_t mapping;
15624         cmdline_fixed_string_t get;
15625         portid_t port_id;
15626         uint8_t valid_only;
15627 };
15628
15629 /* Common CLI fields for ptype mapping get */
15630 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15631         TOKEN_STRING_INITIALIZER
15632                 (struct cmd_ptype_mapping_get_result,
15633                  ptype, "ptype");
15634 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15635         TOKEN_STRING_INITIALIZER
15636                 (struct cmd_ptype_mapping_get_result,
15637                  mapping, "mapping");
15638 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15639         TOKEN_STRING_INITIALIZER
15640                 (struct cmd_ptype_mapping_get_result,
15641                  get, "get");
15642 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15643         TOKEN_NUM_INITIALIZER
15644                 (struct cmd_ptype_mapping_get_result,
15645                  port_id, UINT16);
15646 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15647         TOKEN_NUM_INITIALIZER
15648                 (struct cmd_ptype_mapping_get_result,
15649                  valid_only, UINT8);
15650
15651 static void
15652 cmd_ptype_mapping_get_parsed(
15653         void *parsed_result,
15654         __attribute__((unused)) struct cmdline *cl,
15655         __attribute__((unused)) void *data)
15656 {
15657         struct cmd_ptype_mapping_get_result *res = parsed_result;
15658         int ret = -ENOTSUP;
15659 #ifdef RTE_LIBRTE_I40E_PMD
15660         int max_ptype_num = 256;
15661         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15662         uint16_t count;
15663         int i;
15664 #endif
15665
15666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15667                 return;
15668
15669 #ifdef RTE_LIBRTE_I40E_PMD
15670         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15671                                         mapping,
15672                                         max_ptype_num,
15673                                         &count,
15674                                         res->valid_only);
15675 #endif
15676
15677         switch (ret) {
15678         case 0:
15679                 break;
15680         case -ENODEV:
15681                 printf("invalid port_id %d\n", res->port_id);
15682                 break;
15683         case -ENOTSUP:
15684                 printf("function not implemented\n");
15685                 break;
15686         default:
15687                 printf("programming error: (%s)\n", strerror(-ret));
15688         }
15689
15690 #ifdef RTE_LIBRTE_I40E_PMD
15691         if (!ret) {
15692                 for (i = 0; i < count; i++)
15693                         printf("%3d\t0x%08x\n",
15694                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15695         }
15696 #endif
15697 }
15698
15699 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15700         .f = cmd_ptype_mapping_get_parsed,
15701         .data = NULL,
15702         .help_str = "ptype mapping get <port_id> <valid_only>",
15703         .tokens = {
15704                 (void *)&cmd_ptype_mapping_get_ptype,
15705                 (void *)&cmd_ptype_mapping_get_mapping,
15706                 (void *)&cmd_ptype_mapping_get_get,
15707                 (void *)&cmd_ptype_mapping_get_port_id,
15708                 (void *)&cmd_ptype_mapping_get_valid_only,
15709                 NULL,
15710         },
15711 };
15712
15713 /* ptype mapping replace */
15714
15715 /* Common result structure for ptype mapping replace */
15716 struct cmd_ptype_mapping_replace_result {
15717         cmdline_fixed_string_t ptype;
15718         cmdline_fixed_string_t mapping;
15719         cmdline_fixed_string_t replace;
15720         portid_t port_id;
15721         uint32_t target;
15722         uint8_t mask;
15723         uint32_t pkt_type;
15724 };
15725
15726 /* Common CLI fields for ptype mapping replace */
15727 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15728         TOKEN_STRING_INITIALIZER
15729                 (struct cmd_ptype_mapping_replace_result,
15730                  ptype, "ptype");
15731 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15732         TOKEN_STRING_INITIALIZER
15733                 (struct cmd_ptype_mapping_replace_result,
15734                  mapping, "mapping");
15735 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15736         TOKEN_STRING_INITIALIZER
15737                 (struct cmd_ptype_mapping_replace_result,
15738                  replace, "replace");
15739 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15740         TOKEN_NUM_INITIALIZER
15741                 (struct cmd_ptype_mapping_replace_result,
15742                  port_id, UINT16);
15743 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15744         TOKEN_NUM_INITIALIZER
15745                 (struct cmd_ptype_mapping_replace_result,
15746                  target, UINT32);
15747 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15748         TOKEN_NUM_INITIALIZER
15749                 (struct cmd_ptype_mapping_replace_result,
15750                  mask, UINT8);
15751 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15752         TOKEN_NUM_INITIALIZER
15753                 (struct cmd_ptype_mapping_replace_result,
15754                  pkt_type, UINT32);
15755
15756 static void
15757 cmd_ptype_mapping_replace_parsed(
15758         void *parsed_result,
15759         __attribute__((unused)) struct cmdline *cl,
15760         __attribute__((unused)) void *data)
15761 {
15762         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15763         int ret = -ENOTSUP;
15764
15765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15766                 return;
15767
15768 #ifdef RTE_LIBRTE_I40E_PMD
15769         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15770                                         res->target,
15771                                         res->mask,
15772                                         res->pkt_type);
15773 #endif
15774
15775         switch (ret) {
15776         case 0:
15777                 break;
15778         case -EINVAL:
15779                 printf("invalid ptype 0x%8x or 0x%8x\n",
15780                                 res->target, res->pkt_type);
15781                 break;
15782         case -ENODEV:
15783                 printf("invalid port_id %d\n", res->port_id);
15784                 break;
15785         case -ENOTSUP:
15786                 printf("function not implemented\n");
15787                 break;
15788         default:
15789                 printf("programming error: (%s)\n", strerror(-ret));
15790         }
15791 }
15792
15793 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15794         .f = cmd_ptype_mapping_replace_parsed,
15795         .data = NULL,
15796         .help_str =
15797                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15798         .tokens = {
15799                 (void *)&cmd_ptype_mapping_replace_ptype,
15800                 (void *)&cmd_ptype_mapping_replace_mapping,
15801                 (void *)&cmd_ptype_mapping_replace_replace,
15802                 (void *)&cmd_ptype_mapping_replace_port_id,
15803                 (void *)&cmd_ptype_mapping_replace_target,
15804                 (void *)&cmd_ptype_mapping_replace_mask,
15805                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15806                 NULL,
15807         },
15808 };
15809
15810 /* ptype mapping reset */
15811
15812 /* Common result structure for ptype mapping reset */
15813 struct cmd_ptype_mapping_reset_result {
15814         cmdline_fixed_string_t ptype;
15815         cmdline_fixed_string_t mapping;
15816         cmdline_fixed_string_t reset;
15817         portid_t port_id;
15818 };
15819
15820 /* Common CLI fields for ptype mapping reset*/
15821 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15822         TOKEN_STRING_INITIALIZER
15823                 (struct cmd_ptype_mapping_reset_result,
15824                  ptype, "ptype");
15825 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15826         TOKEN_STRING_INITIALIZER
15827                 (struct cmd_ptype_mapping_reset_result,
15828                  mapping, "mapping");
15829 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15830         TOKEN_STRING_INITIALIZER
15831                 (struct cmd_ptype_mapping_reset_result,
15832                  reset, "reset");
15833 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15834         TOKEN_NUM_INITIALIZER
15835                 (struct cmd_ptype_mapping_reset_result,
15836                  port_id, UINT16);
15837
15838 static void
15839 cmd_ptype_mapping_reset_parsed(
15840         void *parsed_result,
15841         __attribute__((unused)) struct cmdline *cl,
15842         __attribute__((unused)) void *data)
15843 {
15844         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15845         int ret = -ENOTSUP;
15846
15847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15848                 return;
15849
15850 #ifdef RTE_LIBRTE_I40E_PMD
15851         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15852 #endif
15853
15854         switch (ret) {
15855         case 0:
15856                 break;
15857         case -ENODEV:
15858                 printf("invalid port_id %d\n", res->port_id);
15859                 break;
15860         case -ENOTSUP:
15861                 printf("function not implemented\n");
15862                 break;
15863         default:
15864                 printf("programming error: (%s)\n", strerror(-ret));
15865         }
15866 }
15867
15868 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15869         .f = cmd_ptype_mapping_reset_parsed,
15870         .data = NULL,
15871         .help_str = "ptype mapping reset <port_id>",
15872         .tokens = {
15873                 (void *)&cmd_ptype_mapping_reset_ptype,
15874                 (void *)&cmd_ptype_mapping_reset_mapping,
15875                 (void *)&cmd_ptype_mapping_reset_reset,
15876                 (void *)&cmd_ptype_mapping_reset_port_id,
15877                 NULL,
15878         },
15879 };
15880
15881 /* ptype mapping update */
15882
15883 /* Common result structure for ptype mapping update */
15884 struct cmd_ptype_mapping_update_result {
15885         cmdline_fixed_string_t ptype;
15886         cmdline_fixed_string_t mapping;
15887         cmdline_fixed_string_t reset;
15888         portid_t port_id;
15889         uint8_t hw_ptype;
15890         uint32_t sw_ptype;
15891 };
15892
15893 /* Common CLI fields for ptype mapping update*/
15894 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15895         TOKEN_STRING_INITIALIZER
15896                 (struct cmd_ptype_mapping_update_result,
15897                  ptype, "ptype");
15898 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15899         TOKEN_STRING_INITIALIZER
15900                 (struct cmd_ptype_mapping_update_result,
15901                  mapping, "mapping");
15902 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15903         TOKEN_STRING_INITIALIZER
15904                 (struct cmd_ptype_mapping_update_result,
15905                  reset, "update");
15906 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15907         TOKEN_NUM_INITIALIZER
15908                 (struct cmd_ptype_mapping_update_result,
15909                  port_id, UINT16);
15910 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15911         TOKEN_NUM_INITIALIZER
15912                 (struct cmd_ptype_mapping_update_result,
15913                  hw_ptype, UINT8);
15914 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15915         TOKEN_NUM_INITIALIZER
15916                 (struct cmd_ptype_mapping_update_result,
15917                  sw_ptype, UINT32);
15918
15919 static void
15920 cmd_ptype_mapping_update_parsed(
15921         void *parsed_result,
15922         __attribute__((unused)) struct cmdline *cl,
15923         __attribute__((unused)) void *data)
15924 {
15925         struct cmd_ptype_mapping_update_result *res = parsed_result;
15926         int ret = -ENOTSUP;
15927 #ifdef RTE_LIBRTE_I40E_PMD
15928         struct rte_pmd_i40e_ptype_mapping mapping;
15929 #endif
15930         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15931                 return;
15932
15933 #ifdef RTE_LIBRTE_I40E_PMD
15934         mapping.hw_ptype = res->hw_ptype;
15935         mapping.sw_ptype = res->sw_ptype;
15936         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15937                                                 &mapping,
15938                                                 1,
15939                                                 0);
15940 #endif
15941
15942         switch (ret) {
15943         case 0:
15944                 break;
15945         case -EINVAL:
15946                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15947                 break;
15948         case -ENODEV:
15949                 printf("invalid port_id %d\n", res->port_id);
15950                 break;
15951         case -ENOTSUP:
15952                 printf("function not implemented\n");
15953                 break;
15954         default:
15955                 printf("programming error: (%s)\n", strerror(-ret));
15956         }
15957 }
15958
15959 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15960         .f = cmd_ptype_mapping_update_parsed,
15961         .data = NULL,
15962         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15963         .tokens = {
15964                 (void *)&cmd_ptype_mapping_update_ptype,
15965                 (void *)&cmd_ptype_mapping_update_mapping,
15966                 (void *)&cmd_ptype_mapping_update_update,
15967                 (void *)&cmd_ptype_mapping_update_port_id,
15968                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15969                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15970                 NULL,
15971         },
15972 };
15973
15974 /* Common result structure for file commands */
15975 struct cmd_cmdfile_result {
15976         cmdline_fixed_string_t load;
15977         cmdline_fixed_string_t filename;
15978 };
15979
15980 /* Common CLI fields for file commands */
15981 cmdline_parse_token_string_t cmd_load_cmdfile =
15982         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15983 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15984         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15985
15986 static void
15987 cmd_load_from_file_parsed(
15988         void *parsed_result,
15989         __attribute__((unused)) struct cmdline *cl,
15990         __attribute__((unused)) void *data)
15991 {
15992         struct cmd_cmdfile_result *res = parsed_result;
15993
15994         cmdline_read_from_file(res->filename);
15995 }
15996
15997 cmdline_parse_inst_t cmd_load_from_file = {
15998         .f = cmd_load_from_file_parsed,
15999         .data = NULL,
16000         .help_str = "load <filename>",
16001         .tokens = {
16002                 (void *)&cmd_load_cmdfile,
16003                 (void *)&cmd_load_cmdfile_filename,
16004                 NULL,
16005         },
16006 };
16007
16008 /* ******************************************************************************** */
16009
16010 /* list of instructions */
16011 cmdline_parse_ctx_t main_ctx[] = {
16012         (cmdline_parse_inst_t *)&cmd_help_brief,
16013         (cmdline_parse_inst_t *)&cmd_help_long,
16014         (cmdline_parse_inst_t *)&cmd_quit,
16015         (cmdline_parse_inst_t *)&cmd_load_from_file,
16016         (cmdline_parse_inst_t *)&cmd_showport,
16017         (cmdline_parse_inst_t *)&cmd_showqueue,
16018         (cmdline_parse_inst_t *)&cmd_showportall,
16019         (cmdline_parse_inst_t *)&cmd_showcfg,
16020         (cmdline_parse_inst_t *)&cmd_start,
16021         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16022         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16023         (cmdline_parse_inst_t *)&cmd_set_link_up,
16024         (cmdline_parse_inst_t *)&cmd_set_link_down,
16025         (cmdline_parse_inst_t *)&cmd_reset,
16026         (cmdline_parse_inst_t *)&cmd_set_numbers,
16027         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16028         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16029         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16030         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16031         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16032         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16033         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16034         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16035         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16036         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16037         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16038         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16039         (cmdline_parse_inst_t *)&cmd_set_link_check,
16040         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16041         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16042         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16043         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16044 #ifdef RTE_LIBRTE_PMD_BOND
16045         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16046         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16047         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16048         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16049         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16050         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16051         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16052         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16053         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16054         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16055         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16056 #endif
16057         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16058         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16059         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16060         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16061         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16062         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16063         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16064         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16065         (cmdline_parse_inst_t *)&cmd_csum_set,
16066         (cmdline_parse_inst_t *)&cmd_csum_show,
16067         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16068         (cmdline_parse_inst_t *)&cmd_tso_set,
16069         (cmdline_parse_inst_t *)&cmd_tso_show,
16070         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16071         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16072         (cmdline_parse_inst_t *)&cmd_gro_enable,
16073         (cmdline_parse_inst_t *)&cmd_gro_flush,
16074         (cmdline_parse_inst_t *)&cmd_gro_show,
16075         (cmdline_parse_inst_t *)&cmd_gso_enable,
16076         (cmdline_parse_inst_t *)&cmd_gso_size,
16077         (cmdline_parse_inst_t *)&cmd_gso_show,
16078         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16079         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16080         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16081         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16082         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16083         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16084         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16085         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16086         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16087         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16088         (cmdline_parse_inst_t *)&cmd_config_dcb,
16089         (cmdline_parse_inst_t *)&cmd_read_reg,
16090         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16091         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16092         (cmdline_parse_inst_t *)&cmd_write_reg,
16093         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16094         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16095         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16096         (cmdline_parse_inst_t *)&cmd_stop,
16097         (cmdline_parse_inst_t *)&cmd_mac_addr,
16098         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16099         (cmdline_parse_inst_t *)&cmd_set_qmap,
16100         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16101         (cmdline_parse_inst_t *)&cmd_operate_port,
16102         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16103         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16104         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16105         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16106         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16107         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16108         (cmdline_parse_inst_t *)&cmd_config_mtu,
16109         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16110         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16111         (cmdline_parse_inst_t *)&cmd_config_rss,
16112         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16113         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16114         (cmdline_parse_inst_t *)&cmd_showport_reta,
16115         (cmdline_parse_inst_t *)&cmd_config_burst,
16116         (cmdline_parse_inst_t *)&cmd_config_thresh,
16117         (cmdline_parse_inst_t *)&cmd_config_threshold,
16118         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16119         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16120         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16121         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16122         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16123         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16124         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16125         (cmdline_parse_inst_t *)&cmd_global_config,
16126         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16127         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16128         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16129         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16130         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16131         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16132         (cmdline_parse_inst_t *)&cmd_dump,
16133         (cmdline_parse_inst_t *)&cmd_dump_one,
16134         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16135         (cmdline_parse_inst_t *)&cmd_syn_filter,
16136         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16137         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16138         (cmdline_parse_inst_t *)&cmd_flex_filter,
16139         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16140         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16141         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16142         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16143         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16144         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16145         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16146         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16147         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16148         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16149         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16150         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16151         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16152         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16153         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16154         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16155         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16156         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16157         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16158         (cmdline_parse_inst_t *)&cmd_flow,
16159         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16160         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16161         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16162         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16163         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16164         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16165         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16166         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16167         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16168         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16169         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16170         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16171         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16172         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16173         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16174         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16175         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16176         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16177         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16178         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16179         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16180         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16181         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16182         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16183         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16184         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16185         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16186         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16187         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16188         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16189         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16190         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16191         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16192         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16193         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16194         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16195         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16196         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16197         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16198         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16199         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16200         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16201         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16202         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16203         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16204         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16205         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16206         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16207         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16208 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16209         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16210 #endif
16211         (cmdline_parse_inst_t *)&cmd_ddp_add,
16212         (cmdline_parse_inst_t *)&cmd_ddp_del,
16213         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16214         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16215         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16216         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16217         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16218         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16219         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16220         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16221         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16222         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16223
16224         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16225         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16226         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16227         (cmdline_parse_inst_t *)&cmd_queue_region,
16228         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16229         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16230         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16231         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16232         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16233         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16234         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16235         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16236         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16237         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16238         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16239         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16240         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16241         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16242         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16243         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16244         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16245         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16246         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16247         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16248         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16249         NULL,
16250 };
16251
16252 /* read cmdline commands from file */
16253 void
16254 cmdline_read_from_file(const char *filename)
16255 {
16256         struct cmdline *cl;
16257
16258         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16259         if (cl == NULL) {
16260                 printf("Failed to create file based cmdline context: %s\n",
16261                        filename);
16262                 return;
16263         }
16264
16265         cmdline_interact(cl);
16266         cmdline_quit(cl);
16267
16268         cmdline_free(cl);
16269
16270         printf("Read CLI commands from %s\n", filename);
16271 }
16272
16273 /* prompt function, called from main on MASTER lcore */
16274 void
16275 prompt(void)
16276 {
16277         /* initialize non-constant commands */
16278         cmd_set_fwd_mode_init();
16279         cmd_set_fwd_retry_mode_init();
16280
16281         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16282         if (testpmd_cl == NULL)
16283                 return;
16284         cmdline_interact(testpmd_cl);
16285         cmdline_stdin_exit(testpmd_cl);
16286 }
16287
16288 void
16289 prompt_exit(void)
16290 {
16291         if (testpmd_cl != NULL)
16292                 cmdline_quit(testpmd_cl);
16293 }
16294
16295 static void
16296 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16297 {
16298         if (id == (portid_t)RTE_PORT_ALL) {
16299                 portid_t pid;
16300
16301                 RTE_ETH_FOREACH_DEV(pid) {
16302                         /* check if need_reconfig has been set to 1 */
16303                         if (ports[pid].need_reconfig == 0)
16304                                 ports[pid].need_reconfig = dev;
16305                         /* check if need_reconfig_queues has been set to 1 */
16306                         if (ports[pid].need_reconfig_queues == 0)
16307                                 ports[pid].need_reconfig_queues = queue;
16308                 }
16309         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16310                 /* check if need_reconfig has been set to 1 */
16311                 if (ports[id].need_reconfig == 0)
16312                         ports[id].need_reconfig = dev;
16313                 /* check if need_reconfig_queues has been set to 1 */
16314                 if (ports[id].need_reconfig_queues == 0)
16315                         ports[id].need_reconfig_queues = queue;
16316         }
16317 }