app/testpmd: add configuration for input set
[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                 nb_rxq = res->value;
1542         }
1543         else if (!strcmp(res->name, "txq")) {
1544                 if (!res->value && !nb_rxq) {
1545                         printf("Warning: Either rx or tx queues should be non zero\n");
1546                         return;
1547                 }
1548                 nb_txq = res->value;
1549         }
1550         else if (!strcmp(res->name, "rxd")) {
1551                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1552                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1553                                         res->value, RTE_TEST_RX_DESC_MAX);
1554                         return;
1555                 }
1556                 nb_rxd = res->value;
1557         } else if (!strcmp(res->name, "txd")) {
1558                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1559                         printf("txd %d invalid - must be > 0 && <= %d\n",
1560                                         res->value, RTE_TEST_TX_DESC_MAX);
1561                         return;
1562                 }
1563                 nb_txd = res->value;
1564         } else {
1565                 printf("Unknown parameter\n");
1566                 return;
1567         }
1568
1569         fwd_config_setup();
1570
1571         init_port_config();
1572
1573         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1574 }
1575
1576 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1577         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1578 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1579         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1580 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1582 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1584                                                 "rxq#txq#rxd#txd");
1585 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1586         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1587
1588 cmdline_parse_inst_t cmd_config_rx_tx = {
1589         .f = cmd_config_rx_tx_parsed,
1590         .data = NULL,
1591         .help_str = "port config all rxq|txq|rxd|txd <value>",
1592         .tokens = {
1593                 (void *)&cmd_config_rx_tx_port,
1594                 (void *)&cmd_config_rx_tx_keyword,
1595                 (void *)&cmd_config_rx_tx_all,
1596                 (void *)&cmd_config_rx_tx_name,
1597                 (void *)&cmd_config_rx_tx_value,
1598                 NULL,
1599         },
1600 };
1601
1602 /* *** config max packet length *** */
1603 struct cmd_config_max_pkt_len_result {
1604         cmdline_fixed_string_t port;
1605         cmdline_fixed_string_t keyword;
1606         cmdline_fixed_string_t all;
1607         cmdline_fixed_string_t name;
1608         uint32_t value;
1609 };
1610
1611 static void
1612 cmd_config_max_pkt_len_parsed(void *parsed_result,
1613                                 __attribute__((unused)) struct cmdline *cl,
1614                                 __attribute__((unused)) void *data)
1615 {
1616         struct cmd_config_max_pkt_len_result *res = parsed_result;
1617         portid_t pid;
1618
1619         if (!all_ports_stopped()) {
1620                 printf("Please stop all ports first\n");
1621                 return;
1622         }
1623
1624         RTE_ETH_FOREACH_DEV(pid) {
1625                 struct rte_port *port = &ports[pid];
1626                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1627
1628                 if (!strcmp(res->name, "max-pkt-len")) {
1629                         if (res->value < ETHER_MIN_LEN) {
1630                                 printf("max-pkt-len can not be less than %d\n",
1631                                                 ETHER_MIN_LEN);
1632                                 return;
1633                         }
1634                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1635                                 return;
1636
1637                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1638                         if (res->value > ETHER_MAX_LEN)
1639                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1640                         else
1641                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1642                         port->dev_conf.rxmode.offloads = rx_offloads;
1643                 } else {
1644                         printf("Unknown parameter\n");
1645                         return;
1646                 }
1647         }
1648
1649         init_port_config();
1650
1651         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1652 }
1653
1654 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1656                                                                 "port");
1657 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1659                                                                 "config");
1660 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1662                                                                 "all");
1663 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1665                                                                 "max-pkt-len");
1666 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1667         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1668                                                                 UINT32);
1669
1670 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1671         .f = cmd_config_max_pkt_len_parsed,
1672         .data = NULL,
1673         .help_str = "port config all max-pkt-len <value>",
1674         .tokens = {
1675                 (void *)&cmd_config_max_pkt_len_port,
1676                 (void *)&cmd_config_max_pkt_len_keyword,
1677                 (void *)&cmd_config_max_pkt_len_all,
1678                 (void *)&cmd_config_max_pkt_len_name,
1679                 (void *)&cmd_config_max_pkt_len_value,
1680                 NULL,
1681         },
1682 };
1683
1684 /* *** configure port MTU *** */
1685 struct cmd_config_mtu_result {
1686         cmdline_fixed_string_t port;
1687         cmdline_fixed_string_t keyword;
1688         cmdline_fixed_string_t mtu;
1689         portid_t port_id;
1690         uint16_t value;
1691 };
1692
1693 static void
1694 cmd_config_mtu_parsed(void *parsed_result,
1695                       __attribute__((unused)) struct cmdline *cl,
1696                       __attribute__((unused)) void *data)
1697 {
1698         struct cmd_config_mtu_result *res = parsed_result;
1699
1700         if (res->value < ETHER_MIN_LEN) {
1701                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1702                 return;
1703         }
1704         port_mtu_set(res->port_id, res->value);
1705 }
1706
1707 cmdline_parse_token_string_t cmd_config_mtu_port =
1708         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1709                                  "port");
1710 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1711         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1712                                  "config");
1713 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1715                                  "mtu");
1716 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1717         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1718 cmdline_parse_token_num_t cmd_config_mtu_value =
1719         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1720
1721 cmdline_parse_inst_t cmd_config_mtu = {
1722         .f = cmd_config_mtu_parsed,
1723         .data = NULL,
1724         .help_str = "port config mtu <port_id> <value>",
1725         .tokens = {
1726                 (void *)&cmd_config_mtu_port,
1727                 (void *)&cmd_config_mtu_keyword,
1728                 (void *)&cmd_config_mtu_mtu,
1729                 (void *)&cmd_config_mtu_port_id,
1730                 (void *)&cmd_config_mtu_value,
1731                 NULL,
1732         },
1733 };
1734
1735 /* *** configure rx mode *** */
1736 struct cmd_config_rx_mode_flag {
1737         cmdline_fixed_string_t port;
1738         cmdline_fixed_string_t keyword;
1739         cmdline_fixed_string_t all;
1740         cmdline_fixed_string_t name;
1741         cmdline_fixed_string_t value;
1742 };
1743
1744 static void
1745 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1746                                 __attribute__((unused)) struct cmdline *cl,
1747                                 __attribute__((unused)) void *data)
1748 {
1749         struct cmd_config_rx_mode_flag *res = parsed_result;
1750         portid_t pid;
1751
1752         if (!all_ports_stopped()) {
1753                 printf("Please stop all ports first\n");
1754                 return;
1755         }
1756
1757         RTE_ETH_FOREACH_DEV(pid) {
1758                 struct rte_port *port;
1759                 uint64_t rx_offloads;
1760
1761                 port = &ports[pid];
1762                 rx_offloads = port->dev_conf.rxmode.offloads;
1763                 if (!strcmp(res->name, "crc-strip")) {
1764                         if (!strcmp(res->value, "on"))
1765                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1766                         else if (!strcmp(res->value, "off"))
1767                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1768                         else {
1769                                 printf("Unknown parameter\n");
1770                                 return;
1771                         }
1772                 } else if (!strcmp(res->name, "scatter")) {
1773                         if (!strcmp(res->value, "on")) {
1774                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1775                         } else if (!strcmp(res->value, "off")) {
1776                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1777                         } else {
1778                                 printf("Unknown parameter\n");
1779                                 return;
1780                         }
1781                 } else if (!strcmp(res->name, "rx-cksum")) {
1782                         if (!strcmp(res->value, "on"))
1783                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1784                         else if (!strcmp(res->value, "off"))
1785                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1786                         else {
1787                                 printf("Unknown parameter\n");
1788                                 return;
1789                         }
1790                 } else if (!strcmp(res->name, "rx-timestamp")) {
1791                         if (!strcmp(res->value, "on"))
1792                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1793                         else if (!strcmp(res->value, "off"))
1794                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1795                         else {
1796                                 printf("Unknown parameter\n");
1797                                 return;
1798                         }
1799                 } else if (!strcmp(res->name, "hw-vlan")) {
1800                         if (!strcmp(res->value, "on")) {
1801                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1802                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1803                         } else if (!strcmp(res->value, "off")) {
1804                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1805                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1806                         } else {
1807                                 printf("Unknown parameter\n");
1808                                 return;
1809                         }
1810                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1811                         if (!strcmp(res->value, "on"))
1812                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1813                         else if (!strcmp(res->value, "off"))
1814                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1815                         else {
1816                                 printf("Unknown parameter\n");
1817                                 return;
1818                         }
1819                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1820                         if (!strcmp(res->value, "on"))
1821                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1822                         else if (!strcmp(res->value, "off"))
1823                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1824                         else {
1825                                 printf("Unknown parameter\n");
1826                                 return;
1827                         }
1828                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1829                         if (!strcmp(res->value, "on"))
1830                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1831                         else if (!strcmp(res->value, "off"))
1832                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1833                         else {
1834                                 printf("Unknown parameter\n");
1835                                 return;
1836                         }
1837                 } else if (!strcmp(res->name, "drop-en")) {
1838                         if (!strcmp(res->value, "on"))
1839                                 rx_drop_en = 1;
1840                         else if (!strcmp(res->value, "off"))
1841                                 rx_drop_en = 0;
1842                         else {
1843                                 printf("Unknown parameter\n");
1844                                 return;
1845                         }
1846                 } else {
1847                         printf("Unknown parameter\n");
1848                         return;
1849                 }
1850                 port->dev_conf.rxmode.offloads = rx_offloads;
1851         }
1852
1853         init_port_config();
1854
1855         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1856 }
1857
1858 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1860 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1862                                                                 "config");
1863 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1864         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1865 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1867                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1868                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1869 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1870         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1871                                                         "on#off");
1872
1873 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1874         .f = cmd_config_rx_mode_flag_parsed,
1875         .data = NULL,
1876         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1877                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1878         .tokens = {
1879                 (void *)&cmd_config_rx_mode_flag_port,
1880                 (void *)&cmd_config_rx_mode_flag_keyword,
1881                 (void *)&cmd_config_rx_mode_flag_all,
1882                 (void *)&cmd_config_rx_mode_flag_name,
1883                 (void *)&cmd_config_rx_mode_flag_value,
1884                 NULL,
1885         },
1886 };
1887
1888 /* *** configure rss *** */
1889 struct cmd_config_rss {
1890         cmdline_fixed_string_t port;
1891         cmdline_fixed_string_t keyword;
1892         cmdline_fixed_string_t all;
1893         cmdline_fixed_string_t name;
1894         cmdline_fixed_string_t value;
1895 };
1896
1897 static void
1898 cmd_config_rss_parsed(void *parsed_result,
1899                         __attribute__((unused)) struct cmdline *cl,
1900                         __attribute__((unused)) void *data)
1901 {
1902         struct cmd_config_rss *res = parsed_result;
1903         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1904         int diag;
1905         uint8_t i;
1906
1907         if (!strcmp(res->value, "all"))
1908                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1909                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1910                                         ETH_RSS_L2_PAYLOAD;
1911         else if (!strcmp(res->value, "ip"))
1912                 rss_conf.rss_hf = ETH_RSS_IP;
1913         else if (!strcmp(res->value, "udp"))
1914                 rss_conf.rss_hf = ETH_RSS_UDP;
1915         else if (!strcmp(res->value, "tcp"))
1916                 rss_conf.rss_hf = ETH_RSS_TCP;
1917         else if (!strcmp(res->value, "sctp"))
1918                 rss_conf.rss_hf = ETH_RSS_SCTP;
1919         else if (!strcmp(res->value, "ether"))
1920                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1921         else if (!strcmp(res->value, "port"))
1922                 rss_conf.rss_hf = ETH_RSS_PORT;
1923         else if (!strcmp(res->value, "vxlan"))
1924                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1925         else if (!strcmp(res->value, "geneve"))
1926                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1927         else if (!strcmp(res->value, "nvgre"))
1928                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1929         else if (!strcmp(res->value, "none"))
1930                 rss_conf.rss_hf = 0;
1931         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1932                                                 atoi(res->value) < 64)
1933                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1934         else {
1935                 printf("Unknown parameter\n");
1936                 return;
1937         }
1938         rss_conf.rss_key = NULL;
1939         for (i = 0; i < rte_eth_dev_count(); i++) {
1940                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1941                 if (diag < 0)
1942                         printf("Configuration of RSS hash at ethernet port %d "
1943                                 "failed with error (%d): %s.\n",
1944                                 i, -diag, strerror(-diag));
1945         }
1946 }
1947
1948 cmdline_parse_token_string_t cmd_config_rss_port =
1949         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1950 cmdline_parse_token_string_t cmd_config_rss_keyword =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1952 cmdline_parse_token_string_t cmd_config_rss_all =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1954 cmdline_parse_token_string_t cmd_config_rss_name =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1956 cmdline_parse_token_string_t cmd_config_rss_value =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1958
1959 cmdline_parse_inst_t cmd_config_rss = {
1960         .f = cmd_config_rss_parsed,
1961         .data = NULL,
1962         .help_str = "port config all rss "
1963                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1964         .tokens = {
1965                 (void *)&cmd_config_rss_port,
1966                 (void *)&cmd_config_rss_keyword,
1967                 (void *)&cmd_config_rss_all,
1968                 (void *)&cmd_config_rss_name,
1969                 (void *)&cmd_config_rss_value,
1970                 NULL,
1971         },
1972 };
1973
1974 /* *** configure rss hash key *** */
1975 struct cmd_config_rss_hash_key {
1976         cmdline_fixed_string_t port;
1977         cmdline_fixed_string_t config;
1978         portid_t port_id;
1979         cmdline_fixed_string_t rss_hash_key;
1980         cmdline_fixed_string_t rss_type;
1981         cmdline_fixed_string_t key;
1982 };
1983
1984 static uint8_t
1985 hexa_digit_to_value(char hexa_digit)
1986 {
1987         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1988                 return (uint8_t) (hexa_digit - '0');
1989         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1990                 return (uint8_t) ((hexa_digit - 'a') + 10);
1991         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1992                 return (uint8_t) ((hexa_digit - 'A') + 10);
1993         /* Invalid hexa digit */
1994         return 0xFF;
1995 }
1996
1997 static uint8_t
1998 parse_and_check_key_hexa_digit(char *key, int idx)
1999 {
2000         uint8_t hexa_v;
2001
2002         hexa_v = hexa_digit_to_value(key[idx]);
2003         if (hexa_v == 0xFF)
2004                 printf("invalid key: character %c at position %d is not a "
2005                        "valid hexa digit\n", key[idx], idx);
2006         return hexa_v;
2007 }
2008
2009 static void
2010 cmd_config_rss_hash_key_parsed(void *parsed_result,
2011                                __attribute__((unused)) struct cmdline *cl,
2012                                __attribute__((unused)) void *data)
2013 {
2014         struct cmd_config_rss_hash_key *res = parsed_result;
2015         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2016         uint8_t xdgt0;
2017         uint8_t xdgt1;
2018         int i;
2019         struct rte_eth_dev_info dev_info;
2020         uint8_t hash_key_size;
2021         uint32_t key_len;
2022
2023         memset(&dev_info, 0, sizeof(dev_info));
2024         rte_eth_dev_info_get(res->port_id, &dev_info);
2025         if (dev_info.hash_key_size > 0 &&
2026                         dev_info.hash_key_size <= sizeof(hash_key))
2027                 hash_key_size = dev_info.hash_key_size;
2028         else {
2029                 printf("dev_info did not provide a valid hash key size\n");
2030                 return;
2031         }
2032         /* Check the length of the RSS hash key */
2033         key_len = strlen(res->key);
2034         if (key_len != (hash_key_size * 2)) {
2035                 printf("key length: %d invalid - key must be a string of %d"
2036                            " hexa-decimal numbers\n",
2037                            (int) key_len, hash_key_size * 2);
2038                 return;
2039         }
2040         /* Translate RSS hash key into binary representation */
2041         for (i = 0; i < hash_key_size; i++) {
2042                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2043                 if (xdgt0 == 0xFF)
2044                         return;
2045                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2046                 if (xdgt1 == 0xFF)
2047                         return;
2048                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2049         }
2050         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2051                         hash_key_size);
2052 }
2053
2054 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2055         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2056 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2058                                  "config");
2059 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2060         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2061 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2062         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2063                                  rss_hash_key, "rss-hash-key");
2064 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2066                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2067                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2068                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2069                                  "ipv6-tcp-ex#ipv6-udp-ex");
2070 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2072
2073 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2074         .f = cmd_config_rss_hash_key_parsed,
2075         .data = NULL,
2076         .help_str = "port config <port_id> rss-hash-key "
2077                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2078                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2079                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2080                 "<string of hex digits (variable length, NIC dependent)>",
2081         .tokens = {
2082                 (void *)&cmd_config_rss_hash_key_port,
2083                 (void *)&cmd_config_rss_hash_key_config,
2084                 (void *)&cmd_config_rss_hash_key_port_id,
2085                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2086                 (void *)&cmd_config_rss_hash_key_rss_type,
2087                 (void *)&cmd_config_rss_hash_key_value,
2088                 NULL,
2089         },
2090 };
2091
2092 /* *** configure port rxq/txq start/stop *** */
2093 struct cmd_config_rxtx_queue {
2094         cmdline_fixed_string_t port;
2095         portid_t portid;
2096         cmdline_fixed_string_t rxtxq;
2097         uint16_t qid;
2098         cmdline_fixed_string_t opname;
2099 };
2100
2101 static void
2102 cmd_config_rxtx_queue_parsed(void *parsed_result,
2103                         __attribute__((unused)) struct cmdline *cl,
2104                         __attribute__((unused)) void *data)
2105 {
2106         struct cmd_config_rxtx_queue *res = parsed_result;
2107         uint8_t isrx;
2108         uint8_t isstart;
2109         int ret = 0;
2110
2111         if (test_done == 0) {
2112                 printf("Please stop forwarding first\n");
2113                 return;
2114         }
2115
2116         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2117                 return;
2118
2119         if (port_is_started(res->portid) != 1) {
2120                 printf("Please start port %u first\n", res->portid);
2121                 return;
2122         }
2123
2124         if (!strcmp(res->rxtxq, "rxq"))
2125                 isrx = 1;
2126         else if (!strcmp(res->rxtxq, "txq"))
2127                 isrx = 0;
2128         else {
2129                 printf("Unknown parameter\n");
2130                 return;
2131         }
2132
2133         if (isrx && rx_queue_id_is_invalid(res->qid))
2134                 return;
2135         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2136                 return;
2137
2138         if (!strcmp(res->opname, "start"))
2139                 isstart = 1;
2140         else if (!strcmp(res->opname, "stop"))
2141                 isstart = 0;
2142         else {
2143                 printf("Unknown parameter\n");
2144                 return;
2145         }
2146
2147         if (isstart && isrx)
2148                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2149         else if (!isstart && isrx)
2150                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2151         else if (isstart && !isrx)
2152                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2153         else
2154                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2155
2156         if (ret == -ENOTSUP)
2157                 printf("Function not supported in PMD driver\n");
2158 }
2159
2160 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2162 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2163         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2164 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2165         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2166 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2167         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2168 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2170                                                 "start#stop");
2171
2172 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2173         .f = cmd_config_rxtx_queue_parsed,
2174         .data = NULL,
2175         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2176         .tokens = {
2177                 (void *)&cmd_config_speed_all_port,
2178                 (void *)&cmd_config_rxtx_queue_portid,
2179                 (void *)&cmd_config_rxtx_queue_rxtxq,
2180                 (void *)&cmd_config_rxtx_queue_qid,
2181                 (void *)&cmd_config_rxtx_queue_opname,
2182                 NULL,
2183         },
2184 };
2185
2186 /* *** Configure RSS RETA *** */
2187 struct cmd_config_rss_reta {
2188         cmdline_fixed_string_t port;
2189         cmdline_fixed_string_t keyword;
2190         portid_t port_id;
2191         cmdline_fixed_string_t name;
2192         cmdline_fixed_string_t list_name;
2193         cmdline_fixed_string_t list_of_items;
2194 };
2195
2196 static int
2197 parse_reta_config(const char *str,
2198                   struct rte_eth_rss_reta_entry64 *reta_conf,
2199                   uint16_t nb_entries)
2200 {
2201         int i;
2202         unsigned size;
2203         uint16_t hash_index, idx, shift;
2204         uint16_t nb_queue;
2205         char s[256];
2206         const char *p, *p0 = str;
2207         char *end;
2208         enum fieldnames {
2209                 FLD_HASH_INDEX = 0,
2210                 FLD_QUEUE,
2211                 _NUM_FLD
2212         };
2213         unsigned long int_fld[_NUM_FLD];
2214         char *str_fld[_NUM_FLD];
2215
2216         while ((p = strchr(p0,'(')) != NULL) {
2217                 ++p;
2218                 if((p0 = strchr(p,')')) == NULL)
2219                         return -1;
2220
2221                 size = p0 - p;
2222                 if(size >= sizeof(s))
2223                         return -1;
2224
2225                 snprintf(s, sizeof(s), "%.*s", size, p);
2226                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2227                         return -1;
2228                 for (i = 0; i < _NUM_FLD; i++) {
2229                         errno = 0;
2230                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2231                         if (errno != 0 || end == str_fld[i] ||
2232                                         int_fld[i] > 65535)
2233                                 return -1;
2234                 }
2235
2236                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2237                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2238
2239                 if (hash_index >= nb_entries) {
2240                         printf("Invalid RETA hash index=%d\n", hash_index);
2241                         return -1;
2242                 }
2243
2244                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2245                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2246                 reta_conf[idx].mask |= (1ULL << shift);
2247                 reta_conf[idx].reta[shift] = nb_queue;
2248         }
2249
2250         return 0;
2251 }
2252
2253 static void
2254 cmd_set_rss_reta_parsed(void *parsed_result,
2255                         __attribute__((unused)) struct cmdline *cl,
2256                         __attribute__((unused)) void *data)
2257 {
2258         int ret;
2259         struct rte_eth_dev_info dev_info;
2260         struct rte_eth_rss_reta_entry64 reta_conf[8];
2261         struct cmd_config_rss_reta *res = parsed_result;
2262
2263         memset(&dev_info, 0, sizeof(dev_info));
2264         rte_eth_dev_info_get(res->port_id, &dev_info);
2265         if (dev_info.reta_size == 0) {
2266                 printf("Redirection table size is 0 which is "
2267                                         "invalid for RSS\n");
2268                 return;
2269         } else
2270                 printf("The reta size of port %d is %u\n",
2271                         res->port_id, dev_info.reta_size);
2272         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2273                 printf("Currently do not support more than %u entries of "
2274                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2275                 return;
2276         }
2277
2278         memset(reta_conf, 0, sizeof(reta_conf));
2279         if (!strcmp(res->list_name, "reta")) {
2280                 if (parse_reta_config(res->list_of_items, reta_conf,
2281                                                 dev_info.reta_size)) {
2282                         printf("Invalid RSS Redirection Table "
2283                                         "config entered\n");
2284                         return;
2285                 }
2286                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2287                                 reta_conf, dev_info.reta_size);
2288                 if (ret != 0)
2289                         printf("Bad redirection table parameter, "
2290                                         "return code = %d \n", ret);
2291         }
2292 }
2293
2294 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2296 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2298 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2299         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2300 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2302 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2304 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2306                                  NULL);
2307 cmdline_parse_inst_t cmd_config_rss_reta = {
2308         .f = cmd_set_rss_reta_parsed,
2309         .data = NULL,
2310         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2311         .tokens = {
2312                 (void *)&cmd_config_rss_reta_port,
2313                 (void *)&cmd_config_rss_reta_keyword,
2314                 (void *)&cmd_config_rss_reta_port_id,
2315                 (void *)&cmd_config_rss_reta_name,
2316                 (void *)&cmd_config_rss_reta_list_name,
2317                 (void *)&cmd_config_rss_reta_list_of_items,
2318                 NULL,
2319         },
2320 };
2321
2322 /* *** SHOW PORT RETA INFO *** */
2323 struct cmd_showport_reta {
2324         cmdline_fixed_string_t show;
2325         cmdline_fixed_string_t port;
2326         portid_t port_id;
2327         cmdline_fixed_string_t rss;
2328         cmdline_fixed_string_t reta;
2329         uint16_t size;
2330         cmdline_fixed_string_t list_of_items;
2331 };
2332
2333 static int
2334 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2335                            uint16_t nb_entries,
2336                            char *str)
2337 {
2338         uint32_t size;
2339         const char *p, *p0 = str;
2340         char s[256];
2341         char *end;
2342         char *str_fld[8];
2343         uint16_t i;
2344         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2345                         RTE_RETA_GROUP_SIZE;
2346         int ret;
2347
2348         p = strchr(p0, '(');
2349         if (p == NULL)
2350                 return -1;
2351         p++;
2352         p0 = strchr(p, ')');
2353         if (p0 == NULL)
2354                 return -1;
2355         size = p0 - p;
2356         if (size >= sizeof(s)) {
2357                 printf("The string size exceeds the internal buffer size\n");
2358                 return -1;
2359         }
2360         snprintf(s, sizeof(s), "%.*s", size, p);
2361         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2362         if (ret <= 0 || ret != num) {
2363                 printf("The bits of masks do not match the number of "
2364                                         "reta entries: %u\n", num);
2365                 return -1;
2366         }
2367         for (i = 0; i < ret; i++)
2368                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2369
2370         return 0;
2371 }
2372
2373 static void
2374 cmd_showport_reta_parsed(void *parsed_result,
2375                          __attribute__((unused)) struct cmdline *cl,
2376                          __attribute__((unused)) void *data)
2377 {
2378         struct cmd_showport_reta *res = parsed_result;
2379         struct rte_eth_rss_reta_entry64 reta_conf[8];
2380         struct rte_eth_dev_info dev_info;
2381         uint16_t max_reta_size;
2382
2383         memset(&dev_info, 0, sizeof(dev_info));
2384         rte_eth_dev_info_get(res->port_id, &dev_info);
2385         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2386         if (res->size == 0 || res->size > max_reta_size) {
2387                 printf("Invalid redirection table size: %u (1-%u)\n",
2388                         res->size, max_reta_size);
2389                 return;
2390         }
2391
2392         memset(reta_conf, 0, sizeof(reta_conf));
2393         if (showport_parse_reta_config(reta_conf, res->size,
2394                                 res->list_of_items) < 0) {
2395                 printf("Invalid string: %s for reta masks\n",
2396                                         res->list_of_items);
2397                 return;
2398         }
2399         port_rss_reta_info(res->port_id, reta_conf, res->size);
2400 }
2401
2402 cmdline_parse_token_string_t cmd_showport_reta_show =
2403         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2404 cmdline_parse_token_string_t cmd_showport_reta_port =
2405         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2406 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2407         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2408 cmdline_parse_token_string_t cmd_showport_reta_rss =
2409         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2410 cmdline_parse_token_string_t cmd_showport_reta_reta =
2411         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2412 cmdline_parse_token_num_t cmd_showport_reta_size =
2413         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2414 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2415         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2416                                         list_of_items, NULL);
2417
2418 cmdline_parse_inst_t cmd_showport_reta = {
2419         .f = cmd_showport_reta_parsed,
2420         .data = NULL,
2421         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2422         .tokens = {
2423                 (void *)&cmd_showport_reta_show,
2424                 (void *)&cmd_showport_reta_port,
2425                 (void *)&cmd_showport_reta_port_id,
2426                 (void *)&cmd_showport_reta_rss,
2427                 (void *)&cmd_showport_reta_reta,
2428                 (void *)&cmd_showport_reta_size,
2429                 (void *)&cmd_showport_reta_list_of_items,
2430                 NULL,
2431         },
2432 };
2433
2434 /* *** Show RSS hash configuration *** */
2435 struct cmd_showport_rss_hash {
2436         cmdline_fixed_string_t show;
2437         cmdline_fixed_string_t port;
2438         portid_t port_id;
2439         cmdline_fixed_string_t rss_hash;
2440         cmdline_fixed_string_t rss_type;
2441         cmdline_fixed_string_t key; /* optional argument */
2442 };
2443
2444 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2445                                 __attribute__((unused)) struct cmdline *cl,
2446                                 void *show_rss_key)
2447 {
2448         struct cmd_showport_rss_hash *res = parsed_result;
2449
2450         port_rss_hash_conf_show(res->port_id, res->rss_type,
2451                                 show_rss_key != NULL);
2452 }
2453
2454 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2455         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2456 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2457         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2458 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2459         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2460 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2461         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2462                                  "rss-hash");
2463 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2464         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2465                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2466                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2467                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2468                                  "ipv6-tcp-ex#ipv6-udp-ex");
2469 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2470         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2471
2472 cmdline_parse_inst_t cmd_showport_rss_hash = {
2473         .f = cmd_showport_rss_hash_parsed,
2474         .data = NULL,
2475         .help_str = "show port <port_id> rss-hash "
2476                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2477                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2478                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2479         .tokens = {
2480                 (void *)&cmd_showport_rss_hash_show,
2481                 (void *)&cmd_showport_rss_hash_port,
2482                 (void *)&cmd_showport_rss_hash_port_id,
2483                 (void *)&cmd_showport_rss_hash_rss_hash,
2484                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2485                 NULL,
2486         },
2487 };
2488
2489 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2490         .f = cmd_showport_rss_hash_parsed,
2491         .data = (void *)1,
2492         .help_str = "show port <port_id> rss-hash "
2493                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2494                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2495                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2496         .tokens = {
2497                 (void *)&cmd_showport_rss_hash_show,
2498                 (void *)&cmd_showport_rss_hash_port,
2499                 (void *)&cmd_showport_rss_hash_port_id,
2500                 (void *)&cmd_showport_rss_hash_rss_hash,
2501                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2502                 (void *)&cmd_showport_rss_hash_rss_key,
2503                 NULL,
2504         },
2505 };
2506
2507 /* *** Configure DCB *** */
2508 struct cmd_config_dcb {
2509         cmdline_fixed_string_t port;
2510         cmdline_fixed_string_t config;
2511         portid_t port_id;
2512         cmdline_fixed_string_t dcb;
2513         cmdline_fixed_string_t vt;
2514         cmdline_fixed_string_t vt_en;
2515         uint8_t num_tcs;
2516         cmdline_fixed_string_t pfc;
2517         cmdline_fixed_string_t pfc_en;
2518 };
2519
2520 static void
2521 cmd_config_dcb_parsed(void *parsed_result,
2522                         __attribute__((unused)) struct cmdline *cl,
2523                         __attribute__((unused)) void *data)
2524 {
2525         struct cmd_config_dcb *res = parsed_result;
2526         portid_t port_id = res->port_id;
2527         struct rte_port *port;
2528         uint8_t pfc_en;
2529         int ret;
2530
2531         port = &ports[port_id];
2532         /** Check if the port is not started **/
2533         if (port->port_status != RTE_PORT_STOPPED) {
2534                 printf("Please stop port %d first\n", port_id);
2535                 return;
2536         }
2537
2538         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2539                 printf("The invalid number of traffic class,"
2540                         " only 4 or 8 allowed.\n");
2541                 return;
2542         }
2543
2544         if (nb_fwd_lcores < res->num_tcs) {
2545                 printf("nb_cores shouldn't be less than number of TCs.\n");
2546                 return;
2547         }
2548         if (!strncmp(res->pfc_en, "on", 2))
2549                 pfc_en = 1;
2550         else
2551                 pfc_en = 0;
2552
2553         /* DCB in VT mode */
2554         if (!strncmp(res->vt_en, "on", 2))
2555                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2556                                 (enum rte_eth_nb_tcs)res->num_tcs,
2557                                 pfc_en);
2558         else
2559                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2560                                 (enum rte_eth_nb_tcs)res->num_tcs,
2561                                 pfc_en);
2562
2563
2564         if (ret != 0) {
2565                 printf("Cannot initialize network ports.\n");
2566                 return;
2567         }
2568
2569         cmd_reconfig_device_queue(port_id, 1, 1);
2570 }
2571
2572 cmdline_parse_token_string_t cmd_config_dcb_port =
2573         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2574 cmdline_parse_token_string_t cmd_config_dcb_config =
2575         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2576 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2577         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2578 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2579         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2580 cmdline_parse_token_string_t cmd_config_dcb_vt =
2581         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2582 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2584 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2585         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2586 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2587         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2588 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2589         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2590
2591 cmdline_parse_inst_t cmd_config_dcb = {
2592         .f = cmd_config_dcb_parsed,
2593         .data = NULL,
2594         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2595         .tokens = {
2596                 (void *)&cmd_config_dcb_port,
2597                 (void *)&cmd_config_dcb_config,
2598                 (void *)&cmd_config_dcb_port_id,
2599                 (void *)&cmd_config_dcb_dcb,
2600                 (void *)&cmd_config_dcb_vt,
2601                 (void *)&cmd_config_dcb_vt_en,
2602                 (void *)&cmd_config_dcb_num_tcs,
2603                 (void *)&cmd_config_dcb_pfc,
2604                 (void *)&cmd_config_dcb_pfc_en,
2605                 NULL,
2606         },
2607 };
2608
2609 /* *** configure number of packets per burst *** */
2610 struct cmd_config_burst {
2611         cmdline_fixed_string_t port;
2612         cmdline_fixed_string_t keyword;
2613         cmdline_fixed_string_t all;
2614         cmdline_fixed_string_t name;
2615         uint16_t value;
2616 };
2617
2618 static void
2619 cmd_config_burst_parsed(void *parsed_result,
2620                         __attribute__((unused)) struct cmdline *cl,
2621                         __attribute__((unused)) void *data)
2622 {
2623         struct cmd_config_burst *res = parsed_result;
2624
2625         if (!all_ports_stopped()) {
2626                 printf("Please stop all ports first\n");
2627                 return;
2628         }
2629
2630         if (!strcmp(res->name, "burst")) {
2631                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2632                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2633                         return;
2634                 }
2635                 nb_pkt_per_burst = res->value;
2636         } else {
2637                 printf("Unknown parameter\n");
2638                 return;
2639         }
2640
2641         init_port_config();
2642
2643         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2644 }
2645
2646 cmdline_parse_token_string_t cmd_config_burst_port =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2648 cmdline_parse_token_string_t cmd_config_burst_keyword =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2650 cmdline_parse_token_string_t cmd_config_burst_all =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2652 cmdline_parse_token_string_t cmd_config_burst_name =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2654 cmdline_parse_token_num_t cmd_config_burst_value =
2655         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2656
2657 cmdline_parse_inst_t cmd_config_burst = {
2658         .f = cmd_config_burst_parsed,
2659         .data = NULL,
2660         .help_str = "port config all burst <value>",
2661         .tokens = {
2662                 (void *)&cmd_config_burst_port,
2663                 (void *)&cmd_config_burst_keyword,
2664                 (void *)&cmd_config_burst_all,
2665                 (void *)&cmd_config_burst_name,
2666                 (void *)&cmd_config_burst_value,
2667                 NULL,
2668         },
2669 };
2670
2671 /* *** configure rx/tx queues *** */
2672 struct cmd_config_thresh {
2673         cmdline_fixed_string_t port;
2674         cmdline_fixed_string_t keyword;
2675         cmdline_fixed_string_t all;
2676         cmdline_fixed_string_t name;
2677         uint8_t value;
2678 };
2679
2680 static void
2681 cmd_config_thresh_parsed(void *parsed_result,
2682                         __attribute__((unused)) struct cmdline *cl,
2683                         __attribute__((unused)) void *data)
2684 {
2685         struct cmd_config_thresh *res = parsed_result;
2686
2687         if (!all_ports_stopped()) {
2688                 printf("Please stop all ports first\n");
2689                 return;
2690         }
2691
2692         if (!strcmp(res->name, "txpt"))
2693                 tx_pthresh = res->value;
2694         else if(!strcmp(res->name, "txht"))
2695                 tx_hthresh = res->value;
2696         else if(!strcmp(res->name, "txwt"))
2697                 tx_wthresh = res->value;
2698         else if(!strcmp(res->name, "rxpt"))
2699                 rx_pthresh = res->value;
2700         else if(!strcmp(res->name, "rxht"))
2701                 rx_hthresh = res->value;
2702         else if(!strcmp(res->name, "rxwt"))
2703                 rx_wthresh = res->value;
2704         else {
2705                 printf("Unknown parameter\n");
2706                 return;
2707         }
2708
2709         init_port_config();
2710
2711         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2712 }
2713
2714 cmdline_parse_token_string_t cmd_config_thresh_port =
2715         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2716 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2717         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2718 cmdline_parse_token_string_t cmd_config_thresh_all =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2720 cmdline_parse_token_string_t cmd_config_thresh_name =
2721         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2722                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2723 cmdline_parse_token_num_t cmd_config_thresh_value =
2724         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2725
2726 cmdline_parse_inst_t cmd_config_thresh = {
2727         .f = cmd_config_thresh_parsed,
2728         .data = NULL,
2729         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2730         .tokens = {
2731                 (void *)&cmd_config_thresh_port,
2732                 (void *)&cmd_config_thresh_keyword,
2733                 (void *)&cmd_config_thresh_all,
2734                 (void *)&cmd_config_thresh_name,
2735                 (void *)&cmd_config_thresh_value,
2736                 NULL,
2737         },
2738 };
2739
2740 /* *** configure free/rs threshold *** */
2741 struct cmd_config_threshold {
2742         cmdline_fixed_string_t port;
2743         cmdline_fixed_string_t keyword;
2744         cmdline_fixed_string_t all;
2745         cmdline_fixed_string_t name;
2746         uint16_t value;
2747 };
2748
2749 static void
2750 cmd_config_threshold_parsed(void *parsed_result,
2751                         __attribute__((unused)) struct cmdline *cl,
2752                         __attribute__((unused)) void *data)
2753 {
2754         struct cmd_config_threshold *res = parsed_result;
2755
2756         if (!all_ports_stopped()) {
2757                 printf("Please stop all ports first\n");
2758                 return;
2759         }
2760
2761         if (!strcmp(res->name, "txfreet"))
2762                 tx_free_thresh = res->value;
2763         else if (!strcmp(res->name, "txrst"))
2764                 tx_rs_thresh = res->value;
2765         else if (!strcmp(res->name, "rxfreet"))
2766                 rx_free_thresh = res->value;
2767         else {
2768                 printf("Unknown parameter\n");
2769                 return;
2770         }
2771
2772         init_port_config();
2773
2774         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2775 }
2776
2777 cmdline_parse_token_string_t cmd_config_threshold_port =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2779 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2780         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2781                                                                 "config");
2782 cmdline_parse_token_string_t cmd_config_threshold_all =
2783         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2784 cmdline_parse_token_string_t cmd_config_threshold_name =
2785         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2786                                                 "txfreet#txrst#rxfreet");
2787 cmdline_parse_token_num_t cmd_config_threshold_value =
2788         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2789
2790 cmdline_parse_inst_t cmd_config_threshold = {
2791         .f = cmd_config_threshold_parsed,
2792         .data = NULL,
2793         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2794         .tokens = {
2795                 (void *)&cmd_config_threshold_port,
2796                 (void *)&cmd_config_threshold_keyword,
2797                 (void *)&cmd_config_threshold_all,
2798                 (void *)&cmd_config_threshold_name,
2799                 (void *)&cmd_config_threshold_value,
2800                 NULL,
2801         },
2802 };
2803
2804 /* *** stop *** */
2805 struct cmd_stop_result {
2806         cmdline_fixed_string_t stop;
2807 };
2808
2809 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2810                             __attribute__((unused)) struct cmdline *cl,
2811                             __attribute__((unused)) void *data)
2812 {
2813         stop_packet_forwarding();
2814 }
2815
2816 cmdline_parse_token_string_t cmd_stop_stop =
2817         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2818
2819 cmdline_parse_inst_t cmd_stop = {
2820         .f = cmd_stop_parsed,
2821         .data = NULL,
2822         .help_str = "stop: Stop packet forwarding",
2823         .tokens = {
2824                 (void *)&cmd_stop_stop,
2825                 NULL,
2826         },
2827 };
2828
2829 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2830
2831 unsigned int
2832 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2833                 unsigned int *parsed_items, int check_unique_values)
2834 {
2835         unsigned int nb_item;
2836         unsigned int value;
2837         unsigned int i;
2838         unsigned int j;
2839         int value_ok;
2840         char c;
2841
2842         /*
2843          * First parse all items in the list and store their value.
2844          */
2845         value = 0;
2846         nb_item = 0;
2847         value_ok = 0;
2848         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2849                 c = str[i];
2850                 if ((c >= '0') && (c <= '9')) {
2851                         value = (unsigned int) (value * 10 + (c - '0'));
2852                         value_ok = 1;
2853                         continue;
2854                 }
2855                 if (c != ',') {
2856                         printf("character %c is not a decimal digit\n", c);
2857                         return 0;
2858                 }
2859                 if (! value_ok) {
2860                         printf("No valid value before comma\n");
2861                         return 0;
2862                 }
2863                 if (nb_item < max_items) {
2864                         parsed_items[nb_item] = value;
2865                         value_ok = 0;
2866                         value = 0;
2867                 }
2868                 nb_item++;
2869         }
2870         if (nb_item >= max_items) {
2871                 printf("Number of %s = %u > %u (maximum items)\n",
2872                        item_name, nb_item + 1, max_items);
2873                 return 0;
2874         }
2875         parsed_items[nb_item++] = value;
2876         if (! check_unique_values)
2877                 return nb_item;
2878
2879         /*
2880          * Then, check that all values in the list are differents.
2881          * No optimization here...
2882          */
2883         for (i = 0; i < nb_item; i++) {
2884                 for (j = i + 1; j < nb_item; j++) {
2885                         if (parsed_items[j] == parsed_items[i]) {
2886                                 printf("duplicated %s %u at index %u and %u\n",
2887                                        item_name, parsed_items[i], i, j);
2888                                 return 0;
2889                         }
2890                 }
2891         }
2892         return nb_item;
2893 }
2894
2895 struct cmd_set_list_result {
2896         cmdline_fixed_string_t cmd_keyword;
2897         cmdline_fixed_string_t list_name;
2898         cmdline_fixed_string_t list_of_items;
2899 };
2900
2901 static void cmd_set_list_parsed(void *parsed_result,
2902                                 __attribute__((unused)) struct cmdline *cl,
2903                                 __attribute__((unused)) void *data)
2904 {
2905         struct cmd_set_list_result *res;
2906         union {
2907                 unsigned int lcorelist[RTE_MAX_LCORE];
2908                 unsigned int portlist[RTE_MAX_ETHPORTS];
2909         } parsed_items;
2910         unsigned int nb_item;
2911
2912         if (test_done == 0) {
2913                 printf("Please stop forwarding first\n");
2914                 return;
2915         }
2916
2917         res = parsed_result;
2918         if (!strcmp(res->list_name, "corelist")) {
2919                 nb_item = parse_item_list(res->list_of_items, "core",
2920                                           RTE_MAX_LCORE,
2921                                           parsed_items.lcorelist, 1);
2922                 if (nb_item > 0) {
2923                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2924                         fwd_config_setup();
2925                 }
2926                 return;
2927         }
2928         if (!strcmp(res->list_name, "portlist")) {
2929                 nb_item = parse_item_list(res->list_of_items, "port",
2930                                           RTE_MAX_ETHPORTS,
2931                                           parsed_items.portlist, 1);
2932                 if (nb_item > 0) {
2933                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2934                         fwd_config_setup();
2935                 }
2936         }
2937 }
2938
2939 cmdline_parse_token_string_t cmd_set_list_keyword =
2940         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2941                                  "set");
2942 cmdline_parse_token_string_t cmd_set_list_name =
2943         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2944                                  "corelist#portlist");
2945 cmdline_parse_token_string_t cmd_set_list_of_items =
2946         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2947                                  NULL);
2948
2949 cmdline_parse_inst_t cmd_set_fwd_list = {
2950         .f = cmd_set_list_parsed,
2951         .data = NULL,
2952         .help_str = "set corelist|portlist <list0[,list1]*>",
2953         .tokens = {
2954                 (void *)&cmd_set_list_keyword,
2955                 (void *)&cmd_set_list_name,
2956                 (void *)&cmd_set_list_of_items,
2957                 NULL,
2958         },
2959 };
2960
2961 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2962
2963 struct cmd_setmask_result {
2964         cmdline_fixed_string_t set;
2965         cmdline_fixed_string_t mask;
2966         uint64_t hexavalue;
2967 };
2968
2969 static void cmd_set_mask_parsed(void *parsed_result,
2970                                 __attribute__((unused)) struct cmdline *cl,
2971                                 __attribute__((unused)) void *data)
2972 {
2973         struct cmd_setmask_result *res = parsed_result;
2974
2975         if (test_done == 0) {
2976                 printf("Please stop forwarding first\n");
2977                 return;
2978         }
2979         if (!strcmp(res->mask, "coremask")) {
2980                 set_fwd_lcores_mask(res->hexavalue);
2981                 fwd_config_setup();
2982         } else if (!strcmp(res->mask, "portmask")) {
2983                 set_fwd_ports_mask(res->hexavalue);
2984                 fwd_config_setup();
2985         }
2986 }
2987
2988 cmdline_parse_token_string_t cmd_setmask_set =
2989         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2990 cmdline_parse_token_string_t cmd_setmask_mask =
2991         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2992                                  "coremask#portmask");
2993 cmdline_parse_token_num_t cmd_setmask_value =
2994         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2995
2996 cmdline_parse_inst_t cmd_set_fwd_mask = {
2997         .f = cmd_set_mask_parsed,
2998         .data = NULL,
2999         .help_str = "set coremask|portmask <hexadecimal value>",
3000         .tokens = {
3001                 (void *)&cmd_setmask_set,
3002                 (void *)&cmd_setmask_mask,
3003                 (void *)&cmd_setmask_value,
3004                 NULL,
3005         },
3006 };
3007
3008 /*
3009  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3010  */
3011 struct cmd_set_result {
3012         cmdline_fixed_string_t set;
3013         cmdline_fixed_string_t what;
3014         uint16_t value;
3015 };
3016
3017 static void cmd_set_parsed(void *parsed_result,
3018                            __attribute__((unused)) struct cmdline *cl,
3019                            __attribute__((unused)) void *data)
3020 {
3021         struct cmd_set_result *res = parsed_result;
3022         if (!strcmp(res->what, "nbport")) {
3023                 set_fwd_ports_number(res->value);
3024                 fwd_config_setup();
3025         } else if (!strcmp(res->what, "nbcore")) {
3026                 set_fwd_lcores_number(res->value);
3027                 fwd_config_setup();
3028         } else if (!strcmp(res->what, "burst"))
3029                 set_nb_pkt_per_burst(res->value);
3030         else if (!strcmp(res->what, "verbose"))
3031                 set_verbose_level(res->value);
3032 }
3033
3034 cmdline_parse_token_string_t cmd_set_set =
3035         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3036 cmdline_parse_token_string_t cmd_set_what =
3037         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3038                                  "nbport#nbcore#burst#verbose");
3039 cmdline_parse_token_num_t cmd_set_value =
3040         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3041
3042 cmdline_parse_inst_t cmd_set_numbers = {
3043         .f = cmd_set_parsed,
3044         .data = NULL,
3045         .help_str = "set nbport|nbcore|burst|verbose <value>",
3046         .tokens = {
3047                 (void *)&cmd_set_set,
3048                 (void *)&cmd_set_what,
3049                 (void *)&cmd_set_value,
3050                 NULL,
3051         },
3052 };
3053
3054 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3055
3056 struct cmd_set_txpkts_result {
3057         cmdline_fixed_string_t cmd_keyword;
3058         cmdline_fixed_string_t txpkts;
3059         cmdline_fixed_string_t seg_lengths;
3060 };
3061
3062 static void
3063 cmd_set_txpkts_parsed(void *parsed_result,
3064                       __attribute__((unused)) struct cmdline *cl,
3065                       __attribute__((unused)) void *data)
3066 {
3067         struct cmd_set_txpkts_result *res;
3068         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3069         unsigned int nb_segs;
3070
3071         res = parsed_result;
3072         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3073                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3074         if (nb_segs > 0)
3075                 set_tx_pkt_segments(seg_lengths, nb_segs);
3076 }
3077
3078 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3079         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3080                                  cmd_keyword, "set");
3081 cmdline_parse_token_string_t cmd_set_txpkts_name =
3082         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3083                                  txpkts, "txpkts");
3084 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3085         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3086                                  seg_lengths, NULL);
3087
3088 cmdline_parse_inst_t cmd_set_txpkts = {
3089         .f = cmd_set_txpkts_parsed,
3090         .data = NULL,
3091         .help_str = "set txpkts <len0[,len1]*>",
3092         .tokens = {
3093                 (void *)&cmd_set_txpkts_keyword,
3094                 (void *)&cmd_set_txpkts_name,
3095                 (void *)&cmd_set_txpkts_lengths,
3096                 NULL,
3097         },
3098 };
3099
3100 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3101
3102 struct cmd_set_txsplit_result {
3103         cmdline_fixed_string_t cmd_keyword;
3104         cmdline_fixed_string_t txsplit;
3105         cmdline_fixed_string_t mode;
3106 };
3107
3108 static void
3109 cmd_set_txsplit_parsed(void *parsed_result,
3110                       __attribute__((unused)) struct cmdline *cl,
3111                       __attribute__((unused)) void *data)
3112 {
3113         struct cmd_set_txsplit_result *res;
3114
3115         res = parsed_result;
3116         set_tx_pkt_split(res->mode);
3117 }
3118
3119 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3120         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3121                                  cmd_keyword, "set");
3122 cmdline_parse_token_string_t cmd_set_txsplit_name =
3123         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3124                                  txsplit, "txsplit");
3125 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3126         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3127                                  mode, NULL);
3128
3129 cmdline_parse_inst_t cmd_set_txsplit = {
3130         .f = cmd_set_txsplit_parsed,
3131         .data = NULL,
3132         .help_str = "set txsplit on|off|rand",
3133         .tokens = {
3134                 (void *)&cmd_set_txsplit_keyword,
3135                 (void *)&cmd_set_txsplit_name,
3136                 (void *)&cmd_set_txsplit_mode,
3137                 NULL,
3138         },
3139 };
3140
3141 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3142 struct cmd_rx_vlan_filter_all_result {
3143         cmdline_fixed_string_t rx_vlan;
3144         cmdline_fixed_string_t what;
3145         cmdline_fixed_string_t all;
3146         portid_t port_id;
3147 };
3148
3149 static void
3150 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3151                               __attribute__((unused)) struct cmdline *cl,
3152                               __attribute__((unused)) void *data)
3153 {
3154         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3155
3156         if (!strcmp(res->what, "add"))
3157                 rx_vlan_all_filter_set(res->port_id, 1);
3158         else
3159                 rx_vlan_all_filter_set(res->port_id, 0);
3160 }
3161
3162 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3163         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3164                                  rx_vlan, "rx_vlan");
3165 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3166         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3167                                  what, "add#rm");
3168 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3169         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3170                                  all, "all");
3171 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3172         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3173                               port_id, UINT16);
3174
3175 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3176         .f = cmd_rx_vlan_filter_all_parsed,
3177         .data = NULL,
3178         .help_str = "rx_vlan add|rm all <port_id>: "
3179                 "Add/Remove all identifiers to/from the set of VLAN "
3180                 "identifiers filtered by a port",
3181         .tokens = {
3182                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3183                 (void *)&cmd_rx_vlan_filter_all_what,
3184                 (void *)&cmd_rx_vlan_filter_all_all,
3185                 (void *)&cmd_rx_vlan_filter_all_portid,
3186                 NULL,
3187         },
3188 };
3189
3190 /* *** VLAN OFFLOAD SET ON A PORT *** */
3191 struct cmd_vlan_offload_result {
3192         cmdline_fixed_string_t vlan;
3193         cmdline_fixed_string_t set;
3194         cmdline_fixed_string_t vlan_type;
3195         cmdline_fixed_string_t what;
3196         cmdline_fixed_string_t on;
3197         cmdline_fixed_string_t port_id;
3198 };
3199
3200 static void
3201 cmd_vlan_offload_parsed(void *parsed_result,
3202                           __attribute__((unused)) struct cmdline *cl,
3203                           __attribute__((unused)) void *data)
3204 {
3205         int on;
3206         struct cmd_vlan_offload_result *res = parsed_result;
3207         char *str;
3208         int i, len = 0;
3209         portid_t port_id = 0;
3210         unsigned int tmp;
3211
3212         str = res->port_id;
3213         len = strnlen(str, STR_TOKEN_SIZE);
3214         i = 0;
3215         /* Get port_id first */
3216         while(i < len){
3217                 if(str[i] == ',')
3218                         break;
3219
3220                 i++;
3221         }
3222         str[i]='\0';
3223         tmp = strtoul(str, NULL, 0);
3224         /* If port_id greater that what portid_t can represent, return */
3225         if(tmp >= RTE_MAX_ETHPORTS)
3226                 return;
3227         port_id = (portid_t)tmp;
3228
3229         if (!strcmp(res->on, "on"))
3230                 on = 1;
3231         else
3232                 on = 0;
3233
3234         if (!strcmp(res->what, "strip"))
3235                 rx_vlan_strip_set(port_id,  on);
3236         else if(!strcmp(res->what, "stripq")){
3237                 uint16_t queue_id = 0;
3238
3239                 /* No queue_id, return */
3240                 if(i + 1 >= len) {
3241                         printf("must specify (port,queue_id)\n");
3242                         return;
3243                 }
3244                 tmp = strtoul(str + i + 1, NULL, 0);
3245                 /* If queue_id greater that what 16-bits can represent, return */
3246                 if(tmp > 0xffff)
3247                         return;
3248
3249                 queue_id = (uint16_t)tmp;
3250                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3251         }
3252         else if (!strcmp(res->what, "filter"))
3253                 rx_vlan_filter_set(port_id, on);
3254         else
3255                 vlan_extend_set(port_id, on);
3256
3257         return;
3258 }
3259
3260 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3261         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3262                                  vlan, "vlan");
3263 cmdline_parse_token_string_t cmd_vlan_offload_set =
3264         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3265                                  set, "set");
3266 cmdline_parse_token_string_t cmd_vlan_offload_what =
3267         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3268                                  what, "strip#filter#qinq#stripq");
3269 cmdline_parse_token_string_t cmd_vlan_offload_on =
3270         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3271                               on, "on#off");
3272 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3273         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3274                               port_id, NULL);
3275
3276 cmdline_parse_inst_t cmd_vlan_offload = {
3277         .f = cmd_vlan_offload_parsed,
3278         .data = NULL,
3279         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3280                 "<port_id[,queue_id]>: "
3281                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3282         .tokens = {
3283                 (void *)&cmd_vlan_offload_vlan,
3284                 (void *)&cmd_vlan_offload_set,
3285                 (void *)&cmd_vlan_offload_what,
3286                 (void *)&cmd_vlan_offload_on,
3287                 (void *)&cmd_vlan_offload_portid,
3288                 NULL,
3289         },
3290 };
3291
3292 /* *** VLAN TPID SET ON A PORT *** */
3293 struct cmd_vlan_tpid_result {
3294         cmdline_fixed_string_t vlan;
3295         cmdline_fixed_string_t set;
3296         cmdline_fixed_string_t vlan_type;
3297         cmdline_fixed_string_t what;
3298         uint16_t tp_id;
3299         portid_t port_id;
3300 };
3301
3302 static void
3303 cmd_vlan_tpid_parsed(void *parsed_result,
3304                           __attribute__((unused)) struct cmdline *cl,
3305                           __attribute__((unused)) void *data)
3306 {
3307         struct cmd_vlan_tpid_result *res = parsed_result;
3308         enum rte_vlan_type vlan_type;
3309
3310         if (!strcmp(res->vlan_type, "inner"))
3311                 vlan_type = ETH_VLAN_TYPE_INNER;
3312         else if (!strcmp(res->vlan_type, "outer"))
3313                 vlan_type = ETH_VLAN_TYPE_OUTER;
3314         else {
3315                 printf("Unknown vlan type\n");
3316                 return;
3317         }
3318         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3319 }
3320
3321 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3322         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3323                                  vlan, "vlan");
3324 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3325         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3326                                  set, "set");
3327 cmdline_parse_token_string_t cmd_vlan_type =
3328         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3329                                  vlan_type, "inner#outer");
3330 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3331         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3332                                  what, "tpid");
3333 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3334         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3335                               tp_id, UINT16);
3336 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3337         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3338                               port_id, UINT16);
3339
3340 cmdline_parse_inst_t cmd_vlan_tpid = {
3341         .f = cmd_vlan_tpid_parsed,
3342         .data = NULL,
3343         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3344                 "Set the VLAN Ether type",
3345         .tokens = {
3346                 (void *)&cmd_vlan_tpid_vlan,
3347                 (void *)&cmd_vlan_tpid_set,
3348                 (void *)&cmd_vlan_type,
3349                 (void *)&cmd_vlan_tpid_what,
3350                 (void *)&cmd_vlan_tpid_tpid,
3351                 (void *)&cmd_vlan_tpid_portid,
3352                 NULL,
3353         },
3354 };
3355
3356 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3357 struct cmd_rx_vlan_filter_result {
3358         cmdline_fixed_string_t rx_vlan;
3359         cmdline_fixed_string_t what;
3360         uint16_t vlan_id;
3361         portid_t port_id;
3362 };
3363
3364 static void
3365 cmd_rx_vlan_filter_parsed(void *parsed_result,
3366                           __attribute__((unused)) struct cmdline *cl,
3367                           __attribute__((unused)) void *data)
3368 {
3369         struct cmd_rx_vlan_filter_result *res = parsed_result;
3370
3371         if (!strcmp(res->what, "add"))
3372                 rx_vft_set(res->port_id, res->vlan_id, 1);
3373         else
3374                 rx_vft_set(res->port_id, res->vlan_id, 0);
3375 }
3376
3377 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3378         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3379                                  rx_vlan, "rx_vlan");
3380 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3381         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3382                                  what, "add#rm");
3383 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3384         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3385                               vlan_id, UINT16);
3386 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3387         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3388                               port_id, UINT16);
3389
3390 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3391         .f = cmd_rx_vlan_filter_parsed,
3392         .data = NULL,
3393         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3394                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3395                 "identifiers filtered by a port",
3396         .tokens = {
3397                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3398                 (void *)&cmd_rx_vlan_filter_what,
3399                 (void *)&cmd_rx_vlan_filter_vlanid,
3400                 (void *)&cmd_rx_vlan_filter_portid,
3401                 NULL,
3402         },
3403 };
3404
3405 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3406 struct cmd_tx_vlan_set_result {
3407         cmdline_fixed_string_t tx_vlan;
3408         cmdline_fixed_string_t set;
3409         portid_t port_id;
3410         uint16_t vlan_id;
3411 };
3412
3413 static void
3414 cmd_tx_vlan_set_parsed(void *parsed_result,
3415                        __attribute__((unused)) struct cmdline *cl,
3416                        __attribute__((unused)) void *data)
3417 {
3418         struct cmd_tx_vlan_set_result *res = parsed_result;
3419
3420         if (!port_is_stopped(res->port_id)) {
3421                 printf("Please stop port %d first\n", res->port_id);
3422                 return;
3423         }
3424
3425         tx_vlan_set(res->port_id, res->vlan_id);
3426
3427         cmd_reconfig_device_queue(res->port_id, 1, 1);
3428 }
3429
3430 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3431         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3432                                  tx_vlan, "tx_vlan");
3433 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3434         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3435                                  set, "set");
3436 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3437         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3438                               port_id, UINT16);
3439 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3440         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3441                               vlan_id, UINT16);
3442
3443 cmdline_parse_inst_t cmd_tx_vlan_set = {
3444         .f = cmd_tx_vlan_set_parsed,
3445         .data = NULL,
3446         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3447                 "Enable hardware insertion of a single VLAN header "
3448                 "with a given TAG Identifier in packets sent on a port",
3449         .tokens = {
3450                 (void *)&cmd_tx_vlan_set_tx_vlan,
3451                 (void *)&cmd_tx_vlan_set_set,
3452                 (void *)&cmd_tx_vlan_set_portid,
3453                 (void *)&cmd_tx_vlan_set_vlanid,
3454                 NULL,
3455         },
3456 };
3457
3458 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3459 struct cmd_tx_vlan_set_qinq_result {
3460         cmdline_fixed_string_t tx_vlan;
3461         cmdline_fixed_string_t set;
3462         portid_t port_id;
3463         uint16_t vlan_id;
3464         uint16_t vlan_id_outer;
3465 };
3466
3467 static void
3468 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3469                             __attribute__((unused)) struct cmdline *cl,
3470                             __attribute__((unused)) void *data)
3471 {
3472         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3473
3474         if (!port_is_stopped(res->port_id)) {
3475                 printf("Please stop port %d first\n", res->port_id);
3476                 return;
3477         }
3478
3479         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3480
3481         cmd_reconfig_device_queue(res->port_id, 1, 1);
3482 }
3483
3484 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3485         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3486                 tx_vlan, "tx_vlan");
3487 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3488         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3489                 set, "set");
3490 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3491         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3492                 port_id, UINT16);
3493 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3494         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3495                 vlan_id, UINT16);
3496 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3497         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3498                 vlan_id_outer, UINT16);
3499
3500 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3501         .f = cmd_tx_vlan_set_qinq_parsed,
3502         .data = NULL,
3503         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3504                 "Enable hardware insertion of double VLAN header "
3505                 "with given TAG Identifiers in packets sent on a port",
3506         .tokens = {
3507                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3508                 (void *)&cmd_tx_vlan_set_qinq_set,
3509                 (void *)&cmd_tx_vlan_set_qinq_portid,
3510                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3511                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3512                 NULL,
3513         },
3514 };
3515
3516 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3517 struct cmd_tx_vlan_set_pvid_result {
3518         cmdline_fixed_string_t tx_vlan;
3519         cmdline_fixed_string_t set;
3520         cmdline_fixed_string_t pvid;
3521         portid_t port_id;
3522         uint16_t vlan_id;
3523         cmdline_fixed_string_t mode;
3524 };
3525
3526 static void
3527 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3528                             __attribute__((unused)) struct cmdline *cl,
3529                             __attribute__((unused)) void *data)
3530 {
3531         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3532
3533         if (strcmp(res->mode, "on") == 0)
3534                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3535         else
3536                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3537 }
3538
3539 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3540         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3541                                  tx_vlan, "tx_vlan");
3542 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3543         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3544                                  set, "set");
3545 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3546         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3547                                  pvid, "pvid");
3548 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3549         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3550                              port_id, UINT16);
3551 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3552         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3553                               vlan_id, UINT16);
3554 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3555         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3556                                  mode, "on#off");
3557
3558 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3559         .f = cmd_tx_vlan_set_pvid_parsed,
3560         .data = NULL,
3561         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3562         .tokens = {
3563                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3564                 (void *)&cmd_tx_vlan_set_pvid_set,
3565                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3566                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3567                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3568                 (void *)&cmd_tx_vlan_set_pvid_mode,
3569                 NULL,
3570         },
3571 };
3572
3573 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3574 struct cmd_tx_vlan_reset_result {
3575         cmdline_fixed_string_t tx_vlan;
3576         cmdline_fixed_string_t reset;
3577         portid_t port_id;
3578 };
3579
3580 static void
3581 cmd_tx_vlan_reset_parsed(void *parsed_result,
3582                          __attribute__((unused)) struct cmdline *cl,
3583                          __attribute__((unused)) void *data)
3584 {
3585         struct cmd_tx_vlan_reset_result *res = parsed_result;
3586
3587         if (!port_is_stopped(res->port_id)) {
3588                 printf("Please stop port %d first\n", res->port_id);
3589                 return;
3590         }
3591
3592         tx_vlan_reset(res->port_id);
3593
3594         cmd_reconfig_device_queue(res->port_id, 1, 1);
3595 }
3596
3597 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3598         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3599                                  tx_vlan, "tx_vlan");
3600 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3601         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3602                                  reset, "reset");
3603 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3604         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3605                               port_id, UINT16);
3606
3607 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3608         .f = cmd_tx_vlan_reset_parsed,
3609         .data = NULL,
3610         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3611                 "VLAN header in packets sent on a port",
3612         .tokens = {
3613                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3614                 (void *)&cmd_tx_vlan_reset_reset,
3615                 (void *)&cmd_tx_vlan_reset_portid,
3616                 NULL,
3617         },
3618 };
3619
3620
3621 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3622 struct cmd_csum_result {
3623         cmdline_fixed_string_t csum;
3624         cmdline_fixed_string_t mode;
3625         cmdline_fixed_string_t proto;
3626         cmdline_fixed_string_t hwsw;
3627         portid_t port_id;
3628 };
3629
3630 static void
3631 csum_show(int port_id)
3632 {
3633         struct rte_eth_dev_info dev_info;
3634         uint64_t tx_offloads;
3635
3636         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3637         printf("Parse tunnel is %s\n",
3638                 (ports[port_id].parse_tunnel) ? "on" : "off");
3639         printf("IP checksum offload is %s\n",
3640                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3641         printf("UDP checksum offload is %s\n",
3642                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3643         printf("TCP checksum offload is %s\n",
3644                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3645         printf("SCTP checksum offload is %s\n",
3646                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3647         printf("Outer-Ip checksum offload is %s\n",
3648                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3649
3650         /* display warnings if configuration is not supported by the NIC */
3651         rte_eth_dev_info_get(port_id, &dev_info);
3652         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3653                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3654                 printf("Warning: hardware IP checksum enabled but not "
3655                         "supported by port %d\n", port_id);
3656         }
3657         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3658                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3659                 printf("Warning: hardware UDP checksum enabled but not "
3660                         "supported by port %d\n", port_id);
3661         }
3662         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3663                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3664                 printf("Warning: hardware TCP checksum enabled but not "
3665                         "supported by port %d\n", port_id);
3666         }
3667         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3668                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3669                 printf("Warning: hardware SCTP checksum enabled but not "
3670                         "supported by port %d\n", port_id);
3671         }
3672         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3673                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3674                 printf("Warning: hardware outer IP checksum enabled but not "
3675                         "supported by port %d\n", port_id);
3676         }
3677 }
3678
3679 static void
3680 cmd_csum_parsed(void *parsed_result,
3681                        __attribute__((unused)) struct cmdline *cl,
3682                        __attribute__((unused)) void *data)
3683 {
3684         struct cmd_csum_result *res = parsed_result;
3685         int hw = 0;
3686         uint64_t csum_offloads = 0;
3687         struct rte_eth_dev_info dev_info;
3688
3689         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3690                 printf("invalid port %d\n", res->port_id);
3691                 return;
3692         }
3693         if (!port_is_stopped(res->port_id)) {
3694                 printf("Please stop port %d first\n", res->port_id);
3695                 return;
3696         }
3697
3698         rte_eth_dev_info_get(res->port_id, &dev_info);
3699         if (!strcmp(res->mode, "set")) {
3700
3701                 if (!strcmp(res->hwsw, "hw"))
3702                         hw = 1;
3703
3704                 if (!strcmp(res->proto, "ip")) {
3705                         if (dev_info.tx_offload_capa &
3706                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3707                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3708                         } else {
3709                                 printf("IP checksum offload is not supported "
3710                                        "by port %u\n", res->port_id);
3711                         }
3712                 } else if (!strcmp(res->proto, "udp")) {
3713                         if (dev_info.tx_offload_capa &
3714                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3715                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3716                         } else {
3717                                 printf("UDP checksum offload is not supported "
3718                                        "by port %u\n", res->port_id);
3719                         }
3720                 } else if (!strcmp(res->proto, "tcp")) {
3721                         if (dev_info.tx_offload_capa &
3722                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3723                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3724                         } else {
3725                                 printf("TCP checksum offload is not supported "
3726                                        "by port %u\n", res->port_id);
3727                         }
3728                 } else if (!strcmp(res->proto, "sctp")) {
3729                         if (dev_info.tx_offload_capa &
3730                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3731                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3732                         } else {
3733                                 printf("SCTP checksum offload is not supported "
3734                                        "by port %u\n", res->port_id);
3735                         }
3736                 } else if (!strcmp(res->proto, "outer-ip")) {
3737                         if (dev_info.tx_offload_capa &
3738                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3739                                 csum_offloads |=
3740                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3741                         } else {
3742                                 printf("Outer IP checksum offload is not "
3743                                        "supported by port %u\n", res->port_id);
3744                         }
3745                 }
3746
3747                 if (hw) {
3748                         ports[res->port_id].dev_conf.txmode.offloads |=
3749                                                         csum_offloads;
3750                 } else {
3751                         ports[res->port_id].dev_conf.txmode.offloads &=
3752                                                         (~csum_offloads);
3753                 }
3754         }
3755         csum_show(res->port_id);
3756
3757         cmd_reconfig_device_queue(res->port_id, 1, 1);
3758 }
3759
3760 cmdline_parse_token_string_t cmd_csum_csum =
3761         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3762                                 csum, "csum");
3763 cmdline_parse_token_string_t cmd_csum_mode =
3764         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3765                                 mode, "set");
3766 cmdline_parse_token_string_t cmd_csum_proto =
3767         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3768                                 proto, "ip#tcp#udp#sctp#outer-ip");
3769 cmdline_parse_token_string_t cmd_csum_hwsw =
3770         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3771                                 hwsw, "hw#sw");
3772 cmdline_parse_token_num_t cmd_csum_portid =
3773         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3774                                 port_id, UINT16);
3775
3776 cmdline_parse_inst_t cmd_csum_set = {
3777         .f = cmd_csum_parsed,
3778         .data = NULL,
3779         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3780                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3781                 "using csum forward engine",
3782         .tokens = {
3783                 (void *)&cmd_csum_csum,
3784                 (void *)&cmd_csum_mode,
3785                 (void *)&cmd_csum_proto,
3786                 (void *)&cmd_csum_hwsw,
3787                 (void *)&cmd_csum_portid,
3788                 NULL,
3789         },
3790 };
3791
3792 cmdline_parse_token_string_t cmd_csum_mode_show =
3793         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3794                                 mode, "show");
3795
3796 cmdline_parse_inst_t cmd_csum_show = {
3797         .f = cmd_csum_parsed,
3798         .data = NULL,
3799         .help_str = "csum show <port_id>: Show checksum offload configuration",
3800         .tokens = {
3801                 (void *)&cmd_csum_csum,
3802                 (void *)&cmd_csum_mode_show,
3803                 (void *)&cmd_csum_portid,
3804                 NULL,
3805         },
3806 };
3807
3808 /* Enable/disable tunnel parsing */
3809 struct cmd_csum_tunnel_result {
3810         cmdline_fixed_string_t csum;
3811         cmdline_fixed_string_t parse;
3812         cmdline_fixed_string_t onoff;
3813         portid_t port_id;
3814 };
3815
3816 static void
3817 cmd_csum_tunnel_parsed(void *parsed_result,
3818                        __attribute__((unused)) struct cmdline *cl,
3819                        __attribute__((unused)) void *data)
3820 {
3821         struct cmd_csum_tunnel_result *res = parsed_result;
3822
3823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3824                 return;
3825
3826         if (!strcmp(res->onoff, "on"))
3827                 ports[res->port_id].parse_tunnel = 1;
3828         else
3829                 ports[res->port_id].parse_tunnel = 0;
3830
3831         csum_show(res->port_id);
3832 }
3833
3834 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3835         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3836                                 csum, "csum");
3837 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3838         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3839                                 parse, "parse_tunnel");
3840 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3841         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3842                                 onoff, "on#off");
3843 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3844         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3845                                 port_id, UINT16);
3846
3847 cmdline_parse_inst_t cmd_csum_tunnel = {
3848         .f = cmd_csum_tunnel_parsed,
3849         .data = NULL,
3850         .help_str = "csum parse_tunnel on|off <port_id>: "
3851                 "Enable/Disable parsing of tunnels for csum engine",
3852         .tokens = {
3853                 (void *)&cmd_csum_tunnel_csum,
3854                 (void *)&cmd_csum_tunnel_parse,
3855                 (void *)&cmd_csum_tunnel_onoff,
3856                 (void *)&cmd_csum_tunnel_portid,
3857                 NULL,
3858         },
3859 };
3860
3861 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3862 struct cmd_tso_set_result {
3863         cmdline_fixed_string_t tso;
3864         cmdline_fixed_string_t mode;
3865         uint16_t tso_segsz;
3866         portid_t port_id;
3867 };
3868
3869 static void
3870 cmd_tso_set_parsed(void *parsed_result,
3871                        __attribute__((unused)) struct cmdline *cl,
3872                        __attribute__((unused)) void *data)
3873 {
3874         struct cmd_tso_set_result *res = parsed_result;
3875         struct rte_eth_dev_info dev_info;
3876
3877         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3878                 return;
3879         if (!port_is_stopped(res->port_id)) {
3880                 printf("Please stop port %d first\n", res->port_id);
3881                 return;
3882         }
3883
3884         if (!strcmp(res->mode, "set"))
3885                 ports[res->port_id].tso_segsz = res->tso_segsz;
3886
3887         rte_eth_dev_info_get(res->port_id, &dev_info);
3888         if ((ports[res->port_id].tso_segsz != 0) &&
3889                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3890                 printf("Error: TSO is not supported by port %d\n",
3891                        res->port_id);
3892                 return;
3893         }
3894
3895         if (ports[res->port_id].tso_segsz == 0) {
3896                 ports[res->port_id].dev_conf.txmode.offloads &=
3897                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3898                 printf("TSO for non-tunneled packets is disabled\n");
3899         } else {
3900                 ports[res->port_id].dev_conf.txmode.offloads |=
3901                                                 DEV_TX_OFFLOAD_TCP_TSO;
3902                 printf("TSO segment size for non-tunneled packets is %d\n",
3903                         ports[res->port_id].tso_segsz);
3904         }
3905
3906         /* display warnings if configuration is not supported by the NIC */
3907         rte_eth_dev_info_get(res->port_id, &dev_info);
3908         if ((ports[res->port_id].tso_segsz != 0) &&
3909                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3910                 printf("Warning: TSO enabled but not "
3911                         "supported by port %d\n", res->port_id);
3912         }
3913
3914         cmd_reconfig_device_queue(res->port_id, 1, 1);
3915 }
3916
3917 cmdline_parse_token_string_t cmd_tso_set_tso =
3918         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3919                                 tso, "tso");
3920 cmdline_parse_token_string_t cmd_tso_set_mode =
3921         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3922                                 mode, "set");
3923 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3924         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3925                                 tso_segsz, UINT16);
3926 cmdline_parse_token_num_t cmd_tso_set_portid =
3927         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3928                                 port_id, UINT16);
3929
3930 cmdline_parse_inst_t cmd_tso_set = {
3931         .f = cmd_tso_set_parsed,
3932         .data = NULL,
3933         .help_str = "tso set <tso_segsz> <port_id>: "
3934                 "Set TSO segment size of non-tunneled packets for csum engine "
3935                 "(0 to disable)",
3936         .tokens = {
3937                 (void *)&cmd_tso_set_tso,
3938                 (void *)&cmd_tso_set_mode,
3939                 (void *)&cmd_tso_set_tso_segsz,
3940                 (void *)&cmd_tso_set_portid,
3941                 NULL,
3942         },
3943 };
3944
3945 cmdline_parse_token_string_t cmd_tso_show_mode =
3946         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3947                                 mode, "show");
3948
3949
3950 cmdline_parse_inst_t cmd_tso_show = {
3951         .f = cmd_tso_set_parsed,
3952         .data = NULL,
3953         .help_str = "tso show <port_id>: "
3954                 "Show TSO segment size of non-tunneled packets for csum engine",
3955         .tokens = {
3956                 (void *)&cmd_tso_set_tso,
3957                 (void *)&cmd_tso_show_mode,
3958                 (void *)&cmd_tso_set_portid,
3959                 NULL,
3960         },
3961 };
3962
3963 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3964 struct cmd_tunnel_tso_set_result {
3965         cmdline_fixed_string_t tso;
3966         cmdline_fixed_string_t mode;
3967         uint16_t tso_segsz;
3968         portid_t port_id;
3969 };
3970
3971 static struct rte_eth_dev_info
3972 check_tunnel_tso_nic_support(portid_t port_id)
3973 {
3974         struct rte_eth_dev_info dev_info;
3975
3976         rte_eth_dev_info_get(port_id, &dev_info);
3977         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3978                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3979                        "not enabled for port %d\n", port_id);
3980         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3981                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3982                        "not enabled for port %d\n", port_id);
3983         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3984                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3985                        "not enabled for port %d\n", port_id);
3986         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3987                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3988                        "not enabled for port %d\n", port_id);
3989         return dev_info;
3990 }
3991
3992 static void
3993 cmd_tunnel_tso_set_parsed(void *parsed_result,
3994                           __attribute__((unused)) struct cmdline *cl,
3995                           __attribute__((unused)) void *data)
3996 {
3997         struct cmd_tunnel_tso_set_result *res = parsed_result;
3998         struct rte_eth_dev_info dev_info;
3999
4000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4001                 return;
4002         if (!port_is_stopped(res->port_id)) {
4003                 printf("Please stop port %d first\n", res->port_id);
4004                 return;
4005         }
4006
4007         if (!strcmp(res->mode, "set"))
4008                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4009
4010         dev_info = check_tunnel_tso_nic_support(res->port_id);
4011         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4012                 ports[res->port_id].dev_conf.txmode.offloads &=
4013                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4014                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4015                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4016                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4017                 printf("TSO for tunneled packets is disabled\n");
4018         } else {
4019                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4020                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4021                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4022                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4023
4024                 ports[res->port_id].dev_conf.txmode.offloads |=
4025                         (tso_offloads & dev_info.tx_offload_capa);
4026                 printf("TSO segment size for tunneled packets is %d\n",
4027                         ports[res->port_id].tunnel_tso_segsz);
4028
4029                 /* Below conditions are needed to make it work:
4030                  * (1) tunnel TSO is supported by the NIC;
4031                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4032                  * are recognized;
4033                  * (3) for tunneled pkts with outer L3 of IPv4,
4034                  * "csum set outer-ip" must be set to hw, because after tso,
4035                  * total_len of outer IP header is changed, and the checksum
4036                  * of outer IP header calculated by sw should be wrong; that
4037                  * is not necessary for IPv6 tunneled pkts because there's no
4038                  * checksum in IP header anymore.
4039                  */
4040
4041                 if (!ports[res->port_id].parse_tunnel)
4042                         printf("Warning: csum parse_tunnel must be set "
4043                                 "so that tunneled packets are recognized\n");
4044                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4045                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4046                         printf("Warning: csum set outer-ip must be set to hw "
4047                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4048         }
4049
4050         cmd_reconfig_device_queue(res->port_id, 1, 1);
4051 }
4052
4053 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4054         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4055                                 tso, "tunnel_tso");
4056 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4057         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4058                                 mode, "set");
4059 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4060         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4061                                 tso_segsz, UINT16);
4062 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4063         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4064                                 port_id, UINT16);
4065
4066 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4067         .f = cmd_tunnel_tso_set_parsed,
4068         .data = NULL,
4069         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4070                 "Set TSO segment size of tunneled packets for csum engine "
4071                 "(0 to disable)",
4072         .tokens = {
4073                 (void *)&cmd_tunnel_tso_set_tso,
4074                 (void *)&cmd_tunnel_tso_set_mode,
4075                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4076                 (void *)&cmd_tunnel_tso_set_portid,
4077                 NULL,
4078         },
4079 };
4080
4081 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4082         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4083                                 mode, "show");
4084
4085
4086 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4087         .f = cmd_tunnel_tso_set_parsed,
4088         .data = NULL,
4089         .help_str = "tunnel_tso show <port_id> "
4090                 "Show TSO segment size of tunneled packets for csum engine",
4091         .tokens = {
4092                 (void *)&cmd_tunnel_tso_set_tso,
4093                 (void *)&cmd_tunnel_tso_show_mode,
4094                 (void *)&cmd_tunnel_tso_set_portid,
4095                 NULL,
4096         },
4097 };
4098
4099 /* *** SET GRO FOR A PORT *** */
4100 struct cmd_gro_enable_result {
4101         cmdline_fixed_string_t cmd_set;
4102         cmdline_fixed_string_t cmd_port;
4103         cmdline_fixed_string_t cmd_keyword;
4104         cmdline_fixed_string_t cmd_onoff;
4105         portid_t cmd_pid;
4106 };
4107
4108 static void
4109 cmd_gro_enable_parsed(void *parsed_result,
4110                 __attribute__((unused)) struct cmdline *cl,
4111                 __attribute__((unused)) void *data)
4112 {
4113         struct cmd_gro_enable_result *res;
4114
4115         res = parsed_result;
4116         if (!strcmp(res->cmd_keyword, "gro"))
4117                 setup_gro(res->cmd_onoff, res->cmd_pid);
4118 }
4119
4120 cmdline_parse_token_string_t cmd_gro_enable_set =
4121         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4122                         cmd_set, "set");
4123 cmdline_parse_token_string_t cmd_gro_enable_port =
4124         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4125                         cmd_keyword, "port");
4126 cmdline_parse_token_num_t cmd_gro_enable_pid =
4127         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4128                         cmd_pid, UINT16);
4129 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4130         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4131                         cmd_keyword, "gro");
4132 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4133         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4134                         cmd_onoff, "on#off");
4135
4136 cmdline_parse_inst_t cmd_gro_enable = {
4137         .f = cmd_gro_enable_parsed,
4138         .data = NULL,
4139         .help_str = "set port <port_id> gro on|off",
4140         .tokens = {
4141                 (void *)&cmd_gro_enable_set,
4142                 (void *)&cmd_gro_enable_port,
4143                 (void *)&cmd_gro_enable_pid,
4144                 (void *)&cmd_gro_enable_keyword,
4145                 (void *)&cmd_gro_enable_onoff,
4146                 NULL,
4147         },
4148 };
4149
4150 /* *** DISPLAY GRO CONFIGURATION *** */
4151 struct cmd_gro_show_result {
4152         cmdline_fixed_string_t cmd_show;
4153         cmdline_fixed_string_t cmd_port;
4154         cmdline_fixed_string_t cmd_keyword;
4155         portid_t cmd_pid;
4156 };
4157
4158 static void
4159 cmd_gro_show_parsed(void *parsed_result,
4160                 __attribute__((unused)) struct cmdline *cl,
4161                 __attribute__((unused)) void *data)
4162 {
4163         struct cmd_gro_show_result *res;
4164
4165         res = parsed_result;
4166         if (!strcmp(res->cmd_keyword, "gro"))
4167                 show_gro(res->cmd_pid);
4168 }
4169
4170 cmdline_parse_token_string_t cmd_gro_show_show =
4171         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4172                         cmd_show, "show");
4173 cmdline_parse_token_string_t cmd_gro_show_port =
4174         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4175                         cmd_port, "port");
4176 cmdline_parse_token_num_t cmd_gro_show_pid =
4177         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4178                         cmd_pid, UINT16);
4179 cmdline_parse_token_string_t cmd_gro_show_keyword =
4180         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4181                         cmd_keyword, "gro");
4182
4183 cmdline_parse_inst_t cmd_gro_show = {
4184         .f = cmd_gro_show_parsed,
4185         .data = NULL,
4186         .help_str = "show port <port_id> gro",
4187         .tokens = {
4188                 (void *)&cmd_gro_show_show,
4189                 (void *)&cmd_gro_show_port,
4190                 (void *)&cmd_gro_show_pid,
4191                 (void *)&cmd_gro_show_keyword,
4192                 NULL,
4193         },
4194 };
4195
4196 /* *** SET FLUSH CYCLES FOR GRO *** */
4197 struct cmd_gro_flush_result {
4198         cmdline_fixed_string_t cmd_set;
4199         cmdline_fixed_string_t cmd_keyword;
4200         cmdline_fixed_string_t cmd_flush;
4201         uint8_t cmd_cycles;
4202 };
4203
4204 static void
4205 cmd_gro_flush_parsed(void *parsed_result,
4206                 __attribute__((unused)) struct cmdline *cl,
4207                 __attribute__((unused)) void *data)
4208 {
4209         struct cmd_gro_flush_result *res;
4210
4211         res = parsed_result;
4212         if ((!strcmp(res->cmd_keyword, "gro")) &&
4213                         (!strcmp(res->cmd_flush, "flush")))
4214                 setup_gro_flush_cycles(res->cmd_cycles);
4215 }
4216
4217 cmdline_parse_token_string_t cmd_gro_flush_set =
4218         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4219                         cmd_set, "set");
4220 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4221         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4222                         cmd_keyword, "gro");
4223 cmdline_parse_token_string_t cmd_gro_flush_flush =
4224         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4225                         cmd_flush, "flush");
4226 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4227         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4228                         cmd_cycles, UINT8);
4229
4230 cmdline_parse_inst_t cmd_gro_flush = {
4231         .f = cmd_gro_flush_parsed,
4232         .data = NULL,
4233         .help_str = "set gro flush <cycles>",
4234         .tokens = {
4235                 (void *)&cmd_gro_flush_set,
4236                 (void *)&cmd_gro_flush_keyword,
4237                 (void *)&cmd_gro_flush_flush,
4238                 (void *)&cmd_gro_flush_cycles,
4239                 NULL,
4240         },
4241 };
4242
4243 /* *** ENABLE/DISABLE GSO *** */
4244 struct cmd_gso_enable_result {
4245         cmdline_fixed_string_t cmd_set;
4246         cmdline_fixed_string_t cmd_port;
4247         cmdline_fixed_string_t cmd_keyword;
4248         cmdline_fixed_string_t cmd_mode;
4249         portid_t cmd_pid;
4250 };
4251
4252 static void
4253 cmd_gso_enable_parsed(void *parsed_result,
4254                 __attribute__((unused)) struct cmdline *cl,
4255                 __attribute__((unused)) void *data)
4256 {
4257         struct cmd_gso_enable_result *res;
4258
4259         res = parsed_result;
4260         if (!strcmp(res->cmd_keyword, "gso"))
4261                 setup_gso(res->cmd_mode, res->cmd_pid);
4262 }
4263
4264 cmdline_parse_token_string_t cmd_gso_enable_set =
4265         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4266                         cmd_set, "set");
4267 cmdline_parse_token_string_t cmd_gso_enable_port =
4268         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4269                         cmd_port, "port");
4270 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4271         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4272                         cmd_keyword, "gso");
4273 cmdline_parse_token_string_t cmd_gso_enable_mode =
4274         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4275                         cmd_mode, "on#off");
4276 cmdline_parse_token_num_t cmd_gso_enable_pid =
4277         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4278                         cmd_pid, UINT16);
4279
4280 cmdline_parse_inst_t cmd_gso_enable = {
4281         .f = cmd_gso_enable_parsed,
4282         .data = NULL,
4283         .help_str = "set port <port_id> gso on|off",
4284         .tokens = {
4285                 (void *)&cmd_gso_enable_set,
4286                 (void *)&cmd_gso_enable_port,
4287                 (void *)&cmd_gso_enable_pid,
4288                 (void *)&cmd_gso_enable_keyword,
4289                 (void *)&cmd_gso_enable_mode,
4290                 NULL,
4291         },
4292 };
4293
4294 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4295 struct cmd_gso_size_result {
4296         cmdline_fixed_string_t cmd_set;
4297         cmdline_fixed_string_t cmd_keyword;
4298         cmdline_fixed_string_t cmd_segsz;
4299         uint16_t cmd_size;
4300 };
4301
4302 static void
4303 cmd_gso_size_parsed(void *parsed_result,
4304                        __attribute__((unused)) struct cmdline *cl,
4305                        __attribute__((unused)) void *data)
4306 {
4307         struct cmd_gso_size_result *res = parsed_result;
4308
4309         if (test_done == 0) {
4310                 printf("Before setting GSO segsz, please first"
4311                                 " stop fowarding\n");
4312                 return;
4313         }
4314
4315         if (!strcmp(res->cmd_keyword, "gso") &&
4316                         !strcmp(res->cmd_segsz, "segsz")) {
4317                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4318                         printf("gso_size should be larger than %zu."
4319                                         " Please input a legal value\n",
4320                                         RTE_GSO_SEG_SIZE_MIN);
4321                 else
4322                         gso_max_segment_size = res->cmd_size;
4323         }
4324 }
4325
4326 cmdline_parse_token_string_t cmd_gso_size_set =
4327         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4328                                 cmd_set, "set");
4329 cmdline_parse_token_string_t cmd_gso_size_keyword =
4330         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4331                                 cmd_keyword, "gso");
4332 cmdline_parse_token_string_t cmd_gso_size_segsz =
4333         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4334                                 cmd_segsz, "segsz");
4335 cmdline_parse_token_num_t cmd_gso_size_size =
4336         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4337                                 cmd_size, UINT16);
4338
4339 cmdline_parse_inst_t cmd_gso_size = {
4340         .f = cmd_gso_size_parsed,
4341         .data = NULL,
4342         .help_str = "set gso segsz <length>",
4343         .tokens = {
4344                 (void *)&cmd_gso_size_set,
4345                 (void *)&cmd_gso_size_keyword,
4346                 (void *)&cmd_gso_size_segsz,
4347                 (void *)&cmd_gso_size_size,
4348                 NULL,
4349         },
4350 };
4351
4352 /* *** SHOW GSO CONFIGURATION *** */
4353 struct cmd_gso_show_result {
4354         cmdline_fixed_string_t cmd_show;
4355         cmdline_fixed_string_t cmd_port;
4356         cmdline_fixed_string_t cmd_keyword;
4357         portid_t cmd_pid;
4358 };
4359
4360 static void
4361 cmd_gso_show_parsed(void *parsed_result,
4362                        __attribute__((unused)) struct cmdline *cl,
4363                        __attribute__((unused)) void *data)
4364 {
4365         struct cmd_gso_show_result *res = parsed_result;
4366
4367         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4368                 printf("invalid port id %u\n", res->cmd_pid);
4369                 return;
4370         }
4371         if (!strcmp(res->cmd_keyword, "gso")) {
4372                 if (gso_ports[res->cmd_pid].enable) {
4373                         printf("Max GSO'd packet size: %uB\n"
4374                                         "Supported GSO types: TCP/IPv4, "
4375                                         "VxLAN with inner TCP/IPv4 packet, "
4376                                         "GRE with inner TCP/IPv4  packet\n",
4377                                         gso_max_segment_size);
4378                 } else
4379                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4380         }
4381 }
4382
4383 cmdline_parse_token_string_t cmd_gso_show_show =
4384 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4385                 cmd_show, "show");
4386 cmdline_parse_token_string_t cmd_gso_show_port =
4387 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4388                 cmd_port, "port");
4389 cmdline_parse_token_string_t cmd_gso_show_keyword =
4390         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4391                                 cmd_keyword, "gso");
4392 cmdline_parse_token_num_t cmd_gso_show_pid =
4393         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4394                                 cmd_pid, UINT16);
4395
4396 cmdline_parse_inst_t cmd_gso_show = {
4397         .f = cmd_gso_show_parsed,
4398         .data = NULL,
4399         .help_str = "show port <port_id> gso",
4400         .tokens = {
4401                 (void *)&cmd_gso_show_show,
4402                 (void *)&cmd_gso_show_port,
4403                 (void *)&cmd_gso_show_pid,
4404                 (void *)&cmd_gso_show_keyword,
4405                 NULL,
4406         },
4407 };
4408
4409 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4410 struct cmd_set_flush_rx {
4411         cmdline_fixed_string_t set;
4412         cmdline_fixed_string_t flush_rx;
4413         cmdline_fixed_string_t mode;
4414 };
4415
4416 static void
4417 cmd_set_flush_rx_parsed(void *parsed_result,
4418                 __attribute__((unused)) struct cmdline *cl,
4419                 __attribute__((unused)) void *data)
4420 {
4421         struct cmd_set_flush_rx *res = parsed_result;
4422         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4423 }
4424
4425 cmdline_parse_token_string_t cmd_setflushrx_set =
4426         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4427                         set, "set");
4428 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4429         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4430                         flush_rx, "flush_rx");
4431 cmdline_parse_token_string_t cmd_setflushrx_mode =
4432         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4433                         mode, "on#off");
4434
4435
4436 cmdline_parse_inst_t cmd_set_flush_rx = {
4437         .f = cmd_set_flush_rx_parsed,
4438         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4439         .data = NULL,
4440         .tokens = {
4441                 (void *)&cmd_setflushrx_set,
4442                 (void *)&cmd_setflushrx_flush_rx,
4443                 (void *)&cmd_setflushrx_mode,
4444                 NULL,
4445         },
4446 };
4447
4448 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4449 struct cmd_set_link_check {
4450         cmdline_fixed_string_t set;
4451         cmdline_fixed_string_t link_check;
4452         cmdline_fixed_string_t mode;
4453 };
4454
4455 static void
4456 cmd_set_link_check_parsed(void *parsed_result,
4457                 __attribute__((unused)) struct cmdline *cl,
4458                 __attribute__((unused)) void *data)
4459 {
4460         struct cmd_set_link_check *res = parsed_result;
4461         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4462 }
4463
4464 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4465         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4466                         set, "set");
4467 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4468         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4469                         link_check, "link_check");
4470 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4471         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4472                         mode, "on#off");
4473
4474
4475 cmdline_parse_inst_t cmd_set_link_check = {
4476         .f = cmd_set_link_check_parsed,
4477         .help_str = "set link_check on|off: Enable/Disable link status check "
4478                     "when starting/stopping a port",
4479         .data = NULL,
4480         .tokens = {
4481                 (void *)&cmd_setlinkcheck_set,
4482                 (void *)&cmd_setlinkcheck_link_check,
4483                 (void *)&cmd_setlinkcheck_mode,
4484                 NULL,
4485         },
4486 };
4487
4488 /* *** SET NIC BYPASS MODE *** */
4489 struct cmd_set_bypass_mode_result {
4490         cmdline_fixed_string_t set;
4491         cmdline_fixed_string_t bypass;
4492         cmdline_fixed_string_t mode;
4493         cmdline_fixed_string_t value;
4494         portid_t port_id;
4495 };
4496
4497 static void
4498 cmd_set_bypass_mode_parsed(void *parsed_result,
4499                 __attribute__((unused)) struct cmdline *cl,
4500                 __attribute__((unused)) void *data)
4501 {
4502         struct cmd_set_bypass_mode_result *res = parsed_result;
4503         portid_t port_id = res->port_id;
4504         int32_t rc = -EINVAL;
4505
4506 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4507         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4508
4509         if (!strcmp(res->value, "bypass"))
4510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4511         else if (!strcmp(res->value, "isolate"))
4512                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4513         else
4514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4515
4516         /* Set the bypass mode for the relevant port. */
4517         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4518 #endif
4519         if (rc != 0)
4520                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4521 }
4522
4523 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4524         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4525                         set, "set");
4526 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4527         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4528                         bypass, "bypass");
4529 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4530         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4531                         mode, "mode");
4532 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4533         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4534                         value, "normal#bypass#isolate");
4535 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4536         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4537                                 port_id, UINT16);
4538
4539 cmdline_parse_inst_t cmd_set_bypass_mode = {
4540         .f = cmd_set_bypass_mode_parsed,
4541         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4542                     "Set the NIC bypass mode for port_id",
4543         .data = NULL,
4544         .tokens = {
4545                 (void *)&cmd_setbypass_mode_set,
4546                 (void *)&cmd_setbypass_mode_bypass,
4547                 (void *)&cmd_setbypass_mode_mode,
4548                 (void *)&cmd_setbypass_mode_value,
4549                 (void *)&cmd_setbypass_mode_port,
4550                 NULL,
4551         },
4552 };
4553
4554 /* *** SET NIC BYPASS EVENT *** */
4555 struct cmd_set_bypass_event_result {
4556         cmdline_fixed_string_t set;
4557         cmdline_fixed_string_t bypass;
4558         cmdline_fixed_string_t event;
4559         cmdline_fixed_string_t event_value;
4560         cmdline_fixed_string_t mode;
4561         cmdline_fixed_string_t mode_value;
4562         portid_t port_id;
4563 };
4564
4565 static void
4566 cmd_set_bypass_event_parsed(void *parsed_result,
4567                 __attribute__((unused)) struct cmdline *cl,
4568                 __attribute__((unused)) void *data)
4569 {
4570         int32_t rc = -EINVAL;
4571         struct cmd_set_bypass_event_result *res = parsed_result;
4572         portid_t port_id = res->port_id;
4573
4574 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4575         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4576         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4577
4578         if (!strcmp(res->event_value, "timeout"))
4579                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4580         else if (!strcmp(res->event_value, "os_on"))
4581                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4582         else if (!strcmp(res->event_value, "os_off"))
4583                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4584         else if (!strcmp(res->event_value, "power_on"))
4585                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4586         else if (!strcmp(res->event_value, "power_off"))
4587                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4588         else
4589                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4590
4591         if (!strcmp(res->mode_value, "bypass"))
4592                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4593         else if (!strcmp(res->mode_value, "isolate"))
4594                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4595         else
4596                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4597
4598         /* Set the watchdog timeout. */
4599         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4600
4601                 rc = -EINVAL;
4602                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4603                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4604                                                            bypass_timeout);
4605                 }
4606                 if (rc != 0) {
4607                         printf("Failed to set timeout value %u "
4608                         "for port %d, errto code: %d.\n",
4609                         bypass_timeout, port_id, rc);
4610                 }
4611         }
4612
4613         /* Set the bypass event to transition to bypass mode. */
4614         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4615                                               bypass_mode);
4616 #endif
4617
4618         if (rc != 0)
4619                 printf("\t Failed to set bypass event for port = %d.\n",
4620                        port_id);
4621 }
4622
4623 cmdline_parse_token_string_t cmd_setbypass_event_set =
4624         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4625                         set, "set");
4626 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4627         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4628                         bypass, "bypass");
4629 cmdline_parse_token_string_t cmd_setbypass_event_event =
4630         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4631                         event, "event");
4632 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4633         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4634                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4635 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4636         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4637                         mode, "mode");
4638 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4639         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4640                         mode_value, "normal#bypass#isolate");
4641 cmdline_parse_token_num_t cmd_setbypass_event_port =
4642         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4643                                 port_id, UINT16);
4644
4645 cmdline_parse_inst_t cmd_set_bypass_event = {
4646         .f = cmd_set_bypass_event_parsed,
4647         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4648                 "power_off mode normal|bypass|isolate <port_id>: "
4649                 "Set the NIC bypass event mode for port_id",
4650         .data = NULL,
4651         .tokens = {
4652                 (void *)&cmd_setbypass_event_set,
4653                 (void *)&cmd_setbypass_event_bypass,
4654                 (void *)&cmd_setbypass_event_event,
4655                 (void *)&cmd_setbypass_event_event_value,
4656                 (void *)&cmd_setbypass_event_mode,
4657                 (void *)&cmd_setbypass_event_mode_value,
4658                 (void *)&cmd_setbypass_event_port,
4659                 NULL,
4660         },
4661 };
4662
4663
4664 /* *** SET NIC BYPASS TIMEOUT *** */
4665 struct cmd_set_bypass_timeout_result {
4666         cmdline_fixed_string_t set;
4667         cmdline_fixed_string_t bypass;
4668         cmdline_fixed_string_t timeout;
4669         cmdline_fixed_string_t value;
4670 };
4671
4672 static void
4673 cmd_set_bypass_timeout_parsed(void *parsed_result,
4674                 __attribute__((unused)) struct cmdline *cl,
4675                 __attribute__((unused)) void *data)
4676 {
4677         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4678
4679 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4680         if (!strcmp(res->value, "1.5"))
4681                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4682         else if (!strcmp(res->value, "2"))
4683                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4684         else if (!strcmp(res->value, "3"))
4685                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4686         else if (!strcmp(res->value, "4"))
4687                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4688         else if (!strcmp(res->value, "8"))
4689                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4690         else if (!strcmp(res->value, "16"))
4691                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4692         else if (!strcmp(res->value, "32"))
4693                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4694         else
4695                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4696 #endif
4697 }
4698
4699 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4701                         set, "set");
4702 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4703         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4704                         bypass, "bypass");
4705 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4707                         timeout, "timeout");
4708 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4709         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4710                         value, "0#1.5#2#3#4#8#16#32");
4711
4712 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4713         .f = cmd_set_bypass_timeout_parsed,
4714         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4715                 "Set the NIC bypass watchdog timeout in seconds",
4716         .data = NULL,
4717         .tokens = {
4718                 (void *)&cmd_setbypass_timeout_set,
4719                 (void *)&cmd_setbypass_timeout_bypass,
4720                 (void *)&cmd_setbypass_timeout_timeout,
4721                 (void *)&cmd_setbypass_timeout_value,
4722                 NULL,
4723         },
4724 };
4725
4726 /* *** SHOW NIC BYPASS MODE *** */
4727 struct cmd_show_bypass_config_result {
4728         cmdline_fixed_string_t show;
4729         cmdline_fixed_string_t bypass;
4730         cmdline_fixed_string_t config;
4731         portid_t port_id;
4732 };
4733
4734 static void
4735 cmd_show_bypass_config_parsed(void *parsed_result,
4736                 __attribute__((unused)) struct cmdline *cl,
4737                 __attribute__((unused)) void *data)
4738 {
4739         struct cmd_show_bypass_config_result *res = parsed_result;
4740         portid_t port_id = res->port_id;
4741         int rc = -EINVAL;
4742 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4743         uint32_t event_mode;
4744         uint32_t bypass_mode;
4745         uint32_t timeout = bypass_timeout;
4746         int i;
4747
4748         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4749                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4750         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4751                 {"UNKNOWN", "normal", "bypass", "isolate"};
4752         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4753                 "NONE",
4754                 "OS/board on",
4755                 "power supply on",
4756                 "OS/board off",
4757                 "power supply off",
4758                 "timeout"};
4759         int num_events = (sizeof events) / (sizeof events[0]);
4760
4761         /* Display the bypass mode.*/
4762         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4763                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4764                 return;
4765         }
4766         else {
4767                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4768                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4769
4770                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4771         }
4772
4773         /* Display the bypass timeout.*/
4774         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4775                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4776
4777         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4778
4779         /* Display the bypass events and associated modes. */
4780         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4781
4782                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4783                         printf("\tFailed to get bypass mode for event = %s\n",
4784                                 events[i]);
4785                 } else {
4786                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4787                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4788
4789                         printf("\tbypass event: %-16s = %s\n", events[i],
4790                                 modes[event_mode]);
4791                 }
4792         }
4793 #endif
4794         if (rc != 0)
4795                 printf("\tFailed to get bypass configuration for port = %d\n",
4796                        port_id);
4797 }
4798
4799 cmdline_parse_token_string_t cmd_showbypass_config_show =
4800         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4801                         show, "show");
4802 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4803         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4804                         bypass, "bypass");
4805 cmdline_parse_token_string_t cmd_showbypass_config_config =
4806         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4807                         config, "config");
4808 cmdline_parse_token_num_t cmd_showbypass_config_port =
4809         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4810                                 port_id, UINT16);
4811
4812 cmdline_parse_inst_t cmd_show_bypass_config = {
4813         .f = cmd_show_bypass_config_parsed,
4814         .help_str = "show bypass config <port_id>: "
4815                     "Show the NIC bypass config for port_id",
4816         .data = NULL,
4817         .tokens = {
4818                 (void *)&cmd_showbypass_config_show,
4819                 (void *)&cmd_showbypass_config_bypass,
4820                 (void *)&cmd_showbypass_config_config,
4821                 (void *)&cmd_showbypass_config_port,
4822                 NULL,
4823         },
4824 };
4825
4826 #ifdef RTE_LIBRTE_PMD_BOND
4827 /* *** SET BONDING MODE *** */
4828 struct cmd_set_bonding_mode_result {
4829         cmdline_fixed_string_t set;
4830         cmdline_fixed_string_t bonding;
4831         cmdline_fixed_string_t mode;
4832         uint8_t value;
4833         portid_t port_id;
4834 };
4835
4836 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4837                 __attribute__((unused))  struct cmdline *cl,
4838                 __attribute__((unused)) void *data)
4839 {
4840         struct cmd_set_bonding_mode_result *res = parsed_result;
4841         portid_t port_id = res->port_id;
4842
4843         /* Set the bonding mode for the relevant port. */
4844         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4845                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4846 }
4847
4848 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4849 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4850                 set, "set");
4851 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4853                 bonding, "bonding");
4854 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4855 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4856                 mode, "mode");
4857 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4858 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4859                 value, UINT8);
4860 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4861 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4862                 port_id, UINT16);
4863
4864 cmdline_parse_inst_t cmd_set_bonding_mode = {
4865                 .f = cmd_set_bonding_mode_parsed,
4866                 .help_str = "set bonding mode <mode_value> <port_id>: "
4867                         "Set the bonding mode for port_id",
4868                 .data = NULL,
4869                 .tokens = {
4870                                 (void *) &cmd_setbonding_mode_set,
4871                                 (void *) &cmd_setbonding_mode_bonding,
4872                                 (void *) &cmd_setbonding_mode_mode,
4873                                 (void *) &cmd_setbonding_mode_value,
4874                                 (void *) &cmd_setbonding_mode_port,
4875                                 NULL
4876                 }
4877 };
4878
4879 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4880 struct cmd_set_bonding_lacp_dedicated_queues_result {
4881         cmdline_fixed_string_t set;
4882         cmdline_fixed_string_t bonding;
4883         cmdline_fixed_string_t lacp;
4884         cmdline_fixed_string_t dedicated_queues;
4885         portid_t port_id;
4886         cmdline_fixed_string_t mode;
4887 };
4888
4889 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4890                 __attribute__((unused))  struct cmdline *cl,
4891                 __attribute__((unused)) void *data)
4892 {
4893         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4894         portid_t port_id = res->port_id;
4895         struct rte_port *port;
4896
4897         port = &ports[port_id];
4898
4899         /** Check if the port is not started **/
4900         if (port->port_status != RTE_PORT_STOPPED) {
4901                 printf("Please stop port %d first\n", port_id);
4902                 return;
4903         }
4904
4905         if (!strcmp(res->mode, "enable")) {
4906                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4907                         printf("Dedicate queues for LACP control packets"
4908                                         " enabled\n");
4909                 else
4910                         printf("Enabling dedicate queues for LACP control "
4911                                         "packets on port %d failed\n", port_id);
4912         } else if (!strcmp(res->mode, "disable")) {
4913                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4914                         printf("Dedicated queues for LACP control packets "
4915                                         "disabled\n");
4916                 else
4917                         printf("Disabling dedicated queues for LACP control "
4918                                         "traffic on port %d failed\n", port_id);
4919         }
4920 }
4921
4922 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4923 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4924                 set, "set");
4925 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4926 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4927                 bonding, "bonding");
4928 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4929 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4930                 lacp, "lacp");
4931 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4932 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4933                 dedicated_queues, "dedicated_queues");
4934 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4935 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4936                 port_id, UINT16);
4937 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4938 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4939                 mode, "enable#disable");
4940
4941 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4942                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4943                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4944                         "enable|disable: "
4945                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4946                 .data = NULL,
4947                 .tokens = {
4948                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4949                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4950                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4951                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4952                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4953                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4954                         NULL
4955                 }
4956 };
4957
4958 /* *** SET BALANCE XMIT POLICY *** */
4959 struct cmd_set_bonding_balance_xmit_policy_result {
4960         cmdline_fixed_string_t set;
4961         cmdline_fixed_string_t bonding;
4962         cmdline_fixed_string_t balance_xmit_policy;
4963         portid_t port_id;
4964         cmdline_fixed_string_t policy;
4965 };
4966
4967 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4968                 __attribute__((unused))  struct cmdline *cl,
4969                 __attribute__((unused)) void *data)
4970 {
4971         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4972         portid_t port_id = res->port_id;
4973         uint8_t policy;
4974
4975         if (!strcmp(res->policy, "l2")) {
4976                 policy = BALANCE_XMIT_POLICY_LAYER2;
4977         } else if (!strcmp(res->policy, "l23")) {
4978                 policy = BALANCE_XMIT_POLICY_LAYER23;
4979         } else if (!strcmp(res->policy, "l34")) {
4980                 policy = BALANCE_XMIT_POLICY_LAYER34;
4981         } else {
4982                 printf("\t Invalid xmit policy selection");
4983                 return;
4984         }
4985
4986         /* Set the bonding mode for the relevant port. */
4987         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4988                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4989                                 port_id);
4990         }
4991 }
4992
4993 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4994 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4995                 set, "set");
4996 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4997 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4998                 bonding, "bonding");
4999 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5000 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5001                 balance_xmit_policy, "balance_xmit_policy");
5002 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5003 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5004                 port_id, UINT16);
5005 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5006 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5007                 policy, "l2#l23#l34");
5008
5009 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5010                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5011                 .help_str = "set bonding balance_xmit_policy <port_id> "
5012                         "l2|l23|l34: "
5013                         "Set the bonding balance_xmit_policy for port_id",
5014                 .data = NULL,
5015                 .tokens = {
5016                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5017                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5018                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5019                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5020                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5021                                 NULL
5022                 }
5023 };
5024
5025 /* *** SHOW NIC BONDING CONFIGURATION *** */
5026 struct cmd_show_bonding_config_result {
5027         cmdline_fixed_string_t show;
5028         cmdline_fixed_string_t bonding;
5029         cmdline_fixed_string_t config;
5030         portid_t port_id;
5031 };
5032
5033 static void cmd_show_bonding_config_parsed(void *parsed_result,
5034                 __attribute__((unused))  struct cmdline *cl,
5035                 __attribute__((unused)) void *data)
5036 {
5037         struct cmd_show_bonding_config_result *res = parsed_result;
5038         int bonding_mode, agg_mode;
5039         portid_t slaves[RTE_MAX_ETHPORTS];
5040         int num_slaves, num_active_slaves;
5041         int primary_id;
5042         int i;
5043         portid_t port_id = res->port_id;
5044
5045         /* Display the bonding mode.*/
5046         bonding_mode = rte_eth_bond_mode_get(port_id);
5047         if (bonding_mode < 0) {
5048                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5049                 return;
5050         } else
5051                 printf("\tBonding mode: %d\n", bonding_mode);
5052
5053         if (bonding_mode == BONDING_MODE_BALANCE) {
5054                 int balance_xmit_policy;
5055
5056                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5057                 if (balance_xmit_policy < 0) {
5058                         printf("\tFailed to get balance xmit policy for port = %d\n",
5059                                         port_id);
5060                         return;
5061                 } else {
5062                         printf("\tBalance Xmit Policy: ");
5063
5064                         switch (balance_xmit_policy) {
5065                         case BALANCE_XMIT_POLICY_LAYER2:
5066                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5067                                 break;
5068                         case BALANCE_XMIT_POLICY_LAYER23:
5069                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5070                                 break;
5071                         case BALANCE_XMIT_POLICY_LAYER34:
5072                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5073                                 break;
5074                         }
5075                         printf("\n");
5076                 }
5077         }
5078
5079         if (bonding_mode == BONDING_MODE_8023AD) {
5080                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5081                 printf("\tIEEE802.3AD Aggregator Mode: ");
5082                 switch (agg_mode) {
5083                 case AGG_BANDWIDTH:
5084                         printf("bandwidth");
5085                         break;
5086                 case AGG_STABLE:
5087                         printf("stable");
5088                         break;
5089                 case AGG_COUNT:
5090                         printf("count");
5091                         break;
5092                 }
5093                 printf("\n");
5094         }
5095
5096         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5097
5098         if (num_slaves < 0) {
5099                 printf("\tFailed to get slave list for port = %d\n", port_id);
5100                 return;
5101         }
5102         if (num_slaves > 0) {
5103                 printf("\tSlaves (%d): [", num_slaves);
5104                 for (i = 0; i < num_slaves - 1; i++)
5105                         printf("%d ", slaves[i]);
5106
5107                 printf("%d]\n", slaves[num_slaves - 1]);
5108         } else {
5109                 printf("\tSlaves: []\n");
5110
5111         }
5112
5113         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5114                         RTE_MAX_ETHPORTS);
5115
5116         if (num_active_slaves < 0) {
5117                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5118                 return;
5119         }
5120         if (num_active_slaves > 0) {
5121                 printf("\tActive Slaves (%d): [", num_active_slaves);
5122                 for (i = 0; i < num_active_slaves - 1; i++)
5123                         printf("%d ", slaves[i]);
5124
5125                 printf("%d]\n", slaves[num_active_slaves - 1]);
5126
5127         } else {
5128                 printf("\tActive Slaves: []\n");
5129
5130         }
5131
5132         primary_id = rte_eth_bond_primary_get(port_id);
5133         if (primary_id < 0) {
5134                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5135                 return;
5136         } else
5137                 printf("\tPrimary: [%d]\n", primary_id);
5138
5139 }
5140
5141 cmdline_parse_token_string_t cmd_showbonding_config_show =
5142 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5143                 show, "show");
5144 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5145 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5146                 bonding, "bonding");
5147 cmdline_parse_token_string_t cmd_showbonding_config_config =
5148 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5149                 config, "config");
5150 cmdline_parse_token_num_t cmd_showbonding_config_port =
5151 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5152                 port_id, UINT16);
5153
5154 cmdline_parse_inst_t cmd_show_bonding_config = {
5155                 .f = cmd_show_bonding_config_parsed,
5156                 .help_str = "show bonding config <port_id>: "
5157                         "Show the bonding config for port_id",
5158                 .data = NULL,
5159                 .tokens = {
5160                                 (void *)&cmd_showbonding_config_show,
5161                                 (void *)&cmd_showbonding_config_bonding,
5162                                 (void *)&cmd_showbonding_config_config,
5163                                 (void *)&cmd_showbonding_config_port,
5164                                 NULL
5165                 }
5166 };
5167
5168 /* *** SET BONDING PRIMARY *** */
5169 struct cmd_set_bonding_primary_result {
5170         cmdline_fixed_string_t set;
5171         cmdline_fixed_string_t bonding;
5172         cmdline_fixed_string_t primary;
5173         portid_t slave_id;
5174         portid_t port_id;
5175 };
5176
5177 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5178                 __attribute__((unused))  struct cmdline *cl,
5179                 __attribute__((unused)) void *data)
5180 {
5181         struct cmd_set_bonding_primary_result *res = parsed_result;
5182         portid_t master_port_id = res->port_id;
5183         portid_t slave_port_id = res->slave_id;
5184
5185         /* Set the primary slave for a bonded device. */
5186         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5187                 printf("\t Failed to set primary slave for port = %d.\n",
5188                                 master_port_id);
5189                 return;
5190         }
5191         init_port_config();
5192 }
5193
5194 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5195 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5196                 set, "set");
5197 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5198 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5199                 bonding, "bonding");
5200 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5201 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5202                 primary, "primary");
5203 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5204 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5205                 slave_id, UINT16);
5206 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5207 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5208                 port_id, UINT16);
5209
5210 cmdline_parse_inst_t cmd_set_bonding_primary = {
5211                 .f = cmd_set_bonding_primary_parsed,
5212                 .help_str = "set bonding primary <slave_id> <port_id>: "
5213                         "Set the primary slave for port_id",
5214                 .data = NULL,
5215                 .tokens = {
5216                                 (void *)&cmd_setbonding_primary_set,
5217                                 (void *)&cmd_setbonding_primary_bonding,
5218                                 (void *)&cmd_setbonding_primary_primary,
5219                                 (void *)&cmd_setbonding_primary_slave,
5220                                 (void *)&cmd_setbonding_primary_port,
5221                                 NULL
5222                 }
5223 };
5224
5225 /* *** ADD SLAVE *** */
5226 struct cmd_add_bonding_slave_result {
5227         cmdline_fixed_string_t add;
5228         cmdline_fixed_string_t bonding;
5229         cmdline_fixed_string_t slave;
5230         portid_t slave_id;
5231         portid_t port_id;
5232 };
5233
5234 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5235                 __attribute__((unused))  struct cmdline *cl,
5236                 __attribute__((unused)) void *data)
5237 {
5238         struct cmd_add_bonding_slave_result *res = parsed_result;
5239         portid_t master_port_id = res->port_id;
5240         portid_t slave_port_id = res->slave_id;
5241
5242         /* add the slave for a bonded device. */
5243         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5244                 printf("\t Failed to add slave %d to master port = %d.\n",
5245                                 slave_port_id, master_port_id);
5246                 return;
5247         }
5248         init_port_config();
5249         set_port_slave_flag(slave_port_id);
5250 }
5251
5252 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5253 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5254                 add, "add");
5255 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5256 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5257                 bonding, "bonding");
5258 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5259 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5260                 slave, "slave");
5261 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5262 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5263                 slave_id, UINT16);
5264 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5265 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5266                 port_id, UINT16);
5267
5268 cmdline_parse_inst_t cmd_add_bonding_slave = {
5269                 .f = cmd_add_bonding_slave_parsed,
5270                 .help_str = "add bonding slave <slave_id> <port_id>: "
5271                         "Add a slave device to a bonded device",
5272                 .data = NULL,
5273                 .tokens = {
5274                                 (void *)&cmd_addbonding_slave_add,
5275                                 (void *)&cmd_addbonding_slave_bonding,
5276                                 (void *)&cmd_addbonding_slave_slave,
5277                                 (void *)&cmd_addbonding_slave_slaveid,
5278                                 (void *)&cmd_addbonding_slave_port,
5279                                 NULL
5280                 }
5281 };
5282
5283 /* *** REMOVE SLAVE *** */
5284 struct cmd_remove_bonding_slave_result {
5285         cmdline_fixed_string_t remove;
5286         cmdline_fixed_string_t bonding;
5287         cmdline_fixed_string_t slave;
5288         portid_t slave_id;
5289         portid_t port_id;
5290 };
5291
5292 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5293                 __attribute__((unused))  struct cmdline *cl,
5294                 __attribute__((unused)) void *data)
5295 {
5296         struct cmd_remove_bonding_slave_result *res = parsed_result;
5297         portid_t master_port_id = res->port_id;
5298         portid_t slave_port_id = res->slave_id;
5299
5300         /* remove the slave from a bonded device. */
5301         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5302                 printf("\t Failed to remove slave %d from master port = %d.\n",
5303                                 slave_port_id, master_port_id);
5304                 return;
5305         }
5306         init_port_config();
5307         clear_port_slave_flag(slave_port_id);
5308 }
5309
5310 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5311                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5312                                 remove, "remove");
5313 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5314                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5315                                 bonding, "bonding");
5316 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5317                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5318                                 slave, "slave");
5319 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5320                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5321                                 slave_id, UINT16);
5322 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5323                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5324                                 port_id, UINT16);
5325
5326 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5327                 .f = cmd_remove_bonding_slave_parsed,
5328                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5329                         "Remove a slave device from a bonded device",
5330                 .data = NULL,
5331                 .tokens = {
5332                                 (void *)&cmd_removebonding_slave_remove,
5333                                 (void *)&cmd_removebonding_slave_bonding,
5334                                 (void *)&cmd_removebonding_slave_slave,
5335                                 (void *)&cmd_removebonding_slave_slaveid,
5336                                 (void *)&cmd_removebonding_slave_port,
5337                                 NULL
5338                 }
5339 };
5340
5341 /* *** CREATE BONDED DEVICE *** */
5342 struct cmd_create_bonded_device_result {
5343         cmdline_fixed_string_t create;
5344         cmdline_fixed_string_t bonded;
5345         cmdline_fixed_string_t device;
5346         uint8_t mode;
5347         uint8_t socket;
5348 };
5349
5350 static int bond_dev_num = 0;
5351
5352 static void cmd_create_bonded_device_parsed(void *parsed_result,
5353                 __attribute__((unused))  struct cmdline *cl,
5354                 __attribute__((unused)) void *data)
5355 {
5356         struct cmd_create_bonded_device_result *res = parsed_result;
5357         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5358         int port_id;
5359
5360         if (test_done == 0) {
5361                 printf("Please stop forwarding first\n");
5362                 return;
5363         }
5364
5365         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5366                         bond_dev_num++);
5367
5368         /* Create a new bonded device. */
5369         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5370         if (port_id < 0) {
5371                 printf("\t Failed to create bonded device.\n");
5372                 return;
5373         } else {
5374                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5375                                 port_id);
5376
5377                 /* Update number of ports */
5378                 nb_ports = rte_eth_dev_count();
5379                 reconfig(port_id, res->socket);
5380                 rte_eth_promiscuous_enable(port_id);
5381         }
5382
5383 }
5384
5385 cmdline_parse_token_string_t cmd_createbonded_device_create =
5386                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5387                                 create, "create");
5388 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5389                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5390                                 bonded, "bonded");
5391 cmdline_parse_token_string_t cmd_createbonded_device_device =
5392                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5393                                 device, "device");
5394 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5395                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5396                                 mode, UINT8);
5397 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5398                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5399                                 socket, UINT8);
5400
5401 cmdline_parse_inst_t cmd_create_bonded_device = {
5402                 .f = cmd_create_bonded_device_parsed,
5403                 .help_str = "create bonded device <mode> <socket>: "
5404                         "Create a new bonded device with specific bonding mode and socket",
5405                 .data = NULL,
5406                 .tokens = {
5407                                 (void *)&cmd_createbonded_device_create,
5408                                 (void *)&cmd_createbonded_device_bonded,
5409                                 (void *)&cmd_createbonded_device_device,
5410                                 (void *)&cmd_createbonded_device_mode,
5411                                 (void *)&cmd_createbonded_device_socket,
5412                                 NULL
5413                 }
5414 };
5415
5416 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5417 struct cmd_set_bond_mac_addr_result {
5418         cmdline_fixed_string_t set;
5419         cmdline_fixed_string_t bonding;
5420         cmdline_fixed_string_t mac_addr;
5421         uint16_t port_num;
5422         struct ether_addr address;
5423 };
5424
5425 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5426                 __attribute__((unused))  struct cmdline *cl,
5427                 __attribute__((unused)) void *data)
5428 {
5429         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5430         int ret;
5431
5432         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5433                 return;
5434
5435         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5436
5437         /* check the return value and print it if is < 0 */
5438         if (ret < 0)
5439                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5440 }
5441
5442 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5443                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5444 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5445                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5446                                 "bonding");
5447 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5448                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5449                                 "mac_addr");
5450 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5451                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5452                                 port_num, UINT16);
5453 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5454                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5455
5456 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5457                 .f = cmd_set_bond_mac_addr_parsed,
5458                 .data = (void *) 0,
5459                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5460                 .tokens = {
5461                                 (void *)&cmd_set_bond_mac_addr_set,
5462                                 (void *)&cmd_set_bond_mac_addr_bonding,
5463                                 (void *)&cmd_set_bond_mac_addr_mac,
5464                                 (void *)&cmd_set_bond_mac_addr_portnum,
5465                                 (void *)&cmd_set_bond_mac_addr_addr,
5466                                 NULL
5467                 }
5468 };
5469
5470
5471 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5472 struct cmd_set_bond_mon_period_result {
5473         cmdline_fixed_string_t set;
5474         cmdline_fixed_string_t bonding;
5475         cmdline_fixed_string_t mon_period;
5476         uint16_t port_num;
5477         uint32_t period_ms;
5478 };
5479
5480 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5481                 __attribute__((unused))  struct cmdline *cl,
5482                 __attribute__((unused)) void *data)
5483 {
5484         struct cmd_set_bond_mon_period_result *res = parsed_result;
5485         int ret;
5486
5487         if (res->port_num >= nb_ports) {
5488                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5489                 return;
5490         }
5491
5492         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5493
5494         /* check the return value and print it if is < 0 */
5495         if (ret < 0)
5496                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5497 }
5498
5499 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5500                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5501                                 set, "set");
5502 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5503                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5504                                 bonding, "bonding");
5505 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5506                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5507                                 mon_period,     "mon_period");
5508 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5509                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5510                                 port_num, UINT16);
5511 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5512                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5513                                 period_ms, UINT32);
5514
5515 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5516                 .f = cmd_set_bond_mon_period_parsed,
5517                 .data = (void *) 0,
5518                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5519                 .tokens = {
5520                                 (void *)&cmd_set_bond_mon_period_set,
5521                                 (void *)&cmd_set_bond_mon_period_bonding,
5522                                 (void *)&cmd_set_bond_mon_period_mon_period,
5523                                 (void *)&cmd_set_bond_mon_period_portnum,
5524                                 (void *)&cmd_set_bond_mon_period_period_ms,
5525                                 NULL
5526                 }
5527 };
5528
5529
5530
5531 struct cmd_set_bonding_agg_mode_policy_result {
5532         cmdline_fixed_string_t set;
5533         cmdline_fixed_string_t bonding;
5534         cmdline_fixed_string_t agg_mode;
5535         uint16_t port_num;
5536         cmdline_fixed_string_t policy;
5537 };
5538
5539
5540 static void
5541 cmd_set_bonding_agg_mode(void *parsed_result,
5542                 __attribute__((unused)) struct cmdline *cl,
5543                 __attribute__((unused)) void *data)
5544 {
5545         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5546         uint8_t policy = AGG_BANDWIDTH;
5547
5548         if (res->port_num >= nb_ports) {
5549                 printf("Port id %d must be less than %d\n",
5550                                 res->port_num, nb_ports);
5551                 return;
5552         }
5553
5554         if (!strcmp(res->policy, "bandwidth"))
5555                 policy = AGG_BANDWIDTH;
5556         else if (!strcmp(res->policy, "stable"))
5557                 policy = AGG_STABLE;
5558         else if (!strcmp(res->policy, "count"))
5559                 policy = AGG_COUNT;
5560
5561         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5562 }
5563
5564
5565 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5566         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5567                                 set, "set");
5568 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5569         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5570                                 bonding, "bonding");
5571
5572 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5573         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5574                                 agg_mode, "agg_mode");
5575
5576 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5577         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5578                                 port_num, UINT16);
5579
5580 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5581         TOKEN_STRING_INITIALIZER(
5582                         struct cmd_set_bonding_balance_xmit_policy_result,
5583                 policy, "stable#bandwidth#count");
5584
5585 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5586         .f = cmd_set_bonding_agg_mode,
5587         .data = (void *) 0,
5588         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5589         .tokens = {
5590                         (void *)&cmd_set_bonding_agg_mode_set,
5591                         (void *)&cmd_set_bonding_agg_mode_bonding,
5592                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5593                         (void *)&cmd_set_bonding_agg_mode_portnum,
5594                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5595                         NULL
5596                 }
5597 };
5598
5599
5600 #endif /* RTE_LIBRTE_PMD_BOND */
5601
5602 /* *** SET FORWARDING MODE *** */
5603 struct cmd_set_fwd_mode_result {
5604         cmdline_fixed_string_t set;
5605         cmdline_fixed_string_t fwd;
5606         cmdline_fixed_string_t mode;
5607 };
5608
5609 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5610                                     __attribute__((unused)) struct cmdline *cl,
5611                                     __attribute__((unused)) void *data)
5612 {
5613         struct cmd_set_fwd_mode_result *res = parsed_result;
5614
5615         retry_enabled = 0;
5616         set_pkt_forwarding_mode(res->mode);
5617 }
5618
5619 cmdline_parse_token_string_t cmd_setfwd_set =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5621 cmdline_parse_token_string_t cmd_setfwd_fwd =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5623 cmdline_parse_token_string_t cmd_setfwd_mode =
5624         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5625                 "" /* defined at init */);
5626
5627 cmdline_parse_inst_t cmd_set_fwd_mode = {
5628         .f = cmd_set_fwd_mode_parsed,
5629         .data = NULL,
5630         .help_str = NULL, /* defined at init */
5631         .tokens = {
5632                 (void *)&cmd_setfwd_set,
5633                 (void *)&cmd_setfwd_fwd,
5634                 (void *)&cmd_setfwd_mode,
5635                 NULL,
5636         },
5637 };
5638
5639 static void cmd_set_fwd_mode_init(void)
5640 {
5641         char *modes, *c;
5642         static char token[128];
5643         static char help[256];
5644         cmdline_parse_token_string_t *token_struct;
5645
5646         modes = list_pkt_forwarding_modes();
5647         snprintf(help, sizeof(help), "set fwd %s: "
5648                 "Set packet forwarding mode", modes);
5649         cmd_set_fwd_mode.help_str = help;
5650
5651         /* string token separator is # */
5652         for (c = token; *modes != '\0'; modes++)
5653                 if (*modes == '|')
5654                         *c++ = '#';
5655                 else
5656                         *c++ = *modes;
5657         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5658         token_struct->string_data.str = token;
5659 }
5660
5661 /* *** SET RETRY FORWARDING MODE *** */
5662 struct cmd_set_fwd_retry_mode_result {
5663         cmdline_fixed_string_t set;
5664         cmdline_fixed_string_t fwd;
5665         cmdline_fixed_string_t mode;
5666         cmdline_fixed_string_t retry;
5667 };
5668
5669 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5670                             __attribute__((unused)) struct cmdline *cl,
5671                             __attribute__((unused)) void *data)
5672 {
5673         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5674
5675         retry_enabled = 1;
5676         set_pkt_forwarding_mode(res->mode);
5677 }
5678
5679 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5680         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5681                         set, "set");
5682 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5683         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5684                         fwd, "fwd");
5685 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5686         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5687                         mode,
5688                 "" /* defined at init */);
5689 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5691                         retry, "retry");
5692
5693 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5694         .f = cmd_set_fwd_retry_mode_parsed,
5695         .data = NULL,
5696         .help_str = NULL, /* defined at init */
5697         .tokens = {
5698                 (void *)&cmd_setfwd_retry_set,
5699                 (void *)&cmd_setfwd_retry_fwd,
5700                 (void *)&cmd_setfwd_retry_mode,
5701                 (void *)&cmd_setfwd_retry_retry,
5702                 NULL,
5703         },
5704 };
5705
5706 static void cmd_set_fwd_retry_mode_init(void)
5707 {
5708         char *modes, *c;
5709         static char token[128];
5710         static char help[256];
5711         cmdline_parse_token_string_t *token_struct;
5712
5713         modes = list_pkt_forwarding_retry_modes();
5714         snprintf(help, sizeof(help), "set fwd %s retry: "
5715                 "Set packet forwarding mode with retry", modes);
5716         cmd_set_fwd_retry_mode.help_str = help;
5717
5718         /* string token separator is # */
5719         for (c = token; *modes != '\0'; modes++)
5720                 if (*modes == '|')
5721                         *c++ = '#';
5722                 else
5723                         *c++ = *modes;
5724         token_struct = (cmdline_parse_token_string_t *)
5725                 cmd_set_fwd_retry_mode.tokens[2];
5726         token_struct->string_data.str = token;
5727 }
5728
5729 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5730 struct cmd_set_burst_tx_retry_result {
5731         cmdline_fixed_string_t set;
5732         cmdline_fixed_string_t burst;
5733         cmdline_fixed_string_t tx;
5734         cmdline_fixed_string_t delay;
5735         uint32_t time;
5736         cmdline_fixed_string_t retry;
5737         uint32_t retry_num;
5738 };
5739
5740 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5741                                         __attribute__((unused)) struct cmdline *cl,
5742                                         __attribute__((unused)) void *data)
5743 {
5744         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5745
5746         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5747                 && !strcmp(res->tx, "tx")) {
5748                 if (!strcmp(res->delay, "delay"))
5749                         burst_tx_delay_time = res->time;
5750                 if (!strcmp(res->retry, "retry"))
5751                         burst_tx_retry_num = res->retry_num;
5752         }
5753
5754 }
5755
5756 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5757         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5758 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5759         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5760                                  "burst");
5761 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5762         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5763 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5765 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5766         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5767 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5768         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5769 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5770         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5771
5772 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5773         .f = cmd_set_burst_tx_retry_parsed,
5774         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5775         .tokens = {
5776                 (void *)&cmd_set_burst_tx_retry_set,
5777                 (void *)&cmd_set_burst_tx_retry_burst,
5778                 (void *)&cmd_set_burst_tx_retry_tx,
5779                 (void *)&cmd_set_burst_tx_retry_delay,
5780                 (void *)&cmd_set_burst_tx_retry_time,
5781                 (void *)&cmd_set_burst_tx_retry_retry,
5782                 (void *)&cmd_set_burst_tx_retry_retry_num,
5783                 NULL,
5784         },
5785 };
5786
5787 /* *** SET PROMISC MODE *** */
5788 struct cmd_set_promisc_mode_result {
5789         cmdline_fixed_string_t set;
5790         cmdline_fixed_string_t promisc;
5791         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5792         uint16_t port_num;               /* valid if "allports" argument == 0 */
5793         cmdline_fixed_string_t mode;
5794 };
5795
5796 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5797                                         __attribute__((unused)) struct cmdline *cl,
5798                                         void *allports)
5799 {
5800         struct cmd_set_promisc_mode_result *res = parsed_result;
5801         int enable;
5802         portid_t i;
5803
5804         if (!strcmp(res->mode, "on"))
5805                 enable = 1;
5806         else
5807                 enable = 0;
5808
5809         /* all ports */
5810         if (allports) {
5811                 RTE_ETH_FOREACH_DEV(i) {
5812                         if (enable)
5813                                 rte_eth_promiscuous_enable(i);
5814                         else
5815                                 rte_eth_promiscuous_disable(i);
5816                 }
5817         }
5818         else {
5819                 if (enable)
5820                         rte_eth_promiscuous_enable(res->port_num);
5821                 else
5822                         rte_eth_promiscuous_disable(res->port_num);
5823         }
5824 }
5825
5826 cmdline_parse_token_string_t cmd_setpromisc_set =
5827         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5828 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5829         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5830                                  "promisc");
5831 cmdline_parse_token_string_t cmd_setpromisc_portall =
5832         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5833                                  "all");
5834 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5835         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5836                               UINT8);
5837 cmdline_parse_token_string_t cmd_setpromisc_mode =
5838         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5839                                  "on#off");
5840
5841 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5842         .f = cmd_set_promisc_mode_parsed,
5843         .data = (void *)1,
5844         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5845         .tokens = {
5846                 (void *)&cmd_setpromisc_set,
5847                 (void *)&cmd_setpromisc_promisc,
5848                 (void *)&cmd_setpromisc_portall,
5849                 (void *)&cmd_setpromisc_mode,
5850                 NULL,
5851         },
5852 };
5853
5854 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5855         .f = cmd_set_promisc_mode_parsed,
5856         .data = (void *)0,
5857         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5858         .tokens = {
5859                 (void *)&cmd_setpromisc_set,
5860                 (void *)&cmd_setpromisc_promisc,
5861                 (void *)&cmd_setpromisc_portnum,
5862                 (void *)&cmd_setpromisc_mode,
5863                 NULL,
5864         },
5865 };
5866
5867 /* *** SET ALLMULTI MODE *** */
5868 struct cmd_set_allmulti_mode_result {
5869         cmdline_fixed_string_t set;
5870         cmdline_fixed_string_t allmulti;
5871         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5872         uint16_t port_num;               /* valid if "allports" argument == 0 */
5873         cmdline_fixed_string_t mode;
5874 };
5875
5876 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5877                                         __attribute__((unused)) struct cmdline *cl,
5878                                         void *allports)
5879 {
5880         struct cmd_set_allmulti_mode_result *res = parsed_result;
5881         int enable;
5882         portid_t i;
5883
5884         if (!strcmp(res->mode, "on"))
5885                 enable = 1;
5886         else
5887                 enable = 0;
5888
5889         /* all ports */
5890         if (allports) {
5891                 RTE_ETH_FOREACH_DEV(i) {
5892                         if (enable)
5893                                 rte_eth_allmulticast_enable(i);
5894                         else
5895                                 rte_eth_allmulticast_disable(i);
5896                 }
5897         }
5898         else {
5899                 if (enable)
5900                         rte_eth_allmulticast_enable(res->port_num);
5901                 else
5902                         rte_eth_allmulticast_disable(res->port_num);
5903         }
5904 }
5905
5906 cmdline_parse_token_string_t cmd_setallmulti_set =
5907         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5908 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5909         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5910                                  "allmulti");
5911 cmdline_parse_token_string_t cmd_setallmulti_portall =
5912         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5913                                  "all");
5914 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5915         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5916                               UINT16);
5917 cmdline_parse_token_string_t cmd_setallmulti_mode =
5918         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5919                                  "on#off");
5920
5921 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5922         .f = cmd_set_allmulti_mode_parsed,
5923         .data = (void *)1,
5924         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5925         .tokens = {
5926                 (void *)&cmd_setallmulti_set,
5927                 (void *)&cmd_setallmulti_allmulti,
5928                 (void *)&cmd_setallmulti_portall,
5929                 (void *)&cmd_setallmulti_mode,
5930                 NULL,
5931         },
5932 };
5933
5934 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5935         .f = cmd_set_allmulti_mode_parsed,
5936         .data = (void *)0,
5937         .help_str = "set allmulti <port_id> on|off: "
5938                 "Set allmulti mode on port_id",
5939         .tokens = {
5940                 (void *)&cmd_setallmulti_set,
5941                 (void *)&cmd_setallmulti_allmulti,
5942                 (void *)&cmd_setallmulti_portnum,
5943                 (void *)&cmd_setallmulti_mode,
5944                 NULL,
5945         },
5946 };
5947
5948 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5949 struct cmd_link_flow_ctrl_set_result {
5950         cmdline_fixed_string_t set;
5951         cmdline_fixed_string_t flow_ctrl;
5952         cmdline_fixed_string_t rx;
5953         cmdline_fixed_string_t rx_lfc_mode;
5954         cmdline_fixed_string_t tx;
5955         cmdline_fixed_string_t tx_lfc_mode;
5956         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5957         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5958         cmdline_fixed_string_t autoneg_str;
5959         cmdline_fixed_string_t autoneg;
5960         cmdline_fixed_string_t hw_str;
5961         uint32_t high_water;
5962         cmdline_fixed_string_t lw_str;
5963         uint32_t low_water;
5964         cmdline_fixed_string_t pt_str;
5965         uint16_t pause_time;
5966         cmdline_fixed_string_t xon_str;
5967         uint16_t send_xon;
5968         portid_t port_id;
5969 };
5970
5971 cmdline_parse_token_string_t cmd_lfc_set_set =
5972         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5973                                 set, "set");
5974 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5975         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5976                                 flow_ctrl, "flow_ctrl");
5977 cmdline_parse_token_string_t cmd_lfc_set_rx =
5978         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5979                                 rx, "rx");
5980 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5981         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5982                                 rx_lfc_mode, "on#off");
5983 cmdline_parse_token_string_t cmd_lfc_set_tx =
5984         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5985                                 tx, "tx");
5986 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5987         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5988                                 tx_lfc_mode, "on#off");
5989 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5990         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5991                                 hw_str, "high_water");
5992 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5993         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5994                                 high_water, UINT32);
5995 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5996         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5997                                 lw_str, "low_water");
5998 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5999         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6000                                 low_water, UINT32);
6001 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6002         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6003                                 pt_str, "pause_time");
6004 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6005         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6006                                 pause_time, UINT16);
6007 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6008         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6009                                 xon_str, "send_xon");
6010 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6011         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6012                                 send_xon, UINT16);
6013 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6014         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6015                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6016 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6017         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6018                                 mac_ctrl_frame_fwd_mode, "on#off");
6019 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6020         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6021                                 autoneg_str, "autoneg");
6022 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6023         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6024                                 autoneg, "on#off");
6025 cmdline_parse_token_num_t cmd_lfc_set_portid =
6026         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6027                                 port_id, UINT16);
6028
6029 /* forward declaration */
6030 static void
6031 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6032                               void *data);
6033
6034 cmdline_parse_inst_t cmd_link_flow_control_set = {
6035         .f = cmd_link_flow_ctrl_set_parsed,
6036         .data = NULL,
6037         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6038                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6039                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6040         .tokens = {
6041                 (void *)&cmd_lfc_set_set,
6042                 (void *)&cmd_lfc_set_flow_ctrl,
6043                 (void *)&cmd_lfc_set_rx,
6044                 (void *)&cmd_lfc_set_rx_mode,
6045                 (void *)&cmd_lfc_set_tx,
6046                 (void *)&cmd_lfc_set_tx_mode,
6047                 (void *)&cmd_lfc_set_high_water,
6048                 (void *)&cmd_lfc_set_low_water,
6049                 (void *)&cmd_lfc_set_pause_time,
6050                 (void *)&cmd_lfc_set_send_xon,
6051                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6052                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6053                 (void *)&cmd_lfc_set_autoneg_str,
6054                 (void *)&cmd_lfc_set_autoneg,
6055                 (void *)&cmd_lfc_set_portid,
6056                 NULL,
6057         },
6058 };
6059
6060 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6061         .f = cmd_link_flow_ctrl_set_parsed,
6062         .data = (void *)&cmd_link_flow_control_set_rx,
6063         .help_str = "set flow_ctrl rx on|off <port_id>: "
6064                 "Change rx flow control parameter",
6065         .tokens = {
6066                 (void *)&cmd_lfc_set_set,
6067                 (void *)&cmd_lfc_set_flow_ctrl,
6068                 (void *)&cmd_lfc_set_rx,
6069                 (void *)&cmd_lfc_set_rx_mode,
6070                 (void *)&cmd_lfc_set_portid,
6071                 NULL,
6072         },
6073 };
6074
6075 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6076         .f = cmd_link_flow_ctrl_set_parsed,
6077         .data = (void *)&cmd_link_flow_control_set_tx,
6078         .help_str = "set flow_ctrl tx on|off <port_id>: "
6079                 "Change tx flow control parameter",
6080         .tokens = {
6081                 (void *)&cmd_lfc_set_set,
6082                 (void *)&cmd_lfc_set_flow_ctrl,
6083                 (void *)&cmd_lfc_set_tx,
6084                 (void *)&cmd_lfc_set_tx_mode,
6085                 (void *)&cmd_lfc_set_portid,
6086                 NULL,
6087         },
6088 };
6089
6090 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6091         .f = cmd_link_flow_ctrl_set_parsed,
6092         .data = (void *)&cmd_link_flow_control_set_hw,
6093         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6094                 "Change high water flow control parameter",
6095         .tokens = {
6096                 (void *)&cmd_lfc_set_set,
6097                 (void *)&cmd_lfc_set_flow_ctrl,
6098                 (void *)&cmd_lfc_set_high_water_str,
6099                 (void *)&cmd_lfc_set_high_water,
6100                 (void *)&cmd_lfc_set_portid,
6101                 NULL,
6102         },
6103 };
6104
6105 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6106         .f = cmd_link_flow_ctrl_set_parsed,
6107         .data = (void *)&cmd_link_flow_control_set_lw,
6108         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6109                 "Change low water flow control parameter",
6110         .tokens = {
6111                 (void *)&cmd_lfc_set_set,
6112                 (void *)&cmd_lfc_set_flow_ctrl,
6113                 (void *)&cmd_lfc_set_low_water_str,
6114                 (void *)&cmd_lfc_set_low_water,
6115                 (void *)&cmd_lfc_set_portid,
6116                 NULL,
6117         },
6118 };
6119
6120 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6121         .f = cmd_link_flow_ctrl_set_parsed,
6122         .data = (void *)&cmd_link_flow_control_set_pt,
6123         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6124                 "Change pause time flow control parameter",
6125         .tokens = {
6126                 (void *)&cmd_lfc_set_set,
6127                 (void *)&cmd_lfc_set_flow_ctrl,
6128                 (void *)&cmd_lfc_set_pause_time_str,
6129                 (void *)&cmd_lfc_set_pause_time,
6130                 (void *)&cmd_lfc_set_portid,
6131                 NULL,
6132         },
6133 };
6134
6135 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6136         .f = cmd_link_flow_ctrl_set_parsed,
6137         .data = (void *)&cmd_link_flow_control_set_xon,
6138         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6139                 "Change send_xon flow control parameter",
6140         .tokens = {
6141                 (void *)&cmd_lfc_set_set,
6142                 (void *)&cmd_lfc_set_flow_ctrl,
6143                 (void *)&cmd_lfc_set_send_xon_str,
6144                 (void *)&cmd_lfc_set_send_xon,
6145                 (void *)&cmd_lfc_set_portid,
6146                 NULL,
6147         },
6148 };
6149
6150 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6151         .f = cmd_link_flow_ctrl_set_parsed,
6152         .data = (void *)&cmd_link_flow_control_set_macfwd,
6153         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6154                 "Change mac ctrl fwd flow control parameter",
6155         .tokens = {
6156                 (void *)&cmd_lfc_set_set,
6157                 (void *)&cmd_lfc_set_flow_ctrl,
6158                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6159                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6160                 (void *)&cmd_lfc_set_portid,
6161                 NULL,
6162         },
6163 };
6164
6165 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6166         .f = cmd_link_flow_ctrl_set_parsed,
6167         .data = (void *)&cmd_link_flow_control_set_autoneg,
6168         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6169                 "Change autoneg flow control parameter",
6170         .tokens = {
6171                 (void *)&cmd_lfc_set_set,
6172                 (void *)&cmd_lfc_set_flow_ctrl,
6173                 (void *)&cmd_lfc_set_autoneg_str,
6174                 (void *)&cmd_lfc_set_autoneg,
6175                 (void *)&cmd_lfc_set_portid,
6176                 NULL,
6177         },
6178 };
6179
6180 static void
6181 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6182                               __attribute__((unused)) struct cmdline *cl,
6183                               void *data)
6184 {
6185         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6186         cmdline_parse_inst_t *cmd = data;
6187         struct rte_eth_fc_conf fc_conf;
6188         int rx_fc_en = 0;
6189         int tx_fc_en = 0;
6190         int ret;
6191
6192         /*
6193          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6194          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6195          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6196          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6197          */
6198         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6199                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6200         };
6201
6202         /* Partial command line, retrieve current configuration */
6203         if (cmd) {
6204                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6205                 if (ret != 0) {
6206                         printf("cannot get current flow ctrl parameters, return"
6207                                "code = %d\n", ret);
6208                         return;
6209                 }
6210
6211                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6212                     (fc_conf.mode == RTE_FC_FULL))
6213                         rx_fc_en = 1;
6214                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6215                     (fc_conf.mode == RTE_FC_FULL))
6216                         tx_fc_en = 1;
6217         }
6218
6219         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6220                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6221
6222         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6223                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6224
6225         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6226
6227         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6228                 fc_conf.high_water = res->high_water;
6229
6230         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6231                 fc_conf.low_water = res->low_water;
6232
6233         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6234                 fc_conf.pause_time = res->pause_time;
6235
6236         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6237                 fc_conf.send_xon = res->send_xon;
6238
6239         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6240                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6241                         fc_conf.mac_ctrl_frame_fwd = 1;
6242                 else
6243                         fc_conf.mac_ctrl_frame_fwd = 0;
6244         }
6245
6246         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6247                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6248
6249         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6250         if (ret != 0)
6251                 printf("bad flow contrl parameter, return code = %d \n", ret);
6252 }
6253
6254 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6255 struct cmd_priority_flow_ctrl_set_result {
6256         cmdline_fixed_string_t set;
6257         cmdline_fixed_string_t pfc_ctrl;
6258         cmdline_fixed_string_t rx;
6259         cmdline_fixed_string_t rx_pfc_mode;
6260         cmdline_fixed_string_t tx;
6261         cmdline_fixed_string_t tx_pfc_mode;
6262         uint32_t high_water;
6263         uint32_t low_water;
6264         uint16_t pause_time;
6265         uint8_t  priority;
6266         portid_t port_id;
6267 };
6268
6269 static void
6270 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6271                        __attribute__((unused)) struct cmdline *cl,
6272                        __attribute__((unused)) void *data)
6273 {
6274         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6275         struct rte_eth_pfc_conf pfc_conf;
6276         int rx_fc_enable, tx_fc_enable;
6277         int ret;
6278
6279         /*
6280          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6281          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6282          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6283          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6284          */
6285         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6286                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6287         };
6288
6289         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6290         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6291         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6292         pfc_conf.fc.high_water = res->high_water;
6293         pfc_conf.fc.low_water  = res->low_water;
6294         pfc_conf.fc.pause_time = res->pause_time;
6295         pfc_conf.priority      = res->priority;
6296
6297         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6298         if (ret != 0)
6299                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6300 }
6301
6302 cmdline_parse_token_string_t cmd_pfc_set_set =
6303         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6304                                 set, "set");
6305 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6306         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6307                                 pfc_ctrl, "pfc_ctrl");
6308 cmdline_parse_token_string_t cmd_pfc_set_rx =
6309         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6310                                 rx, "rx");
6311 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6312         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6313                                 rx_pfc_mode, "on#off");
6314 cmdline_parse_token_string_t cmd_pfc_set_tx =
6315         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6316                                 tx, "tx");
6317 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6318         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6319                                 tx_pfc_mode, "on#off");
6320 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6321         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6322                                 high_water, UINT32);
6323 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6324         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6325                                 low_water, UINT32);
6326 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6327         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6328                                 pause_time, UINT16);
6329 cmdline_parse_token_num_t cmd_pfc_set_priority =
6330         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6331                                 priority, UINT8);
6332 cmdline_parse_token_num_t cmd_pfc_set_portid =
6333         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6334                                 port_id, UINT16);
6335
6336 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6337         .f = cmd_priority_flow_ctrl_set_parsed,
6338         .data = NULL,
6339         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6340                 "<pause_time> <priority> <port_id>: "
6341                 "Configure the Ethernet priority flow control",
6342         .tokens = {
6343                 (void *)&cmd_pfc_set_set,
6344                 (void *)&cmd_pfc_set_flow_ctrl,
6345                 (void *)&cmd_pfc_set_rx,
6346                 (void *)&cmd_pfc_set_rx_mode,
6347                 (void *)&cmd_pfc_set_tx,
6348                 (void *)&cmd_pfc_set_tx_mode,
6349                 (void *)&cmd_pfc_set_high_water,
6350                 (void *)&cmd_pfc_set_low_water,
6351                 (void *)&cmd_pfc_set_pause_time,
6352                 (void *)&cmd_pfc_set_priority,
6353                 (void *)&cmd_pfc_set_portid,
6354                 NULL,
6355         },
6356 };
6357
6358 /* *** RESET CONFIGURATION *** */
6359 struct cmd_reset_result {
6360         cmdline_fixed_string_t reset;
6361         cmdline_fixed_string_t def;
6362 };
6363
6364 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6365                              struct cmdline *cl,
6366                              __attribute__((unused)) void *data)
6367 {
6368         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6369         set_def_fwd_config();
6370 }
6371
6372 cmdline_parse_token_string_t cmd_reset_set =
6373         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6374 cmdline_parse_token_string_t cmd_reset_def =
6375         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6376                                  "default");
6377
6378 cmdline_parse_inst_t cmd_reset = {
6379         .f = cmd_reset_parsed,
6380         .data = NULL,
6381         .help_str = "set default: Reset default forwarding configuration",
6382         .tokens = {
6383                 (void *)&cmd_reset_set,
6384                 (void *)&cmd_reset_def,
6385                 NULL,
6386         },
6387 };
6388
6389 /* *** START FORWARDING *** */
6390 struct cmd_start_result {
6391         cmdline_fixed_string_t start;
6392 };
6393
6394 cmdline_parse_token_string_t cmd_start_start =
6395         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6396
6397 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6398                              __attribute__((unused)) struct cmdline *cl,
6399                              __attribute__((unused)) void *data)
6400 {
6401         start_packet_forwarding(0);
6402 }
6403
6404 cmdline_parse_inst_t cmd_start = {
6405         .f = cmd_start_parsed,
6406         .data = NULL,
6407         .help_str = "start: Start packet forwarding",
6408         .tokens = {
6409                 (void *)&cmd_start_start,
6410                 NULL,
6411         },
6412 };
6413
6414 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6415 struct cmd_start_tx_first_result {
6416         cmdline_fixed_string_t start;
6417         cmdline_fixed_string_t tx_first;
6418 };
6419
6420 static void
6421 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6422                           __attribute__((unused)) struct cmdline *cl,
6423                           __attribute__((unused)) void *data)
6424 {
6425         start_packet_forwarding(1);
6426 }
6427
6428 cmdline_parse_token_string_t cmd_start_tx_first_start =
6429         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6430                                  "start");
6431 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6432         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6433                                  tx_first, "tx_first");
6434
6435 cmdline_parse_inst_t cmd_start_tx_first = {
6436         .f = cmd_start_tx_first_parsed,
6437         .data = NULL,
6438         .help_str = "start tx_first: Start packet forwarding, "
6439                 "after sending 1 burst of packets",
6440         .tokens = {
6441                 (void *)&cmd_start_tx_first_start,
6442                 (void *)&cmd_start_tx_first_tx_first,
6443                 NULL,
6444         },
6445 };
6446
6447 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6448 struct cmd_start_tx_first_n_result {
6449         cmdline_fixed_string_t start;
6450         cmdline_fixed_string_t tx_first;
6451         uint32_t tx_num;
6452 };
6453
6454 static void
6455 cmd_start_tx_first_n_parsed(void *parsed_result,
6456                           __attribute__((unused)) struct cmdline *cl,
6457                           __attribute__((unused)) void *data)
6458 {
6459         struct cmd_start_tx_first_n_result *res = parsed_result;
6460
6461         start_packet_forwarding(res->tx_num);
6462 }
6463
6464 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6465         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6466                         start, "start");
6467 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6468         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6469                         tx_first, "tx_first");
6470 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6471         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6472                         tx_num, UINT32);
6473
6474 cmdline_parse_inst_t cmd_start_tx_first_n = {
6475         .f = cmd_start_tx_first_n_parsed,
6476         .data = NULL,
6477         .help_str = "start tx_first <num>: "
6478                 "packet forwarding, after sending <num> bursts of packets",
6479         .tokens = {
6480                 (void *)&cmd_start_tx_first_n_start,
6481                 (void *)&cmd_start_tx_first_n_tx_first,
6482                 (void *)&cmd_start_tx_first_n_tx_num,
6483                 NULL,
6484         },
6485 };
6486
6487 /* *** SET LINK UP *** */
6488 struct cmd_set_link_up_result {
6489         cmdline_fixed_string_t set;
6490         cmdline_fixed_string_t link_up;
6491         cmdline_fixed_string_t port;
6492         portid_t port_id;
6493 };
6494
6495 cmdline_parse_token_string_t cmd_set_link_up_set =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6497 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6498         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6499                                 "link-up");
6500 cmdline_parse_token_string_t cmd_set_link_up_port =
6501         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6502 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6503         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6504
6505 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6506                              __attribute__((unused)) struct cmdline *cl,
6507                              __attribute__((unused)) void *data)
6508 {
6509         struct cmd_set_link_up_result *res = parsed_result;
6510         dev_set_link_up(res->port_id);
6511 }
6512
6513 cmdline_parse_inst_t cmd_set_link_up = {
6514         .f = cmd_set_link_up_parsed,
6515         .data = NULL,
6516         .help_str = "set link-up port <port id>",
6517         .tokens = {
6518                 (void *)&cmd_set_link_up_set,
6519                 (void *)&cmd_set_link_up_link_up,
6520                 (void *)&cmd_set_link_up_port,
6521                 (void *)&cmd_set_link_up_port_id,
6522                 NULL,
6523         },
6524 };
6525
6526 /* *** SET LINK DOWN *** */
6527 struct cmd_set_link_down_result {
6528         cmdline_fixed_string_t set;
6529         cmdline_fixed_string_t link_down;
6530         cmdline_fixed_string_t port;
6531         portid_t port_id;
6532 };
6533
6534 cmdline_parse_token_string_t cmd_set_link_down_set =
6535         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6536 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6537         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6538                                 "link-down");
6539 cmdline_parse_token_string_t cmd_set_link_down_port =
6540         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6541 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6542         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6543
6544 static void cmd_set_link_down_parsed(
6545                                 __attribute__((unused)) void *parsed_result,
6546                                 __attribute__((unused)) struct cmdline *cl,
6547                                 __attribute__((unused)) void *data)
6548 {
6549         struct cmd_set_link_down_result *res = parsed_result;
6550         dev_set_link_down(res->port_id);
6551 }
6552
6553 cmdline_parse_inst_t cmd_set_link_down = {
6554         .f = cmd_set_link_down_parsed,
6555         .data = NULL,
6556         .help_str = "set link-down port <port id>",
6557         .tokens = {
6558                 (void *)&cmd_set_link_down_set,
6559                 (void *)&cmd_set_link_down_link_down,
6560                 (void *)&cmd_set_link_down_port,
6561                 (void *)&cmd_set_link_down_port_id,
6562                 NULL,
6563         },
6564 };
6565
6566 /* *** SHOW CFG *** */
6567 struct cmd_showcfg_result {
6568         cmdline_fixed_string_t show;
6569         cmdline_fixed_string_t cfg;
6570         cmdline_fixed_string_t what;
6571 };
6572
6573 static void cmd_showcfg_parsed(void *parsed_result,
6574                                __attribute__((unused)) struct cmdline *cl,
6575                                __attribute__((unused)) void *data)
6576 {
6577         struct cmd_showcfg_result *res = parsed_result;
6578         if (!strcmp(res->what, "rxtx"))
6579                 rxtx_config_display();
6580         else if (!strcmp(res->what, "cores"))
6581                 fwd_lcores_config_display();
6582         else if (!strcmp(res->what, "fwd"))
6583                 pkt_fwd_config_display(&cur_fwd_config);
6584         else if (!strcmp(res->what, "txpkts"))
6585                 show_tx_pkt_segments();
6586 }
6587
6588 cmdline_parse_token_string_t cmd_showcfg_show =
6589         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6590 cmdline_parse_token_string_t cmd_showcfg_port =
6591         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6592 cmdline_parse_token_string_t cmd_showcfg_what =
6593         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6594                                  "rxtx#cores#fwd#txpkts");
6595
6596 cmdline_parse_inst_t cmd_showcfg = {
6597         .f = cmd_showcfg_parsed,
6598         .data = NULL,
6599         .help_str = "show config rxtx|cores|fwd|txpkts",
6600         .tokens = {
6601                 (void *)&cmd_showcfg_show,
6602                 (void *)&cmd_showcfg_port,
6603                 (void *)&cmd_showcfg_what,
6604                 NULL,
6605         },
6606 };
6607
6608 /* *** SHOW ALL PORT INFO *** */
6609 struct cmd_showportall_result {
6610         cmdline_fixed_string_t show;
6611         cmdline_fixed_string_t port;
6612         cmdline_fixed_string_t what;
6613         cmdline_fixed_string_t all;
6614 };
6615
6616 static void cmd_showportall_parsed(void *parsed_result,
6617                                 __attribute__((unused)) struct cmdline *cl,
6618                                 __attribute__((unused)) void *data)
6619 {
6620         portid_t i;
6621
6622         struct cmd_showportall_result *res = parsed_result;
6623         if (!strcmp(res->show, "clear")) {
6624                 if (!strcmp(res->what, "stats"))
6625                         RTE_ETH_FOREACH_DEV(i)
6626                                 nic_stats_clear(i);
6627                 else if (!strcmp(res->what, "xstats"))
6628                         RTE_ETH_FOREACH_DEV(i)
6629                                 nic_xstats_clear(i);
6630         } else if (!strcmp(res->what, "info"))
6631                 RTE_ETH_FOREACH_DEV(i)
6632                         port_infos_display(i);
6633         else if (!strcmp(res->what, "stats"))
6634                 RTE_ETH_FOREACH_DEV(i)
6635                         nic_stats_display(i);
6636         else if (!strcmp(res->what, "xstats"))
6637                 RTE_ETH_FOREACH_DEV(i)
6638                         nic_xstats_display(i);
6639         else if (!strcmp(res->what, "fdir"))
6640                 RTE_ETH_FOREACH_DEV(i)
6641                         fdir_get_infos(i);
6642         else if (!strcmp(res->what, "stat_qmap"))
6643                 RTE_ETH_FOREACH_DEV(i)
6644                         nic_stats_mapping_display(i);
6645         else if (!strcmp(res->what, "dcb_tc"))
6646                 RTE_ETH_FOREACH_DEV(i)
6647                         port_dcb_info_display(i);
6648         else if (!strcmp(res->what, "cap"))
6649                 RTE_ETH_FOREACH_DEV(i)
6650                         port_offload_cap_display(i);
6651 }
6652
6653 cmdline_parse_token_string_t cmd_showportall_show =
6654         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6655                                  "show#clear");
6656 cmdline_parse_token_string_t cmd_showportall_port =
6657         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6658 cmdline_parse_token_string_t cmd_showportall_what =
6659         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6660                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6661 cmdline_parse_token_string_t cmd_showportall_all =
6662         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6663 cmdline_parse_inst_t cmd_showportall = {
6664         .f = cmd_showportall_parsed,
6665         .data = NULL,
6666         .help_str = "show|clear port "
6667                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6668         .tokens = {
6669                 (void *)&cmd_showportall_show,
6670                 (void *)&cmd_showportall_port,
6671                 (void *)&cmd_showportall_what,
6672                 (void *)&cmd_showportall_all,
6673                 NULL,
6674         },
6675 };
6676
6677 /* *** SHOW PORT INFO *** */
6678 struct cmd_showport_result {
6679         cmdline_fixed_string_t show;
6680         cmdline_fixed_string_t port;
6681         cmdline_fixed_string_t what;
6682         uint16_t portnum;
6683 };
6684
6685 static void cmd_showport_parsed(void *parsed_result,
6686                                 __attribute__((unused)) struct cmdline *cl,
6687                                 __attribute__((unused)) void *data)
6688 {
6689         struct cmd_showport_result *res = parsed_result;
6690         if (!strcmp(res->show, "clear")) {
6691                 if (!strcmp(res->what, "stats"))
6692                         nic_stats_clear(res->portnum);
6693                 else if (!strcmp(res->what, "xstats"))
6694                         nic_xstats_clear(res->portnum);
6695         } else if (!strcmp(res->what, "info"))
6696                 port_infos_display(res->portnum);
6697         else if (!strcmp(res->what, "stats"))
6698                 nic_stats_display(res->portnum);
6699         else if (!strcmp(res->what, "xstats"))
6700                 nic_xstats_display(res->portnum);
6701         else if (!strcmp(res->what, "fdir"))
6702                  fdir_get_infos(res->portnum);
6703         else if (!strcmp(res->what, "stat_qmap"))
6704                 nic_stats_mapping_display(res->portnum);
6705         else if (!strcmp(res->what, "dcb_tc"))
6706                 port_dcb_info_display(res->portnum);
6707         else if (!strcmp(res->what, "cap"))
6708                 port_offload_cap_display(res->portnum);
6709 }
6710
6711 cmdline_parse_token_string_t cmd_showport_show =
6712         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6713                                  "show#clear");
6714 cmdline_parse_token_string_t cmd_showport_port =
6715         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6716 cmdline_parse_token_string_t cmd_showport_what =
6717         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6718                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6719 cmdline_parse_token_num_t cmd_showport_portnum =
6720         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6721
6722 cmdline_parse_inst_t cmd_showport = {
6723         .f = cmd_showport_parsed,
6724         .data = NULL,
6725         .help_str = "show|clear port "
6726                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6727                 "<port_id>",
6728         .tokens = {
6729                 (void *)&cmd_showport_show,
6730                 (void *)&cmd_showport_port,
6731                 (void *)&cmd_showport_what,
6732                 (void *)&cmd_showport_portnum,
6733                 NULL,
6734         },
6735 };
6736
6737 /* *** SHOW QUEUE INFO *** */
6738 struct cmd_showqueue_result {
6739         cmdline_fixed_string_t show;
6740         cmdline_fixed_string_t type;
6741         cmdline_fixed_string_t what;
6742         uint16_t portnum;
6743         uint16_t queuenum;
6744 };
6745
6746 static void
6747 cmd_showqueue_parsed(void *parsed_result,
6748         __attribute__((unused)) struct cmdline *cl,
6749         __attribute__((unused)) void *data)
6750 {
6751         struct cmd_showqueue_result *res = parsed_result;
6752
6753         if (!strcmp(res->type, "rxq"))
6754                 rx_queue_infos_display(res->portnum, res->queuenum);
6755         else if (!strcmp(res->type, "txq"))
6756                 tx_queue_infos_display(res->portnum, res->queuenum);
6757 }
6758
6759 cmdline_parse_token_string_t cmd_showqueue_show =
6760         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6761 cmdline_parse_token_string_t cmd_showqueue_type =
6762         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6763 cmdline_parse_token_string_t cmd_showqueue_what =
6764         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6765 cmdline_parse_token_num_t cmd_showqueue_portnum =
6766         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6767 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6768         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6769
6770 cmdline_parse_inst_t cmd_showqueue = {
6771         .f = cmd_showqueue_parsed,
6772         .data = NULL,
6773         .help_str = "show rxq|txq info <port_id> <queue_id>",
6774         .tokens = {
6775                 (void *)&cmd_showqueue_show,
6776                 (void *)&cmd_showqueue_type,
6777                 (void *)&cmd_showqueue_what,
6778                 (void *)&cmd_showqueue_portnum,
6779                 (void *)&cmd_showqueue_queuenum,
6780                 NULL,
6781         },
6782 };
6783
6784 /* *** READ PORT REGISTER *** */
6785 struct cmd_read_reg_result {
6786         cmdline_fixed_string_t read;
6787         cmdline_fixed_string_t reg;
6788         portid_t port_id;
6789         uint32_t reg_off;
6790 };
6791
6792 static void
6793 cmd_read_reg_parsed(void *parsed_result,
6794                     __attribute__((unused)) struct cmdline *cl,
6795                     __attribute__((unused)) void *data)
6796 {
6797         struct cmd_read_reg_result *res = parsed_result;
6798         port_reg_display(res->port_id, res->reg_off);
6799 }
6800
6801 cmdline_parse_token_string_t cmd_read_reg_read =
6802         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6803 cmdline_parse_token_string_t cmd_read_reg_reg =
6804         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6805 cmdline_parse_token_num_t cmd_read_reg_port_id =
6806         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6807 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6808         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6809
6810 cmdline_parse_inst_t cmd_read_reg = {
6811         .f = cmd_read_reg_parsed,
6812         .data = NULL,
6813         .help_str = "read reg <port_id> <reg_off>",
6814         .tokens = {
6815                 (void *)&cmd_read_reg_read,
6816                 (void *)&cmd_read_reg_reg,
6817                 (void *)&cmd_read_reg_port_id,
6818                 (void *)&cmd_read_reg_reg_off,
6819                 NULL,
6820         },
6821 };
6822
6823 /* *** READ PORT REGISTER BIT FIELD *** */
6824 struct cmd_read_reg_bit_field_result {
6825         cmdline_fixed_string_t read;
6826         cmdline_fixed_string_t regfield;
6827         portid_t port_id;
6828         uint32_t reg_off;
6829         uint8_t bit1_pos;
6830         uint8_t bit2_pos;
6831 };
6832
6833 static void
6834 cmd_read_reg_bit_field_parsed(void *parsed_result,
6835                               __attribute__((unused)) struct cmdline *cl,
6836                               __attribute__((unused)) void *data)
6837 {
6838         struct cmd_read_reg_bit_field_result *res = parsed_result;
6839         port_reg_bit_field_display(res->port_id, res->reg_off,
6840                                    res->bit1_pos, res->bit2_pos);
6841 }
6842
6843 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6844         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6845                                  "read");
6846 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6847         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6848                                  regfield, "regfield");
6849 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6850         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6851                               UINT16);
6852 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6853         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6854                               UINT32);
6855 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6856         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6857                               UINT8);
6858 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6859         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6860                               UINT8);
6861
6862 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6863         .f = cmd_read_reg_bit_field_parsed,
6864         .data = NULL,
6865         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6866         "Read register bit field between bit_x and bit_y included",
6867         .tokens = {
6868                 (void *)&cmd_read_reg_bit_field_read,
6869                 (void *)&cmd_read_reg_bit_field_regfield,
6870                 (void *)&cmd_read_reg_bit_field_port_id,
6871                 (void *)&cmd_read_reg_bit_field_reg_off,
6872                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6873                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6874                 NULL,
6875         },
6876 };
6877
6878 /* *** READ PORT REGISTER BIT *** */
6879 struct cmd_read_reg_bit_result {
6880         cmdline_fixed_string_t read;
6881         cmdline_fixed_string_t regbit;
6882         portid_t port_id;
6883         uint32_t reg_off;
6884         uint8_t bit_pos;
6885 };
6886
6887 static void
6888 cmd_read_reg_bit_parsed(void *parsed_result,
6889                         __attribute__((unused)) struct cmdline *cl,
6890                         __attribute__((unused)) void *data)
6891 {
6892         struct cmd_read_reg_bit_result *res = parsed_result;
6893         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6894 }
6895
6896 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6897         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6898 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6899         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6900                                  regbit, "regbit");
6901 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6902         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6903 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6904         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6905 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6907
6908 cmdline_parse_inst_t cmd_read_reg_bit = {
6909         .f = cmd_read_reg_bit_parsed,
6910         .data = NULL,
6911         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6912         .tokens = {
6913                 (void *)&cmd_read_reg_bit_read,
6914                 (void *)&cmd_read_reg_bit_regbit,
6915                 (void *)&cmd_read_reg_bit_port_id,
6916                 (void *)&cmd_read_reg_bit_reg_off,
6917                 (void *)&cmd_read_reg_bit_bit_pos,
6918                 NULL,
6919         },
6920 };
6921
6922 /* *** WRITE PORT REGISTER *** */
6923 struct cmd_write_reg_result {
6924         cmdline_fixed_string_t write;
6925         cmdline_fixed_string_t reg;
6926         portid_t port_id;
6927         uint32_t reg_off;
6928         uint32_t value;
6929 };
6930
6931 static void
6932 cmd_write_reg_parsed(void *parsed_result,
6933                      __attribute__((unused)) struct cmdline *cl,
6934                      __attribute__((unused)) void *data)
6935 {
6936         struct cmd_write_reg_result *res = parsed_result;
6937         port_reg_set(res->port_id, res->reg_off, res->value);
6938 }
6939
6940 cmdline_parse_token_string_t cmd_write_reg_write =
6941         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6942 cmdline_parse_token_string_t cmd_write_reg_reg =
6943         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6944 cmdline_parse_token_num_t cmd_write_reg_port_id =
6945         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6946 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6947         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6948 cmdline_parse_token_num_t cmd_write_reg_value =
6949         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6950
6951 cmdline_parse_inst_t cmd_write_reg = {
6952         .f = cmd_write_reg_parsed,
6953         .data = NULL,
6954         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6955         .tokens = {
6956                 (void *)&cmd_write_reg_write,
6957                 (void *)&cmd_write_reg_reg,
6958                 (void *)&cmd_write_reg_port_id,
6959                 (void *)&cmd_write_reg_reg_off,
6960                 (void *)&cmd_write_reg_value,
6961                 NULL,
6962         },
6963 };
6964
6965 /* *** WRITE PORT REGISTER BIT FIELD *** */
6966 struct cmd_write_reg_bit_field_result {
6967         cmdline_fixed_string_t write;
6968         cmdline_fixed_string_t regfield;
6969         portid_t port_id;
6970         uint32_t reg_off;
6971         uint8_t bit1_pos;
6972         uint8_t bit2_pos;
6973         uint32_t value;
6974 };
6975
6976 static void
6977 cmd_write_reg_bit_field_parsed(void *parsed_result,
6978                                __attribute__((unused)) struct cmdline *cl,
6979                                __attribute__((unused)) void *data)
6980 {
6981         struct cmd_write_reg_bit_field_result *res = parsed_result;
6982         port_reg_bit_field_set(res->port_id, res->reg_off,
6983                           res->bit1_pos, res->bit2_pos, res->value);
6984 }
6985
6986 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6987         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6988                                  "write");
6989 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6990         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6991                                  regfield, "regfield");
6992 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6994                               UINT16);
6995 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6997                               UINT32);
6998 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6999         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7000                               UINT8);
7001 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7002         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7003                               UINT8);
7004 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7005         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7006                               UINT32);
7007
7008 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7009         .f = cmd_write_reg_bit_field_parsed,
7010         .data = NULL,
7011         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7012                 "<reg_value>: "
7013                 "Set register bit field between bit_x and bit_y included",
7014         .tokens = {
7015                 (void *)&cmd_write_reg_bit_field_write,
7016                 (void *)&cmd_write_reg_bit_field_regfield,
7017                 (void *)&cmd_write_reg_bit_field_port_id,
7018                 (void *)&cmd_write_reg_bit_field_reg_off,
7019                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7020                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7021                 (void *)&cmd_write_reg_bit_field_value,
7022                 NULL,
7023         },
7024 };
7025
7026 /* *** WRITE PORT REGISTER BIT *** */
7027 struct cmd_write_reg_bit_result {
7028         cmdline_fixed_string_t write;
7029         cmdline_fixed_string_t regbit;
7030         portid_t port_id;
7031         uint32_t reg_off;
7032         uint8_t bit_pos;
7033         uint8_t value;
7034 };
7035
7036 static void
7037 cmd_write_reg_bit_parsed(void *parsed_result,
7038                          __attribute__((unused)) struct cmdline *cl,
7039                          __attribute__((unused)) void *data)
7040 {
7041         struct cmd_write_reg_bit_result *res = parsed_result;
7042         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7043 }
7044
7045 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7046         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7047                                  "write");
7048 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7049         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7050                                  regbit, "regbit");
7051 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7052         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7053 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7054         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7055 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7056         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7057 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7059
7060 cmdline_parse_inst_t cmd_write_reg_bit = {
7061         .f = cmd_write_reg_bit_parsed,
7062         .data = NULL,
7063         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7064                 "0 <= bit_x <= 31",
7065         .tokens = {
7066                 (void *)&cmd_write_reg_bit_write,
7067                 (void *)&cmd_write_reg_bit_regbit,
7068                 (void *)&cmd_write_reg_bit_port_id,
7069                 (void *)&cmd_write_reg_bit_reg_off,
7070                 (void *)&cmd_write_reg_bit_bit_pos,
7071                 (void *)&cmd_write_reg_bit_value,
7072                 NULL,
7073         },
7074 };
7075
7076 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7077 struct cmd_read_rxd_txd_result {
7078         cmdline_fixed_string_t read;
7079         cmdline_fixed_string_t rxd_txd;
7080         portid_t port_id;
7081         uint16_t queue_id;
7082         uint16_t desc_id;
7083 };
7084
7085 static void
7086 cmd_read_rxd_txd_parsed(void *parsed_result,
7087                         __attribute__((unused)) struct cmdline *cl,
7088                         __attribute__((unused)) void *data)
7089 {
7090         struct cmd_read_rxd_txd_result *res = parsed_result;
7091
7092         if (!strcmp(res->rxd_txd, "rxd"))
7093                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7094         else if (!strcmp(res->rxd_txd, "txd"))
7095                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7096 }
7097
7098 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7099         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7100 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7101         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7102                                  "rxd#txd");
7103 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7104         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7105 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7106         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7107 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7108         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7109
7110 cmdline_parse_inst_t cmd_read_rxd_txd = {
7111         .f = cmd_read_rxd_txd_parsed,
7112         .data = NULL,
7113         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7114         .tokens = {
7115                 (void *)&cmd_read_rxd_txd_read,
7116                 (void *)&cmd_read_rxd_txd_rxd_txd,
7117                 (void *)&cmd_read_rxd_txd_port_id,
7118                 (void *)&cmd_read_rxd_txd_queue_id,
7119                 (void *)&cmd_read_rxd_txd_desc_id,
7120                 NULL,
7121         },
7122 };
7123
7124 /* *** QUIT *** */
7125 struct cmd_quit_result {
7126         cmdline_fixed_string_t quit;
7127 };
7128
7129 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7130                             struct cmdline *cl,
7131                             __attribute__((unused)) void *data)
7132 {
7133         pmd_test_exit();
7134         cmdline_quit(cl);
7135 }
7136
7137 cmdline_parse_token_string_t cmd_quit_quit =
7138         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7139
7140 cmdline_parse_inst_t cmd_quit = {
7141         .f = cmd_quit_parsed,
7142         .data = NULL,
7143         .help_str = "quit: Exit application",
7144         .tokens = {
7145                 (void *)&cmd_quit_quit,
7146                 NULL,
7147         },
7148 };
7149
7150 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7151 struct cmd_mac_addr_result {
7152         cmdline_fixed_string_t mac_addr_cmd;
7153         cmdline_fixed_string_t what;
7154         uint16_t port_num;
7155         struct ether_addr address;
7156 };
7157
7158 static void cmd_mac_addr_parsed(void *parsed_result,
7159                 __attribute__((unused)) struct cmdline *cl,
7160                 __attribute__((unused)) void *data)
7161 {
7162         struct cmd_mac_addr_result *res = parsed_result;
7163         int ret;
7164
7165         if (strcmp(res->what, "add") == 0)
7166                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7167         else if (strcmp(res->what, "set") == 0)
7168                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7169                                                        &res->address);
7170         else
7171                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7172
7173         /* check the return value and print it if is < 0 */
7174         if(ret < 0)
7175                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7176
7177 }
7178
7179 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7180         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7181                                 "mac_addr");
7182 cmdline_parse_token_string_t cmd_mac_addr_what =
7183         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7184                                 "add#remove#set");
7185 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7186                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7187                                         UINT16);
7188 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7189                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7190
7191 cmdline_parse_inst_t cmd_mac_addr = {
7192         .f = cmd_mac_addr_parsed,
7193         .data = (void *)0,
7194         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7195                         "Add/Remove/Set MAC address on port_id",
7196         .tokens = {
7197                 (void *)&cmd_mac_addr_cmd,
7198                 (void *)&cmd_mac_addr_what,
7199                 (void *)&cmd_mac_addr_portnum,
7200                 (void *)&cmd_mac_addr_addr,
7201                 NULL,
7202         },
7203 };
7204
7205 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7206 struct cmd_eth_peer_result {
7207         cmdline_fixed_string_t set;
7208         cmdline_fixed_string_t eth_peer;
7209         portid_t port_id;
7210         cmdline_fixed_string_t peer_addr;
7211 };
7212
7213 static void cmd_set_eth_peer_parsed(void *parsed_result,
7214                         __attribute__((unused)) struct cmdline *cl,
7215                         __attribute__((unused)) void *data)
7216 {
7217                 struct cmd_eth_peer_result *res = parsed_result;
7218
7219                 if (test_done == 0) {
7220                         printf("Please stop forwarding first\n");
7221                         return;
7222                 }
7223                 if (!strcmp(res->eth_peer, "eth-peer")) {
7224                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7225                         fwd_config_setup();
7226                 }
7227 }
7228 cmdline_parse_token_string_t cmd_eth_peer_set =
7229         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7230 cmdline_parse_token_string_t cmd_eth_peer =
7231         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7232 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7233         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7234 cmdline_parse_token_string_t cmd_eth_peer_addr =
7235         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7236
7237 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7238         .f = cmd_set_eth_peer_parsed,
7239         .data = NULL,
7240         .help_str = "set eth-peer <port_id> <peer_mac>",
7241         .tokens = {
7242                 (void *)&cmd_eth_peer_set,
7243                 (void *)&cmd_eth_peer,
7244                 (void *)&cmd_eth_peer_port_id,
7245                 (void *)&cmd_eth_peer_addr,
7246                 NULL,
7247         },
7248 };
7249
7250 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7251 struct cmd_set_qmap_result {
7252         cmdline_fixed_string_t set;
7253         cmdline_fixed_string_t qmap;
7254         cmdline_fixed_string_t what;
7255         portid_t port_id;
7256         uint16_t queue_id;
7257         uint8_t map_value;
7258 };
7259
7260 static void
7261 cmd_set_qmap_parsed(void *parsed_result,
7262                        __attribute__((unused)) struct cmdline *cl,
7263                        __attribute__((unused)) void *data)
7264 {
7265         struct cmd_set_qmap_result *res = parsed_result;
7266         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7267
7268         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7269 }
7270
7271 cmdline_parse_token_string_t cmd_setqmap_set =
7272         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7273                                  set, "set");
7274 cmdline_parse_token_string_t cmd_setqmap_qmap =
7275         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7276                                  qmap, "stat_qmap");
7277 cmdline_parse_token_string_t cmd_setqmap_what =
7278         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7279                                  what, "tx#rx");
7280 cmdline_parse_token_num_t cmd_setqmap_portid =
7281         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7282                               port_id, UINT16);
7283 cmdline_parse_token_num_t cmd_setqmap_queueid =
7284         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7285                               queue_id, UINT16);
7286 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7287         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7288                               map_value, UINT8);
7289
7290 cmdline_parse_inst_t cmd_set_qmap = {
7291         .f = cmd_set_qmap_parsed,
7292         .data = NULL,
7293         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7294                 "Set statistics mapping value on tx|rx queue_id of port_id",
7295         .tokens = {
7296                 (void *)&cmd_setqmap_set,
7297                 (void *)&cmd_setqmap_qmap,
7298                 (void *)&cmd_setqmap_what,
7299                 (void *)&cmd_setqmap_portid,
7300                 (void *)&cmd_setqmap_queueid,
7301                 (void *)&cmd_setqmap_mapvalue,
7302                 NULL,
7303         },
7304 };
7305
7306 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7307 struct cmd_set_xstats_hide_zero_result {
7308         cmdline_fixed_string_t keyword;
7309         cmdline_fixed_string_t name;
7310         cmdline_fixed_string_t on_off;
7311 };
7312
7313 static void
7314 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7315                         __attribute__((unused)) struct cmdline *cl,
7316                         __attribute__((unused)) void *data)
7317 {
7318         struct cmd_set_xstats_hide_zero_result *res;
7319         uint16_t on_off = 0;
7320
7321         res = parsed_result;
7322         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7323         set_xstats_hide_zero(on_off);
7324 }
7325
7326 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7327         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7328                                  keyword, "set");
7329 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7330         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7331                                  name, "xstats-hide-zero");
7332 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7333         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7334                                  on_off, "on#off");
7335
7336 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7337         .f = cmd_set_xstats_hide_zero_parsed,
7338         .data = NULL,
7339         .help_str = "set xstats-hide-zero on|off",
7340         .tokens = {
7341                 (void *)&cmd_set_xstats_hide_zero_keyword,
7342                 (void *)&cmd_set_xstats_hide_zero_name,
7343                 (void *)&cmd_set_xstats_hide_zero_on_off,
7344                 NULL,
7345         },
7346 };
7347
7348 /* *** CONFIGURE UNICAST HASH TABLE *** */
7349 struct cmd_set_uc_hash_table {
7350         cmdline_fixed_string_t set;
7351         cmdline_fixed_string_t port;
7352         portid_t port_id;
7353         cmdline_fixed_string_t what;
7354         struct ether_addr address;
7355         cmdline_fixed_string_t mode;
7356 };
7357
7358 static void
7359 cmd_set_uc_hash_parsed(void *parsed_result,
7360                        __attribute__((unused)) struct cmdline *cl,
7361                        __attribute__((unused)) void *data)
7362 {
7363         int ret=0;
7364         struct cmd_set_uc_hash_table *res = parsed_result;
7365
7366         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7367
7368         if (strcmp(res->what, "uta") == 0)
7369                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7370                                                 &res->address,(uint8_t)is_on);
7371         if (ret < 0)
7372                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7373
7374 }
7375
7376 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7378                                  set, "set");
7379 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7380         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7381                                  port, "port");
7382 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7383         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7384                               port_id, UINT16);
7385 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7386         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7387                                  what, "uta");
7388 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7389         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7390                                 address);
7391 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7392         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7393                                  mode, "on#off");
7394
7395 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7396         .f = cmd_set_uc_hash_parsed,
7397         .data = NULL,
7398         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7399         .tokens = {
7400                 (void *)&cmd_set_uc_hash_set,
7401                 (void *)&cmd_set_uc_hash_port,
7402                 (void *)&cmd_set_uc_hash_portid,
7403                 (void *)&cmd_set_uc_hash_what,
7404                 (void *)&cmd_set_uc_hash_mac,
7405                 (void *)&cmd_set_uc_hash_mode,
7406                 NULL,
7407         },
7408 };
7409
7410 struct cmd_set_uc_all_hash_table {
7411         cmdline_fixed_string_t set;
7412         cmdline_fixed_string_t port;
7413         portid_t port_id;
7414         cmdline_fixed_string_t what;
7415         cmdline_fixed_string_t value;
7416         cmdline_fixed_string_t mode;
7417 };
7418
7419 static void
7420 cmd_set_uc_all_hash_parsed(void *parsed_result,
7421                        __attribute__((unused)) struct cmdline *cl,
7422                        __attribute__((unused)) void *data)
7423 {
7424         int ret=0;
7425         struct cmd_set_uc_all_hash_table *res = parsed_result;
7426
7427         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7428
7429         if ((strcmp(res->what, "uta") == 0) &&
7430                 (strcmp(res->value, "all") == 0))
7431                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7432         if (ret < 0)
7433                 printf("bad unicast hash table parameter,"
7434                         "return code = %d \n", ret);
7435 }
7436
7437 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7438         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7439                                  set, "set");
7440 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7441         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7442                                  port, "port");
7443 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7444         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7445                               port_id, UINT16);
7446 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7447         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7448                                  what, "uta");
7449 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7450         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7451                                 value,"all");
7452 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7453         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7454                                  mode, "on#off");
7455
7456 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7457         .f = cmd_set_uc_all_hash_parsed,
7458         .data = NULL,
7459         .help_str = "set port <port_id> uta all on|off",
7460         .tokens = {
7461                 (void *)&cmd_set_uc_all_hash_set,
7462                 (void *)&cmd_set_uc_all_hash_port,
7463                 (void *)&cmd_set_uc_all_hash_portid,
7464                 (void *)&cmd_set_uc_all_hash_what,
7465                 (void *)&cmd_set_uc_all_hash_value,
7466                 (void *)&cmd_set_uc_all_hash_mode,
7467                 NULL,
7468         },
7469 };
7470
7471 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7472 struct cmd_set_vf_macvlan_filter {
7473         cmdline_fixed_string_t set;
7474         cmdline_fixed_string_t port;
7475         portid_t port_id;
7476         cmdline_fixed_string_t vf;
7477         uint8_t vf_id;
7478         struct ether_addr address;
7479         cmdline_fixed_string_t filter_type;
7480         cmdline_fixed_string_t mode;
7481 };
7482
7483 static void
7484 cmd_set_vf_macvlan_parsed(void *parsed_result,
7485                        __attribute__((unused)) struct cmdline *cl,
7486                        __attribute__((unused)) void *data)
7487 {
7488         int is_on, ret = 0;
7489         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7490         struct rte_eth_mac_filter filter;
7491
7492         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7493
7494         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7495
7496         /* set VF MAC filter */
7497         filter.is_vf = 1;
7498
7499         /* set VF ID */
7500         filter.dst_id = res->vf_id;
7501
7502         if (!strcmp(res->filter_type, "exact-mac"))
7503                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7504         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7505                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7506         else if (!strcmp(res->filter_type, "hashmac"))
7507                 filter.filter_type = RTE_MAC_HASH_MATCH;
7508         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7509                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7510
7511         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7512
7513         if (is_on)
7514                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7515                                         RTE_ETH_FILTER_MACVLAN,
7516                                         RTE_ETH_FILTER_ADD,
7517                                          &filter);
7518         else
7519                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7520                                         RTE_ETH_FILTER_MACVLAN,
7521                                         RTE_ETH_FILTER_DELETE,
7522                                         &filter);
7523
7524         if (ret < 0)
7525                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7526
7527 }
7528
7529 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7530         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7531                                  set, "set");
7532 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7533         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7534                                  port, "port");
7535 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7536         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7537                               port_id, UINT16);
7538 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7539         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7540                                  vf, "vf");
7541 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7542         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7543                                 vf_id, UINT8);
7544 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7545         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7546                                 address);
7547 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7548         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7549                                 filter_type, "exact-mac#exact-mac-vlan"
7550                                 "#hashmac#hashmac-vlan");
7551 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7552         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7553                                  mode, "on#off");
7554
7555 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7556         .f = cmd_set_vf_macvlan_parsed,
7557         .data = NULL,
7558         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7559                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7560                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7561                 "hash match rule: hash match of MAC and exact match of VLAN",
7562         .tokens = {
7563                 (void *)&cmd_set_vf_macvlan_set,
7564                 (void *)&cmd_set_vf_macvlan_port,
7565                 (void *)&cmd_set_vf_macvlan_portid,
7566                 (void *)&cmd_set_vf_macvlan_vf,
7567                 (void *)&cmd_set_vf_macvlan_vf_id,
7568                 (void *)&cmd_set_vf_macvlan_mac,
7569                 (void *)&cmd_set_vf_macvlan_filter_type,
7570                 (void *)&cmd_set_vf_macvlan_mode,
7571                 NULL,
7572         },
7573 };
7574
7575 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7576 struct cmd_set_vf_traffic {
7577         cmdline_fixed_string_t set;
7578         cmdline_fixed_string_t port;
7579         portid_t port_id;
7580         cmdline_fixed_string_t vf;
7581         uint8_t vf_id;
7582         cmdline_fixed_string_t what;
7583         cmdline_fixed_string_t mode;
7584 };
7585
7586 static void
7587 cmd_set_vf_traffic_parsed(void *parsed_result,
7588                        __attribute__((unused)) struct cmdline *cl,
7589                        __attribute__((unused)) void *data)
7590 {
7591         struct cmd_set_vf_traffic *res = parsed_result;
7592         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7593         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7594
7595         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7596 }
7597
7598 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7599         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7600                                  set, "set");
7601 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7602         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7603                                  port, "port");
7604 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7605         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7606                               port_id, UINT16);
7607 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7608         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7609                                  vf, "vf");
7610 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7611         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7612                               vf_id, UINT8);
7613 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7614         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7615                                  what, "tx#rx");
7616 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7617         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7618                                  mode, "on#off");
7619
7620 cmdline_parse_inst_t cmd_set_vf_traffic = {
7621         .f = cmd_set_vf_traffic_parsed,
7622         .data = NULL,
7623         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7624         .tokens = {
7625                 (void *)&cmd_setvf_traffic_set,
7626                 (void *)&cmd_setvf_traffic_port,
7627                 (void *)&cmd_setvf_traffic_portid,
7628                 (void *)&cmd_setvf_traffic_vf,
7629                 (void *)&cmd_setvf_traffic_vfid,
7630                 (void *)&cmd_setvf_traffic_what,
7631                 (void *)&cmd_setvf_traffic_mode,
7632                 NULL,
7633         },
7634 };
7635
7636 /* *** CONFIGURE VF RECEIVE MODE *** */
7637 struct cmd_set_vf_rxmode {
7638         cmdline_fixed_string_t set;
7639         cmdline_fixed_string_t port;
7640         portid_t port_id;
7641         cmdline_fixed_string_t vf;
7642         uint8_t vf_id;
7643         cmdline_fixed_string_t what;
7644         cmdline_fixed_string_t mode;
7645         cmdline_fixed_string_t on;
7646 };
7647
7648 static void
7649 cmd_set_vf_rxmode_parsed(void *parsed_result,
7650                        __attribute__((unused)) struct cmdline *cl,
7651                        __attribute__((unused)) void *data)
7652 {
7653         int ret = -ENOTSUP;
7654         uint16_t rx_mode = 0;
7655         struct cmd_set_vf_rxmode *res = parsed_result;
7656
7657         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7658         if (!strcmp(res->what,"rxmode")) {
7659                 if (!strcmp(res->mode, "AUPE"))
7660                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7661                 else if (!strcmp(res->mode, "ROPE"))
7662                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7663                 else if (!strcmp(res->mode, "BAM"))
7664                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7665                 else if (!strncmp(res->mode, "MPE",3))
7666                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7667         }
7668
7669         RTE_SET_USED(is_on);
7670
7671 #ifdef RTE_LIBRTE_IXGBE_PMD
7672         if (ret == -ENOTSUP)
7673                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7674                                                   rx_mode, (uint8_t)is_on);
7675 #endif
7676 #ifdef RTE_LIBRTE_BNXT_PMD
7677         if (ret == -ENOTSUP)
7678                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7679                                                  rx_mode, (uint8_t)is_on);
7680 #endif
7681         if (ret < 0)
7682                 printf("bad VF receive mode parameter, return code = %d \n",
7683                 ret);
7684 }
7685
7686 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7687         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7688                                  set, "set");
7689 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7690         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7691                                  port, "port");
7692 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7693         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7694                               port_id, UINT16);
7695 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7696         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7697                                  vf, "vf");
7698 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7699         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7700                               vf_id, UINT8);
7701 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7702         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7703                                  what, "rxmode");
7704 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7705         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7706                                  mode, "AUPE#ROPE#BAM#MPE");
7707 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7708         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7709                                  on, "on#off");
7710
7711 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7712         .f = cmd_set_vf_rxmode_parsed,
7713         .data = NULL,
7714         .help_str = "set port <port_id> vf <vf_id> rxmode "
7715                 "AUPE|ROPE|BAM|MPE on|off",
7716         .tokens = {
7717                 (void *)&cmd_set_vf_rxmode_set,
7718                 (void *)&cmd_set_vf_rxmode_port,
7719                 (void *)&cmd_set_vf_rxmode_portid,
7720                 (void *)&cmd_set_vf_rxmode_vf,
7721                 (void *)&cmd_set_vf_rxmode_vfid,
7722                 (void *)&cmd_set_vf_rxmode_what,
7723                 (void *)&cmd_set_vf_rxmode_mode,
7724                 (void *)&cmd_set_vf_rxmode_on,
7725                 NULL,
7726         },
7727 };
7728
7729 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7730 struct cmd_vf_mac_addr_result {
7731         cmdline_fixed_string_t mac_addr_cmd;
7732         cmdline_fixed_string_t what;
7733         cmdline_fixed_string_t port;
7734         uint16_t port_num;
7735         cmdline_fixed_string_t vf;
7736         uint8_t vf_num;
7737         struct ether_addr address;
7738 };
7739
7740 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7741                 __attribute__((unused)) struct cmdline *cl,
7742                 __attribute__((unused)) void *data)
7743 {
7744         struct cmd_vf_mac_addr_result *res = parsed_result;
7745         int ret = -ENOTSUP;
7746
7747         if (strcmp(res->what, "add") != 0)
7748                 return;
7749
7750 #ifdef RTE_LIBRTE_I40E_PMD
7751         if (ret == -ENOTSUP)
7752                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7753                                                    &res->address);
7754 #endif
7755 #ifdef RTE_LIBRTE_BNXT_PMD
7756         if (ret == -ENOTSUP)
7757                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7758                                                 res->vf_num);
7759 #endif
7760
7761         if(ret < 0)
7762                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7763
7764 }
7765
7766 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7767         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7768                                 mac_addr_cmd,"mac_addr");
7769 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7770         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7771                                 what,"add");
7772 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7773         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7774                                 port,"port");
7775 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7776         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7777                                 port_num, UINT16);
7778 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7779         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7780                                 vf,"vf");
7781 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7782         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7783                                 vf_num, UINT8);
7784 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7785         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7786                                 address);
7787
7788 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7789         .f = cmd_vf_mac_addr_parsed,
7790         .data = (void *)0,
7791         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7792                 "Add MAC address filtering for a VF on port_id",
7793         .tokens = {
7794                 (void *)&cmd_vf_mac_addr_cmd,
7795                 (void *)&cmd_vf_mac_addr_what,
7796                 (void *)&cmd_vf_mac_addr_port,
7797                 (void *)&cmd_vf_mac_addr_portnum,
7798                 (void *)&cmd_vf_mac_addr_vf,
7799                 (void *)&cmd_vf_mac_addr_vfnum,
7800                 (void *)&cmd_vf_mac_addr_addr,
7801                 NULL,
7802         },
7803 };
7804
7805 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7806 struct cmd_vf_rx_vlan_filter {
7807         cmdline_fixed_string_t rx_vlan;
7808         cmdline_fixed_string_t what;
7809         uint16_t vlan_id;
7810         cmdline_fixed_string_t port;
7811         portid_t port_id;
7812         cmdline_fixed_string_t vf;
7813         uint64_t vf_mask;
7814 };
7815
7816 static void
7817 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7818                           __attribute__((unused)) struct cmdline *cl,
7819                           __attribute__((unused)) void *data)
7820 {
7821         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7822         int ret = -ENOTSUP;
7823
7824         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7825
7826 #ifdef RTE_LIBRTE_IXGBE_PMD
7827         if (ret == -ENOTSUP)
7828                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7829                                 res->vlan_id, res->vf_mask, is_add);
7830 #endif
7831 #ifdef RTE_LIBRTE_I40E_PMD
7832         if (ret == -ENOTSUP)
7833                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7834                                 res->vlan_id, res->vf_mask, is_add);
7835 #endif
7836 #ifdef RTE_LIBRTE_BNXT_PMD
7837         if (ret == -ENOTSUP)
7838                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7839                                 res->vlan_id, res->vf_mask, is_add);
7840 #endif
7841
7842         switch (ret) {
7843         case 0:
7844                 break;
7845         case -EINVAL:
7846                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7847                                 res->vlan_id, res->vf_mask);
7848                 break;
7849         case -ENODEV:
7850                 printf("invalid port_id %d\n", res->port_id);
7851                 break;
7852         case -ENOTSUP:
7853                 printf("function not implemented or supported\n");
7854                 break;
7855         default:
7856                 printf("programming error: (%s)\n", strerror(-ret));
7857         }
7858 }
7859
7860 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7861         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7862                                  rx_vlan, "rx_vlan");
7863 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7864         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7865                                  what, "add#rm");
7866 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7867         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7868                               vlan_id, UINT16);
7869 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7870         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7871                                  port, "port");
7872 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7873         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7874                               port_id, UINT16);
7875 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7876         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7877                                  vf, "vf");
7878 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7879         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7880                               vf_mask, UINT64);
7881
7882 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7883         .f = cmd_vf_rx_vlan_filter_parsed,
7884         .data = NULL,
7885         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7886                 "(vf_mask = hexadecimal VF mask)",
7887         .tokens = {
7888                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7889                 (void *)&cmd_vf_rx_vlan_filter_what,
7890                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7891                 (void *)&cmd_vf_rx_vlan_filter_port,
7892                 (void *)&cmd_vf_rx_vlan_filter_portid,
7893                 (void *)&cmd_vf_rx_vlan_filter_vf,
7894                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7895                 NULL,
7896         },
7897 };
7898
7899 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7900 struct cmd_queue_rate_limit_result {
7901         cmdline_fixed_string_t set;
7902         cmdline_fixed_string_t port;
7903         uint16_t port_num;
7904         cmdline_fixed_string_t queue;
7905         uint8_t queue_num;
7906         cmdline_fixed_string_t rate;
7907         uint16_t rate_num;
7908 };
7909
7910 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7911                 __attribute__((unused)) struct cmdline *cl,
7912                 __attribute__((unused)) void *data)
7913 {
7914         struct cmd_queue_rate_limit_result *res = parsed_result;
7915         int ret = 0;
7916
7917         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7918                 && (strcmp(res->queue, "queue") == 0)
7919                 && (strcmp(res->rate, "rate") == 0))
7920                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7921                                         res->rate_num);
7922         if (ret < 0)
7923                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7924
7925 }
7926
7927 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7928         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7929                                 set, "set");
7930 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7931         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7932                                 port, "port");
7933 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7934         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7935                                 port_num, UINT16);
7936 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7937         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7938                                 queue, "queue");
7939 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7940         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7941                                 queue_num, UINT8);
7942 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7943         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7944                                 rate, "rate");
7945 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7946         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7947                                 rate_num, UINT16);
7948
7949 cmdline_parse_inst_t cmd_queue_rate_limit = {
7950         .f = cmd_queue_rate_limit_parsed,
7951         .data = (void *)0,
7952         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7953                 "Set rate limit for a queue on port_id",
7954         .tokens = {
7955                 (void *)&cmd_queue_rate_limit_set,
7956                 (void *)&cmd_queue_rate_limit_port,
7957                 (void *)&cmd_queue_rate_limit_portnum,
7958                 (void *)&cmd_queue_rate_limit_queue,
7959                 (void *)&cmd_queue_rate_limit_queuenum,
7960                 (void *)&cmd_queue_rate_limit_rate,
7961                 (void *)&cmd_queue_rate_limit_ratenum,
7962                 NULL,
7963         },
7964 };
7965
7966 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7967 struct cmd_vf_rate_limit_result {
7968         cmdline_fixed_string_t set;
7969         cmdline_fixed_string_t port;
7970         uint16_t port_num;
7971         cmdline_fixed_string_t vf;
7972         uint8_t vf_num;
7973         cmdline_fixed_string_t rate;
7974         uint16_t rate_num;
7975         cmdline_fixed_string_t q_msk;
7976         uint64_t q_msk_val;
7977 };
7978
7979 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7980                 __attribute__((unused)) struct cmdline *cl,
7981                 __attribute__((unused)) void *data)
7982 {
7983         struct cmd_vf_rate_limit_result *res = parsed_result;
7984         int ret = 0;
7985
7986         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7987                 && (strcmp(res->vf, "vf") == 0)
7988                 && (strcmp(res->rate, "rate") == 0)
7989                 && (strcmp(res->q_msk, "queue_mask") == 0))
7990                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7991                                         res->rate_num, res->q_msk_val);
7992         if (ret < 0)
7993                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7994
7995 }
7996
7997 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7998         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7999                                 set, "set");
8000 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8001         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8002                                 port, "port");
8003 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8004         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8005                                 port_num, UINT16);
8006 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8007         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8008                                 vf, "vf");
8009 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8010         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8011                                 vf_num, UINT8);
8012 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8013         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8014                                 rate, "rate");
8015 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8016         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8017                                 rate_num, UINT16);
8018 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8019         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8020                                 q_msk, "queue_mask");
8021 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8022         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8023                                 q_msk_val, UINT64);
8024
8025 cmdline_parse_inst_t cmd_vf_rate_limit = {
8026         .f = cmd_vf_rate_limit_parsed,
8027         .data = (void *)0,
8028         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8029                 "queue_mask <queue_mask_value>: "
8030                 "Set rate limit for queues of VF on port_id",
8031         .tokens = {
8032                 (void *)&cmd_vf_rate_limit_set,
8033                 (void *)&cmd_vf_rate_limit_port,
8034                 (void *)&cmd_vf_rate_limit_portnum,
8035                 (void *)&cmd_vf_rate_limit_vf,
8036                 (void *)&cmd_vf_rate_limit_vfnum,
8037                 (void *)&cmd_vf_rate_limit_rate,
8038                 (void *)&cmd_vf_rate_limit_ratenum,
8039                 (void *)&cmd_vf_rate_limit_q_msk,
8040                 (void *)&cmd_vf_rate_limit_q_msk_val,
8041                 NULL,
8042         },
8043 };
8044
8045 /* *** ADD TUNNEL FILTER OF A PORT *** */
8046 struct cmd_tunnel_filter_result {
8047         cmdline_fixed_string_t cmd;
8048         cmdline_fixed_string_t what;
8049         portid_t port_id;
8050         struct ether_addr outer_mac;
8051         struct ether_addr inner_mac;
8052         cmdline_ipaddr_t ip_value;
8053         uint16_t inner_vlan;
8054         cmdline_fixed_string_t tunnel_type;
8055         cmdline_fixed_string_t filter_type;
8056         uint32_t tenant_id;
8057         uint16_t queue_num;
8058 };
8059
8060 static void
8061 cmd_tunnel_filter_parsed(void *parsed_result,
8062                           __attribute__((unused)) struct cmdline *cl,
8063                           __attribute__((unused)) void *data)
8064 {
8065         struct cmd_tunnel_filter_result *res = parsed_result;
8066         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8067         int ret = 0;
8068
8069         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8070
8071         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8072         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8073         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8074
8075         if (res->ip_value.family == AF_INET) {
8076                 tunnel_filter_conf.ip_addr.ipv4_addr =
8077                         res->ip_value.addr.ipv4.s_addr;
8078                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8079         } else {
8080                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8081                         &(res->ip_value.addr.ipv6),
8082                         sizeof(struct in6_addr));
8083                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8084         }
8085
8086         if (!strcmp(res->filter_type, "imac-ivlan"))
8087                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8088         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8089                 tunnel_filter_conf.filter_type =
8090                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8091         else if (!strcmp(res->filter_type, "imac-tenid"))
8092                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8093         else if (!strcmp(res->filter_type, "imac"))
8094                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8095         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8096                 tunnel_filter_conf.filter_type =
8097                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8098         else if (!strcmp(res->filter_type, "oip"))
8099                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8100         else if (!strcmp(res->filter_type, "iip"))
8101                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8102         else {
8103                 printf("The filter type is not supported");
8104                 return;
8105         }
8106
8107         if (!strcmp(res->tunnel_type, "vxlan"))
8108                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8109         else if (!strcmp(res->tunnel_type, "nvgre"))
8110                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8111         else if (!strcmp(res->tunnel_type, "ipingre"))
8112                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8113         else {
8114                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8115                 return;
8116         }
8117
8118         tunnel_filter_conf.tenant_id = res->tenant_id;
8119         tunnel_filter_conf.queue_id = res->queue_num;
8120         if (!strcmp(res->what, "add"))
8121                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8122                                         RTE_ETH_FILTER_TUNNEL,
8123                                         RTE_ETH_FILTER_ADD,
8124                                         &tunnel_filter_conf);
8125         else
8126                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8127                                         RTE_ETH_FILTER_TUNNEL,
8128                                         RTE_ETH_FILTER_DELETE,
8129                                         &tunnel_filter_conf);
8130         if (ret < 0)
8131                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8132                                 strerror(-ret));
8133
8134 }
8135 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8136         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8137         cmd, "tunnel_filter");
8138 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8139         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8140         what, "add#rm");
8141 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8142         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8143         port_id, UINT16);
8144 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8145         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8146         outer_mac);
8147 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8148         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8149         inner_mac);
8150 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8151         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8152         inner_vlan, UINT16);
8153 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8154         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8155         ip_value);
8156 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8157         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8158         tunnel_type, "vxlan#nvgre#ipingre");
8159
8160 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8161         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8162         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8163                 "imac#omac-imac-tenid");
8164 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8165         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8166         tenant_id, UINT32);
8167 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8168         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8169         queue_num, UINT16);
8170
8171 cmdline_parse_inst_t cmd_tunnel_filter = {
8172         .f = cmd_tunnel_filter_parsed,
8173         .data = (void *)0,
8174         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8175                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8176                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8177                 "<queue_id>: Add/Rm tunnel filter of a port",
8178         .tokens = {
8179                 (void *)&cmd_tunnel_filter_cmd,
8180                 (void *)&cmd_tunnel_filter_what,
8181                 (void *)&cmd_tunnel_filter_port_id,
8182                 (void *)&cmd_tunnel_filter_outer_mac,
8183                 (void *)&cmd_tunnel_filter_inner_mac,
8184                 (void *)&cmd_tunnel_filter_ip_value,
8185                 (void *)&cmd_tunnel_filter_innner_vlan,
8186                 (void *)&cmd_tunnel_filter_tunnel_type,
8187                 (void *)&cmd_tunnel_filter_filter_type,
8188                 (void *)&cmd_tunnel_filter_tenant_id,
8189                 (void *)&cmd_tunnel_filter_queue_num,
8190                 NULL,
8191         },
8192 };
8193
8194 /* *** CONFIGURE TUNNEL UDP PORT *** */
8195 struct cmd_tunnel_udp_config {
8196         cmdline_fixed_string_t cmd;
8197         cmdline_fixed_string_t what;
8198         uint16_t udp_port;
8199         portid_t port_id;
8200 };
8201
8202 static void
8203 cmd_tunnel_udp_config_parsed(void *parsed_result,
8204                           __attribute__((unused)) struct cmdline *cl,
8205                           __attribute__((unused)) void *data)
8206 {
8207         struct cmd_tunnel_udp_config *res = parsed_result;
8208         struct rte_eth_udp_tunnel tunnel_udp;
8209         int ret;
8210
8211         tunnel_udp.udp_port = res->udp_port;
8212
8213         if (!strcmp(res->cmd, "rx_vxlan_port"))
8214                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8215
8216         if (!strcmp(res->what, "add"))
8217                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8218                                                       &tunnel_udp);
8219         else
8220                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8221                                                          &tunnel_udp);
8222
8223         if (ret < 0)
8224                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8225 }
8226
8227 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8228         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8229                                 cmd, "rx_vxlan_port");
8230 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8231         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8232                                 what, "add#rm");
8233 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8234         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8235                                 udp_port, UINT16);
8236 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8237         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8238                                 port_id, UINT16);
8239
8240 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8241         .f = cmd_tunnel_udp_config_parsed,
8242         .data = (void *)0,
8243         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8244                 "Add/Remove a tunneling UDP port filter",
8245         .tokens = {
8246                 (void *)&cmd_tunnel_udp_config_cmd,
8247                 (void *)&cmd_tunnel_udp_config_what,
8248                 (void *)&cmd_tunnel_udp_config_udp_port,
8249                 (void *)&cmd_tunnel_udp_config_port_id,
8250                 NULL,
8251         },
8252 };
8253
8254 /* *** GLOBAL CONFIG *** */
8255 struct cmd_global_config_result {
8256         cmdline_fixed_string_t cmd;
8257         portid_t port_id;
8258         cmdline_fixed_string_t cfg_type;
8259         uint8_t len;
8260 };
8261
8262 static void
8263 cmd_global_config_parsed(void *parsed_result,
8264                          __attribute__((unused)) struct cmdline *cl,
8265                          __attribute__((unused)) void *data)
8266 {
8267         struct cmd_global_config_result *res = parsed_result;
8268         struct rte_eth_global_cfg conf;
8269         int ret;
8270
8271         memset(&conf, 0, sizeof(conf));
8272         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8273         conf.cfg.gre_key_len = res->len;
8274         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8275                                       RTE_ETH_FILTER_SET, &conf);
8276         if (ret != 0)
8277                 printf("Global config error\n");
8278 }
8279
8280 cmdline_parse_token_string_t cmd_global_config_cmd =
8281         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8282                 "global_config");
8283 cmdline_parse_token_num_t cmd_global_config_port_id =
8284         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8285                                UINT16);
8286 cmdline_parse_token_string_t cmd_global_config_type =
8287         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8288                 cfg_type, "gre-key-len");
8289 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8290         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8291                 len, UINT8);
8292
8293 cmdline_parse_inst_t cmd_global_config = {
8294         .f = cmd_global_config_parsed,
8295         .data = (void *)NULL,
8296         .help_str = "global_config <port_id> gre-key-len <key_len>",
8297         .tokens = {
8298                 (void *)&cmd_global_config_cmd,
8299                 (void *)&cmd_global_config_port_id,
8300                 (void *)&cmd_global_config_type,
8301                 (void *)&cmd_global_config_gre_key_len,
8302                 NULL,
8303         },
8304 };
8305
8306 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8307 struct cmd_set_mirror_mask_result {
8308         cmdline_fixed_string_t set;
8309         cmdline_fixed_string_t port;
8310         portid_t port_id;
8311         cmdline_fixed_string_t mirror;
8312         uint8_t rule_id;
8313         cmdline_fixed_string_t what;
8314         cmdline_fixed_string_t value;
8315         cmdline_fixed_string_t dstpool;
8316         uint8_t dstpool_id;
8317         cmdline_fixed_string_t on;
8318 };
8319
8320 cmdline_parse_token_string_t cmd_mirror_mask_set =
8321         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8322                                 set, "set");
8323 cmdline_parse_token_string_t cmd_mirror_mask_port =
8324         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8325                                 port, "port");
8326 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8327         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8328                                 port_id, UINT16);
8329 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8330         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8331                                 mirror, "mirror-rule");
8332 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8333         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8334                                 rule_id, UINT8);
8335 cmdline_parse_token_string_t cmd_mirror_mask_what =
8336         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8337                                 what, "pool-mirror-up#pool-mirror-down"
8338                                       "#vlan-mirror");
8339 cmdline_parse_token_string_t cmd_mirror_mask_value =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8341                                 value, NULL);
8342 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8344                                 dstpool, "dst-pool");
8345 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8347                                 dstpool_id, UINT8);
8348 cmdline_parse_token_string_t cmd_mirror_mask_on =
8349         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8350                                 on, "on#off");
8351
8352 static void
8353 cmd_set_mirror_mask_parsed(void *parsed_result,
8354                        __attribute__((unused)) struct cmdline *cl,
8355                        __attribute__((unused)) void *data)
8356 {
8357         int ret,nb_item,i;
8358         struct cmd_set_mirror_mask_result *res = parsed_result;
8359         struct rte_eth_mirror_conf mr_conf;
8360
8361         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8362
8363         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8364
8365         mr_conf.dst_pool = res->dstpool_id;
8366
8367         if (!strcmp(res->what, "pool-mirror-up")) {
8368                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8369                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8370         } else if (!strcmp(res->what, "pool-mirror-down")) {
8371                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8372                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8373         } else if (!strcmp(res->what, "vlan-mirror")) {
8374                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8375                 nb_item = parse_item_list(res->value, "vlan",
8376                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8377                 if (nb_item <= 0)
8378                         return;
8379
8380                 for (i = 0; i < nb_item; i++) {
8381                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8382                                 printf("Invalid vlan_id: must be < 4096\n");
8383                                 return;
8384                         }
8385
8386                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8387                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8388                 }
8389         }
8390
8391         if (!strcmp(res->on, "on"))
8392                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8393                                                 res->rule_id, 1);
8394         else
8395                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8396                                                 res->rule_id, 0);
8397         if (ret < 0)
8398                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8399 }
8400
8401 cmdline_parse_inst_t cmd_set_mirror_mask = {
8402                 .f = cmd_set_mirror_mask_parsed,
8403                 .data = NULL,
8404                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8405                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8406                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8407                 .tokens = {
8408                         (void *)&cmd_mirror_mask_set,
8409                         (void *)&cmd_mirror_mask_port,
8410                         (void *)&cmd_mirror_mask_portid,
8411                         (void *)&cmd_mirror_mask_mirror,
8412                         (void *)&cmd_mirror_mask_ruleid,
8413                         (void *)&cmd_mirror_mask_what,
8414                         (void *)&cmd_mirror_mask_value,
8415                         (void *)&cmd_mirror_mask_dstpool,
8416                         (void *)&cmd_mirror_mask_poolid,
8417                         (void *)&cmd_mirror_mask_on,
8418                         NULL,
8419                 },
8420 };
8421
8422 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8423 struct cmd_set_mirror_link_result {
8424         cmdline_fixed_string_t set;
8425         cmdline_fixed_string_t port;
8426         portid_t port_id;
8427         cmdline_fixed_string_t mirror;
8428         uint8_t rule_id;
8429         cmdline_fixed_string_t what;
8430         cmdline_fixed_string_t dstpool;
8431         uint8_t dstpool_id;
8432         cmdline_fixed_string_t on;
8433 };
8434
8435 cmdline_parse_token_string_t cmd_mirror_link_set =
8436         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8437                                  set, "set");
8438 cmdline_parse_token_string_t cmd_mirror_link_port =
8439         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8440                                 port, "port");
8441 cmdline_parse_token_num_t cmd_mirror_link_portid =
8442         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8443                                 port_id, UINT16);
8444 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8445         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8446                                 mirror, "mirror-rule");
8447 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8448         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8449                             rule_id, UINT8);
8450 cmdline_parse_token_string_t cmd_mirror_link_what =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8452                                 what, "uplink-mirror#downlink-mirror");
8453 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8455                                 dstpool, "dst-pool");
8456 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8457         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8458                                 dstpool_id, UINT8);
8459 cmdline_parse_token_string_t cmd_mirror_link_on =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8461                                 on, "on#off");
8462
8463 static void
8464 cmd_set_mirror_link_parsed(void *parsed_result,
8465                        __attribute__((unused)) struct cmdline *cl,
8466                        __attribute__((unused)) void *data)
8467 {
8468         int ret;
8469         struct cmd_set_mirror_link_result *res = parsed_result;
8470         struct rte_eth_mirror_conf mr_conf;
8471
8472         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8473         if (!strcmp(res->what, "uplink-mirror"))
8474                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8475         else
8476                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8477
8478         mr_conf.dst_pool = res->dstpool_id;
8479
8480         if (!strcmp(res->on, "on"))
8481                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8482                                                 res->rule_id, 1);
8483         else
8484                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8485                                                 res->rule_id, 0);
8486
8487         /* check the return value and print it if is < 0 */
8488         if (ret < 0)
8489                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8490
8491 }
8492
8493 cmdline_parse_inst_t cmd_set_mirror_link = {
8494                 .f = cmd_set_mirror_link_parsed,
8495                 .data = NULL,
8496                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8497                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8498                 .tokens = {
8499                         (void *)&cmd_mirror_link_set,
8500                         (void *)&cmd_mirror_link_port,
8501                         (void *)&cmd_mirror_link_portid,
8502                         (void *)&cmd_mirror_link_mirror,
8503                         (void *)&cmd_mirror_link_ruleid,
8504                         (void *)&cmd_mirror_link_what,
8505                         (void *)&cmd_mirror_link_dstpool,
8506                         (void *)&cmd_mirror_link_poolid,
8507                         (void *)&cmd_mirror_link_on,
8508                         NULL,
8509                 },
8510 };
8511
8512 /* *** RESET VM MIRROR RULE *** */
8513 struct cmd_rm_mirror_rule_result {
8514         cmdline_fixed_string_t reset;
8515         cmdline_fixed_string_t port;
8516         portid_t port_id;
8517         cmdline_fixed_string_t mirror;
8518         uint8_t rule_id;
8519 };
8520
8521 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8522         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8523                                  reset, "reset");
8524 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8525         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8526                                 port, "port");
8527 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8528         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8529                                 port_id, UINT16);
8530 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8531         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8532                                 mirror, "mirror-rule");
8533 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8534         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8535                                 rule_id, UINT8);
8536
8537 static void
8538 cmd_reset_mirror_rule_parsed(void *parsed_result,
8539                        __attribute__((unused)) struct cmdline *cl,
8540                        __attribute__((unused)) void *data)
8541 {
8542         int ret;
8543         struct cmd_set_mirror_link_result *res = parsed_result;
8544         /* check rule_id */
8545         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8546         if(ret < 0)
8547                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8548 }
8549
8550 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8551                 .f = cmd_reset_mirror_rule_parsed,
8552                 .data = NULL,
8553                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8554                 .tokens = {
8555                         (void *)&cmd_rm_mirror_rule_reset,
8556                         (void *)&cmd_rm_mirror_rule_port,
8557                         (void *)&cmd_rm_mirror_rule_portid,
8558                         (void *)&cmd_rm_mirror_rule_mirror,
8559                         (void *)&cmd_rm_mirror_rule_ruleid,
8560                         NULL,
8561                 },
8562 };
8563
8564 /* ******************************************************************************** */
8565
8566 struct cmd_dump_result {
8567         cmdline_fixed_string_t dump;
8568 };
8569
8570 static void
8571 dump_struct_sizes(void)
8572 {
8573 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8574         DUMP_SIZE(struct rte_mbuf);
8575         DUMP_SIZE(struct rte_mempool);
8576         DUMP_SIZE(struct rte_ring);
8577 #undef DUMP_SIZE
8578 }
8579
8580 static void cmd_dump_parsed(void *parsed_result,
8581                             __attribute__((unused)) struct cmdline *cl,
8582                             __attribute__((unused)) void *data)
8583 {
8584         struct cmd_dump_result *res = parsed_result;
8585
8586         if (!strcmp(res->dump, "dump_physmem"))
8587                 rte_dump_physmem_layout(stdout);
8588         else if (!strcmp(res->dump, "dump_memzone"))
8589                 rte_memzone_dump(stdout);
8590         else if (!strcmp(res->dump, "dump_struct_sizes"))
8591                 dump_struct_sizes();
8592         else if (!strcmp(res->dump, "dump_ring"))
8593                 rte_ring_list_dump(stdout);
8594         else if (!strcmp(res->dump, "dump_mempool"))
8595                 rte_mempool_list_dump(stdout);
8596         else if (!strcmp(res->dump, "dump_devargs"))
8597                 rte_eal_devargs_dump(stdout);
8598         else if (!strcmp(res->dump, "dump_log_types"))
8599                 rte_log_dump(stdout);
8600 }
8601
8602 cmdline_parse_token_string_t cmd_dump_dump =
8603         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8604                 "dump_physmem#"
8605                 "dump_memzone#"
8606                 "dump_struct_sizes#"
8607                 "dump_ring#"
8608                 "dump_mempool#"
8609                 "dump_devargs#"
8610                 "dump_log_types");
8611
8612 cmdline_parse_inst_t cmd_dump = {
8613         .f = cmd_dump_parsed,  /* function to call */
8614         .data = NULL,      /* 2nd arg of func */
8615         .help_str = "Dump status",
8616         .tokens = {        /* token list, NULL terminated */
8617                 (void *)&cmd_dump_dump,
8618                 NULL,
8619         },
8620 };
8621
8622 /* ******************************************************************************** */
8623
8624 struct cmd_dump_one_result {
8625         cmdline_fixed_string_t dump;
8626         cmdline_fixed_string_t name;
8627 };
8628
8629 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8630                                 __attribute__((unused)) void *data)
8631 {
8632         struct cmd_dump_one_result *res = parsed_result;
8633
8634         if (!strcmp(res->dump, "dump_ring")) {
8635                 struct rte_ring *r;
8636                 r = rte_ring_lookup(res->name);
8637                 if (r == NULL) {
8638                         cmdline_printf(cl, "Cannot find ring\n");
8639                         return;
8640                 }
8641                 rte_ring_dump(stdout, r);
8642         } else if (!strcmp(res->dump, "dump_mempool")) {
8643                 struct rte_mempool *mp;
8644                 mp = rte_mempool_lookup(res->name);
8645                 if (mp == NULL) {
8646                         cmdline_printf(cl, "Cannot find mempool\n");
8647                         return;
8648                 }
8649                 rte_mempool_dump(stdout, mp);
8650         }
8651 }
8652
8653 cmdline_parse_token_string_t cmd_dump_one_dump =
8654         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8655                                  "dump_ring#dump_mempool");
8656
8657 cmdline_parse_token_string_t cmd_dump_one_name =
8658         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8659
8660 cmdline_parse_inst_t cmd_dump_one = {
8661         .f = cmd_dump_one_parsed,  /* function to call */
8662         .data = NULL,      /* 2nd arg of func */
8663         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8664         .tokens = {        /* token list, NULL terminated */
8665                 (void *)&cmd_dump_one_dump,
8666                 (void *)&cmd_dump_one_name,
8667                 NULL,
8668         },
8669 };
8670
8671 /* *** Add/Del syn filter *** */
8672 struct cmd_syn_filter_result {
8673         cmdline_fixed_string_t filter;
8674         portid_t port_id;
8675         cmdline_fixed_string_t ops;
8676         cmdline_fixed_string_t priority;
8677         cmdline_fixed_string_t high;
8678         cmdline_fixed_string_t queue;
8679         uint16_t queue_id;
8680 };
8681
8682 static void
8683 cmd_syn_filter_parsed(void *parsed_result,
8684                         __attribute__((unused)) struct cmdline *cl,
8685                         __attribute__((unused)) void *data)
8686 {
8687         struct cmd_syn_filter_result *res = parsed_result;
8688         struct rte_eth_syn_filter syn_filter;
8689         int ret = 0;
8690
8691         ret = rte_eth_dev_filter_supported(res->port_id,
8692                                         RTE_ETH_FILTER_SYN);
8693         if (ret < 0) {
8694                 printf("syn filter is not supported on port %u.\n",
8695                                 res->port_id);
8696                 return;
8697         }
8698
8699         memset(&syn_filter, 0, sizeof(syn_filter));
8700
8701         if (!strcmp(res->ops, "add")) {
8702                 if (!strcmp(res->high, "high"))
8703                         syn_filter.hig_pri = 1;
8704                 else
8705                         syn_filter.hig_pri = 0;
8706
8707                 syn_filter.queue = res->queue_id;
8708                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8709                                                 RTE_ETH_FILTER_SYN,
8710                                                 RTE_ETH_FILTER_ADD,
8711                                                 &syn_filter);
8712         } else
8713                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8714                                                 RTE_ETH_FILTER_SYN,
8715                                                 RTE_ETH_FILTER_DELETE,
8716                                                 &syn_filter);
8717
8718         if (ret < 0)
8719                 printf("syn filter programming error: (%s)\n",
8720                                 strerror(-ret));
8721 }
8722
8723 cmdline_parse_token_string_t cmd_syn_filter_filter =
8724         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8725         filter, "syn_filter");
8726 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8727         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8728         port_id, UINT16);
8729 cmdline_parse_token_string_t cmd_syn_filter_ops =
8730         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8731         ops, "add#del");
8732 cmdline_parse_token_string_t cmd_syn_filter_priority =
8733         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8734                                 priority, "priority");
8735 cmdline_parse_token_string_t cmd_syn_filter_high =
8736         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8737                                 high, "high#low");
8738 cmdline_parse_token_string_t cmd_syn_filter_queue =
8739         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8740                                 queue, "queue");
8741 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8742         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8743                                 queue_id, UINT16);
8744
8745 cmdline_parse_inst_t cmd_syn_filter = {
8746         .f = cmd_syn_filter_parsed,
8747         .data = NULL,
8748         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8749                 "<queue_id>: Add/Delete syn filter",
8750         .tokens = {
8751                 (void *)&cmd_syn_filter_filter,
8752                 (void *)&cmd_syn_filter_port_id,
8753                 (void *)&cmd_syn_filter_ops,
8754                 (void *)&cmd_syn_filter_priority,
8755                 (void *)&cmd_syn_filter_high,
8756                 (void *)&cmd_syn_filter_queue,
8757                 (void *)&cmd_syn_filter_queue_id,
8758                 NULL,
8759         },
8760 };
8761
8762 /* *** queue region set *** */
8763 struct cmd_queue_region_result {
8764         cmdline_fixed_string_t set;
8765         cmdline_fixed_string_t port;
8766         portid_t port_id;
8767         cmdline_fixed_string_t cmd;
8768         cmdline_fixed_string_t region;
8769         uint8_t  region_id;
8770         cmdline_fixed_string_t queue_start_index;
8771         uint8_t  queue_id;
8772         cmdline_fixed_string_t queue_num;
8773         uint8_t  queue_num_value;
8774 };
8775
8776 static void
8777 cmd_queue_region_parsed(void *parsed_result,
8778                         __attribute__((unused)) struct cmdline *cl,
8779                         __attribute__((unused)) void *data)
8780 {
8781         struct cmd_queue_region_result *res = parsed_result;
8782         int ret = -ENOTSUP;
8783 #ifdef RTE_LIBRTE_I40E_PMD
8784         struct rte_pmd_i40e_queue_region_conf region_conf;
8785         enum rte_pmd_i40e_queue_region_op op_type;
8786 #endif
8787
8788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8789                 return;
8790
8791 #ifdef RTE_LIBRTE_I40E_PMD
8792         memset(&region_conf, 0, sizeof(region_conf));
8793         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8794         region_conf.region_id = res->region_id;
8795         region_conf.queue_num = res->queue_num_value;
8796         region_conf.queue_start_index = res->queue_id;
8797
8798         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8799                                 op_type, &region_conf);
8800 #endif
8801
8802         switch (ret) {
8803         case 0:
8804                 break;
8805         case -ENOTSUP:
8806                 printf("function not implemented or supported\n");
8807                 break;
8808         default:
8809                 printf("queue region config error: (%s)\n", strerror(-ret));
8810         }
8811 }
8812
8813 cmdline_parse_token_string_t cmd_queue_region_set =
8814 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8815                 set, "set");
8816 cmdline_parse_token_string_t cmd_queue_region_port =
8817         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8818 cmdline_parse_token_num_t cmd_queue_region_port_id =
8819         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8820                                 port_id, UINT16);
8821 cmdline_parse_token_string_t cmd_queue_region_cmd =
8822         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8823                                  cmd, "queue-region");
8824 cmdline_parse_token_string_t cmd_queue_region_id =
8825         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8826                                 region, "region_id");
8827 cmdline_parse_token_num_t cmd_queue_region_index =
8828         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8829                                 region_id, UINT8);
8830 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8831         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8832                                 queue_start_index, "queue_start_index");
8833 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8834         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8835                                 queue_id, UINT8);
8836 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8837         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8838                                 queue_num, "queue_num");
8839 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8840         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8841                                 queue_num_value, UINT8);
8842
8843 cmdline_parse_inst_t cmd_queue_region = {
8844         .f = cmd_queue_region_parsed,
8845         .data = NULL,
8846         .help_str = "set port <port_id> queue-region region_id <value> "
8847                 "queue_start_index <value> queue_num <value>: Set a queue region",
8848         .tokens = {
8849                 (void *)&cmd_queue_region_set,
8850                 (void *)&cmd_queue_region_port,
8851                 (void *)&cmd_queue_region_port_id,
8852                 (void *)&cmd_queue_region_cmd,
8853                 (void *)&cmd_queue_region_id,
8854                 (void *)&cmd_queue_region_index,
8855                 (void *)&cmd_queue_region_queue_start_index,
8856                 (void *)&cmd_queue_region_queue_id,
8857                 (void *)&cmd_queue_region_queue_num,
8858                 (void *)&cmd_queue_region_queue_num_value,
8859                 NULL,
8860         },
8861 };
8862
8863 /* *** queue region and flowtype set *** */
8864 struct cmd_region_flowtype_result {
8865         cmdline_fixed_string_t set;
8866         cmdline_fixed_string_t port;
8867         portid_t port_id;
8868         cmdline_fixed_string_t cmd;
8869         cmdline_fixed_string_t region;
8870         uint8_t  region_id;
8871         cmdline_fixed_string_t flowtype;
8872         uint8_t  flowtype_id;
8873 };
8874
8875 static void
8876 cmd_region_flowtype_parsed(void *parsed_result,
8877                         __attribute__((unused)) struct cmdline *cl,
8878                         __attribute__((unused)) void *data)
8879 {
8880         struct cmd_region_flowtype_result *res = parsed_result;
8881         int ret = -ENOTSUP;
8882 #ifdef RTE_LIBRTE_I40E_PMD
8883         struct rte_pmd_i40e_queue_region_conf region_conf;
8884         enum rte_pmd_i40e_queue_region_op op_type;
8885 #endif
8886
8887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8888                 return;
8889
8890 #ifdef RTE_LIBRTE_I40E_PMD
8891         memset(&region_conf, 0, sizeof(region_conf));
8892
8893         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8894         region_conf.region_id = res->region_id;
8895         region_conf.hw_flowtype = res->flowtype_id;
8896
8897         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8898                         op_type, &region_conf);
8899 #endif
8900
8901         switch (ret) {
8902         case 0:
8903                 break;
8904         case -ENOTSUP:
8905                 printf("function not implemented or supported\n");
8906                 break;
8907         default:
8908                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8909         }
8910 }
8911
8912 cmdline_parse_token_string_t cmd_region_flowtype_set =
8913 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8914                                 set, "set");
8915 cmdline_parse_token_string_t cmd_region_flowtype_port =
8916         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8917                                 port, "port");
8918 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8919         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8920                                 port_id, UINT16);
8921 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8922         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8923                                 cmd, "queue-region");
8924 cmdline_parse_token_string_t cmd_region_flowtype_index =
8925         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8926                                 region, "region_id");
8927 cmdline_parse_token_num_t cmd_region_flowtype_id =
8928         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8929                                 region_id, UINT8);
8930 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8931         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8932                                 flowtype, "flowtype");
8933 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8934         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8935                                 flowtype_id, UINT8);
8936 cmdline_parse_inst_t cmd_region_flowtype = {
8937         .f = cmd_region_flowtype_parsed,
8938         .data = NULL,
8939         .help_str = "set port <port_id> queue-region region_id <value> "
8940                 "flowtype <value>: Set a flowtype region index",
8941         .tokens = {
8942                 (void *)&cmd_region_flowtype_set,
8943                 (void *)&cmd_region_flowtype_port,
8944                 (void *)&cmd_region_flowtype_port_index,
8945                 (void *)&cmd_region_flowtype_cmd,
8946                 (void *)&cmd_region_flowtype_index,
8947                 (void *)&cmd_region_flowtype_id,
8948                 (void *)&cmd_region_flowtype_flow_index,
8949                 (void *)&cmd_region_flowtype_flow_id,
8950                 NULL,
8951         },
8952 };
8953
8954 /* *** User Priority (UP) to queue region (region_id) set *** */
8955 struct cmd_user_priority_region_result {
8956         cmdline_fixed_string_t set;
8957         cmdline_fixed_string_t port;
8958         portid_t port_id;
8959         cmdline_fixed_string_t cmd;
8960         cmdline_fixed_string_t user_priority;
8961         uint8_t  user_priority_id;
8962         cmdline_fixed_string_t region;
8963         uint8_t  region_id;
8964 };
8965
8966 static void
8967 cmd_user_priority_region_parsed(void *parsed_result,
8968                         __attribute__((unused)) struct cmdline *cl,
8969                         __attribute__((unused)) void *data)
8970 {
8971         struct cmd_user_priority_region_result *res = parsed_result;
8972         int ret = -ENOTSUP;
8973 #ifdef RTE_LIBRTE_I40E_PMD
8974         struct rte_pmd_i40e_queue_region_conf region_conf;
8975         enum rte_pmd_i40e_queue_region_op op_type;
8976 #endif
8977
8978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8979                 return;
8980
8981 #ifdef RTE_LIBRTE_I40E_PMD
8982         memset(&region_conf, 0, sizeof(region_conf));
8983         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8984         region_conf.user_priority = res->user_priority_id;
8985         region_conf.region_id = res->region_id;
8986
8987         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8988                                 op_type, &region_conf);
8989 #endif
8990
8991         switch (ret) {
8992         case 0:
8993                 break;
8994         case -ENOTSUP:
8995                 printf("function not implemented or supported\n");
8996                 break;
8997         default:
8998                 printf("user_priority region config error: (%s)\n",
8999                                 strerror(-ret));
9000         }
9001 }
9002
9003 cmdline_parse_token_string_t cmd_user_priority_region_set =
9004         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9005                                 set, "set");
9006 cmdline_parse_token_string_t cmd_user_priority_region_port =
9007         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9008                                 port, "port");
9009 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9010         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9011                                 port_id, UINT16);
9012 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9013         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9014                                 cmd, "queue-region");
9015 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9016         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9017                                 user_priority, "UP");
9018 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9019         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9020                                 user_priority_id, UINT8);
9021 cmdline_parse_token_string_t cmd_user_priority_region_region =
9022         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9023                                 region, "region_id");
9024 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9025         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9026                                 region_id, UINT8);
9027
9028 cmdline_parse_inst_t cmd_user_priority_region = {
9029         .f = cmd_user_priority_region_parsed,
9030         .data = NULL,
9031         .help_str = "set port <port_id> queue-region UP <value> "
9032                 "region_id <value>: Set the mapping of User Priority (UP) "
9033                 "to queue region (region_id) ",
9034         .tokens = {
9035                 (void *)&cmd_user_priority_region_set,
9036                 (void *)&cmd_user_priority_region_port,
9037                 (void *)&cmd_user_priority_region_port_index,
9038                 (void *)&cmd_user_priority_region_cmd,
9039                 (void *)&cmd_user_priority_region_UP,
9040                 (void *)&cmd_user_priority_region_UP_id,
9041                 (void *)&cmd_user_priority_region_region,
9042                 (void *)&cmd_user_priority_region_region_id,
9043                 NULL,
9044         },
9045 };
9046
9047 /* *** flush all queue region related configuration *** */
9048 struct cmd_flush_queue_region_result {
9049         cmdline_fixed_string_t set;
9050         cmdline_fixed_string_t port;
9051         portid_t port_id;
9052         cmdline_fixed_string_t cmd;
9053         cmdline_fixed_string_t flush;
9054         cmdline_fixed_string_t what;
9055 };
9056
9057 static void
9058 cmd_flush_queue_region_parsed(void *parsed_result,
9059                         __attribute__((unused)) struct cmdline *cl,
9060                         __attribute__((unused)) void *data)
9061 {
9062         struct cmd_flush_queue_region_result *res = parsed_result;
9063         int ret = -ENOTSUP;
9064 #ifdef RTE_LIBRTE_I40E_PMD
9065         struct rte_pmd_i40e_queue_region_conf region_conf;
9066         enum rte_pmd_i40e_queue_region_op op_type;
9067 #endif
9068
9069         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9070                 return;
9071
9072 #ifdef RTE_LIBRTE_I40E_PMD
9073         memset(&region_conf, 0, sizeof(region_conf));
9074
9075         if (strcmp(res->what, "on") == 0)
9076                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9077         else
9078                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9079
9080         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9081                                 op_type, &region_conf);
9082 #endif
9083
9084         switch (ret) {
9085         case 0:
9086                 break;
9087         case -ENOTSUP:
9088                 printf("function not implemented or supported\n");
9089                 break;
9090         default:
9091                 printf("queue region config flush error: (%s)\n",
9092                                 strerror(-ret));
9093         }
9094 }
9095
9096 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9097         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9098                                 set, "set");
9099 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9100         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9101                                 port, "port");
9102 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9103         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9104                                 port_id, UINT16);
9105 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9106         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9107                                 cmd, "queue-region");
9108 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9109         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9110                                 flush, "flush");
9111 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9112         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9113                                 what, "on#off");
9114
9115 cmdline_parse_inst_t cmd_flush_queue_region = {
9116         .f = cmd_flush_queue_region_parsed,
9117         .data = NULL,
9118         .help_str = "set port <port_id> queue-region flush on|off"
9119                 ": flush all queue region related configuration",
9120         .tokens = {
9121                 (void *)&cmd_flush_queue_region_set,
9122                 (void *)&cmd_flush_queue_region_port,
9123                 (void *)&cmd_flush_queue_region_port_index,
9124                 (void *)&cmd_flush_queue_region_cmd,
9125                 (void *)&cmd_flush_queue_region_flush,
9126                 (void *)&cmd_flush_queue_region_what,
9127                 NULL,
9128         },
9129 };
9130
9131 /* *** get all queue region related configuration info *** */
9132 struct cmd_show_queue_region_info {
9133         cmdline_fixed_string_t show;
9134         cmdline_fixed_string_t port;
9135         portid_t port_id;
9136         cmdline_fixed_string_t cmd;
9137 };
9138
9139 static void
9140 cmd_show_queue_region_info_parsed(void *parsed_result,
9141                         __attribute__((unused)) struct cmdline *cl,
9142                         __attribute__((unused)) void *data)
9143 {
9144         struct cmd_show_queue_region_info *res = parsed_result;
9145         int ret = -ENOTSUP;
9146 #ifdef RTE_LIBRTE_I40E_PMD
9147         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9148         enum rte_pmd_i40e_queue_region_op op_type;
9149 #endif
9150
9151         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9152                 return;
9153
9154 #ifdef RTE_LIBRTE_I40E_PMD
9155         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9156
9157         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9158
9159         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9160                                         op_type, &rte_pmd_regions);
9161
9162         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9163 #endif
9164
9165         switch (ret) {
9166         case 0:
9167                 break;
9168         case -ENOTSUP:
9169                 printf("function not implemented or supported\n");
9170                 break;
9171         default:
9172                 printf("queue region config info show error: (%s)\n",
9173                                 strerror(-ret));
9174         }
9175 }
9176
9177 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9178 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9179                                 show, "show");
9180 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9181         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9182                                 port, "port");
9183 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9184         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9185                                 port_id, UINT16);
9186 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9187         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9188                                 cmd, "queue-region");
9189
9190 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9191         .f = cmd_show_queue_region_info_parsed,
9192         .data = NULL,
9193         .help_str = "show port <port_id> queue-region"
9194                 ": show all queue region related configuration info",
9195         .tokens = {
9196                 (void *)&cmd_show_queue_region_info_get,
9197                 (void *)&cmd_show_queue_region_info_port,
9198                 (void *)&cmd_show_queue_region_info_port_index,
9199                 (void *)&cmd_show_queue_region_info_cmd,
9200                 NULL,
9201         },
9202 };
9203
9204 /* *** ADD/REMOVE A 2tuple FILTER *** */
9205 struct cmd_2tuple_filter_result {
9206         cmdline_fixed_string_t filter;
9207         portid_t port_id;
9208         cmdline_fixed_string_t ops;
9209         cmdline_fixed_string_t dst_port;
9210         uint16_t dst_port_value;
9211         cmdline_fixed_string_t protocol;
9212         uint8_t protocol_value;
9213         cmdline_fixed_string_t mask;
9214         uint8_t  mask_value;
9215         cmdline_fixed_string_t tcp_flags;
9216         uint8_t tcp_flags_value;
9217         cmdline_fixed_string_t priority;
9218         uint8_t  priority_value;
9219         cmdline_fixed_string_t queue;
9220         uint16_t  queue_id;
9221 };
9222
9223 static void
9224 cmd_2tuple_filter_parsed(void *parsed_result,
9225                         __attribute__((unused)) struct cmdline *cl,
9226                         __attribute__((unused)) void *data)
9227 {
9228         struct rte_eth_ntuple_filter filter;
9229         struct cmd_2tuple_filter_result *res = parsed_result;
9230         int ret = 0;
9231
9232         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9233         if (ret < 0) {
9234                 printf("ntuple filter is not supported on port %u.\n",
9235                         res->port_id);
9236                 return;
9237         }
9238
9239         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9240
9241         filter.flags = RTE_2TUPLE_FLAGS;
9242         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9243         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9244         filter.proto = res->protocol_value;
9245         filter.priority = res->priority_value;
9246         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9247                 printf("nonzero tcp_flags is only meaningful"
9248                         " when protocol is TCP.\n");
9249                 return;
9250         }
9251         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9252                 printf("invalid TCP flags.\n");
9253                 return;
9254         }
9255
9256         if (res->tcp_flags_value != 0) {
9257                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9258                 filter.tcp_flags = res->tcp_flags_value;
9259         }
9260
9261         /* need convert to big endian. */
9262         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9263         filter.queue = res->queue_id;
9264
9265         if (!strcmp(res->ops, "add"))
9266                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9267                                 RTE_ETH_FILTER_NTUPLE,
9268                                 RTE_ETH_FILTER_ADD,
9269                                 &filter);
9270         else
9271                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9272                                 RTE_ETH_FILTER_NTUPLE,
9273                                 RTE_ETH_FILTER_DELETE,
9274                                 &filter);
9275         if (ret < 0)
9276                 printf("2tuple filter programming error: (%s)\n",
9277                         strerror(-ret));
9278
9279 }
9280
9281 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9282         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9283                                  filter, "2tuple_filter");
9284 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9285         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9286                                 port_id, UINT16);
9287 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9288         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9289                                  ops, "add#del");
9290 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9291         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9292                                 dst_port, "dst_port");
9293 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9294         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9295                                 dst_port_value, UINT16);
9296 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9297         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9298                                 protocol, "protocol");
9299 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9300         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9301                                 protocol_value, UINT8);
9302 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9303         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9304                                 mask, "mask");
9305 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9306         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9307                                 mask_value, INT8);
9308 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9309         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9310                                 tcp_flags, "tcp_flags");
9311 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9312         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9313                                 tcp_flags_value, UINT8);
9314 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9315         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9316                                 priority, "priority");
9317 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9318         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9319                                 priority_value, UINT8);
9320 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9321         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9322                                 queue, "queue");
9323 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9324         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9325                                 queue_id, UINT16);
9326
9327 cmdline_parse_inst_t cmd_2tuple_filter = {
9328         .f = cmd_2tuple_filter_parsed,
9329         .data = NULL,
9330         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9331                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9332                 "<queue_id>: Add a 2tuple filter",
9333         .tokens = {
9334                 (void *)&cmd_2tuple_filter_filter,
9335                 (void *)&cmd_2tuple_filter_port_id,
9336                 (void *)&cmd_2tuple_filter_ops,
9337                 (void *)&cmd_2tuple_filter_dst_port,
9338                 (void *)&cmd_2tuple_filter_dst_port_value,
9339                 (void *)&cmd_2tuple_filter_protocol,
9340                 (void *)&cmd_2tuple_filter_protocol_value,
9341                 (void *)&cmd_2tuple_filter_mask,
9342                 (void *)&cmd_2tuple_filter_mask_value,
9343                 (void *)&cmd_2tuple_filter_tcp_flags,
9344                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9345                 (void *)&cmd_2tuple_filter_priority,
9346                 (void *)&cmd_2tuple_filter_priority_value,
9347                 (void *)&cmd_2tuple_filter_queue,
9348                 (void *)&cmd_2tuple_filter_queue_id,
9349                 NULL,
9350         },
9351 };
9352
9353 /* *** ADD/REMOVE A 5tuple FILTER *** */
9354 struct cmd_5tuple_filter_result {
9355         cmdline_fixed_string_t filter;
9356         portid_t port_id;
9357         cmdline_fixed_string_t ops;
9358         cmdline_fixed_string_t dst_ip;
9359         cmdline_ipaddr_t dst_ip_value;
9360         cmdline_fixed_string_t src_ip;
9361         cmdline_ipaddr_t src_ip_value;
9362         cmdline_fixed_string_t dst_port;
9363         uint16_t dst_port_value;
9364         cmdline_fixed_string_t src_port;
9365         uint16_t src_port_value;
9366         cmdline_fixed_string_t protocol;
9367         uint8_t protocol_value;
9368         cmdline_fixed_string_t mask;
9369         uint8_t  mask_value;
9370         cmdline_fixed_string_t tcp_flags;
9371         uint8_t tcp_flags_value;
9372         cmdline_fixed_string_t priority;
9373         uint8_t  priority_value;
9374         cmdline_fixed_string_t queue;
9375         uint16_t  queue_id;
9376 };
9377
9378 static void
9379 cmd_5tuple_filter_parsed(void *parsed_result,
9380                         __attribute__((unused)) struct cmdline *cl,
9381                         __attribute__((unused)) void *data)
9382 {
9383         struct rte_eth_ntuple_filter filter;
9384         struct cmd_5tuple_filter_result *res = parsed_result;
9385         int ret = 0;
9386
9387         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9388         if (ret < 0) {
9389                 printf("ntuple filter is not supported on port %u.\n",
9390                         res->port_id);
9391                 return;
9392         }
9393
9394         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9395
9396         filter.flags = RTE_5TUPLE_FLAGS;
9397         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9398         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9399         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9400         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9401         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9402         filter.proto = res->protocol_value;
9403         filter.priority = res->priority_value;
9404         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9405                 printf("nonzero tcp_flags is only meaningful"
9406                         " when protocol is TCP.\n");
9407                 return;
9408         }
9409         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9410                 printf("invalid TCP flags.\n");
9411                 return;
9412         }
9413
9414         if (res->tcp_flags_value != 0) {
9415                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9416                 filter.tcp_flags = res->tcp_flags_value;
9417         }
9418
9419         if (res->dst_ip_value.family == AF_INET)
9420                 /* no need to convert, already big endian. */
9421                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9422         else {
9423                 if (filter.dst_ip_mask == 0) {
9424                         printf("can not support ipv6 involved compare.\n");
9425                         return;
9426                 }
9427                 filter.dst_ip = 0;
9428         }
9429
9430         if (res->src_ip_value.family == AF_INET)
9431                 /* no need to convert, already big endian. */
9432                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9433         else {
9434                 if (filter.src_ip_mask == 0) {
9435                         printf("can not support ipv6 involved compare.\n");
9436                         return;
9437                 }
9438                 filter.src_ip = 0;
9439         }
9440         /* need convert to big endian. */
9441         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9442         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9443         filter.queue = res->queue_id;
9444
9445         if (!strcmp(res->ops, "add"))
9446                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9447                                 RTE_ETH_FILTER_NTUPLE,
9448                                 RTE_ETH_FILTER_ADD,
9449                                 &filter);
9450         else
9451                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9452                                 RTE_ETH_FILTER_NTUPLE,
9453                                 RTE_ETH_FILTER_DELETE,
9454                                 &filter);
9455         if (ret < 0)
9456                 printf("5tuple filter programming error: (%s)\n",
9457                         strerror(-ret));
9458 }
9459
9460 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9461         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9462                                  filter, "5tuple_filter");
9463 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9464         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9465                                 port_id, UINT16);
9466 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9467         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9468                                  ops, "add#del");
9469 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9470         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9471                                 dst_ip, "dst_ip");
9472 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9473         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9474                                 dst_ip_value);
9475 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9476         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9477                                 src_ip, "src_ip");
9478 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9479         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9480                                 src_ip_value);
9481 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9482         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9483                                 dst_port, "dst_port");
9484 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9485         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9486                                 dst_port_value, UINT16);
9487 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9488         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9489                                 src_port, "src_port");
9490 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9491         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9492                                 src_port_value, UINT16);
9493 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9494         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9495                                 protocol, "protocol");
9496 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9497         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9498                                 protocol_value, UINT8);
9499 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9500         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9501                                 mask, "mask");
9502 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9503         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9504                                 mask_value, INT8);
9505 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9506         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9507                                 tcp_flags, "tcp_flags");
9508 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9509         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9510                                 tcp_flags_value, UINT8);
9511 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9512         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9513                                 priority, "priority");
9514 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9515         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9516                                 priority_value, UINT8);
9517 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9518         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9519                                 queue, "queue");
9520 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9521         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9522                                 queue_id, UINT16);
9523
9524 cmdline_parse_inst_t cmd_5tuple_filter = {
9525         .f = cmd_5tuple_filter_parsed,
9526         .data = NULL,
9527         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9528                 "src_ip <value> dst_port <value> src_port <value> "
9529                 "protocol <value>  mask <value> tcp_flags <value> "
9530                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9531         .tokens = {
9532                 (void *)&cmd_5tuple_filter_filter,
9533                 (void *)&cmd_5tuple_filter_port_id,
9534                 (void *)&cmd_5tuple_filter_ops,
9535                 (void *)&cmd_5tuple_filter_dst_ip,
9536                 (void *)&cmd_5tuple_filter_dst_ip_value,
9537                 (void *)&cmd_5tuple_filter_src_ip,
9538                 (void *)&cmd_5tuple_filter_src_ip_value,
9539                 (void *)&cmd_5tuple_filter_dst_port,
9540                 (void *)&cmd_5tuple_filter_dst_port_value,
9541                 (void *)&cmd_5tuple_filter_src_port,
9542                 (void *)&cmd_5tuple_filter_src_port_value,
9543                 (void *)&cmd_5tuple_filter_protocol,
9544                 (void *)&cmd_5tuple_filter_protocol_value,
9545                 (void *)&cmd_5tuple_filter_mask,
9546                 (void *)&cmd_5tuple_filter_mask_value,
9547                 (void *)&cmd_5tuple_filter_tcp_flags,
9548                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9549                 (void *)&cmd_5tuple_filter_priority,
9550                 (void *)&cmd_5tuple_filter_priority_value,
9551                 (void *)&cmd_5tuple_filter_queue,
9552                 (void *)&cmd_5tuple_filter_queue_id,
9553                 NULL,
9554         },
9555 };
9556
9557 /* *** ADD/REMOVE A flex FILTER *** */
9558 struct cmd_flex_filter_result {
9559         cmdline_fixed_string_t filter;
9560         cmdline_fixed_string_t ops;
9561         portid_t port_id;
9562         cmdline_fixed_string_t len;
9563         uint8_t len_value;
9564         cmdline_fixed_string_t bytes;
9565         cmdline_fixed_string_t bytes_value;
9566         cmdline_fixed_string_t mask;
9567         cmdline_fixed_string_t mask_value;
9568         cmdline_fixed_string_t priority;
9569         uint8_t priority_value;
9570         cmdline_fixed_string_t queue;
9571         uint16_t queue_id;
9572 };
9573
9574 static int xdigit2val(unsigned char c)
9575 {
9576         int val;
9577         if (isdigit(c))
9578                 val = c - '0';
9579         else if (isupper(c))
9580                 val = c - 'A' + 10;
9581         else
9582                 val = c - 'a' + 10;
9583         return val;
9584 }
9585
9586 static void
9587 cmd_flex_filter_parsed(void *parsed_result,
9588                           __attribute__((unused)) struct cmdline *cl,
9589                           __attribute__((unused)) void *data)
9590 {
9591         int ret = 0;
9592         struct rte_eth_flex_filter filter;
9593         struct cmd_flex_filter_result *res = parsed_result;
9594         char *bytes_ptr, *mask_ptr;
9595         uint16_t len, i, j = 0;
9596         char c;
9597         int val;
9598         uint8_t byte = 0;
9599
9600         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9601                 printf("the len exceed the max length 128\n");
9602                 return;
9603         }
9604         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9605         filter.len = res->len_value;
9606         filter.priority = res->priority_value;
9607         filter.queue = res->queue_id;
9608         bytes_ptr = res->bytes_value;
9609         mask_ptr = res->mask_value;
9610
9611          /* translate bytes string to array. */
9612         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9613                 (bytes_ptr[1] == 'X')))
9614                 bytes_ptr += 2;
9615         len = strnlen(bytes_ptr, res->len_value * 2);
9616         if (len == 0 || (len % 8 != 0)) {
9617                 printf("please check len and bytes input\n");
9618                 return;
9619         }
9620         for (i = 0; i < len; i++) {
9621                 c = bytes_ptr[i];
9622                 if (isxdigit(c) == 0) {
9623                         /* invalid characters. */
9624                         printf("invalid input\n");
9625                         return;
9626                 }
9627                 val = xdigit2val(c);
9628                 if (i % 2) {
9629                         byte |= val;
9630                         filter.bytes[j] = byte;
9631                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9632                         j++;
9633                         byte = 0;
9634                 } else
9635                         byte |= val << 4;
9636         }
9637         printf("\n");
9638          /* translate mask string to uint8_t array. */
9639         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9640                 (mask_ptr[1] == 'X')))
9641                 mask_ptr += 2;
9642         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9643         if (len == 0) {
9644                 printf("invalid input\n");
9645                 return;
9646         }
9647         j = 0;
9648         byte = 0;
9649         for (i = 0; i < len; i++) {
9650                 c = mask_ptr[i];
9651                 if (isxdigit(c) == 0) {
9652                         /* invalid characters. */
9653                         printf("invalid input\n");
9654                         return;
9655                 }
9656                 val = xdigit2val(c);
9657                 if (i % 2) {
9658                         byte |= val;
9659                         filter.mask[j] = byte;
9660                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9661                         j++;
9662                         byte = 0;
9663                 } else
9664                         byte |= val << 4;
9665         }
9666         printf("\n");
9667
9668         if (!strcmp(res->ops, "add"))
9669                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9670                                 RTE_ETH_FILTER_FLEXIBLE,
9671                                 RTE_ETH_FILTER_ADD,
9672                                 &filter);
9673         else
9674                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9675                                 RTE_ETH_FILTER_FLEXIBLE,
9676                                 RTE_ETH_FILTER_DELETE,
9677                                 &filter);
9678
9679         if (ret < 0)
9680                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9681 }
9682
9683 cmdline_parse_token_string_t cmd_flex_filter_filter =
9684         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9685                                 filter, "flex_filter");
9686 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9687         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9688                                 port_id, UINT16);
9689 cmdline_parse_token_string_t cmd_flex_filter_ops =
9690         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9691                                 ops, "add#del");
9692 cmdline_parse_token_string_t cmd_flex_filter_len =
9693         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9694                                 len, "len");
9695 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9696         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9697                                 len_value, UINT8);
9698 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9699         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9700                                 bytes, "bytes");
9701 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9702         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9703                                 bytes_value, NULL);
9704 cmdline_parse_token_string_t cmd_flex_filter_mask =
9705         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9706                                 mask, "mask");
9707 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9708         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9709                                 mask_value, NULL);
9710 cmdline_parse_token_string_t cmd_flex_filter_priority =
9711         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9712                                 priority, "priority");
9713 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9714         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9715                                 priority_value, UINT8);
9716 cmdline_parse_token_string_t cmd_flex_filter_queue =
9717         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9718                                 queue, "queue");
9719 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9720         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9721                                 queue_id, UINT16);
9722 cmdline_parse_inst_t cmd_flex_filter = {
9723         .f = cmd_flex_filter_parsed,
9724         .data = NULL,
9725         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9726                 "<value> mask <value> priority <value> queue <queue_id>: "
9727                 "Add/Del a flex filter",
9728         .tokens = {
9729                 (void *)&cmd_flex_filter_filter,
9730                 (void *)&cmd_flex_filter_port_id,
9731                 (void *)&cmd_flex_filter_ops,
9732                 (void *)&cmd_flex_filter_len,
9733                 (void *)&cmd_flex_filter_len_value,
9734                 (void *)&cmd_flex_filter_bytes,
9735                 (void *)&cmd_flex_filter_bytes_value,
9736                 (void *)&cmd_flex_filter_mask,
9737                 (void *)&cmd_flex_filter_mask_value,
9738                 (void *)&cmd_flex_filter_priority,
9739                 (void *)&cmd_flex_filter_priority_value,
9740                 (void *)&cmd_flex_filter_queue,
9741                 (void *)&cmd_flex_filter_queue_id,
9742                 NULL,
9743         },
9744 };
9745
9746 /* *** Filters Control *** */
9747
9748 /* *** deal with ethertype filter *** */
9749 struct cmd_ethertype_filter_result {
9750         cmdline_fixed_string_t filter;
9751         portid_t port_id;
9752         cmdline_fixed_string_t ops;
9753         cmdline_fixed_string_t mac;
9754         struct ether_addr mac_addr;
9755         cmdline_fixed_string_t ethertype;
9756         uint16_t ethertype_value;
9757         cmdline_fixed_string_t drop;
9758         cmdline_fixed_string_t queue;
9759         uint16_t  queue_id;
9760 };
9761
9762 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9763         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9764                                  filter, "ethertype_filter");
9765 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9766         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9767                               port_id, UINT16);
9768 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9769         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9770                                  ops, "add#del");
9771 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9772         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9773                                  mac, "mac_addr#mac_ignr");
9774 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9775         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9776                                      mac_addr);
9777 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9778         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9779                                  ethertype, "ethertype");
9780 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9781         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9782                               ethertype_value, UINT16);
9783 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9784         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9785                                  drop, "drop#fwd");
9786 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9787         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9788                                  queue, "queue");
9789 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9790         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9791                               queue_id, UINT16);
9792
9793 static void
9794 cmd_ethertype_filter_parsed(void *parsed_result,
9795                           __attribute__((unused)) struct cmdline *cl,
9796                           __attribute__((unused)) void *data)
9797 {
9798         struct cmd_ethertype_filter_result *res = parsed_result;
9799         struct rte_eth_ethertype_filter filter;
9800         int ret = 0;
9801
9802         ret = rte_eth_dev_filter_supported(res->port_id,
9803                         RTE_ETH_FILTER_ETHERTYPE);
9804         if (ret < 0) {
9805                 printf("ethertype filter is not supported on port %u.\n",
9806                         res->port_id);
9807                 return;
9808         }
9809
9810         memset(&filter, 0, sizeof(filter));
9811         if (!strcmp(res->mac, "mac_addr")) {
9812                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9813                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9814                         sizeof(struct ether_addr));
9815         }
9816         if (!strcmp(res->drop, "drop"))
9817                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9818         filter.ether_type = res->ethertype_value;
9819         filter.queue = res->queue_id;
9820
9821         if (!strcmp(res->ops, "add"))
9822                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9823                                 RTE_ETH_FILTER_ETHERTYPE,
9824                                 RTE_ETH_FILTER_ADD,
9825                                 &filter);
9826         else
9827                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9828                                 RTE_ETH_FILTER_ETHERTYPE,
9829                                 RTE_ETH_FILTER_DELETE,
9830                                 &filter);
9831         if (ret < 0)
9832                 printf("ethertype filter programming error: (%s)\n",
9833                         strerror(-ret));
9834 }
9835
9836 cmdline_parse_inst_t cmd_ethertype_filter = {
9837         .f = cmd_ethertype_filter_parsed,
9838         .data = NULL,
9839         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9840                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9841                 "Add or delete an ethertype filter entry",
9842         .tokens = {
9843                 (void *)&cmd_ethertype_filter_filter,
9844                 (void *)&cmd_ethertype_filter_port_id,
9845                 (void *)&cmd_ethertype_filter_ops,
9846                 (void *)&cmd_ethertype_filter_mac,
9847                 (void *)&cmd_ethertype_filter_mac_addr,
9848                 (void *)&cmd_ethertype_filter_ethertype,
9849                 (void *)&cmd_ethertype_filter_ethertype_value,
9850                 (void *)&cmd_ethertype_filter_drop,
9851                 (void *)&cmd_ethertype_filter_queue,
9852                 (void *)&cmd_ethertype_filter_queue_id,
9853                 NULL,
9854         },
9855 };
9856
9857 /* *** deal with flow director filter *** */
9858 struct cmd_flow_director_result {
9859         cmdline_fixed_string_t flow_director_filter;
9860         portid_t port_id;
9861         cmdline_fixed_string_t mode;
9862         cmdline_fixed_string_t mode_value;
9863         cmdline_fixed_string_t ops;
9864         cmdline_fixed_string_t flow;
9865         cmdline_fixed_string_t flow_type;
9866         cmdline_fixed_string_t ether;
9867         uint16_t ether_type;
9868         cmdline_fixed_string_t src;
9869         cmdline_ipaddr_t ip_src;
9870         uint16_t port_src;
9871         cmdline_fixed_string_t dst;
9872         cmdline_ipaddr_t ip_dst;
9873         uint16_t port_dst;
9874         cmdline_fixed_string_t verify_tag;
9875         uint32_t verify_tag_value;
9876         cmdline_ipaddr_t tos;
9877         uint8_t tos_value;
9878         cmdline_ipaddr_t proto;
9879         uint8_t proto_value;
9880         cmdline_ipaddr_t ttl;
9881         uint8_t ttl_value;
9882         cmdline_fixed_string_t vlan;
9883         uint16_t vlan_value;
9884         cmdline_fixed_string_t flexbytes;
9885         cmdline_fixed_string_t flexbytes_value;
9886         cmdline_fixed_string_t pf_vf;
9887         cmdline_fixed_string_t drop;
9888         cmdline_fixed_string_t queue;
9889         uint16_t  queue_id;
9890         cmdline_fixed_string_t fd_id;
9891         uint32_t  fd_id_value;
9892         cmdline_fixed_string_t mac;
9893         struct ether_addr mac_addr;
9894         cmdline_fixed_string_t tunnel;
9895         cmdline_fixed_string_t tunnel_type;
9896         cmdline_fixed_string_t tunnel_id;
9897         uint32_t tunnel_id_value;
9898         cmdline_fixed_string_t packet;
9899         char filepath[];
9900 };
9901
9902 static inline int
9903 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9904 {
9905         char s[256];
9906         const char *p, *p0 = q_arg;
9907         char *end;
9908         unsigned long int_fld;
9909         char *str_fld[max_num];
9910         int i;
9911         unsigned size;
9912         int ret = -1;
9913
9914         p = strchr(p0, '(');
9915         if (p == NULL)
9916                 return -1;
9917         ++p;
9918         p0 = strchr(p, ')');
9919         if (p0 == NULL)
9920                 return -1;
9921
9922         size = p0 - p;
9923         if (size >= sizeof(s))
9924                 return -1;
9925
9926         snprintf(s, sizeof(s), "%.*s", size, p);
9927         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9928         if (ret < 0 || ret > max_num)
9929                 return -1;
9930         for (i = 0; i < ret; i++) {
9931                 errno = 0;
9932                 int_fld = strtoul(str_fld[i], &end, 0);
9933                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9934                         return -1;
9935                 flexbytes[i] = (uint8_t)int_fld;
9936         }
9937         return ret;
9938 }
9939
9940 static uint16_t
9941 str2flowtype(char *string)
9942 {
9943         uint8_t i = 0;
9944         static const struct {
9945                 char str[32];
9946                 uint16_t type;
9947         } flowtype_str[] = {
9948                 {"raw", RTE_ETH_FLOW_RAW},
9949                 {"ipv4", RTE_ETH_FLOW_IPV4},
9950                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9951                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9952                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9953                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9954                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9955                 {"ipv6", RTE_ETH_FLOW_IPV6},
9956                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9957                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9958                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9959                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9960                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9961                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9962         };
9963
9964         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9965                 if (!strcmp(flowtype_str[i].str, string))
9966                         return flowtype_str[i].type;
9967         }
9968
9969         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9970                 return (uint16_t)atoi(string);
9971
9972         return RTE_ETH_FLOW_UNKNOWN;
9973 }
9974
9975 static enum rte_eth_fdir_tunnel_type
9976 str2fdir_tunneltype(char *string)
9977 {
9978         uint8_t i = 0;
9979
9980         static const struct {
9981                 char str[32];
9982                 enum rte_eth_fdir_tunnel_type type;
9983         } tunneltype_str[] = {
9984                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9985                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9986         };
9987
9988         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9989                 if (!strcmp(tunneltype_str[i].str, string))
9990                         return tunneltype_str[i].type;
9991         }
9992         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9993 }
9994
9995 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9996 do { \
9997         if ((ip_addr).family == AF_INET) \
9998                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9999         else { \
10000                 printf("invalid parameter.\n"); \
10001                 return; \
10002         } \
10003 } while (0)
10004
10005 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10006 do { \
10007         if ((ip_addr).family == AF_INET6) \
10008                 rte_memcpy(&(ip), \
10009                                  &((ip_addr).addr.ipv6), \
10010                                  sizeof(struct in6_addr)); \
10011         else { \
10012                 printf("invalid parameter.\n"); \
10013                 return; \
10014         } \
10015 } while (0)
10016
10017 static void
10018 cmd_flow_director_filter_parsed(void *parsed_result,
10019                           __attribute__((unused)) struct cmdline *cl,
10020                           __attribute__((unused)) void *data)
10021 {
10022         struct cmd_flow_director_result *res = parsed_result;
10023         struct rte_eth_fdir_filter entry;
10024         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10025         char *end;
10026         unsigned long vf_id;
10027         int ret = 0;
10028
10029         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10030         if (ret < 0) {
10031                 printf("flow director is not supported on port %u.\n",
10032                         res->port_id);
10033                 return;
10034         }
10035         memset(flexbytes, 0, sizeof(flexbytes));
10036         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10037
10038         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10039                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10040                         printf("Please set mode to MAC-VLAN.\n");
10041                         return;
10042                 }
10043         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10044                 if (strcmp(res->mode_value, "Tunnel")) {
10045                         printf("Please set mode to Tunnel.\n");
10046                         return;
10047                 }
10048         } else {
10049                 if (!strcmp(res->mode_value, "raw")) {
10050 #ifdef RTE_LIBRTE_I40E_PMD
10051                         struct rte_pmd_i40e_flow_type_mapping
10052                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10053                         struct rte_pmd_i40e_pkt_template_conf conf;
10054                         uint16_t flow_type = str2flowtype(res->flow_type);
10055                         uint16_t i, port = res->port_id;
10056                         uint8_t add;
10057
10058                         memset(&conf, 0, sizeof(conf));
10059
10060                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10061                                 printf("Invalid flow type specified.\n");
10062                                 return;
10063                         }
10064                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10065                                                                  mapping);
10066                         if (ret)
10067                                 return;
10068                         if (mapping[flow_type].pctype == 0ULL) {
10069                                 printf("Invalid flow type specified.\n");
10070                                 return;
10071                         }
10072                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10073                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10074                                         conf.input.pctype = i;
10075                                         break;
10076                                 }
10077                         }
10078
10079                         conf.input.packet = open_file(res->filepath,
10080                                                 &conf.input.length);
10081                         if (!conf.input.packet)
10082                                 return;
10083                         if (!strcmp(res->drop, "drop"))
10084                                 conf.action.behavior =
10085                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10086                         else
10087                                 conf.action.behavior =
10088                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10089                         conf.action.report_status =
10090                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10091                         conf.action.rx_queue = res->queue_id;
10092                         conf.soft_id = res->fd_id_value;
10093                         add  = strcmp(res->ops, "del") ? 1 : 0;
10094                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10095                                                                         &conf,
10096                                                                         add);
10097                         if (ret < 0)
10098                                 printf("flow director config error: (%s)\n",
10099                                        strerror(-ret));
10100                         close_file(conf.input.packet);
10101 #endif
10102                         return;
10103                 } else if (strcmp(res->mode_value, "IP")) {
10104                         printf("Please set mode to IP or raw.\n");
10105                         return;
10106                 }
10107                 entry.input.flow_type = str2flowtype(res->flow_type);
10108         }
10109
10110         ret = parse_flexbytes(res->flexbytes_value,
10111                                         flexbytes,
10112                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10113         if (ret < 0) {
10114                 printf("error: Cannot parse flexbytes input.\n");
10115                 return;
10116         }
10117
10118         switch (entry.input.flow_type) {
10119         case RTE_ETH_FLOW_FRAG_IPV4:
10120         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10121                 entry.input.flow.ip4_flow.proto = res->proto_value;
10122                 /* fall-through */
10123         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10124         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10125                 IPV4_ADDR_TO_UINT(res->ip_dst,
10126                         entry.input.flow.ip4_flow.dst_ip);
10127                 IPV4_ADDR_TO_UINT(res->ip_src,
10128                         entry.input.flow.ip4_flow.src_ip);
10129                 entry.input.flow.ip4_flow.tos = res->tos_value;
10130                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10131                 /* need convert to big endian. */
10132                 entry.input.flow.udp4_flow.dst_port =
10133                                 rte_cpu_to_be_16(res->port_dst);
10134                 entry.input.flow.udp4_flow.src_port =
10135                                 rte_cpu_to_be_16(res->port_src);
10136                 break;
10137         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10138                 IPV4_ADDR_TO_UINT(res->ip_dst,
10139                         entry.input.flow.sctp4_flow.ip.dst_ip);
10140                 IPV4_ADDR_TO_UINT(res->ip_src,
10141                         entry.input.flow.sctp4_flow.ip.src_ip);
10142                 entry.input.flow.ip4_flow.tos = res->tos_value;
10143                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10144                 /* need convert to big endian. */
10145                 entry.input.flow.sctp4_flow.dst_port =
10146                                 rte_cpu_to_be_16(res->port_dst);
10147                 entry.input.flow.sctp4_flow.src_port =
10148                                 rte_cpu_to_be_16(res->port_src);
10149                 entry.input.flow.sctp4_flow.verify_tag =
10150                                 rte_cpu_to_be_32(res->verify_tag_value);
10151                 break;
10152         case RTE_ETH_FLOW_FRAG_IPV6:
10153         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10154                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10155                 /* fall-through */
10156         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10157         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10158                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10159                         entry.input.flow.ipv6_flow.dst_ip);
10160                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10161                         entry.input.flow.ipv6_flow.src_ip);
10162                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10163                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10164                 /* need convert to big endian. */
10165                 entry.input.flow.udp6_flow.dst_port =
10166                                 rte_cpu_to_be_16(res->port_dst);
10167                 entry.input.flow.udp6_flow.src_port =
10168                                 rte_cpu_to_be_16(res->port_src);
10169                 break;
10170         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10171                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10172                         entry.input.flow.sctp6_flow.ip.dst_ip);
10173                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10174                         entry.input.flow.sctp6_flow.ip.src_ip);
10175                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10176                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10177                 /* need convert to big endian. */
10178                 entry.input.flow.sctp6_flow.dst_port =
10179                                 rte_cpu_to_be_16(res->port_dst);
10180                 entry.input.flow.sctp6_flow.src_port =
10181                                 rte_cpu_to_be_16(res->port_src);
10182                 entry.input.flow.sctp6_flow.verify_tag =
10183                                 rte_cpu_to_be_32(res->verify_tag_value);
10184                 break;
10185         case RTE_ETH_FLOW_L2_PAYLOAD:
10186                 entry.input.flow.l2_flow.ether_type =
10187                         rte_cpu_to_be_16(res->ether_type);
10188                 break;
10189         default:
10190                 break;
10191         }
10192
10193         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10194                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10195                                  &res->mac_addr,
10196                                  sizeof(struct ether_addr));
10197
10198         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10199                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10200                                  &res->mac_addr,
10201                                  sizeof(struct ether_addr));
10202                 entry.input.flow.tunnel_flow.tunnel_type =
10203                         str2fdir_tunneltype(res->tunnel_type);
10204                 entry.input.flow.tunnel_flow.tunnel_id =
10205                         rte_cpu_to_be_32(res->tunnel_id_value);
10206         }
10207
10208         rte_memcpy(entry.input.flow_ext.flexbytes,
10209                    flexbytes,
10210                    RTE_ETH_FDIR_MAX_FLEXLEN);
10211
10212         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10213
10214         entry.action.flex_off = 0;  /*use 0 by default */
10215         if (!strcmp(res->drop, "drop"))
10216                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10217         else
10218                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10219
10220         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10221             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10222                 if (!strcmp(res->pf_vf, "pf"))
10223                         entry.input.flow_ext.is_vf = 0;
10224                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10225                         struct rte_eth_dev_info dev_info;
10226
10227                         memset(&dev_info, 0, sizeof(dev_info));
10228                         rte_eth_dev_info_get(res->port_id, &dev_info);
10229                         errno = 0;
10230                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10231                         if (errno != 0 || *end != '\0' ||
10232                             vf_id >= dev_info.max_vfs) {
10233                                 printf("invalid parameter %s.\n", res->pf_vf);
10234                                 return;
10235                         }
10236                         entry.input.flow_ext.is_vf = 1;
10237                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10238                 } else {
10239                         printf("invalid parameter %s.\n", res->pf_vf);
10240                         return;
10241                 }
10242         }
10243
10244         /* set to report FD ID by default */
10245         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10246         entry.action.rx_queue = res->queue_id;
10247         entry.soft_id = res->fd_id_value;
10248         if (!strcmp(res->ops, "add"))
10249                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10250                                              RTE_ETH_FILTER_ADD, &entry);
10251         else if (!strcmp(res->ops, "del"))
10252                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10253                                              RTE_ETH_FILTER_DELETE, &entry);
10254         else
10255                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10256                                              RTE_ETH_FILTER_UPDATE, &entry);
10257         if (ret < 0)
10258                 printf("flow director programming error: (%s)\n",
10259                         strerror(-ret));
10260 }
10261
10262 cmdline_parse_token_string_t cmd_flow_director_filter =
10263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10264                                  flow_director_filter, "flow_director_filter");
10265 cmdline_parse_token_num_t cmd_flow_director_port_id =
10266         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10267                               port_id, UINT16);
10268 cmdline_parse_token_string_t cmd_flow_director_ops =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10270                                  ops, "add#del#update");
10271 cmdline_parse_token_string_t cmd_flow_director_flow =
10272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10273                                  flow, "flow");
10274 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10276                 flow_type, NULL);
10277 cmdline_parse_token_string_t cmd_flow_director_ether =
10278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10279                                  ether, "ether");
10280 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10282                               ether_type, UINT16);
10283 cmdline_parse_token_string_t cmd_flow_director_src =
10284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10285                                  src, "src");
10286 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10287         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10288                                  ip_src);
10289 cmdline_parse_token_num_t cmd_flow_director_port_src =
10290         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10291                               port_src, UINT16);
10292 cmdline_parse_token_string_t cmd_flow_director_dst =
10293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10294                                  dst, "dst");
10295 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10296         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10297                                  ip_dst);
10298 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10299         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10300                               port_dst, UINT16);
10301 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10302         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10303                                   verify_tag, "verify_tag");
10304 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10305         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10306                               verify_tag_value, UINT32);
10307 cmdline_parse_token_string_t cmd_flow_director_tos =
10308         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10309                                  tos, "tos");
10310 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10311         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10312                               tos_value, UINT8);
10313 cmdline_parse_token_string_t cmd_flow_director_proto =
10314         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10315                                  proto, "proto");
10316 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10317         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10318                               proto_value, UINT8);
10319 cmdline_parse_token_string_t cmd_flow_director_ttl =
10320         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10321                                  ttl, "ttl");
10322 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10323         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10324                               ttl_value, UINT8);
10325 cmdline_parse_token_string_t cmd_flow_director_vlan =
10326         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10327                                  vlan, "vlan");
10328 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10329         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10330                               vlan_value, UINT16);
10331 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10333                                  flexbytes, "flexbytes");
10334 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10335         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10336                               flexbytes_value, NULL);
10337 cmdline_parse_token_string_t cmd_flow_director_drop =
10338         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10339                                  drop, "drop#fwd");
10340 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10342                               pf_vf, NULL);
10343 cmdline_parse_token_string_t cmd_flow_director_queue =
10344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10345                                  queue, "queue");
10346 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10347         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10348                               queue_id, UINT16);
10349 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10351                                  fd_id, "fd_id");
10352 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10353         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10354                               fd_id_value, UINT32);
10355
10356 cmdline_parse_token_string_t cmd_flow_director_mode =
10357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10358                                  mode, "mode");
10359 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10360         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10361                                  mode_value, "IP");
10362 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10364                                  mode_value, "MAC-VLAN");
10365 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10366         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10367                                  mode_value, "Tunnel");
10368 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10370                                  mode_value, "raw");
10371 cmdline_parse_token_string_t cmd_flow_director_mac =
10372         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10373                                  mac, "mac");
10374 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10375         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10376                                     mac_addr);
10377 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10378         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10379                                  tunnel, "tunnel");
10380 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10382                                  tunnel_type, "NVGRE#VxLAN");
10383 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10385                                  tunnel_id, "tunnel-id");
10386 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10387         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10388                               tunnel_id_value, UINT32);
10389 cmdline_parse_token_string_t cmd_flow_director_packet =
10390         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10391                                  packet, "packet");
10392 cmdline_parse_token_string_t cmd_flow_director_filepath =
10393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10394                                  filepath, NULL);
10395
10396 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10397         .f = cmd_flow_director_filter_parsed,
10398         .data = NULL,
10399         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10400                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10401                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10402                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10403                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10404                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10405                 "fd_id <fd_id_value>: "
10406                 "Add or delete an ip flow director entry on NIC",
10407         .tokens = {
10408                 (void *)&cmd_flow_director_filter,
10409                 (void *)&cmd_flow_director_port_id,
10410                 (void *)&cmd_flow_director_mode,
10411                 (void *)&cmd_flow_director_mode_ip,
10412                 (void *)&cmd_flow_director_ops,
10413                 (void *)&cmd_flow_director_flow,
10414                 (void *)&cmd_flow_director_flow_type,
10415                 (void *)&cmd_flow_director_src,
10416                 (void *)&cmd_flow_director_ip_src,
10417                 (void *)&cmd_flow_director_dst,
10418                 (void *)&cmd_flow_director_ip_dst,
10419                 (void *)&cmd_flow_director_tos,
10420                 (void *)&cmd_flow_director_tos_value,
10421                 (void *)&cmd_flow_director_proto,
10422                 (void *)&cmd_flow_director_proto_value,
10423                 (void *)&cmd_flow_director_ttl,
10424                 (void *)&cmd_flow_director_ttl_value,
10425                 (void *)&cmd_flow_director_vlan,
10426                 (void *)&cmd_flow_director_vlan_value,
10427                 (void *)&cmd_flow_director_flexbytes,
10428                 (void *)&cmd_flow_director_flexbytes_value,
10429                 (void *)&cmd_flow_director_drop,
10430                 (void *)&cmd_flow_director_pf_vf,
10431                 (void *)&cmd_flow_director_queue,
10432                 (void *)&cmd_flow_director_queue_id,
10433                 (void *)&cmd_flow_director_fd_id,
10434                 (void *)&cmd_flow_director_fd_id_value,
10435                 NULL,
10436         },
10437 };
10438
10439 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10440         .f = cmd_flow_director_filter_parsed,
10441         .data = NULL,
10442         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10443                 "director entry on NIC",
10444         .tokens = {
10445                 (void *)&cmd_flow_director_filter,
10446                 (void *)&cmd_flow_director_port_id,
10447                 (void *)&cmd_flow_director_mode,
10448                 (void *)&cmd_flow_director_mode_ip,
10449                 (void *)&cmd_flow_director_ops,
10450                 (void *)&cmd_flow_director_flow,
10451                 (void *)&cmd_flow_director_flow_type,
10452                 (void *)&cmd_flow_director_src,
10453                 (void *)&cmd_flow_director_ip_src,
10454                 (void *)&cmd_flow_director_port_src,
10455                 (void *)&cmd_flow_director_dst,
10456                 (void *)&cmd_flow_director_ip_dst,
10457                 (void *)&cmd_flow_director_port_dst,
10458                 (void *)&cmd_flow_director_tos,
10459                 (void *)&cmd_flow_director_tos_value,
10460                 (void *)&cmd_flow_director_ttl,
10461                 (void *)&cmd_flow_director_ttl_value,
10462                 (void *)&cmd_flow_director_vlan,
10463                 (void *)&cmd_flow_director_vlan_value,
10464                 (void *)&cmd_flow_director_flexbytes,
10465                 (void *)&cmd_flow_director_flexbytes_value,
10466                 (void *)&cmd_flow_director_drop,
10467                 (void *)&cmd_flow_director_pf_vf,
10468                 (void *)&cmd_flow_director_queue,
10469                 (void *)&cmd_flow_director_queue_id,
10470                 (void *)&cmd_flow_director_fd_id,
10471                 (void *)&cmd_flow_director_fd_id_value,
10472                 NULL,
10473         },
10474 };
10475
10476 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10477         .f = cmd_flow_director_filter_parsed,
10478         .data = NULL,
10479         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10480                 "director entry on NIC",
10481         .tokens = {
10482                 (void *)&cmd_flow_director_filter,
10483                 (void *)&cmd_flow_director_port_id,
10484                 (void *)&cmd_flow_director_mode,
10485                 (void *)&cmd_flow_director_mode_ip,
10486                 (void *)&cmd_flow_director_ops,
10487                 (void *)&cmd_flow_director_flow,
10488                 (void *)&cmd_flow_director_flow_type,
10489                 (void *)&cmd_flow_director_src,
10490                 (void *)&cmd_flow_director_ip_src,
10491                 (void *)&cmd_flow_director_port_dst,
10492                 (void *)&cmd_flow_director_dst,
10493                 (void *)&cmd_flow_director_ip_dst,
10494                 (void *)&cmd_flow_director_port_dst,
10495                 (void *)&cmd_flow_director_verify_tag,
10496                 (void *)&cmd_flow_director_verify_tag_value,
10497                 (void *)&cmd_flow_director_tos,
10498                 (void *)&cmd_flow_director_tos_value,
10499                 (void *)&cmd_flow_director_ttl,
10500                 (void *)&cmd_flow_director_ttl_value,
10501                 (void *)&cmd_flow_director_vlan,
10502                 (void *)&cmd_flow_director_vlan_value,
10503                 (void *)&cmd_flow_director_flexbytes,
10504                 (void *)&cmd_flow_director_flexbytes_value,
10505                 (void *)&cmd_flow_director_drop,
10506                 (void *)&cmd_flow_director_pf_vf,
10507                 (void *)&cmd_flow_director_queue,
10508                 (void *)&cmd_flow_director_queue_id,
10509                 (void *)&cmd_flow_director_fd_id,
10510                 (void *)&cmd_flow_director_fd_id_value,
10511                 NULL,
10512         },
10513 };
10514
10515 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10516         .f = cmd_flow_director_filter_parsed,
10517         .data = NULL,
10518         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10519                 "director entry on NIC",
10520         .tokens = {
10521                 (void *)&cmd_flow_director_filter,
10522                 (void *)&cmd_flow_director_port_id,
10523                 (void *)&cmd_flow_director_mode,
10524                 (void *)&cmd_flow_director_mode_ip,
10525                 (void *)&cmd_flow_director_ops,
10526                 (void *)&cmd_flow_director_flow,
10527                 (void *)&cmd_flow_director_flow_type,
10528                 (void *)&cmd_flow_director_ether,
10529                 (void *)&cmd_flow_director_ether_type,
10530                 (void *)&cmd_flow_director_flexbytes,
10531                 (void *)&cmd_flow_director_flexbytes_value,
10532                 (void *)&cmd_flow_director_drop,
10533                 (void *)&cmd_flow_director_pf_vf,
10534                 (void *)&cmd_flow_director_queue,
10535                 (void *)&cmd_flow_director_queue_id,
10536                 (void *)&cmd_flow_director_fd_id,
10537                 (void *)&cmd_flow_director_fd_id_value,
10538                 NULL,
10539         },
10540 };
10541
10542 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10543         .f = cmd_flow_director_filter_parsed,
10544         .data = NULL,
10545         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10546                 "director entry on NIC",
10547         .tokens = {
10548                 (void *)&cmd_flow_director_filter,
10549                 (void *)&cmd_flow_director_port_id,
10550                 (void *)&cmd_flow_director_mode,
10551                 (void *)&cmd_flow_director_mode_mac_vlan,
10552                 (void *)&cmd_flow_director_ops,
10553                 (void *)&cmd_flow_director_mac,
10554                 (void *)&cmd_flow_director_mac_addr,
10555                 (void *)&cmd_flow_director_vlan,
10556                 (void *)&cmd_flow_director_vlan_value,
10557                 (void *)&cmd_flow_director_flexbytes,
10558                 (void *)&cmd_flow_director_flexbytes_value,
10559                 (void *)&cmd_flow_director_drop,
10560                 (void *)&cmd_flow_director_queue,
10561                 (void *)&cmd_flow_director_queue_id,
10562                 (void *)&cmd_flow_director_fd_id,
10563                 (void *)&cmd_flow_director_fd_id_value,
10564                 NULL,
10565         },
10566 };
10567
10568 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10569         .f = cmd_flow_director_filter_parsed,
10570         .data = NULL,
10571         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10572                 "director entry on NIC",
10573         .tokens = {
10574                 (void *)&cmd_flow_director_filter,
10575                 (void *)&cmd_flow_director_port_id,
10576                 (void *)&cmd_flow_director_mode,
10577                 (void *)&cmd_flow_director_mode_tunnel,
10578                 (void *)&cmd_flow_director_ops,
10579                 (void *)&cmd_flow_director_mac,
10580                 (void *)&cmd_flow_director_mac_addr,
10581                 (void *)&cmd_flow_director_vlan,
10582                 (void *)&cmd_flow_director_vlan_value,
10583                 (void *)&cmd_flow_director_tunnel,
10584                 (void *)&cmd_flow_director_tunnel_type,
10585                 (void *)&cmd_flow_director_tunnel_id,
10586                 (void *)&cmd_flow_director_tunnel_id_value,
10587                 (void *)&cmd_flow_director_flexbytes,
10588                 (void *)&cmd_flow_director_flexbytes_value,
10589                 (void *)&cmd_flow_director_drop,
10590                 (void *)&cmd_flow_director_queue,
10591                 (void *)&cmd_flow_director_queue_id,
10592                 (void *)&cmd_flow_director_fd_id,
10593                 (void *)&cmd_flow_director_fd_id_value,
10594                 NULL,
10595         },
10596 };
10597
10598 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10599         .f = cmd_flow_director_filter_parsed,
10600         .data = NULL,
10601         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10602                 "director entry on NIC",
10603         .tokens = {
10604                 (void *)&cmd_flow_director_filter,
10605                 (void *)&cmd_flow_director_port_id,
10606                 (void *)&cmd_flow_director_mode,
10607                 (void *)&cmd_flow_director_mode_raw,
10608                 (void *)&cmd_flow_director_ops,
10609                 (void *)&cmd_flow_director_flow,
10610                 (void *)&cmd_flow_director_flow_type,
10611                 (void *)&cmd_flow_director_drop,
10612                 (void *)&cmd_flow_director_queue,
10613                 (void *)&cmd_flow_director_queue_id,
10614                 (void *)&cmd_flow_director_fd_id,
10615                 (void *)&cmd_flow_director_fd_id_value,
10616                 (void *)&cmd_flow_director_packet,
10617                 (void *)&cmd_flow_director_filepath,
10618                 NULL,
10619         },
10620 };
10621
10622 struct cmd_flush_flow_director_result {
10623         cmdline_fixed_string_t flush_flow_director;
10624         portid_t port_id;
10625 };
10626
10627 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10628         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10629                                  flush_flow_director, "flush_flow_director");
10630 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10631         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10632                               port_id, UINT16);
10633
10634 static void
10635 cmd_flush_flow_director_parsed(void *parsed_result,
10636                           __attribute__((unused)) struct cmdline *cl,
10637                           __attribute__((unused)) void *data)
10638 {
10639         struct cmd_flow_director_result *res = parsed_result;
10640         int ret = 0;
10641
10642         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10643         if (ret < 0) {
10644                 printf("flow director is not supported on port %u.\n",
10645                         res->port_id);
10646                 return;
10647         }
10648
10649         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10650                         RTE_ETH_FILTER_FLUSH, NULL);
10651         if (ret < 0)
10652                 printf("flow director table flushing error: (%s)\n",
10653                         strerror(-ret));
10654 }
10655
10656 cmdline_parse_inst_t cmd_flush_flow_director = {
10657         .f = cmd_flush_flow_director_parsed,
10658         .data = NULL,
10659         .help_str = "flush_flow_director <port_id>: "
10660                 "Flush all flow director entries of a device on NIC",
10661         .tokens = {
10662                 (void *)&cmd_flush_flow_director_flush,
10663                 (void *)&cmd_flush_flow_director_port_id,
10664                 NULL,
10665         },
10666 };
10667
10668 /* *** deal with flow director mask *** */
10669 struct cmd_flow_director_mask_result {
10670         cmdline_fixed_string_t flow_director_mask;
10671         portid_t port_id;
10672         cmdline_fixed_string_t mode;
10673         cmdline_fixed_string_t mode_value;
10674         cmdline_fixed_string_t vlan;
10675         uint16_t vlan_mask;
10676         cmdline_fixed_string_t src_mask;
10677         cmdline_ipaddr_t ipv4_src;
10678         cmdline_ipaddr_t ipv6_src;
10679         uint16_t port_src;
10680         cmdline_fixed_string_t dst_mask;
10681         cmdline_ipaddr_t ipv4_dst;
10682         cmdline_ipaddr_t ipv6_dst;
10683         uint16_t port_dst;
10684         cmdline_fixed_string_t mac;
10685         uint8_t mac_addr_byte_mask;
10686         cmdline_fixed_string_t tunnel_id;
10687         uint32_t tunnel_id_mask;
10688         cmdline_fixed_string_t tunnel_type;
10689         uint8_t tunnel_type_mask;
10690 };
10691
10692 static void
10693 cmd_flow_director_mask_parsed(void *parsed_result,
10694                           __attribute__((unused)) struct cmdline *cl,
10695                           __attribute__((unused)) void *data)
10696 {
10697         struct cmd_flow_director_mask_result *res = parsed_result;
10698         struct rte_eth_fdir_masks *mask;
10699         struct rte_port *port;
10700
10701         if (res->port_id > nb_ports) {
10702                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10703                 return;
10704         }
10705
10706         port = &ports[res->port_id];
10707         /** Check if the port is not started **/
10708         if (port->port_status != RTE_PORT_STOPPED) {
10709                 printf("Please stop port %d first\n", res->port_id);
10710                 return;
10711         }
10712
10713         mask = &port->dev_conf.fdir_conf.mask;
10714
10715         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10716                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10717                         printf("Please set mode to MAC-VLAN.\n");
10718                         return;
10719                 }
10720
10721                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10722         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10723                 if (strcmp(res->mode_value, "Tunnel")) {
10724                         printf("Please set mode to Tunnel.\n");
10725                         return;
10726                 }
10727
10728                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10729                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10730                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10731                 mask->tunnel_type_mask = res->tunnel_type_mask;
10732         } else {
10733                 if (strcmp(res->mode_value, "IP")) {
10734                         printf("Please set mode to IP.\n");
10735                         return;
10736                 }
10737
10738                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10739                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10740                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10741                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10742                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10743                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10744                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10745         }
10746
10747         cmd_reconfig_device_queue(res->port_id, 1, 1);
10748 }
10749
10750 cmdline_parse_token_string_t cmd_flow_director_mask =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10752                                  flow_director_mask, "flow_director_mask");
10753 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10754         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10755                               port_id, UINT16);
10756 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10757         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10758                                  vlan, "vlan");
10759 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10760         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10761                               vlan_mask, UINT16);
10762 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10763         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10764                                  src_mask, "src_mask");
10765 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10766         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10767                                  ipv4_src);
10768 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10769         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10770                                  ipv6_src);
10771 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10772         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10773                               port_src, UINT16);
10774 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10776                                  dst_mask, "dst_mask");
10777 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10778         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10779                                  ipv4_dst);
10780 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10781         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10782                                  ipv6_dst);
10783 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10784         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10785                               port_dst, UINT16);
10786
10787 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10788         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10789                                  mode, "mode");
10790 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10791         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10792                                  mode_value, "IP");
10793 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10794         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10795                                  mode_value, "MAC-VLAN");
10796 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10797         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10798                                  mode_value, "Tunnel");
10799 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10800         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10801                                  mac, "mac");
10802 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10803         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10804                               mac_addr_byte_mask, UINT8);
10805 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10806         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10807                                  tunnel_type, "tunnel-type");
10808 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10809         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10810                               tunnel_type_mask, UINT8);
10811 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10812         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10813                                  tunnel_id, "tunnel-id");
10814 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10815         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10816                               tunnel_id_mask, UINT32);
10817
10818 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10819         .f = cmd_flow_director_mask_parsed,
10820         .data = NULL,
10821         .help_str = "flow_director_mask ... : "
10822                 "Set IP mode flow director's mask on NIC",
10823         .tokens = {
10824                 (void *)&cmd_flow_director_mask,
10825                 (void *)&cmd_flow_director_mask_port_id,
10826                 (void *)&cmd_flow_director_mask_mode,
10827                 (void *)&cmd_flow_director_mask_mode_ip,
10828                 (void *)&cmd_flow_director_mask_vlan,
10829                 (void *)&cmd_flow_director_mask_vlan_value,
10830                 (void *)&cmd_flow_director_mask_src,
10831                 (void *)&cmd_flow_director_mask_ipv4_src,
10832                 (void *)&cmd_flow_director_mask_ipv6_src,
10833                 (void *)&cmd_flow_director_mask_port_src,
10834                 (void *)&cmd_flow_director_mask_dst,
10835                 (void *)&cmd_flow_director_mask_ipv4_dst,
10836                 (void *)&cmd_flow_director_mask_ipv6_dst,
10837                 (void *)&cmd_flow_director_mask_port_dst,
10838                 NULL,
10839         },
10840 };
10841
10842 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10843         .f = cmd_flow_director_mask_parsed,
10844         .data = NULL,
10845         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10846                 "flow director's mask on NIC",
10847         .tokens = {
10848                 (void *)&cmd_flow_director_mask,
10849                 (void *)&cmd_flow_director_mask_port_id,
10850                 (void *)&cmd_flow_director_mask_mode,
10851                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10852                 (void *)&cmd_flow_director_mask_vlan,
10853                 (void *)&cmd_flow_director_mask_vlan_value,
10854                 NULL,
10855         },
10856 };
10857
10858 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10859         .f = cmd_flow_director_mask_parsed,
10860         .data = NULL,
10861         .help_str = "flow_director_mask ... : Set tunnel mode "
10862                 "flow director's mask on NIC",
10863         .tokens = {
10864                 (void *)&cmd_flow_director_mask,
10865                 (void *)&cmd_flow_director_mask_port_id,
10866                 (void *)&cmd_flow_director_mask_mode,
10867                 (void *)&cmd_flow_director_mask_mode_tunnel,
10868                 (void *)&cmd_flow_director_mask_vlan,
10869                 (void *)&cmd_flow_director_mask_vlan_value,
10870                 (void *)&cmd_flow_director_mask_mac,
10871                 (void *)&cmd_flow_director_mask_mac_value,
10872                 (void *)&cmd_flow_director_mask_tunnel_type,
10873                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10874                 (void *)&cmd_flow_director_mask_tunnel_id,
10875                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10876                 NULL,
10877         },
10878 };
10879
10880 /* *** deal with flow director mask on flexible payload *** */
10881 struct cmd_flow_director_flex_mask_result {
10882         cmdline_fixed_string_t flow_director_flexmask;
10883         portid_t port_id;
10884         cmdline_fixed_string_t flow;
10885         cmdline_fixed_string_t flow_type;
10886         cmdline_fixed_string_t mask;
10887 };
10888
10889 static void
10890 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10891                           __attribute__((unused)) struct cmdline *cl,
10892                           __attribute__((unused)) void *data)
10893 {
10894         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10895         struct rte_eth_fdir_info fdir_info;
10896         struct rte_eth_fdir_flex_mask flex_mask;
10897         struct rte_port *port;
10898         uint32_t flow_type_mask;
10899         uint16_t i;
10900         int ret;
10901
10902         if (res->port_id > nb_ports) {
10903                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10904                 return;
10905         }
10906
10907         port = &ports[res->port_id];
10908         /** Check if the port is not started **/
10909         if (port->port_status != RTE_PORT_STOPPED) {
10910                 printf("Please stop port %d first\n", res->port_id);
10911                 return;
10912         }
10913
10914         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10915         ret = parse_flexbytes(res->mask,
10916                         flex_mask.mask,
10917                         RTE_ETH_FDIR_MAX_FLEXLEN);
10918         if (ret < 0) {
10919                 printf("error: Cannot parse mask input.\n");
10920                 return;
10921         }
10922
10923         memset(&fdir_info, 0, sizeof(fdir_info));
10924         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10925                                 RTE_ETH_FILTER_INFO, &fdir_info);
10926         if (ret < 0) {
10927                 printf("Cannot get FDir filter info\n");
10928                 return;
10929         }
10930
10931         if (!strcmp(res->flow_type, "none")) {
10932                 /* means don't specify the flow type */
10933                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10934                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10935                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10936                                0, sizeof(struct rte_eth_fdir_flex_mask));
10937                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10938                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10939                                  &flex_mask,
10940                                  sizeof(struct rte_eth_fdir_flex_mask));
10941                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10942                 return;
10943         }
10944         flow_type_mask = fdir_info.flow_types_mask[0];
10945         if (!strcmp(res->flow_type, "all")) {
10946                 if (!flow_type_mask) {
10947                         printf("No flow type supported\n");
10948                         return;
10949                 }
10950                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10951                         if (flow_type_mask & (1 << i)) {
10952                                 flex_mask.flow_type = i;
10953                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10954                         }
10955                 }
10956                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10957                 return;
10958         }
10959         flex_mask.flow_type = str2flowtype(res->flow_type);
10960         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10961                 printf("Flow type %s not supported on port %d\n",
10962                                 res->flow_type, res->port_id);
10963                 return;
10964         }
10965         fdir_set_flex_mask(res->port_id, &flex_mask);
10966         cmd_reconfig_device_queue(res->port_id, 1, 1);
10967 }
10968
10969 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10970         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10971                                  flow_director_flexmask,
10972                                  "flow_director_flex_mask");
10973 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10974         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10975                               port_id, UINT16);
10976 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10977         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10978                                  flow, "flow");
10979 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10981                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10982                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10983 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10985                                  mask, NULL);
10986
10987 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10988         .f = cmd_flow_director_flex_mask_parsed,
10989         .data = NULL,
10990         .help_str = "flow_director_flex_mask ... : "
10991                 "Set flow director's flex mask on NIC",
10992         .tokens = {
10993                 (void *)&cmd_flow_director_flexmask,
10994                 (void *)&cmd_flow_director_flexmask_port_id,
10995                 (void *)&cmd_flow_director_flexmask_flow,
10996                 (void *)&cmd_flow_director_flexmask_flow_type,
10997                 (void *)&cmd_flow_director_flexmask_mask,
10998                 NULL,
10999         },
11000 };
11001
11002 /* *** deal with flow director flexible payload configuration *** */
11003 struct cmd_flow_director_flexpayload_result {
11004         cmdline_fixed_string_t flow_director_flexpayload;
11005         portid_t port_id;
11006         cmdline_fixed_string_t payload_layer;
11007         cmdline_fixed_string_t payload_cfg;
11008 };
11009
11010 static inline int
11011 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11012 {
11013         char s[256];
11014         const char *p, *p0 = q_arg;
11015         char *end;
11016         unsigned long int_fld;
11017         char *str_fld[max_num];
11018         int i;
11019         unsigned size;
11020         int ret = -1;
11021
11022         p = strchr(p0, '(');
11023         if (p == NULL)
11024                 return -1;
11025         ++p;
11026         p0 = strchr(p, ')');
11027         if (p0 == NULL)
11028                 return -1;
11029
11030         size = p0 - p;
11031         if (size >= sizeof(s))
11032                 return -1;
11033
11034         snprintf(s, sizeof(s), "%.*s", size, p);
11035         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11036         if (ret < 0 || ret > max_num)
11037                 return -1;
11038         for (i = 0; i < ret; i++) {
11039                 errno = 0;
11040                 int_fld = strtoul(str_fld[i], &end, 0);
11041                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11042                         return -1;
11043                 offsets[i] = (uint16_t)int_fld;
11044         }
11045         return ret;
11046 }
11047
11048 static void
11049 cmd_flow_director_flxpld_parsed(void *parsed_result,
11050                           __attribute__((unused)) struct cmdline *cl,
11051                           __attribute__((unused)) void *data)
11052 {
11053         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11054         struct rte_eth_flex_payload_cfg flex_cfg;
11055         struct rte_port *port;
11056         int ret = 0;
11057
11058         if (res->port_id > nb_ports) {
11059                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11060                 return;
11061         }
11062
11063         port = &ports[res->port_id];
11064         /** Check if the port is not started **/
11065         if (port->port_status != RTE_PORT_STOPPED) {
11066                 printf("Please stop port %d first\n", res->port_id);
11067                 return;
11068         }
11069
11070         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11071
11072         if (!strcmp(res->payload_layer, "raw"))
11073                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11074         else if (!strcmp(res->payload_layer, "l2"))
11075                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11076         else if (!strcmp(res->payload_layer, "l3"))
11077                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11078         else if (!strcmp(res->payload_layer, "l4"))
11079                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11080
11081         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11082                             RTE_ETH_FDIR_MAX_FLEXLEN);
11083         if (ret < 0) {
11084                 printf("error: Cannot parse flex payload input.\n");
11085                 return;
11086         }
11087
11088         fdir_set_flex_payload(res->port_id, &flex_cfg);
11089         cmd_reconfig_device_queue(res->port_id, 1, 1);
11090 }
11091
11092 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11093         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11094                                  flow_director_flexpayload,
11095                                  "flow_director_flex_payload");
11096 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11097         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11098                               port_id, UINT16);
11099 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11100         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11101                                  payload_layer, "raw#l2#l3#l4");
11102 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11103         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11104                                  payload_cfg, NULL);
11105
11106 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11107         .f = cmd_flow_director_flxpld_parsed,
11108         .data = NULL,
11109         .help_str = "flow_director_flexpayload ... : "
11110                 "Set flow director's flex payload on NIC",
11111         .tokens = {
11112                 (void *)&cmd_flow_director_flexpayload,
11113                 (void *)&cmd_flow_director_flexpayload_port_id,
11114                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11115                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11116                 NULL,
11117         },
11118 };
11119
11120 /* Generic flow interface command. */
11121 extern cmdline_parse_inst_t cmd_flow;
11122
11123 /* *** Classification Filters Control *** */
11124 /* *** Get symmetric hash enable per port *** */
11125 struct cmd_get_sym_hash_ena_per_port_result {
11126         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11127         portid_t port_id;
11128 };
11129
11130 static void
11131 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11132                                  __rte_unused struct cmdline *cl,
11133                                  __rte_unused void *data)
11134 {
11135         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11136         struct rte_eth_hash_filter_info info;
11137         int ret;
11138
11139         if (rte_eth_dev_filter_supported(res->port_id,
11140                                 RTE_ETH_FILTER_HASH) < 0) {
11141                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11142                                                         res->port_id);
11143                 return;
11144         }
11145
11146         memset(&info, 0, sizeof(info));
11147         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11148         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11149                                                 RTE_ETH_FILTER_GET, &info);
11150
11151         if (ret < 0) {
11152                 printf("Cannot get symmetric hash enable per port "
11153                                         "on port %u\n", res->port_id);
11154                 return;
11155         }
11156
11157         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11158                                 "enabled" : "disabled", res->port_id);
11159 }
11160
11161 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11162         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11163                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11164 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11165         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11166                 port_id, UINT16);
11167
11168 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11169         .f = cmd_get_sym_hash_per_port_parsed,
11170         .data = NULL,
11171         .help_str = "get_sym_hash_ena_per_port <port_id>",
11172         .tokens = {
11173                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11174                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11175                 NULL,
11176         },
11177 };
11178
11179 /* *** Set symmetric hash enable per port *** */
11180 struct cmd_set_sym_hash_ena_per_port_result {
11181         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11182         cmdline_fixed_string_t enable;
11183         portid_t port_id;
11184 };
11185
11186 static void
11187 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11188                                  __rte_unused struct cmdline *cl,
11189                                  __rte_unused void *data)
11190 {
11191         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11192         struct rte_eth_hash_filter_info info;
11193         int ret;
11194
11195         if (rte_eth_dev_filter_supported(res->port_id,
11196                                 RTE_ETH_FILTER_HASH) < 0) {
11197                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11198                                                         res->port_id);
11199                 return;
11200         }
11201
11202         memset(&info, 0, sizeof(info));
11203         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11204         if (!strcmp(res->enable, "enable"))
11205                 info.info.enable = 1;
11206         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11207                                         RTE_ETH_FILTER_SET, &info);
11208         if (ret < 0) {
11209                 printf("Cannot set symmetric hash enable per port on "
11210                                         "port %u\n", res->port_id);
11211                 return;
11212         }
11213         printf("Symmetric hash has been set to %s on port %u\n",
11214                                         res->enable, res->port_id);
11215 }
11216
11217 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11218         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11219                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11220 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11221         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11222                 port_id, UINT16);
11223 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11224         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11225                 enable, "enable#disable");
11226
11227 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11228         .f = cmd_set_sym_hash_per_port_parsed,
11229         .data = NULL,
11230         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11231         .tokens = {
11232                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11233                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11234                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11235                 NULL,
11236         },
11237 };
11238
11239 /* Get global config of hash function */
11240 struct cmd_get_hash_global_config_result {
11241         cmdline_fixed_string_t get_hash_global_config;
11242         portid_t port_id;
11243 };
11244
11245 static char *
11246 flowtype_to_str(uint16_t ftype)
11247 {
11248         uint16_t i;
11249         static struct {
11250                 char str[16];
11251                 uint16_t ftype;
11252         } ftype_table[] = {
11253                 {"ipv4", RTE_ETH_FLOW_IPV4},
11254                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11255                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11256                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11257                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11258                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11259                 {"ipv6", RTE_ETH_FLOW_IPV6},
11260                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11261                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11262                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11263                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11264                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11265                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11266                 {"port", RTE_ETH_FLOW_PORT},
11267                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11268                 {"geneve", RTE_ETH_FLOW_GENEVE},
11269                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11270         };
11271
11272         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11273                 if (ftype_table[i].ftype == ftype)
11274                         return ftype_table[i].str;
11275         }
11276
11277         return NULL;
11278 }
11279
11280 static void
11281 cmd_get_hash_global_config_parsed(void *parsed_result,
11282                                   __rte_unused struct cmdline *cl,
11283                                   __rte_unused void *data)
11284 {
11285         struct cmd_get_hash_global_config_result *res = parsed_result;
11286         struct rte_eth_hash_filter_info info;
11287         uint32_t idx, offset;
11288         uint16_t i;
11289         char *str;
11290         int ret;
11291
11292         if (rte_eth_dev_filter_supported(res->port_id,
11293                         RTE_ETH_FILTER_HASH) < 0) {
11294                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11295                                                         res->port_id);
11296                 return;
11297         }
11298
11299         memset(&info, 0, sizeof(info));
11300         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11301         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11302                                         RTE_ETH_FILTER_GET, &info);
11303         if (ret < 0) {
11304                 printf("Cannot get hash global configurations by port %d\n",
11305                                                         res->port_id);
11306                 return;
11307         }
11308
11309         switch (info.info.global_conf.hash_func) {
11310         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11311                 printf("Hash function is Toeplitz\n");
11312                 break;
11313         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11314                 printf("Hash function is Simple XOR\n");
11315                 break;
11316         default:
11317                 printf("Unknown hash function\n");
11318                 break;
11319         }
11320
11321         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11322                 idx = i / UINT32_BIT;
11323                 offset = i % UINT32_BIT;
11324                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11325                                                 (1UL << offset)))
11326                         continue;
11327                 str = flowtype_to_str(i);
11328                 if (!str)
11329                         continue;
11330                 printf("Symmetric hash is %s globally for flow type %s "
11331                                                         "by port %d\n",
11332                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11333                         (1UL << offset)) ? "enabled" : "disabled"), str,
11334                                                         res->port_id);
11335         }
11336 }
11337
11338 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11339         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11340                 get_hash_global_config, "get_hash_global_config");
11341 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11342         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11343                 port_id, UINT16);
11344
11345 cmdline_parse_inst_t cmd_get_hash_global_config = {
11346         .f = cmd_get_hash_global_config_parsed,
11347         .data = NULL,
11348         .help_str = "get_hash_global_config <port_id>",
11349         .tokens = {
11350                 (void *)&cmd_get_hash_global_config_all,
11351                 (void *)&cmd_get_hash_global_config_port_id,
11352                 NULL,
11353         },
11354 };
11355
11356 /* Set global config of hash function */
11357 struct cmd_set_hash_global_config_result {
11358         cmdline_fixed_string_t set_hash_global_config;
11359         portid_t port_id;
11360         cmdline_fixed_string_t hash_func;
11361         cmdline_fixed_string_t flow_type;
11362         cmdline_fixed_string_t enable;
11363 };
11364
11365 static void
11366 cmd_set_hash_global_config_parsed(void *parsed_result,
11367                                   __rte_unused struct cmdline *cl,
11368                                   __rte_unused void *data)
11369 {
11370         struct cmd_set_hash_global_config_result *res = parsed_result;
11371         struct rte_eth_hash_filter_info info;
11372         uint32_t ftype, idx, offset;
11373         int ret;
11374
11375         if (rte_eth_dev_filter_supported(res->port_id,
11376                                 RTE_ETH_FILTER_HASH) < 0) {
11377                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11378                                                         res->port_id);
11379                 return;
11380         }
11381         memset(&info, 0, sizeof(info));
11382         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11383         if (!strcmp(res->hash_func, "toeplitz"))
11384                 info.info.global_conf.hash_func =
11385                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11386         else if (!strcmp(res->hash_func, "simple_xor"))
11387                 info.info.global_conf.hash_func =
11388                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11389         else if (!strcmp(res->hash_func, "default"))
11390                 info.info.global_conf.hash_func =
11391                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11392
11393         ftype = str2flowtype(res->flow_type);
11394         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11395         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11396         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11397         if (!strcmp(res->enable, "enable"))
11398                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11399                                                 (1UL << offset);
11400         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11401                                         RTE_ETH_FILTER_SET, &info);
11402         if (ret < 0)
11403                 printf("Cannot set global hash configurations by port %d\n",
11404                                                         res->port_id);
11405         else
11406                 printf("Global hash configurations have been set "
11407                         "succcessfully by port %d\n", res->port_id);
11408 }
11409
11410 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11411         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11412                 set_hash_global_config, "set_hash_global_config");
11413 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11414         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11415                 port_id, UINT16);
11416 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11417         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11418                 hash_func, "toeplitz#simple_xor#default");
11419 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11420         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11421                 flow_type,
11422                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11423                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11424 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11425         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11426                 enable, "enable#disable");
11427
11428 cmdline_parse_inst_t cmd_set_hash_global_config = {
11429         .f = cmd_set_hash_global_config_parsed,
11430         .data = NULL,
11431         .help_str = "set_hash_global_config <port_id> "
11432                 "toeplitz|simple_xor|default "
11433                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11434                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11435                 "l2_payload enable|disable",
11436         .tokens = {
11437                 (void *)&cmd_set_hash_global_config_all,
11438                 (void *)&cmd_set_hash_global_config_port_id,
11439                 (void *)&cmd_set_hash_global_config_hash_func,
11440                 (void *)&cmd_set_hash_global_config_flow_type,
11441                 (void *)&cmd_set_hash_global_config_enable,
11442                 NULL,
11443         },
11444 };
11445
11446 /* Set hash input set */
11447 struct cmd_set_hash_input_set_result {
11448         cmdline_fixed_string_t set_hash_input_set;
11449         portid_t port_id;
11450         cmdline_fixed_string_t flow_type;
11451         cmdline_fixed_string_t inset_field;
11452         cmdline_fixed_string_t select;
11453 };
11454
11455 static enum rte_eth_input_set_field
11456 str2inset(char *string)
11457 {
11458         uint16_t i;
11459
11460         static const struct {
11461                 char str[32];
11462                 enum rte_eth_input_set_field inset;
11463         } inset_table[] = {
11464                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11465                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11466                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11467                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11468                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11469                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11470                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11471                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11472                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11473                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11474                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11475                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11476                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11477                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11478                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11479                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11480                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11481                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11482                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11483                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11484                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11485                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11486                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11487                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11488                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11489                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11490                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11491                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11492                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11493                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11494                 {"none", RTE_ETH_INPUT_SET_NONE},
11495         };
11496
11497         for (i = 0; i < RTE_DIM(inset_table); i++) {
11498                 if (!strcmp(string, inset_table[i].str))
11499                         return inset_table[i].inset;
11500         }
11501
11502         return RTE_ETH_INPUT_SET_UNKNOWN;
11503 }
11504
11505 static void
11506 cmd_set_hash_input_set_parsed(void *parsed_result,
11507                               __rte_unused struct cmdline *cl,
11508                               __rte_unused void *data)
11509 {
11510         struct cmd_set_hash_input_set_result *res = parsed_result;
11511         struct rte_eth_hash_filter_info info;
11512
11513         memset(&info, 0, sizeof(info));
11514         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11515         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11516         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11517         info.info.input_set_conf.inset_size = 1;
11518         if (!strcmp(res->select, "select"))
11519                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11520         else if (!strcmp(res->select, "add"))
11521                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11522         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11523                                 RTE_ETH_FILTER_SET, &info);
11524 }
11525
11526 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11527         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11528                 set_hash_input_set, "set_hash_input_set");
11529 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11530         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11531                 port_id, UINT16);
11532 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11533         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11534                 flow_type, NULL);
11535 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11536         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11537                 inset_field,
11538                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11539                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11540                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11541                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11542                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11543                 "fld-8th#none");
11544 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11545         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11546                 select, "select#add");
11547
11548 cmdline_parse_inst_t cmd_set_hash_input_set = {
11549         .f = cmd_set_hash_input_set_parsed,
11550         .data = NULL,
11551         .help_str = "set_hash_input_set <port_id> "
11552         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11553         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11554         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11555         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11556         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11557         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11558         "fld-7th|fld-8th|none select|add",
11559         .tokens = {
11560                 (void *)&cmd_set_hash_input_set_cmd,
11561                 (void *)&cmd_set_hash_input_set_port_id,
11562                 (void *)&cmd_set_hash_input_set_flow_type,
11563                 (void *)&cmd_set_hash_input_set_field,
11564                 (void *)&cmd_set_hash_input_set_select,
11565                 NULL,
11566         },
11567 };
11568
11569 /* Set flow director input set */
11570 struct cmd_set_fdir_input_set_result {
11571         cmdline_fixed_string_t set_fdir_input_set;
11572         portid_t port_id;
11573         cmdline_fixed_string_t flow_type;
11574         cmdline_fixed_string_t inset_field;
11575         cmdline_fixed_string_t select;
11576 };
11577
11578 static void
11579 cmd_set_fdir_input_set_parsed(void *parsed_result,
11580         __rte_unused struct cmdline *cl,
11581         __rte_unused void *data)
11582 {
11583         struct cmd_set_fdir_input_set_result *res = parsed_result;
11584         struct rte_eth_fdir_filter_info info;
11585
11586         memset(&info, 0, sizeof(info));
11587         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11588         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11589         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11590         info.info.input_set_conf.inset_size = 1;
11591         if (!strcmp(res->select, "select"))
11592                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11593         else if (!strcmp(res->select, "add"))
11594                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11595         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11596                 RTE_ETH_FILTER_SET, &info);
11597 }
11598
11599 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11600         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11601         set_fdir_input_set, "set_fdir_input_set");
11602 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11603         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11604         port_id, UINT16);
11605 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11606         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11607         flow_type,
11608         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11609         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11610 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11611         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11612         inset_field,
11613         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11614         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11615         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11616         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11617         "sctp-veri-tag#none");
11618 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11619         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11620         select, "select#add");
11621
11622 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11623         .f = cmd_set_fdir_input_set_parsed,
11624         .data = NULL,
11625         .help_str = "set_fdir_input_set <port_id> "
11626         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11627         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11628         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11629         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11630         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11631         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11632         "sctp-veri-tag|none select|add",
11633         .tokens = {
11634                 (void *)&cmd_set_fdir_input_set_cmd,
11635                 (void *)&cmd_set_fdir_input_set_port_id,
11636                 (void *)&cmd_set_fdir_input_set_flow_type,
11637                 (void *)&cmd_set_fdir_input_set_field,
11638                 (void *)&cmd_set_fdir_input_set_select,
11639                 NULL,
11640         },
11641 };
11642
11643 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11644 struct cmd_mcast_addr_result {
11645         cmdline_fixed_string_t mcast_addr_cmd;
11646         cmdline_fixed_string_t what;
11647         uint16_t port_num;
11648         struct ether_addr mc_addr;
11649 };
11650
11651 static void cmd_mcast_addr_parsed(void *parsed_result,
11652                 __attribute__((unused)) struct cmdline *cl,
11653                 __attribute__((unused)) void *data)
11654 {
11655         struct cmd_mcast_addr_result *res = parsed_result;
11656
11657         if (!is_multicast_ether_addr(&res->mc_addr)) {
11658                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11659                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11660                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11661                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11662                 return;
11663         }
11664         if (strcmp(res->what, "add") == 0)
11665                 mcast_addr_add(res->port_num, &res->mc_addr);
11666         else
11667                 mcast_addr_remove(res->port_num, &res->mc_addr);
11668 }
11669
11670 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11671         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11672                                  mcast_addr_cmd, "mcast_addr");
11673 cmdline_parse_token_string_t cmd_mcast_addr_what =
11674         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11675                                  "add#remove");
11676 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11677         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11678 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11679         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11680
11681 cmdline_parse_inst_t cmd_mcast_addr = {
11682         .f = cmd_mcast_addr_parsed,
11683         .data = (void *)0,
11684         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11685                 "Add/Remove multicast MAC address on port_id",
11686         .tokens = {
11687                 (void *)&cmd_mcast_addr_cmd,
11688                 (void *)&cmd_mcast_addr_what,
11689                 (void *)&cmd_mcast_addr_portnum,
11690                 (void *)&cmd_mcast_addr_addr,
11691                 NULL,
11692         },
11693 };
11694
11695 /* l2 tunnel config
11696  * only support E-tag now.
11697  */
11698
11699 /* Ether type config */
11700 struct cmd_config_l2_tunnel_eth_type_result {
11701         cmdline_fixed_string_t port;
11702         cmdline_fixed_string_t config;
11703         cmdline_fixed_string_t all;
11704         uint8_t id;
11705         cmdline_fixed_string_t l2_tunnel;
11706         cmdline_fixed_string_t l2_tunnel_type;
11707         cmdline_fixed_string_t eth_type;
11708         uint16_t eth_type_val;
11709 };
11710
11711 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11712         TOKEN_STRING_INITIALIZER
11713                 (struct cmd_config_l2_tunnel_eth_type_result,
11714                  port, "port");
11715 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11716         TOKEN_STRING_INITIALIZER
11717                 (struct cmd_config_l2_tunnel_eth_type_result,
11718                  config, "config");
11719 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11720         TOKEN_STRING_INITIALIZER
11721                 (struct cmd_config_l2_tunnel_eth_type_result,
11722                  all, "all");
11723 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11724         TOKEN_NUM_INITIALIZER
11725                 (struct cmd_config_l2_tunnel_eth_type_result,
11726                  id, UINT8);
11727 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11728         TOKEN_STRING_INITIALIZER
11729                 (struct cmd_config_l2_tunnel_eth_type_result,
11730                  l2_tunnel, "l2-tunnel");
11731 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11732         TOKEN_STRING_INITIALIZER
11733                 (struct cmd_config_l2_tunnel_eth_type_result,
11734                  l2_tunnel_type, "E-tag");
11735 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_config_l2_tunnel_eth_type_result,
11738                  eth_type, "ether-type");
11739 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11740         TOKEN_NUM_INITIALIZER
11741                 (struct cmd_config_l2_tunnel_eth_type_result,
11742                  eth_type_val, UINT16);
11743
11744 static enum rte_eth_tunnel_type
11745 str2fdir_l2_tunnel_type(char *string)
11746 {
11747         uint32_t i = 0;
11748
11749         static const struct {
11750                 char str[32];
11751                 enum rte_eth_tunnel_type type;
11752         } l2_tunnel_type_str[] = {
11753                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11754         };
11755
11756         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11757                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11758                         return l2_tunnel_type_str[i].type;
11759         }
11760         return RTE_TUNNEL_TYPE_NONE;
11761 }
11762
11763 /* ether type config for all ports */
11764 static void
11765 cmd_config_l2_tunnel_eth_type_all_parsed
11766         (void *parsed_result,
11767          __attribute__((unused)) struct cmdline *cl,
11768          __attribute__((unused)) void *data)
11769 {
11770         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11771         struct rte_eth_l2_tunnel_conf entry;
11772         portid_t pid;
11773
11774         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11775         entry.ether_type = res->eth_type_val;
11776
11777         RTE_ETH_FOREACH_DEV(pid) {
11778                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11779         }
11780 }
11781
11782 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11783         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11784         .data = NULL,
11785         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11786         .tokens = {
11787                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11788                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11789                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11790                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11791                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11792                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11793                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11794                 NULL,
11795         },
11796 };
11797
11798 /* ether type config for a specific port */
11799 static void
11800 cmd_config_l2_tunnel_eth_type_specific_parsed(
11801         void *parsed_result,
11802         __attribute__((unused)) struct cmdline *cl,
11803         __attribute__((unused)) void *data)
11804 {
11805         struct cmd_config_l2_tunnel_eth_type_result *res =
11806                  parsed_result;
11807         struct rte_eth_l2_tunnel_conf entry;
11808
11809         if (port_id_is_invalid(res->id, ENABLED_WARN))
11810                 return;
11811
11812         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11813         entry.ether_type = res->eth_type_val;
11814
11815         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11816 }
11817
11818 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11819         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11820         .data = NULL,
11821         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11822         .tokens = {
11823                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11824                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11825                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11826                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11827                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11828                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11829                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11830                 NULL,
11831         },
11832 };
11833
11834 /* Enable/disable l2 tunnel */
11835 struct cmd_config_l2_tunnel_en_dis_result {
11836         cmdline_fixed_string_t port;
11837         cmdline_fixed_string_t config;
11838         cmdline_fixed_string_t all;
11839         uint8_t id;
11840         cmdline_fixed_string_t l2_tunnel;
11841         cmdline_fixed_string_t l2_tunnel_type;
11842         cmdline_fixed_string_t en_dis;
11843 };
11844
11845 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11846         TOKEN_STRING_INITIALIZER
11847                 (struct cmd_config_l2_tunnel_en_dis_result,
11848                  port, "port");
11849 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11850         TOKEN_STRING_INITIALIZER
11851                 (struct cmd_config_l2_tunnel_en_dis_result,
11852                  config, "config");
11853 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11854         TOKEN_STRING_INITIALIZER
11855                 (struct cmd_config_l2_tunnel_en_dis_result,
11856                  all, "all");
11857 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11858         TOKEN_NUM_INITIALIZER
11859                 (struct cmd_config_l2_tunnel_en_dis_result,
11860                  id, UINT8);
11861 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11862         TOKEN_STRING_INITIALIZER
11863                 (struct cmd_config_l2_tunnel_en_dis_result,
11864                  l2_tunnel, "l2-tunnel");
11865 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11866         TOKEN_STRING_INITIALIZER
11867                 (struct cmd_config_l2_tunnel_en_dis_result,
11868                  l2_tunnel_type, "E-tag");
11869 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11870         TOKEN_STRING_INITIALIZER
11871                 (struct cmd_config_l2_tunnel_en_dis_result,
11872                  en_dis, "enable#disable");
11873
11874 /* enable/disable l2 tunnel for all ports */
11875 static void
11876 cmd_config_l2_tunnel_en_dis_all_parsed(
11877         void *parsed_result,
11878         __attribute__((unused)) struct cmdline *cl,
11879         __attribute__((unused)) void *data)
11880 {
11881         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11882         struct rte_eth_l2_tunnel_conf entry;
11883         portid_t pid;
11884         uint8_t en;
11885
11886         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11887
11888         if (!strcmp("enable", res->en_dis))
11889                 en = 1;
11890         else
11891                 en = 0;
11892
11893         RTE_ETH_FOREACH_DEV(pid) {
11894                 rte_eth_dev_l2_tunnel_offload_set(pid,
11895                                                   &entry,
11896                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11897                                                   en);
11898         }
11899 }
11900
11901 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11902         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11903         .data = NULL,
11904         .help_str = "port config all l2-tunnel E-tag enable|disable",
11905         .tokens = {
11906                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11907                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11908                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11909                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11910                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11911                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11912                 NULL,
11913         },
11914 };
11915
11916 /* enable/disable l2 tunnel for a port */
11917 static void
11918 cmd_config_l2_tunnel_en_dis_specific_parsed(
11919         void *parsed_result,
11920         __attribute__((unused)) struct cmdline *cl,
11921         __attribute__((unused)) void *data)
11922 {
11923         struct cmd_config_l2_tunnel_en_dis_result *res =
11924                 parsed_result;
11925         struct rte_eth_l2_tunnel_conf entry;
11926
11927         if (port_id_is_invalid(res->id, ENABLED_WARN))
11928                 return;
11929
11930         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11931
11932         if (!strcmp("enable", res->en_dis))
11933                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11934                                                   &entry,
11935                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11936                                                   1);
11937         else
11938                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11939                                                   &entry,
11940                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11941                                                   0);
11942 }
11943
11944 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11945         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11946         .data = NULL,
11947         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11948         .tokens = {
11949                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11950                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11951                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11952                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11953                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11954                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11955                 NULL,
11956         },
11957 };
11958
11959 /* E-tag configuration */
11960
11961 /* Common result structure for all E-tag configuration */
11962 struct cmd_config_e_tag_result {
11963         cmdline_fixed_string_t e_tag;
11964         cmdline_fixed_string_t set;
11965         cmdline_fixed_string_t insertion;
11966         cmdline_fixed_string_t stripping;
11967         cmdline_fixed_string_t forwarding;
11968         cmdline_fixed_string_t filter;
11969         cmdline_fixed_string_t add;
11970         cmdline_fixed_string_t del;
11971         cmdline_fixed_string_t on;
11972         cmdline_fixed_string_t off;
11973         cmdline_fixed_string_t on_off;
11974         cmdline_fixed_string_t port_tag_id;
11975         uint32_t port_tag_id_val;
11976         cmdline_fixed_string_t e_tag_id;
11977         uint16_t e_tag_id_val;
11978         cmdline_fixed_string_t dst_pool;
11979         uint8_t dst_pool_val;
11980         cmdline_fixed_string_t port;
11981         portid_t port_id;
11982         cmdline_fixed_string_t vf;
11983         uint8_t vf_id;
11984 };
11985
11986 /* Common CLI fields for all E-tag configuration */
11987 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11988         TOKEN_STRING_INITIALIZER
11989                 (struct cmd_config_e_tag_result,
11990                  e_tag, "E-tag");
11991 cmdline_parse_token_string_t cmd_config_e_tag_set =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_config_e_tag_result,
11994                  set, "set");
11995 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11996         TOKEN_STRING_INITIALIZER
11997                 (struct cmd_config_e_tag_result,
11998                  insertion, "insertion");
11999 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_config_e_tag_result,
12002                  stripping, "stripping");
12003 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12004         TOKEN_STRING_INITIALIZER
12005                 (struct cmd_config_e_tag_result,
12006                  forwarding, "forwarding");
12007 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_e_tag_result,
12010                  filter, "filter");
12011 cmdline_parse_token_string_t cmd_config_e_tag_add =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_config_e_tag_result,
12014                  add, "add");
12015 cmdline_parse_token_string_t cmd_config_e_tag_del =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_config_e_tag_result,
12018                  del, "del");
12019 cmdline_parse_token_string_t cmd_config_e_tag_on =
12020         TOKEN_STRING_INITIALIZER
12021                 (struct cmd_config_e_tag_result,
12022                  on, "on");
12023 cmdline_parse_token_string_t cmd_config_e_tag_off =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_config_e_tag_result,
12026                  off, "off");
12027 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12028         TOKEN_STRING_INITIALIZER
12029                 (struct cmd_config_e_tag_result,
12030                  on_off, "on#off");
12031 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12032         TOKEN_STRING_INITIALIZER
12033                 (struct cmd_config_e_tag_result,
12034                  port_tag_id, "port-tag-id");
12035 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12036         TOKEN_NUM_INITIALIZER
12037                 (struct cmd_config_e_tag_result,
12038                  port_tag_id_val, UINT32);
12039 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12040         TOKEN_STRING_INITIALIZER
12041                 (struct cmd_config_e_tag_result,
12042                  e_tag_id, "e-tag-id");
12043 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12044         TOKEN_NUM_INITIALIZER
12045                 (struct cmd_config_e_tag_result,
12046                  e_tag_id_val, UINT16);
12047 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12048         TOKEN_STRING_INITIALIZER
12049                 (struct cmd_config_e_tag_result,
12050                  dst_pool, "dst-pool");
12051 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12052         TOKEN_NUM_INITIALIZER
12053                 (struct cmd_config_e_tag_result,
12054                  dst_pool_val, UINT8);
12055 cmdline_parse_token_string_t cmd_config_e_tag_port =
12056         TOKEN_STRING_INITIALIZER
12057                 (struct cmd_config_e_tag_result,
12058                  port, "port");
12059 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12060         TOKEN_NUM_INITIALIZER
12061                 (struct cmd_config_e_tag_result,
12062                  port_id, UINT16);
12063 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12064         TOKEN_STRING_INITIALIZER
12065                 (struct cmd_config_e_tag_result,
12066                  vf, "vf");
12067 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12068         TOKEN_NUM_INITIALIZER
12069                 (struct cmd_config_e_tag_result,
12070                  vf_id, UINT8);
12071
12072 /* E-tag insertion configuration */
12073 static void
12074 cmd_config_e_tag_insertion_en_parsed(
12075         void *parsed_result,
12076         __attribute__((unused)) struct cmdline *cl,
12077         __attribute__((unused)) void *data)
12078 {
12079         struct cmd_config_e_tag_result *res =
12080                 parsed_result;
12081         struct rte_eth_l2_tunnel_conf entry;
12082
12083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12084                 return;
12085
12086         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12087         entry.tunnel_id = res->port_tag_id_val;
12088         entry.vf_id = res->vf_id;
12089         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12090                                           &entry,
12091                                           ETH_L2_TUNNEL_INSERTION_MASK,
12092                                           1);
12093 }
12094
12095 static void
12096 cmd_config_e_tag_insertion_dis_parsed(
12097         void *parsed_result,
12098         __attribute__((unused)) struct cmdline *cl,
12099         __attribute__((unused)) void *data)
12100 {
12101         struct cmd_config_e_tag_result *res =
12102                 parsed_result;
12103         struct rte_eth_l2_tunnel_conf entry;
12104
12105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12106                 return;
12107
12108         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12109         entry.vf_id = res->vf_id;
12110
12111         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12112                                           &entry,
12113                                           ETH_L2_TUNNEL_INSERTION_MASK,
12114                                           0);
12115 }
12116
12117 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12118         .f = cmd_config_e_tag_insertion_en_parsed,
12119         .data = NULL,
12120         .help_str = "E-tag ... : E-tag insertion enable",
12121         .tokens = {
12122                 (void *)&cmd_config_e_tag_e_tag,
12123                 (void *)&cmd_config_e_tag_set,
12124                 (void *)&cmd_config_e_tag_insertion,
12125                 (void *)&cmd_config_e_tag_on,
12126                 (void *)&cmd_config_e_tag_port_tag_id,
12127                 (void *)&cmd_config_e_tag_port_tag_id_val,
12128                 (void *)&cmd_config_e_tag_port,
12129                 (void *)&cmd_config_e_tag_port_id,
12130                 (void *)&cmd_config_e_tag_vf,
12131                 (void *)&cmd_config_e_tag_vf_id,
12132                 NULL,
12133         },
12134 };
12135
12136 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12137         .f = cmd_config_e_tag_insertion_dis_parsed,
12138         .data = NULL,
12139         .help_str = "E-tag ... : E-tag insertion disable",
12140         .tokens = {
12141                 (void *)&cmd_config_e_tag_e_tag,
12142                 (void *)&cmd_config_e_tag_set,
12143                 (void *)&cmd_config_e_tag_insertion,
12144                 (void *)&cmd_config_e_tag_off,
12145                 (void *)&cmd_config_e_tag_port,
12146                 (void *)&cmd_config_e_tag_port_id,
12147                 (void *)&cmd_config_e_tag_vf,
12148                 (void *)&cmd_config_e_tag_vf_id,
12149                 NULL,
12150         },
12151 };
12152
12153 /* E-tag stripping configuration */
12154 static void
12155 cmd_config_e_tag_stripping_parsed(
12156         void *parsed_result,
12157         __attribute__((unused)) struct cmdline *cl,
12158         __attribute__((unused)) void *data)
12159 {
12160         struct cmd_config_e_tag_result *res =
12161                 parsed_result;
12162         struct rte_eth_l2_tunnel_conf entry;
12163
12164         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12165                 return;
12166
12167         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12168
12169         if (!strcmp(res->on_off, "on"))
12170                 rte_eth_dev_l2_tunnel_offload_set
12171                         (res->port_id,
12172                          &entry,
12173                          ETH_L2_TUNNEL_STRIPPING_MASK,
12174                          1);
12175         else
12176                 rte_eth_dev_l2_tunnel_offload_set
12177                         (res->port_id,
12178                          &entry,
12179                          ETH_L2_TUNNEL_STRIPPING_MASK,
12180                          0);
12181 }
12182
12183 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12184         .f = cmd_config_e_tag_stripping_parsed,
12185         .data = NULL,
12186         .help_str = "E-tag ... : E-tag stripping enable/disable",
12187         .tokens = {
12188                 (void *)&cmd_config_e_tag_e_tag,
12189                 (void *)&cmd_config_e_tag_set,
12190                 (void *)&cmd_config_e_tag_stripping,
12191                 (void *)&cmd_config_e_tag_on_off,
12192                 (void *)&cmd_config_e_tag_port,
12193                 (void *)&cmd_config_e_tag_port_id,
12194                 NULL,
12195         },
12196 };
12197
12198 /* E-tag forwarding configuration */
12199 static void
12200 cmd_config_e_tag_forwarding_parsed(
12201         void *parsed_result,
12202         __attribute__((unused)) struct cmdline *cl,
12203         __attribute__((unused)) void *data)
12204 {
12205         struct cmd_config_e_tag_result *res = parsed_result;
12206         struct rte_eth_l2_tunnel_conf entry;
12207
12208         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12209                 return;
12210
12211         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12212
12213         if (!strcmp(res->on_off, "on"))
12214                 rte_eth_dev_l2_tunnel_offload_set
12215                         (res->port_id,
12216                          &entry,
12217                          ETH_L2_TUNNEL_FORWARDING_MASK,
12218                          1);
12219         else
12220                 rte_eth_dev_l2_tunnel_offload_set
12221                         (res->port_id,
12222                          &entry,
12223                          ETH_L2_TUNNEL_FORWARDING_MASK,
12224                          0);
12225 }
12226
12227 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12228         .f = cmd_config_e_tag_forwarding_parsed,
12229         .data = NULL,
12230         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12231         .tokens = {
12232                 (void *)&cmd_config_e_tag_e_tag,
12233                 (void *)&cmd_config_e_tag_set,
12234                 (void *)&cmd_config_e_tag_forwarding,
12235                 (void *)&cmd_config_e_tag_on_off,
12236                 (void *)&cmd_config_e_tag_port,
12237                 (void *)&cmd_config_e_tag_port_id,
12238                 NULL,
12239         },
12240 };
12241
12242 /* E-tag filter configuration */
12243 static void
12244 cmd_config_e_tag_filter_add_parsed(
12245         void *parsed_result,
12246         __attribute__((unused)) struct cmdline *cl,
12247         __attribute__((unused)) void *data)
12248 {
12249         struct cmd_config_e_tag_result *res = parsed_result;
12250         struct rte_eth_l2_tunnel_conf entry;
12251         int ret = 0;
12252
12253         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12254                 return;
12255
12256         if (res->e_tag_id_val > 0x3fff) {
12257                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12258                 return;
12259         }
12260
12261         ret = rte_eth_dev_filter_supported(res->port_id,
12262                                            RTE_ETH_FILTER_L2_TUNNEL);
12263         if (ret < 0) {
12264                 printf("E-tag filter is not supported on port %u.\n",
12265                        res->port_id);
12266                 return;
12267         }
12268
12269         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12270         entry.tunnel_id = res->e_tag_id_val;
12271         entry.pool = res->dst_pool_val;
12272
12273         ret = rte_eth_dev_filter_ctrl(res->port_id,
12274                                       RTE_ETH_FILTER_L2_TUNNEL,
12275                                       RTE_ETH_FILTER_ADD,
12276                                       &entry);
12277         if (ret < 0)
12278                 printf("E-tag filter programming error: (%s)\n",
12279                        strerror(-ret));
12280 }
12281
12282 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12283         .f = cmd_config_e_tag_filter_add_parsed,
12284         .data = NULL,
12285         .help_str = "E-tag ... : E-tag filter add",
12286         .tokens = {
12287                 (void *)&cmd_config_e_tag_e_tag,
12288                 (void *)&cmd_config_e_tag_set,
12289                 (void *)&cmd_config_e_tag_filter,
12290                 (void *)&cmd_config_e_tag_add,
12291                 (void *)&cmd_config_e_tag_e_tag_id,
12292                 (void *)&cmd_config_e_tag_e_tag_id_val,
12293                 (void *)&cmd_config_e_tag_dst_pool,
12294                 (void *)&cmd_config_e_tag_dst_pool_val,
12295                 (void *)&cmd_config_e_tag_port,
12296                 (void *)&cmd_config_e_tag_port_id,
12297                 NULL,
12298         },
12299 };
12300
12301 static void
12302 cmd_config_e_tag_filter_del_parsed(
12303         void *parsed_result,
12304         __attribute__((unused)) struct cmdline *cl,
12305         __attribute__((unused)) void *data)
12306 {
12307         struct cmd_config_e_tag_result *res = parsed_result;
12308         struct rte_eth_l2_tunnel_conf entry;
12309         int ret = 0;
12310
12311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12312                 return;
12313
12314         if (res->e_tag_id_val > 0x3fff) {
12315                 printf("e-tag-id must be less than 0x3fff.\n");
12316                 return;
12317         }
12318
12319         ret = rte_eth_dev_filter_supported(res->port_id,
12320                                            RTE_ETH_FILTER_L2_TUNNEL);
12321         if (ret < 0) {
12322                 printf("E-tag filter is not supported on port %u.\n",
12323                        res->port_id);
12324                 return;
12325         }
12326
12327         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12328         entry.tunnel_id = res->e_tag_id_val;
12329
12330         ret = rte_eth_dev_filter_ctrl(res->port_id,
12331                                       RTE_ETH_FILTER_L2_TUNNEL,
12332                                       RTE_ETH_FILTER_DELETE,
12333                                       &entry);
12334         if (ret < 0)
12335                 printf("E-tag filter programming error: (%s)\n",
12336                        strerror(-ret));
12337 }
12338
12339 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12340         .f = cmd_config_e_tag_filter_del_parsed,
12341         .data = NULL,
12342         .help_str = "E-tag ... : E-tag filter delete",
12343         .tokens = {
12344                 (void *)&cmd_config_e_tag_e_tag,
12345                 (void *)&cmd_config_e_tag_set,
12346                 (void *)&cmd_config_e_tag_filter,
12347                 (void *)&cmd_config_e_tag_del,
12348                 (void *)&cmd_config_e_tag_e_tag_id,
12349                 (void *)&cmd_config_e_tag_e_tag_id_val,
12350                 (void *)&cmd_config_e_tag_port,
12351                 (void *)&cmd_config_e_tag_port_id,
12352                 NULL,
12353         },
12354 };
12355
12356 /* vf vlan anti spoof configuration */
12357
12358 /* Common result structure for vf vlan anti spoof */
12359 struct cmd_vf_vlan_anti_spoof_result {
12360         cmdline_fixed_string_t set;
12361         cmdline_fixed_string_t vf;
12362         cmdline_fixed_string_t vlan;
12363         cmdline_fixed_string_t antispoof;
12364         portid_t port_id;
12365         uint32_t vf_id;
12366         cmdline_fixed_string_t on_off;
12367 };
12368
12369 /* Common CLI fields for vf vlan anti spoof enable disable */
12370 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12371         TOKEN_STRING_INITIALIZER
12372                 (struct cmd_vf_vlan_anti_spoof_result,
12373                  set, "set");
12374 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_vf_vlan_anti_spoof_result,
12377                  vf, "vf");
12378 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_vf_vlan_anti_spoof_result,
12381                  vlan, "vlan");
12382 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12383         TOKEN_STRING_INITIALIZER
12384                 (struct cmd_vf_vlan_anti_spoof_result,
12385                  antispoof, "antispoof");
12386 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12387         TOKEN_NUM_INITIALIZER
12388                 (struct cmd_vf_vlan_anti_spoof_result,
12389                  port_id, UINT16);
12390 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12391         TOKEN_NUM_INITIALIZER
12392                 (struct cmd_vf_vlan_anti_spoof_result,
12393                  vf_id, UINT32);
12394 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12395         TOKEN_STRING_INITIALIZER
12396                 (struct cmd_vf_vlan_anti_spoof_result,
12397                  on_off, "on#off");
12398
12399 static void
12400 cmd_set_vf_vlan_anti_spoof_parsed(
12401         void *parsed_result,
12402         __attribute__((unused)) struct cmdline *cl,
12403         __attribute__((unused)) void *data)
12404 {
12405         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12406         int ret = -ENOTSUP;
12407
12408         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12409
12410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12411                 return;
12412
12413 #ifdef RTE_LIBRTE_IXGBE_PMD
12414         if (ret == -ENOTSUP)
12415                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12416                                 res->vf_id, is_on);
12417 #endif
12418 #ifdef RTE_LIBRTE_I40E_PMD
12419         if (ret == -ENOTSUP)
12420                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12421                                 res->vf_id, is_on);
12422 #endif
12423 #ifdef RTE_LIBRTE_BNXT_PMD
12424         if (ret == -ENOTSUP)
12425                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12426                                 res->vf_id, is_on);
12427 #endif
12428
12429         switch (ret) {
12430         case 0:
12431                 break;
12432         case -EINVAL:
12433                 printf("invalid vf_id %d\n", res->vf_id);
12434                 break;
12435         case -ENODEV:
12436                 printf("invalid port_id %d\n", res->port_id);
12437                 break;
12438         case -ENOTSUP:
12439                 printf("function not implemented\n");
12440                 break;
12441         default:
12442                 printf("programming error: (%s)\n", strerror(-ret));
12443         }
12444 }
12445
12446 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12447         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12448         .data = NULL,
12449         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12450         .tokens = {
12451                 (void *)&cmd_vf_vlan_anti_spoof_set,
12452                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12453                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12454                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12455                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12456                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12457                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12458                 NULL,
12459         },
12460 };
12461
12462 /* vf mac anti spoof configuration */
12463
12464 /* Common result structure for vf mac anti spoof */
12465 struct cmd_vf_mac_anti_spoof_result {
12466         cmdline_fixed_string_t set;
12467         cmdline_fixed_string_t vf;
12468         cmdline_fixed_string_t mac;
12469         cmdline_fixed_string_t antispoof;
12470         portid_t port_id;
12471         uint32_t vf_id;
12472         cmdline_fixed_string_t on_off;
12473 };
12474
12475 /* Common CLI fields for vf mac anti spoof enable disable */
12476 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_vf_mac_anti_spoof_result,
12479                  set, "set");
12480 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12481         TOKEN_STRING_INITIALIZER
12482                 (struct cmd_vf_mac_anti_spoof_result,
12483                  vf, "vf");
12484 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_vf_mac_anti_spoof_result,
12487                  mac, "mac");
12488 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_vf_mac_anti_spoof_result,
12491                  antispoof, "antispoof");
12492 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12493         TOKEN_NUM_INITIALIZER
12494                 (struct cmd_vf_mac_anti_spoof_result,
12495                  port_id, UINT16);
12496 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12497         TOKEN_NUM_INITIALIZER
12498                 (struct cmd_vf_mac_anti_spoof_result,
12499                  vf_id, UINT32);
12500 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_vf_mac_anti_spoof_result,
12503                  on_off, "on#off");
12504
12505 static void
12506 cmd_set_vf_mac_anti_spoof_parsed(
12507         void *parsed_result,
12508         __attribute__((unused)) struct cmdline *cl,
12509         __attribute__((unused)) void *data)
12510 {
12511         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12512         int ret = -ENOTSUP;
12513
12514         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12515
12516         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12517                 return;
12518
12519 #ifdef RTE_LIBRTE_IXGBE_PMD
12520         if (ret == -ENOTSUP)
12521                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12522                         res->vf_id, is_on);
12523 #endif
12524 #ifdef RTE_LIBRTE_I40E_PMD
12525         if (ret == -ENOTSUP)
12526                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12527                         res->vf_id, is_on);
12528 #endif
12529 #ifdef RTE_LIBRTE_BNXT_PMD
12530         if (ret == -ENOTSUP)
12531                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12532                         res->vf_id, is_on);
12533 #endif
12534
12535         switch (ret) {
12536         case 0:
12537                 break;
12538         case -EINVAL:
12539                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12540                 break;
12541         case -ENODEV:
12542                 printf("invalid port_id %d\n", res->port_id);
12543                 break;
12544         case -ENOTSUP:
12545                 printf("function not implemented\n");
12546                 break;
12547         default:
12548                 printf("programming error: (%s)\n", strerror(-ret));
12549         }
12550 }
12551
12552 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12553         .f = cmd_set_vf_mac_anti_spoof_parsed,
12554         .data = NULL,
12555         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12556         .tokens = {
12557                 (void *)&cmd_vf_mac_anti_spoof_set,
12558                 (void *)&cmd_vf_mac_anti_spoof_vf,
12559                 (void *)&cmd_vf_mac_anti_spoof_mac,
12560                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12561                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12562                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12563                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12564                 NULL,
12565         },
12566 };
12567
12568 /* vf vlan strip queue configuration */
12569
12570 /* Common result structure for vf mac anti spoof */
12571 struct cmd_vf_vlan_stripq_result {
12572         cmdline_fixed_string_t set;
12573         cmdline_fixed_string_t vf;
12574         cmdline_fixed_string_t vlan;
12575         cmdline_fixed_string_t stripq;
12576         portid_t port_id;
12577         uint16_t vf_id;
12578         cmdline_fixed_string_t on_off;
12579 };
12580
12581 /* Common CLI fields for vf vlan strip enable disable */
12582 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12583         TOKEN_STRING_INITIALIZER
12584                 (struct cmd_vf_vlan_stripq_result,
12585                  set, "set");
12586 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12587         TOKEN_STRING_INITIALIZER
12588                 (struct cmd_vf_vlan_stripq_result,
12589                  vf, "vf");
12590 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12591         TOKEN_STRING_INITIALIZER
12592                 (struct cmd_vf_vlan_stripq_result,
12593                  vlan, "vlan");
12594 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12595         TOKEN_STRING_INITIALIZER
12596                 (struct cmd_vf_vlan_stripq_result,
12597                  stripq, "stripq");
12598 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12599         TOKEN_NUM_INITIALIZER
12600                 (struct cmd_vf_vlan_stripq_result,
12601                  port_id, UINT16);
12602 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12603         TOKEN_NUM_INITIALIZER
12604                 (struct cmd_vf_vlan_stripq_result,
12605                  vf_id, UINT16);
12606 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12607         TOKEN_STRING_INITIALIZER
12608                 (struct cmd_vf_vlan_stripq_result,
12609                  on_off, "on#off");
12610
12611 static void
12612 cmd_set_vf_vlan_stripq_parsed(
12613         void *parsed_result,
12614         __attribute__((unused)) struct cmdline *cl,
12615         __attribute__((unused)) void *data)
12616 {
12617         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12618         int ret = -ENOTSUP;
12619
12620         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12621
12622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12623                 return;
12624
12625 #ifdef RTE_LIBRTE_IXGBE_PMD
12626         if (ret == -ENOTSUP)
12627                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12628                         res->vf_id, is_on);
12629 #endif
12630 #ifdef RTE_LIBRTE_I40E_PMD
12631         if (ret == -ENOTSUP)
12632                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12633                         res->vf_id, is_on);
12634 #endif
12635 #ifdef RTE_LIBRTE_BNXT_PMD
12636         if (ret == -ENOTSUP)
12637                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12638                         res->vf_id, is_on);
12639 #endif
12640
12641         switch (ret) {
12642         case 0:
12643                 break;
12644         case -EINVAL:
12645                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12646                 break;
12647         case -ENODEV:
12648                 printf("invalid port_id %d\n", res->port_id);
12649                 break;
12650         case -ENOTSUP:
12651                 printf("function not implemented\n");
12652                 break;
12653         default:
12654                 printf("programming error: (%s)\n", strerror(-ret));
12655         }
12656 }
12657
12658 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12659         .f = cmd_set_vf_vlan_stripq_parsed,
12660         .data = NULL,
12661         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12662         .tokens = {
12663                 (void *)&cmd_vf_vlan_stripq_set,
12664                 (void *)&cmd_vf_vlan_stripq_vf,
12665                 (void *)&cmd_vf_vlan_stripq_vlan,
12666                 (void *)&cmd_vf_vlan_stripq_stripq,
12667                 (void *)&cmd_vf_vlan_stripq_port_id,
12668                 (void *)&cmd_vf_vlan_stripq_vf_id,
12669                 (void *)&cmd_vf_vlan_stripq_on_off,
12670                 NULL,
12671         },
12672 };
12673
12674 /* vf vlan insert configuration */
12675
12676 /* Common result structure for vf vlan insert */
12677 struct cmd_vf_vlan_insert_result {
12678         cmdline_fixed_string_t set;
12679         cmdline_fixed_string_t vf;
12680         cmdline_fixed_string_t vlan;
12681         cmdline_fixed_string_t insert;
12682         portid_t port_id;
12683         uint16_t vf_id;
12684         uint16_t vlan_id;
12685 };
12686
12687 /* Common CLI fields for vf vlan insert enable disable */
12688 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12689         TOKEN_STRING_INITIALIZER
12690                 (struct cmd_vf_vlan_insert_result,
12691                  set, "set");
12692 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12693         TOKEN_STRING_INITIALIZER
12694                 (struct cmd_vf_vlan_insert_result,
12695                  vf, "vf");
12696 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12697         TOKEN_STRING_INITIALIZER
12698                 (struct cmd_vf_vlan_insert_result,
12699                  vlan, "vlan");
12700 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12701         TOKEN_STRING_INITIALIZER
12702                 (struct cmd_vf_vlan_insert_result,
12703                  insert, "insert");
12704 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12705         TOKEN_NUM_INITIALIZER
12706                 (struct cmd_vf_vlan_insert_result,
12707                  port_id, UINT16);
12708 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12709         TOKEN_NUM_INITIALIZER
12710                 (struct cmd_vf_vlan_insert_result,
12711                  vf_id, UINT16);
12712 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12713         TOKEN_NUM_INITIALIZER
12714                 (struct cmd_vf_vlan_insert_result,
12715                  vlan_id, UINT16);
12716
12717 static void
12718 cmd_set_vf_vlan_insert_parsed(
12719         void *parsed_result,
12720         __attribute__((unused)) struct cmdline *cl,
12721         __attribute__((unused)) void *data)
12722 {
12723         struct cmd_vf_vlan_insert_result *res = parsed_result;
12724         int ret = -ENOTSUP;
12725
12726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12727                 return;
12728
12729 #ifdef RTE_LIBRTE_IXGBE_PMD
12730         if (ret == -ENOTSUP)
12731                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12732                         res->vlan_id);
12733 #endif
12734 #ifdef RTE_LIBRTE_I40E_PMD
12735         if (ret == -ENOTSUP)
12736                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12737                         res->vlan_id);
12738 #endif
12739 #ifdef RTE_LIBRTE_BNXT_PMD
12740         if (ret == -ENOTSUP)
12741                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12742                         res->vlan_id);
12743 #endif
12744
12745         switch (ret) {
12746         case 0:
12747                 break;
12748         case -EINVAL:
12749                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12750                 break;
12751         case -ENODEV:
12752                 printf("invalid port_id %d\n", res->port_id);
12753                 break;
12754         case -ENOTSUP:
12755                 printf("function not implemented\n");
12756                 break;
12757         default:
12758                 printf("programming error: (%s)\n", strerror(-ret));
12759         }
12760 }
12761
12762 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12763         .f = cmd_set_vf_vlan_insert_parsed,
12764         .data = NULL,
12765         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12766         .tokens = {
12767                 (void *)&cmd_vf_vlan_insert_set,
12768                 (void *)&cmd_vf_vlan_insert_vf,
12769                 (void *)&cmd_vf_vlan_insert_vlan,
12770                 (void *)&cmd_vf_vlan_insert_insert,
12771                 (void *)&cmd_vf_vlan_insert_port_id,
12772                 (void *)&cmd_vf_vlan_insert_vf_id,
12773                 (void *)&cmd_vf_vlan_insert_vlan_id,
12774                 NULL,
12775         },
12776 };
12777
12778 /* tx loopback configuration */
12779
12780 /* Common result structure for tx loopback */
12781 struct cmd_tx_loopback_result {
12782         cmdline_fixed_string_t set;
12783         cmdline_fixed_string_t tx;
12784         cmdline_fixed_string_t loopback;
12785         portid_t port_id;
12786         cmdline_fixed_string_t on_off;
12787 };
12788
12789 /* Common CLI fields for tx loopback enable disable */
12790 cmdline_parse_token_string_t cmd_tx_loopback_set =
12791         TOKEN_STRING_INITIALIZER
12792                 (struct cmd_tx_loopback_result,
12793                  set, "set");
12794 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12795         TOKEN_STRING_INITIALIZER
12796                 (struct cmd_tx_loopback_result,
12797                  tx, "tx");
12798 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12799         TOKEN_STRING_INITIALIZER
12800                 (struct cmd_tx_loopback_result,
12801                  loopback, "loopback");
12802 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12803         TOKEN_NUM_INITIALIZER
12804                 (struct cmd_tx_loopback_result,
12805                  port_id, UINT16);
12806 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12807         TOKEN_STRING_INITIALIZER
12808                 (struct cmd_tx_loopback_result,
12809                  on_off, "on#off");
12810
12811 static void
12812 cmd_set_tx_loopback_parsed(
12813         void *parsed_result,
12814         __attribute__((unused)) struct cmdline *cl,
12815         __attribute__((unused)) void *data)
12816 {
12817         struct cmd_tx_loopback_result *res = parsed_result;
12818         int ret = -ENOTSUP;
12819
12820         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12821
12822         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12823                 return;
12824
12825 #ifdef RTE_LIBRTE_IXGBE_PMD
12826         if (ret == -ENOTSUP)
12827                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12828 #endif
12829 #ifdef RTE_LIBRTE_I40E_PMD
12830         if (ret == -ENOTSUP)
12831                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12832 #endif
12833 #ifdef RTE_LIBRTE_BNXT_PMD
12834         if (ret == -ENOTSUP)
12835                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12836 #endif
12837 #ifdef RTE_LIBRTE_DPAA_PMD
12838         if (ret == -ENOTSUP)
12839                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12840 #endif
12841
12842         switch (ret) {
12843         case 0:
12844                 break;
12845         case -EINVAL:
12846                 printf("invalid is_on %d\n", is_on);
12847                 break;
12848         case -ENODEV:
12849                 printf("invalid port_id %d\n", res->port_id);
12850                 break;
12851         case -ENOTSUP:
12852                 printf("function not implemented\n");
12853                 break;
12854         default:
12855                 printf("programming error: (%s)\n", strerror(-ret));
12856         }
12857 }
12858
12859 cmdline_parse_inst_t cmd_set_tx_loopback = {
12860         .f = cmd_set_tx_loopback_parsed,
12861         .data = NULL,
12862         .help_str = "set tx loopback <port_id> on|off",
12863         .tokens = {
12864                 (void *)&cmd_tx_loopback_set,
12865                 (void *)&cmd_tx_loopback_tx,
12866                 (void *)&cmd_tx_loopback_loopback,
12867                 (void *)&cmd_tx_loopback_port_id,
12868                 (void *)&cmd_tx_loopback_on_off,
12869                 NULL,
12870         },
12871 };
12872
12873 /* all queues drop enable configuration */
12874
12875 /* Common result structure for all queues drop enable */
12876 struct cmd_all_queues_drop_en_result {
12877         cmdline_fixed_string_t set;
12878         cmdline_fixed_string_t all;
12879         cmdline_fixed_string_t queues;
12880         cmdline_fixed_string_t drop;
12881         portid_t port_id;
12882         cmdline_fixed_string_t on_off;
12883 };
12884
12885 /* Common CLI fields for tx loopback enable disable */
12886 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12887         TOKEN_STRING_INITIALIZER
12888                 (struct cmd_all_queues_drop_en_result,
12889                  set, "set");
12890 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_all_queues_drop_en_result,
12893                  all, "all");
12894 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12895         TOKEN_STRING_INITIALIZER
12896                 (struct cmd_all_queues_drop_en_result,
12897                  queues, "queues");
12898 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12899         TOKEN_STRING_INITIALIZER
12900                 (struct cmd_all_queues_drop_en_result,
12901                  drop, "drop");
12902 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12903         TOKEN_NUM_INITIALIZER
12904                 (struct cmd_all_queues_drop_en_result,
12905                  port_id, UINT16);
12906 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12907         TOKEN_STRING_INITIALIZER
12908                 (struct cmd_all_queues_drop_en_result,
12909                  on_off, "on#off");
12910
12911 static void
12912 cmd_set_all_queues_drop_en_parsed(
12913         void *parsed_result,
12914         __attribute__((unused)) struct cmdline *cl,
12915         __attribute__((unused)) void *data)
12916 {
12917         struct cmd_all_queues_drop_en_result *res = parsed_result;
12918         int ret = -ENOTSUP;
12919         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12920
12921         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12922                 return;
12923
12924 #ifdef RTE_LIBRTE_IXGBE_PMD
12925         if (ret == -ENOTSUP)
12926                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12927 #endif
12928 #ifdef RTE_LIBRTE_BNXT_PMD
12929         if (ret == -ENOTSUP)
12930                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12931 #endif
12932         switch (ret) {
12933         case 0:
12934                 break;
12935         case -EINVAL:
12936                 printf("invalid is_on %d\n", is_on);
12937                 break;
12938         case -ENODEV:
12939                 printf("invalid port_id %d\n", res->port_id);
12940                 break;
12941         case -ENOTSUP:
12942                 printf("function not implemented\n");
12943                 break;
12944         default:
12945                 printf("programming error: (%s)\n", strerror(-ret));
12946         }
12947 }
12948
12949 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12950         .f = cmd_set_all_queues_drop_en_parsed,
12951         .data = NULL,
12952         .help_str = "set all queues drop <port_id> on|off",
12953         .tokens = {
12954                 (void *)&cmd_all_queues_drop_en_set,
12955                 (void *)&cmd_all_queues_drop_en_all,
12956                 (void *)&cmd_all_queues_drop_en_queues,
12957                 (void *)&cmd_all_queues_drop_en_drop,
12958                 (void *)&cmd_all_queues_drop_en_port_id,
12959                 (void *)&cmd_all_queues_drop_en_on_off,
12960                 NULL,
12961         },
12962 };
12963
12964 /* vf split drop enable configuration */
12965
12966 /* Common result structure for vf split drop enable */
12967 struct cmd_vf_split_drop_en_result {
12968         cmdline_fixed_string_t set;
12969         cmdline_fixed_string_t vf;
12970         cmdline_fixed_string_t split;
12971         cmdline_fixed_string_t drop;
12972         portid_t port_id;
12973         uint16_t vf_id;
12974         cmdline_fixed_string_t on_off;
12975 };
12976
12977 /* Common CLI fields for vf split drop enable disable */
12978 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12979         TOKEN_STRING_INITIALIZER
12980                 (struct cmd_vf_split_drop_en_result,
12981                  set, "set");
12982 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12983         TOKEN_STRING_INITIALIZER
12984                 (struct cmd_vf_split_drop_en_result,
12985                  vf, "vf");
12986 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12987         TOKEN_STRING_INITIALIZER
12988                 (struct cmd_vf_split_drop_en_result,
12989                  split, "split");
12990 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12991         TOKEN_STRING_INITIALIZER
12992                 (struct cmd_vf_split_drop_en_result,
12993                  drop, "drop");
12994 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12995         TOKEN_NUM_INITIALIZER
12996                 (struct cmd_vf_split_drop_en_result,
12997                  port_id, UINT16);
12998 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12999         TOKEN_NUM_INITIALIZER
13000                 (struct cmd_vf_split_drop_en_result,
13001                  vf_id, UINT16);
13002 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13003         TOKEN_STRING_INITIALIZER
13004                 (struct cmd_vf_split_drop_en_result,
13005                  on_off, "on#off");
13006
13007 static void
13008 cmd_set_vf_split_drop_en_parsed(
13009         void *parsed_result,
13010         __attribute__((unused)) struct cmdline *cl,
13011         __attribute__((unused)) void *data)
13012 {
13013         struct cmd_vf_split_drop_en_result *res = parsed_result;
13014         int ret = -ENOTSUP;
13015         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13016
13017         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13018                 return;
13019
13020 #ifdef RTE_LIBRTE_IXGBE_PMD
13021         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13022                         is_on);
13023 #endif
13024         switch (ret) {
13025         case 0:
13026                 break;
13027         case -EINVAL:
13028                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13029                 break;
13030         case -ENODEV:
13031                 printf("invalid port_id %d\n", res->port_id);
13032                 break;
13033         case -ENOTSUP:
13034                 printf("not supported on port %d\n", res->port_id);
13035                 break;
13036         default:
13037                 printf("programming error: (%s)\n", strerror(-ret));
13038         }
13039 }
13040
13041 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13042         .f = cmd_set_vf_split_drop_en_parsed,
13043         .data = NULL,
13044         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13045         .tokens = {
13046                 (void *)&cmd_vf_split_drop_en_set,
13047                 (void *)&cmd_vf_split_drop_en_vf,
13048                 (void *)&cmd_vf_split_drop_en_split,
13049                 (void *)&cmd_vf_split_drop_en_drop,
13050                 (void *)&cmd_vf_split_drop_en_port_id,
13051                 (void *)&cmd_vf_split_drop_en_vf_id,
13052                 (void *)&cmd_vf_split_drop_en_on_off,
13053                 NULL,
13054         },
13055 };
13056
13057 /* vf mac address configuration */
13058
13059 /* Common result structure for vf mac address */
13060 struct cmd_set_vf_mac_addr_result {
13061         cmdline_fixed_string_t set;
13062         cmdline_fixed_string_t vf;
13063         cmdline_fixed_string_t mac;
13064         cmdline_fixed_string_t addr;
13065         portid_t port_id;
13066         uint16_t vf_id;
13067         struct ether_addr mac_addr;
13068
13069 };
13070
13071 /* Common CLI fields for vf split drop enable disable */
13072 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13073         TOKEN_STRING_INITIALIZER
13074                 (struct cmd_set_vf_mac_addr_result,
13075                  set, "set");
13076 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_set_vf_mac_addr_result,
13079                  vf, "vf");
13080 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13081         TOKEN_STRING_INITIALIZER
13082                 (struct cmd_set_vf_mac_addr_result,
13083                  mac, "mac");
13084 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_set_vf_mac_addr_result,
13087                  addr, "addr");
13088 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13089         TOKEN_NUM_INITIALIZER
13090                 (struct cmd_set_vf_mac_addr_result,
13091                  port_id, UINT16);
13092 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13093         TOKEN_NUM_INITIALIZER
13094                 (struct cmd_set_vf_mac_addr_result,
13095                  vf_id, UINT16);
13096 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13097         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13098                  mac_addr);
13099
13100 static void
13101 cmd_set_vf_mac_addr_parsed(
13102         void *parsed_result,
13103         __attribute__((unused)) struct cmdline *cl,
13104         __attribute__((unused)) void *data)
13105 {
13106         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13107         int ret = -ENOTSUP;
13108
13109         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13110                 return;
13111
13112 #ifdef RTE_LIBRTE_IXGBE_PMD
13113         if (ret == -ENOTSUP)
13114                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13115                                 &res->mac_addr);
13116 #endif
13117 #ifdef RTE_LIBRTE_I40E_PMD
13118         if (ret == -ENOTSUP)
13119                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13120                                 &res->mac_addr);
13121 #endif
13122 #ifdef RTE_LIBRTE_BNXT_PMD
13123         if (ret == -ENOTSUP)
13124                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13125                                 &res->mac_addr);
13126 #endif
13127
13128         switch (ret) {
13129         case 0:
13130                 break;
13131         case -EINVAL:
13132                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13133                 break;
13134         case -ENODEV:
13135                 printf("invalid port_id %d\n", res->port_id);
13136                 break;
13137         case -ENOTSUP:
13138                 printf("function not implemented\n");
13139                 break;
13140         default:
13141                 printf("programming error: (%s)\n", strerror(-ret));
13142         }
13143 }
13144
13145 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13146         .f = cmd_set_vf_mac_addr_parsed,
13147         .data = NULL,
13148         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13149         .tokens = {
13150                 (void *)&cmd_set_vf_mac_addr_set,
13151                 (void *)&cmd_set_vf_mac_addr_vf,
13152                 (void *)&cmd_set_vf_mac_addr_mac,
13153                 (void *)&cmd_set_vf_mac_addr_addr,
13154                 (void *)&cmd_set_vf_mac_addr_port_id,
13155                 (void *)&cmd_set_vf_mac_addr_vf_id,
13156                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13157                 NULL,
13158         },
13159 };
13160
13161 /* MACsec configuration */
13162
13163 /* Common result structure for MACsec offload enable */
13164 struct cmd_macsec_offload_on_result {
13165         cmdline_fixed_string_t set;
13166         cmdline_fixed_string_t macsec;
13167         cmdline_fixed_string_t offload;
13168         portid_t port_id;
13169         cmdline_fixed_string_t on;
13170         cmdline_fixed_string_t encrypt;
13171         cmdline_fixed_string_t en_on_off;
13172         cmdline_fixed_string_t replay_protect;
13173         cmdline_fixed_string_t rp_on_off;
13174 };
13175
13176 /* Common CLI fields for MACsec offload disable */
13177 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13178         TOKEN_STRING_INITIALIZER
13179                 (struct cmd_macsec_offload_on_result,
13180                  set, "set");
13181 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13182         TOKEN_STRING_INITIALIZER
13183                 (struct cmd_macsec_offload_on_result,
13184                  macsec, "macsec");
13185 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13186         TOKEN_STRING_INITIALIZER
13187                 (struct cmd_macsec_offload_on_result,
13188                  offload, "offload");
13189 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13190         TOKEN_NUM_INITIALIZER
13191                 (struct cmd_macsec_offload_on_result,
13192                  port_id, UINT16);
13193 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13194         TOKEN_STRING_INITIALIZER
13195                 (struct cmd_macsec_offload_on_result,
13196                  on, "on");
13197 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13198         TOKEN_STRING_INITIALIZER
13199                 (struct cmd_macsec_offload_on_result,
13200                  encrypt, "encrypt");
13201 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13202         TOKEN_STRING_INITIALIZER
13203                 (struct cmd_macsec_offload_on_result,
13204                  en_on_off, "on#off");
13205 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13206         TOKEN_STRING_INITIALIZER
13207                 (struct cmd_macsec_offload_on_result,
13208                  replay_protect, "replay-protect");
13209 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13210         TOKEN_STRING_INITIALIZER
13211                 (struct cmd_macsec_offload_on_result,
13212                  rp_on_off, "on#off");
13213
13214 static void
13215 cmd_set_macsec_offload_on_parsed(
13216         void *parsed_result,
13217         __attribute__((unused)) struct cmdline *cl,
13218         __attribute__((unused)) void *data)
13219 {
13220         struct cmd_macsec_offload_on_result *res = parsed_result;
13221         int ret = -ENOTSUP;
13222         portid_t port_id = res->port_id;
13223         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13224         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13225         struct rte_eth_dev_info dev_info;
13226
13227         if (port_id_is_invalid(port_id, ENABLED_WARN))
13228                 return;
13229         if (!port_is_stopped(port_id)) {
13230                 printf("Please stop port %d first\n", port_id);
13231                 return;
13232         }
13233
13234         rte_eth_dev_info_get(port_id, &dev_info);
13235         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13236 #ifdef RTE_LIBRTE_IXGBE_PMD
13237                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13238 #endif
13239         }
13240         RTE_SET_USED(en);
13241         RTE_SET_USED(rp);
13242
13243         switch (ret) {
13244         case 0:
13245                 ports[port_id].dev_conf.txmode.offloads |=
13246                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13247                 cmd_reconfig_device_queue(port_id, 1, 1);
13248                 break;
13249         case -ENODEV:
13250                 printf("invalid port_id %d\n", port_id);
13251                 break;
13252         case -ENOTSUP:
13253                 printf("not supported on port %d\n", port_id);
13254                 break;
13255         default:
13256                 printf("programming error: (%s)\n", strerror(-ret));
13257         }
13258 }
13259
13260 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13261         .f = cmd_set_macsec_offload_on_parsed,
13262         .data = NULL,
13263         .help_str = "set macsec offload <port_id> on "
13264                 "encrypt on|off replay-protect on|off",
13265         .tokens = {
13266                 (void *)&cmd_macsec_offload_on_set,
13267                 (void *)&cmd_macsec_offload_on_macsec,
13268                 (void *)&cmd_macsec_offload_on_offload,
13269                 (void *)&cmd_macsec_offload_on_port_id,
13270                 (void *)&cmd_macsec_offload_on_on,
13271                 (void *)&cmd_macsec_offload_on_encrypt,
13272                 (void *)&cmd_macsec_offload_on_en_on_off,
13273                 (void *)&cmd_macsec_offload_on_replay_protect,
13274                 (void *)&cmd_macsec_offload_on_rp_on_off,
13275                 NULL,
13276         },
13277 };
13278
13279 /* Common result structure for MACsec offload disable */
13280 struct cmd_macsec_offload_off_result {
13281         cmdline_fixed_string_t set;
13282         cmdline_fixed_string_t macsec;
13283         cmdline_fixed_string_t offload;
13284         portid_t port_id;
13285         cmdline_fixed_string_t off;
13286 };
13287
13288 /* Common CLI fields for MACsec offload disable */
13289 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13290         TOKEN_STRING_INITIALIZER
13291                 (struct cmd_macsec_offload_off_result,
13292                  set, "set");
13293 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13294         TOKEN_STRING_INITIALIZER
13295                 (struct cmd_macsec_offload_off_result,
13296                  macsec, "macsec");
13297 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13298         TOKEN_STRING_INITIALIZER
13299                 (struct cmd_macsec_offload_off_result,
13300                  offload, "offload");
13301 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13302         TOKEN_NUM_INITIALIZER
13303                 (struct cmd_macsec_offload_off_result,
13304                  port_id, UINT16);
13305 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13306         TOKEN_STRING_INITIALIZER
13307                 (struct cmd_macsec_offload_off_result,
13308                  off, "off");
13309
13310 static void
13311 cmd_set_macsec_offload_off_parsed(
13312         void *parsed_result,
13313         __attribute__((unused)) struct cmdline *cl,
13314         __attribute__((unused)) void *data)
13315 {
13316         struct cmd_macsec_offload_off_result *res = parsed_result;
13317         int ret = -ENOTSUP;
13318         struct rte_eth_dev_info dev_info;
13319         portid_t port_id = res->port_id;
13320
13321         if (port_id_is_invalid(port_id, ENABLED_WARN))
13322                 return;
13323         if (!port_is_stopped(port_id)) {
13324                 printf("Please stop port %d first\n", port_id);
13325                 return;
13326         }
13327
13328         rte_eth_dev_info_get(port_id, &dev_info);
13329         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13330 #ifdef RTE_LIBRTE_IXGBE_PMD
13331                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13332 #endif
13333         }
13334         switch (ret) {
13335         case 0:
13336                 ports[port_id].dev_conf.txmode.offloads &=
13337                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13338                 cmd_reconfig_device_queue(port_id, 1, 1);
13339                 break;
13340         case -ENODEV:
13341                 printf("invalid port_id %d\n", port_id);
13342                 break;
13343         case -ENOTSUP:
13344                 printf("not supported on port %d\n", port_id);
13345                 break;
13346         default:
13347                 printf("programming error: (%s)\n", strerror(-ret));
13348         }
13349 }
13350
13351 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13352         .f = cmd_set_macsec_offload_off_parsed,
13353         .data = NULL,
13354         .help_str = "set macsec offload <port_id> off",
13355         .tokens = {
13356                 (void *)&cmd_macsec_offload_off_set,
13357                 (void *)&cmd_macsec_offload_off_macsec,
13358                 (void *)&cmd_macsec_offload_off_offload,
13359                 (void *)&cmd_macsec_offload_off_port_id,
13360                 (void *)&cmd_macsec_offload_off_off,
13361                 NULL,
13362         },
13363 };
13364
13365 /* Common result structure for MACsec secure connection configure */
13366 struct cmd_macsec_sc_result {
13367         cmdline_fixed_string_t set;
13368         cmdline_fixed_string_t macsec;
13369         cmdline_fixed_string_t sc;
13370         cmdline_fixed_string_t tx_rx;
13371         portid_t port_id;
13372         struct ether_addr mac;
13373         uint16_t pi;
13374 };
13375
13376 /* Common CLI fields for MACsec secure connection configure */
13377 cmdline_parse_token_string_t cmd_macsec_sc_set =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_macsec_sc_result,
13380                  set, "set");
13381 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_macsec_sc_result,
13384                  macsec, "macsec");
13385 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_macsec_sc_result,
13388                  sc, "sc");
13389 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13390         TOKEN_STRING_INITIALIZER
13391                 (struct cmd_macsec_sc_result,
13392                  tx_rx, "tx#rx");
13393 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13394         TOKEN_NUM_INITIALIZER
13395                 (struct cmd_macsec_sc_result,
13396                  port_id, UINT16);
13397 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13398         TOKEN_ETHERADDR_INITIALIZER
13399                 (struct cmd_macsec_sc_result,
13400                  mac);
13401 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13402         TOKEN_NUM_INITIALIZER
13403                 (struct cmd_macsec_sc_result,
13404                  pi, UINT16);
13405
13406 static void
13407 cmd_set_macsec_sc_parsed(
13408         void *parsed_result,
13409         __attribute__((unused)) struct cmdline *cl,
13410         __attribute__((unused)) void *data)
13411 {
13412         struct cmd_macsec_sc_result *res = parsed_result;
13413         int ret = -ENOTSUP;
13414         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13415
13416 #ifdef RTE_LIBRTE_IXGBE_PMD
13417         ret = is_tx ?
13418                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13419                                 res->mac.addr_bytes) :
13420                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13421                                 res->mac.addr_bytes, res->pi);
13422 #endif
13423         RTE_SET_USED(is_tx);
13424
13425         switch (ret) {
13426         case 0:
13427                 break;
13428         case -ENODEV:
13429                 printf("invalid port_id %d\n", res->port_id);
13430                 break;
13431         case -ENOTSUP:
13432                 printf("not supported on port %d\n", res->port_id);
13433                 break;
13434         default:
13435                 printf("programming error: (%s)\n", strerror(-ret));
13436         }
13437 }
13438
13439 cmdline_parse_inst_t cmd_set_macsec_sc = {
13440         .f = cmd_set_macsec_sc_parsed,
13441         .data = NULL,
13442         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13443         .tokens = {
13444                 (void *)&cmd_macsec_sc_set,
13445                 (void *)&cmd_macsec_sc_macsec,
13446                 (void *)&cmd_macsec_sc_sc,
13447                 (void *)&cmd_macsec_sc_tx_rx,
13448                 (void *)&cmd_macsec_sc_port_id,
13449                 (void *)&cmd_macsec_sc_mac,
13450                 (void *)&cmd_macsec_sc_pi,
13451                 NULL,
13452         },
13453 };
13454
13455 /* Common result structure for MACsec secure connection configure */
13456 struct cmd_macsec_sa_result {
13457         cmdline_fixed_string_t set;
13458         cmdline_fixed_string_t macsec;
13459         cmdline_fixed_string_t sa;
13460         cmdline_fixed_string_t tx_rx;
13461         portid_t port_id;
13462         uint8_t idx;
13463         uint8_t an;
13464         uint32_t pn;
13465         cmdline_fixed_string_t key;
13466 };
13467
13468 /* Common CLI fields for MACsec secure connection configure */
13469 cmdline_parse_token_string_t cmd_macsec_sa_set =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_macsec_sa_result,
13472                  set, "set");
13473 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_macsec_sa_result,
13476                  macsec, "macsec");
13477 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_macsec_sa_result,
13480                  sa, "sa");
13481 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13482         TOKEN_STRING_INITIALIZER
13483                 (struct cmd_macsec_sa_result,
13484                  tx_rx, "tx#rx");
13485 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13486         TOKEN_NUM_INITIALIZER
13487                 (struct cmd_macsec_sa_result,
13488                  port_id, UINT16);
13489 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13490         TOKEN_NUM_INITIALIZER
13491                 (struct cmd_macsec_sa_result,
13492                  idx, UINT8);
13493 cmdline_parse_token_num_t cmd_macsec_sa_an =
13494         TOKEN_NUM_INITIALIZER
13495                 (struct cmd_macsec_sa_result,
13496                  an, UINT8);
13497 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13498         TOKEN_NUM_INITIALIZER
13499                 (struct cmd_macsec_sa_result,
13500                  pn, UINT32);
13501 cmdline_parse_token_string_t cmd_macsec_sa_key =
13502         TOKEN_STRING_INITIALIZER
13503                 (struct cmd_macsec_sa_result,
13504                  key, NULL);
13505
13506 static void
13507 cmd_set_macsec_sa_parsed(
13508         void *parsed_result,
13509         __attribute__((unused)) struct cmdline *cl,
13510         __attribute__((unused)) void *data)
13511 {
13512         struct cmd_macsec_sa_result *res = parsed_result;
13513         int ret = -ENOTSUP;
13514         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13515         uint8_t key[16] = { 0 };
13516         uint8_t xdgt0;
13517         uint8_t xdgt1;
13518         int key_len;
13519         int i;
13520
13521         key_len = strlen(res->key) / 2;
13522         if (key_len > 16)
13523                 key_len = 16;
13524
13525         for (i = 0; i < key_len; i++) {
13526                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13527                 if (xdgt0 == 0xFF)
13528                         return;
13529                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13530                 if (xdgt1 == 0xFF)
13531                         return;
13532                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13533         }
13534
13535 #ifdef RTE_LIBRTE_IXGBE_PMD
13536         ret = is_tx ?
13537                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13538                         res->idx, res->an, res->pn, key) :
13539                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13540                         res->idx, res->an, res->pn, key);
13541 #endif
13542         RTE_SET_USED(is_tx);
13543         RTE_SET_USED(key);
13544
13545         switch (ret) {
13546         case 0:
13547                 break;
13548         case -EINVAL:
13549                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13550                 break;
13551         case -ENODEV:
13552                 printf("invalid port_id %d\n", res->port_id);
13553                 break;
13554         case -ENOTSUP:
13555                 printf("not supported on port %d\n", res->port_id);
13556                 break;
13557         default:
13558                 printf("programming error: (%s)\n", strerror(-ret));
13559         }
13560 }
13561
13562 cmdline_parse_inst_t cmd_set_macsec_sa = {
13563         .f = cmd_set_macsec_sa_parsed,
13564         .data = NULL,
13565         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13566         .tokens = {
13567                 (void *)&cmd_macsec_sa_set,
13568                 (void *)&cmd_macsec_sa_macsec,
13569                 (void *)&cmd_macsec_sa_sa,
13570                 (void *)&cmd_macsec_sa_tx_rx,
13571                 (void *)&cmd_macsec_sa_port_id,
13572                 (void *)&cmd_macsec_sa_idx,
13573                 (void *)&cmd_macsec_sa_an,
13574                 (void *)&cmd_macsec_sa_pn,
13575                 (void *)&cmd_macsec_sa_key,
13576                 NULL,
13577         },
13578 };
13579
13580 /* VF unicast promiscuous mode configuration */
13581
13582 /* Common result structure for VF unicast promiscuous mode */
13583 struct cmd_vf_promisc_result {
13584         cmdline_fixed_string_t set;
13585         cmdline_fixed_string_t vf;
13586         cmdline_fixed_string_t promisc;
13587         portid_t port_id;
13588         uint32_t vf_id;
13589         cmdline_fixed_string_t on_off;
13590 };
13591
13592 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13593 cmdline_parse_token_string_t cmd_vf_promisc_set =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_vf_promisc_result,
13596                  set, "set");
13597 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_promisc_result,
13600                  vf, "vf");
13601 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13602         TOKEN_STRING_INITIALIZER
13603                 (struct cmd_vf_promisc_result,
13604                  promisc, "promisc");
13605 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13606         TOKEN_NUM_INITIALIZER
13607                 (struct cmd_vf_promisc_result,
13608                  port_id, UINT16);
13609 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_promisc_result,
13612                  vf_id, UINT32);
13613 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13614         TOKEN_STRING_INITIALIZER
13615                 (struct cmd_vf_promisc_result,
13616                  on_off, "on#off");
13617
13618 static void
13619 cmd_set_vf_promisc_parsed(
13620         void *parsed_result,
13621         __attribute__((unused)) struct cmdline *cl,
13622         __attribute__((unused)) void *data)
13623 {
13624         struct cmd_vf_promisc_result *res = parsed_result;
13625         int ret = -ENOTSUP;
13626
13627         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13628
13629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13630                 return;
13631
13632 #ifdef RTE_LIBRTE_I40E_PMD
13633         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13634                                                   res->vf_id, is_on);
13635 #endif
13636
13637         switch (ret) {
13638         case 0:
13639                 break;
13640         case -EINVAL:
13641                 printf("invalid vf_id %d\n", res->vf_id);
13642                 break;
13643         case -ENODEV:
13644                 printf("invalid port_id %d\n", res->port_id);
13645                 break;
13646         case -ENOTSUP:
13647                 printf("function not implemented\n");
13648                 break;
13649         default:
13650                 printf("programming error: (%s)\n", strerror(-ret));
13651         }
13652 }
13653
13654 cmdline_parse_inst_t cmd_set_vf_promisc = {
13655         .f = cmd_set_vf_promisc_parsed,
13656         .data = NULL,
13657         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13658                 "Set unicast promiscuous mode for a VF from the PF",
13659         .tokens = {
13660                 (void *)&cmd_vf_promisc_set,
13661                 (void *)&cmd_vf_promisc_vf,
13662                 (void *)&cmd_vf_promisc_promisc,
13663                 (void *)&cmd_vf_promisc_port_id,
13664                 (void *)&cmd_vf_promisc_vf_id,
13665                 (void *)&cmd_vf_promisc_on_off,
13666                 NULL,
13667         },
13668 };
13669
13670 /* VF multicast promiscuous mode configuration */
13671
13672 /* Common result structure for VF multicast promiscuous mode */
13673 struct cmd_vf_allmulti_result {
13674         cmdline_fixed_string_t set;
13675         cmdline_fixed_string_t vf;
13676         cmdline_fixed_string_t allmulti;
13677         portid_t port_id;
13678         uint32_t vf_id;
13679         cmdline_fixed_string_t on_off;
13680 };
13681
13682 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13683 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13684         TOKEN_STRING_INITIALIZER
13685                 (struct cmd_vf_allmulti_result,
13686                  set, "set");
13687 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13688         TOKEN_STRING_INITIALIZER
13689                 (struct cmd_vf_allmulti_result,
13690                  vf, "vf");
13691 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13692         TOKEN_STRING_INITIALIZER
13693                 (struct cmd_vf_allmulti_result,
13694                  allmulti, "allmulti");
13695 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13696         TOKEN_NUM_INITIALIZER
13697                 (struct cmd_vf_allmulti_result,
13698                  port_id, UINT16);
13699 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13700         TOKEN_NUM_INITIALIZER
13701                 (struct cmd_vf_allmulti_result,
13702                  vf_id, UINT32);
13703 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_vf_allmulti_result,
13706                  on_off, "on#off");
13707
13708 static void
13709 cmd_set_vf_allmulti_parsed(
13710         void *parsed_result,
13711         __attribute__((unused)) struct cmdline *cl,
13712         __attribute__((unused)) void *data)
13713 {
13714         struct cmd_vf_allmulti_result *res = parsed_result;
13715         int ret = -ENOTSUP;
13716
13717         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13718
13719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13720                 return;
13721
13722 #ifdef RTE_LIBRTE_I40E_PMD
13723         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13724                                                     res->vf_id, is_on);
13725 #endif
13726
13727         switch (ret) {
13728         case 0:
13729                 break;
13730         case -EINVAL:
13731                 printf("invalid vf_id %d\n", res->vf_id);
13732                 break;
13733         case -ENODEV:
13734                 printf("invalid port_id %d\n", res->port_id);
13735                 break;
13736         case -ENOTSUP:
13737                 printf("function not implemented\n");
13738                 break;
13739         default:
13740                 printf("programming error: (%s)\n", strerror(-ret));
13741         }
13742 }
13743
13744 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13745         .f = cmd_set_vf_allmulti_parsed,
13746         .data = NULL,
13747         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13748                 "Set multicast promiscuous mode for a VF from the PF",
13749         .tokens = {
13750                 (void *)&cmd_vf_allmulti_set,
13751                 (void *)&cmd_vf_allmulti_vf,
13752                 (void *)&cmd_vf_allmulti_allmulti,
13753                 (void *)&cmd_vf_allmulti_port_id,
13754                 (void *)&cmd_vf_allmulti_vf_id,
13755                 (void *)&cmd_vf_allmulti_on_off,
13756                 NULL,
13757         },
13758 };
13759
13760 /* vf broadcast mode configuration */
13761
13762 /* Common result structure for vf broadcast */
13763 struct cmd_set_vf_broadcast_result {
13764         cmdline_fixed_string_t set;
13765         cmdline_fixed_string_t vf;
13766         cmdline_fixed_string_t broadcast;
13767         portid_t port_id;
13768         uint16_t vf_id;
13769         cmdline_fixed_string_t on_off;
13770 };
13771
13772 /* Common CLI fields for vf broadcast enable disable */
13773 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13774         TOKEN_STRING_INITIALIZER
13775                 (struct cmd_set_vf_broadcast_result,
13776                  set, "set");
13777 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_set_vf_broadcast_result,
13780                  vf, "vf");
13781 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13782         TOKEN_STRING_INITIALIZER
13783                 (struct cmd_set_vf_broadcast_result,
13784                  broadcast, "broadcast");
13785 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13786         TOKEN_NUM_INITIALIZER
13787                 (struct cmd_set_vf_broadcast_result,
13788                  port_id, UINT16);
13789 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_set_vf_broadcast_result,
13792                  vf_id, UINT16);
13793 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13794         TOKEN_STRING_INITIALIZER
13795                 (struct cmd_set_vf_broadcast_result,
13796                  on_off, "on#off");
13797
13798 static void
13799 cmd_set_vf_broadcast_parsed(
13800         void *parsed_result,
13801         __attribute__((unused)) struct cmdline *cl,
13802         __attribute__((unused)) void *data)
13803 {
13804         struct cmd_set_vf_broadcast_result *res = parsed_result;
13805         int ret = -ENOTSUP;
13806
13807         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13808
13809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13810                 return;
13811
13812 #ifdef RTE_LIBRTE_I40E_PMD
13813         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13814                                             res->vf_id, is_on);
13815 #endif
13816
13817         switch (ret) {
13818         case 0:
13819                 break;
13820         case -EINVAL:
13821                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13822                 break;
13823         case -ENODEV:
13824                 printf("invalid port_id %d\n", res->port_id);
13825                 break;
13826         case -ENOTSUP:
13827                 printf("function not implemented\n");
13828                 break;
13829         default:
13830                 printf("programming error: (%s)\n", strerror(-ret));
13831         }
13832 }
13833
13834 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13835         .f = cmd_set_vf_broadcast_parsed,
13836         .data = NULL,
13837         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13838         .tokens = {
13839                 (void *)&cmd_set_vf_broadcast_set,
13840                 (void *)&cmd_set_vf_broadcast_vf,
13841                 (void *)&cmd_set_vf_broadcast_broadcast,
13842                 (void *)&cmd_set_vf_broadcast_port_id,
13843                 (void *)&cmd_set_vf_broadcast_vf_id,
13844                 (void *)&cmd_set_vf_broadcast_on_off,
13845                 NULL,
13846         },
13847 };
13848
13849 /* vf vlan tag configuration */
13850
13851 /* Common result structure for vf vlan tag */
13852 struct cmd_set_vf_vlan_tag_result {
13853         cmdline_fixed_string_t set;
13854         cmdline_fixed_string_t vf;
13855         cmdline_fixed_string_t vlan;
13856         cmdline_fixed_string_t tag;
13857         portid_t port_id;
13858         uint16_t vf_id;
13859         cmdline_fixed_string_t on_off;
13860 };
13861
13862 /* Common CLI fields for vf vlan tag enable disable */
13863 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13864         TOKEN_STRING_INITIALIZER
13865                 (struct cmd_set_vf_vlan_tag_result,
13866                  set, "set");
13867 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13868         TOKEN_STRING_INITIALIZER
13869                 (struct cmd_set_vf_vlan_tag_result,
13870                  vf, "vf");
13871 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13872         TOKEN_STRING_INITIALIZER
13873                 (struct cmd_set_vf_vlan_tag_result,
13874                  vlan, "vlan");
13875 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_set_vf_vlan_tag_result,
13878                  tag, "tag");
13879 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13880         TOKEN_NUM_INITIALIZER
13881                 (struct cmd_set_vf_vlan_tag_result,
13882                  port_id, UINT16);
13883 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13884         TOKEN_NUM_INITIALIZER
13885                 (struct cmd_set_vf_vlan_tag_result,
13886                  vf_id, UINT16);
13887 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13888         TOKEN_STRING_INITIALIZER
13889                 (struct cmd_set_vf_vlan_tag_result,
13890                  on_off, "on#off");
13891
13892 static void
13893 cmd_set_vf_vlan_tag_parsed(
13894         void *parsed_result,
13895         __attribute__((unused)) struct cmdline *cl,
13896         __attribute__((unused)) void *data)
13897 {
13898         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13899         int ret = -ENOTSUP;
13900
13901         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13902
13903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13904                 return;
13905
13906 #ifdef RTE_LIBRTE_I40E_PMD
13907         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13908                                            res->vf_id, is_on);
13909 #endif
13910
13911         switch (ret) {
13912         case 0:
13913                 break;
13914         case -EINVAL:
13915                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13916                 break;
13917         case -ENODEV:
13918                 printf("invalid port_id %d\n", res->port_id);
13919                 break;
13920         case -ENOTSUP:
13921                 printf("function not implemented\n");
13922                 break;
13923         default:
13924                 printf("programming error: (%s)\n", strerror(-ret));
13925         }
13926 }
13927
13928 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13929         .f = cmd_set_vf_vlan_tag_parsed,
13930         .data = NULL,
13931         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13932         .tokens = {
13933                 (void *)&cmd_set_vf_vlan_tag_set,
13934                 (void *)&cmd_set_vf_vlan_tag_vf,
13935                 (void *)&cmd_set_vf_vlan_tag_vlan,
13936                 (void *)&cmd_set_vf_vlan_tag_tag,
13937                 (void *)&cmd_set_vf_vlan_tag_port_id,
13938                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13939                 (void *)&cmd_set_vf_vlan_tag_on_off,
13940                 NULL,
13941         },
13942 };
13943
13944 /* Common definition of VF and TC TX bandwidth configuration */
13945 struct cmd_vf_tc_bw_result {
13946         cmdline_fixed_string_t set;
13947         cmdline_fixed_string_t vf;
13948         cmdline_fixed_string_t tc;
13949         cmdline_fixed_string_t tx;
13950         cmdline_fixed_string_t min_bw;
13951         cmdline_fixed_string_t max_bw;
13952         cmdline_fixed_string_t strict_link_prio;
13953         portid_t port_id;
13954         uint16_t vf_id;
13955         uint8_t tc_no;
13956         uint32_t bw;
13957         cmdline_fixed_string_t bw_list;
13958         uint8_t tc_map;
13959 };
13960
13961 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13962         TOKEN_STRING_INITIALIZER
13963                 (struct cmd_vf_tc_bw_result,
13964                  set, "set");
13965 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13966         TOKEN_STRING_INITIALIZER
13967                 (struct cmd_vf_tc_bw_result,
13968                  vf, "vf");
13969 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13970         TOKEN_STRING_INITIALIZER
13971                 (struct cmd_vf_tc_bw_result,
13972                  tc, "tc");
13973 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13974         TOKEN_STRING_INITIALIZER
13975                 (struct cmd_vf_tc_bw_result,
13976                  tx, "tx");
13977 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13978         TOKEN_STRING_INITIALIZER
13979                 (struct cmd_vf_tc_bw_result,
13980                  strict_link_prio, "strict-link-priority");
13981 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13982         TOKEN_STRING_INITIALIZER
13983                 (struct cmd_vf_tc_bw_result,
13984                  min_bw, "min-bandwidth");
13985 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13986         TOKEN_STRING_INITIALIZER
13987                 (struct cmd_vf_tc_bw_result,
13988                  max_bw, "max-bandwidth");
13989 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13990         TOKEN_NUM_INITIALIZER
13991                 (struct cmd_vf_tc_bw_result,
13992                  port_id, UINT16);
13993 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13994         TOKEN_NUM_INITIALIZER
13995                 (struct cmd_vf_tc_bw_result,
13996                  vf_id, UINT16);
13997 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13998         TOKEN_NUM_INITIALIZER
13999                 (struct cmd_vf_tc_bw_result,
14000                  tc_no, UINT8);
14001 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14002         TOKEN_NUM_INITIALIZER
14003                 (struct cmd_vf_tc_bw_result,
14004                  bw, UINT32);
14005 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14006         TOKEN_STRING_INITIALIZER
14007                 (struct cmd_vf_tc_bw_result,
14008                  bw_list, NULL);
14009 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14010         TOKEN_NUM_INITIALIZER
14011                 (struct cmd_vf_tc_bw_result,
14012                  tc_map, UINT8);
14013
14014 /* VF max bandwidth setting */
14015 static void
14016 cmd_vf_max_bw_parsed(
14017         void *parsed_result,
14018         __attribute__((unused)) struct cmdline *cl,
14019         __attribute__((unused)) void *data)
14020 {
14021         struct cmd_vf_tc_bw_result *res = parsed_result;
14022         int ret = -ENOTSUP;
14023
14024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14025                 return;
14026
14027 #ifdef RTE_LIBRTE_I40E_PMD
14028         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14029                                          res->vf_id, res->bw);
14030 #endif
14031
14032         switch (ret) {
14033         case 0:
14034                 break;
14035         case -EINVAL:
14036                 printf("invalid vf_id %d or bandwidth %d\n",
14037                        res->vf_id, res->bw);
14038                 break;
14039         case -ENODEV:
14040                 printf("invalid port_id %d\n", res->port_id);
14041                 break;
14042         case -ENOTSUP:
14043                 printf("function not implemented\n");
14044                 break;
14045         default:
14046                 printf("programming error: (%s)\n", strerror(-ret));
14047         }
14048 }
14049
14050 cmdline_parse_inst_t cmd_vf_max_bw = {
14051         .f = cmd_vf_max_bw_parsed,
14052         .data = NULL,
14053         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14054         .tokens = {
14055                 (void *)&cmd_vf_tc_bw_set,
14056                 (void *)&cmd_vf_tc_bw_vf,
14057                 (void *)&cmd_vf_tc_bw_tx,
14058                 (void *)&cmd_vf_tc_bw_max_bw,
14059                 (void *)&cmd_vf_tc_bw_port_id,
14060                 (void *)&cmd_vf_tc_bw_vf_id,
14061                 (void *)&cmd_vf_tc_bw_bw,
14062                 NULL,
14063         },
14064 };
14065
14066 static int
14067 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14068                            uint8_t *tc_num,
14069                            char *str)
14070 {
14071         uint32_t size;
14072         const char *p, *p0 = str;
14073         char s[256];
14074         char *end;
14075         char *str_fld[16];
14076         uint16_t i;
14077         int ret;
14078
14079         p = strchr(p0, '(');
14080         if (p == NULL) {
14081                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14082                 return -1;
14083         }
14084         p++;
14085         p0 = strchr(p, ')');
14086         if (p0 == NULL) {
14087                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14088                 return -1;
14089         }
14090         size = p0 - p;
14091         if (size >= sizeof(s)) {
14092                 printf("The string size exceeds the internal buffer size\n");
14093                 return -1;
14094         }
14095         snprintf(s, sizeof(s), "%.*s", size, p);
14096         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14097         if (ret <= 0) {
14098                 printf("Failed to get the bandwidth list. ");
14099                 return -1;
14100         }
14101         *tc_num = ret;
14102         for (i = 0; i < ret; i++)
14103                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14104
14105         return 0;
14106 }
14107
14108 /* TC min bandwidth setting */
14109 static void
14110 cmd_vf_tc_min_bw_parsed(
14111         void *parsed_result,
14112         __attribute__((unused)) struct cmdline *cl,
14113         __attribute__((unused)) void *data)
14114 {
14115         struct cmd_vf_tc_bw_result *res = parsed_result;
14116         uint8_t tc_num;
14117         uint8_t bw[16];
14118         int ret = -ENOTSUP;
14119
14120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14121                 return;
14122
14123         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14124         if (ret)
14125                 return;
14126
14127 #ifdef RTE_LIBRTE_I40E_PMD
14128         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14129                                               tc_num, bw);
14130 #endif
14131
14132         switch (ret) {
14133         case 0:
14134                 break;
14135         case -EINVAL:
14136                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14137                 break;
14138         case -ENODEV:
14139                 printf("invalid port_id %d\n", res->port_id);
14140                 break;
14141         case -ENOTSUP:
14142                 printf("function not implemented\n");
14143                 break;
14144         default:
14145                 printf("programming error: (%s)\n", strerror(-ret));
14146         }
14147 }
14148
14149 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14150         .f = cmd_vf_tc_min_bw_parsed,
14151         .data = NULL,
14152         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14153                     " <bw1, bw2, ...>",
14154         .tokens = {
14155                 (void *)&cmd_vf_tc_bw_set,
14156                 (void *)&cmd_vf_tc_bw_vf,
14157                 (void *)&cmd_vf_tc_bw_tc,
14158                 (void *)&cmd_vf_tc_bw_tx,
14159                 (void *)&cmd_vf_tc_bw_min_bw,
14160                 (void *)&cmd_vf_tc_bw_port_id,
14161                 (void *)&cmd_vf_tc_bw_vf_id,
14162                 (void *)&cmd_vf_tc_bw_bw_list,
14163                 NULL,
14164         },
14165 };
14166
14167 static void
14168 cmd_tc_min_bw_parsed(
14169         void *parsed_result,
14170         __attribute__((unused)) struct cmdline *cl,
14171         __attribute__((unused)) void *data)
14172 {
14173         struct cmd_vf_tc_bw_result *res = parsed_result;
14174         struct rte_port *port;
14175         uint8_t tc_num;
14176         uint8_t bw[16];
14177         int ret = -ENOTSUP;
14178
14179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14180                 return;
14181
14182         port = &ports[res->port_id];
14183         /** Check if the port is not started **/
14184         if (port->port_status != RTE_PORT_STOPPED) {
14185                 printf("Please stop port %d first\n", res->port_id);
14186                 return;
14187         }
14188
14189         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14190         if (ret)
14191                 return;
14192
14193 #ifdef RTE_LIBRTE_IXGBE_PMD
14194         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14195 #endif
14196
14197         switch (ret) {
14198         case 0:
14199                 break;
14200         case -EINVAL:
14201                 printf("invalid bandwidth\n");
14202                 break;
14203         case -ENODEV:
14204                 printf("invalid port_id %d\n", res->port_id);
14205                 break;
14206         case -ENOTSUP:
14207                 printf("function not implemented\n");
14208                 break;
14209         default:
14210                 printf("programming error: (%s)\n", strerror(-ret));
14211         }
14212 }
14213
14214 cmdline_parse_inst_t cmd_tc_min_bw = {
14215         .f = cmd_tc_min_bw_parsed,
14216         .data = NULL,
14217         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14218         .tokens = {
14219                 (void *)&cmd_vf_tc_bw_set,
14220                 (void *)&cmd_vf_tc_bw_tc,
14221                 (void *)&cmd_vf_tc_bw_tx,
14222                 (void *)&cmd_vf_tc_bw_min_bw,
14223                 (void *)&cmd_vf_tc_bw_port_id,
14224                 (void *)&cmd_vf_tc_bw_bw_list,
14225                 NULL,
14226         },
14227 };
14228
14229 /* TC max bandwidth setting */
14230 static void
14231 cmd_vf_tc_max_bw_parsed(
14232         void *parsed_result,
14233         __attribute__((unused)) struct cmdline *cl,
14234         __attribute__((unused)) void *data)
14235 {
14236         struct cmd_vf_tc_bw_result *res = parsed_result;
14237         int ret = -ENOTSUP;
14238
14239         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14240                 return;
14241
14242 #ifdef RTE_LIBRTE_I40E_PMD
14243         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14244                                             res->tc_no, res->bw);
14245 #endif
14246
14247         switch (ret) {
14248         case 0:
14249                 break;
14250         case -EINVAL:
14251                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14252                        res->vf_id, res->tc_no, res->bw);
14253                 break;
14254         case -ENODEV:
14255                 printf("invalid port_id %d\n", res->port_id);
14256                 break;
14257         case -ENOTSUP:
14258                 printf("function not implemented\n");
14259                 break;
14260         default:
14261                 printf("programming error: (%s)\n", strerror(-ret));
14262         }
14263 }
14264
14265 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14266         .f = cmd_vf_tc_max_bw_parsed,
14267         .data = NULL,
14268         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14269                     " <bandwidth>",
14270         .tokens = {
14271                 (void *)&cmd_vf_tc_bw_set,
14272                 (void *)&cmd_vf_tc_bw_vf,
14273                 (void *)&cmd_vf_tc_bw_tc,
14274                 (void *)&cmd_vf_tc_bw_tx,
14275                 (void *)&cmd_vf_tc_bw_max_bw,
14276                 (void *)&cmd_vf_tc_bw_port_id,
14277                 (void *)&cmd_vf_tc_bw_vf_id,
14278                 (void *)&cmd_vf_tc_bw_tc_no,
14279                 (void *)&cmd_vf_tc_bw_bw,
14280                 NULL,
14281         },
14282 };
14283
14284
14285 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14286
14287 /* *** Set Port default Traffic Management Hierarchy *** */
14288 struct cmd_set_port_tm_hierarchy_default_result {
14289         cmdline_fixed_string_t set;
14290         cmdline_fixed_string_t port;
14291         cmdline_fixed_string_t tm;
14292         cmdline_fixed_string_t hierarchy;
14293         cmdline_fixed_string_t def;
14294         portid_t port_id;
14295 };
14296
14297 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14298         TOKEN_STRING_INITIALIZER(
14299                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14300 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14301         TOKEN_STRING_INITIALIZER(
14302                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14303 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14304         TOKEN_STRING_INITIALIZER(
14305                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14306 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14307         TOKEN_STRING_INITIALIZER(
14308                 struct cmd_set_port_tm_hierarchy_default_result,
14309                         hierarchy, "hierarchy");
14310 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14311         TOKEN_STRING_INITIALIZER(
14312                 struct cmd_set_port_tm_hierarchy_default_result,
14313                         def, "default");
14314 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14315         TOKEN_NUM_INITIALIZER(
14316                 struct cmd_set_port_tm_hierarchy_default_result,
14317                         port_id, UINT16);
14318
14319 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14320         __attribute__((unused)) struct cmdline *cl,
14321         __attribute__((unused)) void *data)
14322 {
14323         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14324         struct rte_port *p;
14325         portid_t port_id = res->port_id;
14326
14327         if (port_id_is_invalid(port_id, ENABLED_WARN))
14328                 return;
14329
14330         p = &ports[port_id];
14331
14332         /* Port tm flag */
14333         if (p->softport.tm_flag == 0) {
14334                 printf("  tm not enabled on port %u (error)\n", port_id);
14335                 return;
14336         }
14337
14338         /* Forward mode: tm */
14339         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14340                 printf("  tm mode not enabled(error)\n");
14341                 return;
14342         }
14343
14344         /* Set the default tm hierarchy */
14345         p->softport.tm.default_hierarchy_enable = 1;
14346 }
14347
14348 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14349         .f = cmd_set_port_tm_hierarchy_default_parsed,
14350         .data = NULL,
14351         .help_str = "set port tm hierarchy default <port_id>",
14352         .tokens = {
14353                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14354                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14355                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14356                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14357                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14358                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14359                 NULL,
14360         },
14361 };
14362 #endif
14363
14364 /* Strict link priority scheduling mode setting */
14365 static void
14366 cmd_strict_link_prio_parsed(
14367         void *parsed_result,
14368         __attribute__((unused)) struct cmdline *cl,
14369         __attribute__((unused)) void *data)
14370 {
14371         struct cmd_vf_tc_bw_result *res = parsed_result;
14372         int ret = -ENOTSUP;
14373
14374         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14375                 return;
14376
14377 #ifdef RTE_LIBRTE_I40E_PMD
14378         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14379 #endif
14380
14381         switch (ret) {
14382         case 0:
14383                 break;
14384         case -EINVAL:
14385                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14386                 break;
14387         case -ENODEV:
14388                 printf("invalid port_id %d\n", res->port_id);
14389                 break;
14390         case -ENOTSUP:
14391                 printf("function not implemented\n");
14392                 break;
14393         default:
14394                 printf("programming error: (%s)\n", strerror(-ret));
14395         }
14396 }
14397
14398 cmdline_parse_inst_t cmd_strict_link_prio = {
14399         .f = cmd_strict_link_prio_parsed,
14400         .data = NULL,
14401         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14402         .tokens = {
14403                 (void *)&cmd_vf_tc_bw_set,
14404                 (void *)&cmd_vf_tc_bw_tx,
14405                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14406                 (void *)&cmd_vf_tc_bw_port_id,
14407                 (void *)&cmd_vf_tc_bw_tc_map,
14408                 NULL,
14409         },
14410 };
14411
14412 /* Load dynamic device personalization*/
14413 struct cmd_ddp_add_result {
14414         cmdline_fixed_string_t ddp;
14415         cmdline_fixed_string_t add;
14416         portid_t port_id;
14417         char filepath[];
14418 };
14419
14420 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14421         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14422 cmdline_parse_token_string_t cmd_ddp_add_add =
14423         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14424 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14425         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14426 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14427         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14428
14429 static void
14430 cmd_ddp_add_parsed(
14431         void *parsed_result,
14432         __attribute__((unused)) struct cmdline *cl,
14433         __attribute__((unused)) void *data)
14434 {
14435         struct cmd_ddp_add_result *res = parsed_result;
14436         uint8_t *buff;
14437         uint32_t size;
14438         char *filepath;
14439         char *file_fld[2];
14440         int file_num;
14441         int ret = -ENOTSUP;
14442
14443         if (res->port_id > nb_ports) {
14444                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14445                 return;
14446         }
14447
14448         if (!all_ports_stopped()) {
14449                 printf("Please stop all ports first\n");
14450                 return;
14451         }
14452
14453         filepath = strdup(res->filepath);
14454         if (filepath == NULL) {
14455                 printf("Failed to allocate memory\n");
14456                 return;
14457         }
14458         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14459
14460         buff = open_file(file_fld[0], &size);
14461         if (!buff) {
14462                 free((void *)filepath);
14463                 return;
14464         }
14465
14466 #ifdef RTE_LIBRTE_I40E_PMD
14467         if (ret == -ENOTSUP)
14468                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14469                                                buff, size,
14470                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14471 #endif
14472
14473         if (ret == -EEXIST)
14474                 printf("Profile has already existed.\n");
14475         else if (ret < 0)
14476                 printf("Failed to load profile.\n");
14477         else if (file_num == 2)
14478                 save_file(file_fld[1], buff, size);
14479
14480         close_file(buff);
14481         free((void *)filepath);
14482 }
14483
14484 cmdline_parse_inst_t cmd_ddp_add = {
14485         .f = cmd_ddp_add_parsed,
14486         .data = NULL,
14487         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14488         .tokens = {
14489                 (void *)&cmd_ddp_add_ddp,
14490                 (void *)&cmd_ddp_add_add,
14491                 (void *)&cmd_ddp_add_port_id,
14492                 (void *)&cmd_ddp_add_filepath,
14493                 NULL,
14494         },
14495 };
14496
14497 /* Delete dynamic device personalization*/
14498 struct cmd_ddp_del_result {
14499         cmdline_fixed_string_t ddp;
14500         cmdline_fixed_string_t del;
14501         portid_t port_id;
14502         char filepath[];
14503 };
14504
14505 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14506         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14507 cmdline_parse_token_string_t cmd_ddp_del_del =
14508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14509 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14510         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14511 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14512         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14513
14514 static void
14515 cmd_ddp_del_parsed(
14516         void *parsed_result,
14517         __attribute__((unused)) struct cmdline *cl,
14518         __attribute__((unused)) void *data)
14519 {
14520         struct cmd_ddp_del_result *res = parsed_result;
14521         uint8_t *buff;
14522         uint32_t size;
14523         int ret = -ENOTSUP;
14524
14525         if (res->port_id > nb_ports) {
14526                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14527                 return;
14528         }
14529
14530         if (!all_ports_stopped()) {
14531                 printf("Please stop all ports first\n");
14532                 return;
14533         }
14534
14535         buff = open_file(res->filepath, &size);
14536         if (!buff)
14537                 return;
14538
14539 #ifdef RTE_LIBRTE_I40E_PMD
14540         if (ret == -ENOTSUP)
14541                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14542                                                buff, size,
14543                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14544 #endif
14545
14546         if (ret == -EACCES)
14547                 printf("Profile does not exist.\n");
14548         else if (ret < 0)
14549                 printf("Failed to delete profile.\n");
14550
14551         close_file(buff);
14552 }
14553
14554 cmdline_parse_inst_t cmd_ddp_del = {
14555         .f = cmd_ddp_del_parsed,
14556         .data = NULL,
14557         .help_str = "ddp del <port_id> <profile_path>",
14558         .tokens = {
14559                 (void *)&cmd_ddp_del_ddp,
14560                 (void *)&cmd_ddp_del_del,
14561                 (void *)&cmd_ddp_del_port_id,
14562                 (void *)&cmd_ddp_del_filepath,
14563                 NULL,
14564         },
14565 };
14566
14567 /* Get dynamic device personalization profile info */
14568 struct cmd_ddp_info_result {
14569         cmdline_fixed_string_t ddp;
14570         cmdline_fixed_string_t get;
14571         cmdline_fixed_string_t info;
14572         char filepath[];
14573 };
14574
14575 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14576         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14577 cmdline_parse_token_string_t cmd_ddp_info_get =
14578         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14579 cmdline_parse_token_string_t cmd_ddp_info_info =
14580         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14581 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14582         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14583
14584 static void
14585 cmd_ddp_info_parsed(
14586         void *parsed_result,
14587         __attribute__((unused)) struct cmdline *cl,
14588         __attribute__((unused)) void *data)
14589 {
14590         struct cmd_ddp_info_result *res = parsed_result;
14591         uint8_t *pkg;
14592         uint32_t pkg_size;
14593         int ret = -ENOTSUP;
14594 #ifdef RTE_LIBRTE_I40E_PMD
14595         uint32_t i, j, n;
14596         uint8_t *buff;
14597         uint32_t buff_size = 0;
14598         struct rte_pmd_i40e_profile_info info;
14599         uint32_t dev_num = 0;
14600         struct rte_pmd_i40e_ddp_device_id *devs;
14601         uint32_t proto_num = 0;
14602         struct rte_pmd_i40e_proto_info *proto = NULL;
14603         uint32_t pctype_num = 0;
14604         struct rte_pmd_i40e_ptype_info *pctype;
14605         uint32_t ptype_num = 0;
14606         struct rte_pmd_i40e_ptype_info *ptype;
14607         uint8_t proto_id;
14608
14609 #endif
14610
14611         pkg = open_file(res->filepath, &pkg_size);
14612         if (!pkg)
14613                 return;
14614
14615 #ifdef RTE_LIBRTE_I40E_PMD
14616         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14617                                 (uint8_t *)&info, sizeof(info),
14618                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14619         if (!ret) {
14620                 printf("Global Track id:       0x%x\n", info.track_id);
14621                 printf("Global Version:        %d.%d.%d.%d\n",
14622                         info.version.major,
14623                         info.version.minor,
14624                         info.version.update,
14625                         info.version.draft);
14626                 printf("Global Package name:   %s\n\n", info.name);
14627         }
14628
14629         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14630                                 (uint8_t *)&info, sizeof(info),
14631                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14632         if (!ret) {
14633                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14634                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14635                         info.version.major,
14636                         info.version.minor,
14637                         info.version.update,
14638                         info.version.draft);
14639                 printf("i40e Profile name:     %s\n\n", info.name);
14640         }
14641
14642         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14643                                 (uint8_t *)&buff_size, sizeof(buff_size),
14644                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14645         if (!ret && buff_size) {
14646                 buff = (uint8_t *)malloc(buff_size);
14647                 if (buff) {
14648                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14649                                                 buff, buff_size,
14650                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14651                         if (!ret)
14652                                 printf("Package Notes:\n%s\n\n", buff);
14653                         free(buff);
14654                 }
14655         }
14656
14657         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14658                                 (uint8_t *)&dev_num, sizeof(dev_num),
14659                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14660         if (!ret && dev_num) {
14661                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14662                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14663                 if (devs) {
14664                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14665                                                 (uint8_t *)devs, buff_size,
14666                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14667                         if (!ret) {
14668                                 printf("List of supported devices:\n");
14669                                 for (i = 0; i < dev_num; i++) {
14670                                         printf("  %04X:%04X %04X:%04X\n",
14671                                                 devs[i].vendor_dev_id >> 16,
14672                                                 devs[i].vendor_dev_id & 0xFFFF,
14673                                                 devs[i].sub_vendor_dev_id >> 16,
14674                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14675                                 }
14676                                 printf("\n");
14677                         }
14678                         free(devs);
14679                 }
14680         }
14681
14682         /* get information about protocols and packet types */
14683         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14684                 (uint8_t *)&proto_num, sizeof(proto_num),
14685                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14686         if (ret || !proto_num)
14687                 goto no_print_return;
14688
14689         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14690         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14691         if (!proto)
14692                 goto no_print_return;
14693
14694         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14695                                         buff_size,
14696                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14697         if (!ret) {
14698                 printf("List of used protocols:\n");
14699                 for (i = 0; i < proto_num; i++)
14700                         printf("  %2u: %s\n", proto[i].proto_id,
14701                                proto[i].name);
14702                 printf("\n");
14703         }
14704         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14705                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14706                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14707         if (ret || !pctype_num)
14708                 goto no_print_pctypes;
14709
14710         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14711         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14712         if (!pctype)
14713                 goto no_print_pctypes;
14714
14715         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14716                                         buff_size,
14717                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14718         if (ret) {
14719                 free(pctype);
14720                 goto no_print_pctypes;
14721         }
14722
14723         printf("List of defined packet classification types:\n");
14724         for (i = 0; i < pctype_num; i++) {
14725                 printf("  %2u:", pctype[i].ptype_id);
14726                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14727                         proto_id = pctype[i].protocols[j];
14728                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14729                                 for (n = 0; n < proto_num; n++) {
14730                                         if (proto[n].proto_id == proto_id) {
14731                                                 printf(" %s", proto[n].name);
14732                                                 break;
14733                                         }
14734                                 }
14735                         }
14736                 }
14737                 printf("\n");
14738         }
14739         printf("\n");
14740         free(pctype);
14741
14742 no_print_pctypes:
14743
14744         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14745                                         sizeof(ptype_num),
14746                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14747         if (ret || !ptype_num)
14748                 goto no_print_return;
14749
14750         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14751         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14752         if (!ptype)
14753                 goto no_print_return;
14754
14755         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14756                                         buff_size,
14757                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14758         if (ret) {
14759                 free(ptype);
14760                 goto no_print_return;
14761         }
14762         printf("List of defined packet types:\n");
14763         for (i = 0; i < ptype_num; i++) {
14764                 printf("  %2u:", ptype[i].ptype_id);
14765                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14766                         proto_id = ptype[i].protocols[j];
14767                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14768                                 for (n = 0; n < proto_num; n++) {
14769                                         if (proto[n].proto_id == proto_id) {
14770                                                 printf(" %s", proto[n].name);
14771                                                 break;
14772                                         }
14773                                 }
14774                         }
14775                 }
14776                 printf("\n");
14777         }
14778         free(ptype);
14779         printf("\n");
14780
14781         ret = 0;
14782 no_print_return:
14783         if (proto)
14784                 free(proto);
14785 #endif
14786         if (ret == -ENOTSUP)
14787                 printf("Function not supported in PMD driver\n");
14788         close_file(pkg);
14789 }
14790
14791 cmdline_parse_inst_t cmd_ddp_get_info = {
14792         .f = cmd_ddp_info_parsed,
14793         .data = NULL,
14794         .help_str = "ddp get info <profile_path>",
14795         .tokens = {
14796                 (void *)&cmd_ddp_info_ddp,
14797                 (void *)&cmd_ddp_info_get,
14798                 (void *)&cmd_ddp_info_info,
14799                 (void *)&cmd_ddp_info_filepath,
14800                 NULL,
14801         },
14802 };
14803
14804 /* Get dynamic device personalization profile info list*/
14805 #define PROFILE_INFO_SIZE 48
14806 #define MAX_PROFILE_NUM 16
14807
14808 struct cmd_ddp_get_list_result {
14809         cmdline_fixed_string_t ddp;
14810         cmdline_fixed_string_t get;
14811         cmdline_fixed_string_t list;
14812         portid_t port_id;
14813 };
14814
14815 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14816         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14817 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14818         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14819 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14820         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14821 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14822         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14823
14824 static void
14825 cmd_ddp_get_list_parsed(
14826         void *parsed_result,
14827         __attribute__((unused)) struct cmdline *cl,
14828         __attribute__((unused)) void *data)
14829 {
14830         struct cmd_ddp_get_list_result *res = parsed_result;
14831 #ifdef RTE_LIBRTE_I40E_PMD
14832         struct rte_pmd_i40e_profile_list *p_list;
14833         struct rte_pmd_i40e_profile_info *p_info;
14834         uint32_t p_num;
14835         uint32_t size;
14836         uint32_t i;
14837 #endif
14838         int ret = -ENOTSUP;
14839
14840         if (res->port_id > nb_ports) {
14841                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14842                 return;
14843         }
14844
14845 #ifdef RTE_LIBRTE_I40E_PMD
14846         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14847         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14848         if (!p_list)
14849                 printf("%s: Failed to malloc buffer\n", __func__);
14850
14851         if (ret == -ENOTSUP)
14852                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14853                                                 (uint8_t *)p_list, size);
14854
14855         if (!ret) {
14856                 p_num = p_list->p_count;
14857                 printf("Profile number is: %d\n\n", p_num);
14858
14859                 for (i = 0; i < p_num; i++) {
14860                         p_info = &p_list->p_info[i];
14861                         printf("Profile %d:\n", i);
14862                         printf("Track id:     0x%x\n", p_info->track_id);
14863                         printf("Version:      %d.%d.%d.%d\n",
14864                                p_info->version.major,
14865                                p_info->version.minor,
14866                                p_info->version.update,
14867                                p_info->version.draft);
14868                         printf("Profile name: %s\n\n", p_info->name);
14869                 }
14870         }
14871
14872         free(p_list);
14873 #endif
14874
14875         if (ret < 0)
14876                 printf("Failed to get ddp list\n");
14877 }
14878
14879 cmdline_parse_inst_t cmd_ddp_get_list = {
14880         .f = cmd_ddp_get_list_parsed,
14881         .data = NULL,
14882         .help_str = "ddp get list <port_id>",
14883         .tokens = {
14884                 (void *)&cmd_ddp_get_list_ddp,
14885                 (void *)&cmd_ddp_get_list_get,
14886                 (void *)&cmd_ddp_get_list_list,
14887                 (void *)&cmd_ddp_get_list_port_id,
14888                 NULL,
14889         },
14890 };
14891
14892 /* Configure input set */
14893 struct cmd_cfg_input_set_result {
14894         cmdline_fixed_string_t port;
14895         cmdline_fixed_string_t cfg;
14896         portid_t port_id;
14897         cmdline_fixed_string_t pctype;
14898         uint8_t pctype_id;
14899         cmdline_fixed_string_t inset_type;
14900         cmdline_fixed_string_t opt;
14901         cmdline_fixed_string_t field;
14902         uint8_t field_idx;
14903 };
14904
14905 static void
14906 cmd_cfg_input_set_parsed(
14907         void *parsed_result,
14908         __attribute__((unused)) struct cmdline *cl,
14909         __attribute__((unused)) void *data)
14910 {
14911         struct cmd_cfg_input_set_result *res = parsed_result;
14912 #ifdef RTE_LIBRTE_I40E_PMD
14913         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14914         struct rte_pmd_i40e_inset inset;
14915 #endif
14916         int ret = -ENOTSUP;
14917
14918         if (res->port_id > nb_ports) {
14919                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14920                 return;
14921         }
14922
14923         if (!all_ports_stopped()) {
14924                 printf("Please stop all ports first\n");
14925                 return;
14926         }
14927
14928 #ifdef RTE_LIBRTE_I40E_PMD
14929         if (!strcmp(res->inset_type, "hash_inset"))
14930                 inset_type = INSET_HASH;
14931         else if (!strcmp(res->inset_type, "fdir_inset"))
14932                 inset_type = INSET_FDIR;
14933         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14934                 inset_type = INSET_FDIR_FLX;
14935         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14936                                      &inset, inset_type);
14937         if (ret) {
14938                 printf("Failed to get input set.\n");
14939                 return;
14940         }
14941
14942         if (!strcmp(res->opt, "get")) {
14943                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14944                                                    res->field_idx);
14945                 if (ret)
14946                         printf("Field index %d is enabled.\n", res->field_idx);
14947                 else
14948                         printf("Field index %d is disabled.\n", res->field_idx);
14949                 return;
14950         } else if (!strcmp(res->opt, "set"))
14951                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14952                                                    res->field_idx);
14953         else if (!strcmp(res->opt, "clear"))
14954                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14955                                                      res->field_idx);
14956         if (ret) {
14957                 printf("Failed to configure input set field.\n");
14958                 return;
14959         }
14960
14961         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14962                                      &inset, inset_type);
14963         if (ret) {
14964                 printf("Failed to set input set.\n");
14965                 return;
14966         }
14967 #endif
14968
14969         if (ret == -ENOTSUP)
14970                 printf("Function not supported\n");
14971 }
14972
14973 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14974         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14975                                  port, "port");
14976 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14977         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14978                                  cfg, "config");
14979 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14980         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14981                               port_id, UINT16);
14982 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14983         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14984                                  pctype, "pctype");
14985 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14986         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14987                               pctype_id, UINT8);
14988 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14989         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14990                                  inset_type,
14991                                  "hash_inset#fdir_inset#fdir_flx_inset");
14992 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14993         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14994                                  opt, "get#set#clear");
14995 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14996         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14997                                  field, "field");
14998 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14999         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15000                               field_idx, UINT8);
15001
15002 cmdline_parse_inst_t cmd_cfg_input_set = {
15003         .f = cmd_cfg_input_set_parsed,
15004         .data = NULL,
15005         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15006                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15007         .tokens = {
15008                 (void *)&cmd_cfg_input_set_port,
15009                 (void *)&cmd_cfg_input_set_cfg,
15010                 (void *)&cmd_cfg_input_set_port_id,
15011                 (void *)&cmd_cfg_input_set_pctype,
15012                 (void *)&cmd_cfg_input_set_pctype_id,
15013                 (void *)&cmd_cfg_input_set_inset_type,
15014                 (void *)&cmd_cfg_input_set_opt,
15015                 (void *)&cmd_cfg_input_set_field,
15016                 (void *)&cmd_cfg_input_set_field_idx,
15017                 NULL,
15018         },
15019 };
15020
15021 /* Clear input set */
15022 struct cmd_clear_input_set_result {
15023         cmdline_fixed_string_t port;
15024         cmdline_fixed_string_t cfg;
15025         portid_t port_id;
15026         cmdline_fixed_string_t pctype;
15027         uint8_t pctype_id;
15028         cmdline_fixed_string_t inset_type;
15029         cmdline_fixed_string_t clear;
15030         cmdline_fixed_string_t all;
15031 };
15032
15033 static void
15034 cmd_clear_input_set_parsed(
15035         void *parsed_result,
15036         __attribute__((unused)) struct cmdline *cl,
15037         __attribute__((unused)) void *data)
15038 {
15039         struct cmd_clear_input_set_result *res = parsed_result;
15040 #ifdef RTE_LIBRTE_I40E_PMD
15041         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15042         struct rte_pmd_i40e_inset inset;
15043 #endif
15044         int ret = -ENOTSUP;
15045
15046         if (res->port_id > nb_ports) {
15047                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15048                 return;
15049         }
15050
15051         if (!all_ports_stopped()) {
15052                 printf("Please stop all ports first\n");
15053                 return;
15054         }
15055
15056 #ifdef RTE_LIBRTE_I40E_PMD
15057         if (!strcmp(res->inset_type, "hash_inset"))
15058                 inset_type = INSET_HASH;
15059         else if (!strcmp(res->inset_type, "fdir_inset"))
15060                 inset_type = INSET_FDIR;
15061         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15062                 inset_type = INSET_FDIR_FLX;
15063
15064         memset(&inset, 0, sizeof(inset));
15065
15066         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15067                                      &inset, inset_type);
15068         if (ret) {
15069                 printf("Failed to clear input set.\n");
15070                 return;
15071         }
15072
15073 #endif
15074
15075         if (ret == -ENOTSUP)
15076                 printf("Function not supported\n");
15077 }
15078
15079 cmdline_parse_token_string_t cmd_clear_input_set_port =
15080         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15081                                  port, "port");
15082 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15083         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15084                                  cfg, "config");
15085 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15086         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15087                               port_id, UINT16);
15088 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15089         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15090                                  pctype, "pctype");
15091 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15092         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15093                               pctype_id, UINT8);
15094 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15095         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15096                                  inset_type,
15097                                  "hash_inset#fdir_inset#fdir_flx_inset");
15098 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15099         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15100                                  clear, "clear");
15101 cmdline_parse_token_string_t cmd_clear_input_set_all =
15102         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15103                                  all, "all");
15104
15105 cmdline_parse_inst_t cmd_clear_input_set = {
15106         .f = cmd_clear_input_set_parsed,
15107         .data = NULL,
15108         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15109                     "fdir_inset|fdir_flx_inset clear all",
15110         .tokens = {
15111                 (void *)&cmd_clear_input_set_port,
15112                 (void *)&cmd_clear_input_set_cfg,
15113                 (void *)&cmd_clear_input_set_port_id,
15114                 (void *)&cmd_clear_input_set_pctype,
15115                 (void *)&cmd_clear_input_set_pctype_id,
15116                 (void *)&cmd_clear_input_set_inset_type,
15117                 (void *)&cmd_clear_input_set_clear,
15118                 (void *)&cmd_clear_input_set_all,
15119                 NULL,
15120         },
15121 };
15122
15123 /* show vf stats */
15124
15125 /* Common result structure for show vf stats */
15126 struct cmd_show_vf_stats_result {
15127         cmdline_fixed_string_t show;
15128         cmdline_fixed_string_t vf;
15129         cmdline_fixed_string_t stats;
15130         portid_t port_id;
15131         uint16_t vf_id;
15132 };
15133
15134 /* Common CLI fields show vf stats*/
15135 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_show_vf_stats_result,
15138                  show, "show");
15139 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_show_vf_stats_result,
15142                  vf, "vf");
15143 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_show_vf_stats_result,
15146                  stats, "stats");
15147 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15148         TOKEN_NUM_INITIALIZER
15149                 (struct cmd_show_vf_stats_result,
15150                  port_id, UINT16);
15151 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15152         TOKEN_NUM_INITIALIZER
15153                 (struct cmd_show_vf_stats_result,
15154                  vf_id, UINT16);
15155
15156 static void
15157 cmd_show_vf_stats_parsed(
15158         void *parsed_result,
15159         __attribute__((unused)) struct cmdline *cl,
15160         __attribute__((unused)) void *data)
15161 {
15162         struct cmd_show_vf_stats_result *res = parsed_result;
15163         struct rte_eth_stats stats;
15164         int ret = -ENOTSUP;
15165         static const char *nic_stats_border = "########################";
15166
15167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15168                 return;
15169
15170         memset(&stats, 0, sizeof(stats));
15171
15172 #ifdef RTE_LIBRTE_I40E_PMD
15173         if (ret == -ENOTSUP)
15174                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15175                                                 res->vf_id,
15176                                                 &stats);
15177 #endif
15178 #ifdef RTE_LIBRTE_BNXT_PMD
15179         if (ret == -ENOTSUP)
15180                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15181                                                 res->vf_id,
15182                                                 &stats);
15183 #endif
15184
15185         switch (ret) {
15186         case 0:
15187                 break;
15188         case -EINVAL:
15189                 printf("invalid vf_id %d\n", res->vf_id);
15190                 break;
15191         case -ENODEV:
15192                 printf("invalid port_id %d\n", res->port_id);
15193                 break;
15194         case -ENOTSUP:
15195                 printf("function not implemented\n");
15196                 break;
15197         default:
15198                 printf("programming error: (%s)\n", strerror(-ret));
15199         }
15200
15201         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15202                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15203
15204         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15205                "%-"PRIu64"\n",
15206                stats.ipackets, stats.imissed, stats.ibytes);
15207         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15208         printf("  RX-nombuf:  %-10"PRIu64"\n",
15209                stats.rx_nombuf);
15210         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15211                "%-"PRIu64"\n",
15212                stats.opackets, stats.oerrors, stats.obytes);
15213
15214         printf("  %s############################%s\n",
15215                                nic_stats_border, nic_stats_border);
15216 }
15217
15218 cmdline_parse_inst_t cmd_show_vf_stats = {
15219         .f = cmd_show_vf_stats_parsed,
15220         .data = NULL,
15221         .help_str = "show vf stats <port_id> <vf_id>",
15222         .tokens = {
15223                 (void *)&cmd_show_vf_stats_show,
15224                 (void *)&cmd_show_vf_stats_vf,
15225                 (void *)&cmd_show_vf_stats_stats,
15226                 (void *)&cmd_show_vf_stats_port_id,
15227                 (void *)&cmd_show_vf_stats_vf_id,
15228                 NULL,
15229         },
15230 };
15231
15232 /* clear vf stats */
15233
15234 /* Common result structure for clear vf stats */
15235 struct cmd_clear_vf_stats_result {
15236         cmdline_fixed_string_t clear;
15237         cmdline_fixed_string_t vf;
15238         cmdline_fixed_string_t stats;
15239         portid_t port_id;
15240         uint16_t vf_id;
15241 };
15242
15243 /* Common CLI fields clear vf stats*/
15244 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15245         TOKEN_STRING_INITIALIZER
15246                 (struct cmd_clear_vf_stats_result,
15247                  clear, "clear");
15248 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15249         TOKEN_STRING_INITIALIZER
15250                 (struct cmd_clear_vf_stats_result,
15251                  vf, "vf");
15252 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15253         TOKEN_STRING_INITIALIZER
15254                 (struct cmd_clear_vf_stats_result,
15255                  stats, "stats");
15256 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15257         TOKEN_NUM_INITIALIZER
15258                 (struct cmd_clear_vf_stats_result,
15259                  port_id, UINT16);
15260 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15261         TOKEN_NUM_INITIALIZER
15262                 (struct cmd_clear_vf_stats_result,
15263                  vf_id, UINT16);
15264
15265 static void
15266 cmd_clear_vf_stats_parsed(
15267         void *parsed_result,
15268         __attribute__((unused)) struct cmdline *cl,
15269         __attribute__((unused)) void *data)
15270 {
15271         struct cmd_clear_vf_stats_result *res = parsed_result;
15272         int ret = -ENOTSUP;
15273
15274         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15275                 return;
15276
15277 #ifdef RTE_LIBRTE_I40E_PMD
15278         if (ret == -ENOTSUP)
15279                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15280                                                   res->vf_id);
15281 #endif
15282 #ifdef RTE_LIBRTE_BNXT_PMD
15283         if (ret == -ENOTSUP)
15284                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15285                                                   res->vf_id);
15286 #endif
15287
15288         switch (ret) {
15289         case 0:
15290                 break;
15291         case -EINVAL:
15292                 printf("invalid vf_id %d\n", res->vf_id);
15293                 break;
15294         case -ENODEV:
15295                 printf("invalid port_id %d\n", res->port_id);
15296                 break;
15297         case -ENOTSUP:
15298                 printf("function not implemented\n");
15299                 break;
15300         default:
15301                 printf("programming error: (%s)\n", strerror(-ret));
15302         }
15303 }
15304
15305 cmdline_parse_inst_t cmd_clear_vf_stats = {
15306         .f = cmd_clear_vf_stats_parsed,
15307         .data = NULL,
15308         .help_str = "clear vf stats <port_id> <vf_id>",
15309         .tokens = {
15310                 (void *)&cmd_clear_vf_stats_clear,
15311                 (void *)&cmd_clear_vf_stats_vf,
15312                 (void *)&cmd_clear_vf_stats_stats,
15313                 (void *)&cmd_clear_vf_stats_port_id,
15314                 (void *)&cmd_clear_vf_stats_vf_id,
15315                 NULL,
15316         },
15317 };
15318
15319 /* port config pctype mapping reset */
15320
15321 /* Common result structure for port config pctype mapping reset */
15322 struct cmd_pctype_mapping_reset_result {
15323         cmdline_fixed_string_t port;
15324         cmdline_fixed_string_t config;
15325         portid_t port_id;
15326         cmdline_fixed_string_t pctype;
15327         cmdline_fixed_string_t mapping;
15328         cmdline_fixed_string_t reset;
15329 };
15330
15331 /* Common CLI fields for port config pctype mapping reset*/
15332 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15333         TOKEN_STRING_INITIALIZER
15334                 (struct cmd_pctype_mapping_reset_result,
15335                  port, "port");
15336 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15337         TOKEN_STRING_INITIALIZER
15338                 (struct cmd_pctype_mapping_reset_result,
15339                  config, "config");
15340 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15341         TOKEN_NUM_INITIALIZER
15342                 (struct cmd_pctype_mapping_reset_result,
15343                  port_id, UINT16);
15344 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15345         TOKEN_STRING_INITIALIZER
15346                 (struct cmd_pctype_mapping_reset_result,
15347                  pctype, "pctype");
15348 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15349         TOKEN_STRING_INITIALIZER
15350                 (struct cmd_pctype_mapping_reset_result,
15351                  mapping, "mapping");
15352 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15353         TOKEN_STRING_INITIALIZER
15354                 (struct cmd_pctype_mapping_reset_result,
15355                  reset, "reset");
15356
15357 static void
15358 cmd_pctype_mapping_reset_parsed(
15359         void *parsed_result,
15360         __attribute__((unused)) struct cmdline *cl,
15361         __attribute__((unused)) void *data)
15362 {
15363         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15364         int ret = -ENOTSUP;
15365
15366         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15367                 return;
15368
15369 #ifdef RTE_LIBRTE_I40E_PMD
15370         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15371 #endif
15372
15373         switch (ret) {
15374         case 0:
15375                 break;
15376         case -ENODEV:
15377                 printf("invalid port_id %d\n", res->port_id);
15378                 break;
15379         case -ENOTSUP:
15380                 printf("function not implemented\n");
15381                 break;
15382         default:
15383                 printf("programming error: (%s)\n", strerror(-ret));
15384         }
15385 }
15386
15387 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15388         .f = cmd_pctype_mapping_reset_parsed,
15389         .data = NULL,
15390         .help_str = "port config <port_id> pctype mapping reset",
15391         .tokens = {
15392                 (void *)&cmd_pctype_mapping_reset_port,
15393                 (void *)&cmd_pctype_mapping_reset_config,
15394                 (void *)&cmd_pctype_mapping_reset_port_id,
15395                 (void *)&cmd_pctype_mapping_reset_pctype,
15396                 (void *)&cmd_pctype_mapping_reset_mapping,
15397                 (void *)&cmd_pctype_mapping_reset_reset,
15398                 NULL,
15399         },
15400 };
15401
15402 /* show port pctype mapping */
15403
15404 /* Common result structure for show port pctype mapping */
15405 struct cmd_pctype_mapping_get_result {
15406         cmdline_fixed_string_t show;
15407         cmdline_fixed_string_t port;
15408         portid_t port_id;
15409         cmdline_fixed_string_t pctype;
15410         cmdline_fixed_string_t mapping;
15411 };
15412
15413 /* Common CLI fields for pctype mapping get */
15414 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15415         TOKEN_STRING_INITIALIZER
15416                 (struct cmd_pctype_mapping_get_result,
15417                  show, "show");
15418 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15419         TOKEN_STRING_INITIALIZER
15420                 (struct cmd_pctype_mapping_get_result,
15421                  port, "port");
15422 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15423         TOKEN_NUM_INITIALIZER
15424                 (struct cmd_pctype_mapping_get_result,
15425                  port_id, UINT16);
15426 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15427         TOKEN_STRING_INITIALIZER
15428                 (struct cmd_pctype_mapping_get_result,
15429                  pctype, "pctype");
15430 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15431         TOKEN_STRING_INITIALIZER
15432                 (struct cmd_pctype_mapping_get_result,
15433                  mapping, "mapping");
15434
15435 static void
15436 cmd_pctype_mapping_get_parsed(
15437         void *parsed_result,
15438         __attribute__((unused)) struct cmdline *cl,
15439         __attribute__((unused)) void *data)
15440 {
15441         struct cmd_pctype_mapping_get_result *res = parsed_result;
15442         int ret = -ENOTSUP;
15443 #ifdef RTE_LIBRTE_I40E_PMD
15444         struct rte_pmd_i40e_flow_type_mapping
15445                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15446         int i, j, first_pctype;
15447 #endif
15448
15449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15450                 return;
15451
15452 #ifdef RTE_LIBRTE_I40E_PMD
15453         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15454 #endif
15455
15456         switch (ret) {
15457         case 0:
15458                 break;
15459         case -ENODEV:
15460                 printf("invalid port_id %d\n", res->port_id);
15461                 return;
15462         case -ENOTSUP:
15463                 printf("function not implemented\n");
15464                 return;
15465         default:
15466                 printf("programming error: (%s)\n", strerror(-ret));
15467                 return;
15468         }
15469
15470 #ifdef RTE_LIBRTE_I40E_PMD
15471         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15472                 if (mapping[i].pctype != 0ULL) {
15473                         first_pctype = 1;
15474
15475                         printf("pctype: ");
15476                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15477                                 if (mapping[i].pctype & (1ULL << j)) {
15478                                         printf(first_pctype ?
15479                                                "%02d" : ",%02d", j);
15480                                         first_pctype = 0;
15481                                 }
15482                         }
15483                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15484                 }
15485         }
15486 #endif
15487 }
15488
15489 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15490         .f = cmd_pctype_mapping_get_parsed,
15491         .data = NULL,
15492         .help_str = "show port <port_id> pctype mapping",
15493         .tokens = {
15494                 (void *)&cmd_pctype_mapping_get_show,
15495                 (void *)&cmd_pctype_mapping_get_port,
15496                 (void *)&cmd_pctype_mapping_get_port_id,
15497                 (void *)&cmd_pctype_mapping_get_pctype,
15498                 (void *)&cmd_pctype_mapping_get_mapping,
15499                 NULL,
15500         },
15501 };
15502
15503 /* port config pctype mapping update */
15504
15505 /* Common result structure for port config pctype mapping update */
15506 struct cmd_pctype_mapping_update_result {
15507         cmdline_fixed_string_t port;
15508         cmdline_fixed_string_t config;
15509         portid_t port_id;
15510         cmdline_fixed_string_t pctype;
15511         cmdline_fixed_string_t mapping;
15512         cmdline_fixed_string_t update;
15513         cmdline_fixed_string_t pctype_list;
15514         uint16_t flow_type;
15515 };
15516
15517 /* Common CLI fields for pctype mapping update*/
15518 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15519         TOKEN_STRING_INITIALIZER
15520                 (struct cmd_pctype_mapping_update_result,
15521                  port, "port");
15522 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15523         TOKEN_STRING_INITIALIZER
15524                 (struct cmd_pctype_mapping_update_result,
15525                  config, "config");
15526 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15527         TOKEN_NUM_INITIALIZER
15528                 (struct cmd_pctype_mapping_update_result,
15529                  port_id, UINT16);
15530 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15531         TOKEN_STRING_INITIALIZER
15532                 (struct cmd_pctype_mapping_update_result,
15533                  pctype, "pctype");
15534 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15535         TOKEN_STRING_INITIALIZER
15536                 (struct cmd_pctype_mapping_update_result,
15537                  mapping, "mapping");
15538 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15539         TOKEN_STRING_INITIALIZER
15540                 (struct cmd_pctype_mapping_update_result,
15541                  update, "update");
15542 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15543         TOKEN_STRING_INITIALIZER
15544                 (struct cmd_pctype_mapping_update_result,
15545                  pctype_list, NULL);
15546 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15547         TOKEN_NUM_INITIALIZER
15548                 (struct cmd_pctype_mapping_update_result,
15549                  flow_type, UINT16);
15550
15551 static void
15552 cmd_pctype_mapping_update_parsed(
15553         void *parsed_result,
15554         __attribute__((unused)) struct cmdline *cl,
15555         __attribute__((unused)) void *data)
15556 {
15557         struct cmd_pctype_mapping_update_result *res = parsed_result;
15558         int ret = -ENOTSUP;
15559 #ifdef RTE_LIBRTE_I40E_PMD
15560         struct rte_pmd_i40e_flow_type_mapping mapping;
15561         unsigned int i;
15562         unsigned int nb_item;
15563         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15564 #endif
15565
15566         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15567                 return;
15568
15569 #ifdef RTE_LIBRTE_I40E_PMD
15570         nb_item = parse_item_list(res->pctype_list, "pctypes",
15571                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15572         mapping.flow_type = res->flow_type;
15573         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15574                 mapping.pctype |= (1ULL << pctype_list[i]);
15575         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15576                                                 &mapping,
15577                                                 1,
15578                                                 0);
15579 #endif
15580
15581         switch (ret) {
15582         case 0:
15583                 break;
15584         case -EINVAL:
15585                 printf("invalid pctype or flow type\n");
15586                 break;
15587         case -ENODEV:
15588                 printf("invalid port_id %d\n", res->port_id);
15589                 break;
15590         case -ENOTSUP:
15591                 printf("function not implemented\n");
15592                 break;
15593         default:
15594                 printf("programming error: (%s)\n", strerror(-ret));
15595         }
15596 }
15597
15598 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15599         .f = cmd_pctype_mapping_update_parsed,
15600         .data = NULL,
15601         .help_str = "port config <port_id> pctype mapping update"
15602         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15603         .tokens = {
15604                 (void *)&cmd_pctype_mapping_update_port,
15605                 (void *)&cmd_pctype_mapping_update_config,
15606                 (void *)&cmd_pctype_mapping_update_port_id,
15607                 (void *)&cmd_pctype_mapping_update_pctype,
15608                 (void *)&cmd_pctype_mapping_update_mapping,
15609                 (void *)&cmd_pctype_mapping_update_update,
15610                 (void *)&cmd_pctype_mapping_update_pc_type,
15611                 (void *)&cmd_pctype_mapping_update_flow_type,
15612                 NULL,
15613         },
15614 };
15615
15616 /* ptype mapping get */
15617
15618 /* Common result structure for ptype mapping get */
15619 struct cmd_ptype_mapping_get_result {
15620         cmdline_fixed_string_t ptype;
15621         cmdline_fixed_string_t mapping;
15622         cmdline_fixed_string_t get;
15623         portid_t port_id;
15624         uint8_t valid_only;
15625 };
15626
15627 /* Common CLI fields for ptype mapping get */
15628 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15629         TOKEN_STRING_INITIALIZER
15630                 (struct cmd_ptype_mapping_get_result,
15631                  ptype, "ptype");
15632 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15633         TOKEN_STRING_INITIALIZER
15634                 (struct cmd_ptype_mapping_get_result,
15635                  mapping, "mapping");
15636 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15637         TOKEN_STRING_INITIALIZER
15638                 (struct cmd_ptype_mapping_get_result,
15639                  get, "get");
15640 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15641         TOKEN_NUM_INITIALIZER
15642                 (struct cmd_ptype_mapping_get_result,
15643                  port_id, UINT16);
15644 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15645         TOKEN_NUM_INITIALIZER
15646                 (struct cmd_ptype_mapping_get_result,
15647                  valid_only, UINT8);
15648
15649 static void
15650 cmd_ptype_mapping_get_parsed(
15651         void *parsed_result,
15652         __attribute__((unused)) struct cmdline *cl,
15653         __attribute__((unused)) void *data)
15654 {
15655         struct cmd_ptype_mapping_get_result *res = parsed_result;
15656         int ret = -ENOTSUP;
15657 #ifdef RTE_LIBRTE_I40E_PMD
15658         int max_ptype_num = 256;
15659         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15660         uint16_t count;
15661         int i;
15662 #endif
15663
15664         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15665                 return;
15666
15667 #ifdef RTE_LIBRTE_I40E_PMD
15668         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15669                                         mapping,
15670                                         max_ptype_num,
15671                                         &count,
15672                                         res->valid_only);
15673 #endif
15674
15675         switch (ret) {
15676         case 0:
15677                 break;
15678         case -ENODEV:
15679                 printf("invalid port_id %d\n", res->port_id);
15680                 break;
15681         case -ENOTSUP:
15682                 printf("function not implemented\n");
15683                 break;
15684         default:
15685                 printf("programming error: (%s)\n", strerror(-ret));
15686         }
15687
15688 #ifdef RTE_LIBRTE_I40E_PMD
15689         if (!ret) {
15690                 for (i = 0; i < count; i++)
15691                         printf("%3d\t0x%08x\n",
15692                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15693         }
15694 #endif
15695 }
15696
15697 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15698         .f = cmd_ptype_mapping_get_parsed,
15699         .data = NULL,
15700         .help_str = "ptype mapping get <port_id> <valid_only>",
15701         .tokens = {
15702                 (void *)&cmd_ptype_mapping_get_ptype,
15703                 (void *)&cmd_ptype_mapping_get_mapping,
15704                 (void *)&cmd_ptype_mapping_get_get,
15705                 (void *)&cmd_ptype_mapping_get_port_id,
15706                 (void *)&cmd_ptype_mapping_get_valid_only,
15707                 NULL,
15708         },
15709 };
15710
15711 /* ptype mapping replace */
15712
15713 /* Common result structure for ptype mapping replace */
15714 struct cmd_ptype_mapping_replace_result {
15715         cmdline_fixed_string_t ptype;
15716         cmdline_fixed_string_t mapping;
15717         cmdline_fixed_string_t replace;
15718         portid_t port_id;
15719         uint32_t target;
15720         uint8_t mask;
15721         uint32_t pkt_type;
15722 };
15723
15724 /* Common CLI fields for ptype mapping replace */
15725 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15726         TOKEN_STRING_INITIALIZER
15727                 (struct cmd_ptype_mapping_replace_result,
15728                  ptype, "ptype");
15729 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15730         TOKEN_STRING_INITIALIZER
15731                 (struct cmd_ptype_mapping_replace_result,
15732                  mapping, "mapping");
15733 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15734         TOKEN_STRING_INITIALIZER
15735                 (struct cmd_ptype_mapping_replace_result,
15736                  replace, "replace");
15737 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15738         TOKEN_NUM_INITIALIZER
15739                 (struct cmd_ptype_mapping_replace_result,
15740                  port_id, UINT16);
15741 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15742         TOKEN_NUM_INITIALIZER
15743                 (struct cmd_ptype_mapping_replace_result,
15744                  target, UINT32);
15745 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15746         TOKEN_NUM_INITIALIZER
15747                 (struct cmd_ptype_mapping_replace_result,
15748                  mask, UINT8);
15749 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15750         TOKEN_NUM_INITIALIZER
15751                 (struct cmd_ptype_mapping_replace_result,
15752                  pkt_type, UINT32);
15753
15754 static void
15755 cmd_ptype_mapping_replace_parsed(
15756         void *parsed_result,
15757         __attribute__((unused)) struct cmdline *cl,
15758         __attribute__((unused)) void *data)
15759 {
15760         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15761         int ret = -ENOTSUP;
15762
15763         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15764                 return;
15765
15766 #ifdef RTE_LIBRTE_I40E_PMD
15767         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15768                                         res->target,
15769                                         res->mask,
15770                                         res->pkt_type);
15771 #endif
15772
15773         switch (ret) {
15774         case 0:
15775                 break;
15776         case -EINVAL:
15777                 printf("invalid ptype 0x%8x or 0x%8x\n",
15778                                 res->target, res->pkt_type);
15779                 break;
15780         case -ENODEV:
15781                 printf("invalid port_id %d\n", res->port_id);
15782                 break;
15783         case -ENOTSUP:
15784                 printf("function not implemented\n");
15785                 break;
15786         default:
15787                 printf("programming error: (%s)\n", strerror(-ret));
15788         }
15789 }
15790
15791 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15792         .f = cmd_ptype_mapping_replace_parsed,
15793         .data = NULL,
15794         .help_str =
15795                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15796         .tokens = {
15797                 (void *)&cmd_ptype_mapping_replace_ptype,
15798                 (void *)&cmd_ptype_mapping_replace_mapping,
15799                 (void *)&cmd_ptype_mapping_replace_replace,
15800                 (void *)&cmd_ptype_mapping_replace_port_id,
15801                 (void *)&cmd_ptype_mapping_replace_target,
15802                 (void *)&cmd_ptype_mapping_replace_mask,
15803                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15804                 NULL,
15805         },
15806 };
15807
15808 /* ptype mapping reset */
15809
15810 /* Common result structure for ptype mapping reset */
15811 struct cmd_ptype_mapping_reset_result {
15812         cmdline_fixed_string_t ptype;
15813         cmdline_fixed_string_t mapping;
15814         cmdline_fixed_string_t reset;
15815         portid_t port_id;
15816 };
15817
15818 /* Common CLI fields for ptype mapping reset*/
15819 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15820         TOKEN_STRING_INITIALIZER
15821                 (struct cmd_ptype_mapping_reset_result,
15822                  ptype, "ptype");
15823 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15824         TOKEN_STRING_INITIALIZER
15825                 (struct cmd_ptype_mapping_reset_result,
15826                  mapping, "mapping");
15827 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15828         TOKEN_STRING_INITIALIZER
15829                 (struct cmd_ptype_mapping_reset_result,
15830                  reset, "reset");
15831 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15832         TOKEN_NUM_INITIALIZER
15833                 (struct cmd_ptype_mapping_reset_result,
15834                  port_id, UINT16);
15835
15836 static void
15837 cmd_ptype_mapping_reset_parsed(
15838         void *parsed_result,
15839         __attribute__((unused)) struct cmdline *cl,
15840         __attribute__((unused)) void *data)
15841 {
15842         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15843         int ret = -ENOTSUP;
15844
15845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15846                 return;
15847
15848 #ifdef RTE_LIBRTE_I40E_PMD
15849         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15850 #endif
15851
15852         switch (ret) {
15853         case 0:
15854                 break;
15855         case -ENODEV:
15856                 printf("invalid port_id %d\n", res->port_id);
15857                 break;
15858         case -ENOTSUP:
15859                 printf("function not implemented\n");
15860                 break;
15861         default:
15862                 printf("programming error: (%s)\n", strerror(-ret));
15863         }
15864 }
15865
15866 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15867         .f = cmd_ptype_mapping_reset_parsed,
15868         .data = NULL,
15869         .help_str = "ptype mapping reset <port_id>",
15870         .tokens = {
15871                 (void *)&cmd_ptype_mapping_reset_ptype,
15872                 (void *)&cmd_ptype_mapping_reset_mapping,
15873                 (void *)&cmd_ptype_mapping_reset_reset,
15874                 (void *)&cmd_ptype_mapping_reset_port_id,
15875                 NULL,
15876         },
15877 };
15878
15879 /* ptype mapping update */
15880
15881 /* Common result structure for ptype mapping update */
15882 struct cmd_ptype_mapping_update_result {
15883         cmdline_fixed_string_t ptype;
15884         cmdline_fixed_string_t mapping;
15885         cmdline_fixed_string_t reset;
15886         portid_t port_id;
15887         uint8_t hw_ptype;
15888         uint32_t sw_ptype;
15889 };
15890
15891 /* Common CLI fields for ptype mapping update*/
15892 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15893         TOKEN_STRING_INITIALIZER
15894                 (struct cmd_ptype_mapping_update_result,
15895                  ptype, "ptype");
15896 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15897         TOKEN_STRING_INITIALIZER
15898                 (struct cmd_ptype_mapping_update_result,
15899                  mapping, "mapping");
15900 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15901         TOKEN_STRING_INITIALIZER
15902                 (struct cmd_ptype_mapping_update_result,
15903                  reset, "update");
15904 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15905         TOKEN_NUM_INITIALIZER
15906                 (struct cmd_ptype_mapping_update_result,
15907                  port_id, UINT16);
15908 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15909         TOKEN_NUM_INITIALIZER
15910                 (struct cmd_ptype_mapping_update_result,
15911                  hw_ptype, UINT8);
15912 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15913         TOKEN_NUM_INITIALIZER
15914                 (struct cmd_ptype_mapping_update_result,
15915                  sw_ptype, UINT32);
15916
15917 static void
15918 cmd_ptype_mapping_update_parsed(
15919         void *parsed_result,
15920         __attribute__((unused)) struct cmdline *cl,
15921         __attribute__((unused)) void *data)
15922 {
15923         struct cmd_ptype_mapping_update_result *res = parsed_result;
15924         int ret = -ENOTSUP;
15925 #ifdef RTE_LIBRTE_I40E_PMD
15926         struct rte_pmd_i40e_ptype_mapping mapping;
15927 #endif
15928         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15929                 return;
15930
15931 #ifdef RTE_LIBRTE_I40E_PMD
15932         mapping.hw_ptype = res->hw_ptype;
15933         mapping.sw_ptype = res->sw_ptype;
15934         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15935                                                 &mapping,
15936                                                 1,
15937                                                 0);
15938 #endif
15939
15940         switch (ret) {
15941         case 0:
15942                 break;
15943         case -EINVAL:
15944                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15945                 break;
15946         case -ENODEV:
15947                 printf("invalid port_id %d\n", res->port_id);
15948                 break;
15949         case -ENOTSUP:
15950                 printf("function not implemented\n");
15951                 break;
15952         default:
15953                 printf("programming error: (%s)\n", strerror(-ret));
15954         }
15955 }
15956
15957 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15958         .f = cmd_ptype_mapping_update_parsed,
15959         .data = NULL,
15960         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15961         .tokens = {
15962                 (void *)&cmd_ptype_mapping_update_ptype,
15963                 (void *)&cmd_ptype_mapping_update_mapping,
15964                 (void *)&cmd_ptype_mapping_update_update,
15965                 (void *)&cmd_ptype_mapping_update_port_id,
15966                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15967                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15968                 NULL,
15969         },
15970 };
15971
15972 /* Common result structure for file commands */
15973 struct cmd_cmdfile_result {
15974         cmdline_fixed_string_t load;
15975         cmdline_fixed_string_t filename;
15976 };
15977
15978 /* Common CLI fields for file commands */
15979 cmdline_parse_token_string_t cmd_load_cmdfile =
15980         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15981 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15982         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15983
15984 static void
15985 cmd_load_from_file_parsed(
15986         void *parsed_result,
15987         __attribute__((unused)) struct cmdline *cl,
15988         __attribute__((unused)) void *data)
15989 {
15990         struct cmd_cmdfile_result *res = parsed_result;
15991
15992         cmdline_read_from_file(res->filename);
15993 }
15994
15995 cmdline_parse_inst_t cmd_load_from_file = {
15996         .f = cmd_load_from_file_parsed,
15997         .data = NULL,
15998         .help_str = "load <filename>",
15999         .tokens = {
16000                 (void *)&cmd_load_cmdfile,
16001                 (void *)&cmd_load_cmdfile_filename,
16002                 NULL,
16003         },
16004 };
16005
16006 /* ******************************************************************************** */
16007
16008 /* list of instructions */
16009 cmdline_parse_ctx_t main_ctx[] = {
16010         (cmdline_parse_inst_t *)&cmd_help_brief,
16011         (cmdline_parse_inst_t *)&cmd_help_long,
16012         (cmdline_parse_inst_t *)&cmd_quit,
16013         (cmdline_parse_inst_t *)&cmd_load_from_file,
16014         (cmdline_parse_inst_t *)&cmd_showport,
16015         (cmdline_parse_inst_t *)&cmd_showqueue,
16016         (cmdline_parse_inst_t *)&cmd_showportall,
16017         (cmdline_parse_inst_t *)&cmd_showcfg,
16018         (cmdline_parse_inst_t *)&cmd_start,
16019         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16020         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16021         (cmdline_parse_inst_t *)&cmd_set_link_up,
16022         (cmdline_parse_inst_t *)&cmd_set_link_down,
16023         (cmdline_parse_inst_t *)&cmd_reset,
16024         (cmdline_parse_inst_t *)&cmd_set_numbers,
16025         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16026         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16027         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16028         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16029         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16030         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16031         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16032         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16033         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16034         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16035         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16036         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16037         (cmdline_parse_inst_t *)&cmd_set_link_check,
16038         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16039         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16040         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16041         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16042 #ifdef RTE_LIBRTE_PMD_BOND
16043         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16044         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16045         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16046         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16047         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16048         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16049         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16050         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16051         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16052         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16053         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16054 #endif
16055         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16056         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16057         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16058         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16059         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16060         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16061         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16062         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16063         (cmdline_parse_inst_t *)&cmd_csum_set,
16064         (cmdline_parse_inst_t *)&cmd_csum_show,
16065         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16066         (cmdline_parse_inst_t *)&cmd_tso_set,
16067         (cmdline_parse_inst_t *)&cmd_tso_show,
16068         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16069         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16070         (cmdline_parse_inst_t *)&cmd_gro_enable,
16071         (cmdline_parse_inst_t *)&cmd_gro_flush,
16072         (cmdline_parse_inst_t *)&cmd_gro_show,
16073         (cmdline_parse_inst_t *)&cmd_gso_enable,
16074         (cmdline_parse_inst_t *)&cmd_gso_size,
16075         (cmdline_parse_inst_t *)&cmd_gso_show,
16076         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16077         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16078         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16079         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16080         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16081         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16082         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16083         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16084         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16085         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16086         (cmdline_parse_inst_t *)&cmd_config_dcb,
16087         (cmdline_parse_inst_t *)&cmd_read_reg,
16088         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16089         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16090         (cmdline_parse_inst_t *)&cmd_write_reg,
16091         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16092         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16093         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16094         (cmdline_parse_inst_t *)&cmd_stop,
16095         (cmdline_parse_inst_t *)&cmd_mac_addr,
16096         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16097         (cmdline_parse_inst_t *)&cmd_set_qmap,
16098         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16099         (cmdline_parse_inst_t *)&cmd_operate_port,
16100         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16101         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16102         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16103         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16104         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16105         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16106         (cmdline_parse_inst_t *)&cmd_config_mtu,
16107         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16108         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16109         (cmdline_parse_inst_t *)&cmd_config_rss,
16110         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16111         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16112         (cmdline_parse_inst_t *)&cmd_showport_reta,
16113         (cmdline_parse_inst_t *)&cmd_config_burst,
16114         (cmdline_parse_inst_t *)&cmd_config_thresh,
16115         (cmdline_parse_inst_t *)&cmd_config_threshold,
16116         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16117         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16118         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16119         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16120         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16121         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16122         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16123         (cmdline_parse_inst_t *)&cmd_global_config,
16124         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16125         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16126         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16127         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16128         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16129         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16130         (cmdline_parse_inst_t *)&cmd_dump,
16131         (cmdline_parse_inst_t *)&cmd_dump_one,
16132         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16133         (cmdline_parse_inst_t *)&cmd_syn_filter,
16134         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16135         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16136         (cmdline_parse_inst_t *)&cmd_flex_filter,
16137         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16138         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16139         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16140         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16141         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16142         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16143         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16144         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16145         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16146         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16147         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16148         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16149         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16150         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16151         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16152         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16153         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16154         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16155         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16156         (cmdline_parse_inst_t *)&cmd_flow,
16157         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16158         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16159         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16160         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16161         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16162         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16163         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16164         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16165         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16166         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16167         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16168         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16169         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16170         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16171         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16172         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16173         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16174         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16175         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16176         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16177         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16178         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16179         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16180         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16181         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16182         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16183         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16184         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16185         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16186         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16187         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16188         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16189         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16190         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16191         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16192         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16193         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16194         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16195         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16196         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16197         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16198         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16199         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16200         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16201         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16202         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16203         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16204         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16205         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16206 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16207         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16208 #endif
16209         (cmdline_parse_inst_t *)&cmd_ddp_add,
16210         (cmdline_parse_inst_t *)&cmd_ddp_del,
16211         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16212         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16213         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16214         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16215         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16216         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16217         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16218         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16219         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16220         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16221
16222         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16223         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16224         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16225         (cmdline_parse_inst_t *)&cmd_queue_region,
16226         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16227         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16228         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16229         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16230         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16231         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16232         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16233         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16234         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16235         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16236         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16237         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16238         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16239         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16240         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16241         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16242         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16243         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16244         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16245         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16246         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16247         NULL,
16248 };
16249
16250 /* read cmdline commands from file */
16251 void
16252 cmdline_read_from_file(const char *filename)
16253 {
16254         struct cmdline *cl;
16255
16256         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16257         if (cl == NULL) {
16258                 printf("Failed to create file based cmdline context: %s\n",
16259                        filename);
16260                 return;
16261         }
16262
16263         cmdline_interact(cl);
16264         cmdline_quit(cl);
16265
16266         cmdline_free(cl);
16267
16268         printf("Read CLI commands from %s\n", filename);
16269 }
16270
16271 /* prompt function, called from main on MASTER lcore */
16272 void
16273 prompt(void)
16274 {
16275         /* initialize non-constant commands */
16276         cmd_set_fwd_mode_init();
16277         cmd_set_fwd_retry_mode_init();
16278
16279         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16280         if (testpmd_cl == NULL)
16281                 return;
16282         cmdline_interact(testpmd_cl);
16283         cmdline_stdin_exit(testpmd_cl);
16284 }
16285
16286 void
16287 prompt_exit(void)
16288 {
16289         if (testpmd_cl != NULL)
16290                 cmdline_quit(testpmd_cl);
16291 }
16292
16293 static void
16294 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16295 {
16296         if (id == (portid_t)RTE_PORT_ALL) {
16297                 portid_t pid;
16298
16299                 RTE_ETH_FOREACH_DEV(pid) {
16300                         /* check if need_reconfig has been set to 1 */
16301                         if (ports[pid].need_reconfig == 0)
16302                                 ports[pid].need_reconfig = dev;
16303                         /* check if need_reconfig_queues has been set to 1 */
16304                         if (ports[pid].need_reconfig_queues == 0)
16305                                 ports[pid].need_reconfig_queues = queue;
16306                 }
16307         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16308                 /* check if need_reconfig has been set to 1 */
16309                 if (ports[id].need_reconfig == 0)
16310                         ports[id].need_reconfig = dev;
16311                 /* check if need_reconfig_queues has been set to 1 */
16312                 if (ports[id].need_reconfig_queues == 0)
16313                         ports[id].need_reconfig_queues = queue;
16314         }
16315 }