app/testpmd: fix invalid Tx queue number setting
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_DPAA_PMD
93 #include <rte_pmd_dpaa.h>
94 #endif
95 #ifdef RTE_LIBRTE_IXGBE_PMD
96 #include <rte_pmd_ixgbe.h>
97 #endif
98 #ifdef RTE_LIBRTE_I40E_PMD
99 #include <rte_pmd_i40e.h>
100 #endif
101 #ifdef RTE_LIBRTE_BNXT_PMD
102 #include <rte_pmd_bnxt.h>
103 #endif
104 #include "testpmd.h"
105 #include "cmdline_mtr.h"
106 #include "cmdline_tm.h"
107
108 static struct cmdline *testpmd_cl;
109
110 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
111
112 /* *** Help command with introduction. *** */
113 struct cmd_help_brief_result {
114         cmdline_fixed_string_t help;
115 };
116
117 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
118                                   struct cmdline *cl,
119                                   __attribute__((unused)) void *data)
120 {
121         cmdline_printf(
122                 cl,
123                 "\n"
124                 "Help is available for the following sections:\n\n"
125                 "    help control    : Start and stop forwarding.\n"
126                 "    help display    : Displaying port, stats and config "
127                 "information.\n"
128                 "    help config     : Configuration information.\n"
129                 "    help ports      : Configuring ports.\n"
130                 "    help registers  : Reading and setting port registers.\n"
131                 "    help filters    : Filters configuration help.\n"
132                 "    help all        : All of the above sections.\n\n"
133         );
134
135 }
136
137 cmdline_parse_token_string_t cmd_help_brief_help =
138         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
139
140 cmdline_parse_inst_t cmd_help_brief = {
141         .f = cmd_help_brief_parsed,
142         .data = NULL,
143         .help_str = "help: Show help",
144         .tokens = {
145                 (void *)&cmd_help_brief_help,
146                 NULL,
147         },
148 };
149
150 /* *** Help command with help sections. *** */
151 struct cmd_help_long_result {
152         cmdline_fixed_string_t help;
153         cmdline_fixed_string_t section;
154 };
155
156 static void cmd_help_long_parsed(void *parsed_result,
157                                  struct cmdline *cl,
158                                  __attribute__((unused)) void *data)
159 {
160         int show_all = 0;
161         struct cmd_help_long_result *res = parsed_result;
162
163         if (!strcmp(res->section, "all"))
164                 show_all = 1;
165
166         if (show_all || !strcmp(res->section, "control")) {
167
168                 cmdline_printf(
169                         cl,
170                         "\n"
171                         "Control forwarding:\n"
172                         "-------------------\n\n"
173
174                         "start\n"
175                         "    Start packet forwarding with current configuration.\n\n"
176
177                         "start tx_first\n"
178                         "    Start packet forwarding with current config"
179                         " after sending one burst of packets.\n\n"
180
181                         "stop\n"
182                         "    Stop packet forwarding, and display accumulated"
183                         " statistics.\n\n"
184
185                         "quit\n"
186                         "    Quit to prompt.\n\n"
187                 );
188         }
189
190         if (show_all || !strcmp(res->section, "display")) {
191
192                 cmdline_printf(
193                         cl,
194                         "\n"
195                         "Display:\n"
196                         "--------\n\n"
197
198                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
199                         "    Display information for port_id, or all.\n\n"
200
201                         "show port X rss reta (size) (mask0,mask1,...)\n"
202                         "    Display the rss redirection table entry indicated"
203                         " by masks on port X. size is used to indicate the"
204                         " hardware supported reta size\n\n"
205
206                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
207                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
208                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
209                         "    Display the RSS hash functions and RSS hash key"
210                         " of port X\n\n"
211
212                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
213                         "    Clear information for port_id, or all.\n\n"
214
215                         "show (rxq|txq) info (port_id) (queue_id)\n"
216                         "    Display information for configured RX/TX queue.\n\n"
217
218                         "show config (rxtx|cores|fwd|txpkts)\n"
219                         "    Display the given configuration.\n\n"
220
221                         "read rxd (port_id) (queue_id) (rxd_id)\n"
222                         "    Display an RX descriptor of a port RX queue.\n\n"
223
224                         "read txd (port_id) (queue_id) (txd_id)\n"
225                         "    Display a TX descriptor of a port TX queue.\n\n"
226
227                         "ddp get list (port_id)\n"
228                         "    Get ddp profile info list\n\n"
229
230                         "ddp get info (profile_path)\n"
231                         "    Get ddp profile information.\n\n"
232
233                         "show vf stats (port_id) (vf_id)\n"
234                         "    Display a VF's statistics.\n\n"
235
236                         "clear vf stats (port_id) (vf_id)\n"
237                         "    Reset a VF's statistics.\n\n"
238
239                         "show port (port_id) pctype mapping\n"
240                         "    Get flow ptype to pctype mapping on a port\n\n"
241
242                         "show port meter stats (port_id) (meter_id) (clear)\n"
243                         "    Get meter stats on a port\n\n"
244                         "show port tm cap (port_id)\n"
245                         "       Display the port TM capability.\n\n"
246
247                         "show port tm level cap (port_id) (level_id)\n"
248                         "       Display the port TM hierarchical level capability.\n\n"
249
250                         "show port tm node cap (port_id) (node_id)\n"
251                         "       Display the port TM node capability.\n\n"
252
253                         "show port tm node type (port_id) (node_id)\n"
254                         "       Display the port TM node type.\n\n"
255
256                         "show port tm node stats (port_id) (node_id) (clear)\n"
257                         "       Display the port TM node stats.\n\n"
258
259                 );
260         }
261
262         if (show_all || !strcmp(res->section, "config")) {
263                 cmdline_printf(
264                         cl,
265                         "\n"
266                         "Configuration:\n"
267                         "--------------\n"
268                         "Configuration changes only become active when"
269                         " forwarding is started/restarted.\n\n"
270
271                         "set default\n"
272                         "    Reset forwarding to the default configuration.\n\n"
273
274                         "set verbose (level)\n"
275                         "    Set the debug verbosity level X.\n\n"
276
277                         "set nbport (num)\n"
278                         "    Set number of ports.\n\n"
279
280                         "set nbcore (num)\n"
281                         "    Set number of cores.\n\n"
282
283                         "set coremask (mask)\n"
284                         "    Set the forwarding cores hexadecimal mask.\n\n"
285
286                         "set portmask (mask)\n"
287                         "    Set the forwarding ports hexadecimal mask.\n\n"
288
289                         "set burst (num)\n"
290                         "    Set number of packets per burst.\n\n"
291
292                         "set burst tx delay (microseconds) retry (num)\n"
293                         "    Set the transmit delay time and number of retries,"
294                         " effective when retry is enabled.\n\n"
295
296                         "set txpkts (x[,y]*)\n"
297                         "    Set the length of each segment of TXONLY"
298                         " and optionally CSUM packets.\n\n"
299
300                         "set txsplit (off|on|rand)\n"
301                         "    Set the split policy for the TX packets."
302                         " Right now only applicable for CSUM and TXONLY"
303                         " modes\n\n"
304
305                         "set corelist (x[,y]*)\n"
306                         "    Set the list of forwarding cores.\n\n"
307
308                         "set portlist (x[,y]*)\n"
309                         "    Set the list of forwarding ports.\n\n"
310
311                         "set tx loopback (port_id) (on|off)\n"
312                         "    Enable or disable tx loopback.\n\n"
313
314                         "set all queues drop (port_id) (on|off)\n"
315                         "    Set drop enable bit for all queues.\n\n"
316
317                         "set vf split drop (port_id) (vf_id) (on|off)\n"
318                         "    Set split drop enable bit for a VF from the PF.\n\n"
319
320                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
321                         "    Set MAC antispoof for a VF from the PF.\n\n"
322
323                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
324                         "    Enable MACsec offload.\n\n"
325
326                         "set macsec offload (port_id) off\n"
327                         "    Disable MACsec offload.\n\n"
328
329                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
330                         "    Configure MACsec secure connection (SC).\n\n"
331
332                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
333                         "    Configure MACsec secure association (SA).\n\n"
334
335                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
336                         "    Set VF broadcast for a VF from the PF.\n\n"
337
338                         "vlan set strip (on|off) (port_id)\n"
339                         "    Set the VLAN strip on a port.\n\n"
340
341                         "vlan set stripq (on|off) (port_id,queue_id)\n"
342                         "    Set the VLAN strip for a queue on a port.\n\n"
343
344                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
345                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
346
347                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
348                         "    Set VLAN insert for a VF from the PF.\n\n"
349
350                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN antispoof for a VF from the PF.\n\n"
352
353                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
354                         "    Set VLAN tag for a VF from the PF.\n\n"
355
356                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
357                         "    Set a VF's max bandwidth(Mbps).\n\n"
358
359                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
360                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
361
362                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
363                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
364
365                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
366                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
367
368                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
369                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
370
371                         "vlan set filter (on|off) (port_id)\n"
372                         "    Set the VLAN filter on a port.\n\n"
373
374                         "vlan set qinq (on|off) (port_id)\n"
375                         "    Set the VLAN QinQ (extended queue in queue)"
376                         " on a port.\n\n"
377
378                         "vlan set (inner|outer) tpid (value) (port_id)\n"
379                         "    Set the VLAN TPID for Packet Filtering on"
380                         " a port\n\n"
381
382                         "rx_vlan add (vlan_id|all) (port_id)\n"
383                         "    Add a vlan_id, or all identifiers, to the set"
384                         " of VLAN identifiers filtered by port_id.\n\n"
385
386                         "rx_vlan rm (vlan_id|all) (port_id)\n"
387                         "    Remove a vlan_id, or all identifiers, from the set"
388                         " of VLAN identifiers filtered by port_id.\n\n"
389
390                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
391                         "    Add a vlan_id, to the set of VLAN identifiers"
392                         "filtered for VF(s) from port_id.\n\n"
393
394                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
395                         "    Remove a vlan_id, to the set of VLAN identifiers"
396                         "filtered for VF(s) from port_id.\n\n"
397
398                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
399                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
400                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
401                         "   add a tunnel filter of a port.\n\n"
402
403                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
404                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
405                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
406                         "   remove a tunnel filter of a port.\n\n"
407
408                         "rx_vxlan_port add (udp_port) (port_id)\n"
409                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "rx_vxlan_port rm (udp_port) (port_id)\n"
412                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
415                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
416                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
417
418                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
419                         "    Set port based TX VLAN insertion.\n\n"
420
421                         "tx_vlan reset (port_id)\n"
422                         "    Disable hardware insertion of a VLAN header in"
423                         " packets sent on a port.\n\n"
424
425                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
426                         "    Select hardware or software calculation of the"
427                         " checksum when transmitting a packet using the"
428                         " csum forward engine.\n"
429                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
430                         "    outer-ip concerns the outer IP layer in"
431                         " case the packet is recognized as a tunnel packet by"
432                         " the forward engine (vxlan, gre and ipip are supported)\n"
433                         "    Please check the NIC datasheet for HW limits.\n\n"
434
435                         "csum parse-tunnel (on|off) (tx_port_id)\n"
436                         "    If disabled, treat tunnel packets as non-tunneled"
437                         " packets (treat inner headers as payload). The port\n"
438                         "    argument is the port used for TX in csum forward"
439                         " engine.\n\n"
440
441                         "csum show (port_id)\n"
442                         "    Display tx checksum offload configuration\n\n"
443
444                         "tso set (segsize) (portid)\n"
445                         "    Enable TCP Segmentation Offload in csum forward"
446                         " engine.\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "tso show (portid)"
450                         "    Display the status of TCP Segmentation Offload.\n\n"
451
452                         "set port (port_id) gro on|off\n"
453                         "    Enable or disable Generic Receive Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "show port (port_id) gro\n"
457                         "    Display GRO configuration.\n\n"
458
459                         "set gro flush (cycles)\n"
460                         "    Set the cycle to flush GROed packets from"
461                         " reassembly tables.\n\n"
462
463                         "set port (port_id) gso (on|off)"
464                         "    Enable or disable Generic Segmentation Offload in"
465                         " csum forwarding engine.\n\n"
466
467                         "set gso segsz (length)\n"
468                         "    Set max packet length for output GSO segments,"
469                         " including packet header and payload.\n\n"
470
471                         "show port (port_id) gso\n"
472                         "    Show GSO configuration.\n\n"
473
474                         "set fwd (%s)\n"
475                         "    Set packet forwarding mode.\n\n"
476
477                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Add a MAC address on port_id.\n\n"
479
480                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Remove a MAC address from port_id.\n\n"
482
483                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
484                         "    Set the default MAC address for port_id.\n\n"
485
486                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
487                         "    Add a MAC address for a VF on the port.\n\n"
488
489                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
490                         "    Set the MAC address for a VF from the PF.\n\n"
491
492                         "set eth-peer (port_id) (peer_addr)\n"
493                         "    set the peer address for certain port.\n\n"
494
495                         "set port (port_id) uta (mac_address|all) (on|off)\n"
496                         "    Add/Remove a or all unicast hash filter(s)"
497                         "from port X.\n\n"
498
499                         "set promisc (port_id|all) (on|off)\n"
500                         "    Set the promiscuous mode on port_id, or all.\n\n"
501
502                         "set allmulti (port_id|all) (on|off)\n"
503                         "    Set the allmulti mode on port_id, or all.\n\n"
504
505                         "set vf promisc (port_id) (vf_id) (on|off)\n"
506                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
507
508                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
509                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
510
511                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
513                         " (on|off) autoneg (on|off) (port_id)\n"
514                         "set flow_ctrl rx (on|off) (portid)\n"
515                         "set flow_ctrl tx (on|off) (portid)\n"
516                         "set flow_ctrl high_water (high_water) (portid)\n"
517                         "set flow_ctrl low_water (low_water) (portid)\n"
518                         "set flow_ctrl pause_time (pause_time) (portid)\n"
519                         "set flow_ctrl send_xon (send_xon) (portid)\n"
520                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
521                         "set flow_ctrl autoneg (on|off) (port_id)\n"
522                         "    Set the link flow control parameter on a port.\n\n"
523
524                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
525                         " (low_water) (pause_time) (priority) (port_id)\n"
526                         "    Set the priority flow control parameter on a"
527                         " port.\n\n"
528
529                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
530                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
531                         " queue on port.\n"
532                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
533                         " on port 0 to mapping 5.\n\n"
534
535                         "set xstats-hide-zero on|off\n"
536                         "    Set the option to hide the zero values"
537                         " for xstats display.\n"
538
539                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
540                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
541
542                         "set port (port_id) vf (vf_id) (mac_addr)"
543                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
544                         "   Add/Remove unicast or multicast MAC addr filter"
545                         " for a VF.\n\n"
546
547                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
548                         "|MPE) (on|off)\n"
549                         "    AUPE:accepts untagged VLAN;"
550                         "ROPE:accept unicast hash\n\n"
551                         "    BAM:accepts broadcast packets;"
552                         "MPE:accepts all multicast packets\n\n"
553                         "    Enable/Disable a VF receive mode of a port\n\n"
554
555                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
556                         "    Set rate limit for a queue of a port\n\n"
557
558                         "set port (port_id) vf (vf_id) rate (rate_num) "
559                         "queue_mask (queue_mask_value)\n"
560                         "    Set rate limit for queues in VF of a port\n\n"
561
562                         "set port (port_id) mirror-rule (rule_id)"
563                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
564                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
565                         "   Set pool or vlan type mirror rule on a port.\n"
566                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
567                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
568                         " to pool 0.\n\n"
569
570                         "set port (port_id) mirror-rule (rule_id)"
571                         " (uplink-mirror|downlink-mirror) dst-pool"
572                         " (pool_id) (on|off)\n"
573                         "   Set uplink or downlink type mirror rule on a port.\n"
574                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
575                         " 0 on' enable mirror income traffic to pool 0.\n\n"
576
577                         "reset port (port_id) mirror-rule (rule_id)\n"
578                         "   Reset a mirror rule.\n\n"
579
580                         "set flush_rx (on|off)\n"
581                         "   Flush (default) or don't flush RX streams before"
582                         " forwarding. Mainly used with PCAP drivers.\n\n"
583
584                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
585                         "   Set the bypass mode for the lowest port on bypass enabled"
586                         " NIC.\n\n"
587
588                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
589                         "mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the event required to initiate specified bypass mode for"
591                         " the lowest port on a bypass enabled NIC where:\n"
592                         "       timeout   = enable bypass after watchdog timeout.\n"
593                         "       os_on     = enable bypass when OS/board is powered on.\n"
594                         "       os_off    = enable bypass when OS/board is powered off.\n"
595                         "       power_on  = enable bypass when power supply is turned on.\n"
596                         "       power_off = enable bypass when power supply is turned off."
597                         "\n\n"
598
599                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
600                         "   Set the bypass watchdog timeout to 'n' seconds"
601                         " where 0 = instant.\n\n"
602
603                         "show bypass config (port_id)\n"
604                         "   Show the bypass configuration for a bypass enabled NIC"
605                         " using the lowest port on the NIC.\n\n"
606
607 #ifdef RTE_LIBRTE_PMD_BOND
608                         "create bonded device (mode) (socket)\n"
609                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
610
611                         "add bonding slave (slave_id) (port_id)\n"
612                         "       Add a slave device to a bonded device.\n\n"
613
614                         "remove bonding slave (slave_id) (port_id)\n"
615                         "       Remove a slave device from a bonded device.\n\n"
616
617                         "set bonding mode (value) (port_id)\n"
618                         "       Set the bonding mode on a bonded device.\n\n"
619
620                         "set bonding primary (slave_id) (port_id)\n"
621                         "       Set the primary slave for a bonded device.\n\n"
622
623                         "show bonding config (port_id)\n"
624                         "       Show the bonding config for port_id.\n\n"
625
626                         "set bonding mac_addr (port_id) (address)\n"
627                         "       Set the MAC address of a bonded device.\n\n"
628
629                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
630                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
631
632                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
633                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
634
635                         "set bonding mon_period (port_id) (value)\n"
636                         "       Set the bonding link status monitoring polling period in ms.\n\n"
637
638                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
639                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
640
641 #endif
642                         "set link-up port (port_id)\n"
643                         "       Set link up for a port.\n\n"
644
645                         "set link-down port (port_id)\n"
646                         "       Set link down for a port.\n\n"
647
648                         "E-tag set insertion on port-tag-id (value)"
649                         " port (port_id) vf (vf_id)\n"
650                         "    Enable E-tag insertion for a VF on a port\n\n"
651
652                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
653                         "    Disable E-tag insertion for a VF on a port\n\n"
654
655                         "E-tag set stripping (on|off) port (port_id)\n"
656                         "    Enable/disable E-tag stripping on a port\n\n"
657
658                         "E-tag set forwarding (on|off) port (port_id)\n"
659                         "    Enable/disable E-tag based forwarding"
660                         " on a port\n\n"
661
662                         "E-tag set filter add e-tag-id (value) dst-pool"
663                         " (pool_id) port (port_id)\n"
664                         "    Add an E-tag forwarding filter on a port\n\n"
665
666                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
667                         "    Delete an E-tag forwarding filter on a port\n\n"
668
669 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
670                         "set port tm hierarchy default (port_id)\n"
671                         "       Set default traffic Management hierarchy on a port\n\n"
672
673 #endif
674                         "ddp add (port_id) (profile_path[,output_path])\n"
675                         "    Load a profile package on a port\n\n"
676
677                         "ddp del (port_id) (profile_path)\n"
678                         "    Delete a profile package from a port\n\n"
679
680                         "ptype mapping get (port_id) (valid_only)\n"
681                         "    Get ptype mapping on a port\n\n"
682
683                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
684                         "    Replace target with the pkt_type in ptype mapping\n\n"
685
686                         "ptype mapping reset (port_id)\n"
687                         "    Reset ptype mapping on a port\n\n"
688
689                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
690                         "    Update a ptype mapping item on a port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "queue_start_index (value) queue_num (value)\n"
694                         "    Set a queue region on a port\n\n"
695
696                         "set port (port_id) queue-region region_id (value) "
697                         "flowtype (value)\n"
698                         "    Set a flowtype region index on a port\n\n"
699
700                         "set port (port_id) queue-region UP (value) region_id (value)\n"
701                         "    Set the mapping of User Priority to "
702                         "queue region on a port\n\n"
703
704                         "set port (port_id) queue-region flush (on|off)\n"
705                         "    flush all queue region related configuration\n\n"
706
707                         "show port meter cap (port_id)\n"
708                         "    Show port meter capability information\n\n"
709
710                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
711                         "    meter profile add - srtcm rfc 2697\n\n"
712
713                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
714                         "    meter profile add - trtcm rfc 2698\n\n"
715
716                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
717                         "    meter profile add - trtcm rfc 4115\n\n"
718
719                         "del port meter profile (port_id) (profile_id)\n"
720                         "    meter profile delete\n\n"
721
722                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
723                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
724                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
725                         "(dscp_tbl_entry63)]\n"
726                         "    meter create\n\n"
727
728                         "enable port meter (port_id) (mtr_id)\n"
729                         "    meter enable\n\n"
730
731                         "disable port meter (port_id) (mtr_id)\n"
732                         "    meter disable\n\n"
733
734                         "del port meter (port_id) (mtr_id)\n"
735                         "    meter delete\n\n"
736
737                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
738                         "    meter update meter profile\n\n"
739
740                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
741                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
742                         "    update meter dscp table entries\n\n"
743
744                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
745                         "(action0) [(action1) (action2)]\n"
746                         "    meter update policer action\n\n"
747
748                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
749                         "    meter update stats\n\n"
750
751                         "show port (port_id) queue-region\n"
752                         "    show all queue region related configuration info\n\n"
753
754                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
755                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
756                         "       Add port tm node private shaper profile.\n\n"
757
758                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
759                         "       Delete port tm node private shaper profile.\n\n"
760
761                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
762                         " (shaper_profile_id)\n"
763                         "       Add/update port tm node shared shaper.\n\n"
764
765                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
766                         "       Delete port tm node shared shaper.\n\n"
767
768                         "set port tm node shaper profile (port_id) (node_id)"
769                         " (shaper_profile_id)\n"
770                         "       Set port tm node shaper profile.\n\n"
771
772                         "add port tm node wred profile (port_id) (wred_profile_id)"
773                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
774                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
775                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
776                         "       Add port tm node wred profile.\n\n"
777
778                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
779                         "       Delete port tm node wred profile.\n\n"
780
781                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm nonleaf node.\n\n"
786
787                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
788                         " (priority) (weight) (level_id) (shaper_profile_id)"
789                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
790                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
791                         "       Add port tm leaf node.\n\n"
792
793                         "del port tm node (port_id) (node_id)\n"
794                         "       Delete port tm node.\n\n"
795
796                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
797                         " (priority) (weight)\n"
798                         "       Set port tm node parent.\n\n"
799
800                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
801                         "       Commit tm hierarchy.\n\n"
802
803                         , list_pkt_forwarding_modes()
804                 );
805         }
806
807         if (show_all || !strcmp(res->section, "ports")) {
808
809                 cmdline_printf(
810                         cl,
811                         "\n"
812                         "Port Operations:\n"
813                         "----------------\n\n"
814
815                         "port start (port_id|all)\n"
816                         "    Start all ports or port_id.\n\n"
817
818                         "port stop (port_id|all)\n"
819                         "    Stop all ports or port_id.\n\n"
820
821                         "port close (port_id|all)\n"
822                         "    Close all ports or port_id.\n\n"
823
824                         "port attach (ident)\n"
825                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
826
827                         "port detach (port_id)\n"
828                         "    Detach physical or virtual dev by port_id\n\n"
829
830                         "port config (port_id|all)"
831                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
832                         " duplex (half|full|auto)\n"
833                         "    Set speed and duplex for all ports or port_id\n\n"
834
835                         "port config all (rxq|txq|rxd|txd) (value)\n"
836                         "    Set number for rxq/txq/rxd/txd.\n\n"
837
838                         "port config all max-pkt-len (value)\n"
839                         "    Set the max packet length.\n\n"
840
841                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
842                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
843                         " (on|off)\n"
844                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
845                         " for ports.\n\n"
846
847                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
848                         "geneve|nvgre|none|<flowtype_id>)\n"
849                         "    Set the RSS mode.\n\n"
850
851                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
852                         "    Set the RSS redirection table.\n\n"
853
854                         "port config (port_id) dcb vt (on|off) (traffic_class)"
855                         " pfc (on|off)\n"
856                         "    Set the DCB mode.\n\n"
857
858                         "port config all burst (value)\n"
859                         "    Set the number of packets per burst.\n\n"
860
861                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
862                         " (value)\n"
863                         "    Set the ring prefetch/host/writeback threshold"
864                         " for tx/rx queue.\n\n"
865
866                         "port config all (txfreet|txrst|rxfreet) (value)\n"
867                         "    Set free threshold for rx/tx, or set"
868                         " tx rs bit threshold.\n\n"
869                         "port config mtu X value\n"
870                         "    Set the MTU of port X to a given value\n\n"
871
872                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
873                         "    Start/stop a rx/tx queue of port X. Only take effect"
874                         " when port X is started\n\n"
875
876                         "port config (port_id|all) l2-tunnel E-tag ether-type"
877                         " (value)\n"
878                         "    Set the value of E-tag ether-type.\n\n"
879
880                         "port config (port_id|all) l2-tunnel E-tag"
881                         " (enable|disable)\n"
882                         "    Enable/disable the E-tag support.\n\n"
883
884                         "port config (port_id) pctype mapping reset\n"
885                         "    Reset flow type to pctype mapping on a port\n\n"
886
887                         "port config (port_id) pctype mapping update"
888                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
889                         "    Update a flow type to pctype mapping item on a port\n\n"
890
891                         "port config (port_id) pctype (pctype_id) hash_inset|"
892                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
893                         " (field_idx)\n"
894                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
895
896                         "port config (port_id) pctype (pctype_id) hash_inset|"
897                         "fdir_inset|fdir_flx_inset clear all"
898                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
899                 );
900         }
901
902         if (show_all || !strcmp(res->section, "registers")) {
903
904                 cmdline_printf(
905                         cl,
906                         "\n"
907                         "Registers:\n"
908                         "----------\n\n"
909
910                         "read reg (port_id) (address)\n"
911                         "    Display value of a port register.\n\n"
912
913                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
914                         "    Display a port register bit field.\n\n"
915
916                         "read regbit (port_id) (address) (bit_x)\n"
917                         "    Display a single port register bit.\n\n"
918
919                         "write reg (port_id) (address) (value)\n"
920                         "    Set value of a port register.\n\n"
921
922                         "write regfield (port_id) (address) (bit_x) (bit_y)"
923                         " (value)\n"
924                         "    Set bit field of a port register.\n\n"
925
926                         "write regbit (port_id) (address) (bit_x) (value)\n"
927                         "    Set single bit value of a port register.\n\n"
928                 );
929         }
930         if (show_all || !strcmp(res->section, "filters")) {
931
932                 cmdline_printf(
933                         cl,
934                         "\n"
935                         "filters:\n"
936                         "--------\n\n"
937
938                         "ethertype_filter (port_id) (add|del)"
939                         " (mac_addr|mac_ignr) (mac_address) ethertype"
940                         " (ether_type) (drop|fwd) queue (queue_id)\n"
941                         "    Add/Del an ethertype filter.\n\n"
942
943                         "2tuple_filter (port_id) (add|del)"
944                         " dst_port (dst_port_value) protocol (protocol_value)"
945                         " mask (mask_value) tcp_flags (tcp_flags_value)"
946                         " priority (prio_value) queue (queue_id)\n"
947                         "    Add/Del a 2tuple filter.\n\n"
948
949                         "5tuple_filter (port_id) (add|del)"
950                         " dst_ip (dst_address) src_ip (src_address)"
951                         " dst_port (dst_port_value) src_port (src_port_value)"
952                         " protocol (protocol_value)"
953                         " mask (mask_value) tcp_flags (tcp_flags_value)"
954                         " priority (prio_value) queue (queue_id)\n"
955                         "    Add/Del a 5tuple filter.\n\n"
956
957                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
958                         "    Add/Del syn filter.\n\n"
959
960                         "flex_filter (port_id) (add|del) len (len_value)"
961                         " bytes (bytes_value) mask (mask_value)"
962                         " priority (prio_value) queue (queue_id)\n"
963                         "    Add/Del a flex filter.\n\n"
964
965                         "flow_director_filter (port_id) mode IP (add|del|update)"
966                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
967                         " src (src_ip_address) dst (dst_ip_address)"
968                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
969                         " vlan (vlan_value) flexbytes (flexbytes_value)"
970                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
971                         " fd_id (fd_id_value)\n"
972                         "    Add/Del an IP type flow director filter.\n\n"
973
974                         "flow_director_filter (port_id) mode IP (add|del|update)"
975                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
976                         " src (src_ip_address) (src_port)"
977                         " dst (dst_ip_address) (dst_port)"
978                         " tos (tos_value) ttl (ttl_value)"
979                         " vlan (vlan_value) flexbytes (flexbytes_value)"
980                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
981                         " fd_id (fd_id_value)\n"
982                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
983
984                         "flow_director_filter (port_id) mode IP (add|del|update)"
985                         " flow (ipv4-sctp|ipv6-sctp)"
986                         " src (src_ip_address) (src_port)"
987                         " dst (dst_ip_address) (dst_port)"
988                         " tag (verification_tag) "
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value)"
991                         " flexbytes (flexbytes_value) (drop|fwd)"
992                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
993                         "    Add/Del a SCTP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow l2_payload ether (ethertype)"
997                         " flexbytes (flexbytes_value) (drop|fwd)"
998                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
999                         "    Add/Del a l2 payload type flow director filter.\n\n"
1000
1001                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1002                         " mac (mac_address) vlan (vlan_value)"
1003                         " flexbytes (flexbytes_value) (drop|fwd)"
1004                         " queue (queue_id) fd_id (fd_id_value)\n"
1005                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1006
1007                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1008                         " mac (mac_address) vlan (vlan_value)"
1009                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1010                         " flexbytes (flexbytes_value) (drop|fwd)"
1011                         " queue (queue_id) fd_id (fd_id_value)\n"
1012                         "    Add/Del a Tunnel flow director filter.\n\n"
1013
1014                         "flow_director_filter (port_id) mode raw (add|del|update)"
1015                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1016                         " fd_id (fd_id_value) packet (packet file name)\n"
1017                         "    Add/Del a raw type flow director filter.\n\n"
1018
1019                         "flush_flow_director (port_id)\n"
1020                         "    Flush all flow director entries of a device.\n\n"
1021
1022                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1023                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1024                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1025                         "    Set flow director IP mask.\n\n"
1026
1027                         "flow_director_mask (port_id) mode MAC-VLAN"
1028                         " vlan (vlan_value)\n"
1029                         "    Set flow director MAC-VLAN mask.\n\n"
1030
1031                         "flow_director_mask (port_id) mode Tunnel"
1032                         " vlan (vlan_value) mac (mac_value)"
1033                         " tunnel-type (tunnel_type_value)"
1034                         " tunnel-id (tunnel_id_value)\n"
1035                         "    Set flow director Tunnel mask.\n\n"
1036
1037                         "flow_director_flex_mask (port_id)"
1038                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1039                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1040                         " (mask)\n"
1041                         "    Configure mask of flex payload.\n\n"
1042
1043                         "flow_director_flex_payload (port_id)"
1044                         " (raw|l2|l3|l4) (config)\n"
1045                         "    Configure flex payload selection.\n\n"
1046
1047                         "get_sym_hash_ena_per_port (port_id)\n"
1048                         "    get symmetric hash enable configuration per port.\n\n"
1049
1050                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1051                         "    set symmetric hash enable configuration per port"
1052                         " to enable or disable.\n\n"
1053
1054                         "get_hash_global_config (port_id)\n"
1055                         "    Get the global configurations of hash filters.\n\n"
1056
1057                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1058                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1059                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1060                         " (enable|disable)\n"
1061                         "    Set the global configurations of hash filters.\n\n"
1062
1063                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1064                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1065                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1066                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1067                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1068                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1069                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1070                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1071                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1072                         "fld-8th|none) (select|add)\n"
1073                         "    Set the input set for hash.\n\n"
1074
1075                         "set_fdir_input_set (port_id) "
1076                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1077                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1078                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1079                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1080                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1081                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1082                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1083                         " (select|add)\n"
1084                         "    Set the input set for FDir.\n\n"
1085
1086                         "flow validate {port_id}"
1087                         " [group {group_id}] [priority {level}]"
1088                         " [ingress] [egress]"
1089                         " pattern {item} [/ {item} [...]] / end"
1090                         " actions {action} [/ {action} [...]] / end\n"
1091                         "    Check whether a flow rule can be created.\n\n"
1092
1093                         "flow create {port_id}"
1094                         " [group {group_id}] [priority {level}]"
1095                         " [ingress] [egress]"
1096                         " pattern {item} [/ {item} [...]] / end"
1097                         " actions {action} [/ {action} [...]] / end\n"
1098                         "    Create a flow rule.\n\n"
1099
1100                         "flow destroy {port_id} rule {rule_id} [...]\n"
1101                         "    Destroy specific flow rules.\n\n"
1102
1103                         "flow flush {port_id}\n"
1104                         "    Destroy all flow rules.\n\n"
1105
1106                         "flow query {port_id} {rule_id} {action}\n"
1107                         "    Query an existing flow rule.\n\n"
1108
1109                         "flow list {port_id} [group {group_id}] [...]\n"
1110                         "    List existing flow rules sorted by priority,"
1111                         " filtered by group identifiers.\n\n"
1112
1113                         "flow isolate {port_id} {boolean}\n"
1114                         "    Restrict ingress traffic to the defined"
1115                         " flow rules\n\n"
1116                 );
1117         }
1118 }
1119
1120 cmdline_parse_token_string_t cmd_help_long_help =
1121         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1122
1123 cmdline_parse_token_string_t cmd_help_long_section =
1124         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1125                         "all#control#display#config#"
1126                         "ports#registers#filters");
1127
1128 cmdline_parse_inst_t cmd_help_long = {
1129         .f = cmd_help_long_parsed,
1130         .data = NULL,
1131         .help_str = "help all|control|display|config|ports|register|filters: "
1132                 "Show help",
1133         .tokens = {
1134                 (void *)&cmd_help_long_help,
1135                 (void *)&cmd_help_long_section,
1136                 NULL,
1137         },
1138 };
1139
1140
1141 /* *** start/stop/close all ports *** */
1142 struct cmd_operate_port_result {
1143         cmdline_fixed_string_t keyword;
1144         cmdline_fixed_string_t name;
1145         cmdline_fixed_string_t value;
1146 };
1147
1148 static void cmd_operate_port_parsed(void *parsed_result,
1149                                 __attribute__((unused)) struct cmdline *cl,
1150                                 __attribute__((unused)) void *data)
1151 {
1152         struct cmd_operate_port_result *res = parsed_result;
1153
1154         if (!strcmp(res->name, "start"))
1155                 start_port(RTE_PORT_ALL);
1156         else if (!strcmp(res->name, "stop"))
1157                 stop_port(RTE_PORT_ALL);
1158         else if (!strcmp(res->name, "close"))
1159                 close_port(RTE_PORT_ALL);
1160         else if (!strcmp(res->name, "reset"))
1161                 reset_port(RTE_PORT_ALL);
1162         else
1163                 printf("Unknown parameter\n");
1164 }
1165
1166 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1167         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1168                                                                 "port");
1169 cmdline_parse_token_string_t cmd_operate_port_all_port =
1170         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1171                                                 "start#stop#close#reset");
1172 cmdline_parse_token_string_t cmd_operate_port_all_all =
1173         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1174
1175 cmdline_parse_inst_t cmd_operate_port = {
1176         .f = cmd_operate_port_parsed,
1177         .data = NULL,
1178         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1179         .tokens = {
1180                 (void *)&cmd_operate_port_all_cmd,
1181                 (void *)&cmd_operate_port_all_port,
1182                 (void *)&cmd_operate_port_all_all,
1183                 NULL,
1184         },
1185 };
1186
1187 /* *** start/stop/close specific port *** */
1188 struct cmd_operate_specific_port_result {
1189         cmdline_fixed_string_t keyword;
1190         cmdline_fixed_string_t name;
1191         uint8_t value;
1192 };
1193
1194 static void cmd_operate_specific_port_parsed(void *parsed_result,
1195                         __attribute__((unused)) struct cmdline *cl,
1196                                 __attribute__((unused)) void *data)
1197 {
1198         struct cmd_operate_specific_port_result *res = parsed_result;
1199
1200         if (!strcmp(res->name, "start"))
1201                 start_port(res->value);
1202         else if (!strcmp(res->name, "stop"))
1203                 stop_port(res->value);
1204         else if (!strcmp(res->name, "close"))
1205                 close_port(res->value);
1206         else if (!strcmp(res->name, "reset"))
1207                 reset_port(res->value);
1208         else
1209                 printf("Unknown parameter\n");
1210 }
1211
1212 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1213         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1214                                                         keyword, "port");
1215 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1217                                                 name, "start#stop#close#reset");
1218 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1219         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1220                                                         value, UINT8);
1221
1222 cmdline_parse_inst_t cmd_operate_specific_port = {
1223         .f = cmd_operate_specific_port_parsed,
1224         .data = NULL,
1225         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1226         .tokens = {
1227                 (void *)&cmd_operate_specific_port_cmd,
1228                 (void *)&cmd_operate_specific_port_port,
1229                 (void *)&cmd_operate_specific_port_id,
1230                 NULL,
1231         },
1232 };
1233
1234 /* *** attach a specified port *** */
1235 struct cmd_operate_attach_port_result {
1236         cmdline_fixed_string_t port;
1237         cmdline_fixed_string_t keyword;
1238         cmdline_fixed_string_t identifier;
1239 };
1240
1241 static void cmd_operate_attach_port_parsed(void *parsed_result,
1242                                 __attribute__((unused)) struct cmdline *cl,
1243                                 __attribute__((unused)) void *data)
1244 {
1245         struct cmd_operate_attach_port_result *res = parsed_result;
1246
1247         if (!strcmp(res->keyword, "attach"))
1248                 attach_port(res->identifier);
1249         else
1250                 printf("Unknown parameter\n");
1251 }
1252
1253 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1254         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1255                         port, "port");
1256 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1257         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1258                         keyword, "attach");
1259 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1260         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1261                         identifier, NULL);
1262
1263 cmdline_parse_inst_t cmd_operate_attach_port = {
1264         .f = cmd_operate_attach_port_parsed,
1265         .data = NULL,
1266         .help_str = "port attach <identifier>: "
1267                 "(identifier: pci address or virtual dev name)",
1268         .tokens = {
1269                 (void *)&cmd_operate_attach_port_port,
1270                 (void *)&cmd_operate_attach_port_keyword,
1271                 (void *)&cmd_operate_attach_port_identifier,
1272                 NULL,
1273         },
1274 };
1275
1276 /* *** detach a specified port *** */
1277 struct cmd_operate_detach_port_result {
1278         cmdline_fixed_string_t port;
1279         cmdline_fixed_string_t keyword;
1280         portid_t port_id;
1281 };
1282
1283 static void cmd_operate_detach_port_parsed(void *parsed_result,
1284                                 __attribute__((unused)) struct cmdline *cl,
1285                                 __attribute__((unused)) void *data)
1286 {
1287         struct cmd_operate_detach_port_result *res = parsed_result;
1288
1289         if (!strcmp(res->keyword, "detach"))
1290                 detach_port(res->port_id);
1291         else
1292                 printf("Unknown parameter\n");
1293 }
1294
1295 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1296         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1297                         port, "port");
1298 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1299         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1300                         keyword, "detach");
1301 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1302         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1303                         port_id, UINT16);
1304
1305 cmdline_parse_inst_t cmd_operate_detach_port = {
1306         .f = cmd_operate_detach_port_parsed,
1307         .data = NULL,
1308         .help_str = "port detach <port_id>",
1309         .tokens = {
1310                 (void *)&cmd_operate_detach_port_port,
1311                 (void *)&cmd_operate_detach_port_keyword,
1312                 (void *)&cmd_operate_detach_port_port_id,
1313                 NULL,
1314         },
1315 };
1316
1317 /* *** configure speed for all ports *** */
1318 struct cmd_config_speed_all {
1319         cmdline_fixed_string_t port;
1320         cmdline_fixed_string_t keyword;
1321         cmdline_fixed_string_t all;
1322         cmdline_fixed_string_t item1;
1323         cmdline_fixed_string_t item2;
1324         cmdline_fixed_string_t value1;
1325         cmdline_fixed_string_t value2;
1326 };
1327
1328 static int
1329 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1330 {
1331
1332         int duplex;
1333
1334         if (!strcmp(duplexstr, "half")) {
1335                 duplex = ETH_LINK_HALF_DUPLEX;
1336         } else if (!strcmp(duplexstr, "full")) {
1337                 duplex = ETH_LINK_FULL_DUPLEX;
1338         } else if (!strcmp(duplexstr, "auto")) {
1339                 duplex = ETH_LINK_FULL_DUPLEX;
1340         } else {
1341                 printf("Unknown duplex parameter\n");
1342                 return -1;
1343         }
1344
1345         if (!strcmp(speedstr, "10")) {
1346                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1347                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1348         } else if (!strcmp(speedstr, "100")) {
1349                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1350                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1351         } else {
1352                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1353                         printf("Invalid speed/duplex parameters\n");
1354                         return -1;
1355                 }
1356                 if (!strcmp(speedstr, "1000")) {
1357                         *speed = ETH_LINK_SPEED_1G;
1358                 } else if (!strcmp(speedstr, "10000")) {
1359                         *speed = ETH_LINK_SPEED_10G;
1360                 } else if (!strcmp(speedstr, "25000")) {
1361                         *speed = ETH_LINK_SPEED_25G;
1362                 } else if (!strcmp(speedstr, "40000")) {
1363                         *speed = ETH_LINK_SPEED_40G;
1364                 } else if (!strcmp(speedstr, "50000")) {
1365                         *speed = ETH_LINK_SPEED_50G;
1366                 } else if (!strcmp(speedstr, "100000")) {
1367                         *speed = ETH_LINK_SPEED_100G;
1368                 } else if (!strcmp(speedstr, "auto")) {
1369                         *speed = ETH_LINK_SPEED_AUTONEG;
1370                 } else {
1371                         printf("Unknown speed parameter\n");
1372                         return -1;
1373                 }
1374         }
1375
1376         return 0;
1377 }
1378
1379 static void
1380 cmd_config_speed_all_parsed(void *parsed_result,
1381                         __attribute__((unused)) struct cmdline *cl,
1382                         __attribute__((unused)) void *data)
1383 {
1384         struct cmd_config_speed_all *res = parsed_result;
1385         uint32_t link_speed;
1386         portid_t pid;
1387
1388         if (!all_ports_stopped()) {
1389                 printf("Please stop all ports first\n");
1390                 return;
1391         }
1392
1393         if (parse_and_check_speed_duplex(res->value1, res->value2,
1394                         &link_speed) < 0)
1395                 return;
1396
1397         RTE_ETH_FOREACH_DEV(pid) {
1398                 ports[pid].dev_conf.link_speeds = link_speed;
1399         }
1400
1401         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1402 }
1403
1404 cmdline_parse_token_string_t cmd_config_speed_all_port =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1406 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1408                                                         "config");
1409 cmdline_parse_token_string_t cmd_config_speed_all_all =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1411 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1412         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1413 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1415                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1416 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1418 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1419         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1420                                                 "half#full#auto");
1421
1422 cmdline_parse_inst_t cmd_config_speed_all = {
1423         .f = cmd_config_speed_all_parsed,
1424         .data = NULL,
1425         .help_str = "port config all speed "
1426                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1427                                                         "half|full|auto",
1428         .tokens = {
1429                 (void *)&cmd_config_speed_all_port,
1430                 (void *)&cmd_config_speed_all_keyword,
1431                 (void *)&cmd_config_speed_all_all,
1432                 (void *)&cmd_config_speed_all_item1,
1433                 (void *)&cmd_config_speed_all_value1,
1434                 (void *)&cmd_config_speed_all_item2,
1435                 (void *)&cmd_config_speed_all_value2,
1436                 NULL,
1437         },
1438 };
1439
1440 /* *** configure speed for specific port *** */
1441 struct cmd_config_speed_specific {
1442         cmdline_fixed_string_t port;
1443         cmdline_fixed_string_t keyword;
1444         uint8_t id;
1445         cmdline_fixed_string_t item1;
1446         cmdline_fixed_string_t item2;
1447         cmdline_fixed_string_t value1;
1448         cmdline_fixed_string_t value2;
1449 };
1450
1451 static void
1452 cmd_config_speed_specific_parsed(void *parsed_result,
1453                                 __attribute__((unused)) struct cmdline *cl,
1454                                 __attribute__((unused)) void *data)
1455 {
1456         struct cmd_config_speed_specific *res = parsed_result;
1457         uint32_t link_speed;
1458
1459         if (!all_ports_stopped()) {
1460                 printf("Please stop all ports first\n");
1461                 return;
1462         }
1463
1464         if (port_id_is_invalid(res->id, ENABLED_WARN))
1465                 return;
1466
1467         if (parse_and_check_speed_duplex(res->value1, res->value2,
1468                         &link_speed) < 0)
1469                 return;
1470
1471         ports[res->id].dev_conf.link_speeds = link_speed;
1472
1473         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1474 }
1475
1476
1477 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1478         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1479                                                                 "port");
1480 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1482                                                                 "config");
1483 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1484         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1485 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1486         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1487                                                                 "speed");
1488 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1490                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1491 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1493                                                                 "duplex");
1494 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1495         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1496                                                         "half#full#auto");
1497
1498 cmdline_parse_inst_t cmd_config_speed_specific = {
1499         .f = cmd_config_speed_specific_parsed,
1500         .data = NULL,
1501         .help_str = "port config <port_id> speed "
1502                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1503                                                         "half|full|auto",
1504         .tokens = {
1505                 (void *)&cmd_config_speed_specific_port,
1506                 (void *)&cmd_config_speed_specific_keyword,
1507                 (void *)&cmd_config_speed_specific_id,
1508                 (void *)&cmd_config_speed_specific_item1,
1509                 (void *)&cmd_config_speed_specific_value1,
1510                 (void *)&cmd_config_speed_specific_item2,
1511                 (void *)&cmd_config_speed_specific_value2,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** configure txq/rxq, txd/rxd *** */
1517 struct cmd_config_rx_tx {
1518         cmdline_fixed_string_t port;
1519         cmdline_fixed_string_t keyword;
1520         cmdline_fixed_string_t all;
1521         cmdline_fixed_string_t name;
1522         uint16_t value;
1523 };
1524
1525 static void
1526 cmd_config_rx_tx_parsed(void *parsed_result,
1527                         __attribute__((unused)) struct cmdline *cl,
1528                         __attribute__((unused)) void *data)
1529 {
1530         struct cmd_config_rx_tx *res = parsed_result;
1531
1532         if (!all_ports_stopped()) {
1533                 printf("Please stop all ports first\n");
1534                 return;
1535         }
1536         if (!strcmp(res->name, "rxq")) {
1537                 if (!res->value && !nb_txq) {
1538                         printf("Warning: Either rx or tx queues should be non zero\n");
1539                         return;
1540                 }
1541                 if (check_nb_rxq(res->value) != 0)
1542                         return;
1543                 nb_rxq = res->value;
1544         }
1545         else if (!strcmp(res->name, "txq")) {
1546                 if (!res->value && !nb_rxq) {
1547                         printf("Warning: Either rx or tx queues should be non zero\n");
1548                         return;
1549                 }
1550                 if (check_nb_txq(res->value) != 0)
1551                         return;
1552                 nb_txq = res->value;
1553         }
1554         else if (!strcmp(res->name, "rxd")) {
1555                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1556                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1557                                         res->value, RTE_TEST_RX_DESC_MAX);
1558                         return;
1559                 }
1560                 nb_rxd = res->value;
1561         } else if (!strcmp(res->name, "txd")) {
1562                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1563                         printf("txd %d invalid - must be > 0 && <= %d\n",
1564                                         res->value, RTE_TEST_TX_DESC_MAX);
1565                         return;
1566                 }
1567                 nb_txd = res->value;
1568         } else {
1569                 printf("Unknown parameter\n");
1570                 return;
1571         }
1572
1573         fwd_config_setup();
1574
1575         init_port_config();
1576
1577         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1578 }
1579
1580 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1582 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1584 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1585         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1586 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1587         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1588                                                 "rxq#txq#rxd#txd");
1589 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1590         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1591
1592 cmdline_parse_inst_t cmd_config_rx_tx = {
1593         .f = cmd_config_rx_tx_parsed,
1594         .data = NULL,
1595         .help_str = "port config all rxq|txq|rxd|txd <value>",
1596         .tokens = {
1597                 (void *)&cmd_config_rx_tx_port,
1598                 (void *)&cmd_config_rx_tx_keyword,
1599                 (void *)&cmd_config_rx_tx_all,
1600                 (void *)&cmd_config_rx_tx_name,
1601                 (void *)&cmd_config_rx_tx_value,
1602                 NULL,
1603         },
1604 };
1605
1606 /* *** config max packet length *** */
1607 struct cmd_config_max_pkt_len_result {
1608         cmdline_fixed_string_t port;
1609         cmdline_fixed_string_t keyword;
1610         cmdline_fixed_string_t all;
1611         cmdline_fixed_string_t name;
1612         uint32_t value;
1613 };
1614
1615 static void
1616 cmd_config_max_pkt_len_parsed(void *parsed_result,
1617                                 __attribute__((unused)) struct cmdline *cl,
1618                                 __attribute__((unused)) void *data)
1619 {
1620         struct cmd_config_max_pkt_len_result *res = parsed_result;
1621         portid_t pid;
1622
1623         if (!all_ports_stopped()) {
1624                 printf("Please stop all ports first\n");
1625                 return;
1626         }
1627
1628         RTE_ETH_FOREACH_DEV(pid) {
1629                 struct rte_port *port = &ports[pid];
1630                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1631
1632                 if (!strcmp(res->name, "max-pkt-len")) {
1633                         if (res->value < ETHER_MIN_LEN) {
1634                                 printf("max-pkt-len can not be less than %d\n",
1635                                                 ETHER_MIN_LEN);
1636                                 return;
1637                         }
1638                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1639                                 return;
1640
1641                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1642                         if (res->value > ETHER_MAX_LEN)
1643                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1644                         else
1645                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1646                         port->dev_conf.rxmode.offloads = rx_offloads;
1647                 } else {
1648                         printf("Unknown parameter\n");
1649                         return;
1650                 }
1651         }
1652
1653         init_port_config();
1654
1655         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1656 }
1657
1658 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1660                                                                 "port");
1661 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1663                                                                 "config");
1664 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1666                                                                 "all");
1667 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1669                                                                 "max-pkt-len");
1670 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1671         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1672                                                                 UINT32);
1673
1674 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1675         .f = cmd_config_max_pkt_len_parsed,
1676         .data = NULL,
1677         .help_str = "port config all max-pkt-len <value>",
1678         .tokens = {
1679                 (void *)&cmd_config_max_pkt_len_port,
1680                 (void *)&cmd_config_max_pkt_len_keyword,
1681                 (void *)&cmd_config_max_pkt_len_all,
1682                 (void *)&cmd_config_max_pkt_len_name,
1683                 (void *)&cmd_config_max_pkt_len_value,
1684                 NULL,
1685         },
1686 };
1687
1688 /* *** configure port MTU *** */
1689 struct cmd_config_mtu_result {
1690         cmdline_fixed_string_t port;
1691         cmdline_fixed_string_t keyword;
1692         cmdline_fixed_string_t mtu;
1693         portid_t port_id;
1694         uint16_t value;
1695 };
1696
1697 static void
1698 cmd_config_mtu_parsed(void *parsed_result,
1699                       __attribute__((unused)) struct cmdline *cl,
1700                       __attribute__((unused)) void *data)
1701 {
1702         struct cmd_config_mtu_result *res = parsed_result;
1703
1704         if (res->value < ETHER_MIN_LEN) {
1705                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1706                 return;
1707         }
1708         port_mtu_set(res->port_id, res->value);
1709 }
1710
1711 cmdline_parse_token_string_t cmd_config_mtu_port =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1713                                  "port");
1714 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1716                                  "config");
1717 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1719                                  "mtu");
1720 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1721         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1722 cmdline_parse_token_num_t cmd_config_mtu_value =
1723         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1724
1725 cmdline_parse_inst_t cmd_config_mtu = {
1726         .f = cmd_config_mtu_parsed,
1727         .data = NULL,
1728         .help_str = "port config mtu <port_id> <value>",
1729         .tokens = {
1730                 (void *)&cmd_config_mtu_port,
1731                 (void *)&cmd_config_mtu_keyword,
1732                 (void *)&cmd_config_mtu_mtu,
1733                 (void *)&cmd_config_mtu_port_id,
1734                 (void *)&cmd_config_mtu_value,
1735                 NULL,
1736         },
1737 };
1738
1739 /* *** configure rx mode *** */
1740 struct cmd_config_rx_mode_flag {
1741         cmdline_fixed_string_t port;
1742         cmdline_fixed_string_t keyword;
1743         cmdline_fixed_string_t all;
1744         cmdline_fixed_string_t name;
1745         cmdline_fixed_string_t value;
1746 };
1747
1748 static void
1749 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1750                                 __attribute__((unused)) struct cmdline *cl,
1751                                 __attribute__((unused)) void *data)
1752 {
1753         struct cmd_config_rx_mode_flag *res = parsed_result;
1754         portid_t pid;
1755
1756         if (!all_ports_stopped()) {
1757                 printf("Please stop all ports first\n");
1758                 return;
1759         }
1760
1761         RTE_ETH_FOREACH_DEV(pid) {
1762                 struct rte_port *port;
1763                 uint64_t rx_offloads;
1764
1765                 port = &ports[pid];
1766                 rx_offloads = port->dev_conf.rxmode.offloads;
1767                 if (!strcmp(res->name, "crc-strip")) {
1768                         if (!strcmp(res->value, "on"))
1769                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1770                         else if (!strcmp(res->value, "off"))
1771                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1772                         else {
1773                                 printf("Unknown parameter\n");
1774                                 return;
1775                         }
1776                 } else if (!strcmp(res->name, "scatter")) {
1777                         if (!strcmp(res->value, "on")) {
1778                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1779                         } else if (!strcmp(res->value, "off")) {
1780                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1781                         } else {
1782                                 printf("Unknown parameter\n");
1783                                 return;
1784                         }
1785                 } else if (!strcmp(res->name, "rx-cksum")) {
1786                         if (!strcmp(res->value, "on"))
1787                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1788                         else if (!strcmp(res->value, "off"))
1789                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1790                         else {
1791                                 printf("Unknown parameter\n");
1792                                 return;
1793                         }
1794                 } else if (!strcmp(res->name, "rx-timestamp")) {
1795                         if (!strcmp(res->value, "on"))
1796                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1797                         else if (!strcmp(res->value, "off"))
1798                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1799                         else {
1800                                 printf("Unknown parameter\n");
1801                                 return;
1802                         }
1803                 } else if (!strcmp(res->name, "hw-vlan")) {
1804                         if (!strcmp(res->value, "on")) {
1805                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1806                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1807                         } else if (!strcmp(res->value, "off")) {
1808                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1809                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1810                         } else {
1811                                 printf("Unknown parameter\n");
1812                                 return;
1813                         }
1814                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1815                         if (!strcmp(res->value, "on"))
1816                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1817                         else if (!strcmp(res->value, "off"))
1818                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1819                         else {
1820                                 printf("Unknown parameter\n");
1821                                 return;
1822                         }
1823                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1824                         if (!strcmp(res->value, "on"))
1825                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1826                         else if (!strcmp(res->value, "off"))
1827                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1828                         else {
1829                                 printf("Unknown parameter\n");
1830                                 return;
1831                         }
1832                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1833                         if (!strcmp(res->value, "on"))
1834                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1835                         else if (!strcmp(res->value, "off"))
1836                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1837                         else {
1838                                 printf("Unknown parameter\n");
1839                                 return;
1840                         }
1841                 } else if (!strcmp(res->name, "drop-en")) {
1842                         if (!strcmp(res->value, "on"))
1843                                 rx_drop_en = 1;
1844                         else if (!strcmp(res->value, "off"))
1845                                 rx_drop_en = 0;
1846                         else {
1847                                 printf("Unknown parameter\n");
1848                                 return;
1849                         }
1850                 } else {
1851                         printf("Unknown parameter\n");
1852                         return;
1853                 }
1854                 port->dev_conf.rxmode.offloads = rx_offloads;
1855         }
1856
1857         init_port_config();
1858
1859         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1860 }
1861
1862 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1864 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1865         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1866                                                                 "config");
1867 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1868         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1869 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1870         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1871                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1872                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1873 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1874         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1875                                                         "on#off");
1876
1877 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1878         .f = cmd_config_rx_mode_flag_parsed,
1879         .data = NULL,
1880         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1881                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1882         .tokens = {
1883                 (void *)&cmd_config_rx_mode_flag_port,
1884                 (void *)&cmd_config_rx_mode_flag_keyword,
1885                 (void *)&cmd_config_rx_mode_flag_all,
1886                 (void *)&cmd_config_rx_mode_flag_name,
1887                 (void *)&cmd_config_rx_mode_flag_value,
1888                 NULL,
1889         },
1890 };
1891
1892 /* *** configure rss *** */
1893 struct cmd_config_rss {
1894         cmdline_fixed_string_t port;
1895         cmdline_fixed_string_t keyword;
1896         cmdline_fixed_string_t all;
1897         cmdline_fixed_string_t name;
1898         cmdline_fixed_string_t value;
1899 };
1900
1901 static void
1902 cmd_config_rss_parsed(void *parsed_result,
1903                         __attribute__((unused)) struct cmdline *cl,
1904                         __attribute__((unused)) void *data)
1905 {
1906         struct cmd_config_rss *res = parsed_result;
1907         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1908         int diag;
1909         uint8_t i;
1910
1911         if (!strcmp(res->value, "all"))
1912                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1913                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1914                                         ETH_RSS_L2_PAYLOAD;
1915         else if (!strcmp(res->value, "ip"))
1916                 rss_conf.rss_hf = ETH_RSS_IP;
1917         else if (!strcmp(res->value, "udp"))
1918                 rss_conf.rss_hf = ETH_RSS_UDP;
1919         else if (!strcmp(res->value, "tcp"))
1920                 rss_conf.rss_hf = ETH_RSS_TCP;
1921         else if (!strcmp(res->value, "sctp"))
1922                 rss_conf.rss_hf = ETH_RSS_SCTP;
1923         else if (!strcmp(res->value, "ether"))
1924                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1925         else if (!strcmp(res->value, "port"))
1926                 rss_conf.rss_hf = ETH_RSS_PORT;
1927         else if (!strcmp(res->value, "vxlan"))
1928                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1929         else if (!strcmp(res->value, "geneve"))
1930                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1931         else if (!strcmp(res->value, "nvgre"))
1932                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1933         else if (!strcmp(res->value, "none"))
1934                 rss_conf.rss_hf = 0;
1935         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1936                                                 atoi(res->value) < 64)
1937                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1938         else {
1939                 printf("Unknown parameter\n");
1940                 return;
1941         }
1942         rss_conf.rss_key = NULL;
1943         for (i = 0; i < rte_eth_dev_count(); i++) {
1944                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1945                 if (diag < 0)
1946                         printf("Configuration of RSS hash at ethernet port %d "
1947                                 "failed with error (%d): %s.\n",
1948                                 i, -diag, strerror(-diag));
1949         }
1950 }
1951
1952 cmdline_parse_token_string_t cmd_config_rss_port =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1954 cmdline_parse_token_string_t cmd_config_rss_keyword =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1956 cmdline_parse_token_string_t cmd_config_rss_all =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1958 cmdline_parse_token_string_t cmd_config_rss_name =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1960 cmdline_parse_token_string_t cmd_config_rss_value =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1962
1963 cmdline_parse_inst_t cmd_config_rss = {
1964         .f = cmd_config_rss_parsed,
1965         .data = NULL,
1966         .help_str = "port config all rss "
1967                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1968         .tokens = {
1969                 (void *)&cmd_config_rss_port,
1970                 (void *)&cmd_config_rss_keyword,
1971                 (void *)&cmd_config_rss_all,
1972                 (void *)&cmd_config_rss_name,
1973                 (void *)&cmd_config_rss_value,
1974                 NULL,
1975         },
1976 };
1977
1978 /* *** configure rss hash key *** */
1979 struct cmd_config_rss_hash_key {
1980         cmdline_fixed_string_t port;
1981         cmdline_fixed_string_t config;
1982         portid_t port_id;
1983         cmdline_fixed_string_t rss_hash_key;
1984         cmdline_fixed_string_t rss_type;
1985         cmdline_fixed_string_t key;
1986 };
1987
1988 static uint8_t
1989 hexa_digit_to_value(char hexa_digit)
1990 {
1991         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1992                 return (uint8_t) (hexa_digit - '0');
1993         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1994                 return (uint8_t) ((hexa_digit - 'a') + 10);
1995         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1996                 return (uint8_t) ((hexa_digit - 'A') + 10);
1997         /* Invalid hexa digit */
1998         return 0xFF;
1999 }
2000
2001 static uint8_t
2002 parse_and_check_key_hexa_digit(char *key, int idx)
2003 {
2004         uint8_t hexa_v;
2005
2006         hexa_v = hexa_digit_to_value(key[idx]);
2007         if (hexa_v == 0xFF)
2008                 printf("invalid key: character %c at position %d is not a "
2009                        "valid hexa digit\n", key[idx], idx);
2010         return hexa_v;
2011 }
2012
2013 static void
2014 cmd_config_rss_hash_key_parsed(void *parsed_result,
2015                                __attribute__((unused)) struct cmdline *cl,
2016                                __attribute__((unused)) void *data)
2017 {
2018         struct cmd_config_rss_hash_key *res = parsed_result;
2019         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2020         uint8_t xdgt0;
2021         uint8_t xdgt1;
2022         int i;
2023         struct rte_eth_dev_info dev_info;
2024         uint8_t hash_key_size;
2025         uint32_t key_len;
2026
2027         memset(&dev_info, 0, sizeof(dev_info));
2028         rte_eth_dev_info_get(res->port_id, &dev_info);
2029         if (dev_info.hash_key_size > 0 &&
2030                         dev_info.hash_key_size <= sizeof(hash_key))
2031                 hash_key_size = dev_info.hash_key_size;
2032         else {
2033                 printf("dev_info did not provide a valid hash key size\n");
2034                 return;
2035         }
2036         /* Check the length of the RSS hash key */
2037         key_len = strlen(res->key);
2038         if (key_len != (hash_key_size * 2)) {
2039                 printf("key length: %d invalid - key must be a string of %d"
2040                            " hexa-decimal numbers\n",
2041                            (int) key_len, hash_key_size * 2);
2042                 return;
2043         }
2044         /* Translate RSS hash key into binary representation */
2045         for (i = 0; i < hash_key_size; i++) {
2046                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2047                 if (xdgt0 == 0xFF)
2048                         return;
2049                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2050                 if (xdgt1 == 0xFF)
2051                         return;
2052                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2053         }
2054         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2055                         hash_key_size);
2056 }
2057
2058 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2060 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2062                                  "config");
2063 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2064         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2065 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2066         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2067                                  rss_hash_key, "rss-hash-key");
2068 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2070                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2071                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2072                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2073                                  "ipv6-tcp-ex#ipv6-udp-ex");
2074 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2075         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2076
2077 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2078         .f = cmd_config_rss_hash_key_parsed,
2079         .data = NULL,
2080         .help_str = "port config <port_id> rss-hash-key "
2081                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2082                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2083                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2084                 "<string of hex digits (variable length, NIC dependent)>",
2085         .tokens = {
2086                 (void *)&cmd_config_rss_hash_key_port,
2087                 (void *)&cmd_config_rss_hash_key_config,
2088                 (void *)&cmd_config_rss_hash_key_port_id,
2089                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2090                 (void *)&cmd_config_rss_hash_key_rss_type,
2091                 (void *)&cmd_config_rss_hash_key_value,
2092                 NULL,
2093         },
2094 };
2095
2096 /* *** configure port rxq/txq start/stop *** */
2097 struct cmd_config_rxtx_queue {
2098         cmdline_fixed_string_t port;
2099         portid_t portid;
2100         cmdline_fixed_string_t rxtxq;
2101         uint16_t qid;
2102         cmdline_fixed_string_t opname;
2103 };
2104
2105 static void
2106 cmd_config_rxtx_queue_parsed(void *parsed_result,
2107                         __attribute__((unused)) struct cmdline *cl,
2108                         __attribute__((unused)) void *data)
2109 {
2110         struct cmd_config_rxtx_queue *res = parsed_result;
2111         uint8_t isrx;
2112         uint8_t isstart;
2113         int ret = 0;
2114
2115         if (test_done == 0) {
2116                 printf("Please stop forwarding first\n");
2117                 return;
2118         }
2119
2120         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2121                 return;
2122
2123         if (port_is_started(res->portid) != 1) {
2124                 printf("Please start port %u first\n", res->portid);
2125                 return;
2126         }
2127
2128         if (!strcmp(res->rxtxq, "rxq"))
2129                 isrx = 1;
2130         else if (!strcmp(res->rxtxq, "txq"))
2131                 isrx = 0;
2132         else {
2133                 printf("Unknown parameter\n");
2134                 return;
2135         }
2136
2137         if (isrx && rx_queue_id_is_invalid(res->qid))
2138                 return;
2139         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2140                 return;
2141
2142         if (!strcmp(res->opname, "start"))
2143                 isstart = 1;
2144         else if (!strcmp(res->opname, "stop"))
2145                 isstart = 0;
2146         else {
2147                 printf("Unknown parameter\n");
2148                 return;
2149         }
2150
2151         if (isstart && isrx)
2152                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2153         else if (!isstart && isrx)
2154                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2155         else if (isstart && !isrx)
2156                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2157         else
2158                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2159
2160         if (ret == -ENOTSUP)
2161                 printf("Function not supported in PMD driver\n");
2162 }
2163
2164 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2165         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2166 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2167         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2168 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2170 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2171         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2172 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2173         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2174                                                 "start#stop");
2175
2176 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2177         .f = cmd_config_rxtx_queue_parsed,
2178         .data = NULL,
2179         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2180         .tokens = {
2181                 (void *)&cmd_config_speed_all_port,
2182                 (void *)&cmd_config_rxtx_queue_portid,
2183                 (void *)&cmd_config_rxtx_queue_rxtxq,
2184                 (void *)&cmd_config_rxtx_queue_qid,
2185                 (void *)&cmd_config_rxtx_queue_opname,
2186                 NULL,
2187         },
2188 };
2189
2190 /* *** Configure RSS RETA *** */
2191 struct cmd_config_rss_reta {
2192         cmdline_fixed_string_t port;
2193         cmdline_fixed_string_t keyword;
2194         portid_t port_id;
2195         cmdline_fixed_string_t name;
2196         cmdline_fixed_string_t list_name;
2197         cmdline_fixed_string_t list_of_items;
2198 };
2199
2200 static int
2201 parse_reta_config(const char *str,
2202                   struct rte_eth_rss_reta_entry64 *reta_conf,
2203                   uint16_t nb_entries)
2204 {
2205         int i;
2206         unsigned size;
2207         uint16_t hash_index, idx, shift;
2208         uint16_t nb_queue;
2209         char s[256];
2210         const char *p, *p0 = str;
2211         char *end;
2212         enum fieldnames {
2213                 FLD_HASH_INDEX = 0,
2214                 FLD_QUEUE,
2215                 _NUM_FLD
2216         };
2217         unsigned long int_fld[_NUM_FLD];
2218         char *str_fld[_NUM_FLD];
2219
2220         while ((p = strchr(p0,'(')) != NULL) {
2221                 ++p;
2222                 if((p0 = strchr(p,')')) == NULL)
2223                         return -1;
2224
2225                 size = p0 - p;
2226                 if(size >= sizeof(s))
2227                         return -1;
2228
2229                 snprintf(s, sizeof(s), "%.*s", size, p);
2230                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2231                         return -1;
2232                 for (i = 0; i < _NUM_FLD; i++) {
2233                         errno = 0;
2234                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2235                         if (errno != 0 || end == str_fld[i] ||
2236                                         int_fld[i] > 65535)
2237                                 return -1;
2238                 }
2239
2240                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2241                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2242
2243                 if (hash_index >= nb_entries) {
2244                         printf("Invalid RETA hash index=%d\n", hash_index);
2245                         return -1;
2246                 }
2247
2248                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2249                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2250                 reta_conf[idx].mask |= (1ULL << shift);
2251                 reta_conf[idx].reta[shift] = nb_queue;
2252         }
2253
2254         return 0;
2255 }
2256
2257 static void
2258 cmd_set_rss_reta_parsed(void *parsed_result,
2259                         __attribute__((unused)) struct cmdline *cl,
2260                         __attribute__((unused)) void *data)
2261 {
2262         int ret;
2263         struct rte_eth_dev_info dev_info;
2264         struct rte_eth_rss_reta_entry64 reta_conf[8];
2265         struct cmd_config_rss_reta *res = parsed_result;
2266
2267         memset(&dev_info, 0, sizeof(dev_info));
2268         rte_eth_dev_info_get(res->port_id, &dev_info);
2269         if (dev_info.reta_size == 0) {
2270                 printf("Redirection table size is 0 which is "
2271                                         "invalid for RSS\n");
2272                 return;
2273         } else
2274                 printf("The reta size of port %d is %u\n",
2275                         res->port_id, dev_info.reta_size);
2276         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2277                 printf("Currently do not support more than %u entries of "
2278                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2279                 return;
2280         }
2281
2282         memset(reta_conf, 0, sizeof(reta_conf));
2283         if (!strcmp(res->list_name, "reta")) {
2284                 if (parse_reta_config(res->list_of_items, reta_conf,
2285                                                 dev_info.reta_size)) {
2286                         printf("Invalid RSS Redirection Table "
2287                                         "config entered\n");
2288                         return;
2289                 }
2290                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2291                                 reta_conf, dev_info.reta_size);
2292                 if (ret != 0)
2293                         printf("Bad redirection table parameter, "
2294                                         "return code = %d \n", ret);
2295         }
2296 }
2297
2298 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2300 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2302 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2303         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2304 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2306 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2307         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2308 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2309         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2310                                  NULL);
2311 cmdline_parse_inst_t cmd_config_rss_reta = {
2312         .f = cmd_set_rss_reta_parsed,
2313         .data = NULL,
2314         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2315         .tokens = {
2316                 (void *)&cmd_config_rss_reta_port,
2317                 (void *)&cmd_config_rss_reta_keyword,
2318                 (void *)&cmd_config_rss_reta_port_id,
2319                 (void *)&cmd_config_rss_reta_name,
2320                 (void *)&cmd_config_rss_reta_list_name,
2321                 (void *)&cmd_config_rss_reta_list_of_items,
2322                 NULL,
2323         },
2324 };
2325
2326 /* *** SHOW PORT RETA INFO *** */
2327 struct cmd_showport_reta {
2328         cmdline_fixed_string_t show;
2329         cmdline_fixed_string_t port;
2330         portid_t port_id;
2331         cmdline_fixed_string_t rss;
2332         cmdline_fixed_string_t reta;
2333         uint16_t size;
2334         cmdline_fixed_string_t list_of_items;
2335 };
2336
2337 static int
2338 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2339                            uint16_t nb_entries,
2340                            char *str)
2341 {
2342         uint32_t size;
2343         const char *p, *p0 = str;
2344         char s[256];
2345         char *end;
2346         char *str_fld[8];
2347         uint16_t i;
2348         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2349                         RTE_RETA_GROUP_SIZE;
2350         int ret;
2351
2352         p = strchr(p0, '(');
2353         if (p == NULL)
2354                 return -1;
2355         p++;
2356         p0 = strchr(p, ')');
2357         if (p0 == NULL)
2358                 return -1;
2359         size = p0 - p;
2360         if (size >= sizeof(s)) {
2361                 printf("The string size exceeds the internal buffer size\n");
2362                 return -1;
2363         }
2364         snprintf(s, sizeof(s), "%.*s", size, p);
2365         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2366         if (ret <= 0 || ret != num) {
2367                 printf("The bits of masks do not match the number of "
2368                                         "reta entries: %u\n", num);
2369                 return -1;
2370         }
2371         for (i = 0; i < ret; i++)
2372                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2373
2374         return 0;
2375 }
2376
2377 static void
2378 cmd_showport_reta_parsed(void *parsed_result,
2379                          __attribute__((unused)) struct cmdline *cl,
2380                          __attribute__((unused)) void *data)
2381 {
2382         struct cmd_showport_reta *res = parsed_result;
2383         struct rte_eth_rss_reta_entry64 reta_conf[8];
2384         struct rte_eth_dev_info dev_info;
2385         uint16_t max_reta_size;
2386
2387         memset(&dev_info, 0, sizeof(dev_info));
2388         rte_eth_dev_info_get(res->port_id, &dev_info);
2389         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2390         if (res->size == 0 || res->size > max_reta_size) {
2391                 printf("Invalid redirection table size: %u (1-%u)\n",
2392                         res->size, max_reta_size);
2393                 return;
2394         }
2395
2396         memset(reta_conf, 0, sizeof(reta_conf));
2397         if (showport_parse_reta_config(reta_conf, res->size,
2398                                 res->list_of_items) < 0) {
2399                 printf("Invalid string: %s for reta masks\n",
2400                                         res->list_of_items);
2401                 return;
2402         }
2403         port_rss_reta_info(res->port_id, reta_conf, res->size);
2404 }
2405
2406 cmdline_parse_token_string_t cmd_showport_reta_show =
2407         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2408 cmdline_parse_token_string_t cmd_showport_reta_port =
2409         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2410 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2411         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2412 cmdline_parse_token_string_t cmd_showport_reta_rss =
2413         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2414 cmdline_parse_token_string_t cmd_showport_reta_reta =
2415         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2416 cmdline_parse_token_num_t cmd_showport_reta_size =
2417         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2418 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2419         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2420                                         list_of_items, NULL);
2421
2422 cmdline_parse_inst_t cmd_showport_reta = {
2423         .f = cmd_showport_reta_parsed,
2424         .data = NULL,
2425         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2426         .tokens = {
2427                 (void *)&cmd_showport_reta_show,
2428                 (void *)&cmd_showport_reta_port,
2429                 (void *)&cmd_showport_reta_port_id,
2430                 (void *)&cmd_showport_reta_rss,
2431                 (void *)&cmd_showport_reta_reta,
2432                 (void *)&cmd_showport_reta_size,
2433                 (void *)&cmd_showport_reta_list_of_items,
2434                 NULL,
2435         },
2436 };
2437
2438 /* *** Show RSS hash configuration *** */
2439 struct cmd_showport_rss_hash {
2440         cmdline_fixed_string_t show;
2441         cmdline_fixed_string_t port;
2442         portid_t port_id;
2443         cmdline_fixed_string_t rss_hash;
2444         cmdline_fixed_string_t rss_type;
2445         cmdline_fixed_string_t key; /* optional argument */
2446 };
2447
2448 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2449                                 __attribute__((unused)) struct cmdline *cl,
2450                                 void *show_rss_key)
2451 {
2452         struct cmd_showport_rss_hash *res = parsed_result;
2453
2454         port_rss_hash_conf_show(res->port_id, res->rss_type,
2455                                 show_rss_key != NULL);
2456 }
2457
2458 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2459         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2460 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2461         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2462 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2463         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2464 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2465         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2466                                  "rss-hash");
2467 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2468         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2469                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2470                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2471                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2472                                  "ipv6-tcp-ex#ipv6-udp-ex");
2473 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2474         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2475
2476 cmdline_parse_inst_t cmd_showport_rss_hash = {
2477         .f = cmd_showport_rss_hash_parsed,
2478         .data = NULL,
2479         .help_str = "show port <port_id> rss-hash "
2480                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2481                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2482                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2483         .tokens = {
2484                 (void *)&cmd_showport_rss_hash_show,
2485                 (void *)&cmd_showport_rss_hash_port,
2486                 (void *)&cmd_showport_rss_hash_port_id,
2487                 (void *)&cmd_showport_rss_hash_rss_hash,
2488                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2489                 NULL,
2490         },
2491 };
2492
2493 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2494         .f = cmd_showport_rss_hash_parsed,
2495         .data = (void *)1,
2496         .help_str = "show port <port_id> rss-hash "
2497                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2498                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2499                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2500         .tokens = {
2501                 (void *)&cmd_showport_rss_hash_show,
2502                 (void *)&cmd_showport_rss_hash_port,
2503                 (void *)&cmd_showport_rss_hash_port_id,
2504                 (void *)&cmd_showport_rss_hash_rss_hash,
2505                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2506                 (void *)&cmd_showport_rss_hash_rss_key,
2507                 NULL,
2508         },
2509 };
2510
2511 /* *** Configure DCB *** */
2512 struct cmd_config_dcb {
2513         cmdline_fixed_string_t port;
2514         cmdline_fixed_string_t config;
2515         portid_t port_id;
2516         cmdline_fixed_string_t dcb;
2517         cmdline_fixed_string_t vt;
2518         cmdline_fixed_string_t vt_en;
2519         uint8_t num_tcs;
2520         cmdline_fixed_string_t pfc;
2521         cmdline_fixed_string_t pfc_en;
2522 };
2523
2524 static void
2525 cmd_config_dcb_parsed(void *parsed_result,
2526                         __attribute__((unused)) struct cmdline *cl,
2527                         __attribute__((unused)) void *data)
2528 {
2529         struct cmd_config_dcb *res = parsed_result;
2530         portid_t port_id = res->port_id;
2531         struct rte_port *port;
2532         uint8_t pfc_en;
2533         int ret;
2534
2535         port = &ports[port_id];
2536         /** Check if the port is not started **/
2537         if (port->port_status != RTE_PORT_STOPPED) {
2538                 printf("Please stop port %d first\n", port_id);
2539                 return;
2540         }
2541
2542         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2543                 printf("The invalid number of traffic class,"
2544                         " only 4 or 8 allowed.\n");
2545                 return;
2546         }
2547
2548         if (nb_fwd_lcores < res->num_tcs) {
2549                 printf("nb_cores shouldn't be less than number of TCs.\n");
2550                 return;
2551         }
2552         if (!strncmp(res->pfc_en, "on", 2))
2553                 pfc_en = 1;
2554         else
2555                 pfc_en = 0;
2556
2557         /* DCB in VT mode */
2558         if (!strncmp(res->vt_en, "on", 2))
2559                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2560                                 (enum rte_eth_nb_tcs)res->num_tcs,
2561                                 pfc_en);
2562         else
2563                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2564                                 (enum rte_eth_nb_tcs)res->num_tcs,
2565                                 pfc_en);
2566
2567
2568         if (ret != 0) {
2569                 printf("Cannot initialize network ports.\n");
2570                 return;
2571         }
2572
2573         cmd_reconfig_device_queue(port_id, 1, 1);
2574 }
2575
2576 cmdline_parse_token_string_t cmd_config_dcb_port =
2577         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2578 cmdline_parse_token_string_t cmd_config_dcb_config =
2579         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2580 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2581         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2582 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2584 cmdline_parse_token_string_t cmd_config_dcb_vt =
2585         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2586 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2587         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2588 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2589         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2590 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2591         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2592 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2593         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2594
2595 cmdline_parse_inst_t cmd_config_dcb = {
2596         .f = cmd_config_dcb_parsed,
2597         .data = NULL,
2598         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2599         .tokens = {
2600                 (void *)&cmd_config_dcb_port,
2601                 (void *)&cmd_config_dcb_config,
2602                 (void *)&cmd_config_dcb_port_id,
2603                 (void *)&cmd_config_dcb_dcb,
2604                 (void *)&cmd_config_dcb_vt,
2605                 (void *)&cmd_config_dcb_vt_en,
2606                 (void *)&cmd_config_dcb_num_tcs,
2607                 (void *)&cmd_config_dcb_pfc,
2608                 (void *)&cmd_config_dcb_pfc_en,
2609                 NULL,
2610         },
2611 };
2612
2613 /* *** configure number of packets per burst *** */
2614 struct cmd_config_burst {
2615         cmdline_fixed_string_t port;
2616         cmdline_fixed_string_t keyword;
2617         cmdline_fixed_string_t all;
2618         cmdline_fixed_string_t name;
2619         uint16_t value;
2620 };
2621
2622 static void
2623 cmd_config_burst_parsed(void *parsed_result,
2624                         __attribute__((unused)) struct cmdline *cl,
2625                         __attribute__((unused)) void *data)
2626 {
2627         struct cmd_config_burst *res = parsed_result;
2628
2629         if (!all_ports_stopped()) {
2630                 printf("Please stop all ports first\n");
2631                 return;
2632         }
2633
2634         if (!strcmp(res->name, "burst")) {
2635                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2636                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2637                         return;
2638                 }
2639                 nb_pkt_per_burst = res->value;
2640         } else {
2641                 printf("Unknown parameter\n");
2642                 return;
2643         }
2644
2645         init_port_config();
2646
2647         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2648 }
2649
2650 cmdline_parse_token_string_t cmd_config_burst_port =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2652 cmdline_parse_token_string_t cmd_config_burst_keyword =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2654 cmdline_parse_token_string_t cmd_config_burst_all =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2656 cmdline_parse_token_string_t cmd_config_burst_name =
2657         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2658 cmdline_parse_token_num_t cmd_config_burst_value =
2659         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2660
2661 cmdline_parse_inst_t cmd_config_burst = {
2662         .f = cmd_config_burst_parsed,
2663         .data = NULL,
2664         .help_str = "port config all burst <value>",
2665         .tokens = {
2666                 (void *)&cmd_config_burst_port,
2667                 (void *)&cmd_config_burst_keyword,
2668                 (void *)&cmd_config_burst_all,
2669                 (void *)&cmd_config_burst_name,
2670                 (void *)&cmd_config_burst_value,
2671                 NULL,
2672         },
2673 };
2674
2675 /* *** configure rx/tx queues *** */
2676 struct cmd_config_thresh {
2677         cmdline_fixed_string_t port;
2678         cmdline_fixed_string_t keyword;
2679         cmdline_fixed_string_t all;
2680         cmdline_fixed_string_t name;
2681         uint8_t value;
2682 };
2683
2684 static void
2685 cmd_config_thresh_parsed(void *parsed_result,
2686                         __attribute__((unused)) struct cmdline *cl,
2687                         __attribute__((unused)) void *data)
2688 {
2689         struct cmd_config_thresh *res = parsed_result;
2690
2691         if (!all_ports_stopped()) {
2692                 printf("Please stop all ports first\n");
2693                 return;
2694         }
2695
2696         if (!strcmp(res->name, "txpt"))
2697                 tx_pthresh = res->value;
2698         else if(!strcmp(res->name, "txht"))
2699                 tx_hthresh = res->value;
2700         else if(!strcmp(res->name, "txwt"))
2701                 tx_wthresh = res->value;
2702         else if(!strcmp(res->name, "rxpt"))
2703                 rx_pthresh = res->value;
2704         else if(!strcmp(res->name, "rxht"))
2705                 rx_hthresh = res->value;
2706         else if(!strcmp(res->name, "rxwt"))
2707                 rx_wthresh = res->value;
2708         else {
2709                 printf("Unknown parameter\n");
2710                 return;
2711         }
2712
2713         init_port_config();
2714
2715         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2716 }
2717
2718 cmdline_parse_token_string_t cmd_config_thresh_port =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2720 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2721         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2722 cmdline_parse_token_string_t cmd_config_thresh_all =
2723         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2724 cmdline_parse_token_string_t cmd_config_thresh_name =
2725         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2726                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2727 cmdline_parse_token_num_t cmd_config_thresh_value =
2728         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2729
2730 cmdline_parse_inst_t cmd_config_thresh = {
2731         .f = cmd_config_thresh_parsed,
2732         .data = NULL,
2733         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2734         .tokens = {
2735                 (void *)&cmd_config_thresh_port,
2736                 (void *)&cmd_config_thresh_keyword,
2737                 (void *)&cmd_config_thresh_all,
2738                 (void *)&cmd_config_thresh_name,
2739                 (void *)&cmd_config_thresh_value,
2740                 NULL,
2741         },
2742 };
2743
2744 /* *** configure free/rs threshold *** */
2745 struct cmd_config_threshold {
2746         cmdline_fixed_string_t port;
2747         cmdline_fixed_string_t keyword;
2748         cmdline_fixed_string_t all;
2749         cmdline_fixed_string_t name;
2750         uint16_t value;
2751 };
2752
2753 static void
2754 cmd_config_threshold_parsed(void *parsed_result,
2755                         __attribute__((unused)) struct cmdline *cl,
2756                         __attribute__((unused)) void *data)
2757 {
2758         struct cmd_config_threshold *res = parsed_result;
2759
2760         if (!all_ports_stopped()) {
2761                 printf("Please stop all ports first\n");
2762                 return;
2763         }
2764
2765         if (!strcmp(res->name, "txfreet"))
2766                 tx_free_thresh = res->value;
2767         else if (!strcmp(res->name, "txrst"))
2768                 tx_rs_thresh = res->value;
2769         else if (!strcmp(res->name, "rxfreet"))
2770                 rx_free_thresh = res->value;
2771         else {
2772                 printf("Unknown parameter\n");
2773                 return;
2774         }
2775
2776         init_port_config();
2777
2778         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2779 }
2780
2781 cmdline_parse_token_string_t cmd_config_threshold_port =
2782         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2783 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2784         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2785                                                                 "config");
2786 cmdline_parse_token_string_t cmd_config_threshold_all =
2787         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2788 cmdline_parse_token_string_t cmd_config_threshold_name =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2790                                                 "txfreet#txrst#rxfreet");
2791 cmdline_parse_token_num_t cmd_config_threshold_value =
2792         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2793
2794 cmdline_parse_inst_t cmd_config_threshold = {
2795         .f = cmd_config_threshold_parsed,
2796         .data = NULL,
2797         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2798         .tokens = {
2799                 (void *)&cmd_config_threshold_port,
2800                 (void *)&cmd_config_threshold_keyword,
2801                 (void *)&cmd_config_threshold_all,
2802                 (void *)&cmd_config_threshold_name,
2803                 (void *)&cmd_config_threshold_value,
2804                 NULL,
2805         },
2806 };
2807
2808 /* *** stop *** */
2809 struct cmd_stop_result {
2810         cmdline_fixed_string_t stop;
2811 };
2812
2813 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2814                             __attribute__((unused)) struct cmdline *cl,
2815                             __attribute__((unused)) void *data)
2816 {
2817         stop_packet_forwarding();
2818 }
2819
2820 cmdline_parse_token_string_t cmd_stop_stop =
2821         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2822
2823 cmdline_parse_inst_t cmd_stop = {
2824         .f = cmd_stop_parsed,
2825         .data = NULL,
2826         .help_str = "stop: Stop packet forwarding",
2827         .tokens = {
2828                 (void *)&cmd_stop_stop,
2829                 NULL,
2830         },
2831 };
2832
2833 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2834
2835 unsigned int
2836 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2837                 unsigned int *parsed_items, int check_unique_values)
2838 {
2839         unsigned int nb_item;
2840         unsigned int value;
2841         unsigned int i;
2842         unsigned int j;
2843         int value_ok;
2844         char c;
2845
2846         /*
2847          * First parse all items in the list and store their value.
2848          */
2849         value = 0;
2850         nb_item = 0;
2851         value_ok = 0;
2852         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2853                 c = str[i];
2854                 if ((c >= '0') && (c <= '9')) {
2855                         value = (unsigned int) (value * 10 + (c - '0'));
2856                         value_ok = 1;
2857                         continue;
2858                 }
2859                 if (c != ',') {
2860                         printf("character %c is not a decimal digit\n", c);
2861                         return 0;
2862                 }
2863                 if (! value_ok) {
2864                         printf("No valid value before comma\n");
2865                         return 0;
2866                 }
2867                 if (nb_item < max_items) {
2868                         parsed_items[nb_item] = value;
2869                         value_ok = 0;
2870                         value = 0;
2871                 }
2872                 nb_item++;
2873         }
2874         if (nb_item >= max_items) {
2875                 printf("Number of %s = %u > %u (maximum items)\n",
2876                        item_name, nb_item + 1, max_items);
2877                 return 0;
2878         }
2879         parsed_items[nb_item++] = value;
2880         if (! check_unique_values)
2881                 return nb_item;
2882
2883         /*
2884          * Then, check that all values in the list are differents.
2885          * No optimization here...
2886          */
2887         for (i = 0; i < nb_item; i++) {
2888                 for (j = i + 1; j < nb_item; j++) {
2889                         if (parsed_items[j] == parsed_items[i]) {
2890                                 printf("duplicated %s %u at index %u and %u\n",
2891                                        item_name, parsed_items[i], i, j);
2892                                 return 0;
2893                         }
2894                 }
2895         }
2896         return nb_item;
2897 }
2898
2899 struct cmd_set_list_result {
2900         cmdline_fixed_string_t cmd_keyword;
2901         cmdline_fixed_string_t list_name;
2902         cmdline_fixed_string_t list_of_items;
2903 };
2904
2905 static void cmd_set_list_parsed(void *parsed_result,
2906                                 __attribute__((unused)) struct cmdline *cl,
2907                                 __attribute__((unused)) void *data)
2908 {
2909         struct cmd_set_list_result *res;
2910         union {
2911                 unsigned int lcorelist[RTE_MAX_LCORE];
2912                 unsigned int portlist[RTE_MAX_ETHPORTS];
2913         } parsed_items;
2914         unsigned int nb_item;
2915
2916         if (test_done == 0) {
2917                 printf("Please stop forwarding first\n");
2918                 return;
2919         }
2920
2921         res = parsed_result;
2922         if (!strcmp(res->list_name, "corelist")) {
2923                 nb_item = parse_item_list(res->list_of_items, "core",
2924                                           RTE_MAX_LCORE,
2925                                           parsed_items.lcorelist, 1);
2926                 if (nb_item > 0) {
2927                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2928                         fwd_config_setup();
2929                 }
2930                 return;
2931         }
2932         if (!strcmp(res->list_name, "portlist")) {
2933                 nb_item = parse_item_list(res->list_of_items, "port",
2934                                           RTE_MAX_ETHPORTS,
2935                                           parsed_items.portlist, 1);
2936                 if (nb_item > 0) {
2937                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2938                         fwd_config_setup();
2939                 }
2940         }
2941 }
2942
2943 cmdline_parse_token_string_t cmd_set_list_keyword =
2944         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2945                                  "set");
2946 cmdline_parse_token_string_t cmd_set_list_name =
2947         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2948                                  "corelist#portlist");
2949 cmdline_parse_token_string_t cmd_set_list_of_items =
2950         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2951                                  NULL);
2952
2953 cmdline_parse_inst_t cmd_set_fwd_list = {
2954         .f = cmd_set_list_parsed,
2955         .data = NULL,
2956         .help_str = "set corelist|portlist <list0[,list1]*>",
2957         .tokens = {
2958                 (void *)&cmd_set_list_keyword,
2959                 (void *)&cmd_set_list_name,
2960                 (void *)&cmd_set_list_of_items,
2961                 NULL,
2962         },
2963 };
2964
2965 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2966
2967 struct cmd_setmask_result {
2968         cmdline_fixed_string_t set;
2969         cmdline_fixed_string_t mask;
2970         uint64_t hexavalue;
2971 };
2972
2973 static void cmd_set_mask_parsed(void *parsed_result,
2974                                 __attribute__((unused)) struct cmdline *cl,
2975                                 __attribute__((unused)) void *data)
2976 {
2977         struct cmd_setmask_result *res = parsed_result;
2978
2979         if (test_done == 0) {
2980                 printf("Please stop forwarding first\n");
2981                 return;
2982         }
2983         if (!strcmp(res->mask, "coremask")) {
2984                 set_fwd_lcores_mask(res->hexavalue);
2985                 fwd_config_setup();
2986         } else if (!strcmp(res->mask, "portmask")) {
2987                 set_fwd_ports_mask(res->hexavalue);
2988                 fwd_config_setup();
2989         }
2990 }
2991
2992 cmdline_parse_token_string_t cmd_setmask_set =
2993         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2994 cmdline_parse_token_string_t cmd_setmask_mask =
2995         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2996                                  "coremask#portmask");
2997 cmdline_parse_token_num_t cmd_setmask_value =
2998         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2999
3000 cmdline_parse_inst_t cmd_set_fwd_mask = {
3001         .f = cmd_set_mask_parsed,
3002         .data = NULL,
3003         .help_str = "set coremask|portmask <hexadecimal value>",
3004         .tokens = {
3005                 (void *)&cmd_setmask_set,
3006                 (void *)&cmd_setmask_mask,
3007                 (void *)&cmd_setmask_value,
3008                 NULL,
3009         },
3010 };
3011
3012 /*
3013  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3014  */
3015 struct cmd_set_result {
3016         cmdline_fixed_string_t set;
3017         cmdline_fixed_string_t what;
3018         uint16_t value;
3019 };
3020
3021 static void cmd_set_parsed(void *parsed_result,
3022                            __attribute__((unused)) struct cmdline *cl,
3023                            __attribute__((unused)) void *data)
3024 {
3025         struct cmd_set_result *res = parsed_result;
3026         if (!strcmp(res->what, "nbport")) {
3027                 set_fwd_ports_number(res->value);
3028                 fwd_config_setup();
3029         } else if (!strcmp(res->what, "nbcore")) {
3030                 set_fwd_lcores_number(res->value);
3031                 fwd_config_setup();
3032         } else if (!strcmp(res->what, "burst"))
3033                 set_nb_pkt_per_burst(res->value);
3034         else if (!strcmp(res->what, "verbose"))
3035                 set_verbose_level(res->value);
3036 }
3037
3038 cmdline_parse_token_string_t cmd_set_set =
3039         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3040 cmdline_parse_token_string_t cmd_set_what =
3041         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3042                                  "nbport#nbcore#burst#verbose");
3043 cmdline_parse_token_num_t cmd_set_value =
3044         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3045
3046 cmdline_parse_inst_t cmd_set_numbers = {
3047         .f = cmd_set_parsed,
3048         .data = NULL,
3049         .help_str = "set nbport|nbcore|burst|verbose <value>",
3050         .tokens = {
3051                 (void *)&cmd_set_set,
3052                 (void *)&cmd_set_what,
3053                 (void *)&cmd_set_value,
3054                 NULL,
3055         },
3056 };
3057
3058 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3059
3060 struct cmd_set_txpkts_result {
3061         cmdline_fixed_string_t cmd_keyword;
3062         cmdline_fixed_string_t txpkts;
3063         cmdline_fixed_string_t seg_lengths;
3064 };
3065
3066 static void
3067 cmd_set_txpkts_parsed(void *parsed_result,
3068                       __attribute__((unused)) struct cmdline *cl,
3069                       __attribute__((unused)) void *data)
3070 {
3071         struct cmd_set_txpkts_result *res;
3072         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3073         unsigned int nb_segs;
3074
3075         res = parsed_result;
3076         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3077                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3078         if (nb_segs > 0)
3079                 set_tx_pkt_segments(seg_lengths, nb_segs);
3080 }
3081
3082 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3083         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3084                                  cmd_keyword, "set");
3085 cmdline_parse_token_string_t cmd_set_txpkts_name =
3086         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3087                                  txpkts, "txpkts");
3088 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3089         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3090                                  seg_lengths, NULL);
3091
3092 cmdline_parse_inst_t cmd_set_txpkts = {
3093         .f = cmd_set_txpkts_parsed,
3094         .data = NULL,
3095         .help_str = "set txpkts <len0[,len1]*>",
3096         .tokens = {
3097                 (void *)&cmd_set_txpkts_keyword,
3098                 (void *)&cmd_set_txpkts_name,
3099                 (void *)&cmd_set_txpkts_lengths,
3100                 NULL,
3101         },
3102 };
3103
3104 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3105
3106 struct cmd_set_txsplit_result {
3107         cmdline_fixed_string_t cmd_keyword;
3108         cmdline_fixed_string_t txsplit;
3109         cmdline_fixed_string_t mode;
3110 };
3111
3112 static void
3113 cmd_set_txsplit_parsed(void *parsed_result,
3114                       __attribute__((unused)) struct cmdline *cl,
3115                       __attribute__((unused)) void *data)
3116 {
3117         struct cmd_set_txsplit_result *res;
3118
3119         res = parsed_result;
3120         set_tx_pkt_split(res->mode);
3121 }
3122
3123 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3124         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3125                                  cmd_keyword, "set");
3126 cmdline_parse_token_string_t cmd_set_txsplit_name =
3127         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3128                                  txsplit, "txsplit");
3129 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3130         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3131                                  mode, NULL);
3132
3133 cmdline_parse_inst_t cmd_set_txsplit = {
3134         .f = cmd_set_txsplit_parsed,
3135         .data = NULL,
3136         .help_str = "set txsplit on|off|rand",
3137         .tokens = {
3138                 (void *)&cmd_set_txsplit_keyword,
3139                 (void *)&cmd_set_txsplit_name,
3140                 (void *)&cmd_set_txsplit_mode,
3141                 NULL,
3142         },
3143 };
3144
3145 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3146 struct cmd_rx_vlan_filter_all_result {
3147         cmdline_fixed_string_t rx_vlan;
3148         cmdline_fixed_string_t what;
3149         cmdline_fixed_string_t all;
3150         portid_t port_id;
3151 };
3152
3153 static void
3154 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3155                               __attribute__((unused)) struct cmdline *cl,
3156                               __attribute__((unused)) void *data)
3157 {
3158         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3159
3160         if (!strcmp(res->what, "add"))
3161                 rx_vlan_all_filter_set(res->port_id, 1);
3162         else
3163                 rx_vlan_all_filter_set(res->port_id, 0);
3164 }
3165
3166 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3167         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3168                                  rx_vlan, "rx_vlan");
3169 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3170         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3171                                  what, "add#rm");
3172 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3173         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3174                                  all, "all");
3175 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3176         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3177                               port_id, UINT16);
3178
3179 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3180         .f = cmd_rx_vlan_filter_all_parsed,
3181         .data = NULL,
3182         .help_str = "rx_vlan add|rm all <port_id>: "
3183                 "Add/Remove all identifiers to/from the set of VLAN "
3184                 "identifiers filtered by a port",
3185         .tokens = {
3186                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3187                 (void *)&cmd_rx_vlan_filter_all_what,
3188                 (void *)&cmd_rx_vlan_filter_all_all,
3189                 (void *)&cmd_rx_vlan_filter_all_portid,
3190                 NULL,
3191         },
3192 };
3193
3194 /* *** VLAN OFFLOAD SET ON A PORT *** */
3195 struct cmd_vlan_offload_result {
3196         cmdline_fixed_string_t vlan;
3197         cmdline_fixed_string_t set;
3198         cmdline_fixed_string_t vlan_type;
3199         cmdline_fixed_string_t what;
3200         cmdline_fixed_string_t on;
3201         cmdline_fixed_string_t port_id;
3202 };
3203
3204 static void
3205 cmd_vlan_offload_parsed(void *parsed_result,
3206                           __attribute__((unused)) struct cmdline *cl,
3207                           __attribute__((unused)) void *data)
3208 {
3209         int on;
3210         struct cmd_vlan_offload_result *res = parsed_result;
3211         char *str;
3212         int i, len = 0;
3213         portid_t port_id = 0;
3214         unsigned int tmp;
3215
3216         str = res->port_id;
3217         len = strnlen(str, STR_TOKEN_SIZE);
3218         i = 0;
3219         /* Get port_id first */
3220         while(i < len){
3221                 if(str[i] == ',')
3222                         break;
3223
3224                 i++;
3225         }
3226         str[i]='\0';
3227         tmp = strtoul(str, NULL, 0);
3228         /* If port_id greater that what portid_t can represent, return */
3229         if(tmp >= RTE_MAX_ETHPORTS)
3230                 return;
3231         port_id = (portid_t)tmp;
3232
3233         if (!strcmp(res->on, "on"))
3234                 on = 1;
3235         else
3236                 on = 0;
3237
3238         if (!strcmp(res->what, "strip"))
3239                 rx_vlan_strip_set(port_id,  on);
3240         else if(!strcmp(res->what, "stripq")){
3241                 uint16_t queue_id = 0;
3242
3243                 /* No queue_id, return */
3244                 if(i + 1 >= len) {
3245                         printf("must specify (port,queue_id)\n");
3246                         return;
3247                 }
3248                 tmp = strtoul(str + i + 1, NULL, 0);
3249                 /* If queue_id greater that what 16-bits can represent, return */
3250                 if(tmp > 0xffff)
3251                         return;
3252
3253                 queue_id = (uint16_t)tmp;
3254                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3255         }
3256         else if (!strcmp(res->what, "filter"))
3257                 rx_vlan_filter_set(port_id, on);
3258         else
3259                 vlan_extend_set(port_id, on);
3260
3261         return;
3262 }
3263
3264 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3265         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3266                                  vlan, "vlan");
3267 cmdline_parse_token_string_t cmd_vlan_offload_set =
3268         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3269                                  set, "set");
3270 cmdline_parse_token_string_t cmd_vlan_offload_what =
3271         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3272                                  what, "strip#filter#qinq#stripq");
3273 cmdline_parse_token_string_t cmd_vlan_offload_on =
3274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3275                               on, "on#off");
3276 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3278                               port_id, NULL);
3279
3280 cmdline_parse_inst_t cmd_vlan_offload = {
3281         .f = cmd_vlan_offload_parsed,
3282         .data = NULL,
3283         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3284                 "<port_id[,queue_id]>: "
3285                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3286         .tokens = {
3287                 (void *)&cmd_vlan_offload_vlan,
3288                 (void *)&cmd_vlan_offload_set,
3289                 (void *)&cmd_vlan_offload_what,
3290                 (void *)&cmd_vlan_offload_on,
3291                 (void *)&cmd_vlan_offload_portid,
3292                 NULL,
3293         },
3294 };
3295
3296 /* *** VLAN TPID SET ON A PORT *** */
3297 struct cmd_vlan_tpid_result {
3298         cmdline_fixed_string_t vlan;
3299         cmdline_fixed_string_t set;
3300         cmdline_fixed_string_t vlan_type;
3301         cmdline_fixed_string_t what;
3302         uint16_t tp_id;
3303         portid_t port_id;
3304 };
3305
3306 static void
3307 cmd_vlan_tpid_parsed(void *parsed_result,
3308                           __attribute__((unused)) struct cmdline *cl,
3309                           __attribute__((unused)) void *data)
3310 {
3311         struct cmd_vlan_tpid_result *res = parsed_result;
3312         enum rte_vlan_type vlan_type;
3313
3314         if (!strcmp(res->vlan_type, "inner"))
3315                 vlan_type = ETH_VLAN_TYPE_INNER;
3316         else if (!strcmp(res->vlan_type, "outer"))
3317                 vlan_type = ETH_VLAN_TYPE_OUTER;
3318         else {
3319                 printf("Unknown vlan type\n");
3320                 return;
3321         }
3322         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3323 }
3324
3325 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3326         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3327                                  vlan, "vlan");
3328 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3329         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3330                                  set, "set");
3331 cmdline_parse_token_string_t cmd_vlan_type =
3332         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3333                                  vlan_type, "inner#outer");
3334 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3336                                  what, "tpid");
3337 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3338         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3339                               tp_id, UINT16);
3340 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3341         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3342                               port_id, UINT16);
3343
3344 cmdline_parse_inst_t cmd_vlan_tpid = {
3345         .f = cmd_vlan_tpid_parsed,
3346         .data = NULL,
3347         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3348                 "Set the VLAN Ether type",
3349         .tokens = {
3350                 (void *)&cmd_vlan_tpid_vlan,
3351                 (void *)&cmd_vlan_tpid_set,
3352                 (void *)&cmd_vlan_type,
3353                 (void *)&cmd_vlan_tpid_what,
3354                 (void *)&cmd_vlan_tpid_tpid,
3355                 (void *)&cmd_vlan_tpid_portid,
3356                 NULL,
3357         },
3358 };
3359
3360 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3361 struct cmd_rx_vlan_filter_result {
3362         cmdline_fixed_string_t rx_vlan;
3363         cmdline_fixed_string_t what;
3364         uint16_t vlan_id;
3365         portid_t port_id;
3366 };
3367
3368 static void
3369 cmd_rx_vlan_filter_parsed(void *parsed_result,
3370                           __attribute__((unused)) struct cmdline *cl,
3371                           __attribute__((unused)) void *data)
3372 {
3373         struct cmd_rx_vlan_filter_result *res = parsed_result;
3374
3375         if (!strcmp(res->what, "add"))
3376                 rx_vft_set(res->port_id, res->vlan_id, 1);
3377         else
3378                 rx_vft_set(res->port_id, res->vlan_id, 0);
3379 }
3380
3381 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3382         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3383                                  rx_vlan, "rx_vlan");
3384 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3385         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3386                                  what, "add#rm");
3387 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3388         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3389                               vlan_id, UINT16);
3390 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3391         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3392                               port_id, UINT16);
3393
3394 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3395         .f = cmd_rx_vlan_filter_parsed,
3396         .data = NULL,
3397         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3398                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3399                 "identifiers filtered by a port",
3400         .tokens = {
3401                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3402                 (void *)&cmd_rx_vlan_filter_what,
3403                 (void *)&cmd_rx_vlan_filter_vlanid,
3404                 (void *)&cmd_rx_vlan_filter_portid,
3405                 NULL,
3406         },
3407 };
3408
3409 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3410 struct cmd_tx_vlan_set_result {
3411         cmdline_fixed_string_t tx_vlan;
3412         cmdline_fixed_string_t set;
3413         portid_t port_id;
3414         uint16_t vlan_id;
3415 };
3416
3417 static void
3418 cmd_tx_vlan_set_parsed(void *parsed_result,
3419                        __attribute__((unused)) struct cmdline *cl,
3420                        __attribute__((unused)) void *data)
3421 {
3422         struct cmd_tx_vlan_set_result *res = parsed_result;
3423
3424         if (!port_is_stopped(res->port_id)) {
3425                 printf("Please stop port %d first\n", res->port_id);
3426                 return;
3427         }
3428
3429         tx_vlan_set(res->port_id, res->vlan_id);
3430
3431         cmd_reconfig_device_queue(res->port_id, 1, 1);
3432 }
3433
3434 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3435         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3436                                  tx_vlan, "tx_vlan");
3437 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3438         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3439                                  set, "set");
3440 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3441         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3442                               port_id, UINT16);
3443 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3444         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3445                               vlan_id, UINT16);
3446
3447 cmdline_parse_inst_t cmd_tx_vlan_set = {
3448         .f = cmd_tx_vlan_set_parsed,
3449         .data = NULL,
3450         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3451                 "Enable hardware insertion of a single VLAN header "
3452                 "with a given TAG Identifier in packets sent on a port",
3453         .tokens = {
3454                 (void *)&cmd_tx_vlan_set_tx_vlan,
3455                 (void *)&cmd_tx_vlan_set_set,
3456                 (void *)&cmd_tx_vlan_set_portid,
3457                 (void *)&cmd_tx_vlan_set_vlanid,
3458                 NULL,
3459         },
3460 };
3461
3462 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3463 struct cmd_tx_vlan_set_qinq_result {
3464         cmdline_fixed_string_t tx_vlan;
3465         cmdline_fixed_string_t set;
3466         portid_t port_id;
3467         uint16_t vlan_id;
3468         uint16_t vlan_id_outer;
3469 };
3470
3471 static void
3472 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3473                             __attribute__((unused)) struct cmdline *cl,
3474                             __attribute__((unused)) void *data)
3475 {
3476         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3477
3478         if (!port_is_stopped(res->port_id)) {
3479                 printf("Please stop port %d first\n", res->port_id);
3480                 return;
3481         }
3482
3483         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3484
3485         cmd_reconfig_device_queue(res->port_id, 1, 1);
3486 }
3487
3488 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3489         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3490                 tx_vlan, "tx_vlan");
3491 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3492         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3493                 set, "set");
3494 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3495         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3496                 port_id, UINT16);
3497 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3498         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3499                 vlan_id, UINT16);
3500 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3501         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3502                 vlan_id_outer, UINT16);
3503
3504 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3505         .f = cmd_tx_vlan_set_qinq_parsed,
3506         .data = NULL,
3507         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3508                 "Enable hardware insertion of double VLAN header "
3509                 "with given TAG Identifiers in packets sent on a port",
3510         .tokens = {
3511                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3512                 (void *)&cmd_tx_vlan_set_qinq_set,
3513                 (void *)&cmd_tx_vlan_set_qinq_portid,
3514                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3515                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3521 struct cmd_tx_vlan_set_pvid_result {
3522         cmdline_fixed_string_t tx_vlan;
3523         cmdline_fixed_string_t set;
3524         cmdline_fixed_string_t pvid;
3525         portid_t port_id;
3526         uint16_t vlan_id;
3527         cmdline_fixed_string_t mode;
3528 };
3529
3530 static void
3531 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3532                             __attribute__((unused)) struct cmdline *cl,
3533                             __attribute__((unused)) void *data)
3534 {
3535         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3536
3537         if (strcmp(res->mode, "on") == 0)
3538                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3539         else
3540                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3541 }
3542
3543 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3544         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3545                                  tx_vlan, "tx_vlan");
3546 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3547         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3548                                  set, "set");
3549 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3550         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3551                                  pvid, "pvid");
3552 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3553         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3554                              port_id, UINT16);
3555 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3556         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3557                               vlan_id, UINT16);
3558 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3559         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3560                                  mode, "on#off");
3561
3562 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3563         .f = cmd_tx_vlan_set_pvid_parsed,
3564         .data = NULL,
3565         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3566         .tokens = {
3567                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3568                 (void *)&cmd_tx_vlan_set_pvid_set,
3569                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3570                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3571                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3572                 (void *)&cmd_tx_vlan_set_pvid_mode,
3573                 NULL,
3574         },
3575 };
3576
3577 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3578 struct cmd_tx_vlan_reset_result {
3579         cmdline_fixed_string_t tx_vlan;
3580         cmdline_fixed_string_t reset;
3581         portid_t port_id;
3582 };
3583
3584 static void
3585 cmd_tx_vlan_reset_parsed(void *parsed_result,
3586                          __attribute__((unused)) struct cmdline *cl,
3587                          __attribute__((unused)) void *data)
3588 {
3589         struct cmd_tx_vlan_reset_result *res = parsed_result;
3590
3591         if (!port_is_stopped(res->port_id)) {
3592                 printf("Please stop port %d first\n", res->port_id);
3593                 return;
3594         }
3595
3596         tx_vlan_reset(res->port_id);
3597
3598         cmd_reconfig_device_queue(res->port_id, 1, 1);
3599 }
3600
3601 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3602         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3603                                  tx_vlan, "tx_vlan");
3604 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3605         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3606                                  reset, "reset");
3607 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3608         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3609                               port_id, UINT16);
3610
3611 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3612         .f = cmd_tx_vlan_reset_parsed,
3613         .data = NULL,
3614         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3615                 "VLAN header in packets sent on a port",
3616         .tokens = {
3617                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3618                 (void *)&cmd_tx_vlan_reset_reset,
3619                 (void *)&cmd_tx_vlan_reset_portid,
3620                 NULL,
3621         },
3622 };
3623
3624
3625 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3626 struct cmd_csum_result {
3627         cmdline_fixed_string_t csum;
3628         cmdline_fixed_string_t mode;
3629         cmdline_fixed_string_t proto;
3630         cmdline_fixed_string_t hwsw;
3631         portid_t port_id;
3632 };
3633
3634 static void
3635 csum_show(int port_id)
3636 {
3637         struct rte_eth_dev_info dev_info;
3638         uint64_t tx_offloads;
3639
3640         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3641         printf("Parse tunnel is %s\n",
3642                 (ports[port_id].parse_tunnel) ? "on" : "off");
3643         printf("IP checksum offload is %s\n",
3644                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3645         printf("UDP checksum offload is %s\n",
3646                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3647         printf("TCP checksum offload is %s\n",
3648                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3649         printf("SCTP checksum offload is %s\n",
3650                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3651         printf("Outer-Ip checksum offload is %s\n",
3652                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3653
3654         /* display warnings if configuration is not supported by the NIC */
3655         rte_eth_dev_info_get(port_id, &dev_info);
3656         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3657                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3658                 printf("Warning: hardware IP checksum enabled but not "
3659                         "supported by port %d\n", port_id);
3660         }
3661         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3662                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3663                 printf("Warning: hardware UDP checksum enabled but not "
3664                         "supported by port %d\n", port_id);
3665         }
3666         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3667                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3668                 printf("Warning: hardware TCP checksum enabled but not "
3669                         "supported by port %d\n", port_id);
3670         }
3671         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3672                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3673                 printf("Warning: hardware SCTP checksum enabled but not "
3674                         "supported by port %d\n", port_id);
3675         }
3676         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3677                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3678                 printf("Warning: hardware outer IP checksum enabled but not "
3679                         "supported by port %d\n", port_id);
3680         }
3681 }
3682
3683 static void
3684 cmd_csum_parsed(void *parsed_result,
3685                        __attribute__((unused)) struct cmdline *cl,
3686                        __attribute__((unused)) void *data)
3687 {
3688         struct cmd_csum_result *res = parsed_result;
3689         int hw = 0;
3690         uint64_t csum_offloads = 0;
3691         struct rte_eth_dev_info dev_info;
3692
3693         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3694                 printf("invalid port %d\n", res->port_id);
3695                 return;
3696         }
3697         if (!port_is_stopped(res->port_id)) {
3698                 printf("Please stop port %d first\n", res->port_id);
3699                 return;
3700         }
3701
3702         rte_eth_dev_info_get(res->port_id, &dev_info);
3703         if (!strcmp(res->mode, "set")) {
3704
3705                 if (!strcmp(res->hwsw, "hw"))
3706                         hw = 1;
3707
3708                 if (!strcmp(res->proto, "ip")) {
3709                         if (dev_info.tx_offload_capa &
3710                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3711                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3712                         } else {
3713                                 printf("IP checksum offload is not supported "
3714                                        "by port %u\n", res->port_id);
3715                         }
3716                 } else if (!strcmp(res->proto, "udp")) {
3717                         if (dev_info.tx_offload_capa &
3718                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3719                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3720                         } else {
3721                                 printf("UDP checksum offload is not supported "
3722                                        "by port %u\n", res->port_id);
3723                         }
3724                 } else if (!strcmp(res->proto, "tcp")) {
3725                         if (dev_info.tx_offload_capa &
3726                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3727                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3728                         } else {
3729                                 printf("TCP checksum offload is not supported "
3730                                        "by port %u\n", res->port_id);
3731                         }
3732                 } else if (!strcmp(res->proto, "sctp")) {
3733                         if (dev_info.tx_offload_capa &
3734                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3735                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3736                         } else {
3737                                 printf("SCTP checksum offload is not supported "
3738                                        "by port %u\n", res->port_id);
3739                         }
3740                 } else if (!strcmp(res->proto, "outer-ip")) {
3741                         if (dev_info.tx_offload_capa &
3742                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3743                                 csum_offloads |=
3744                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3745                         } else {
3746                                 printf("Outer IP checksum offload is not "
3747                                        "supported by port %u\n", res->port_id);
3748                         }
3749                 }
3750
3751                 if (hw) {
3752                         ports[res->port_id].dev_conf.txmode.offloads |=
3753                                                         csum_offloads;
3754                 } else {
3755                         ports[res->port_id].dev_conf.txmode.offloads &=
3756                                                         (~csum_offloads);
3757                 }
3758         }
3759         csum_show(res->port_id);
3760
3761         cmd_reconfig_device_queue(res->port_id, 1, 1);
3762 }
3763
3764 cmdline_parse_token_string_t cmd_csum_csum =
3765         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3766                                 csum, "csum");
3767 cmdline_parse_token_string_t cmd_csum_mode =
3768         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3769                                 mode, "set");
3770 cmdline_parse_token_string_t cmd_csum_proto =
3771         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3772                                 proto, "ip#tcp#udp#sctp#outer-ip");
3773 cmdline_parse_token_string_t cmd_csum_hwsw =
3774         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3775                                 hwsw, "hw#sw");
3776 cmdline_parse_token_num_t cmd_csum_portid =
3777         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3778                                 port_id, UINT16);
3779
3780 cmdline_parse_inst_t cmd_csum_set = {
3781         .f = cmd_csum_parsed,
3782         .data = NULL,
3783         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3784                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3785                 "using csum forward engine",
3786         .tokens = {
3787                 (void *)&cmd_csum_csum,
3788                 (void *)&cmd_csum_mode,
3789                 (void *)&cmd_csum_proto,
3790                 (void *)&cmd_csum_hwsw,
3791                 (void *)&cmd_csum_portid,
3792                 NULL,
3793         },
3794 };
3795
3796 cmdline_parse_token_string_t cmd_csum_mode_show =
3797         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3798                                 mode, "show");
3799
3800 cmdline_parse_inst_t cmd_csum_show = {
3801         .f = cmd_csum_parsed,
3802         .data = NULL,
3803         .help_str = "csum show <port_id>: Show checksum offload configuration",
3804         .tokens = {
3805                 (void *)&cmd_csum_csum,
3806                 (void *)&cmd_csum_mode_show,
3807                 (void *)&cmd_csum_portid,
3808                 NULL,
3809         },
3810 };
3811
3812 /* Enable/disable tunnel parsing */
3813 struct cmd_csum_tunnel_result {
3814         cmdline_fixed_string_t csum;
3815         cmdline_fixed_string_t parse;
3816         cmdline_fixed_string_t onoff;
3817         portid_t port_id;
3818 };
3819
3820 static void
3821 cmd_csum_tunnel_parsed(void *parsed_result,
3822                        __attribute__((unused)) struct cmdline *cl,
3823                        __attribute__((unused)) void *data)
3824 {
3825         struct cmd_csum_tunnel_result *res = parsed_result;
3826
3827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3828                 return;
3829
3830         if (!strcmp(res->onoff, "on"))
3831                 ports[res->port_id].parse_tunnel = 1;
3832         else
3833                 ports[res->port_id].parse_tunnel = 0;
3834
3835         csum_show(res->port_id);
3836 }
3837
3838 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3839         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3840                                 csum, "csum");
3841 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3842         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3843                                 parse, "parse_tunnel");
3844 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3845         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3846                                 onoff, "on#off");
3847 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3848         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3849                                 port_id, UINT16);
3850
3851 cmdline_parse_inst_t cmd_csum_tunnel = {
3852         .f = cmd_csum_tunnel_parsed,
3853         .data = NULL,
3854         .help_str = "csum parse_tunnel on|off <port_id>: "
3855                 "Enable/Disable parsing of tunnels for csum engine",
3856         .tokens = {
3857                 (void *)&cmd_csum_tunnel_csum,
3858                 (void *)&cmd_csum_tunnel_parse,
3859                 (void *)&cmd_csum_tunnel_onoff,
3860                 (void *)&cmd_csum_tunnel_portid,
3861                 NULL,
3862         },
3863 };
3864
3865 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3866 struct cmd_tso_set_result {
3867         cmdline_fixed_string_t tso;
3868         cmdline_fixed_string_t mode;
3869         uint16_t tso_segsz;
3870         portid_t port_id;
3871 };
3872
3873 static void
3874 cmd_tso_set_parsed(void *parsed_result,
3875                        __attribute__((unused)) struct cmdline *cl,
3876                        __attribute__((unused)) void *data)
3877 {
3878         struct cmd_tso_set_result *res = parsed_result;
3879         struct rte_eth_dev_info dev_info;
3880
3881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3882                 return;
3883         if (!port_is_stopped(res->port_id)) {
3884                 printf("Please stop port %d first\n", res->port_id);
3885                 return;
3886         }
3887
3888         if (!strcmp(res->mode, "set"))
3889                 ports[res->port_id].tso_segsz = res->tso_segsz;
3890
3891         rte_eth_dev_info_get(res->port_id, &dev_info);
3892         if ((ports[res->port_id].tso_segsz != 0) &&
3893                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3894                 printf("Error: TSO is not supported by port %d\n",
3895                        res->port_id);
3896                 return;
3897         }
3898
3899         if (ports[res->port_id].tso_segsz == 0) {
3900                 ports[res->port_id].dev_conf.txmode.offloads &=
3901                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3902                 printf("TSO for non-tunneled packets is disabled\n");
3903         } else {
3904                 ports[res->port_id].dev_conf.txmode.offloads |=
3905                                                 DEV_TX_OFFLOAD_TCP_TSO;
3906                 printf("TSO segment size for non-tunneled packets is %d\n",
3907                         ports[res->port_id].tso_segsz);
3908         }
3909
3910         /* display warnings if configuration is not supported by the NIC */
3911         rte_eth_dev_info_get(res->port_id, &dev_info);
3912         if ((ports[res->port_id].tso_segsz != 0) &&
3913                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3914                 printf("Warning: TSO enabled but not "
3915                         "supported by port %d\n", res->port_id);
3916         }
3917
3918         cmd_reconfig_device_queue(res->port_id, 1, 1);
3919 }
3920
3921 cmdline_parse_token_string_t cmd_tso_set_tso =
3922         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3923                                 tso, "tso");
3924 cmdline_parse_token_string_t cmd_tso_set_mode =
3925         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3926                                 mode, "set");
3927 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3928         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3929                                 tso_segsz, UINT16);
3930 cmdline_parse_token_num_t cmd_tso_set_portid =
3931         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3932                                 port_id, UINT16);
3933
3934 cmdline_parse_inst_t cmd_tso_set = {
3935         .f = cmd_tso_set_parsed,
3936         .data = NULL,
3937         .help_str = "tso set <tso_segsz> <port_id>: "
3938                 "Set TSO segment size of non-tunneled packets for csum engine "
3939                 "(0 to disable)",
3940         .tokens = {
3941                 (void *)&cmd_tso_set_tso,
3942                 (void *)&cmd_tso_set_mode,
3943                 (void *)&cmd_tso_set_tso_segsz,
3944                 (void *)&cmd_tso_set_portid,
3945                 NULL,
3946         },
3947 };
3948
3949 cmdline_parse_token_string_t cmd_tso_show_mode =
3950         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3951                                 mode, "show");
3952
3953
3954 cmdline_parse_inst_t cmd_tso_show = {
3955         .f = cmd_tso_set_parsed,
3956         .data = NULL,
3957         .help_str = "tso show <port_id>: "
3958                 "Show TSO segment size of non-tunneled packets for csum engine",
3959         .tokens = {
3960                 (void *)&cmd_tso_set_tso,
3961                 (void *)&cmd_tso_show_mode,
3962                 (void *)&cmd_tso_set_portid,
3963                 NULL,
3964         },
3965 };
3966
3967 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3968 struct cmd_tunnel_tso_set_result {
3969         cmdline_fixed_string_t tso;
3970         cmdline_fixed_string_t mode;
3971         uint16_t tso_segsz;
3972         portid_t port_id;
3973 };
3974
3975 static struct rte_eth_dev_info
3976 check_tunnel_tso_nic_support(portid_t port_id)
3977 {
3978         struct rte_eth_dev_info dev_info;
3979
3980         rte_eth_dev_info_get(port_id, &dev_info);
3981         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3982                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3983                        "not enabled for port %d\n", port_id);
3984         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3985                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3986                        "not enabled for port %d\n", port_id);
3987         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3988                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3989                        "not enabled for port %d\n", port_id);
3990         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3991                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3992                        "not enabled for port %d\n", port_id);
3993         return dev_info;
3994 }
3995
3996 static void
3997 cmd_tunnel_tso_set_parsed(void *parsed_result,
3998                           __attribute__((unused)) struct cmdline *cl,
3999                           __attribute__((unused)) void *data)
4000 {
4001         struct cmd_tunnel_tso_set_result *res = parsed_result;
4002         struct rte_eth_dev_info dev_info;
4003
4004         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4005                 return;
4006         if (!port_is_stopped(res->port_id)) {
4007                 printf("Please stop port %d first\n", res->port_id);
4008                 return;
4009         }
4010
4011         if (!strcmp(res->mode, "set"))
4012                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4013
4014         dev_info = check_tunnel_tso_nic_support(res->port_id);
4015         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4016                 ports[res->port_id].dev_conf.txmode.offloads &=
4017                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4018                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4019                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4020                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4021                 printf("TSO for tunneled packets is disabled\n");
4022         } else {
4023                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4024                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4025                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4026                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4027
4028                 ports[res->port_id].dev_conf.txmode.offloads |=
4029                         (tso_offloads & dev_info.tx_offload_capa);
4030                 printf("TSO segment size for tunneled packets is %d\n",
4031                         ports[res->port_id].tunnel_tso_segsz);
4032
4033                 /* Below conditions are needed to make it work:
4034                  * (1) tunnel TSO is supported by the NIC;
4035                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4036                  * are recognized;
4037                  * (3) for tunneled pkts with outer L3 of IPv4,
4038                  * "csum set outer-ip" must be set to hw, because after tso,
4039                  * total_len of outer IP header is changed, and the checksum
4040                  * of outer IP header calculated by sw should be wrong; that
4041                  * is not necessary for IPv6 tunneled pkts because there's no
4042                  * checksum in IP header anymore.
4043                  */
4044
4045                 if (!ports[res->port_id].parse_tunnel)
4046                         printf("Warning: csum parse_tunnel must be set "
4047                                 "so that tunneled packets are recognized\n");
4048                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4049                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4050                         printf("Warning: csum set outer-ip must be set to hw "
4051                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4052         }
4053
4054         cmd_reconfig_device_queue(res->port_id, 1, 1);
4055 }
4056
4057 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4058         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4059                                 tso, "tunnel_tso");
4060 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4061         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4062                                 mode, "set");
4063 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4064         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4065                                 tso_segsz, UINT16);
4066 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4067         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4068                                 port_id, UINT16);
4069
4070 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4071         .f = cmd_tunnel_tso_set_parsed,
4072         .data = NULL,
4073         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4074                 "Set TSO segment size of tunneled packets for csum engine "
4075                 "(0 to disable)",
4076         .tokens = {
4077                 (void *)&cmd_tunnel_tso_set_tso,
4078                 (void *)&cmd_tunnel_tso_set_mode,
4079                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4080                 (void *)&cmd_tunnel_tso_set_portid,
4081                 NULL,
4082         },
4083 };
4084
4085 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4086         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4087                                 mode, "show");
4088
4089
4090 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4091         .f = cmd_tunnel_tso_set_parsed,
4092         .data = NULL,
4093         .help_str = "tunnel_tso show <port_id> "
4094                 "Show TSO segment size of tunneled packets for csum engine",
4095         .tokens = {
4096                 (void *)&cmd_tunnel_tso_set_tso,
4097                 (void *)&cmd_tunnel_tso_show_mode,
4098                 (void *)&cmd_tunnel_tso_set_portid,
4099                 NULL,
4100         },
4101 };
4102
4103 /* *** SET GRO FOR A PORT *** */
4104 struct cmd_gro_enable_result {
4105         cmdline_fixed_string_t cmd_set;
4106         cmdline_fixed_string_t cmd_port;
4107         cmdline_fixed_string_t cmd_keyword;
4108         cmdline_fixed_string_t cmd_onoff;
4109         portid_t cmd_pid;
4110 };
4111
4112 static void
4113 cmd_gro_enable_parsed(void *parsed_result,
4114                 __attribute__((unused)) struct cmdline *cl,
4115                 __attribute__((unused)) void *data)
4116 {
4117         struct cmd_gro_enable_result *res;
4118
4119         res = parsed_result;
4120         if (!strcmp(res->cmd_keyword, "gro"))
4121                 setup_gro(res->cmd_onoff, res->cmd_pid);
4122 }
4123
4124 cmdline_parse_token_string_t cmd_gro_enable_set =
4125         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4126                         cmd_set, "set");
4127 cmdline_parse_token_string_t cmd_gro_enable_port =
4128         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4129                         cmd_keyword, "port");
4130 cmdline_parse_token_num_t cmd_gro_enable_pid =
4131         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4132                         cmd_pid, UINT16);
4133 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4134         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4135                         cmd_keyword, "gro");
4136 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4137         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4138                         cmd_onoff, "on#off");
4139
4140 cmdline_parse_inst_t cmd_gro_enable = {
4141         .f = cmd_gro_enable_parsed,
4142         .data = NULL,
4143         .help_str = "set port <port_id> gro on|off",
4144         .tokens = {
4145                 (void *)&cmd_gro_enable_set,
4146                 (void *)&cmd_gro_enable_port,
4147                 (void *)&cmd_gro_enable_pid,
4148                 (void *)&cmd_gro_enable_keyword,
4149                 (void *)&cmd_gro_enable_onoff,
4150                 NULL,
4151         },
4152 };
4153
4154 /* *** DISPLAY GRO CONFIGURATION *** */
4155 struct cmd_gro_show_result {
4156         cmdline_fixed_string_t cmd_show;
4157         cmdline_fixed_string_t cmd_port;
4158         cmdline_fixed_string_t cmd_keyword;
4159         portid_t cmd_pid;
4160 };
4161
4162 static void
4163 cmd_gro_show_parsed(void *parsed_result,
4164                 __attribute__((unused)) struct cmdline *cl,
4165                 __attribute__((unused)) void *data)
4166 {
4167         struct cmd_gro_show_result *res;
4168
4169         res = parsed_result;
4170         if (!strcmp(res->cmd_keyword, "gro"))
4171                 show_gro(res->cmd_pid);
4172 }
4173
4174 cmdline_parse_token_string_t cmd_gro_show_show =
4175         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4176                         cmd_show, "show");
4177 cmdline_parse_token_string_t cmd_gro_show_port =
4178         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4179                         cmd_port, "port");
4180 cmdline_parse_token_num_t cmd_gro_show_pid =
4181         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4182                         cmd_pid, UINT16);
4183 cmdline_parse_token_string_t cmd_gro_show_keyword =
4184         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4185                         cmd_keyword, "gro");
4186
4187 cmdline_parse_inst_t cmd_gro_show = {
4188         .f = cmd_gro_show_parsed,
4189         .data = NULL,
4190         .help_str = "show port <port_id> gro",
4191         .tokens = {
4192                 (void *)&cmd_gro_show_show,
4193                 (void *)&cmd_gro_show_port,
4194                 (void *)&cmd_gro_show_pid,
4195                 (void *)&cmd_gro_show_keyword,
4196                 NULL,
4197         },
4198 };
4199
4200 /* *** SET FLUSH CYCLES FOR GRO *** */
4201 struct cmd_gro_flush_result {
4202         cmdline_fixed_string_t cmd_set;
4203         cmdline_fixed_string_t cmd_keyword;
4204         cmdline_fixed_string_t cmd_flush;
4205         uint8_t cmd_cycles;
4206 };
4207
4208 static void
4209 cmd_gro_flush_parsed(void *parsed_result,
4210                 __attribute__((unused)) struct cmdline *cl,
4211                 __attribute__((unused)) void *data)
4212 {
4213         struct cmd_gro_flush_result *res;
4214
4215         res = parsed_result;
4216         if ((!strcmp(res->cmd_keyword, "gro")) &&
4217                         (!strcmp(res->cmd_flush, "flush")))
4218                 setup_gro_flush_cycles(res->cmd_cycles);
4219 }
4220
4221 cmdline_parse_token_string_t cmd_gro_flush_set =
4222         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4223                         cmd_set, "set");
4224 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4225         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4226                         cmd_keyword, "gro");
4227 cmdline_parse_token_string_t cmd_gro_flush_flush =
4228         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4229                         cmd_flush, "flush");
4230 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4231         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4232                         cmd_cycles, UINT8);
4233
4234 cmdline_parse_inst_t cmd_gro_flush = {
4235         .f = cmd_gro_flush_parsed,
4236         .data = NULL,
4237         .help_str = "set gro flush <cycles>",
4238         .tokens = {
4239                 (void *)&cmd_gro_flush_set,
4240                 (void *)&cmd_gro_flush_keyword,
4241                 (void *)&cmd_gro_flush_flush,
4242                 (void *)&cmd_gro_flush_cycles,
4243                 NULL,
4244         },
4245 };
4246
4247 /* *** ENABLE/DISABLE GSO *** */
4248 struct cmd_gso_enable_result {
4249         cmdline_fixed_string_t cmd_set;
4250         cmdline_fixed_string_t cmd_port;
4251         cmdline_fixed_string_t cmd_keyword;
4252         cmdline_fixed_string_t cmd_mode;
4253         portid_t cmd_pid;
4254 };
4255
4256 static void
4257 cmd_gso_enable_parsed(void *parsed_result,
4258                 __attribute__((unused)) struct cmdline *cl,
4259                 __attribute__((unused)) void *data)
4260 {
4261         struct cmd_gso_enable_result *res;
4262
4263         res = parsed_result;
4264         if (!strcmp(res->cmd_keyword, "gso"))
4265                 setup_gso(res->cmd_mode, res->cmd_pid);
4266 }
4267
4268 cmdline_parse_token_string_t cmd_gso_enable_set =
4269         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4270                         cmd_set, "set");
4271 cmdline_parse_token_string_t cmd_gso_enable_port =
4272         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4273                         cmd_port, "port");
4274 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4275         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4276                         cmd_keyword, "gso");
4277 cmdline_parse_token_string_t cmd_gso_enable_mode =
4278         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4279                         cmd_mode, "on#off");
4280 cmdline_parse_token_num_t cmd_gso_enable_pid =
4281         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4282                         cmd_pid, UINT16);
4283
4284 cmdline_parse_inst_t cmd_gso_enable = {
4285         .f = cmd_gso_enable_parsed,
4286         .data = NULL,
4287         .help_str = "set port <port_id> gso on|off",
4288         .tokens = {
4289                 (void *)&cmd_gso_enable_set,
4290                 (void *)&cmd_gso_enable_port,
4291                 (void *)&cmd_gso_enable_pid,
4292                 (void *)&cmd_gso_enable_keyword,
4293                 (void *)&cmd_gso_enable_mode,
4294                 NULL,
4295         },
4296 };
4297
4298 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4299 struct cmd_gso_size_result {
4300         cmdline_fixed_string_t cmd_set;
4301         cmdline_fixed_string_t cmd_keyword;
4302         cmdline_fixed_string_t cmd_segsz;
4303         uint16_t cmd_size;
4304 };
4305
4306 static void
4307 cmd_gso_size_parsed(void *parsed_result,
4308                        __attribute__((unused)) struct cmdline *cl,
4309                        __attribute__((unused)) void *data)
4310 {
4311         struct cmd_gso_size_result *res = parsed_result;
4312
4313         if (test_done == 0) {
4314                 printf("Before setting GSO segsz, please first"
4315                                 " stop fowarding\n");
4316                 return;
4317         }
4318
4319         if (!strcmp(res->cmd_keyword, "gso") &&
4320                         !strcmp(res->cmd_segsz, "segsz")) {
4321                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4322                         printf("gso_size should be larger than %zu."
4323                                         " Please input a legal value\n",
4324                                         RTE_GSO_SEG_SIZE_MIN);
4325                 else
4326                         gso_max_segment_size = res->cmd_size;
4327         }
4328 }
4329
4330 cmdline_parse_token_string_t cmd_gso_size_set =
4331         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4332                                 cmd_set, "set");
4333 cmdline_parse_token_string_t cmd_gso_size_keyword =
4334         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4335                                 cmd_keyword, "gso");
4336 cmdline_parse_token_string_t cmd_gso_size_segsz =
4337         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4338                                 cmd_segsz, "segsz");
4339 cmdline_parse_token_num_t cmd_gso_size_size =
4340         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4341                                 cmd_size, UINT16);
4342
4343 cmdline_parse_inst_t cmd_gso_size = {
4344         .f = cmd_gso_size_parsed,
4345         .data = NULL,
4346         .help_str = "set gso segsz <length>",
4347         .tokens = {
4348                 (void *)&cmd_gso_size_set,
4349                 (void *)&cmd_gso_size_keyword,
4350                 (void *)&cmd_gso_size_segsz,
4351                 (void *)&cmd_gso_size_size,
4352                 NULL,
4353         },
4354 };
4355
4356 /* *** SHOW GSO CONFIGURATION *** */
4357 struct cmd_gso_show_result {
4358         cmdline_fixed_string_t cmd_show;
4359         cmdline_fixed_string_t cmd_port;
4360         cmdline_fixed_string_t cmd_keyword;
4361         portid_t cmd_pid;
4362 };
4363
4364 static void
4365 cmd_gso_show_parsed(void *parsed_result,
4366                        __attribute__((unused)) struct cmdline *cl,
4367                        __attribute__((unused)) void *data)
4368 {
4369         struct cmd_gso_show_result *res = parsed_result;
4370
4371         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4372                 printf("invalid port id %u\n", res->cmd_pid);
4373                 return;
4374         }
4375         if (!strcmp(res->cmd_keyword, "gso")) {
4376                 if (gso_ports[res->cmd_pid].enable) {
4377                         printf("Max GSO'd packet size: %uB\n"
4378                                         "Supported GSO types: TCP/IPv4, "
4379                                         "VxLAN with inner TCP/IPv4 packet, "
4380                                         "GRE with inner TCP/IPv4  packet\n",
4381                                         gso_max_segment_size);
4382                 } else
4383                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4384         }
4385 }
4386
4387 cmdline_parse_token_string_t cmd_gso_show_show =
4388 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4389                 cmd_show, "show");
4390 cmdline_parse_token_string_t cmd_gso_show_port =
4391 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4392                 cmd_port, "port");
4393 cmdline_parse_token_string_t cmd_gso_show_keyword =
4394         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4395                                 cmd_keyword, "gso");
4396 cmdline_parse_token_num_t cmd_gso_show_pid =
4397         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4398                                 cmd_pid, UINT16);
4399
4400 cmdline_parse_inst_t cmd_gso_show = {
4401         .f = cmd_gso_show_parsed,
4402         .data = NULL,
4403         .help_str = "show port <port_id> gso",
4404         .tokens = {
4405                 (void *)&cmd_gso_show_show,
4406                 (void *)&cmd_gso_show_port,
4407                 (void *)&cmd_gso_show_pid,
4408                 (void *)&cmd_gso_show_keyword,
4409                 NULL,
4410         },
4411 };
4412
4413 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4414 struct cmd_set_flush_rx {
4415         cmdline_fixed_string_t set;
4416         cmdline_fixed_string_t flush_rx;
4417         cmdline_fixed_string_t mode;
4418 };
4419
4420 static void
4421 cmd_set_flush_rx_parsed(void *parsed_result,
4422                 __attribute__((unused)) struct cmdline *cl,
4423                 __attribute__((unused)) void *data)
4424 {
4425         struct cmd_set_flush_rx *res = parsed_result;
4426         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4427 }
4428
4429 cmdline_parse_token_string_t cmd_setflushrx_set =
4430         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4431                         set, "set");
4432 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4433         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4434                         flush_rx, "flush_rx");
4435 cmdline_parse_token_string_t cmd_setflushrx_mode =
4436         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4437                         mode, "on#off");
4438
4439
4440 cmdline_parse_inst_t cmd_set_flush_rx = {
4441         .f = cmd_set_flush_rx_parsed,
4442         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4443         .data = NULL,
4444         .tokens = {
4445                 (void *)&cmd_setflushrx_set,
4446                 (void *)&cmd_setflushrx_flush_rx,
4447                 (void *)&cmd_setflushrx_mode,
4448                 NULL,
4449         },
4450 };
4451
4452 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4453 struct cmd_set_link_check {
4454         cmdline_fixed_string_t set;
4455         cmdline_fixed_string_t link_check;
4456         cmdline_fixed_string_t mode;
4457 };
4458
4459 static void
4460 cmd_set_link_check_parsed(void *parsed_result,
4461                 __attribute__((unused)) struct cmdline *cl,
4462                 __attribute__((unused)) void *data)
4463 {
4464         struct cmd_set_link_check *res = parsed_result;
4465         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4466 }
4467
4468 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4469         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4470                         set, "set");
4471 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4472         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4473                         link_check, "link_check");
4474 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4475         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4476                         mode, "on#off");
4477
4478
4479 cmdline_parse_inst_t cmd_set_link_check = {
4480         .f = cmd_set_link_check_parsed,
4481         .help_str = "set link_check on|off: Enable/Disable link status check "
4482                     "when starting/stopping a port",
4483         .data = NULL,
4484         .tokens = {
4485                 (void *)&cmd_setlinkcheck_set,
4486                 (void *)&cmd_setlinkcheck_link_check,
4487                 (void *)&cmd_setlinkcheck_mode,
4488                 NULL,
4489         },
4490 };
4491
4492 /* *** SET NIC BYPASS MODE *** */
4493 struct cmd_set_bypass_mode_result {
4494         cmdline_fixed_string_t set;
4495         cmdline_fixed_string_t bypass;
4496         cmdline_fixed_string_t mode;
4497         cmdline_fixed_string_t value;
4498         portid_t port_id;
4499 };
4500
4501 static void
4502 cmd_set_bypass_mode_parsed(void *parsed_result,
4503                 __attribute__((unused)) struct cmdline *cl,
4504                 __attribute__((unused)) void *data)
4505 {
4506         struct cmd_set_bypass_mode_result *res = parsed_result;
4507         portid_t port_id = res->port_id;
4508         int32_t rc = -EINVAL;
4509
4510 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4511         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4512
4513         if (!strcmp(res->value, "bypass"))
4514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4515         else if (!strcmp(res->value, "isolate"))
4516                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4517         else
4518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4519
4520         /* Set the bypass mode for the relevant port. */
4521         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4522 #endif
4523         if (rc != 0)
4524                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4525 }
4526
4527 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4528         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4529                         set, "set");
4530 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4531         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4532                         bypass, "bypass");
4533 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4534         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4535                         mode, "mode");
4536 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4537         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4538                         value, "normal#bypass#isolate");
4539 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4540         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4541                                 port_id, UINT16);
4542
4543 cmdline_parse_inst_t cmd_set_bypass_mode = {
4544         .f = cmd_set_bypass_mode_parsed,
4545         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4546                     "Set the NIC bypass mode for port_id",
4547         .data = NULL,
4548         .tokens = {
4549                 (void *)&cmd_setbypass_mode_set,
4550                 (void *)&cmd_setbypass_mode_bypass,
4551                 (void *)&cmd_setbypass_mode_mode,
4552                 (void *)&cmd_setbypass_mode_value,
4553                 (void *)&cmd_setbypass_mode_port,
4554                 NULL,
4555         },
4556 };
4557
4558 /* *** SET NIC BYPASS EVENT *** */
4559 struct cmd_set_bypass_event_result {
4560         cmdline_fixed_string_t set;
4561         cmdline_fixed_string_t bypass;
4562         cmdline_fixed_string_t event;
4563         cmdline_fixed_string_t event_value;
4564         cmdline_fixed_string_t mode;
4565         cmdline_fixed_string_t mode_value;
4566         portid_t port_id;
4567 };
4568
4569 static void
4570 cmd_set_bypass_event_parsed(void *parsed_result,
4571                 __attribute__((unused)) struct cmdline *cl,
4572                 __attribute__((unused)) void *data)
4573 {
4574         int32_t rc = -EINVAL;
4575         struct cmd_set_bypass_event_result *res = parsed_result;
4576         portid_t port_id = res->port_id;
4577
4578 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4579         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4580         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4581
4582         if (!strcmp(res->event_value, "timeout"))
4583                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4584         else if (!strcmp(res->event_value, "os_on"))
4585                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4586         else if (!strcmp(res->event_value, "os_off"))
4587                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4588         else if (!strcmp(res->event_value, "power_on"))
4589                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4590         else if (!strcmp(res->event_value, "power_off"))
4591                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4592         else
4593                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4594
4595         if (!strcmp(res->mode_value, "bypass"))
4596                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4597         else if (!strcmp(res->mode_value, "isolate"))
4598                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4599         else
4600                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4601
4602         /* Set the watchdog timeout. */
4603         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4604
4605                 rc = -EINVAL;
4606                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4607                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4608                                                            bypass_timeout);
4609                 }
4610                 if (rc != 0) {
4611                         printf("Failed to set timeout value %u "
4612                         "for port %d, errto code: %d.\n",
4613                         bypass_timeout, port_id, rc);
4614                 }
4615         }
4616
4617         /* Set the bypass event to transition to bypass mode. */
4618         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4619                                               bypass_mode);
4620 #endif
4621
4622         if (rc != 0)
4623                 printf("\t Failed to set bypass event for port = %d.\n",
4624                        port_id);
4625 }
4626
4627 cmdline_parse_token_string_t cmd_setbypass_event_set =
4628         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4629                         set, "set");
4630 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4631         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4632                         bypass, "bypass");
4633 cmdline_parse_token_string_t cmd_setbypass_event_event =
4634         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4635                         event, "event");
4636 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4637         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4638                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4639 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4640         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4641                         mode, "mode");
4642 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4643         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4644                         mode_value, "normal#bypass#isolate");
4645 cmdline_parse_token_num_t cmd_setbypass_event_port =
4646         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4647                                 port_id, UINT16);
4648
4649 cmdline_parse_inst_t cmd_set_bypass_event = {
4650         .f = cmd_set_bypass_event_parsed,
4651         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4652                 "power_off mode normal|bypass|isolate <port_id>: "
4653                 "Set the NIC bypass event mode for port_id",
4654         .data = NULL,
4655         .tokens = {
4656                 (void *)&cmd_setbypass_event_set,
4657                 (void *)&cmd_setbypass_event_bypass,
4658                 (void *)&cmd_setbypass_event_event,
4659                 (void *)&cmd_setbypass_event_event_value,
4660                 (void *)&cmd_setbypass_event_mode,
4661                 (void *)&cmd_setbypass_event_mode_value,
4662                 (void *)&cmd_setbypass_event_port,
4663                 NULL,
4664         },
4665 };
4666
4667
4668 /* *** SET NIC BYPASS TIMEOUT *** */
4669 struct cmd_set_bypass_timeout_result {
4670         cmdline_fixed_string_t set;
4671         cmdline_fixed_string_t bypass;
4672         cmdline_fixed_string_t timeout;
4673         cmdline_fixed_string_t value;
4674 };
4675
4676 static void
4677 cmd_set_bypass_timeout_parsed(void *parsed_result,
4678                 __attribute__((unused)) struct cmdline *cl,
4679                 __attribute__((unused)) void *data)
4680 {
4681         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4682
4683 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4684         if (!strcmp(res->value, "1.5"))
4685                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4686         else if (!strcmp(res->value, "2"))
4687                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4688         else if (!strcmp(res->value, "3"))
4689                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4690         else if (!strcmp(res->value, "4"))
4691                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4692         else if (!strcmp(res->value, "8"))
4693                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4694         else if (!strcmp(res->value, "16"))
4695                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4696         else if (!strcmp(res->value, "32"))
4697                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4698         else
4699                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4700 #endif
4701 }
4702
4703 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4704         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4705                         set, "set");
4706 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4707         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4708                         bypass, "bypass");
4709 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4710         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4711                         timeout, "timeout");
4712 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4713         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4714                         value, "0#1.5#2#3#4#8#16#32");
4715
4716 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4717         .f = cmd_set_bypass_timeout_parsed,
4718         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4719                 "Set the NIC bypass watchdog timeout in seconds",
4720         .data = NULL,
4721         .tokens = {
4722                 (void *)&cmd_setbypass_timeout_set,
4723                 (void *)&cmd_setbypass_timeout_bypass,
4724                 (void *)&cmd_setbypass_timeout_timeout,
4725                 (void *)&cmd_setbypass_timeout_value,
4726                 NULL,
4727         },
4728 };
4729
4730 /* *** SHOW NIC BYPASS MODE *** */
4731 struct cmd_show_bypass_config_result {
4732         cmdline_fixed_string_t show;
4733         cmdline_fixed_string_t bypass;
4734         cmdline_fixed_string_t config;
4735         portid_t port_id;
4736 };
4737
4738 static void
4739 cmd_show_bypass_config_parsed(void *parsed_result,
4740                 __attribute__((unused)) struct cmdline *cl,
4741                 __attribute__((unused)) void *data)
4742 {
4743         struct cmd_show_bypass_config_result *res = parsed_result;
4744         portid_t port_id = res->port_id;
4745         int rc = -EINVAL;
4746 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4747         uint32_t event_mode;
4748         uint32_t bypass_mode;
4749         uint32_t timeout = bypass_timeout;
4750         int i;
4751
4752         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4753                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4754         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4755                 {"UNKNOWN", "normal", "bypass", "isolate"};
4756         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4757                 "NONE",
4758                 "OS/board on",
4759                 "power supply on",
4760                 "OS/board off",
4761                 "power supply off",
4762                 "timeout"};
4763         int num_events = (sizeof events) / (sizeof events[0]);
4764
4765         /* Display the bypass mode.*/
4766         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4767                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4768                 return;
4769         }
4770         else {
4771                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4772                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4773
4774                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4775         }
4776
4777         /* Display the bypass timeout.*/
4778         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4779                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4780
4781         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4782
4783         /* Display the bypass events and associated modes. */
4784         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4785
4786                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4787                         printf("\tFailed to get bypass mode for event = %s\n",
4788                                 events[i]);
4789                 } else {
4790                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4791                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4792
4793                         printf("\tbypass event: %-16s = %s\n", events[i],
4794                                 modes[event_mode]);
4795                 }
4796         }
4797 #endif
4798         if (rc != 0)
4799                 printf("\tFailed to get bypass configuration for port = %d\n",
4800                        port_id);
4801 }
4802
4803 cmdline_parse_token_string_t cmd_showbypass_config_show =
4804         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4805                         show, "show");
4806 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4807         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4808                         bypass, "bypass");
4809 cmdline_parse_token_string_t cmd_showbypass_config_config =
4810         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4811                         config, "config");
4812 cmdline_parse_token_num_t cmd_showbypass_config_port =
4813         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4814                                 port_id, UINT16);
4815
4816 cmdline_parse_inst_t cmd_show_bypass_config = {
4817         .f = cmd_show_bypass_config_parsed,
4818         .help_str = "show bypass config <port_id>: "
4819                     "Show the NIC bypass config for port_id",
4820         .data = NULL,
4821         .tokens = {
4822                 (void *)&cmd_showbypass_config_show,
4823                 (void *)&cmd_showbypass_config_bypass,
4824                 (void *)&cmd_showbypass_config_config,
4825                 (void *)&cmd_showbypass_config_port,
4826                 NULL,
4827         },
4828 };
4829
4830 #ifdef RTE_LIBRTE_PMD_BOND
4831 /* *** SET BONDING MODE *** */
4832 struct cmd_set_bonding_mode_result {
4833         cmdline_fixed_string_t set;
4834         cmdline_fixed_string_t bonding;
4835         cmdline_fixed_string_t mode;
4836         uint8_t value;
4837         portid_t port_id;
4838 };
4839
4840 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4841                 __attribute__((unused))  struct cmdline *cl,
4842                 __attribute__((unused)) void *data)
4843 {
4844         struct cmd_set_bonding_mode_result *res = parsed_result;
4845         portid_t port_id = res->port_id;
4846
4847         /* Set the bonding mode for the relevant port. */
4848         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4849                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4850 }
4851
4852 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4854                 set, "set");
4855 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4857                 bonding, "bonding");
4858 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4859 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4860                 mode, "mode");
4861 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4862 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4863                 value, UINT8);
4864 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4865 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4866                 port_id, UINT16);
4867
4868 cmdline_parse_inst_t cmd_set_bonding_mode = {
4869                 .f = cmd_set_bonding_mode_parsed,
4870                 .help_str = "set bonding mode <mode_value> <port_id>: "
4871                         "Set the bonding mode for port_id",
4872                 .data = NULL,
4873                 .tokens = {
4874                                 (void *) &cmd_setbonding_mode_set,
4875                                 (void *) &cmd_setbonding_mode_bonding,
4876                                 (void *) &cmd_setbonding_mode_mode,
4877                                 (void *) &cmd_setbonding_mode_value,
4878                                 (void *) &cmd_setbonding_mode_port,
4879                                 NULL
4880                 }
4881 };
4882
4883 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4884 struct cmd_set_bonding_lacp_dedicated_queues_result {
4885         cmdline_fixed_string_t set;
4886         cmdline_fixed_string_t bonding;
4887         cmdline_fixed_string_t lacp;
4888         cmdline_fixed_string_t dedicated_queues;
4889         portid_t port_id;
4890         cmdline_fixed_string_t mode;
4891 };
4892
4893 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4894                 __attribute__((unused))  struct cmdline *cl,
4895                 __attribute__((unused)) void *data)
4896 {
4897         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4898         portid_t port_id = res->port_id;
4899         struct rte_port *port;
4900
4901         port = &ports[port_id];
4902
4903         /** Check if the port is not started **/
4904         if (port->port_status != RTE_PORT_STOPPED) {
4905                 printf("Please stop port %d first\n", port_id);
4906                 return;
4907         }
4908
4909         if (!strcmp(res->mode, "enable")) {
4910                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4911                         printf("Dedicate queues for LACP control packets"
4912                                         " enabled\n");
4913                 else
4914                         printf("Enabling dedicate queues for LACP control "
4915                                         "packets on port %d failed\n", port_id);
4916         } else if (!strcmp(res->mode, "disable")) {
4917                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4918                         printf("Dedicated queues for LACP control packets "
4919                                         "disabled\n");
4920                 else
4921                         printf("Disabling dedicated queues for LACP control "
4922                                         "traffic on port %d failed\n", port_id);
4923         }
4924 }
4925
4926 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4928                 set, "set");
4929 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4931                 bonding, "bonding");
4932 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4933 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4934                 lacp, "lacp");
4935 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4936 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4937                 dedicated_queues, "dedicated_queues");
4938 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4939 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4940                 port_id, UINT16);
4941 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4942 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4943                 mode, "enable#disable");
4944
4945 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4946                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4947                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4948                         "enable|disable: "
4949                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4950                 .data = NULL,
4951                 .tokens = {
4952                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4953                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4954                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4955                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4956                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4957                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4958                         NULL
4959                 }
4960 };
4961
4962 /* *** SET BALANCE XMIT POLICY *** */
4963 struct cmd_set_bonding_balance_xmit_policy_result {
4964         cmdline_fixed_string_t set;
4965         cmdline_fixed_string_t bonding;
4966         cmdline_fixed_string_t balance_xmit_policy;
4967         portid_t port_id;
4968         cmdline_fixed_string_t policy;
4969 };
4970
4971 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4972                 __attribute__((unused))  struct cmdline *cl,
4973                 __attribute__((unused)) void *data)
4974 {
4975         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4976         portid_t port_id = res->port_id;
4977         uint8_t policy;
4978
4979         if (!strcmp(res->policy, "l2")) {
4980                 policy = BALANCE_XMIT_POLICY_LAYER2;
4981         } else if (!strcmp(res->policy, "l23")) {
4982                 policy = BALANCE_XMIT_POLICY_LAYER23;
4983         } else if (!strcmp(res->policy, "l34")) {
4984                 policy = BALANCE_XMIT_POLICY_LAYER34;
4985         } else {
4986                 printf("\t Invalid xmit policy selection");
4987                 return;
4988         }
4989
4990         /* Set the bonding mode for the relevant port. */
4991         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4992                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4993                                 port_id);
4994         }
4995 }
4996
4997 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4999                 set, "set");
5000 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5001 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5002                 bonding, "bonding");
5003 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5004 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5005                 balance_xmit_policy, "balance_xmit_policy");
5006 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5007 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5008                 port_id, UINT16);
5009 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5010 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5011                 policy, "l2#l23#l34");
5012
5013 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5014                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5015                 .help_str = "set bonding balance_xmit_policy <port_id> "
5016                         "l2|l23|l34: "
5017                         "Set the bonding balance_xmit_policy for port_id",
5018                 .data = NULL,
5019                 .tokens = {
5020                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5021                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5022                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5023                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5024                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5025                                 NULL
5026                 }
5027 };
5028
5029 /* *** SHOW NIC BONDING CONFIGURATION *** */
5030 struct cmd_show_bonding_config_result {
5031         cmdline_fixed_string_t show;
5032         cmdline_fixed_string_t bonding;
5033         cmdline_fixed_string_t config;
5034         portid_t port_id;
5035 };
5036
5037 static void cmd_show_bonding_config_parsed(void *parsed_result,
5038                 __attribute__((unused))  struct cmdline *cl,
5039                 __attribute__((unused)) void *data)
5040 {
5041         struct cmd_show_bonding_config_result *res = parsed_result;
5042         int bonding_mode, agg_mode;
5043         portid_t slaves[RTE_MAX_ETHPORTS];
5044         int num_slaves, num_active_slaves;
5045         int primary_id;
5046         int i;
5047         portid_t port_id = res->port_id;
5048
5049         /* Display the bonding mode.*/
5050         bonding_mode = rte_eth_bond_mode_get(port_id);
5051         if (bonding_mode < 0) {
5052                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5053                 return;
5054         } else
5055                 printf("\tBonding mode: %d\n", bonding_mode);
5056
5057         if (bonding_mode == BONDING_MODE_BALANCE) {
5058                 int balance_xmit_policy;
5059
5060                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5061                 if (balance_xmit_policy < 0) {
5062                         printf("\tFailed to get balance xmit policy for port = %d\n",
5063                                         port_id);
5064                         return;
5065                 } else {
5066                         printf("\tBalance Xmit Policy: ");
5067
5068                         switch (balance_xmit_policy) {
5069                         case BALANCE_XMIT_POLICY_LAYER2:
5070                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5071                                 break;
5072                         case BALANCE_XMIT_POLICY_LAYER23:
5073                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5074                                 break;
5075                         case BALANCE_XMIT_POLICY_LAYER34:
5076                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5077                                 break;
5078                         }
5079                         printf("\n");
5080                 }
5081         }
5082
5083         if (bonding_mode == BONDING_MODE_8023AD) {
5084                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5085                 printf("\tIEEE802.3AD Aggregator Mode: ");
5086                 switch (agg_mode) {
5087                 case AGG_BANDWIDTH:
5088                         printf("bandwidth");
5089                         break;
5090                 case AGG_STABLE:
5091                         printf("stable");
5092                         break;
5093                 case AGG_COUNT:
5094                         printf("count");
5095                         break;
5096                 }
5097                 printf("\n");
5098         }
5099
5100         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5101
5102         if (num_slaves < 0) {
5103                 printf("\tFailed to get slave list for port = %d\n", port_id);
5104                 return;
5105         }
5106         if (num_slaves > 0) {
5107                 printf("\tSlaves (%d): [", num_slaves);
5108                 for (i = 0; i < num_slaves - 1; i++)
5109                         printf("%d ", slaves[i]);
5110
5111                 printf("%d]\n", slaves[num_slaves - 1]);
5112         } else {
5113                 printf("\tSlaves: []\n");
5114
5115         }
5116
5117         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5118                         RTE_MAX_ETHPORTS);
5119
5120         if (num_active_slaves < 0) {
5121                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5122                 return;
5123         }
5124         if (num_active_slaves > 0) {
5125                 printf("\tActive Slaves (%d): [", num_active_slaves);
5126                 for (i = 0; i < num_active_slaves - 1; i++)
5127                         printf("%d ", slaves[i]);
5128
5129                 printf("%d]\n", slaves[num_active_slaves - 1]);
5130
5131         } else {
5132                 printf("\tActive Slaves: []\n");
5133
5134         }
5135
5136         primary_id = rte_eth_bond_primary_get(port_id);
5137         if (primary_id < 0) {
5138                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5139                 return;
5140         } else
5141                 printf("\tPrimary: [%d]\n", primary_id);
5142
5143 }
5144
5145 cmdline_parse_token_string_t cmd_showbonding_config_show =
5146 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5147                 show, "show");
5148 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5149 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5150                 bonding, "bonding");
5151 cmdline_parse_token_string_t cmd_showbonding_config_config =
5152 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5153                 config, "config");
5154 cmdline_parse_token_num_t cmd_showbonding_config_port =
5155 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5156                 port_id, UINT16);
5157
5158 cmdline_parse_inst_t cmd_show_bonding_config = {
5159                 .f = cmd_show_bonding_config_parsed,
5160                 .help_str = "show bonding config <port_id>: "
5161                         "Show the bonding config for port_id",
5162                 .data = NULL,
5163                 .tokens = {
5164                                 (void *)&cmd_showbonding_config_show,
5165                                 (void *)&cmd_showbonding_config_bonding,
5166                                 (void *)&cmd_showbonding_config_config,
5167                                 (void *)&cmd_showbonding_config_port,
5168                                 NULL
5169                 }
5170 };
5171
5172 /* *** SET BONDING PRIMARY *** */
5173 struct cmd_set_bonding_primary_result {
5174         cmdline_fixed_string_t set;
5175         cmdline_fixed_string_t bonding;
5176         cmdline_fixed_string_t primary;
5177         portid_t slave_id;
5178         portid_t port_id;
5179 };
5180
5181 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5182                 __attribute__((unused))  struct cmdline *cl,
5183                 __attribute__((unused)) void *data)
5184 {
5185         struct cmd_set_bonding_primary_result *res = parsed_result;
5186         portid_t master_port_id = res->port_id;
5187         portid_t slave_port_id = res->slave_id;
5188
5189         /* Set the primary slave for a bonded device. */
5190         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5191                 printf("\t Failed to set primary slave for port = %d.\n",
5192                                 master_port_id);
5193                 return;
5194         }
5195         init_port_config();
5196 }
5197
5198 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5199 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5200                 set, "set");
5201 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5202 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5203                 bonding, "bonding");
5204 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5205 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5206                 primary, "primary");
5207 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5208 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5209                 slave_id, UINT16);
5210 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5211 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5212                 port_id, UINT16);
5213
5214 cmdline_parse_inst_t cmd_set_bonding_primary = {
5215                 .f = cmd_set_bonding_primary_parsed,
5216                 .help_str = "set bonding primary <slave_id> <port_id>: "
5217                         "Set the primary slave for port_id",
5218                 .data = NULL,
5219                 .tokens = {
5220                                 (void *)&cmd_setbonding_primary_set,
5221                                 (void *)&cmd_setbonding_primary_bonding,
5222                                 (void *)&cmd_setbonding_primary_primary,
5223                                 (void *)&cmd_setbonding_primary_slave,
5224                                 (void *)&cmd_setbonding_primary_port,
5225                                 NULL
5226                 }
5227 };
5228
5229 /* *** ADD SLAVE *** */
5230 struct cmd_add_bonding_slave_result {
5231         cmdline_fixed_string_t add;
5232         cmdline_fixed_string_t bonding;
5233         cmdline_fixed_string_t slave;
5234         portid_t slave_id;
5235         portid_t port_id;
5236 };
5237
5238 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5239                 __attribute__((unused))  struct cmdline *cl,
5240                 __attribute__((unused)) void *data)
5241 {
5242         struct cmd_add_bonding_slave_result *res = parsed_result;
5243         portid_t master_port_id = res->port_id;
5244         portid_t slave_port_id = res->slave_id;
5245
5246         /* add the slave for a bonded device. */
5247         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5248                 printf("\t Failed to add slave %d to master port = %d.\n",
5249                                 slave_port_id, master_port_id);
5250                 return;
5251         }
5252         init_port_config();
5253         set_port_slave_flag(slave_port_id);
5254 }
5255
5256 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5257 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5258                 add, "add");
5259 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5260 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5261                 bonding, "bonding");
5262 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5263 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5264                 slave, "slave");
5265 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5266 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5267                 slave_id, UINT16);
5268 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5269 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5270                 port_id, UINT16);
5271
5272 cmdline_parse_inst_t cmd_add_bonding_slave = {
5273                 .f = cmd_add_bonding_slave_parsed,
5274                 .help_str = "add bonding slave <slave_id> <port_id>: "
5275                         "Add a slave device to a bonded device",
5276                 .data = NULL,
5277                 .tokens = {
5278                                 (void *)&cmd_addbonding_slave_add,
5279                                 (void *)&cmd_addbonding_slave_bonding,
5280                                 (void *)&cmd_addbonding_slave_slave,
5281                                 (void *)&cmd_addbonding_slave_slaveid,
5282                                 (void *)&cmd_addbonding_slave_port,
5283                                 NULL
5284                 }
5285 };
5286
5287 /* *** REMOVE SLAVE *** */
5288 struct cmd_remove_bonding_slave_result {
5289         cmdline_fixed_string_t remove;
5290         cmdline_fixed_string_t bonding;
5291         cmdline_fixed_string_t slave;
5292         portid_t slave_id;
5293         portid_t port_id;
5294 };
5295
5296 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5297                 __attribute__((unused))  struct cmdline *cl,
5298                 __attribute__((unused)) void *data)
5299 {
5300         struct cmd_remove_bonding_slave_result *res = parsed_result;
5301         portid_t master_port_id = res->port_id;
5302         portid_t slave_port_id = res->slave_id;
5303
5304         /* remove the slave from a bonded device. */
5305         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5306                 printf("\t Failed to remove slave %d from master port = %d.\n",
5307                                 slave_port_id, master_port_id);
5308                 return;
5309         }
5310         init_port_config();
5311         clear_port_slave_flag(slave_port_id);
5312 }
5313
5314 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5315                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5316                                 remove, "remove");
5317 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5318                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5319                                 bonding, "bonding");
5320 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5321                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5322                                 slave, "slave");
5323 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5324                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5325                                 slave_id, UINT16);
5326 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5327                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5328                                 port_id, UINT16);
5329
5330 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5331                 .f = cmd_remove_bonding_slave_parsed,
5332                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5333                         "Remove a slave device from a bonded device",
5334                 .data = NULL,
5335                 .tokens = {
5336                                 (void *)&cmd_removebonding_slave_remove,
5337                                 (void *)&cmd_removebonding_slave_bonding,
5338                                 (void *)&cmd_removebonding_slave_slave,
5339                                 (void *)&cmd_removebonding_slave_slaveid,
5340                                 (void *)&cmd_removebonding_slave_port,
5341                                 NULL
5342                 }
5343 };
5344
5345 /* *** CREATE BONDED DEVICE *** */
5346 struct cmd_create_bonded_device_result {
5347         cmdline_fixed_string_t create;
5348         cmdline_fixed_string_t bonded;
5349         cmdline_fixed_string_t device;
5350         uint8_t mode;
5351         uint8_t socket;
5352 };
5353
5354 static int bond_dev_num = 0;
5355
5356 static void cmd_create_bonded_device_parsed(void *parsed_result,
5357                 __attribute__((unused))  struct cmdline *cl,
5358                 __attribute__((unused)) void *data)
5359 {
5360         struct cmd_create_bonded_device_result *res = parsed_result;
5361         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5362         int port_id;
5363
5364         if (test_done == 0) {
5365                 printf("Please stop forwarding first\n");
5366                 return;
5367         }
5368
5369         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5370                         bond_dev_num++);
5371
5372         /* Create a new bonded device. */
5373         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5374         if (port_id < 0) {
5375                 printf("\t Failed to create bonded device.\n");
5376                 return;
5377         } else {
5378                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5379                                 port_id);
5380
5381                 /* Update number of ports */
5382                 nb_ports = rte_eth_dev_count();
5383                 reconfig(port_id, res->socket);
5384                 rte_eth_promiscuous_enable(port_id);
5385         }
5386
5387 }
5388
5389 cmdline_parse_token_string_t cmd_createbonded_device_create =
5390                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5391                                 create, "create");
5392 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5393                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5394                                 bonded, "bonded");
5395 cmdline_parse_token_string_t cmd_createbonded_device_device =
5396                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5397                                 device, "device");
5398 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5399                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5400                                 mode, UINT8);
5401 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5402                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5403                                 socket, UINT8);
5404
5405 cmdline_parse_inst_t cmd_create_bonded_device = {
5406                 .f = cmd_create_bonded_device_parsed,
5407                 .help_str = "create bonded device <mode> <socket>: "
5408                         "Create a new bonded device with specific bonding mode and socket",
5409                 .data = NULL,
5410                 .tokens = {
5411                                 (void *)&cmd_createbonded_device_create,
5412                                 (void *)&cmd_createbonded_device_bonded,
5413                                 (void *)&cmd_createbonded_device_device,
5414                                 (void *)&cmd_createbonded_device_mode,
5415                                 (void *)&cmd_createbonded_device_socket,
5416                                 NULL
5417                 }
5418 };
5419
5420 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5421 struct cmd_set_bond_mac_addr_result {
5422         cmdline_fixed_string_t set;
5423         cmdline_fixed_string_t bonding;
5424         cmdline_fixed_string_t mac_addr;
5425         uint16_t port_num;
5426         struct ether_addr address;
5427 };
5428
5429 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5430                 __attribute__((unused))  struct cmdline *cl,
5431                 __attribute__((unused)) void *data)
5432 {
5433         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5434         int ret;
5435
5436         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5437                 return;
5438
5439         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5440
5441         /* check the return value and print it if is < 0 */
5442         if (ret < 0)
5443                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5444 }
5445
5446 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5447                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5448 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5449                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5450                                 "bonding");
5451 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5452                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5453                                 "mac_addr");
5454 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5455                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5456                                 port_num, UINT16);
5457 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5458                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5459
5460 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5461                 .f = cmd_set_bond_mac_addr_parsed,
5462                 .data = (void *) 0,
5463                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5464                 .tokens = {
5465                                 (void *)&cmd_set_bond_mac_addr_set,
5466                                 (void *)&cmd_set_bond_mac_addr_bonding,
5467                                 (void *)&cmd_set_bond_mac_addr_mac,
5468                                 (void *)&cmd_set_bond_mac_addr_portnum,
5469                                 (void *)&cmd_set_bond_mac_addr_addr,
5470                                 NULL
5471                 }
5472 };
5473
5474
5475 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5476 struct cmd_set_bond_mon_period_result {
5477         cmdline_fixed_string_t set;
5478         cmdline_fixed_string_t bonding;
5479         cmdline_fixed_string_t mon_period;
5480         uint16_t port_num;
5481         uint32_t period_ms;
5482 };
5483
5484 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5485                 __attribute__((unused))  struct cmdline *cl,
5486                 __attribute__((unused)) void *data)
5487 {
5488         struct cmd_set_bond_mon_period_result *res = parsed_result;
5489         int ret;
5490
5491         if (res->port_num >= nb_ports) {
5492                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5493                 return;
5494         }
5495
5496         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5497
5498         /* check the return value and print it if is < 0 */
5499         if (ret < 0)
5500                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5501 }
5502
5503 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5504                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5505                                 set, "set");
5506 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5507                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5508                                 bonding, "bonding");
5509 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5510                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5511                                 mon_period,     "mon_period");
5512 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5513                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5514                                 port_num, UINT16);
5515 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5516                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5517                                 period_ms, UINT32);
5518
5519 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5520                 .f = cmd_set_bond_mon_period_parsed,
5521                 .data = (void *) 0,
5522                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5523                 .tokens = {
5524                                 (void *)&cmd_set_bond_mon_period_set,
5525                                 (void *)&cmd_set_bond_mon_period_bonding,
5526                                 (void *)&cmd_set_bond_mon_period_mon_period,
5527                                 (void *)&cmd_set_bond_mon_period_portnum,
5528                                 (void *)&cmd_set_bond_mon_period_period_ms,
5529                                 NULL
5530                 }
5531 };
5532
5533
5534
5535 struct cmd_set_bonding_agg_mode_policy_result {
5536         cmdline_fixed_string_t set;
5537         cmdline_fixed_string_t bonding;
5538         cmdline_fixed_string_t agg_mode;
5539         uint16_t port_num;
5540         cmdline_fixed_string_t policy;
5541 };
5542
5543
5544 static void
5545 cmd_set_bonding_agg_mode(void *parsed_result,
5546                 __attribute__((unused)) struct cmdline *cl,
5547                 __attribute__((unused)) void *data)
5548 {
5549         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5550         uint8_t policy = AGG_BANDWIDTH;
5551
5552         if (res->port_num >= nb_ports) {
5553                 printf("Port id %d must be less than %d\n",
5554                                 res->port_num, nb_ports);
5555                 return;
5556         }
5557
5558         if (!strcmp(res->policy, "bandwidth"))
5559                 policy = AGG_BANDWIDTH;
5560         else if (!strcmp(res->policy, "stable"))
5561                 policy = AGG_STABLE;
5562         else if (!strcmp(res->policy, "count"))
5563                 policy = AGG_COUNT;
5564
5565         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5566 }
5567
5568
5569 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5570         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5571                                 set, "set");
5572 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5573         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5574                                 bonding, "bonding");
5575
5576 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5577         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5578                                 agg_mode, "agg_mode");
5579
5580 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5581         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5582                                 port_num, UINT16);
5583
5584 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5585         TOKEN_STRING_INITIALIZER(
5586                         struct cmd_set_bonding_balance_xmit_policy_result,
5587                 policy, "stable#bandwidth#count");
5588
5589 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5590         .f = cmd_set_bonding_agg_mode,
5591         .data = (void *) 0,
5592         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5593         .tokens = {
5594                         (void *)&cmd_set_bonding_agg_mode_set,
5595                         (void *)&cmd_set_bonding_agg_mode_bonding,
5596                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5597                         (void *)&cmd_set_bonding_agg_mode_portnum,
5598                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5599                         NULL
5600                 }
5601 };
5602
5603
5604 #endif /* RTE_LIBRTE_PMD_BOND */
5605
5606 /* *** SET FORWARDING MODE *** */
5607 struct cmd_set_fwd_mode_result {
5608         cmdline_fixed_string_t set;
5609         cmdline_fixed_string_t fwd;
5610         cmdline_fixed_string_t mode;
5611 };
5612
5613 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5614                                     __attribute__((unused)) struct cmdline *cl,
5615                                     __attribute__((unused)) void *data)
5616 {
5617         struct cmd_set_fwd_mode_result *res = parsed_result;
5618
5619         retry_enabled = 0;
5620         set_pkt_forwarding_mode(res->mode);
5621 }
5622
5623 cmdline_parse_token_string_t cmd_setfwd_set =
5624         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5625 cmdline_parse_token_string_t cmd_setfwd_fwd =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5627 cmdline_parse_token_string_t cmd_setfwd_mode =
5628         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5629                 "" /* defined at init */);
5630
5631 cmdline_parse_inst_t cmd_set_fwd_mode = {
5632         .f = cmd_set_fwd_mode_parsed,
5633         .data = NULL,
5634         .help_str = NULL, /* defined at init */
5635         .tokens = {
5636                 (void *)&cmd_setfwd_set,
5637                 (void *)&cmd_setfwd_fwd,
5638                 (void *)&cmd_setfwd_mode,
5639                 NULL,
5640         },
5641 };
5642
5643 static void cmd_set_fwd_mode_init(void)
5644 {
5645         char *modes, *c;
5646         static char token[128];
5647         static char help[256];
5648         cmdline_parse_token_string_t *token_struct;
5649
5650         modes = list_pkt_forwarding_modes();
5651         snprintf(help, sizeof(help), "set fwd %s: "
5652                 "Set packet forwarding mode", modes);
5653         cmd_set_fwd_mode.help_str = help;
5654
5655         /* string token separator is # */
5656         for (c = token; *modes != '\0'; modes++)
5657                 if (*modes == '|')
5658                         *c++ = '#';
5659                 else
5660                         *c++ = *modes;
5661         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5662         token_struct->string_data.str = token;
5663 }
5664
5665 /* *** SET RETRY FORWARDING MODE *** */
5666 struct cmd_set_fwd_retry_mode_result {
5667         cmdline_fixed_string_t set;
5668         cmdline_fixed_string_t fwd;
5669         cmdline_fixed_string_t mode;
5670         cmdline_fixed_string_t retry;
5671 };
5672
5673 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5674                             __attribute__((unused)) struct cmdline *cl,
5675                             __attribute__((unused)) void *data)
5676 {
5677         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5678
5679         retry_enabled = 1;
5680         set_pkt_forwarding_mode(res->mode);
5681 }
5682
5683 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5684         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5685                         set, "set");
5686 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5687         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5688                         fwd, "fwd");
5689 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5691                         mode,
5692                 "" /* defined at init */);
5693 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5695                         retry, "retry");
5696
5697 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5698         .f = cmd_set_fwd_retry_mode_parsed,
5699         .data = NULL,
5700         .help_str = NULL, /* defined at init */
5701         .tokens = {
5702                 (void *)&cmd_setfwd_retry_set,
5703                 (void *)&cmd_setfwd_retry_fwd,
5704                 (void *)&cmd_setfwd_retry_mode,
5705                 (void *)&cmd_setfwd_retry_retry,
5706                 NULL,
5707         },
5708 };
5709
5710 static void cmd_set_fwd_retry_mode_init(void)
5711 {
5712         char *modes, *c;
5713         static char token[128];
5714         static char help[256];
5715         cmdline_parse_token_string_t *token_struct;
5716
5717         modes = list_pkt_forwarding_retry_modes();
5718         snprintf(help, sizeof(help), "set fwd %s retry: "
5719                 "Set packet forwarding mode with retry", modes);
5720         cmd_set_fwd_retry_mode.help_str = help;
5721
5722         /* string token separator is # */
5723         for (c = token; *modes != '\0'; modes++)
5724                 if (*modes == '|')
5725                         *c++ = '#';
5726                 else
5727                         *c++ = *modes;
5728         token_struct = (cmdline_parse_token_string_t *)
5729                 cmd_set_fwd_retry_mode.tokens[2];
5730         token_struct->string_data.str = token;
5731 }
5732
5733 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5734 struct cmd_set_burst_tx_retry_result {
5735         cmdline_fixed_string_t set;
5736         cmdline_fixed_string_t burst;
5737         cmdline_fixed_string_t tx;
5738         cmdline_fixed_string_t delay;
5739         uint32_t time;
5740         cmdline_fixed_string_t retry;
5741         uint32_t retry_num;
5742 };
5743
5744 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5745                                         __attribute__((unused)) struct cmdline *cl,
5746                                         __attribute__((unused)) void *data)
5747 {
5748         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5749
5750         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5751                 && !strcmp(res->tx, "tx")) {
5752                 if (!strcmp(res->delay, "delay"))
5753                         burst_tx_delay_time = res->time;
5754                 if (!strcmp(res->retry, "retry"))
5755                         burst_tx_retry_num = res->retry_num;
5756         }
5757
5758 }
5759
5760 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5762 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5763         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5764                                  "burst");
5765 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5766         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5767 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5768         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5769 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5770         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5771 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5772         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5773 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5774         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5775
5776 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5777         .f = cmd_set_burst_tx_retry_parsed,
5778         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5779         .tokens = {
5780                 (void *)&cmd_set_burst_tx_retry_set,
5781                 (void *)&cmd_set_burst_tx_retry_burst,
5782                 (void *)&cmd_set_burst_tx_retry_tx,
5783                 (void *)&cmd_set_burst_tx_retry_delay,
5784                 (void *)&cmd_set_burst_tx_retry_time,
5785                 (void *)&cmd_set_burst_tx_retry_retry,
5786                 (void *)&cmd_set_burst_tx_retry_retry_num,
5787                 NULL,
5788         },
5789 };
5790
5791 /* *** SET PROMISC MODE *** */
5792 struct cmd_set_promisc_mode_result {
5793         cmdline_fixed_string_t set;
5794         cmdline_fixed_string_t promisc;
5795         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5796         uint16_t port_num;               /* valid if "allports" argument == 0 */
5797         cmdline_fixed_string_t mode;
5798 };
5799
5800 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5801                                         __attribute__((unused)) struct cmdline *cl,
5802                                         void *allports)
5803 {
5804         struct cmd_set_promisc_mode_result *res = parsed_result;
5805         int enable;
5806         portid_t i;
5807
5808         if (!strcmp(res->mode, "on"))
5809                 enable = 1;
5810         else
5811                 enable = 0;
5812
5813         /* all ports */
5814         if (allports) {
5815                 RTE_ETH_FOREACH_DEV(i) {
5816                         if (enable)
5817                                 rte_eth_promiscuous_enable(i);
5818                         else
5819                                 rte_eth_promiscuous_disable(i);
5820                 }
5821         }
5822         else {
5823                 if (enable)
5824                         rte_eth_promiscuous_enable(res->port_num);
5825                 else
5826                         rte_eth_promiscuous_disable(res->port_num);
5827         }
5828 }
5829
5830 cmdline_parse_token_string_t cmd_setpromisc_set =
5831         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5832 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5833         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5834                                  "promisc");
5835 cmdline_parse_token_string_t cmd_setpromisc_portall =
5836         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5837                                  "all");
5838 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5839         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5840                               UINT8);
5841 cmdline_parse_token_string_t cmd_setpromisc_mode =
5842         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5843                                  "on#off");
5844
5845 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5846         .f = cmd_set_promisc_mode_parsed,
5847         .data = (void *)1,
5848         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5849         .tokens = {
5850                 (void *)&cmd_setpromisc_set,
5851                 (void *)&cmd_setpromisc_promisc,
5852                 (void *)&cmd_setpromisc_portall,
5853                 (void *)&cmd_setpromisc_mode,
5854                 NULL,
5855         },
5856 };
5857
5858 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5859         .f = cmd_set_promisc_mode_parsed,
5860         .data = (void *)0,
5861         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5862         .tokens = {
5863                 (void *)&cmd_setpromisc_set,
5864                 (void *)&cmd_setpromisc_promisc,
5865                 (void *)&cmd_setpromisc_portnum,
5866                 (void *)&cmd_setpromisc_mode,
5867                 NULL,
5868         },
5869 };
5870
5871 /* *** SET ALLMULTI MODE *** */
5872 struct cmd_set_allmulti_mode_result {
5873         cmdline_fixed_string_t set;
5874         cmdline_fixed_string_t allmulti;
5875         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5876         uint16_t port_num;               /* valid if "allports" argument == 0 */
5877         cmdline_fixed_string_t mode;
5878 };
5879
5880 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5881                                         __attribute__((unused)) struct cmdline *cl,
5882                                         void *allports)
5883 {
5884         struct cmd_set_allmulti_mode_result *res = parsed_result;
5885         int enable;
5886         portid_t i;
5887
5888         if (!strcmp(res->mode, "on"))
5889                 enable = 1;
5890         else
5891                 enable = 0;
5892
5893         /* all ports */
5894         if (allports) {
5895                 RTE_ETH_FOREACH_DEV(i) {
5896                         if (enable)
5897                                 rte_eth_allmulticast_enable(i);
5898                         else
5899                                 rte_eth_allmulticast_disable(i);
5900                 }
5901         }
5902         else {
5903                 if (enable)
5904                         rte_eth_allmulticast_enable(res->port_num);
5905                 else
5906                         rte_eth_allmulticast_disable(res->port_num);
5907         }
5908 }
5909
5910 cmdline_parse_token_string_t cmd_setallmulti_set =
5911         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5912 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5913         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5914                                  "allmulti");
5915 cmdline_parse_token_string_t cmd_setallmulti_portall =
5916         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5917                                  "all");
5918 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5919         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5920                               UINT16);
5921 cmdline_parse_token_string_t cmd_setallmulti_mode =
5922         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5923                                  "on#off");
5924
5925 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5926         .f = cmd_set_allmulti_mode_parsed,
5927         .data = (void *)1,
5928         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5929         .tokens = {
5930                 (void *)&cmd_setallmulti_set,
5931                 (void *)&cmd_setallmulti_allmulti,
5932                 (void *)&cmd_setallmulti_portall,
5933                 (void *)&cmd_setallmulti_mode,
5934                 NULL,
5935         },
5936 };
5937
5938 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5939         .f = cmd_set_allmulti_mode_parsed,
5940         .data = (void *)0,
5941         .help_str = "set allmulti <port_id> on|off: "
5942                 "Set allmulti mode on port_id",
5943         .tokens = {
5944                 (void *)&cmd_setallmulti_set,
5945                 (void *)&cmd_setallmulti_allmulti,
5946                 (void *)&cmd_setallmulti_portnum,
5947                 (void *)&cmd_setallmulti_mode,
5948                 NULL,
5949         },
5950 };
5951
5952 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5953 struct cmd_link_flow_ctrl_set_result {
5954         cmdline_fixed_string_t set;
5955         cmdline_fixed_string_t flow_ctrl;
5956         cmdline_fixed_string_t rx;
5957         cmdline_fixed_string_t rx_lfc_mode;
5958         cmdline_fixed_string_t tx;
5959         cmdline_fixed_string_t tx_lfc_mode;
5960         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5961         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5962         cmdline_fixed_string_t autoneg_str;
5963         cmdline_fixed_string_t autoneg;
5964         cmdline_fixed_string_t hw_str;
5965         uint32_t high_water;
5966         cmdline_fixed_string_t lw_str;
5967         uint32_t low_water;
5968         cmdline_fixed_string_t pt_str;
5969         uint16_t pause_time;
5970         cmdline_fixed_string_t xon_str;
5971         uint16_t send_xon;
5972         portid_t port_id;
5973 };
5974
5975 cmdline_parse_token_string_t cmd_lfc_set_set =
5976         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5977                                 set, "set");
5978 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5979         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5980                                 flow_ctrl, "flow_ctrl");
5981 cmdline_parse_token_string_t cmd_lfc_set_rx =
5982         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5983                                 rx, "rx");
5984 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5985         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5986                                 rx_lfc_mode, "on#off");
5987 cmdline_parse_token_string_t cmd_lfc_set_tx =
5988         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5989                                 tx, "tx");
5990 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5991         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5992                                 tx_lfc_mode, "on#off");
5993 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5994         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5995                                 hw_str, "high_water");
5996 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5997         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5998                                 high_water, UINT32);
5999 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6000         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6001                                 lw_str, "low_water");
6002 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6003         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6004                                 low_water, UINT32);
6005 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6006         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6007                                 pt_str, "pause_time");
6008 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6009         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6010                                 pause_time, UINT16);
6011 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6012         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6013                                 xon_str, "send_xon");
6014 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6015         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6016                                 send_xon, UINT16);
6017 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6018         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6019                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6020 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6021         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6022                                 mac_ctrl_frame_fwd_mode, "on#off");
6023 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6024         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6025                                 autoneg_str, "autoneg");
6026 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6027         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6028                                 autoneg, "on#off");
6029 cmdline_parse_token_num_t cmd_lfc_set_portid =
6030         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6031                                 port_id, UINT16);
6032
6033 /* forward declaration */
6034 static void
6035 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6036                               void *data);
6037
6038 cmdline_parse_inst_t cmd_link_flow_control_set = {
6039         .f = cmd_link_flow_ctrl_set_parsed,
6040         .data = NULL,
6041         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6042                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6043                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6044         .tokens = {
6045                 (void *)&cmd_lfc_set_set,
6046                 (void *)&cmd_lfc_set_flow_ctrl,
6047                 (void *)&cmd_lfc_set_rx,
6048                 (void *)&cmd_lfc_set_rx_mode,
6049                 (void *)&cmd_lfc_set_tx,
6050                 (void *)&cmd_lfc_set_tx_mode,
6051                 (void *)&cmd_lfc_set_high_water,
6052                 (void *)&cmd_lfc_set_low_water,
6053                 (void *)&cmd_lfc_set_pause_time,
6054                 (void *)&cmd_lfc_set_send_xon,
6055                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6056                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6057                 (void *)&cmd_lfc_set_autoneg_str,
6058                 (void *)&cmd_lfc_set_autoneg,
6059                 (void *)&cmd_lfc_set_portid,
6060                 NULL,
6061         },
6062 };
6063
6064 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6065         .f = cmd_link_flow_ctrl_set_parsed,
6066         .data = (void *)&cmd_link_flow_control_set_rx,
6067         .help_str = "set flow_ctrl rx on|off <port_id>: "
6068                 "Change rx flow control parameter",
6069         .tokens = {
6070                 (void *)&cmd_lfc_set_set,
6071                 (void *)&cmd_lfc_set_flow_ctrl,
6072                 (void *)&cmd_lfc_set_rx,
6073                 (void *)&cmd_lfc_set_rx_mode,
6074                 (void *)&cmd_lfc_set_portid,
6075                 NULL,
6076         },
6077 };
6078
6079 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6080         .f = cmd_link_flow_ctrl_set_parsed,
6081         .data = (void *)&cmd_link_flow_control_set_tx,
6082         .help_str = "set flow_ctrl tx on|off <port_id>: "
6083                 "Change tx flow control parameter",
6084         .tokens = {
6085                 (void *)&cmd_lfc_set_set,
6086                 (void *)&cmd_lfc_set_flow_ctrl,
6087                 (void *)&cmd_lfc_set_tx,
6088                 (void *)&cmd_lfc_set_tx_mode,
6089                 (void *)&cmd_lfc_set_portid,
6090                 NULL,
6091         },
6092 };
6093
6094 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6095         .f = cmd_link_flow_ctrl_set_parsed,
6096         .data = (void *)&cmd_link_flow_control_set_hw,
6097         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6098                 "Change high water flow control parameter",
6099         .tokens = {
6100                 (void *)&cmd_lfc_set_set,
6101                 (void *)&cmd_lfc_set_flow_ctrl,
6102                 (void *)&cmd_lfc_set_high_water_str,
6103                 (void *)&cmd_lfc_set_high_water,
6104                 (void *)&cmd_lfc_set_portid,
6105                 NULL,
6106         },
6107 };
6108
6109 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6110         .f = cmd_link_flow_ctrl_set_parsed,
6111         .data = (void *)&cmd_link_flow_control_set_lw,
6112         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6113                 "Change low water flow control parameter",
6114         .tokens = {
6115                 (void *)&cmd_lfc_set_set,
6116                 (void *)&cmd_lfc_set_flow_ctrl,
6117                 (void *)&cmd_lfc_set_low_water_str,
6118                 (void *)&cmd_lfc_set_low_water,
6119                 (void *)&cmd_lfc_set_portid,
6120                 NULL,
6121         },
6122 };
6123
6124 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6125         .f = cmd_link_flow_ctrl_set_parsed,
6126         .data = (void *)&cmd_link_flow_control_set_pt,
6127         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6128                 "Change pause time flow control parameter",
6129         .tokens = {
6130                 (void *)&cmd_lfc_set_set,
6131                 (void *)&cmd_lfc_set_flow_ctrl,
6132                 (void *)&cmd_lfc_set_pause_time_str,
6133                 (void *)&cmd_lfc_set_pause_time,
6134                 (void *)&cmd_lfc_set_portid,
6135                 NULL,
6136         },
6137 };
6138
6139 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6140         .f = cmd_link_flow_ctrl_set_parsed,
6141         .data = (void *)&cmd_link_flow_control_set_xon,
6142         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6143                 "Change send_xon flow control parameter",
6144         .tokens = {
6145                 (void *)&cmd_lfc_set_set,
6146                 (void *)&cmd_lfc_set_flow_ctrl,
6147                 (void *)&cmd_lfc_set_send_xon_str,
6148                 (void *)&cmd_lfc_set_send_xon,
6149                 (void *)&cmd_lfc_set_portid,
6150                 NULL,
6151         },
6152 };
6153
6154 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6155         .f = cmd_link_flow_ctrl_set_parsed,
6156         .data = (void *)&cmd_link_flow_control_set_macfwd,
6157         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6158                 "Change mac ctrl fwd flow control parameter",
6159         .tokens = {
6160                 (void *)&cmd_lfc_set_set,
6161                 (void *)&cmd_lfc_set_flow_ctrl,
6162                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6163                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6164                 (void *)&cmd_lfc_set_portid,
6165                 NULL,
6166         },
6167 };
6168
6169 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6170         .f = cmd_link_flow_ctrl_set_parsed,
6171         .data = (void *)&cmd_link_flow_control_set_autoneg,
6172         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6173                 "Change autoneg flow control parameter",
6174         .tokens = {
6175                 (void *)&cmd_lfc_set_set,
6176                 (void *)&cmd_lfc_set_flow_ctrl,
6177                 (void *)&cmd_lfc_set_autoneg_str,
6178                 (void *)&cmd_lfc_set_autoneg,
6179                 (void *)&cmd_lfc_set_portid,
6180                 NULL,
6181         },
6182 };
6183
6184 static void
6185 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6186                               __attribute__((unused)) struct cmdline *cl,
6187                               void *data)
6188 {
6189         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6190         cmdline_parse_inst_t *cmd = data;
6191         struct rte_eth_fc_conf fc_conf;
6192         int rx_fc_en = 0;
6193         int tx_fc_en = 0;
6194         int ret;
6195
6196         /*
6197          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6198          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6199          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6200          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6201          */
6202         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6203                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6204         };
6205
6206         /* Partial command line, retrieve current configuration */
6207         if (cmd) {
6208                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6209                 if (ret != 0) {
6210                         printf("cannot get current flow ctrl parameters, return"
6211                                "code = %d\n", ret);
6212                         return;
6213                 }
6214
6215                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6216                     (fc_conf.mode == RTE_FC_FULL))
6217                         rx_fc_en = 1;
6218                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6219                     (fc_conf.mode == RTE_FC_FULL))
6220                         tx_fc_en = 1;
6221         }
6222
6223         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6224                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6225
6226         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6227                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6228
6229         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6230
6231         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6232                 fc_conf.high_water = res->high_water;
6233
6234         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6235                 fc_conf.low_water = res->low_water;
6236
6237         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6238                 fc_conf.pause_time = res->pause_time;
6239
6240         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6241                 fc_conf.send_xon = res->send_xon;
6242
6243         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6244                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6245                         fc_conf.mac_ctrl_frame_fwd = 1;
6246                 else
6247                         fc_conf.mac_ctrl_frame_fwd = 0;
6248         }
6249
6250         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6251                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6252
6253         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6254         if (ret != 0)
6255                 printf("bad flow contrl parameter, return code = %d \n", ret);
6256 }
6257
6258 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6259 struct cmd_priority_flow_ctrl_set_result {
6260         cmdline_fixed_string_t set;
6261         cmdline_fixed_string_t pfc_ctrl;
6262         cmdline_fixed_string_t rx;
6263         cmdline_fixed_string_t rx_pfc_mode;
6264         cmdline_fixed_string_t tx;
6265         cmdline_fixed_string_t tx_pfc_mode;
6266         uint32_t high_water;
6267         uint32_t low_water;
6268         uint16_t pause_time;
6269         uint8_t  priority;
6270         portid_t port_id;
6271 };
6272
6273 static void
6274 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6275                        __attribute__((unused)) struct cmdline *cl,
6276                        __attribute__((unused)) void *data)
6277 {
6278         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6279         struct rte_eth_pfc_conf pfc_conf;
6280         int rx_fc_enable, tx_fc_enable;
6281         int ret;
6282
6283         /*
6284          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6285          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6286          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6287          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6288          */
6289         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6290                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6291         };
6292
6293         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6294         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6295         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6296         pfc_conf.fc.high_water = res->high_water;
6297         pfc_conf.fc.low_water  = res->low_water;
6298         pfc_conf.fc.pause_time = res->pause_time;
6299         pfc_conf.priority      = res->priority;
6300
6301         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6302         if (ret != 0)
6303                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6304 }
6305
6306 cmdline_parse_token_string_t cmd_pfc_set_set =
6307         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6308                                 set, "set");
6309 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6310         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6311                                 pfc_ctrl, "pfc_ctrl");
6312 cmdline_parse_token_string_t cmd_pfc_set_rx =
6313         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6314                                 rx, "rx");
6315 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6316         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6317                                 rx_pfc_mode, "on#off");
6318 cmdline_parse_token_string_t cmd_pfc_set_tx =
6319         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6320                                 tx, "tx");
6321 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6322         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6323                                 tx_pfc_mode, "on#off");
6324 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6325         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6326                                 high_water, UINT32);
6327 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6328         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6329                                 low_water, UINT32);
6330 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6331         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6332                                 pause_time, UINT16);
6333 cmdline_parse_token_num_t cmd_pfc_set_priority =
6334         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6335                                 priority, UINT8);
6336 cmdline_parse_token_num_t cmd_pfc_set_portid =
6337         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6338                                 port_id, UINT16);
6339
6340 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6341         .f = cmd_priority_flow_ctrl_set_parsed,
6342         .data = NULL,
6343         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6344                 "<pause_time> <priority> <port_id>: "
6345                 "Configure the Ethernet priority flow control",
6346         .tokens = {
6347                 (void *)&cmd_pfc_set_set,
6348                 (void *)&cmd_pfc_set_flow_ctrl,
6349                 (void *)&cmd_pfc_set_rx,
6350                 (void *)&cmd_pfc_set_rx_mode,
6351                 (void *)&cmd_pfc_set_tx,
6352                 (void *)&cmd_pfc_set_tx_mode,
6353                 (void *)&cmd_pfc_set_high_water,
6354                 (void *)&cmd_pfc_set_low_water,
6355                 (void *)&cmd_pfc_set_pause_time,
6356                 (void *)&cmd_pfc_set_priority,
6357                 (void *)&cmd_pfc_set_portid,
6358                 NULL,
6359         },
6360 };
6361
6362 /* *** RESET CONFIGURATION *** */
6363 struct cmd_reset_result {
6364         cmdline_fixed_string_t reset;
6365         cmdline_fixed_string_t def;
6366 };
6367
6368 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6369                              struct cmdline *cl,
6370                              __attribute__((unused)) void *data)
6371 {
6372         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6373         set_def_fwd_config();
6374 }
6375
6376 cmdline_parse_token_string_t cmd_reset_set =
6377         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6378 cmdline_parse_token_string_t cmd_reset_def =
6379         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6380                                  "default");
6381
6382 cmdline_parse_inst_t cmd_reset = {
6383         .f = cmd_reset_parsed,
6384         .data = NULL,
6385         .help_str = "set default: Reset default forwarding configuration",
6386         .tokens = {
6387                 (void *)&cmd_reset_set,
6388                 (void *)&cmd_reset_def,
6389                 NULL,
6390         },
6391 };
6392
6393 /* *** START FORWARDING *** */
6394 struct cmd_start_result {
6395         cmdline_fixed_string_t start;
6396 };
6397
6398 cmdline_parse_token_string_t cmd_start_start =
6399         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6400
6401 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6402                              __attribute__((unused)) struct cmdline *cl,
6403                              __attribute__((unused)) void *data)
6404 {
6405         start_packet_forwarding(0);
6406 }
6407
6408 cmdline_parse_inst_t cmd_start = {
6409         .f = cmd_start_parsed,
6410         .data = NULL,
6411         .help_str = "start: Start packet forwarding",
6412         .tokens = {
6413                 (void *)&cmd_start_start,
6414                 NULL,
6415         },
6416 };
6417
6418 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6419 struct cmd_start_tx_first_result {
6420         cmdline_fixed_string_t start;
6421         cmdline_fixed_string_t tx_first;
6422 };
6423
6424 static void
6425 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6426                           __attribute__((unused)) struct cmdline *cl,
6427                           __attribute__((unused)) void *data)
6428 {
6429         start_packet_forwarding(1);
6430 }
6431
6432 cmdline_parse_token_string_t cmd_start_tx_first_start =
6433         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6434                                  "start");
6435 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6436         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6437                                  tx_first, "tx_first");
6438
6439 cmdline_parse_inst_t cmd_start_tx_first = {
6440         .f = cmd_start_tx_first_parsed,
6441         .data = NULL,
6442         .help_str = "start tx_first: Start packet forwarding, "
6443                 "after sending 1 burst of packets",
6444         .tokens = {
6445                 (void *)&cmd_start_tx_first_start,
6446                 (void *)&cmd_start_tx_first_tx_first,
6447                 NULL,
6448         },
6449 };
6450
6451 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6452 struct cmd_start_tx_first_n_result {
6453         cmdline_fixed_string_t start;
6454         cmdline_fixed_string_t tx_first;
6455         uint32_t tx_num;
6456 };
6457
6458 static void
6459 cmd_start_tx_first_n_parsed(void *parsed_result,
6460                           __attribute__((unused)) struct cmdline *cl,
6461                           __attribute__((unused)) void *data)
6462 {
6463         struct cmd_start_tx_first_n_result *res = parsed_result;
6464
6465         start_packet_forwarding(res->tx_num);
6466 }
6467
6468 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6469         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6470                         start, "start");
6471 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6472         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6473                         tx_first, "tx_first");
6474 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6475         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6476                         tx_num, UINT32);
6477
6478 cmdline_parse_inst_t cmd_start_tx_first_n = {
6479         .f = cmd_start_tx_first_n_parsed,
6480         .data = NULL,
6481         .help_str = "start tx_first <num>: "
6482                 "packet forwarding, after sending <num> bursts of packets",
6483         .tokens = {
6484                 (void *)&cmd_start_tx_first_n_start,
6485                 (void *)&cmd_start_tx_first_n_tx_first,
6486                 (void *)&cmd_start_tx_first_n_tx_num,
6487                 NULL,
6488         },
6489 };
6490
6491 /* *** SET LINK UP *** */
6492 struct cmd_set_link_up_result {
6493         cmdline_fixed_string_t set;
6494         cmdline_fixed_string_t link_up;
6495         cmdline_fixed_string_t port;
6496         portid_t port_id;
6497 };
6498
6499 cmdline_parse_token_string_t cmd_set_link_up_set =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6501 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6503                                 "link-up");
6504 cmdline_parse_token_string_t cmd_set_link_up_port =
6505         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6506 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6507         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6508
6509 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6510                              __attribute__((unused)) struct cmdline *cl,
6511                              __attribute__((unused)) void *data)
6512 {
6513         struct cmd_set_link_up_result *res = parsed_result;
6514         dev_set_link_up(res->port_id);
6515 }
6516
6517 cmdline_parse_inst_t cmd_set_link_up = {
6518         .f = cmd_set_link_up_parsed,
6519         .data = NULL,
6520         .help_str = "set link-up port <port id>",
6521         .tokens = {
6522                 (void *)&cmd_set_link_up_set,
6523                 (void *)&cmd_set_link_up_link_up,
6524                 (void *)&cmd_set_link_up_port,
6525                 (void *)&cmd_set_link_up_port_id,
6526                 NULL,
6527         },
6528 };
6529
6530 /* *** SET LINK DOWN *** */
6531 struct cmd_set_link_down_result {
6532         cmdline_fixed_string_t set;
6533         cmdline_fixed_string_t link_down;
6534         cmdline_fixed_string_t port;
6535         portid_t port_id;
6536 };
6537
6538 cmdline_parse_token_string_t cmd_set_link_down_set =
6539         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6540 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6542                                 "link-down");
6543 cmdline_parse_token_string_t cmd_set_link_down_port =
6544         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6545 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6546         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6547
6548 static void cmd_set_link_down_parsed(
6549                                 __attribute__((unused)) void *parsed_result,
6550                                 __attribute__((unused)) struct cmdline *cl,
6551                                 __attribute__((unused)) void *data)
6552 {
6553         struct cmd_set_link_down_result *res = parsed_result;
6554         dev_set_link_down(res->port_id);
6555 }
6556
6557 cmdline_parse_inst_t cmd_set_link_down = {
6558         .f = cmd_set_link_down_parsed,
6559         .data = NULL,
6560         .help_str = "set link-down port <port id>",
6561         .tokens = {
6562                 (void *)&cmd_set_link_down_set,
6563                 (void *)&cmd_set_link_down_link_down,
6564                 (void *)&cmd_set_link_down_port,
6565                 (void *)&cmd_set_link_down_port_id,
6566                 NULL,
6567         },
6568 };
6569
6570 /* *** SHOW CFG *** */
6571 struct cmd_showcfg_result {
6572         cmdline_fixed_string_t show;
6573         cmdline_fixed_string_t cfg;
6574         cmdline_fixed_string_t what;
6575 };
6576
6577 static void cmd_showcfg_parsed(void *parsed_result,
6578                                __attribute__((unused)) struct cmdline *cl,
6579                                __attribute__((unused)) void *data)
6580 {
6581         struct cmd_showcfg_result *res = parsed_result;
6582         if (!strcmp(res->what, "rxtx"))
6583                 rxtx_config_display();
6584         else if (!strcmp(res->what, "cores"))
6585                 fwd_lcores_config_display();
6586         else if (!strcmp(res->what, "fwd"))
6587                 pkt_fwd_config_display(&cur_fwd_config);
6588         else if (!strcmp(res->what, "txpkts"))
6589                 show_tx_pkt_segments();
6590 }
6591
6592 cmdline_parse_token_string_t cmd_showcfg_show =
6593         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6594 cmdline_parse_token_string_t cmd_showcfg_port =
6595         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6596 cmdline_parse_token_string_t cmd_showcfg_what =
6597         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6598                                  "rxtx#cores#fwd#txpkts");
6599
6600 cmdline_parse_inst_t cmd_showcfg = {
6601         .f = cmd_showcfg_parsed,
6602         .data = NULL,
6603         .help_str = "show config rxtx|cores|fwd|txpkts",
6604         .tokens = {
6605                 (void *)&cmd_showcfg_show,
6606                 (void *)&cmd_showcfg_port,
6607                 (void *)&cmd_showcfg_what,
6608                 NULL,
6609         },
6610 };
6611
6612 /* *** SHOW ALL PORT INFO *** */
6613 struct cmd_showportall_result {
6614         cmdline_fixed_string_t show;
6615         cmdline_fixed_string_t port;
6616         cmdline_fixed_string_t what;
6617         cmdline_fixed_string_t all;
6618 };
6619
6620 static void cmd_showportall_parsed(void *parsed_result,
6621                                 __attribute__((unused)) struct cmdline *cl,
6622                                 __attribute__((unused)) void *data)
6623 {
6624         portid_t i;
6625
6626         struct cmd_showportall_result *res = parsed_result;
6627         if (!strcmp(res->show, "clear")) {
6628                 if (!strcmp(res->what, "stats"))
6629                         RTE_ETH_FOREACH_DEV(i)
6630                                 nic_stats_clear(i);
6631                 else if (!strcmp(res->what, "xstats"))
6632                         RTE_ETH_FOREACH_DEV(i)
6633                                 nic_xstats_clear(i);
6634         } else if (!strcmp(res->what, "info"))
6635                 RTE_ETH_FOREACH_DEV(i)
6636                         port_infos_display(i);
6637         else if (!strcmp(res->what, "stats"))
6638                 RTE_ETH_FOREACH_DEV(i)
6639                         nic_stats_display(i);
6640         else if (!strcmp(res->what, "xstats"))
6641                 RTE_ETH_FOREACH_DEV(i)
6642                         nic_xstats_display(i);
6643         else if (!strcmp(res->what, "fdir"))
6644                 RTE_ETH_FOREACH_DEV(i)
6645                         fdir_get_infos(i);
6646         else if (!strcmp(res->what, "stat_qmap"))
6647                 RTE_ETH_FOREACH_DEV(i)
6648                         nic_stats_mapping_display(i);
6649         else if (!strcmp(res->what, "dcb_tc"))
6650                 RTE_ETH_FOREACH_DEV(i)
6651                         port_dcb_info_display(i);
6652         else if (!strcmp(res->what, "cap"))
6653                 RTE_ETH_FOREACH_DEV(i)
6654                         port_offload_cap_display(i);
6655 }
6656
6657 cmdline_parse_token_string_t cmd_showportall_show =
6658         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6659                                  "show#clear");
6660 cmdline_parse_token_string_t cmd_showportall_port =
6661         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6662 cmdline_parse_token_string_t cmd_showportall_what =
6663         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6664                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6665 cmdline_parse_token_string_t cmd_showportall_all =
6666         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6667 cmdline_parse_inst_t cmd_showportall = {
6668         .f = cmd_showportall_parsed,
6669         .data = NULL,
6670         .help_str = "show|clear port "
6671                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6672         .tokens = {
6673                 (void *)&cmd_showportall_show,
6674                 (void *)&cmd_showportall_port,
6675                 (void *)&cmd_showportall_what,
6676                 (void *)&cmd_showportall_all,
6677                 NULL,
6678         },
6679 };
6680
6681 /* *** SHOW PORT INFO *** */
6682 struct cmd_showport_result {
6683         cmdline_fixed_string_t show;
6684         cmdline_fixed_string_t port;
6685         cmdline_fixed_string_t what;
6686         uint16_t portnum;
6687 };
6688
6689 static void cmd_showport_parsed(void *parsed_result,
6690                                 __attribute__((unused)) struct cmdline *cl,
6691                                 __attribute__((unused)) void *data)
6692 {
6693         struct cmd_showport_result *res = parsed_result;
6694         if (!strcmp(res->show, "clear")) {
6695                 if (!strcmp(res->what, "stats"))
6696                         nic_stats_clear(res->portnum);
6697                 else if (!strcmp(res->what, "xstats"))
6698                         nic_xstats_clear(res->portnum);
6699         } else if (!strcmp(res->what, "info"))
6700                 port_infos_display(res->portnum);
6701         else if (!strcmp(res->what, "stats"))
6702                 nic_stats_display(res->portnum);
6703         else if (!strcmp(res->what, "xstats"))
6704                 nic_xstats_display(res->portnum);
6705         else if (!strcmp(res->what, "fdir"))
6706                  fdir_get_infos(res->portnum);
6707         else if (!strcmp(res->what, "stat_qmap"))
6708                 nic_stats_mapping_display(res->portnum);
6709         else if (!strcmp(res->what, "dcb_tc"))
6710                 port_dcb_info_display(res->portnum);
6711         else if (!strcmp(res->what, "cap"))
6712                 port_offload_cap_display(res->portnum);
6713 }
6714
6715 cmdline_parse_token_string_t cmd_showport_show =
6716         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6717                                  "show#clear");
6718 cmdline_parse_token_string_t cmd_showport_port =
6719         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6720 cmdline_parse_token_string_t cmd_showport_what =
6721         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6722                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6723 cmdline_parse_token_num_t cmd_showport_portnum =
6724         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6725
6726 cmdline_parse_inst_t cmd_showport = {
6727         .f = cmd_showport_parsed,
6728         .data = NULL,
6729         .help_str = "show|clear port "
6730                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6731                 "<port_id>",
6732         .tokens = {
6733                 (void *)&cmd_showport_show,
6734                 (void *)&cmd_showport_port,
6735                 (void *)&cmd_showport_what,
6736                 (void *)&cmd_showport_portnum,
6737                 NULL,
6738         },
6739 };
6740
6741 /* *** SHOW QUEUE INFO *** */
6742 struct cmd_showqueue_result {
6743         cmdline_fixed_string_t show;
6744         cmdline_fixed_string_t type;
6745         cmdline_fixed_string_t what;
6746         uint16_t portnum;
6747         uint16_t queuenum;
6748 };
6749
6750 static void
6751 cmd_showqueue_parsed(void *parsed_result,
6752         __attribute__((unused)) struct cmdline *cl,
6753         __attribute__((unused)) void *data)
6754 {
6755         struct cmd_showqueue_result *res = parsed_result;
6756
6757         if (!strcmp(res->type, "rxq"))
6758                 rx_queue_infos_display(res->portnum, res->queuenum);
6759         else if (!strcmp(res->type, "txq"))
6760                 tx_queue_infos_display(res->portnum, res->queuenum);
6761 }
6762
6763 cmdline_parse_token_string_t cmd_showqueue_show =
6764         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6765 cmdline_parse_token_string_t cmd_showqueue_type =
6766         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6767 cmdline_parse_token_string_t cmd_showqueue_what =
6768         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6769 cmdline_parse_token_num_t cmd_showqueue_portnum =
6770         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6771 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6772         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6773
6774 cmdline_parse_inst_t cmd_showqueue = {
6775         .f = cmd_showqueue_parsed,
6776         .data = NULL,
6777         .help_str = "show rxq|txq info <port_id> <queue_id>",
6778         .tokens = {
6779                 (void *)&cmd_showqueue_show,
6780                 (void *)&cmd_showqueue_type,
6781                 (void *)&cmd_showqueue_what,
6782                 (void *)&cmd_showqueue_portnum,
6783                 (void *)&cmd_showqueue_queuenum,
6784                 NULL,
6785         },
6786 };
6787
6788 /* *** READ PORT REGISTER *** */
6789 struct cmd_read_reg_result {
6790         cmdline_fixed_string_t read;
6791         cmdline_fixed_string_t reg;
6792         portid_t port_id;
6793         uint32_t reg_off;
6794 };
6795
6796 static void
6797 cmd_read_reg_parsed(void *parsed_result,
6798                     __attribute__((unused)) struct cmdline *cl,
6799                     __attribute__((unused)) void *data)
6800 {
6801         struct cmd_read_reg_result *res = parsed_result;
6802         port_reg_display(res->port_id, res->reg_off);
6803 }
6804
6805 cmdline_parse_token_string_t cmd_read_reg_read =
6806         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6807 cmdline_parse_token_string_t cmd_read_reg_reg =
6808         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6809 cmdline_parse_token_num_t cmd_read_reg_port_id =
6810         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6811 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6812         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6813
6814 cmdline_parse_inst_t cmd_read_reg = {
6815         .f = cmd_read_reg_parsed,
6816         .data = NULL,
6817         .help_str = "read reg <port_id> <reg_off>",
6818         .tokens = {
6819                 (void *)&cmd_read_reg_read,
6820                 (void *)&cmd_read_reg_reg,
6821                 (void *)&cmd_read_reg_port_id,
6822                 (void *)&cmd_read_reg_reg_off,
6823                 NULL,
6824         },
6825 };
6826
6827 /* *** READ PORT REGISTER BIT FIELD *** */
6828 struct cmd_read_reg_bit_field_result {
6829         cmdline_fixed_string_t read;
6830         cmdline_fixed_string_t regfield;
6831         portid_t port_id;
6832         uint32_t reg_off;
6833         uint8_t bit1_pos;
6834         uint8_t bit2_pos;
6835 };
6836
6837 static void
6838 cmd_read_reg_bit_field_parsed(void *parsed_result,
6839                               __attribute__((unused)) struct cmdline *cl,
6840                               __attribute__((unused)) void *data)
6841 {
6842         struct cmd_read_reg_bit_field_result *res = parsed_result;
6843         port_reg_bit_field_display(res->port_id, res->reg_off,
6844                                    res->bit1_pos, res->bit2_pos);
6845 }
6846
6847 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6848         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6849                                  "read");
6850 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6851         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6852                                  regfield, "regfield");
6853 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6854         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6855                               UINT16);
6856 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6857         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6858                               UINT32);
6859 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6860         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6861                               UINT8);
6862 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6863         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6864                               UINT8);
6865
6866 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6867         .f = cmd_read_reg_bit_field_parsed,
6868         .data = NULL,
6869         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6870         "Read register bit field between bit_x and bit_y included",
6871         .tokens = {
6872                 (void *)&cmd_read_reg_bit_field_read,
6873                 (void *)&cmd_read_reg_bit_field_regfield,
6874                 (void *)&cmd_read_reg_bit_field_port_id,
6875                 (void *)&cmd_read_reg_bit_field_reg_off,
6876                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6877                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6878                 NULL,
6879         },
6880 };
6881
6882 /* *** READ PORT REGISTER BIT *** */
6883 struct cmd_read_reg_bit_result {
6884         cmdline_fixed_string_t read;
6885         cmdline_fixed_string_t regbit;
6886         portid_t port_id;
6887         uint32_t reg_off;
6888         uint8_t bit_pos;
6889 };
6890
6891 static void
6892 cmd_read_reg_bit_parsed(void *parsed_result,
6893                         __attribute__((unused)) struct cmdline *cl,
6894                         __attribute__((unused)) void *data)
6895 {
6896         struct cmd_read_reg_bit_result *res = parsed_result;
6897         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6898 }
6899
6900 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6901         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6902 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6903         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6904                                  regbit, "regbit");
6905 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6907 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6908         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6909 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6910         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6911
6912 cmdline_parse_inst_t cmd_read_reg_bit = {
6913         .f = cmd_read_reg_bit_parsed,
6914         .data = NULL,
6915         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6916         .tokens = {
6917                 (void *)&cmd_read_reg_bit_read,
6918                 (void *)&cmd_read_reg_bit_regbit,
6919                 (void *)&cmd_read_reg_bit_port_id,
6920                 (void *)&cmd_read_reg_bit_reg_off,
6921                 (void *)&cmd_read_reg_bit_bit_pos,
6922                 NULL,
6923         },
6924 };
6925
6926 /* *** WRITE PORT REGISTER *** */
6927 struct cmd_write_reg_result {
6928         cmdline_fixed_string_t write;
6929         cmdline_fixed_string_t reg;
6930         portid_t port_id;
6931         uint32_t reg_off;
6932         uint32_t value;
6933 };
6934
6935 static void
6936 cmd_write_reg_parsed(void *parsed_result,
6937                      __attribute__((unused)) struct cmdline *cl,
6938                      __attribute__((unused)) void *data)
6939 {
6940         struct cmd_write_reg_result *res = parsed_result;
6941         port_reg_set(res->port_id, res->reg_off, res->value);
6942 }
6943
6944 cmdline_parse_token_string_t cmd_write_reg_write =
6945         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6946 cmdline_parse_token_string_t cmd_write_reg_reg =
6947         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6948 cmdline_parse_token_num_t cmd_write_reg_port_id =
6949         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6950 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6951         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6952 cmdline_parse_token_num_t cmd_write_reg_value =
6953         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6954
6955 cmdline_parse_inst_t cmd_write_reg = {
6956         .f = cmd_write_reg_parsed,
6957         .data = NULL,
6958         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6959         .tokens = {
6960                 (void *)&cmd_write_reg_write,
6961                 (void *)&cmd_write_reg_reg,
6962                 (void *)&cmd_write_reg_port_id,
6963                 (void *)&cmd_write_reg_reg_off,
6964                 (void *)&cmd_write_reg_value,
6965                 NULL,
6966         },
6967 };
6968
6969 /* *** WRITE PORT REGISTER BIT FIELD *** */
6970 struct cmd_write_reg_bit_field_result {
6971         cmdline_fixed_string_t write;
6972         cmdline_fixed_string_t regfield;
6973         portid_t port_id;
6974         uint32_t reg_off;
6975         uint8_t bit1_pos;
6976         uint8_t bit2_pos;
6977         uint32_t value;
6978 };
6979
6980 static void
6981 cmd_write_reg_bit_field_parsed(void *parsed_result,
6982                                __attribute__((unused)) struct cmdline *cl,
6983                                __attribute__((unused)) void *data)
6984 {
6985         struct cmd_write_reg_bit_field_result *res = parsed_result;
6986         port_reg_bit_field_set(res->port_id, res->reg_off,
6987                           res->bit1_pos, res->bit2_pos, res->value);
6988 }
6989
6990 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6991         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6992                                  "write");
6993 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6994         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6995                                  regfield, "regfield");
6996 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6997         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6998                               UINT16);
6999 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7000         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7001                               UINT32);
7002 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7003         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7004                               UINT8);
7005 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7006         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7007                               UINT8);
7008 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7009         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7010                               UINT32);
7011
7012 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7013         .f = cmd_write_reg_bit_field_parsed,
7014         .data = NULL,
7015         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7016                 "<reg_value>: "
7017                 "Set register bit field between bit_x and bit_y included",
7018         .tokens = {
7019                 (void *)&cmd_write_reg_bit_field_write,
7020                 (void *)&cmd_write_reg_bit_field_regfield,
7021                 (void *)&cmd_write_reg_bit_field_port_id,
7022                 (void *)&cmd_write_reg_bit_field_reg_off,
7023                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7024                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7025                 (void *)&cmd_write_reg_bit_field_value,
7026                 NULL,
7027         },
7028 };
7029
7030 /* *** WRITE PORT REGISTER BIT *** */
7031 struct cmd_write_reg_bit_result {
7032         cmdline_fixed_string_t write;
7033         cmdline_fixed_string_t regbit;
7034         portid_t port_id;
7035         uint32_t reg_off;
7036         uint8_t bit_pos;
7037         uint8_t value;
7038 };
7039
7040 static void
7041 cmd_write_reg_bit_parsed(void *parsed_result,
7042                          __attribute__((unused)) struct cmdline *cl,
7043                          __attribute__((unused)) void *data)
7044 {
7045         struct cmd_write_reg_bit_result *res = parsed_result;
7046         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7047 }
7048
7049 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7050         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7051                                  "write");
7052 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7053         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7054                                  regbit, "regbit");
7055 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7056         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7057 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7059 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7060         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7061 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7062         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7063
7064 cmdline_parse_inst_t cmd_write_reg_bit = {
7065         .f = cmd_write_reg_bit_parsed,
7066         .data = NULL,
7067         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7068                 "0 <= bit_x <= 31",
7069         .tokens = {
7070                 (void *)&cmd_write_reg_bit_write,
7071                 (void *)&cmd_write_reg_bit_regbit,
7072                 (void *)&cmd_write_reg_bit_port_id,
7073                 (void *)&cmd_write_reg_bit_reg_off,
7074                 (void *)&cmd_write_reg_bit_bit_pos,
7075                 (void *)&cmd_write_reg_bit_value,
7076                 NULL,
7077         },
7078 };
7079
7080 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7081 struct cmd_read_rxd_txd_result {
7082         cmdline_fixed_string_t read;
7083         cmdline_fixed_string_t rxd_txd;
7084         portid_t port_id;
7085         uint16_t queue_id;
7086         uint16_t desc_id;
7087 };
7088
7089 static void
7090 cmd_read_rxd_txd_parsed(void *parsed_result,
7091                         __attribute__((unused)) struct cmdline *cl,
7092                         __attribute__((unused)) void *data)
7093 {
7094         struct cmd_read_rxd_txd_result *res = parsed_result;
7095
7096         if (!strcmp(res->rxd_txd, "rxd"))
7097                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7098         else if (!strcmp(res->rxd_txd, "txd"))
7099                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7100 }
7101
7102 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7103         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7104 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7105         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7106                                  "rxd#txd");
7107 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7108         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7109 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7110         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7111 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7112         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7113
7114 cmdline_parse_inst_t cmd_read_rxd_txd = {
7115         .f = cmd_read_rxd_txd_parsed,
7116         .data = NULL,
7117         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7118         .tokens = {
7119                 (void *)&cmd_read_rxd_txd_read,
7120                 (void *)&cmd_read_rxd_txd_rxd_txd,
7121                 (void *)&cmd_read_rxd_txd_port_id,
7122                 (void *)&cmd_read_rxd_txd_queue_id,
7123                 (void *)&cmd_read_rxd_txd_desc_id,
7124                 NULL,
7125         },
7126 };
7127
7128 /* *** QUIT *** */
7129 struct cmd_quit_result {
7130         cmdline_fixed_string_t quit;
7131 };
7132
7133 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7134                             struct cmdline *cl,
7135                             __attribute__((unused)) void *data)
7136 {
7137         pmd_test_exit();
7138         cmdline_quit(cl);
7139 }
7140
7141 cmdline_parse_token_string_t cmd_quit_quit =
7142         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7143
7144 cmdline_parse_inst_t cmd_quit = {
7145         .f = cmd_quit_parsed,
7146         .data = NULL,
7147         .help_str = "quit: Exit application",
7148         .tokens = {
7149                 (void *)&cmd_quit_quit,
7150                 NULL,
7151         },
7152 };
7153
7154 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7155 struct cmd_mac_addr_result {
7156         cmdline_fixed_string_t mac_addr_cmd;
7157         cmdline_fixed_string_t what;
7158         uint16_t port_num;
7159         struct ether_addr address;
7160 };
7161
7162 static void cmd_mac_addr_parsed(void *parsed_result,
7163                 __attribute__((unused)) struct cmdline *cl,
7164                 __attribute__((unused)) void *data)
7165 {
7166         struct cmd_mac_addr_result *res = parsed_result;
7167         int ret;
7168
7169         if (strcmp(res->what, "add") == 0)
7170                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7171         else if (strcmp(res->what, "set") == 0)
7172                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7173                                                        &res->address);
7174         else
7175                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7176
7177         /* check the return value and print it if is < 0 */
7178         if(ret < 0)
7179                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7180
7181 }
7182
7183 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7184         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7185                                 "mac_addr");
7186 cmdline_parse_token_string_t cmd_mac_addr_what =
7187         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7188                                 "add#remove#set");
7189 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7190                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7191                                         UINT16);
7192 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7193                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7194
7195 cmdline_parse_inst_t cmd_mac_addr = {
7196         .f = cmd_mac_addr_parsed,
7197         .data = (void *)0,
7198         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7199                         "Add/Remove/Set MAC address on port_id",
7200         .tokens = {
7201                 (void *)&cmd_mac_addr_cmd,
7202                 (void *)&cmd_mac_addr_what,
7203                 (void *)&cmd_mac_addr_portnum,
7204                 (void *)&cmd_mac_addr_addr,
7205                 NULL,
7206         },
7207 };
7208
7209 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7210 struct cmd_eth_peer_result {
7211         cmdline_fixed_string_t set;
7212         cmdline_fixed_string_t eth_peer;
7213         portid_t port_id;
7214         cmdline_fixed_string_t peer_addr;
7215 };
7216
7217 static void cmd_set_eth_peer_parsed(void *parsed_result,
7218                         __attribute__((unused)) struct cmdline *cl,
7219                         __attribute__((unused)) void *data)
7220 {
7221                 struct cmd_eth_peer_result *res = parsed_result;
7222
7223                 if (test_done == 0) {
7224                         printf("Please stop forwarding first\n");
7225                         return;
7226                 }
7227                 if (!strcmp(res->eth_peer, "eth-peer")) {
7228                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7229                         fwd_config_setup();
7230                 }
7231 }
7232 cmdline_parse_token_string_t cmd_eth_peer_set =
7233         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7234 cmdline_parse_token_string_t cmd_eth_peer =
7235         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7236 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7237         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7238 cmdline_parse_token_string_t cmd_eth_peer_addr =
7239         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7240
7241 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7242         .f = cmd_set_eth_peer_parsed,
7243         .data = NULL,
7244         .help_str = "set eth-peer <port_id> <peer_mac>",
7245         .tokens = {
7246                 (void *)&cmd_eth_peer_set,
7247                 (void *)&cmd_eth_peer,
7248                 (void *)&cmd_eth_peer_port_id,
7249                 (void *)&cmd_eth_peer_addr,
7250                 NULL,
7251         },
7252 };
7253
7254 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7255 struct cmd_set_qmap_result {
7256         cmdline_fixed_string_t set;
7257         cmdline_fixed_string_t qmap;
7258         cmdline_fixed_string_t what;
7259         portid_t port_id;
7260         uint16_t queue_id;
7261         uint8_t map_value;
7262 };
7263
7264 static void
7265 cmd_set_qmap_parsed(void *parsed_result,
7266                        __attribute__((unused)) struct cmdline *cl,
7267                        __attribute__((unused)) void *data)
7268 {
7269         struct cmd_set_qmap_result *res = parsed_result;
7270         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7271
7272         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7273 }
7274
7275 cmdline_parse_token_string_t cmd_setqmap_set =
7276         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7277                                  set, "set");
7278 cmdline_parse_token_string_t cmd_setqmap_qmap =
7279         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7280                                  qmap, "stat_qmap");
7281 cmdline_parse_token_string_t cmd_setqmap_what =
7282         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7283                                  what, "tx#rx");
7284 cmdline_parse_token_num_t cmd_setqmap_portid =
7285         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7286                               port_id, UINT16);
7287 cmdline_parse_token_num_t cmd_setqmap_queueid =
7288         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7289                               queue_id, UINT16);
7290 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7291         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7292                               map_value, UINT8);
7293
7294 cmdline_parse_inst_t cmd_set_qmap = {
7295         .f = cmd_set_qmap_parsed,
7296         .data = NULL,
7297         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7298                 "Set statistics mapping value on tx|rx queue_id of port_id",
7299         .tokens = {
7300                 (void *)&cmd_setqmap_set,
7301                 (void *)&cmd_setqmap_qmap,
7302                 (void *)&cmd_setqmap_what,
7303                 (void *)&cmd_setqmap_portid,
7304                 (void *)&cmd_setqmap_queueid,
7305                 (void *)&cmd_setqmap_mapvalue,
7306                 NULL,
7307         },
7308 };
7309
7310 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7311 struct cmd_set_xstats_hide_zero_result {
7312         cmdline_fixed_string_t keyword;
7313         cmdline_fixed_string_t name;
7314         cmdline_fixed_string_t on_off;
7315 };
7316
7317 static void
7318 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7319                         __attribute__((unused)) struct cmdline *cl,
7320                         __attribute__((unused)) void *data)
7321 {
7322         struct cmd_set_xstats_hide_zero_result *res;
7323         uint16_t on_off = 0;
7324
7325         res = parsed_result;
7326         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7327         set_xstats_hide_zero(on_off);
7328 }
7329
7330 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7332                                  keyword, "set");
7333 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7334         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7335                                  name, "xstats-hide-zero");
7336 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7337         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7338                                  on_off, "on#off");
7339
7340 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7341         .f = cmd_set_xstats_hide_zero_parsed,
7342         .data = NULL,
7343         .help_str = "set xstats-hide-zero on|off",
7344         .tokens = {
7345                 (void *)&cmd_set_xstats_hide_zero_keyword,
7346                 (void *)&cmd_set_xstats_hide_zero_name,
7347                 (void *)&cmd_set_xstats_hide_zero_on_off,
7348                 NULL,
7349         },
7350 };
7351
7352 /* *** CONFIGURE UNICAST HASH TABLE *** */
7353 struct cmd_set_uc_hash_table {
7354         cmdline_fixed_string_t set;
7355         cmdline_fixed_string_t port;
7356         portid_t port_id;
7357         cmdline_fixed_string_t what;
7358         struct ether_addr address;
7359         cmdline_fixed_string_t mode;
7360 };
7361
7362 static void
7363 cmd_set_uc_hash_parsed(void *parsed_result,
7364                        __attribute__((unused)) struct cmdline *cl,
7365                        __attribute__((unused)) void *data)
7366 {
7367         int ret=0;
7368         struct cmd_set_uc_hash_table *res = parsed_result;
7369
7370         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7371
7372         if (strcmp(res->what, "uta") == 0)
7373                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7374                                                 &res->address,(uint8_t)is_on);
7375         if (ret < 0)
7376                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7377
7378 }
7379
7380 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7381         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7382                                  set, "set");
7383 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7384         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7385                                  port, "port");
7386 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7387         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7388                               port_id, UINT16);
7389 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7390         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7391                                  what, "uta");
7392 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7393         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7394                                 address);
7395 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7396         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7397                                  mode, "on#off");
7398
7399 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7400         .f = cmd_set_uc_hash_parsed,
7401         .data = NULL,
7402         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7403         .tokens = {
7404                 (void *)&cmd_set_uc_hash_set,
7405                 (void *)&cmd_set_uc_hash_port,
7406                 (void *)&cmd_set_uc_hash_portid,
7407                 (void *)&cmd_set_uc_hash_what,
7408                 (void *)&cmd_set_uc_hash_mac,
7409                 (void *)&cmd_set_uc_hash_mode,
7410                 NULL,
7411         },
7412 };
7413
7414 struct cmd_set_uc_all_hash_table {
7415         cmdline_fixed_string_t set;
7416         cmdline_fixed_string_t port;
7417         portid_t port_id;
7418         cmdline_fixed_string_t what;
7419         cmdline_fixed_string_t value;
7420         cmdline_fixed_string_t mode;
7421 };
7422
7423 static void
7424 cmd_set_uc_all_hash_parsed(void *parsed_result,
7425                        __attribute__((unused)) struct cmdline *cl,
7426                        __attribute__((unused)) void *data)
7427 {
7428         int ret=0;
7429         struct cmd_set_uc_all_hash_table *res = parsed_result;
7430
7431         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7432
7433         if ((strcmp(res->what, "uta") == 0) &&
7434                 (strcmp(res->value, "all") == 0))
7435                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7436         if (ret < 0)
7437                 printf("bad unicast hash table parameter,"
7438                         "return code = %d \n", ret);
7439 }
7440
7441 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7443                                  set, "set");
7444 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7445         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7446                                  port, "port");
7447 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7448         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7449                               port_id, UINT16);
7450 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7451         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7452                                  what, "uta");
7453 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7454         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7455                                 value,"all");
7456 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7457         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7458                                  mode, "on#off");
7459
7460 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7461         .f = cmd_set_uc_all_hash_parsed,
7462         .data = NULL,
7463         .help_str = "set port <port_id> uta all on|off",
7464         .tokens = {
7465                 (void *)&cmd_set_uc_all_hash_set,
7466                 (void *)&cmd_set_uc_all_hash_port,
7467                 (void *)&cmd_set_uc_all_hash_portid,
7468                 (void *)&cmd_set_uc_all_hash_what,
7469                 (void *)&cmd_set_uc_all_hash_value,
7470                 (void *)&cmd_set_uc_all_hash_mode,
7471                 NULL,
7472         },
7473 };
7474
7475 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7476 struct cmd_set_vf_macvlan_filter {
7477         cmdline_fixed_string_t set;
7478         cmdline_fixed_string_t port;
7479         portid_t port_id;
7480         cmdline_fixed_string_t vf;
7481         uint8_t vf_id;
7482         struct ether_addr address;
7483         cmdline_fixed_string_t filter_type;
7484         cmdline_fixed_string_t mode;
7485 };
7486
7487 static void
7488 cmd_set_vf_macvlan_parsed(void *parsed_result,
7489                        __attribute__((unused)) struct cmdline *cl,
7490                        __attribute__((unused)) void *data)
7491 {
7492         int is_on, ret = 0;
7493         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7494         struct rte_eth_mac_filter filter;
7495
7496         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7497
7498         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7499
7500         /* set VF MAC filter */
7501         filter.is_vf = 1;
7502
7503         /* set VF ID */
7504         filter.dst_id = res->vf_id;
7505
7506         if (!strcmp(res->filter_type, "exact-mac"))
7507                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7508         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7509                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7510         else if (!strcmp(res->filter_type, "hashmac"))
7511                 filter.filter_type = RTE_MAC_HASH_MATCH;
7512         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7513                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7514
7515         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7516
7517         if (is_on)
7518                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7519                                         RTE_ETH_FILTER_MACVLAN,
7520                                         RTE_ETH_FILTER_ADD,
7521                                          &filter);
7522         else
7523                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7524                                         RTE_ETH_FILTER_MACVLAN,
7525                                         RTE_ETH_FILTER_DELETE,
7526                                         &filter);
7527
7528         if (ret < 0)
7529                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7530
7531 }
7532
7533 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7534         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7535                                  set, "set");
7536 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7537         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7538                                  port, "port");
7539 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7540         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7541                               port_id, UINT16);
7542 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7543         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7544                                  vf, "vf");
7545 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7546         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7547                                 vf_id, UINT8);
7548 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7549         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7550                                 address);
7551 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7552         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7553                                 filter_type, "exact-mac#exact-mac-vlan"
7554                                 "#hashmac#hashmac-vlan");
7555 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7556         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7557                                  mode, "on#off");
7558
7559 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7560         .f = cmd_set_vf_macvlan_parsed,
7561         .data = NULL,
7562         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7563                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7564                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7565                 "hash match rule: hash match of MAC and exact match of VLAN",
7566         .tokens = {
7567                 (void *)&cmd_set_vf_macvlan_set,
7568                 (void *)&cmd_set_vf_macvlan_port,
7569                 (void *)&cmd_set_vf_macvlan_portid,
7570                 (void *)&cmd_set_vf_macvlan_vf,
7571                 (void *)&cmd_set_vf_macvlan_vf_id,
7572                 (void *)&cmd_set_vf_macvlan_mac,
7573                 (void *)&cmd_set_vf_macvlan_filter_type,
7574                 (void *)&cmd_set_vf_macvlan_mode,
7575                 NULL,
7576         },
7577 };
7578
7579 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7580 struct cmd_set_vf_traffic {
7581         cmdline_fixed_string_t set;
7582         cmdline_fixed_string_t port;
7583         portid_t port_id;
7584         cmdline_fixed_string_t vf;
7585         uint8_t vf_id;
7586         cmdline_fixed_string_t what;
7587         cmdline_fixed_string_t mode;
7588 };
7589
7590 static void
7591 cmd_set_vf_traffic_parsed(void *parsed_result,
7592                        __attribute__((unused)) struct cmdline *cl,
7593                        __attribute__((unused)) void *data)
7594 {
7595         struct cmd_set_vf_traffic *res = parsed_result;
7596         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7597         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7598
7599         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7600 }
7601
7602 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7603         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7604                                  set, "set");
7605 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7606         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7607                                  port, "port");
7608 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7609         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7610                               port_id, UINT16);
7611 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7612         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7613                                  vf, "vf");
7614 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7615         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7616                               vf_id, UINT8);
7617 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7618         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7619                                  what, "tx#rx");
7620 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7621         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7622                                  mode, "on#off");
7623
7624 cmdline_parse_inst_t cmd_set_vf_traffic = {
7625         .f = cmd_set_vf_traffic_parsed,
7626         .data = NULL,
7627         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7628         .tokens = {
7629                 (void *)&cmd_setvf_traffic_set,
7630                 (void *)&cmd_setvf_traffic_port,
7631                 (void *)&cmd_setvf_traffic_portid,
7632                 (void *)&cmd_setvf_traffic_vf,
7633                 (void *)&cmd_setvf_traffic_vfid,
7634                 (void *)&cmd_setvf_traffic_what,
7635                 (void *)&cmd_setvf_traffic_mode,
7636                 NULL,
7637         },
7638 };
7639
7640 /* *** CONFIGURE VF RECEIVE MODE *** */
7641 struct cmd_set_vf_rxmode {
7642         cmdline_fixed_string_t set;
7643         cmdline_fixed_string_t port;
7644         portid_t port_id;
7645         cmdline_fixed_string_t vf;
7646         uint8_t vf_id;
7647         cmdline_fixed_string_t what;
7648         cmdline_fixed_string_t mode;
7649         cmdline_fixed_string_t on;
7650 };
7651
7652 static void
7653 cmd_set_vf_rxmode_parsed(void *parsed_result,
7654                        __attribute__((unused)) struct cmdline *cl,
7655                        __attribute__((unused)) void *data)
7656 {
7657         int ret = -ENOTSUP;
7658         uint16_t rx_mode = 0;
7659         struct cmd_set_vf_rxmode *res = parsed_result;
7660
7661         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7662         if (!strcmp(res->what,"rxmode")) {
7663                 if (!strcmp(res->mode, "AUPE"))
7664                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7665                 else if (!strcmp(res->mode, "ROPE"))
7666                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7667                 else if (!strcmp(res->mode, "BAM"))
7668                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7669                 else if (!strncmp(res->mode, "MPE",3))
7670                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7671         }
7672
7673         RTE_SET_USED(is_on);
7674
7675 #ifdef RTE_LIBRTE_IXGBE_PMD
7676         if (ret == -ENOTSUP)
7677                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7678                                                   rx_mode, (uint8_t)is_on);
7679 #endif
7680 #ifdef RTE_LIBRTE_BNXT_PMD
7681         if (ret == -ENOTSUP)
7682                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7683                                                  rx_mode, (uint8_t)is_on);
7684 #endif
7685         if (ret < 0)
7686                 printf("bad VF receive mode parameter, return code = %d \n",
7687                 ret);
7688 }
7689
7690 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7691         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7692                                  set, "set");
7693 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7694         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7695                                  port, "port");
7696 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7697         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7698                               port_id, UINT16);
7699 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7700         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7701                                  vf, "vf");
7702 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7703         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7704                               vf_id, UINT8);
7705 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7706         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7707                                  what, "rxmode");
7708 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7709         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7710                                  mode, "AUPE#ROPE#BAM#MPE");
7711 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7712         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7713                                  on, "on#off");
7714
7715 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7716         .f = cmd_set_vf_rxmode_parsed,
7717         .data = NULL,
7718         .help_str = "set port <port_id> vf <vf_id> rxmode "
7719                 "AUPE|ROPE|BAM|MPE on|off",
7720         .tokens = {
7721                 (void *)&cmd_set_vf_rxmode_set,
7722                 (void *)&cmd_set_vf_rxmode_port,
7723                 (void *)&cmd_set_vf_rxmode_portid,
7724                 (void *)&cmd_set_vf_rxmode_vf,
7725                 (void *)&cmd_set_vf_rxmode_vfid,
7726                 (void *)&cmd_set_vf_rxmode_what,
7727                 (void *)&cmd_set_vf_rxmode_mode,
7728                 (void *)&cmd_set_vf_rxmode_on,
7729                 NULL,
7730         },
7731 };
7732
7733 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7734 struct cmd_vf_mac_addr_result {
7735         cmdline_fixed_string_t mac_addr_cmd;
7736         cmdline_fixed_string_t what;
7737         cmdline_fixed_string_t port;
7738         uint16_t port_num;
7739         cmdline_fixed_string_t vf;
7740         uint8_t vf_num;
7741         struct ether_addr address;
7742 };
7743
7744 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7745                 __attribute__((unused)) struct cmdline *cl,
7746                 __attribute__((unused)) void *data)
7747 {
7748         struct cmd_vf_mac_addr_result *res = parsed_result;
7749         int ret = -ENOTSUP;
7750
7751         if (strcmp(res->what, "add") != 0)
7752                 return;
7753
7754 #ifdef RTE_LIBRTE_I40E_PMD
7755         if (ret == -ENOTSUP)
7756                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7757                                                    &res->address);
7758 #endif
7759 #ifdef RTE_LIBRTE_BNXT_PMD
7760         if (ret == -ENOTSUP)
7761                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7762                                                 res->vf_num);
7763 #endif
7764
7765         if(ret < 0)
7766                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7767
7768 }
7769
7770 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7771         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7772                                 mac_addr_cmd,"mac_addr");
7773 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7774         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7775                                 what,"add");
7776 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7777         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7778                                 port,"port");
7779 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7780         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7781                                 port_num, UINT16);
7782 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7783         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7784                                 vf,"vf");
7785 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7786         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7787                                 vf_num, UINT8);
7788 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7789         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7790                                 address);
7791
7792 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7793         .f = cmd_vf_mac_addr_parsed,
7794         .data = (void *)0,
7795         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7796                 "Add MAC address filtering for a VF on port_id",
7797         .tokens = {
7798                 (void *)&cmd_vf_mac_addr_cmd,
7799                 (void *)&cmd_vf_mac_addr_what,
7800                 (void *)&cmd_vf_mac_addr_port,
7801                 (void *)&cmd_vf_mac_addr_portnum,
7802                 (void *)&cmd_vf_mac_addr_vf,
7803                 (void *)&cmd_vf_mac_addr_vfnum,
7804                 (void *)&cmd_vf_mac_addr_addr,
7805                 NULL,
7806         },
7807 };
7808
7809 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7810 struct cmd_vf_rx_vlan_filter {
7811         cmdline_fixed_string_t rx_vlan;
7812         cmdline_fixed_string_t what;
7813         uint16_t vlan_id;
7814         cmdline_fixed_string_t port;
7815         portid_t port_id;
7816         cmdline_fixed_string_t vf;
7817         uint64_t vf_mask;
7818 };
7819
7820 static void
7821 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7822                           __attribute__((unused)) struct cmdline *cl,
7823                           __attribute__((unused)) void *data)
7824 {
7825         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7826         int ret = -ENOTSUP;
7827
7828         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7829
7830 #ifdef RTE_LIBRTE_IXGBE_PMD
7831         if (ret == -ENOTSUP)
7832                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7833                                 res->vlan_id, res->vf_mask, is_add);
7834 #endif
7835 #ifdef RTE_LIBRTE_I40E_PMD
7836         if (ret == -ENOTSUP)
7837                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7838                                 res->vlan_id, res->vf_mask, is_add);
7839 #endif
7840 #ifdef RTE_LIBRTE_BNXT_PMD
7841         if (ret == -ENOTSUP)
7842                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7843                                 res->vlan_id, res->vf_mask, is_add);
7844 #endif
7845
7846         switch (ret) {
7847         case 0:
7848                 break;
7849         case -EINVAL:
7850                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7851                                 res->vlan_id, res->vf_mask);
7852                 break;
7853         case -ENODEV:
7854                 printf("invalid port_id %d\n", res->port_id);
7855                 break;
7856         case -ENOTSUP:
7857                 printf("function not implemented or supported\n");
7858                 break;
7859         default:
7860                 printf("programming error: (%s)\n", strerror(-ret));
7861         }
7862 }
7863
7864 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7865         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7866                                  rx_vlan, "rx_vlan");
7867 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7868         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7869                                  what, "add#rm");
7870 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7871         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7872                               vlan_id, UINT16);
7873 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7874         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7875                                  port, "port");
7876 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7877         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7878                               port_id, UINT16);
7879 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7880         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7881                                  vf, "vf");
7882 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7883         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7884                               vf_mask, UINT64);
7885
7886 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7887         .f = cmd_vf_rx_vlan_filter_parsed,
7888         .data = NULL,
7889         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7890                 "(vf_mask = hexadecimal VF mask)",
7891         .tokens = {
7892                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7893                 (void *)&cmd_vf_rx_vlan_filter_what,
7894                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7895                 (void *)&cmd_vf_rx_vlan_filter_port,
7896                 (void *)&cmd_vf_rx_vlan_filter_portid,
7897                 (void *)&cmd_vf_rx_vlan_filter_vf,
7898                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7899                 NULL,
7900         },
7901 };
7902
7903 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7904 struct cmd_queue_rate_limit_result {
7905         cmdline_fixed_string_t set;
7906         cmdline_fixed_string_t port;
7907         uint16_t port_num;
7908         cmdline_fixed_string_t queue;
7909         uint8_t queue_num;
7910         cmdline_fixed_string_t rate;
7911         uint16_t rate_num;
7912 };
7913
7914 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7915                 __attribute__((unused)) struct cmdline *cl,
7916                 __attribute__((unused)) void *data)
7917 {
7918         struct cmd_queue_rate_limit_result *res = parsed_result;
7919         int ret = 0;
7920
7921         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7922                 && (strcmp(res->queue, "queue") == 0)
7923                 && (strcmp(res->rate, "rate") == 0))
7924                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7925                                         res->rate_num);
7926         if (ret < 0)
7927                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7928
7929 }
7930
7931 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7932         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7933                                 set, "set");
7934 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7935         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7936                                 port, "port");
7937 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7938         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7939                                 port_num, UINT16);
7940 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7941         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7942                                 queue, "queue");
7943 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7944         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7945                                 queue_num, UINT8);
7946 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7947         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7948                                 rate, "rate");
7949 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7950         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7951                                 rate_num, UINT16);
7952
7953 cmdline_parse_inst_t cmd_queue_rate_limit = {
7954         .f = cmd_queue_rate_limit_parsed,
7955         .data = (void *)0,
7956         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7957                 "Set rate limit for a queue on port_id",
7958         .tokens = {
7959                 (void *)&cmd_queue_rate_limit_set,
7960                 (void *)&cmd_queue_rate_limit_port,
7961                 (void *)&cmd_queue_rate_limit_portnum,
7962                 (void *)&cmd_queue_rate_limit_queue,
7963                 (void *)&cmd_queue_rate_limit_queuenum,
7964                 (void *)&cmd_queue_rate_limit_rate,
7965                 (void *)&cmd_queue_rate_limit_ratenum,
7966                 NULL,
7967         },
7968 };
7969
7970 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7971 struct cmd_vf_rate_limit_result {
7972         cmdline_fixed_string_t set;
7973         cmdline_fixed_string_t port;
7974         uint16_t port_num;
7975         cmdline_fixed_string_t vf;
7976         uint8_t vf_num;
7977         cmdline_fixed_string_t rate;
7978         uint16_t rate_num;
7979         cmdline_fixed_string_t q_msk;
7980         uint64_t q_msk_val;
7981 };
7982
7983 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7984                 __attribute__((unused)) struct cmdline *cl,
7985                 __attribute__((unused)) void *data)
7986 {
7987         struct cmd_vf_rate_limit_result *res = parsed_result;
7988         int ret = 0;
7989
7990         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7991                 && (strcmp(res->vf, "vf") == 0)
7992                 && (strcmp(res->rate, "rate") == 0)
7993                 && (strcmp(res->q_msk, "queue_mask") == 0))
7994                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7995                                         res->rate_num, res->q_msk_val);
7996         if (ret < 0)
7997                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7998
7999 }
8000
8001 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8002         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8003                                 set, "set");
8004 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8005         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8006                                 port, "port");
8007 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8008         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8009                                 port_num, UINT16);
8010 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8011         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8012                                 vf, "vf");
8013 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8014         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8015                                 vf_num, UINT8);
8016 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8017         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8018                                 rate, "rate");
8019 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8020         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8021                                 rate_num, UINT16);
8022 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8023         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8024                                 q_msk, "queue_mask");
8025 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8026         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8027                                 q_msk_val, UINT64);
8028
8029 cmdline_parse_inst_t cmd_vf_rate_limit = {
8030         .f = cmd_vf_rate_limit_parsed,
8031         .data = (void *)0,
8032         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8033                 "queue_mask <queue_mask_value>: "
8034                 "Set rate limit for queues of VF on port_id",
8035         .tokens = {
8036                 (void *)&cmd_vf_rate_limit_set,
8037                 (void *)&cmd_vf_rate_limit_port,
8038                 (void *)&cmd_vf_rate_limit_portnum,
8039                 (void *)&cmd_vf_rate_limit_vf,
8040                 (void *)&cmd_vf_rate_limit_vfnum,
8041                 (void *)&cmd_vf_rate_limit_rate,
8042                 (void *)&cmd_vf_rate_limit_ratenum,
8043                 (void *)&cmd_vf_rate_limit_q_msk,
8044                 (void *)&cmd_vf_rate_limit_q_msk_val,
8045                 NULL,
8046         },
8047 };
8048
8049 /* *** ADD TUNNEL FILTER OF A PORT *** */
8050 struct cmd_tunnel_filter_result {
8051         cmdline_fixed_string_t cmd;
8052         cmdline_fixed_string_t what;
8053         portid_t port_id;
8054         struct ether_addr outer_mac;
8055         struct ether_addr inner_mac;
8056         cmdline_ipaddr_t ip_value;
8057         uint16_t inner_vlan;
8058         cmdline_fixed_string_t tunnel_type;
8059         cmdline_fixed_string_t filter_type;
8060         uint32_t tenant_id;
8061         uint16_t queue_num;
8062 };
8063
8064 static void
8065 cmd_tunnel_filter_parsed(void *parsed_result,
8066                           __attribute__((unused)) struct cmdline *cl,
8067                           __attribute__((unused)) void *data)
8068 {
8069         struct cmd_tunnel_filter_result *res = parsed_result;
8070         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8071         int ret = 0;
8072
8073         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8074
8075         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8076         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8077         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8078
8079         if (res->ip_value.family == AF_INET) {
8080                 tunnel_filter_conf.ip_addr.ipv4_addr =
8081                         res->ip_value.addr.ipv4.s_addr;
8082                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8083         } else {
8084                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8085                         &(res->ip_value.addr.ipv6),
8086                         sizeof(struct in6_addr));
8087                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8088         }
8089
8090         if (!strcmp(res->filter_type, "imac-ivlan"))
8091                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8092         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8093                 tunnel_filter_conf.filter_type =
8094                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8095         else if (!strcmp(res->filter_type, "imac-tenid"))
8096                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8097         else if (!strcmp(res->filter_type, "imac"))
8098                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8099         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8100                 tunnel_filter_conf.filter_type =
8101                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8102         else if (!strcmp(res->filter_type, "oip"))
8103                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8104         else if (!strcmp(res->filter_type, "iip"))
8105                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8106         else {
8107                 printf("The filter type is not supported");
8108                 return;
8109         }
8110
8111         if (!strcmp(res->tunnel_type, "vxlan"))
8112                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8113         else if (!strcmp(res->tunnel_type, "nvgre"))
8114                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8115         else if (!strcmp(res->tunnel_type, "ipingre"))
8116                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8117         else {
8118                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8119                 return;
8120         }
8121
8122         tunnel_filter_conf.tenant_id = res->tenant_id;
8123         tunnel_filter_conf.queue_id = res->queue_num;
8124         if (!strcmp(res->what, "add"))
8125                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8126                                         RTE_ETH_FILTER_TUNNEL,
8127                                         RTE_ETH_FILTER_ADD,
8128                                         &tunnel_filter_conf);
8129         else
8130                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8131                                         RTE_ETH_FILTER_TUNNEL,
8132                                         RTE_ETH_FILTER_DELETE,
8133                                         &tunnel_filter_conf);
8134         if (ret < 0)
8135                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8136                                 strerror(-ret));
8137
8138 }
8139 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8140         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8141         cmd, "tunnel_filter");
8142 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8143         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8144         what, "add#rm");
8145 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8146         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8147         port_id, UINT16);
8148 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8149         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8150         outer_mac);
8151 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8152         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8153         inner_mac);
8154 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8155         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8156         inner_vlan, UINT16);
8157 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8158         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8159         ip_value);
8160 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8161         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8162         tunnel_type, "vxlan#nvgre#ipingre");
8163
8164 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8165         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8166         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8167                 "imac#omac-imac-tenid");
8168 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8169         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8170         tenant_id, UINT32);
8171 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8172         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8173         queue_num, UINT16);
8174
8175 cmdline_parse_inst_t cmd_tunnel_filter = {
8176         .f = cmd_tunnel_filter_parsed,
8177         .data = (void *)0,
8178         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8179                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8180                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8181                 "<queue_id>: Add/Rm tunnel filter of a port",
8182         .tokens = {
8183                 (void *)&cmd_tunnel_filter_cmd,
8184                 (void *)&cmd_tunnel_filter_what,
8185                 (void *)&cmd_tunnel_filter_port_id,
8186                 (void *)&cmd_tunnel_filter_outer_mac,
8187                 (void *)&cmd_tunnel_filter_inner_mac,
8188                 (void *)&cmd_tunnel_filter_ip_value,
8189                 (void *)&cmd_tunnel_filter_innner_vlan,
8190                 (void *)&cmd_tunnel_filter_tunnel_type,
8191                 (void *)&cmd_tunnel_filter_filter_type,
8192                 (void *)&cmd_tunnel_filter_tenant_id,
8193                 (void *)&cmd_tunnel_filter_queue_num,
8194                 NULL,
8195         },
8196 };
8197
8198 /* *** CONFIGURE TUNNEL UDP PORT *** */
8199 struct cmd_tunnel_udp_config {
8200         cmdline_fixed_string_t cmd;
8201         cmdline_fixed_string_t what;
8202         uint16_t udp_port;
8203         portid_t port_id;
8204 };
8205
8206 static void
8207 cmd_tunnel_udp_config_parsed(void *parsed_result,
8208                           __attribute__((unused)) struct cmdline *cl,
8209                           __attribute__((unused)) void *data)
8210 {
8211         struct cmd_tunnel_udp_config *res = parsed_result;
8212         struct rte_eth_udp_tunnel tunnel_udp;
8213         int ret;
8214
8215         tunnel_udp.udp_port = res->udp_port;
8216
8217         if (!strcmp(res->cmd, "rx_vxlan_port"))
8218                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8219
8220         if (!strcmp(res->what, "add"))
8221                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8222                                                       &tunnel_udp);
8223         else
8224                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8225                                                          &tunnel_udp);
8226
8227         if (ret < 0)
8228                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8229 }
8230
8231 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8232         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8233                                 cmd, "rx_vxlan_port");
8234 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8235         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8236                                 what, "add#rm");
8237 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8238         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8239                                 udp_port, UINT16);
8240 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8241         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8242                                 port_id, UINT16);
8243
8244 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8245         .f = cmd_tunnel_udp_config_parsed,
8246         .data = (void *)0,
8247         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8248                 "Add/Remove a tunneling UDP port filter",
8249         .tokens = {
8250                 (void *)&cmd_tunnel_udp_config_cmd,
8251                 (void *)&cmd_tunnel_udp_config_what,
8252                 (void *)&cmd_tunnel_udp_config_udp_port,
8253                 (void *)&cmd_tunnel_udp_config_port_id,
8254                 NULL,
8255         },
8256 };
8257
8258 /* *** GLOBAL CONFIG *** */
8259 struct cmd_global_config_result {
8260         cmdline_fixed_string_t cmd;
8261         portid_t port_id;
8262         cmdline_fixed_string_t cfg_type;
8263         uint8_t len;
8264 };
8265
8266 static void
8267 cmd_global_config_parsed(void *parsed_result,
8268                          __attribute__((unused)) struct cmdline *cl,
8269                          __attribute__((unused)) void *data)
8270 {
8271         struct cmd_global_config_result *res = parsed_result;
8272         struct rte_eth_global_cfg conf;
8273         int ret;
8274
8275         memset(&conf, 0, sizeof(conf));
8276         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8277         conf.cfg.gre_key_len = res->len;
8278         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8279                                       RTE_ETH_FILTER_SET, &conf);
8280         if (ret != 0)
8281                 printf("Global config error\n");
8282 }
8283
8284 cmdline_parse_token_string_t cmd_global_config_cmd =
8285         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8286                 "global_config");
8287 cmdline_parse_token_num_t cmd_global_config_port_id =
8288         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8289                                UINT16);
8290 cmdline_parse_token_string_t cmd_global_config_type =
8291         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8292                 cfg_type, "gre-key-len");
8293 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8294         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8295                 len, UINT8);
8296
8297 cmdline_parse_inst_t cmd_global_config = {
8298         .f = cmd_global_config_parsed,
8299         .data = (void *)NULL,
8300         .help_str = "global_config <port_id> gre-key-len <key_len>",
8301         .tokens = {
8302                 (void *)&cmd_global_config_cmd,
8303                 (void *)&cmd_global_config_port_id,
8304                 (void *)&cmd_global_config_type,
8305                 (void *)&cmd_global_config_gre_key_len,
8306                 NULL,
8307         },
8308 };
8309
8310 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8311 struct cmd_set_mirror_mask_result {
8312         cmdline_fixed_string_t set;
8313         cmdline_fixed_string_t port;
8314         portid_t port_id;
8315         cmdline_fixed_string_t mirror;
8316         uint8_t rule_id;
8317         cmdline_fixed_string_t what;
8318         cmdline_fixed_string_t value;
8319         cmdline_fixed_string_t dstpool;
8320         uint8_t dstpool_id;
8321         cmdline_fixed_string_t on;
8322 };
8323
8324 cmdline_parse_token_string_t cmd_mirror_mask_set =
8325         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8326                                 set, "set");
8327 cmdline_parse_token_string_t cmd_mirror_mask_port =
8328         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8329                                 port, "port");
8330 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8331         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8332                                 port_id, UINT16);
8333 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8335                                 mirror, "mirror-rule");
8336 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8337         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8338                                 rule_id, UINT8);
8339 cmdline_parse_token_string_t cmd_mirror_mask_what =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8341                                 what, "pool-mirror-up#pool-mirror-down"
8342                                       "#vlan-mirror");
8343 cmdline_parse_token_string_t cmd_mirror_mask_value =
8344         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8345                                 value, NULL);
8346 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8347         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8348                                 dstpool, "dst-pool");
8349 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8350         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8351                                 dstpool_id, UINT8);
8352 cmdline_parse_token_string_t cmd_mirror_mask_on =
8353         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8354                                 on, "on#off");
8355
8356 static void
8357 cmd_set_mirror_mask_parsed(void *parsed_result,
8358                        __attribute__((unused)) struct cmdline *cl,
8359                        __attribute__((unused)) void *data)
8360 {
8361         int ret,nb_item,i;
8362         struct cmd_set_mirror_mask_result *res = parsed_result;
8363         struct rte_eth_mirror_conf mr_conf;
8364
8365         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8366
8367         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8368
8369         mr_conf.dst_pool = res->dstpool_id;
8370
8371         if (!strcmp(res->what, "pool-mirror-up")) {
8372                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8373                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8374         } else if (!strcmp(res->what, "pool-mirror-down")) {
8375                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8376                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8377         } else if (!strcmp(res->what, "vlan-mirror")) {
8378                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8379                 nb_item = parse_item_list(res->value, "vlan",
8380                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8381                 if (nb_item <= 0)
8382                         return;
8383
8384                 for (i = 0; i < nb_item; i++) {
8385                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8386                                 printf("Invalid vlan_id: must be < 4096\n");
8387                                 return;
8388                         }
8389
8390                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8391                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8392                 }
8393         }
8394
8395         if (!strcmp(res->on, "on"))
8396                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8397                                                 res->rule_id, 1);
8398         else
8399                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8400                                                 res->rule_id, 0);
8401         if (ret < 0)
8402                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8403 }
8404
8405 cmdline_parse_inst_t cmd_set_mirror_mask = {
8406                 .f = cmd_set_mirror_mask_parsed,
8407                 .data = NULL,
8408                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8409                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8410                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8411                 .tokens = {
8412                         (void *)&cmd_mirror_mask_set,
8413                         (void *)&cmd_mirror_mask_port,
8414                         (void *)&cmd_mirror_mask_portid,
8415                         (void *)&cmd_mirror_mask_mirror,
8416                         (void *)&cmd_mirror_mask_ruleid,
8417                         (void *)&cmd_mirror_mask_what,
8418                         (void *)&cmd_mirror_mask_value,
8419                         (void *)&cmd_mirror_mask_dstpool,
8420                         (void *)&cmd_mirror_mask_poolid,
8421                         (void *)&cmd_mirror_mask_on,
8422                         NULL,
8423                 },
8424 };
8425
8426 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8427 struct cmd_set_mirror_link_result {
8428         cmdline_fixed_string_t set;
8429         cmdline_fixed_string_t port;
8430         portid_t port_id;
8431         cmdline_fixed_string_t mirror;
8432         uint8_t rule_id;
8433         cmdline_fixed_string_t what;
8434         cmdline_fixed_string_t dstpool;
8435         uint8_t dstpool_id;
8436         cmdline_fixed_string_t on;
8437 };
8438
8439 cmdline_parse_token_string_t cmd_mirror_link_set =
8440         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8441                                  set, "set");
8442 cmdline_parse_token_string_t cmd_mirror_link_port =
8443         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8444                                 port, "port");
8445 cmdline_parse_token_num_t cmd_mirror_link_portid =
8446         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8447                                 port_id, UINT16);
8448 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8449         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8450                                 mirror, "mirror-rule");
8451 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8452         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8453                             rule_id, UINT8);
8454 cmdline_parse_token_string_t cmd_mirror_link_what =
8455         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8456                                 what, "uplink-mirror#downlink-mirror");
8457 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8458         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8459                                 dstpool, "dst-pool");
8460 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8461         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8462                                 dstpool_id, UINT8);
8463 cmdline_parse_token_string_t cmd_mirror_link_on =
8464         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8465                                 on, "on#off");
8466
8467 static void
8468 cmd_set_mirror_link_parsed(void *parsed_result,
8469                        __attribute__((unused)) struct cmdline *cl,
8470                        __attribute__((unused)) void *data)
8471 {
8472         int ret;
8473         struct cmd_set_mirror_link_result *res = parsed_result;
8474         struct rte_eth_mirror_conf mr_conf;
8475
8476         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8477         if (!strcmp(res->what, "uplink-mirror"))
8478                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8479         else
8480                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8481
8482         mr_conf.dst_pool = res->dstpool_id;
8483
8484         if (!strcmp(res->on, "on"))
8485                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8486                                                 res->rule_id, 1);
8487         else
8488                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8489                                                 res->rule_id, 0);
8490
8491         /* check the return value and print it if is < 0 */
8492         if (ret < 0)
8493                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8494
8495 }
8496
8497 cmdline_parse_inst_t cmd_set_mirror_link = {
8498                 .f = cmd_set_mirror_link_parsed,
8499                 .data = NULL,
8500                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8501                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8502                 .tokens = {
8503                         (void *)&cmd_mirror_link_set,
8504                         (void *)&cmd_mirror_link_port,
8505                         (void *)&cmd_mirror_link_portid,
8506                         (void *)&cmd_mirror_link_mirror,
8507                         (void *)&cmd_mirror_link_ruleid,
8508                         (void *)&cmd_mirror_link_what,
8509                         (void *)&cmd_mirror_link_dstpool,
8510                         (void *)&cmd_mirror_link_poolid,
8511                         (void *)&cmd_mirror_link_on,
8512                         NULL,
8513                 },
8514 };
8515
8516 /* *** RESET VM MIRROR RULE *** */
8517 struct cmd_rm_mirror_rule_result {
8518         cmdline_fixed_string_t reset;
8519         cmdline_fixed_string_t port;
8520         portid_t port_id;
8521         cmdline_fixed_string_t mirror;
8522         uint8_t rule_id;
8523 };
8524
8525 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8526         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8527                                  reset, "reset");
8528 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8529         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8530                                 port, "port");
8531 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8532         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8533                                 port_id, UINT16);
8534 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8535         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8536                                 mirror, "mirror-rule");
8537 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8538         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8539                                 rule_id, UINT8);
8540
8541 static void
8542 cmd_reset_mirror_rule_parsed(void *parsed_result,
8543                        __attribute__((unused)) struct cmdline *cl,
8544                        __attribute__((unused)) void *data)
8545 {
8546         int ret;
8547         struct cmd_set_mirror_link_result *res = parsed_result;
8548         /* check rule_id */
8549         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8550         if(ret < 0)
8551                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8552 }
8553
8554 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8555                 .f = cmd_reset_mirror_rule_parsed,
8556                 .data = NULL,
8557                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8558                 .tokens = {
8559                         (void *)&cmd_rm_mirror_rule_reset,
8560                         (void *)&cmd_rm_mirror_rule_port,
8561                         (void *)&cmd_rm_mirror_rule_portid,
8562                         (void *)&cmd_rm_mirror_rule_mirror,
8563                         (void *)&cmd_rm_mirror_rule_ruleid,
8564                         NULL,
8565                 },
8566 };
8567
8568 /* ******************************************************************************** */
8569
8570 struct cmd_dump_result {
8571         cmdline_fixed_string_t dump;
8572 };
8573
8574 static void
8575 dump_struct_sizes(void)
8576 {
8577 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8578         DUMP_SIZE(struct rte_mbuf);
8579         DUMP_SIZE(struct rte_mempool);
8580         DUMP_SIZE(struct rte_ring);
8581 #undef DUMP_SIZE
8582 }
8583
8584 static void cmd_dump_parsed(void *parsed_result,
8585                             __attribute__((unused)) struct cmdline *cl,
8586                             __attribute__((unused)) void *data)
8587 {
8588         struct cmd_dump_result *res = parsed_result;
8589
8590         if (!strcmp(res->dump, "dump_physmem"))
8591                 rte_dump_physmem_layout(stdout);
8592         else if (!strcmp(res->dump, "dump_memzone"))
8593                 rte_memzone_dump(stdout);
8594         else if (!strcmp(res->dump, "dump_struct_sizes"))
8595                 dump_struct_sizes();
8596         else if (!strcmp(res->dump, "dump_ring"))
8597                 rte_ring_list_dump(stdout);
8598         else if (!strcmp(res->dump, "dump_mempool"))
8599                 rte_mempool_list_dump(stdout);
8600         else if (!strcmp(res->dump, "dump_devargs"))
8601                 rte_eal_devargs_dump(stdout);
8602         else if (!strcmp(res->dump, "dump_log_types"))
8603                 rte_log_dump(stdout);
8604 }
8605
8606 cmdline_parse_token_string_t cmd_dump_dump =
8607         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8608                 "dump_physmem#"
8609                 "dump_memzone#"
8610                 "dump_struct_sizes#"
8611                 "dump_ring#"
8612                 "dump_mempool#"
8613                 "dump_devargs#"
8614                 "dump_log_types");
8615
8616 cmdline_parse_inst_t cmd_dump = {
8617         .f = cmd_dump_parsed,  /* function to call */
8618         .data = NULL,      /* 2nd arg of func */
8619         .help_str = "Dump status",
8620         .tokens = {        /* token list, NULL terminated */
8621                 (void *)&cmd_dump_dump,
8622                 NULL,
8623         },
8624 };
8625
8626 /* ******************************************************************************** */
8627
8628 struct cmd_dump_one_result {
8629         cmdline_fixed_string_t dump;
8630         cmdline_fixed_string_t name;
8631 };
8632
8633 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8634                                 __attribute__((unused)) void *data)
8635 {
8636         struct cmd_dump_one_result *res = parsed_result;
8637
8638         if (!strcmp(res->dump, "dump_ring")) {
8639                 struct rte_ring *r;
8640                 r = rte_ring_lookup(res->name);
8641                 if (r == NULL) {
8642                         cmdline_printf(cl, "Cannot find ring\n");
8643                         return;
8644                 }
8645                 rte_ring_dump(stdout, r);
8646         } else if (!strcmp(res->dump, "dump_mempool")) {
8647                 struct rte_mempool *mp;
8648                 mp = rte_mempool_lookup(res->name);
8649                 if (mp == NULL) {
8650                         cmdline_printf(cl, "Cannot find mempool\n");
8651                         return;
8652                 }
8653                 rte_mempool_dump(stdout, mp);
8654         }
8655 }
8656
8657 cmdline_parse_token_string_t cmd_dump_one_dump =
8658         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8659                                  "dump_ring#dump_mempool");
8660
8661 cmdline_parse_token_string_t cmd_dump_one_name =
8662         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8663
8664 cmdline_parse_inst_t cmd_dump_one = {
8665         .f = cmd_dump_one_parsed,  /* function to call */
8666         .data = NULL,      /* 2nd arg of func */
8667         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8668         .tokens = {        /* token list, NULL terminated */
8669                 (void *)&cmd_dump_one_dump,
8670                 (void *)&cmd_dump_one_name,
8671                 NULL,
8672         },
8673 };
8674
8675 /* *** Add/Del syn filter *** */
8676 struct cmd_syn_filter_result {
8677         cmdline_fixed_string_t filter;
8678         portid_t port_id;
8679         cmdline_fixed_string_t ops;
8680         cmdline_fixed_string_t priority;
8681         cmdline_fixed_string_t high;
8682         cmdline_fixed_string_t queue;
8683         uint16_t queue_id;
8684 };
8685
8686 static void
8687 cmd_syn_filter_parsed(void *parsed_result,
8688                         __attribute__((unused)) struct cmdline *cl,
8689                         __attribute__((unused)) void *data)
8690 {
8691         struct cmd_syn_filter_result *res = parsed_result;
8692         struct rte_eth_syn_filter syn_filter;
8693         int ret = 0;
8694
8695         ret = rte_eth_dev_filter_supported(res->port_id,
8696                                         RTE_ETH_FILTER_SYN);
8697         if (ret < 0) {
8698                 printf("syn filter is not supported on port %u.\n",
8699                                 res->port_id);
8700                 return;
8701         }
8702
8703         memset(&syn_filter, 0, sizeof(syn_filter));
8704
8705         if (!strcmp(res->ops, "add")) {
8706                 if (!strcmp(res->high, "high"))
8707                         syn_filter.hig_pri = 1;
8708                 else
8709                         syn_filter.hig_pri = 0;
8710
8711                 syn_filter.queue = res->queue_id;
8712                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8713                                                 RTE_ETH_FILTER_SYN,
8714                                                 RTE_ETH_FILTER_ADD,
8715                                                 &syn_filter);
8716         } else
8717                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8718                                                 RTE_ETH_FILTER_SYN,
8719                                                 RTE_ETH_FILTER_DELETE,
8720                                                 &syn_filter);
8721
8722         if (ret < 0)
8723                 printf("syn filter programming error: (%s)\n",
8724                                 strerror(-ret));
8725 }
8726
8727 cmdline_parse_token_string_t cmd_syn_filter_filter =
8728         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8729         filter, "syn_filter");
8730 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8731         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8732         port_id, UINT16);
8733 cmdline_parse_token_string_t cmd_syn_filter_ops =
8734         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8735         ops, "add#del");
8736 cmdline_parse_token_string_t cmd_syn_filter_priority =
8737         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8738                                 priority, "priority");
8739 cmdline_parse_token_string_t cmd_syn_filter_high =
8740         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8741                                 high, "high#low");
8742 cmdline_parse_token_string_t cmd_syn_filter_queue =
8743         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8744                                 queue, "queue");
8745 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8746         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8747                                 queue_id, UINT16);
8748
8749 cmdline_parse_inst_t cmd_syn_filter = {
8750         .f = cmd_syn_filter_parsed,
8751         .data = NULL,
8752         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8753                 "<queue_id>: Add/Delete syn filter",
8754         .tokens = {
8755                 (void *)&cmd_syn_filter_filter,
8756                 (void *)&cmd_syn_filter_port_id,
8757                 (void *)&cmd_syn_filter_ops,
8758                 (void *)&cmd_syn_filter_priority,
8759                 (void *)&cmd_syn_filter_high,
8760                 (void *)&cmd_syn_filter_queue,
8761                 (void *)&cmd_syn_filter_queue_id,
8762                 NULL,
8763         },
8764 };
8765
8766 /* *** queue region set *** */
8767 struct cmd_queue_region_result {
8768         cmdline_fixed_string_t set;
8769         cmdline_fixed_string_t port;
8770         portid_t port_id;
8771         cmdline_fixed_string_t cmd;
8772         cmdline_fixed_string_t region;
8773         uint8_t  region_id;
8774         cmdline_fixed_string_t queue_start_index;
8775         uint8_t  queue_id;
8776         cmdline_fixed_string_t queue_num;
8777         uint8_t  queue_num_value;
8778 };
8779
8780 static void
8781 cmd_queue_region_parsed(void *parsed_result,
8782                         __attribute__((unused)) struct cmdline *cl,
8783                         __attribute__((unused)) void *data)
8784 {
8785         struct cmd_queue_region_result *res = parsed_result;
8786         int ret = -ENOTSUP;
8787 #ifdef RTE_LIBRTE_I40E_PMD
8788         struct rte_pmd_i40e_queue_region_conf region_conf;
8789         enum rte_pmd_i40e_queue_region_op op_type;
8790 #endif
8791
8792         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8793                 return;
8794
8795 #ifdef RTE_LIBRTE_I40E_PMD
8796         memset(&region_conf, 0, sizeof(region_conf));
8797         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8798         region_conf.region_id = res->region_id;
8799         region_conf.queue_num = res->queue_num_value;
8800         region_conf.queue_start_index = res->queue_id;
8801
8802         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8803                                 op_type, &region_conf);
8804 #endif
8805
8806         switch (ret) {
8807         case 0:
8808                 break;
8809         case -ENOTSUP:
8810                 printf("function not implemented or supported\n");
8811                 break;
8812         default:
8813                 printf("queue region config error: (%s)\n", strerror(-ret));
8814         }
8815 }
8816
8817 cmdline_parse_token_string_t cmd_queue_region_set =
8818 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8819                 set, "set");
8820 cmdline_parse_token_string_t cmd_queue_region_port =
8821         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8822 cmdline_parse_token_num_t cmd_queue_region_port_id =
8823         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8824                                 port_id, UINT16);
8825 cmdline_parse_token_string_t cmd_queue_region_cmd =
8826         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8827                                  cmd, "queue-region");
8828 cmdline_parse_token_string_t cmd_queue_region_id =
8829         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8830                                 region, "region_id");
8831 cmdline_parse_token_num_t cmd_queue_region_index =
8832         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8833                                 region_id, UINT8);
8834 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8835         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8836                                 queue_start_index, "queue_start_index");
8837 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8838         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8839                                 queue_id, UINT8);
8840 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8841         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8842                                 queue_num, "queue_num");
8843 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8844         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8845                                 queue_num_value, UINT8);
8846
8847 cmdline_parse_inst_t cmd_queue_region = {
8848         .f = cmd_queue_region_parsed,
8849         .data = NULL,
8850         .help_str = "set port <port_id> queue-region region_id <value> "
8851                 "queue_start_index <value> queue_num <value>: Set a queue region",
8852         .tokens = {
8853                 (void *)&cmd_queue_region_set,
8854                 (void *)&cmd_queue_region_port,
8855                 (void *)&cmd_queue_region_port_id,
8856                 (void *)&cmd_queue_region_cmd,
8857                 (void *)&cmd_queue_region_id,
8858                 (void *)&cmd_queue_region_index,
8859                 (void *)&cmd_queue_region_queue_start_index,
8860                 (void *)&cmd_queue_region_queue_id,
8861                 (void *)&cmd_queue_region_queue_num,
8862                 (void *)&cmd_queue_region_queue_num_value,
8863                 NULL,
8864         },
8865 };
8866
8867 /* *** queue region and flowtype set *** */
8868 struct cmd_region_flowtype_result {
8869         cmdline_fixed_string_t set;
8870         cmdline_fixed_string_t port;
8871         portid_t port_id;
8872         cmdline_fixed_string_t cmd;
8873         cmdline_fixed_string_t region;
8874         uint8_t  region_id;
8875         cmdline_fixed_string_t flowtype;
8876         uint8_t  flowtype_id;
8877 };
8878
8879 static void
8880 cmd_region_flowtype_parsed(void *parsed_result,
8881                         __attribute__((unused)) struct cmdline *cl,
8882                         __attribute__((unused)) void *data)
8883 {
8884         struct cmd_region_flowtype_result *res = parsed_result;
8885         int ret = -ENOTSUP;
8886 #ifdef RTE_LIBRTE_I40E_PMD
8887         struct rte_pmd_i40e_queue_region_conf region_conf;
8888         enum rte_pmd_i40e_queue_region_op op_type;
8889 #endif
8890
8891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8892                 return;
8893
8894 #ifdef RTE_LIBRTE_I40E_PMD
8895         memset(&region_conf, 0, sizeof(region_conf));
8896
8897         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8898         region_conf.region_id = res->region_id;
8899         region_conf.hw_flowtype = res->flowtype_id;
8900
8901         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8902                         op_type, &region_conf);
8903 #endif
8904
8905         switch (ret) {
8906         case 0:
8907                 break;
8908         case -ENOTSUP:
8909                 printf("function not implemented or supported\n");
8910                 break;
8911         default:
8912                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8913         }
8914 }
8915
8916 cmdline_parse_token_string_t cmd_region_flowtype_set =
8917 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8918                                 set, "set");
8919 cmdline_parse_token_string_t cmd_region_flowtype_port =
8920         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8921                                 port, "port");
8922 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8923         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8924                                 port_id, UINT16);
8925 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8926         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8927                                 cmd, "queue-region");
8928 cmdline_parse_token_string_t cmd_region_flowtype_index =
8929         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8930                                 region, "region_id");
8931 cmdline_parse_token_num_t cmd_region_flowtype_id =
8932         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8933                                 region_id, UINT8);
8934 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8935         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8936                                 flowtype, "flowtype");
8937 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8938         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8939                                 flowtype_id, UINT8);
8940 cmdline_parse_inst_t cmd_region_flowtype = {
8941         .f = cmd_region_flowtype_parsed,
8942         .data = NULL,
8943         .help_str = "set port <port_id> queue-region region_id <value> "
8944                 "flowtype <value>: Set a flowtype region index",
8945         .tokens = {
8946                 (void *)&cmd_region_flowtype_set,
8947                 (void *)&cmd_region_flowtype_port,
8948                 (void *)&cmd_region_flowtype_port_index,
8949                 (void *)&cmd_region_flowtype_cmd,
8950                 (void *)&cmd_region_flowtype_index,
8951                 (void *)&cmd_region_flowtype_id,
8952                 (void *)&cmd_region_flowtype_flow_index,
8953                 (void *)&cmd_region_flowtype_flow_id,
8954                 NULL,
8955         },
8956 };
8957
8958 /* *** User Priority (UP) to queue region (region_id) set *** */
8959 struct cmd_user_priority_region_result {
8960         cmdline_fixed_string_t set;
8961         cmdline_fixed_string_t port;
8962         portid_t port_id;
8963         cmdline_fixed_string_t cmd;
8964         cmdline_fixed_string_t user_priority;
8965         uint8_t  user_priority_id;
8966         cmdline_fixed_string_t region;
8967         uint8_t  region_id;
8968 };
8969
8970 static void
8971 cmd_user_priority_region_parsed(void *parsed_result,
8972                         __attribute__((unused)) struct cmdline *cl,
8973                         __attribute__((unused)) void *data)
8974 {
8975         struct cmd_user_priority_region_result *res = parsed_result;
8976         int ret = -ENOTSUP;
8977 #ifdef RTE_LIBRTE_I40E_PMD
8978         struct rte_pmd_i40e_queue_region_conf region_conf;
8979         enum rte_pmd_i40e_queue_region_op op_type;
8980 #endif
8981
8982         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8983                 return;
8984
8985 #ifdef RTE_LIBRTE_I40E_PMD
8986         memset(&region_conf, 0, sizeof(region_conf));
8987         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8988         region_conf.user_priority = res->user_priority_id;
8989         region_conf.region_id = res->region_id;
8990
8991         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8992                                 op_type, &region_conf);
8993 #endif
8994
8995         switch (ret) {
8996         case 0:
8997                 break;
8998         case -ENOTSUP:
8999                 printf("function not implemented or supported\n");
9000                 break;
9001         default:
9002                 printf("user_priority region config error: (%s)\n",
9003                                 strerror(-ret));
9004         }
9005 }
9006
9007 cmdline_parse_token_string_t cmd_user_priority_region_set =
9008         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9009                                 set, "set");
9010 cmdline_parse_token_string_t cmd_user_priority_region_port =
9011         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9012                                 port, "port");
9013 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9014         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9015                                 port_id, UINT16);
9016 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9017         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9018                                 cmd, "queue-region");
9019 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9020         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9021                                 user_priority, "UP");
9022 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9023         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9024                                 user_priority_id, UINT8);
9025 cmdline_parse_token_string_t cmd_user_priority_region_region =
9026         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9027                                 region, "region_id");
9028 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9029         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9030                                 region_id, UINT8);
9031
9032 cmdline_parse_inst_t cmd_user_priority_region = {
9033         .f = cmd_user_priority_region_parsed,
9034         .data = NULL,
9035         .help_str = "set port <port_id> queue-region UP <value> "
9036                 "region_id <value>: Set the mapping of User Priority (UP) "
9037                 "to queue region (region_id) ",
9038         .tokens = {
9039                 (void *)&cmd_user_priority_region_set,
9040                 (void *)&cmd_user_priority_region_port,
9041                 (void *)&cmd_user_priority_region_port_index,
9042                 (void *)&cmd_user_priority_region_cmd,
9043                 (void *)&cmd_user_priority_region_UP,
9044                 (void *)&cmd_user_priority_region_UP_id,
9045                 (void *)&cmd_user_priority_region_region,
9046                 (void *)&cmd_user_priority_region_region_id,
9047                 NULL,
9048         },
9049 };
9050
9051 /* *** flush all queue region related configuration *** */
9052 struct cmd_flush_queue_region_result {
9053         cmdline_fixed_string_t set;
9054         cmdline_fixed_string_t port;
9055         portid_t port_id;
9056         cmdline_fixed_string_t cmd;
9057         cmdline_fixed_string_t flush;
9058         cmdline_fixed_string_t what;
9059 };
9060
9061 static void
9062 cmd_flush_queue_region_parsed(void *parsed_result,
9063                         __attribute__((unused)) struct cmdline *cl,
9064                         __attribute__((unused)) void *data)
9065 {
9066         struct cmd_flush_queue_region_result *res = parsed_result;
9067         int ret = -ENOTSUP;
9068 #ifdef RTE_LIBRTE_I40E_PMD
9069         struct rte_pmd_i40e_queue_region_conf region_conf;
9070         enum rte_pmd_i40e_queue_region_op op_type;
9071 #endif
9072
9073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9074                 return;
9075
9076 #ifdef RTE_LIBRTE_I40E_PMD
9077         memset(&region_conf, 0, sizeof(region_conf));
9078
9079         if (strcmp(res->what, "on") == 0)
9080                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9081         else
9082                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9083
9084         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9085                                 op_type, &region_conf);
9086 #endif
9087
9088         switch (ret) {
9089         case 0:
9090                 break;
9091         case -ENOTSUP:
9092                 printf("function not implemented or supported\n");
9093                 break;
9094         default:
9095                 printf("queue region config flush error: (%s)\n",
9096                                 strerror(-ret));
9097         }
9098 }
9099
9100 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9101         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9102                                 set, "set");
9103 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9104         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9105                                 port, "port");
9106 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9107         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9108                                 port_id, UINT16);
9109 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9110         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9111                                 cmd, "queue-region");
9112 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9113         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9114                                 flush, "flush");
9115 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9116         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9117                                 what, "on#off");
9118
9119 cmdline_parse_inst_t cmd_flush_queue_region = {
9120         .f = cmd_flush_queue_region_parsed,
9121         .data = NULL,
9122         .help_str = "set port <port_id> queue-region flush on|off"
9123                 ": flush all queue region related configuration",
9124         .tokens = {
9125                 (void *)&cmd_flush_queue_region_set,
9126                 (void *)&cmd_flush_queue_region_port,
9127                 (void *)&cmd_flush_queue_region_port_index,
9128                 (void *)&cmd_flush_queue_region_cmd,
9129                 (void *)&cmd_flush_queue_region_flush,
9130                 (void *)&cmd_flush_queue_region_what,
9131                 NULL,
9132         },
9133 };
9134
9135 /* *** get all queue region related configuration info *** */
9136 struct cmd_show_queue_region_info {
9137         cmdline_fixed_string_t show;
9138         cmdline_fixed_string_t port;
9139         portid_t port_id;
9140         cmdline_fixed_string_t cmd;
9141 };
9142
9143 static void
9144 cmd_show_queue_region_info_parsed(void *parsed_result,
9145                         __attribute__((unused)) struct cmdline *cl,
9146                         __attribute__((unused)) void *data)
9147 {
9148         struct cmd_show_queue_region_info *res = parsed_result;
9149         int ret = -ENOTSUP;
9150 #ifdef RTE_LIBRTE_I40E_PMD
9151         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9152         enum rte_pmd_i40e_queue_region_op op_type;
9153 #endif
9154
9155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9156                 return;
9157
9158 #ifdef RTE_LIBRTE_I40E_PMD
9159         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9160
9161         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9162
9163         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9164                                         op_type, &rte_pmd_regions);
9165
9166         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9167 #endif
9168
9169         switch (ret) {
9170         case 0:
9171                 break;
9172         case -ENOTSUP:
9173                 printf("function not implemented or supported\n");
9174                 break;
9175         default:
9176                 printf("queue region config info show error: (%s)\n",
9177                                 strerror(-ret));
9178         }
9179 }
9180
9181 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9182 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9183                                 show, "show");
9184 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9185         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9186                                 port, "port");
9187 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9188         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9189                                 port_id, UINT16);
9190 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9191         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9192                                 cmd, "queue-region");
9193
9194 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9195         .f = cmd_show_queue_region_info_parsed,
9196         .data = NULL,
9197         .help_str = "show port <port_id> queue-region"
9198                 ": show all queue region related configuration info",
9199         .tokens = {
9200                 (void *)&cmd_show_queue_region_info_get,
9201                 (void *)&cmd_show_queue_region_info_port,
9202                 (void *)&cmd_show_queue_region_info_port_index,
9203                 (void *)&cmd_show_queue_region_info_cmd,
9204                 NULL,
9205         },
9206 };
9207
9208 /* *** ADD/REMOVE A 2tuple FILTER *** */
9209 struct cmd_2tuple_filter_result {
9210         cmdline_fixed_string_t filter;
9211         portid_t port_id;
9212         cmdline_fixed_string_t ops;
9213         cmdline_fixed_string_t dst_port;
9214         uint16_t dst_port_value;
9215         cmdline_fixed_string_t protocol;
9216         uint8_t protocol_value;
9217         cmdline_fixed_string_t mask;
9218         uint8_t  mask_value;
9219         cmdline_fixed_string_t tcp_flags;
9220         uint8_t tcp_flags_value;
9221         cmdline_fixed_string_t priority;
9222         uint8_t  priority_value;
9223         cmdline_fixed_string_t queue;
9224         uint16_t  queue_id;
9225 };
9226
9227 static void
9228 cmd_2tuple_filter_parsed(void *parsed_result,
9229                         __attribute__((unused)) struct cmdline *cl,
9230                         __attribute__((unused)) void *data)
9231 {
9232         struct rte_eth_ntuple_filter filter;
9233         struct cmd_2tuple_filter_result *res = parsed_result;
9234         int ret = 0;
9235
9236         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9237         if (ret < 0) {
9238                 printf("ntuple filter is not supported on port %u.\n",
9239                         res->port_id);
9240                 return;
9241         }
9242
9243         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9244
9245         filter.flags = RTE_2TUPLE_FLAGS;
9246         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9247         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9248         filter.proto = res->protocol_value;
9249         filter.priority = res->priority_value;
9250         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9251                 printf("nonzero tcp_flags is only meaningful"
9252                         " when protocol is TCP.\n");
9253                 return;
9254         }
9255         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9256                 printf("invalid TCP flags.\n");
9257                 return;
9258         }
9259
9260         if (res->tcp_flags_value != 0) {
9261                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9262                 filter.tcp_flags = res->tcp_flags_value;
9263         }
9264
9265         /* need convert to big endian. */
9266         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9267         filter.queue = res->queue_id;
9268
9269         if (!strcmp(res->ops, "add"))
9270                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9271                                 RTE_ETH_FILTER_NTUPLE,
9272                                 RTE_ETH_FILTER_ADD,
9273                                 &filter);
9274         else
9275                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9276                                 RTE_ETH_FILTER_NTUPLE,
9277                                 RTE_ETH_FILTER_DELETE,
9278                                 &filter);
9279         if (ret < 0)
9280                 printf("2tuple filter programming error: (%s)\n",
9281                         strerror(-ret));
9282
9283 }
9284
9285 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9286         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9287                                  filter, "2tuple_filter");
9288 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9289         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9290                                 port_id, UINT16);
9291 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9292         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9293                                  ops, "add#del");
9294 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9295         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9296                                 dst_port, "dst_port");
9297 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9298         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9299                                 dst_port_value, UINT16);
9300 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9301         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9302                                 protocol, "protocol");
9303 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9304         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9305                                 protocol_value, UINT8);
9306 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9307         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9308                                 mask, "mask");
9309 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9310         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9311                                 mask_value, INT8);
9312 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9313         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9314                                 tcp_flags, "tcp_flags");
9315 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9316         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9317                                 tcp_flags_value, UINT8);
9318 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9319         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9320                                 priority, "priority");
9321 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9322         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9323                                 priority_value, UINT8);
9324 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9325         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9326                                 queue, "queue");
9327 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9328         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9329                                 queue_id, UINT16);
9330
9331 cmdline_parse_inst_t cmd_2tuple_filter = {
9332         .f = cmd_2tuple_filter_parsed,
9333         .data = NULL,
9334         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9335                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9336                 "<queue_id>: Add a 2tuple filter",
9337         .tokens = {
9338                 (void *)&cmd_2tuple_filter_filter,
9339                 (void *)&cmd_2tuple_filter_port_id,
9340                 (void *)&cmd_2tuple_filter_ops,
9341                 (void *)&cmd_2tuple_filter_dst_port,
9342                 (void *)&cmd_2tuple_filter_dst_port_value,
9343                 (void *)&cmd_2tuple_filter_protocol,
9344                 (void *)&cmd_2tuple_filter_protocol_value,
9345                 (void *)&cmd_2tuple_filter_mask,
9346                 (void *)&cmd_2tuple_filter_mask_value,
9347                 (void *)&cmd_2tuple_filter_tcp_flags,
9348                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9349                 (void *)&cmd_2tuple_filter_priority,
9350                 (void *)&cmd_2tuple_filter_priority_value,
9351                 (void *)&cmd_2tuple_filter_queue,
9352                 (void *)&cmd_2tuple_filter_queue_id,
9353                 NULL,
9354         },
9355 };
9356
9357 /* *** ADD/REMOVE A 5tuple FILTER *** */
9358 struct cmd_5tuple_filter_result {
9359         cmdline_fixed_string_t filter;
9360         portid_t port_id;
9361         cmdline_fixed_string_t ops;
9362         cmdline_fixed_string_t dst_ip;
9363         cmdline_ipaddr_t dst_ip_value;
9364         cmdline_fixed_string_t src_ip;
9365         cmdline_ipaddr_t src_ip_value;
9366         cmdline_fixed_string_t dst_port;
9367         uint16_t dst_port_value;
9368         cmdline_fixed_string_t src_port;
9369         uint16_t src_port_value;
9370         cmdline_fixed_string_t protocol;
9371         uint8_t protocol_value;
9372         cmdline_fixed_string_t mask;
9373         uint8_t  mask_value;
9374         cmdline_fixed_string_t tcp_flags;
9375         uint8_t tcp_flags_value;
9376         cmdline_fixed_string_t priority;
9377         uint8_t  priority_value;
9378         cmdline_fixed_string_t queue;
9379         uint16_t  queue_id;
9380 };
9381
9382 static void
9383 cmd_5tuple_filter_parsed(void *parsed_result,
9384                         __attribute__((unused)) struct cmdline *cl,
9385                         __attribute__((unused)) void *data)
9386 {
9387         struct rte_eth_ntuple_filter filter;
9388         struct cmd_5tuple_filter_result *res = parsed_result;
9389         int ret = 0;
9390
9391         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9392         if (ret < 0) {
9393                 printf("ntuple filter is not supported on port %u.\n",
9394                         res->port_id);
9395                 return;
9396         }
9397
9398         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9399
9400         filter.flags = RTE_5TUPLE_FLAGS;
9401         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9402         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9403         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9404         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9405         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9406         filter.proto = res->protocol_value;
9407         filter.priority = res->priority_value;
9408         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9409                 printf("nonzero tcp_flags is only meaningful"
9410                         " when protocol is TCP.\n");
9411                 return;
9412         }
9413         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9414                 printf("invalid TCP flags.\n");
9415                 return;
9416         }
9417
9418         if (res->tcp_flags_value != 0) {
9419                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9420                 filter.tcp_flags = res->tcp_flags_value;
9421         }
9422
9423         if (res->dst_ip_value.family == AF_INET)
9424                 /* no need to convert, already big endian. */
9425                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9426         else {
9427                 if (filter.dst_ip_mask == 0) {
9428                         printf("can not support ipv6 involved compare.\n");
9429                         return;
9430                 }
9431                 filter.dst_ip = 0;
9432         }
9433
9434         if (res->src_ip_value.family == AF_INET)
9435                 /* no need to convert, already big endian. */
9436                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9437         else {
9438                 if (filter.src_ip_mask == 0) {
9439                         printf("can not support ipv6 involved compare.\n");
9440                         return;
9441                 }
9442                 filter.src_ip = 0;
9443         }
9444         /* need convert to big endian. */
9445         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9446         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9447         filter.queue = res->queue_id;
9448
9449         if (!strcmp(res->ops, "add"))
9450                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9451                                 RTE_ETH_FILTER_NTUPLE,
9452                                 RTE_ETH_FILTER_ADD,
9453                                 &filter);
9454         else
9455                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9456                                 RTE_ETH_FILTER_NTUPLE,
9457                                 RTE_ETH_FILTER_DELETE,
9458                                 &filter);
9459         if (ret < 0)
9460                 printf("5tuple filter programming error: (%s)\n",
9461                         strerror(-ret));
9462 }
9463
9464 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9465         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9466                                  filter, "5tuple_filter");
9467 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9468         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9469                                 port_id, UINT16);
9470 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9471         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9472                                  ops, "add#del");
9473 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9474         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9475                                 dst_ip, "dst_ip");
9476 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9477         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9478                                 dst_ip_value);
9479 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9480         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9481                                 src_ip, "src_ip");
9482 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9483         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9484                                 src_ip_value);
9485 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9486         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9487                                 dst_port, "dst_port");
9488 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9489         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9490                                 dst_port_value, UINT16);
9491 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9492         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9493                                 src_port, "src_port");
9494 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9495         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9496                                 src_port_value, UINT16);
9497 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9498         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9499                                 protocol, "protocol");
9500 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9501         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9502                                 protocol_value, UINT8);
9503 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9504         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9505                                 mask, "mask");
9506 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9507         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9508                                 mask_value, INT8);
9509 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9510         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9511                                 tcp_flags, "tcp_flags");
9512 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9513         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9514                                 tcp_flags_value, UINT8);
9515 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9516         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9517                                 priority, "priority");
9518 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9519         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9520                                 priority_value, UINT8);
9521 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9522         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9523                                 queue, "queue");
9524 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9525         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9526                                 queue_id, UINT16);
9527
9528 cmdline_parse_inst_t cmd_5tuple_filter = {
9529         .f = cmd_5tuple_filter_parsed,
9530         .data = NULL,
9531         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9532                 "src_ip <value> dst_port <value> src_port <value> "
9533                 "protocol <value>  mask <value> tcp_flags <value> "
9534                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9535         .tokens = {
9536                 (void *)&cmd_5tuple_filter_filter,
9537                 (void *)&cmd_5tuple_filter_port_id,
9538                 (void *)&cmd_5tuple_filter_ops,
9539                 (void *)&cmd_5tuple_filter_dst_ip,
9540                 (void *)&cmd_5tuple_filter_dst_ip_value,
9541                 (void *)&cmd_5tuple_filter_src_ip,
9542                 (void *)&cmd_5tuple_filter_src_ip_value,
9543                 (void *)&cmd_5tuple_filter_dst_port,
9544                 (void *)&cmd_5tuple_filter_dst_port_value,
9545                 (void *)&cmd_5tuple_filter_src_port,
9546                 (void *)&cmd_5tuple_filter_src_port_value,
9547                 (void *)&cmd_5tuple_filter_protocol,
9548                 (void *)&cmd_5tuple_filter_protocol_value,
9549                 (void *)&cmd_5tuple_filter_mask,
9550                 (void *)&cmd_5tuple_filter_mask_value,
9551                 (void *)&cmd_5tuple_filter_tcp_flags,
9552                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9553                 (void *)&cmd_5tuple_filter_priority,
9554                 (void *)&cmd_5tuple_filter_priority_value,
9555                 (void *)&cmd_5tuple_filter_queue,
9556                 (void *)&cmd_5tuple_filter_queue_id,
9557                 NULL,
9558         },
9559 };
9560
9561 /* *** ADD/REMOVE A flex FILTER *** */
9562 struct cmd_flex_filter_result {
9563         cmdline_fixed_string_t filter;
9564         cmdline_fixed_string_t ops;
9565         portid_t port_id;
9566         cmdline_fixed_string_t len;
9567         uint8_t len_value;
9568         cmdline_fixed_string_t bytes;
9569         cmdline_fixed_string_t bytes_value;
9570         cmdline_fixed_string_t mask;
9571         cmdline_fixed_string_t mask_value;
9572         cmdline_fixed_string_t priority;
9573         uint8_t priority_value;
9574         cmdline_fixed_string_t queue;
9575         uint16_t queue_id;
9576 };
9577
9578 static int xdigit2val(unsigned char c)
9579 {
9580         int val;
9581         if (isdigit(c))
9582                 val = c - '0';
9583         else if (isupper(c))
9584                 val = c - 'A' + 10;
9585         else
9586                 val = c - 'a' + 10;
9587         return val;
9588 }
9589
9590 static void
9591 cmd_flex_filter_parsed(void *parsed_result,
9592                           __attribute__((unused)) struct cmdline *cl,
9593                           __attribute__((unused)) void *data)
9594 {
9595         int ret = 0;
9596         struct rte_eth_flex_filter filter;
9597         struct cmd_flex_filter_result *res = parsed_result;
9598         char *bytes_ptr, *mask_ptr;
9599         uint16_t len, i, j = 0;
9600         char c;
9601         int val;
9602         uint8_t byte = 0;
9603
9604         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9605                 printf("the len exceed the max length 128\n");
9606                 return;
9607         }
9608         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9609         filter.len = res->len_value;
9610         filter.priority = res->priority_value;
9611         filter.queue = res->queue_id;
9612         bytes_ptr = res->bytes_value;
9613         mask_ptr = res->mask_value;
9614
9615          /* translate bytes string to array. */
9616         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9617                 (bytes_ptr[1] == 'X')))
9618                 bytes_ptr += 2;
9619         len = strnlen(bytes_ptr, res->len_value * 2);
9620         if (len == 0 || (len % 8 != 0)) {
9621                 printf("please check len and bytes input\n");
9622                 return;
9623         }
9624         for (i = 0; i < len; i++) {
9625                 c = bytes_ptr[i];
9626                 if (isxdigit(c) == 0) {
9627                         /* invalid characters. */
9628                         printf("invalid input\n");
9629                         return;
9630                 }
9631                 val = xdigit2val(c);
9632                 if (i % 2) {
9633                         byte |= val;
9634                         filter.bytes[j] = byte;
9635                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9636                         j++;
9637                         byte = 0;
9638                 } else
9639                         byte |= val << 4;
9640         }
9641         printf("\n");
9642          /* translate mask string to uint8_t array. */
9643         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9644                 (mask_ptr[1] == 'X')))
9645                 mask_ptr += 2;
9646         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9647         if (len == 0) {
9648                 printf("invalid input\n");
9649                 return;
9650         }
9651         j = 0;
9652         byte = 0;
9653         for (i = 0; i < len; i++) {
9654                 c = mask_ptr[i];
9655                 if (isxdigit(c) == 0) {
9656                         /* invalid characters. */
9657                         printf("invalid input\n");
9658                         return;
9659                 }
9660                 val = xdigit2val(c);
9661                 if (i % 2) {
9662                         byte |= val;
9663                         filter.mask[j] = byte;
9664                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9665                         j++;
9666                         byte = 0;
9667                 } else
9668                         byte |= val << 4;
9669         }
9670         printf("\n");
9671
9672         if (!strcmp(res->ops, "add"))
9673                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9674                                 RTE_ETH_FILTER_FLEXIBLE,
9675                                 RTE_ETH_FILTER_ADD,
9676                                 &filter);
9677         else
9678                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9679                                 RTE_ETH_FILTER_FLEXIBLE,
9680                                 RTE_ETH_FILTER_DELETE,
9681                                 &filter);
9682
9683         if (ret < 0)
9684                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9685 }
9686
9687 cmdline_parse_token_string_t cmd_flex_filter_filter =
9688         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9689                                 filter, "flex_filter");
9690 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9691         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9692                                 port_id, UINT16);
9693 cmdline_parse_token_string_t cmd_flex_filter_ops =
9694         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9695                                 ops, "add#del");
9696 cmdline_parse_token_string_t cmd_flex_filter_len =
9697         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9698                                 len, "len");
9699 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9700         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9701                                 len_value, UINT8);
9702 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9703         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9704                                 bytes, "bytes");
9705 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9706         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9707                                 bytes_value, NULL);
9708 cmdline_parse_token_string_t cmd_flex_filter_mask =
9709         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9710                                 mask, "mask");
9711 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9712         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9713                                 mask_value, NULL);
9714 cmdline_parse_token_string_t cmd_flex_filter_priority =
9715         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9716                                 priority, "priority");
9717 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9718         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9719                                 priority_value, UINT8);
9720 cmdline_parse_token_string_t cmd_flex_filter_queue =
9721         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9722                                 queue, "queue");
9723 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9724         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9725                                 queue_id, UINT16);
9726 cmdline_parse_inst_t cmd_flex_filter = {
9727         .f = cmd_flex_filter_parsed,
9728         .data = NULL,
9729         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9730                 "<value> mask <value> priority <value> queue <queue_id>: "
9731                 "Add/Del a flex filter",
9732         .tokens = {
9733                 (void *)&cmd_flex_filter_filter,
9734                 (void *)&cmd_flex_filter_port_id,
9735                 (void *)&cmd_flex_filter_ops,
9736                 (void *)&cmd_flex_filter_len,
9737                 (void *)&cmd_flex_filter_len_value,
9738                 (void *)&cmd_flex_filter_bytes,
9739                 (void *)&cmd_flex_filter_bytes_value,
9740                 (void *)&cmd_flex_filter_mask,
9741                 (void *)&cmd_flex_filter_mask_value,
9742                 (void *)&cmd_flex_filter_priority,
9743                 (void *)&cmd_flex_filter_priority_value,
9744                 (void *)&cmd_flex_filter_queue,
9745                 (void *)&cmd_flex_filter_queue_id,
9746                 NULL,
9747         },
9748 };
9749
9750 /* *** Filters Control *** */
9751
9752 /* *** deal with ethertype filter *** */
9753 struct cmd_ethertype_filter_result {
9754         cmdline_fixed_string_t filter;
9755         portid_t port_id;
9756         cmdline_fixed_string_t ops;
9757         cmdline_fixed_string_t mac;
9758         struct ether_addr mac_addr;
9759         cmdline_fixed_string_t ethertype;
9760         uint16_t ethertype_value;
9761         cmdline_fixed_string_t drop;
9762         cmdline_fixed_string_t queue;
9763         uint16_t  queue_id;
9764 };
9765
9766 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9767         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9768                                  filter, "ethertype_filter");
9769 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9770         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9771                               port_id, UINT16);
9772 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9773         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9774                                  ops, "add#del");
9775 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9776         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9777                                  mac, "mac_addr#mac_ignr");
9778 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9779         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9780                                      mac_addr);
9781 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9782         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9783                                  ethertype, "ethertype");
9784 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9785         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9786                               ethertype_value, UINT16);
9787 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9788         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9789                                  drop, "drop#fwd");
9790 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9791         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9792                                  queue, "queue");
9793 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9794         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9795                               queue_id, UINT16);
9796
9797 static void
9798 cmd_ethertype_filter_parsed(void *parsed_result,
9799                           __attribute__((unused)) struct cmdline *cl,
9800                           __attribute__((unused)) void *data)
9801 {
9802         struct cmd_ethertype_filter_result *res = parsed_result;
9803         struct rte_eth_ethertype_filter filter;
9804         int ret = 0;
9805
9806         ret = rte_eth_dev_filter_supported(res->port_id,
9807                         RTE_ETH_FILTER_ETHERTYPE);
9808         if (ret < 0) {
9809                 printf("ethertype filter is not supported on port %u.\n",
9810                         res->port_id);
9811                 return;
9812         }
9813
9814         memset(&filter, 0, sizeof(filter));
9815         if (!strcmp(res->mac, "mac_addr")) {
9816                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9817                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9818                         sizeof(struct ether_addr));
9819         }
9820         if (!strcmp(res->drop, "drop"))
9821                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9822         filter.ether_type = res->ethertype_value;
9823         filter.queue = res->queue_id;
9824
9825         if (!strcmp(res->ops, "add"))
9826                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9827                                 RTE_ETH_FILTER_ETHERTYPE,
9828                                 RTE_ETH_FILTER_ADD,
9829                                 &filter);
9830         else
9831                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9832                                 RTE_ETH_FILTER_ETHERTYPE,
9833                                 RTE_ETH_FILTER_DELETE,
9834                                 &filter);
9835         if (ret < 0)
9836                 printf("ethertype filter programming error: (%s)\n",
9837                         strerror(-ret));
9838 }
9839
9840 cmdline_parse_inst_t cmd_ethertype_filter = {
9841         .f = cmd_ethertype_filter_parsed,
9842         .data = NULL,
9843         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9844                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9845                 "Add or delete an ethertype filter entry",
9846         .tokens = {
9847                 (void *)&cmd_ethertype_filter_filter,
9848                 (void *)&cmd_ethertype_filter_port_id,
9849                 (void *)&cmd_ethertype_filter_ops,
9850                 (void *)&cmd_ethertype_filter_mac,
9851                 (void *)&cmd_ethertype_filter_mac_addr,
9852                 (void *)&cmd_ethertype_filter_ethertype,
9853                 (void *)&cmd_ethertype_filter_ethertype_value,
9854                 (void *)&cmd_ethertype_filter_drop,
9855                 (void *)&cmd_ethertype_filter_queue,
9856                 (void *)&cmd_ethertype_filter_queue_id,
9857                 NULL,
9858         },
9859 };
9860
9861 /* *** deal with flow director filter *** */
9862 struct cmd_flow_director_result {
9863         cmdline_fixed_string_t flow_director_filter;
9864         portid_t port_id;
9865         cmdline_fixed_string_t mode;
9866         cmdline_fixed_string_t mode_value;
9867         cmdline_fixed_string_t ops;
9868         cmdline_fixed_string_t flow;
9869         cmdline_fixed_string_t flow_type;
9870         cmdline_fixed_string_t ether;
9871         uint16_t ether_type;
9872         cmdline_fixed_string_t src;
9873         cmdline_ipaddr_t ip_src;
9874         uint16_t port_src;
9875         cmdline_fixed_string_t dst;
9876         cmdline_ipaddr_t ip_dst;
9877         uint16_t port_dst;
9878         cmdline_fixed_string_t verify_tag;
9879         uint32_t verify_tag_value;
9880         cmdline_ipaddr_t tos;
9881         uint8_t tos_value;
9882         cmdline_ipaddr_t proto;
9883         uint8_t proto_value;
9884         cmdline_ipaddr_t ttl;
9885         uint8_t ttl_value;
9886         cmdline_fixed_string_t vlan;
9887         uint16_t vlan_value;
9888         cmdline_fixed_string_t flexbytes;
9889         cmdline_fixed_string_t flexbytes_value;
9890         cmdline_fixed_string_t pf_vf;
9891         cmdline_fixed_string_t drop;
9892         cmdline_fixed_string_t queue;
9893         uint16_t  queue_id;
9894         cmdline_fixed_string_t fd_id;
9895         uint32_t  fd_id_value;
9896         cmdline_fixed_string_t mac;
9897         struct ether_addr mac_addr;
9898         cmdline_fixed_string_t tunnel;
9899         cmdline_fixed_string_t tunnel_type;
9900         cmdline_fixed_string_t tunnel_id;
9901         uint32_t tunnel_id_value;
9902         cmdline_fixed_string_t packet;
9903         char filepath[];
9904 };
9905
9906 static inline int
9907 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9908 {
9909         char s[256];
9910         const char *p, *p0 = q_arg;
9911         char *end;
9912         unsigned long int_fld;
9913         char *str_fld[max_num];
9914         int i;
9915         unsigned size;
9916         int ret = -1;
9917
9918         p = strchr(p0, '(');
9919         if (p == NULL)
9920                 return -1;
9921         ++p;
9922         p0 = strchr(p, ')');
9923         if (p0 == NULL)
9924                 return -1;
9925
9926         size = p0 - p;
9927         if (size >= sizeof(s))
9928                 return -1;
9929
9930         snprintf(s, sizeof(s), "%.*s", size, p);
9931         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9932         if (ret < 0 || ret > max_num)
9933                 return -1;
9934         for (i = 0; i < ret; i++) {
9935                 errno = 0;
9936                 int_fld = strtoul(str_fld[i], &end, 0);
9937                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9938                         return -1;
9939                 flexbytes[i] = (uint8_t)int_fld;
9940         }
9941         return ret;
9942 }
9943
9944 static uint16_t
9945 str2flowtype(char *string)
9946 {
9947         uint8_t i = 0;
9948         static const struct {
9949                 char str[32];
9950                 uint16_t type;
9951         } flowtype_str[] = {
9952                 {"raw", RTE_ETH_FLOW_RAW},
9953                 {"ipv4", RTE_ETH_FLOW_IPV4},
9954                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9955                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9956                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9957                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9958                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9959                 {"ipv6", RTE_ETH_FLOW_IPV6},
9960                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9961                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9962                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9963                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9964                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9965                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9966         };
9967
9968         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9969                 if (!strcmp(flowtype_str[i].str, string))
9970                         return flowtype_str[i].type;
9971         }
9972
9973         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9974                 return (uint16_t)atoi(string);
9975
9976         return RTE_ETH_FLOW_UNKNOWN;
9977 }
9978
9979 static enum rte_eth_fdir_tunnel_type
9980 str2fdir_tunneltype(char *string)
9981 {
9982         uint8_t i = 0;
9983
9984         static const struct {
9985                 char str[32];
9986                 enum rte_eth_fdir_tunnel_type type;
9987         } tunneltype_str[] = {
9988                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9989                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9990         };
9991
9992         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9993                 if (!strcmp(tunneltype_str[i].str, string))
9994                         return tunneltype_str[i].type;
9995         }
9996         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9997 }
9998
9999 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10000 do { \
10001         if ((ip_addr).family == AF_INET) \
10002                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10003         else { \
10004                 printf("invalid parameter.\n"); \
10005                 return; \
10006         } \
10007 } while (0)
10008
10009 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10010 do { \
10011         if ((ip_addr).family == AF_INET6) \
10012                 rte_memcpy(&(ip), \
10013                                  &((ip_addr).addr.ipv6), \
10014                                  sizeof(struct in6_addr)); \
10015         else { \
10016                 printf("invalid parameter.\n"); \
10017                 return; \
10018         } \
10019 } while (0)
10020
10021 static void
10022 cmd_flow_director_filter_parsed(void *parsed_result,
10023                           __attribute__((unused)) struct cmdline *cl,
10024                           __attribute__((unused)) void *data)
10025 {
10026         struct cmd_flow_director_result *res = parsed_result;
10027         struct rte_eth_fdir_filter entry;
10028         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10029         char *end;
10030         unsigned long vf_id;
10031         int ret = 0;
10032
10033         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10034         if (ret < 0) {
10035                 printf("flow director is not supported on port %u.\n",
10036                         res->port_id);
10037                 return;
10038         }
10039         memset(flexbytes, 0, sizeof(flexbytes));
10040         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10041
10042         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10043                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10044                         printf("Please set mode to MAC-VLAN.\n");
10045                         return;
10046                 }
10047         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10048                 if (strcmp(res->mode_value, "Tunnel")) {
10049                         printf("Please set mode to Tunnel.\n");
10050                         return;
10051                 }
10052         } else {
10053                 if (!strcmp(res->mode_value, "raw")) {
10054 #ifdef RTE_LIBRTE_I40E_PMD
10055                         struct rte_pmd_i40e_flow_type_mapping
10056                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10057                         struct rte_pmd_i40e_pkt_template_conf conf;
10058                         uint16_t flow_type = str2flowtype(res->flow_type);
10059                         uint16_t i, port = res->port_id;
10060                         uint8_t add;
10061
10062                         memset(&conf, 0, sizeof(conf));
10063
10064                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10065                                 printf("Invalid flow type specified.\n");
10066                                 return;
10067                         }
10068                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10069                                                                  mapping);
10070                         if (ret)
10071                                 return;
10072                         if (mapping[flow_type].pctype == 0ULL) {
10073                                 printf("Invalid flow type specified.\n");
10074                                 return;
10075                         }
10076                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10077                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10078                                         conf.input.pctype = i;
10079                                         break;
10080                                 }
10081                         }
10082
10083                         conf.input.packet = open_file(res->filepath,
10084                                                 &conf.input.length);
10085                         if (!conf.input.packet)
10086                                 return;
10087                         if (!strcmp(res->drop, "drop"))
10088                                 conf.action.behavior =
10089                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10090                         else
10091                                 conf.action.behavior =
10092                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10093                         conf.action.report_status =
10094                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10095                         conf.action.rx_queue = res->queue_id;
10096                         conf.soft_id = res->fd_id_value;
10097                         add  = strcmp(res->ops, "del") ? 1 : 0;
10098                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10099                                                                         &conf,
10100                                                                         add);
10101                         if (ret < 0)
10102                                 printf("flow director config error: (%s)\n",
10103                                        strerror(-ret));
10104                         close_file(conf.input.packet);
10105 #endif
10106                         return;
10107                 } else if (strcmp(res->mode_value, "IP")) {
10108                         printf("Please set mode to IP or raw.\n");
10109                         return;
10110                 }
10111                 entry.input.flow_type = str2flowtype(res->flow_type);
10112         }
10113
10114         ret = parse_flexbytes(res->flexbytes_value,
10115                                         flexbytes,
10116                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10117         if (ret < 0) {
10118                 printf("error: Cannot parse flexbytes input.\n");
10119                 return;
10120         }
10121
10122         switch (entry.input.flow_type) {
10123         case RTE_ETH_FLOW_FRAG_IPV4:
10124         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10125                 entry.input.flow.ip4_flow.proto = res->proto_value;
10126                 /* fall-through */
10127         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10128         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10129                 IPV4_ADDR_TO_UINT(res->ip_dst,
10130                         entry.input.flow.ip4_flow.dst_ip);
10131                 IPV4_ADDR_TO_UINT(res->ip_src,
10132                         entry.input.flow.ip4_flow.src_ip);
10133                 entry.input.flow.ip4_flow.tos = res->tos_value;
10134                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10135                 /* need convert to big endian. */
10136                 entry.input.flow.udp4_flow.dst_port =
10137                                 rte_cpu_to_be_16(res->port_dst);
10138                 entry.input.flow.udp4_flow.src_port =
10139                                 rte_cpu_to_be_16(res->port_src);
10140                 break;
10141         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10142                 IPV4_ADDR_TO_UINT(res->ip_dst,
10143                         entry.input.flow.sctp4_flow.ip.dst_ip);
10144                 IPV4_ADDR_TO_UINT(res->ip_src,
10145                         entry.input.flow.sctp4_flow.ip.src_ip);
10146                 entry.input.flow.ip4_flow.tos = res->tos_value;
10147                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10148                 /* need convert to big endian. */
10149                 entry.input.flow.sctp4_flow.dst_port =
10150                                 rte_cpu_to_be_16(res->port_dst);
10151                 entry.input.flow.sctp4_flow.src_port =
10152                                 rte_cpu_to_be_16(res->port_src);
10153                 entry.input.flow.sctp4_flow.verify_tag =
10154                                 rte_cpu_to_be_32(res->verify_tag_value);
10155                 break;
10156         case RTE_ETH_FLOW_FRAG_IPV6:
10157         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10158                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10159                 /* fall-through */
10160         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10161         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10162                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10163                         entry.input.flow.ipv6_flow.dst_ip);
10164                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10165                         entry.input.flow.ipv6_flow.src_ip);
10166                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10167                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10168                 /* need convert to big endian. */
10169                 entry.input.flow.udp6_flow.dst_port =
10170                                 rte_cpu_to_be_16(res->port_dst);
10171                 entry.input.flow.udp6_flow.src_port =
10172                                 rte_cpu_to_be_16(res->port_src);
10173                 break;
10174         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10175                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10176                         entry.input.flow.sctp6_flow.ip.dst_ip);
10177                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10178                         entry.input.flow.sctp6_flow.ip.src_ip);
10179                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10180                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10181                 /* need convert to big endian. */
10182                 entry.input.flow.sctp6_flow.dst_port =
10183                                 rte_cpu_to_be_16(res->port_dst);
10184                 entry.input.flow.sctp6_flow.src_port =
10185                                 rte_cpu_to_be_16(res->port_src);
10186                 entry.input.flow.sctp6_flow.verify_tag =
10187                                 rte_cpu_to_be_32(res->verify_tag_value);
10188                 break;
10189         case RTE_ETH_FLOW_L2_PAYLOAD:
10190                 entry.input.flow.l2_flow.ether_type =
10191                         rte_cpu_to_be_16(res->ether_type);
10192                 break;
10193         default:
10194                 break;
10195         }
10196
10197         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10198                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10199                                  &res->mac_addr,
10200                                  sizeof(struct ether_addr));
10201
10202         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10203                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10204                                  &res->mac_addr,
10205                                  sizeof(struct ether_addr));
10206                 entry.input.flow.tunnel_flow.tunnel_type =
10207                         str2fdir_tunneltype(res->tunnel_type);
10208                 entry.input.flow.tunnel_flow.tunnel_id =
10209                         rte_cpu_to_be_32(res->tunnel_id_value);
10210         }
10211
10212         rte_memcpy(entry.input.flow_ext.flexbytes,
10213                    flexbytes,
10214                    RTE_ETH_FDIR_MAX_FLEXLEN);
10215
10216         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10217
10218         entry.action.flex_off = 0;  /*use 0 by default */
10219         if (!strcmp(res->drop, "drop"))
10220                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10221         else
10222                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10223
10224         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10225             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10226                 if (!strcmp(res->pf_vf, "pf"))
10227                         entry.input.flow_ext.is_vf = 0;
10228                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10229                         struct rte_eth_dev_info dev_info;
10230
10231                         memset(&dev_info, 0, sizeof(dev_info));
10232                         rte_eth_dev_info_get(res->port_id, &dev_info);
10233                         errno = 0;
10234                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10235                         if (errno != 0 || *end != '\0' ||
10236                             vf_id >= dev_info.max_vfs) {
10237                                 printf("invalid parameter %s.\n", res->pf_vf);
10238                                 return;
10239                         }
10240                         entry.input.flow_ext.is_vf = 1;
10241                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10242                 } else {
10243                         printf("invalid parameter %s.\n", res->pf_vf);
10244                         return;
10245                 }
10246         }
10247
10248         /* set to report FD ID by default */
10249         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10250         entry.action.rx_queue = res->queue_id;
10251         entry.soft_id = res->fd_id_value;
10252         if (!strcmp(res->ops, "add"))
10253                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10254                                              RTE_ETH_FILTER_ADD, &entry);
10255         else if (!strcmp(res->ops, "del"))
10256                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10257                                              RTE_ETH_FILTER_DELETE, &entry);
10258         else
10259                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10260                                              RTE_ETH_FILTER_UPDATE, &entry);
10261         if (ret < 0)
10262                 printf("flow director programming error: (%s)\n",
10263                         strerror(-ret));
10264 }
10265
10266 cmdline_parse_token_string_t cmd_flow_director_filter =
10267         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10268                                  flow_director_filter, "flow_director_filter");
10269 cmdline_parse_token_num_t cmd_flow_director_port_id =
10270         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10271                               port_id, UINT16);
10272 cmdline_parse_token_string_t cmd_flow_director_ops =
10273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10274                                  ops, "add#del#update");
10275 cmdline_parse_token_string_t cmd_flow_director_flow =
10276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10277                                  flow, "flow");
10278 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10279         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10280                 flow_type, NULL);
10281 cmdline_parse_token_string_t cmd_flow_director_ether =
10282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10283                                  ether, "ether");
10284 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10285         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10286                               ether_type, UINT16);
10287 cmdline_parse_token_string_t cmd_flow_director_src =
10288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10289                                  src, "src");
10290 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10291         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10292                                  ip_src);
10293 cmdline_parse_token_num_t cmd_flow_director_port_src =
10294         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10295                               port_src, UINT16);
10296 cmdline_parse_token_string_t cmd_flow_director_dst =
10297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10298                                  dst, "dst");
10299 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10300         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10301                                  ip_dst);
10302 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10303         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10304                               port_dst, UINT16);
10305 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10307                                   verify_tag, "verify_tag");
10308 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10309         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10310                               verify_tag_value, UINT32);
10311 cmdline_parse_token_string_t cmd_flow_director_tos =
10312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10313                                  tos, "tos");
10314 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10315         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10316                               tos_value, UINT8);
10317 cmdline_parse_token_string_t cmd_flow_director_proto =
10318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10319                                  proto, "proto");
10320 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10321         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10322                               proto_value, UINT8);
10323 cmdline_parse_token_string_t cmd_flow_director_ttl =
10324         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10325                                  ttl, "ttl");
10326 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10327         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10328                               ttl_value, UINT8);
10329 cmdline_parse_token_string_t cmd_flow_director_vlan =
10330         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10331                                  vlan, "vlan");
10332 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10333         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10334                               vlan_value, UINT16);
10335 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10337                                  flexbytes, "flexbytes");
10338 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10340                               flexbytes_value, NULL);
10341 cmdline_parse_token_string_t cmd_flow_director_drop =
10342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10343                                  drop, "drop#fwd");
10344 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10346                               pf_vf, NULL);
10347 cmdline_parse_token_string_t cmd_flow_director_queue =
10348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10349                                  queue, "queue");
10350 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10351         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10352                               queue_id, UINT16);
10353 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10355                                  fd_id, "fd_id");
10356 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10357         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10358                               fd_id_value, UINT32);
10359
10360 cmdline_parse_token_string_t cmd_flow_director_mode =
10361         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10362                                  mode, "mode");
10363 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10365                                  mode_value, "IP");
10366 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10367         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10368                                  mode_value, "MAC-VLAN");
10369 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10371                                  mode_value, "Tunnel");
10372 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10373         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10374                                  mode_value, "raw");
10375 cmdline_parse_token_string_t cmd_flow_director_mac =
10376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10377                                  mac, "mac");
10378 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10379         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10380                                     mac_addr);
10381 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10383                                  tunnel, "tunnel");
10384 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10385         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10386                                  tunnel_type, "NVGRE#VxLAN");
10387 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10389                                  tunnel_id, "tunnel-id");
10390 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10391         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10392                               tunnel_id_value, UINT32);
10393 cmdline_parse_token_string_t cmd_flow_director_packet =
10394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10395                                  packet, "packet");
10396 cmdline_parse_token_string_t cmd_flow_director_filepath =
10397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10398                                  filepath, NULL);
10399
10400 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10401         .f = cmd_flow_director_filter_parsed,
10402         .data = NULL,
10403         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10404                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10405                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10406                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10407                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10408                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10409                 "fd_id <fd_id_value>: "
10410                 "Add or delete an ip flow director entry on NIC",
10411         .tokens = {
10412                 (void *)&cmd_flow_director_filter,
10413                 (void *)&cmd_flow_director_port_id,
10414                 (void *)&cmd_flow_director_mode,
10415                 (void *)&cmd_flow_director_mode_ip,
10416                 (void *)&cmd_flow_director_ops,
10417                 (void *)&cmd_flow_director_flow,
10418                 (void *)&cmd_flow_director_flow_type,
10419                 (void *)&cmd_flow_director_src,
10420                 (void *)&cmd_flow_director_ip_src,
10421                 (void *)&cmd_flow_director_dst,
10422                 (void *)&cmd_flow_director_ip_dst,
10423                 (void *)&cmd_flow_director_tos,
10424                 (void *)&cmd_flow_director_tos_value,
10425                 (void *)&cmd_flow_director_proto,
10426                 (void *)&cmd_flow_director_proto_value,
10427                 (void *)&cmd_flow_director_ttl,
10428                 (void *)&cmd_flow_director_ttl_value,
10429                 (void *)&cmd_flow_director_vlan,
10430                 (void *)&cmd_flow_director_vlan_value,
10431                 (void *)&cmd_flow_director_flexbytes,
10432                 (void *)&cmd_flow_director_flexbytes_value,
10433                 (void *)&cmd_flow_director_drop,
10434                 (void *)&cmd_flow_director_pf_vf,
10435                 (void *)&cmd_flow_director_queue,
10436                 (void *)&cmd_flow_director_queue_id,
10437                 (void *)&cmd_flow_director_fd_id,
10438                 (void *)&cmd_flow_director_fd_id_value,
10439                 NULL,
10440         },
10441 };
10442
10443 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10444         .f = cmd_flow_director_filter_parsed,
10445         .data = NULL,
10446         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10447                 "director entry on NIC",
10448         .tokens = {
10449                 (void *)&cmd_flow_director_filter,
10450                 (void *)&cmd_flow_director_port_id,
10451                 (void *)&cmd_flow_director_mode,
10452                 (void *)&cmd_flow_director_mode_ip,
10453                 (void *)&cmd_flow_director_ops,
10454                 (void *)&cmd_flow_director_flow,
10455                 (void *)&cmd_flow_director_flow_type,
10456                 (void *)&cmd_flow_director_src,
10457                 (void *)&cmd_flow_director_ip_src,
10458                 (void *)&cmd_flow_director_port_src,
10459                 (void *)&cmd_flow_director_dst,
10460                 (void *)&cmd_flow_director_ip_dst,
10461                 (void *)&cmd_flow_director_port_dst,
10462                 (void *)&cmd_flow_director_tos,
10463                 (void *)&cmd_flow_director_tos_value,
10464                 (void *)&cmd_flow_director_ttl,
10465                 (void *)&cmd_flow_director_ttl_value,
10466                 (void *)&cmd_flow_director_vlan,
10467                 (void *)&cmd_flow_director_vlan_value,
10468                 (void *)&cmd_flow_director_flexbytes,
10469                 (void *)&cmd_flow_director_flexbytes_value,
10470                 (void *)&cmd_flow_director_drop,
10471                 (void *)&cmd_flow_director_pf_vf,
10472                 (void *)&cmd_flow_director_queue,
10473                 (void *)&cmd_flow_director_queue_id,
10474                 (void *)&cmd_flow_director_fd_id,
10475                 (void *)&cmd_flow_director_fd_id_value,
10476                 NULL,
10477         },
10478 };
10479
10480 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10481         .f = cmd_flow_director_filter_parsed,
10482         .data = NULL,
10483         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10484                 "director entry on NIC",
10485         .tokens = {
10486                 (void *)&cmd_flow_director_filter,
10487                 (void *)&cmd_flow_director_port_id,
10488                 (void *)&cmd_flow_director_mode,
10489                 (void *)&cmd_flow_director_mode_ip,
10490                 (void *)&cmd_flow_director_ops,
10491                 (void *)&cmd_flow_director_flow,
10492                 (void *)&cmd_flow_director_flow_type,
10493                 (void *)&cmd_flow_director_src,
10494                 (void *)&cmd_flow_director_ip_src,
10495                 (void *)&cmd_flow_director_port_dst,
10496                 (void *)&cmd_flow_director_dst,
10497                 (void *)&cmd_flow_director_ip_dst,
10498                 (void *)&cmd_flow_director_port_dst,
10499                 (void *)&cmd_flow_director_verify_tag,
10500                 (void *)&cmd_flow_director_verify_tag_value,
10501                 (void *)&cmd_flow_director_tos,
10502                 (void *)&cmd_flow_director_tos_value,
10503                 (void *)&cmd_flow_director_ttl,
10504                 (void *)&cmd_flow_director_ttl_value,
10505                 (void *)&cmd_flow_director_vlan,
10506                 (void *)&cmd_flow_director_vlan_value,
10507                 (void *)&cmd_flow_director_flexbytes,
10508                 (void *)&cmd_flow_director_flexbytes_value,
10509                 (void *)&cmd_flow_director_drop,
10510                 (void *)&cmd_flow_director_pf_vf,
10511                 (void *)&cmd_flow_director_queue,
10512                 (void *)&cmd_flow_director_queue_id,
10513                 (void *)&cmd_flow_director_fd_id,
10514                 (void *)&cmd_flow_director_fd_id_value,
10515                 NULL,
10516         },
10517 };
10518
10519 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10520         .f = cmd_flow_director_filter_parsed,
10521         .data = NULL,
10522         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10523                 "director entry on NIC",
10524         .tokens = {
10525                 (void *)&cmd_flow_director_filter,
10526                 (void *)&cmd_flow_director_port_id,
10527                 (void *)&cmd_flow_director_mode,
10528                 (void *)&cmd_flow_director_mode_ip,
10529                 (void *)&cmd_flow_director_ops,
10530                 (void *)&cmd_flow_director_flow,
10531                 (void *)&cmd_flow_director_flow_type,
10532                 (void *)&cmd_flow_director_ether,
10533                 (void *)&cmd_flow_director_ether_type,
10534                 (void *)&cmd_flow_director_flexbytes,
10535                 (void *)&cmd_flow_director_flexbytes_value,
10536                 (void *)&cmd_flow_director_drop,
10537                 (void *)&cmd_flow_director_pf_vf,
10538                 (void *)&cmd_flow_director_queue,
10539                 (void *)&cmd_flow_director_queue_id,
10540                 (void *)&cmd_flow_director_fd_id,
10541                 (void *)&cmd_flow_director_fd_id_value,
10542                 NULL,
10543         },
10544 };
10545
10546 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10547         .f = cmd_flow_director_filter_parsed,
10548         .data = NULL,
10549         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10550                 "director entry on NIC",
10551         .tokens = {
10552                 (void *)&cmd_flow_director_filter,
10553                 (void *)&cmd_flow_director_port_id,
10554                 (void *)&cmd_flow_director_mode,
10555                 (void *)&cmd_flow_director_mode_mac_vlan,
10556                 (void *)&cmd_flow_director_ops,
10557                 (void *)&cmd_flow_director_mac,
10558                 (void *)&cmd_flow_director_mac_addr,
10559                 (void *)&cmd_flow_director_vlan,
10560                 (void *)&cmd_flow_director_vlan_value,
10561                 (void *)&cmd_flow_director_flexbytes,
10562                 (void *)&cmd_flow_director_flexbytes_value,
10563                 (void *)&cmd_flow_director_drop,
10564                 (void *)&cmd_flow_director_queue,
10565                 (void *)&cmd_flow_director_queue_id,
10566                 (void *)&cmd_flow_director_fd_id,
10567                 (void *)&cmd_flow_director_fd_id_value,
10568                 NULL,
10569         },
10570 };
10571
10572 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10573         .f = cmd_flow_director_filter_parsed,
10574         .data = NULL,
10575         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10576                 "director entry on NIC",
10577         .tokens = {
10578                 (void *)&cmd_flow_director_filter,
10579                 (void *)&cmd_flow_director_port_id,
10580                 (void *)&cmd_flow_director_mode,
10581                 (void *)&cmd_flow_director_mode_tunnel,
10582                 (void *)&cmd_flow_director_ops,
10583                 (void *)&cmd_flow_director_mac,
10584                 (void *)&cmd_flow_director_mac_addr,
10585                 (void *)&cmd_flow_director_vlan,
10586                 (void *)&cmd_flow_director_vlan_value,
10587                 (void *)&cmd_flow_director_tunnel,
10588                 (void *)&cmd_flow_director_tunnel_type,
10589                 (void *)&cmd_flow_director_tunnel_id,
10590                 (void *)&cmd_flow_director_tunnel_id_value,
10591                 (void *)&cmd_flow_director_flexbytes,
10592                 (void *)&cmd_flow_director_flexbytes_value,
10593                 (void *)&cmd_flow_director_drop,
10594                 (void *)&cmd_flow_director_queue,
10595                 (void *)&cmd_flow_director_queue_id,
10596                 (void *)&cmd_flow_director_fd_id,
10597                 (void *)&cmd_flow_director_fd_id_value,
10598                 NULL,
10599         },
10600 };
10601
10602 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10603         .f = cmd_flow_director_filter_parsed,
10604         .data = NULL,
10605         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10606                 "director entry on NIC",
10607         .tokens = {
10608                 (void *)&cmd_flow_director_filter,
10609                 (void *)&cmd_flow_director_port_id,
10610                 (void *)&cmd_flow_director_mode,
10611                 (void *)&cmd_flow_director_mode_raw,
10612                 (void *)&cmd_flow_director_ops,
10613                 (void *)&cmd_flow_director_flow,
10614                 (void *)&cmd_flow_director_flow_type,
10615                 (void *)&cmd_flow_director_drop,
10616                 (void *)&cmd_flow_director_queue,
10617                 (void *)&cmd_flow_director_queue_id,
10618                 (void *)&cmd_flow_director_fd_id,
10619                 (void *)&cmd_flow_director_fd_id_value,
10620                 (void *)&cmd_flow_director_packet,
10621                 (void *)&cmd_flow_director_filepath,
10622                 NULL,
10623         },
10624 };
10625
10626 struct cmd_flush_flow_director_result {
10627         cmdline_fixed_string_t flush_flow_director;
10628         portid_t port_id;
10629 };
10630
10631 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10632         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10633                                  flush_flow_director, "flush_flow_director");
10634 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10635         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10636                               port_id, UINT16);
10637
10638 static void
10639 cmd_flush_flow_director_parsed(void *parsed_result,
10640                           __attribute__((unused)) struct cmdline *cl,
10641                           __attribute__((unused)) void *data)
10642 {
10643         struct cmd_flow_director_result *res = parsed_result;
10644         int ret = 0;
10645
10646         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10647         if (ret < 0) {
10648                 printf("flow director is not supported on port %u.\n",
10649                         res->port_id);
10650                 return;
10651         }
10652
10653         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10654                         RTE_ETH_FILTER_FLUSH, NULL);
10655         if (ret < 0)
10656                 printf("flow director table flushing error: (%s)\n",
10657                         strerror(-ret));
10658 }
10659
10660 cmdline_parse_inst_t cmd_flush_flow_director = {
10661         .f = cmd_flush_flow_director_parsed,
10662         .data = NULL,
10663         .help_str = "flush_flow_director <port_id>: "
10664                 "Flush all flow director entries of a device on NIC",
10665         .tokens = {
10666                 (void *)&cmd_flush_flow_director_flush,
10667                 (void *)&cmd_flush_flow_director_port_id,
10668                 NULL,
10669         },
10670 };
10671
10672 /* *** deal with flow director mask *** */
10673 struct cmd_flow_director_mask_result {
10674         cmdline_fixed_string_t flow_director_mask;
10675         portid_t port_id;
10676         cmdline_fixed_string_t mode;
10677         cmdline_fixed_string_t mode_value;
10678         cmdline_fixed_string_t vlan;
10679         uint16_t vlan_mask;
10680         cmdline_fixed_string_t src_mask;
10681         cmdline_ipaddr_t ipv4_src;
10682         cmdline_ipaddr_t ipv6_src;
10683         uint16_t port_src;
10684         cmdline_fixed_string_t dst_mask;
10685         cmdline_ipaddr_t ipv4_dst;
10686         cmdline_ipaddr_t ipv6_dst;
10687         uint16_t port_dst;
10688         cmdline_fixed_string_t mac;
10689         uint8_t mac_addr_byte_mask;
10690         cmdline_fixed_string_t tunnel_id;
10691         uint32_t tunnel_id_mask;
10692         cmdline_fixed_string_t tunnel_type;
10693         uint8_t tunnel_type_mask;
10694 };
10695
10696 static void
10697 cmd_flow_director_mask_parsed(void *parsed_result,
10698                           __attribute__((unused)) struct cmdline *cl,
10699                           __attribute__((unused)) void *data)
10700 {
10701         struct cmd_flow_director_mask_result *res = parsed_result;
10702         struct rte_eth_fdir_masks *mask;
10703         struct rte_port *port;
10704
10705         if (res->port_id > nb_ports) {
10706                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10707                 return;
10708         }
10709
10710         port = &ports[res->port_id];
10711         /** Check if the port is not started **/
10712         if (port->port_status != RTE_PORT_STOPPED) {
10713                 printf("Please stop port %d first\n", res->port_id);
10714                 return;
10715         }
10716
10717         mask = &port->dev_conf.fdir_conf.mask;
10718
10719         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10720                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10721                         printf("Please set mode to MAC-VLAN.\n");
10722                         return;
10723                 }
10724
10725                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10726         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10727                 if (strcmp(res->mode_value, "Tunnel")) {
10728                         printf("Please set mode to Tunnel.\n");
10729                         return;
10730                 }
10731
10732                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10733                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10734                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10735                 mask->tunnel_type_mask = res->tunnel_type_mask;
10736         } else {
10737                 if (strcmp(res->mode_value, "IP")) {
10738                         printf("Please set mode to IP.\n");
10739                         return;
10740                 }
10741
10742                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10743                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10744                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10745                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10746                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10747                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10748                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10749         }
10750
10751         cmd_reconfig_device_queue(res->port_id, 1, 1);
10752 }
10753
10754 cmdline_parse_token_string_t cmd_flow_director_mask =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10756                                  flow_director_mask, "flow_director_mask");
10757 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10758         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10759                               port_id, UINT16);
10760 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10761         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10762                                  vlan, "vlan");
10763 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10764         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10765                               vlan_mask, UINT16);
10766 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10768                                  src_mask, "src_mask");
10769 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10770         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10771                                  ipv4_src);
10772 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10773         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10774                                  ipv6_src);
10775 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10776         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10777                               port_src, UINT16);
10778 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10779         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10780                                  dst_mask, "dst_mask");
10781 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10782         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10783                                  ipv4_dst);
10784 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10785         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10786                                  ipv6_dst);
10787 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10788         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10789                               port_dst, UINT16);
10790
10791 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10793                                  mode, "mode");
10794 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10795         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10796                                  mode_value, "IP");
10797 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10798         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10799                                  mode_value, "MAC-VLAN");
10800 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10801         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10802                                  mode_value, "Tunnel");
10803 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10804         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10805                                  mac, "mac");
10806 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10807         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10808                               mac_addr_byte_mask, UINT8);
10809 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10810         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10811                                  tunnel_type, "tunnel-type");
10812 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10813         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10814                               tunnel_type_mask, UINT8);
10815 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10817                                  tunnel_id, "tunnel-id");
10818 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10819         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10820                               tunnel_id_mask, UINT32);
10821
10822 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10823         .f = cmd_flow_director_mask_parsed,
10824         .data = NULL,
10825         .help_str = "flow_director_mask ... : "
10826                 "Set IP mode flow director's mask on NIC",
10827         .tokens = {
10828                 (void *)&cmd_flow_director_mask,
10829                 (void *)&cmd_flow_director_mask_port_id,
10830                 (void *)&cmd_flow_director_mask_mode,
10831                 (void *)&cmd_flow_director_mask_mode_ip,
10832                 (void *)&cmd_flow_director_mask_vlan,
10833                 (void *)&cmd_flow_director_mask_vlan_value,
10834                 (void *)&cmd_flow_director_mask_src,
10835                 (void *)&cmd_flow_director_mask_ipv4_src,
10836                 (void *)&cmd_flow_director_mask_ipv6_src,
10837                 (void *)&cmd_flow_director_mask_port_src,
10838                 (void *)&cmd_flow_director_mask_dst,
10839                 (void *)&cmd_flow_director_mask_ipv4_dst,
10840                 (void *)&cmd_flow_director_mask_ipv6_dst,
10841                 (void *)&cmd_flow_director_mask_port_dst,
10842                 NULL,
10843         },
10844 };
10845
10846 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10847         .f = cmd_flow_director_mask_parsed,
10848         .data = NULL,
10849         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10850                 "flow director's mask on NIC",
10851         .tokens = {
10852                 (void *)&cmd_flow_director_mask,
10853                 (void *)&cmd_flow_director_mask_port_id,
10854                 (void *)&cmd_flow_director_mask_mode,
10855                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10856                 (void *)&cmd_flow_director_mask_vlan,
10857                 (void *)&cmd_flow_director_mask_vlan_value,
10858                 NULL,
10859         },
10860 };
10861
10862 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10863         .f = cmd_flow_director_mask_parsed,
10864         .data = NULL,
10865         .help_str = "flow_director_mask ... : Set tunnel mode "
10866                 "flow director's mask on NIC",
10867         .tokens = {
10868                 (void *)&cmd_flow_director_mask,
10869                 (void *)&cmd_flow_director_mask_port_id,
10870                 (void *)&cmd_flow_director_mask_mode,
10871                 (void *)&cmd_flow_director_mask_mode_tunnel,
10872                 (void *)&cmd_flow_director_mask_vlan,
10873                 (void *)&cmd_flow_director_mask_vlan_value,
10874                 (void *)&cmd_flow_director_mask_mac,
10875                 (void *)&cmd_flow_director_mask_mac_value,
10876                 (void *)&cmd_flow_director_mask_tunnel_type,
10877                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10878                 (void *)&cmd_flow_director_mask_tunnel_id,
10879                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10880                 NULL,
10881         },
10882 };
10883
10884 /* *** deal with flow director mask on flexible payload *** */
10885 struct cmd_flow_director_flex_mask_result {
10886         cmdline_fixed_string_t flow_director_flexmask;
10887         portid_t port_id;
10888         cmdline_fixed_string_t flow;
10889         cmdline_fixed_string_t flow_type;
10890         cmdline_fixed_string_t mask;
10891 };
10892
10893 static void
10894 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10895                           __attribute__((unused)) struct cmdline *cl,
10896                           __attribute__((unused)) void *data)
10897 {
10898         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10899         struct rte_eth_fdir_info fdir_info;
10900         struct rte_eth_fdir_flex_mask flex_mask;
10901         struct rte_port *port;
10902         uint32_t flow_type_mask;
10903         uint16_t i;
10904         int ret;
10905
10906         if (res->port_id > nb_ports) {
10907                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10908                 return;
10909         }
10910
10911         port = &ports[res->port_id];
10912         /** Check if the port is not started **/
10913         if (port->port_status != RTE_PORT_STOPPED) {
10914                 printf("Please stop port %d first\n", res->port_id);
10915                 return;
10916         }
10917
10918         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10919         ret = parse_flexbytes(res->mask,
10920                         flex_mask.mask,
10921                         RTE_ETH_FDIR_MAX_FLEXLEN);
10922         if (ret < 0) {
10923                 printf("error: Cannot parse mask input.\n");
10924                 return;
10925         }
10926
10927         memset(&fdir_info, 0, sizeof(fdir_info));
10928         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10929                                 RTE_ETH_FILTER_INFO, &fdir_info);
10930         if (ret < 0) {
10931                 printf("Cannot get FDir filter info\n");
10932                 return;
10933         }
10934
10935         if (!strcmp(res->flow_type, "none")) {
10936                 /* means don't specify the flow type */
10937                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10938                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10939                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10940                                0, sizeof(struct rte_eth_fdir_flex_mask));
10941                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10942                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10943                                  &flex_mask,
10944                                  sizeof(struct rte_eth_fdir_flex_mask));
10945                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10946                 return;
10947         }
10948         flow_type_mask = fdir_info.flow_types_mask[0];
10949         if (!strcmp(res->flow_type, "all")) {
10950                 if (!flow_type_mask) {
10951                         printf("No flow type supported\n");
10952                         return;
10953                 }
10954                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10955                         if (flow_type_mask & (1 << i)) {
10956                                 flex_mask.flow_type = i;
10957                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10958                         }
10959                 }
10960                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10961                 return;
10962         }
10963         flex_mask.flow_type = str2flowtype(res->flow_type);
10964         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10965                 printf("Flow type %s not supported on port %d\n",
10966                                 res->flow_type, res->port_id);
10967                 return;
10968         }
10969         fdir_set_flex_mask(res->port_id, &flex_mask);
10970         cmd_reconfig_device_queue(res->port_id, 1, 1);
10971 }
10972
10973 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10974         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10975                                  flow_director_flexmask,
10976                                  "flow_director_flex_mask");
10977 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10978         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10979                               port_id, UINT16);
10980 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10981         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10982                                  flow, "flow");
10983 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10985                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10986                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10987 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10988         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10989                                  mask, NULL);
10990
10991 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10992         .f = cmd_flow_director_flex_mask_parsed,
10993         .data = NULL,
10994         .help_str = "flow_director_flex_mask ... : "
10995                 "Set flow director's flex mask on NIC",
10996         .tokens = {
10997                 (void *)&cmd_flow_director_flexmask,
10998                 (void *)&cmd_flow_director_flexmask_port_id,
10999                 (void *)&cmd_flow_director_flexmask_flow,
11000                 (void *)&cmd_flow_director_flexmask_flow_type,
11001                 (void *)&cmd_flow_director_flexmask_mask,
11002                 NULL,
11003         },
11004 };
11005
11006 /* *** deal with flow director flexible payload configuration *** */
11007 struct cmd_flow_director_flexpayload_result {
11008         cmdline_fixed_string_t flow_director_flexpayload;
11009         portid_t port_id;
11010         cmdline_fixed_string_t payload_layer;
11011         cmdline_fixed_string_t payload_cfg;
11012 };
11013
11014 static inline int
11015 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11016 {
11017         char s[256];
11018         const char *p, *p0 = q_arg;
11019         char *end;
11020         unsigned long int_fld;
11021         char *str_fld[max_num];
11022         int i;
11023         unsigned size;
11024         int ret = -1;
11025
11026         p = strchr(p0, '(');
11027         if (p == NULL)
11028                 return -1;
11029         ++p;
11030         p0 = strchr(p, ')');
11031         if (p0 == NULL)
11032                 return -1;
11033
11034         size = p0 - p;
11035         if (size >= sizeof(s))
11036                 return -1;
11037
11038         snprintf(s, sizeof(s), "%.*s", size, p);
11039         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11040         if (ret < 0 || ret > max_num)
11041                 return -1;
11042         for (i = 0; i < ret; i++) {
11043                 errno = 0;
11044                 int_fld = strtoul(str_fld[i], &end, 0);
11045                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11046                         return -1;
11047                 offsets[i] = (uint16_t)int_fld;
11048         }
11049         return ret;
11050 }
11051
11052 static void
11053 cmd_flow_director_flxpld_parsed(void *parsed_result,
11054                           __attribute__((unused)) struct cmdline *cl,
11055                           __attribute__((unused)) void *data)
11056 {
11057         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11058         struct rte_eth_flex_payload_cfg flex_cfg;
11059         struct rte_port *port;
11060         int ret = 0;
11061
11062         if (res->port_id > nb_ports) {
11063                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11064                 return;
11065         }
11066
11067         port = &ports[res->port_id];
11068         /** Check if the port is not started **/
11069         if (port->port_status != RTE_PORT_STOPPED) {
11070                 printf("Please stop port %d first\n", res->port_id);
11071                 return;
11072         }
11073
11074         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11075
11076         if (!strcmp(res->payload_layer, "raw"))
11077                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11078         else if (!strcmp(res->payload_layer, "l2"))
11079                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11080         else if (!strcmp(res->payload_layer, "l3"))
11081                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11082         else if (!strcmp(res->payload_layer, "l4"))
11083                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11084
11085         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11086                             RTE_ETH_FDIR_MAX_FLEXLEN);
11087         if (ret < 0) {
11088                 printf("error: Cannot parse flex payload input.\n");
11089                 return;
11090         }
11091
11092         fdir_set_flex_payload(res->port_id, &flex_cfg);
11093         cmd_reconfig_device_queue(res->port_id, 1, 1);
11094 }
11095
11096 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11098                                  flow_director_flexpayload,
11099                                  "flow_director_flex_payload");
11100 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11101         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11102                               port_id, UINT16);
11103 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11104         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11105                                  payload_layer, "raw#l2#l3#l4");
11106 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11108                                  payload_cfg, NULL);
11109
11110 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11111         .f = cmd_flow_director_flxpld_parsed,
11112         .data = NULL,
11113         .help_str = "flow_director_flexpayload ... : "
11114                 "Set flow director's flex payload on NIC",
11115         .tokens = {
11116                 (void *)&cmd_flow_director_flexpayload,
11117                 (void *)&cmd_flow_director_flexpayload_port_id,
11118                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11119                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11120                 NULL,
11121         },
11122 };
11123
11124 /* Generic flow interface command. */
11125 extern cmdline_parse_inst_t cmd_flow;
11126
11127 /* *** Classification Filters Control *** */
11128 /* *** Get symmetric hash enable per port *** */
11129 struct cmd_get_sym_hash_ena_per_port_result {
11130         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11131         portid_t port_id;
11132 };
11133
11134 static void
11135 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11136                                  __rte_unused struct cmdline *cl,
11137                                  __rte_unused void *data)
11138 {
11139         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11140         struct rte_eth_hash_filter_info info;
11141         int ret;
11142
11143         if (rte_eth_dev_filter_supported(res->port_id,
11144                                 RTE_ETH_FILTER_HASH) < 0) {
11145                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11146                                                         res->port_id);
11147                 return;
11148         }
11149
11150         memset(&info, 0, sizeof(info));
11151         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11152         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11153                                                 RTE_ETH_FILTER_GET, &info);
11154
11155         if (ret < 0) {
11156                 printf("Cannot get symmetric hash enable per port "
11157                                         "on port %u\n", res->port_id);
11158                 return;
11159         }
11160
11161         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11162                                 "enabled" : "disabled", res->port_id);
11163 }
11164
11165 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11166         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11167                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11168 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11169         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11170                 port_id, UINT16);
11171
11172 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11173         .f = cmd_get_sym_hash_per_port_parsed,
11174         .data = NULL,
11175         .help_str = "get_sym_hash_ena_per_port <port_id>",
11176         .tokens = {
11177                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11178                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11179                 NULL,
11180         },
11181 };
11182
11183 /* *** Set symmetric hash enable per port *** */
11184 struct cmd_set_sym_hash_ena_per_port_result {
11185         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11186         cmdline_fixed_string_t enable;
11187         portid_t port_id;
11188 };
11189
11190 static void
11191 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11192                                  __rte_unused struct cmdline *cl,
11193                                  __rte_unused void *data)
11194 {
11195         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11196         struct rte_eth_hash_filter_info info;
11197         int ret;
11198
11199         if (rte_eth_dev_filter_supported(res->port_id,
11200                                 RTE_ETH_FILTER_HASH) < 0) {
11201                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11202                                                         res->port_id);
11203                 return;
11204         }
11205
11206         memset(&info, 0, sizeof(info));
11207         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11208         if (!strcmp(res->enable, "enable"))
11209                 info.info.enable = 1;
11210         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11211                                         RTE_ETH_FILTER_SET, &info);
11212         if (ret < 0) {
11213                 printf("Cannot set symmetric hash enable per port on "
11214                                         "port %u\n", res->port_id);
11215                 return;
11216         }
11217         printf("Symmetric hash has been set to %s on port %u\n",
11218                                         res->enable, res->port_id);
11219 }
11220
11221 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11222         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11223                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11224 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11225         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11226                 port_id, UINT16);
11227 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11228         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11229                 enable, "enable#disable");
11230
11231 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11232         .f = cmd_set_sym_hash_per_port_parsed,
11233         .data = NULL,
11234         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11235         .tokens = {
11236                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11237                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11238                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11239                 NULL,
11240         },
11241 };
11242
11243 /* Get global config of hash function */
11244 struct cmd_get_hash_global_config_result {
11245         cmdline_fixed_string_t get_hash_global_config;
11246         portid_t port_id;
11247 };
11248
11249 static char *
11250 flowtype_to_str(uint16_t ftype)
11251 {
11252         uint16_t i;
11253         static struct {
11254                 char str[16];
11255                 uint16_t ftype;
11256         } ftype_table[] = {
11257                 {"ipv4", RTE_ETH_FLOW_IPV4},
11258                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11259                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11260                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11261                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11262                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11263                 {"ipv6", RTE_ETH_FLOW_IPV6},
11264                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11265                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11266                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11267                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11268                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11269                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11270                 {"port", RTE_ETH_FLOW_PORT},
11271                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11272                 {"geneve", RTE_ETH_FLOW_GENEVE},
11273                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11274         };
11275
11276         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11277                 if (ftype_table[i].ftype == ftype)
11278                         return ftype_table[i].str;
11279         }
11280
11281         return NULL;
11282 }
11283
11284 static void
11285 cmd_get_hash_global_config_parsed(void *parsed_result,
11286                                   __rte_unused struct cmdline *cl,
11287                                   __rte_unused void *data)
11288 {
11289         struct cmd_get_hash_global_config_result *res = parsed_result;
11290         struct rte_eth_hash_filter_info info;
11291         uint32_t idx, offset;
11292         uint16_t i;
11293         char *str;
11294         int ret;
11295
11296         if (rte_eth_dev_filter_supported(res->port_id,
11297                         RTE_ETH_FILTER_HASH) < 0) {
11298                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11299                                                         res->port_id);
11300                 return;
11301         }
11302
11303         memset(&info, 0, sizeof(info));
11304         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11305         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11306                                         RTE_ETH_FILTER_GET, &info);
11307         if (ret < 0) {
11308                 printf("Cannot get hash global configurations by port %d\n",
11309                                                         res->port_id);
11310                 return;
11311         }
11312
11313         switch (info.info.global_conf.hash_func) {
11314         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11315                 printf("Hash function is Toeplitz\n");
11316                 break;
11317         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11318                 printf("Hash function is Simple XOR\n");
11319                 break;
11320         default:
11321                 printf("Unknown hash function\n");
11322                 break;
11323         }
11324
11325         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11326                 idx = i / UINT32_BIT;
11327                 offset = i % UINT32_BIT;
11328                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11329                                                 (1UL << offset)))
11330                         continue;
11331                 str = flowtype_to_str(i);
11332                 if (!str)
11333                         continue;
11334                 printf("Symmetric hash is %s globally for flow type %s "
11335                                                         "by port %d\n",
11336                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11337                         (1UL << offset)) ? "enabled" : "disabled"), str,
11338                                                         res->port_id);
11339         }
11340 }
11341
11342 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11343         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11344                 get_hash_global_config, "get_hash_global_config");
11345 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11346         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11347                 port_id, UINT16);
11348
11349 cmdline_parse_inst_t cmd_get_hash_global_config = {
11350         .f = cmd_get_hash_global_config_parsed,
11351         .data = NULL,
11352         .help_str = "get_hash_global_config <port_id>",
11353         .tokens = {
11354                 (void *)&cmd_get_hash_global_config_all,
11355                 (void *)&cmd_get_hash_global_config_port_id,
11356                 NULL,
11357         },
11358 };
11359
11360 /* Set global config of hash function */
11361 struct cmd_set_hash_global_config_result {
11362         cmdline_fixed_string_t set_hash_global_config;
11363         portid_t port_id;
11364         cmdline_fixed_string_t hash_func;
11365         cmdline_fixed_string_t flow_type;
11366         cmdline_fixed_string_t enable;
11367 };
11368
11369 static void
11370 cmd_set_hash_global_config_parsed(void *parsed_result,
11371                                   __rte_unused struct cmdline *cl,
11372                                   __rte_unused void *data)
11373 {
11374         struct cmd_set_hash_global_config_result *res = parsed_result;
11375         struct rte_eth_hash_filter_info info;
11376         uint32_t ftype, idx, offset;
11377         int ret;
11378
11379         if (rte_eth_dev_filter_supported(res->port_id,
11380                                 RTE_ETH_FILTER_HASH) < 0) {
11381                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11382                                                         res->port_id);
11383                 return;
11384         }
11385         memset(&info, 0, sizeof(info));
11386         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11387         if (!strcmp(res->hash_func, "toeplitz"))
11388                 info.info.global_conf.hash_func =
11389                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11390         else if (!strcmp(res->hash_func, "simple_xor"))
11391                 info.info.global_conf.hash_func =
11392                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11393         else if (!strcmp(res->hash_func, "default"))
11394                 info.info.global_conf.hash_func =
11395                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11396
11397         ftype = str2flowtype(res->flow_type);
11398         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11399         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11400         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11401         if (!strcmp(res->enable, "enable"))
11402                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11403                                                 (1UL << offset);
11404         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11405                                         RTE_ETH_FILTER_SET, &info);
11406         if (ret < 0)
11407                 printf("Cannot set global hash configurations by port %d\n",
11408                                                         res->port_id);
11409         else
11410                 printf("Global hash configurations have been set "
11411                         "succcessfully by port %d\n", res->port_id);
11412 }
11413
11414 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11415         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11416                 set_hash_global_config, "set_hash_global_config");
11417 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11418         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11419                 port_id, UINT16);
11420 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11421         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11422                 hash_func, "toeplitz#simple_xor#default");
11423 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11424         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11425                 flow_type,
11426                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11427                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11428 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11429         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11430                 enable, "enable#disable");
11431
11432 cmdline_parse_inst_t cmd_set_hash_global_config = {
11433         .f = cmd_set_hash_global_config_parsed,
11434         .data = NULL,
11435         .help_str = "set_hash_global_config <port_id> "
11436                 "toeplitz|simple_xor|default "
11437                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11438                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11439                 "l2_payload enable|disable",
11440         .tokens = {
11441                 (void *)&cmd_set_hash_global_config_all,
11442                 (void *)&cmd_set_hash_global_config_port_id,
11443                 (void *)&cmd_set_hash_global_config_hash_func,
11444                 (void *)&cmd_set_hash_global_config_flow_type,
11445                 (void *)&cmd_set_hash_global_config_enable,
11446                 NULL,
11447         },
11448 };
11449
11450 /* Set hash input set */
11451 struct cmd_set_hash_input_set_result {
11452         cmdline_fixed_string_t set_hash_input_set;
11453         portid_t port_id;
11454         cmdline_fixed_string_t flow_type;
11455         cmdline_fixed_string_t inset_field;
11456         cmdline_fixed_string_t select;
11457 };
11458
11459 static enum rte_eth_input_set_field
11460 str2inset(char *string)
11461 {
11462         uint16_t i;
11463
11464         static const struct {
11465                 char str[32];
11466                 enum rte_eth_input_set_field inset;
11467         } inset_table[] = {
11468                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11469                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11470                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11471                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11472                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11473                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11474                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11475                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11476                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11477                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11478                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11479                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11480                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11481                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11482                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11483                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11484                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11485                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11486                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11487                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11488                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11489                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11490                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11491                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11492                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11493                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11494                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11495                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11496                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11497                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11498                 {"none", RTE_ETH_INPUT_SET_NONE},
11499         };
11500
11501         for (i = 0; i < RTE_DIM(inset_table); i++) {
11502                 if (!strcmp(string, inset_table[i].str))
11503                         return inset_table[i].inset;
11504         }
11505
11506         return RTE_ETH_INPUT_SET_UNKNOWN;
11507 }
11508
11509 static void
11510 cmd_set_hash_input_set_parsed(void *parsed_result,
11511                               __rte_unused struct cmdline *cl,
11512                               __rte_unused void *data)
11513 {
11514         struct cmd_set_hash_input_set_result *res = parsed_result;
11515         struct rte_eth_hash_filter_info info;
11516
11517         memset(&info, 0, sizeof(info));
11518         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11519         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11520         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11521         info.info.input_set_conf.inset_size = 1;
11522         if (!strcmp(res->select, "select"))
11523                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11524         else if (!strcmp(res->select, "add"))
11525                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11526         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11527                                 RTE_ETH_FILTER_SET, &info);
11528 }
11529
11530 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11531         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11532                 set_hash_input_set, "set_hash_input_set");
11533 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11534         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11535                 port_id, UINT16);
11536 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11537         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11538                 flow_type, NULL);
11539 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11540         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11541                 inset_field,
11542                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11543                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11544                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11545                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11546                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11547                 "fld-8th#none");
11548 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11549         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11550                 select, "select#add");
11551
11552 cmdline_parse_inst_t cmd_set_hash_input_set = {
11553         .f = cmd_set_hash_input_set_parsed,
11554         .data = NULL,
11555         .help_str = "set_hash_input_set <port_id> "
11556         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11557         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11558         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11559         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11560         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11561         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11562         "fld-7th|fld-8th|none select|add",
11563         .tokens = {
11564                 (void *)&cmd_set_hash_input_set_cmd,
11565                 (void *)&cmd_set_hash_input_set_port_id,
11566                 (void *)&cmd_set_hash_input_set_flow_type,
11567                 (void *)&cmd_set_hash_input_set_field,
11568                 (void *)&cmd_set_hash_input_set_select,
11569                 NULL,
11570         },
11571 };
11572
11573 /* Set flow director input set */
11574 struct cmd_set_fdir_input_set_result {
11575         cmdline_fixed_string_t set_fdir_input_set;
11576         portid_t port_id;
11577         cmdline_fixed_string_t flow_type;
11578         cmdline_fixed_string_t inset_field;
11579         cmdline_fixed_string_t select;
11580 };
11581
11582 static void
11583 cmd_set_fdir_input_set_parsed(void *parsed_result,
11584         __rte_unused struct cmdline *cl,
11585         __rte_unused void *data)
11586 {
11587         struct cmd_set_fdir_input_set_result *res = parsed_result;
11588         struct rte_eth_fdir_filter_info info;
11589
11590         memset(&info, 0, sizeof(info));
11591         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11592         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11593         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11594         info.info.input_set_conf.inset_size = 1;
11595         if (!strcmp(res->select, "select"))
11596                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11597         else if (!strcmp(res->select, "add"))
11598                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11599         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11600                 RTE_ETH_FILTER_SET, &info);
11601 }
11602
11603 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11604         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11605         set_fdir_input_set, "set_fdir_input_set");
11606 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11607         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11608         port_id, UINT16);
11609 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11610         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11611         flow_type,
11612         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11613         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11614 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11615         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11616         inset_field,
11617         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11618         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11619         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11620         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11621         "sctp-veri-tag#none");
11622 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11623         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11624         select, "select#add");
11625
11626 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11627         .f = cmd_set_fdir_input_set_parsed,
11628         .data = NULL,
11629         .help_str = "set_fdir_input_set <port_id> "
11630         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11631         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11632         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11633         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11634         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11635         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11636         "sctp-veri-tag|none select|add",
11637         .tokens = {
11638                 (void *)&cmd_set_fdir_input_set_cmd,
11639                 (void *)&cmd_set_fdir_input_set_port_id,
11640                 (void *)&cmd_set_fdir_input_set_flow_type,
11641                 (void *)&cmd_set_fdir_input_set_field,
11642                 (void *)&cmd_set_fdir_input_set_select,
11643                 NULL,
11644         },
11645 };
11646
11647 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11648 struct cmd_mcast_addr_result {
11649         cmdline_fixed_string_t mcast_addr_cmd;
11650         cmdline_fixed_string_t what;
11651         uint16_t port_num;
11652         struct ether_addr mc_addr;
11653 };
11654
11655 static void cmd_mcast_addr_parsed(void *parsed_result,
11656                 __attribute__((unused)) struct cmdline *cl,
11657                 __attribute__((unused)) void *data)
11658 {
11659         struct cmd_mcast_addr_result *res = parsed_result;
11660
11661         if (!is_multicast_ether_addr(&res->mc_addr)) {
11662                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11663                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11664                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11665                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11666                 return;
11667         }
11668         if (strcmp(res->what, "add") == 0)
11669                 mcast_addr_add(res->port_num, &res->mc_addr);
11670         else
11671                 mcast_addr_remove(res->port_num, &res->mc_addr);
11672 }
11673
11674 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11675         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11676                                  mcast_addr_cmd, "mcast_addr");
11677 cmdline_parse_token_string_t cmd_mcast_addr_what =
11678         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11679                                  "add#remove");
11680 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11681         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11682 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11683         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11684
11685 cmdline_parse_inst_t cmd_mcast_addr = {
11686         .f = cmd_mcast_addr_parsed,
11687         .data = (void *)0,
11688         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11689                 "Add/Remove multicast MAC address on port_id",
11690         .tokens = {
11691                 (void *)&cmd_mcast_addr_cmd,
11692                 (void *)&cmd_mcast_addr_what,
11693                 (void *)&cmd_mcast_addr_portnum,
11694                 (void *)&cmd_mcast_addr_addr,
11695                 NULL,
11696         },
11697 };
11698
11699 /* l2 tunnel config
11700  * only support E-tag now.
11701  */
11702
11703 /* Ether type config */
11704 struct cmd_config_l2_tunnel_eth_type_result {
11705         cmdline_fixed_string_t port;
11706         cmdline_fixed_string_t config;
11707         cmdline_fixed_string_t all;
11708         uint8_t id;
11709         cmdline_fixed_string_t l2_tunnel;
11710         cmdline_fixed_string_t l2_tunnel_type;
11711         cmdline_fixed_string_t eth_type;
11712         uint16_t eth_type_val;
11713 };
11714
11715 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11716         TOKEN_STRING_INITIALIZER
11717                 (struct cmd_config_l2_tunnel_eth_type_result,
11718                  port, "port");
11719 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11720         TOKEN_STRING_INITIALIZER
11721                 (struct cmd_config_l2_tunnel_eth_type_result,
11722                  config, "config");
11723 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11724         TOKEN_STRING_INITIALIZER
11725                 (struct cmd_config_l2_tunnel_eth_type_result,
11726                  all, "all");
11727 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11728         TOKEN_NUM_INITIALIZER
11729                 (struct cmd_config_l2_tunnel_eth_type_result,
11730                  id, UINT8);
11731 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11732         TOKEN_STRING_INITIALIZER
11733                 (struct cmd_config_l2_tunnel_eth_type_result,
11734                  l2_tunnel, "l2-tunnel");
11735 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_config_l2_tunnel_eth_type_result,
11738                  l2_tunnel_type, "E-tag");
11739 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11740         TOKEN_STRING_INITIALIZER
11741                 (struct cmd_config_l2_tunnel_eth_type_result,
11742                  eth_type, "ether-type");
11743 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11744         TOKEN_NUM_INITIALIZER
11745                 (struct cmd_config_l2_tunnel_eth_type_result,
11746                  eth_type_val, UINT16);
11747
11748 static enum rte_eth_tunnel_type
11749 str2fdir_l2_tunnel_type(char *string)
11750 {
11751         uint32_t i = 0;
11752
11753         static const struct {
11754                 char str[32];
11755                 enum rte_eth_tunnel_type type;
11756         } l2_tunnel_type_str[] = {
11757                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11758         };
11759
11760         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11761                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11762                         return l2_tunnel_type_str[i].type;
11763         }
11764         return RTE_TUNNEL_TYPE_NONE;
11765 }
11766
11767 /* ether type config for all ports */
11768 static void
11769 cmd_config_l2_tunnel_eth_type_all_parsed
11770         (void *parsed_result,
11771          __attribute__((unused)) struct cmdline *cl,
11772          __attribute__((unused)) void *data)
11773 {
11774         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11775         struct rte_eth_l2_tunnel_conf entry;
11776         portid_t pid;
11777
11778         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11779         entry.ether_type = res->eth_type_val;
11780
11781         RTE_ETH_FOREACH_DEV(pid) {
11782                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11783         }
11784 }
11785
11786 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11787         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11788         .data = NULL,
11789         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11790         .tokens = {
11791                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11792                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11793                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11794                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11795                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11796                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11797                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11798                 NULL,
11799         },
11800 };
11801
11802 /* ether type config for a specific port */
11803 static void
11804 cmd_config_l2_tunnel_eth_type_specific_parsed(
11805         void *parsed_result,
11806         __attribute__((unused)) struct cmdline *cl,
11807         __attribute__((unused)) void *data)
11808 {
11809         struct cmd_config_l2_tunnel_eth_type_result *res =
11810                  parsed_result;
11811         struct rte_eth_l2_tunnel_conf entry;
11812
11813         if (port_id_is_invalid(res->id, ENABLED_WARN))
11814                 return;
11815
11816         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11817         entry.ether_type = res->eth_type_val;
11818
11819         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11820 }
11821
11822 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11823         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11824         .data = NULL,
11825         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11826         .tokens = {
11827                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11828                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11829                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11830                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11831                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11832                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11833                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11834                 NULL,
11835         },
11836 };
11837
11838 /* Enable/disable l2 tunnel */
11839 struct cmd_config_l2_tunnel_en_dis_result {
11840         cmdline_fixed_string_t port;
11841         cmdline_fixed_string_t config;
11842         cmdline_fixed_string_t all;
11843         uint8_t id;
11844         cmdline_fixed_string_t l2_tunnel;
11845         cmdline_fixed_string_t l2_tunnel_type;
11846         cmdline_fixed_string_t en_dis;
11847 };
11848
11849 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11850         TOKEN_STRING_INITIALIZER
11851                 (struct cmd_config_l2_tunnel_en_dis_result,
11852                  port, "port");
11853 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11854         TOKEN_STRING_INITIALIZER
11855                 (struct cmd_config_l2_tunnel_en_dis_result,
11856                  config, "config");
11857 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11858         TOKEN_STRING_INITIALIZER
11859                 (struct cmd_config_l2_tunnel_en_dis_result,
11860                  all, "all");
11861 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11862         TOKEN_NUM_INITIALIZER
11863                 (struct cmd_config_l2_tunnel_en_dis_result,
11864                  id, UINT8);
11865 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11866         TOKEN_STRING_INITIALIZER
11867                 (struct cmd_config_l2_tunnel_en_dis_result,
11868                  l2_tunnel, "l2-tunnel");
11869 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11870         TOKEN_STRING_INITIALIZER
11871                 (struct cmd_config_l2_tunnel_en_dis_result,
11872                  l2_tunnel_type, "E-tag");
11873 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11874         TOKEN_STRING_INITIALIZER
11875                 (struct cmd_config_l2_tunnel_en_dis_result,
11876                  en_dis, "enable#disable");
11877
11878 /* enable/disable l2 tunnel for all ports */
11879 static void
11880 cmd_config_l2_tunnel_en_dis_all_parsed(
11881         void *parsed_result,
11882         __attribute__((unused)) struct cmdline *cl,
11883         __attribute__((unused)) void *data)
11884 {
11885         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11886         struct rte_eth_l2_tunnel_conf entry;
11887         portid_t pid;
11888         uint8_t en;
11889
11890         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11891
11892         if (!strcmp("enable", res->en_dis))
11893                 en = 1;
11894         else
11895                 en = 0;
11896
11897         RTE_ETH_FOREACH_DEV(pid) {
11898                 rte_eth_dev_l2_tunnel_offload_set(pid,
11899                                                   &entry,
11900                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11901                                                   en);
11902         }
11903 }
11904
11905 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11906         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11907         .data = NULL,
11908         .help_str = "port config all l2-tunnel E-tag enable|disable",
11909         .tokens = {
11910                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11911                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11912                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11913                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11914                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11915                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11916                 NULL,
11917         },
11918 };
11919
11920 /* enable/disable l2 tunnel for a port */
11921 static void
11922 cmd_config_l2_tunnel_en_dis_specific_parsed(
11923         void *parsed_result,
11924         __attribute__((unused)) struct cmdline *cl,
11925         __attribute__((unused)) void *data)
11926 {
11927         struct cmd_config_l2_tunnel_en_dis_result *res =
11928                 parsed_result;
11929         struct rte_eth_l2_tunnel_conf entry;
11930
11931         if (port_id_is_invalid(res->id, ENABLED_WARN))
11932                 return;
11933
11934         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11935
11936         if (!strcmp("enable", res->en_dis))
11937                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11938                                                   &entry,
11939                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11940                                                   1);
11941         else
11942                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11943                                                   &entry,
11944                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11945                                                   0);
11946 }
11947
11948 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11949         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11950         .data = NULL,
11951         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11952         .tokens = {
11953                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11954                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11955                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11956                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11957                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11958                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11959                 NULL,
11960         },
11961 };
11962
11963 /* E-tag configuration */
11964
11965 /* Common result structure for all E-tag configuration */
11966 struct cmd_config_e_tag_result {
11967         cmdline_fixed_string_t e_tag;
11968         cmdline_fixed_string_t set;
11969         cmdline_fixed_string_t insertion;
11970         cmdline_fixed_string_t stripping;
11971         cmdline_fixed_string_t forwarding;
11972         cmdline_fixed_string_t filter;
11973         cmdline_fixed_string_t add;
11974         cmdline_fixed_string_t del;
11975         cmdline_fixed_string_t on;
11976         cmdline_fixed_string_t off;
11977         cmdline_fixed_string_t on_off;
11978         cmdline_fixed_string_t port_tag_id;
11979         uint32_t port_tag_id_val;
11980         cmdline_fixed_string_t e_tag_id;
11981         uint16_t e_tag_id_val;
11982         cmdline_fixed_string_t dst_pool;
11983         uint8_t dst_pool_val;
11984         cmdline_fixed_string_t port;
11985         portid_t port_id;
11986         cmdline_fixed_string_t vf;
11987         uint8_t vf_id;
11988 };
11989
11990 /* Common CLI fields for all E-tag configuration */
11991 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_config_e_tag_result,
11994                  e_tag, "E-tag");
11995 cmdline_parse_token_string_t cmd_config_e_tag_set =
11996         TOKEN_STRING_INITIALIZER
11997                 (struct cmd_config_e_tag_result,
11998                  set, "set");
11999 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_config_e_tag_result,
12002                  insertion, "insertion");
12003 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12004         TOKEN_STRING_INITIALIZER
12005                 (struct cmd_config_e_tag_result,
12006                  stripping, "stripping");
12007 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_e_tag_result,
12010                  forwarding, "forwarding");
12011 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_config_e_tag_result,
12014                  filter, "filter");
12015 cmdline_parse_token_string_t cmd_config_e_tag_add =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_config_e_tag_result,
12018                  add, "add");
12019 cmdline_parse_token_string_t cmd_config_e_tag_del =
12020         TOKEN_STRING_INITIALIZER
12021                 (struct cmd_config_e_tag_result,
12022                  del, "del");
12023 cmdline_parse_token_string_t cmd_config_e_tag_on =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_config_e_tag_result,
12026                  on, "on");
12027 cmdline_parse_token_string_t cmd_config_e_tag_off =
12028         TOKEN_STRING_INITIALIZER
12029                 (struct cmd_config_e_tag_result,
12030                  off, "off");
12031 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12032         TOKEN_STRING_INITIALIZER
12033                 (struct cmd_config_e_tag_result,
12034                  on_off, "on#off");
12035 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12036         TOKEN_STRING_INITIALIZER
12037                 (struct cmd_config_e_tag_result,
12038                  port_tag_id, "port-tag-id");
12039 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12040         TOKEN_NUM_INITIALIZER
12041                 (struct cmd_config_e_tag_result,
12042                  port_tag_id_val, UINT32);
12043 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12044         TOKEN_STRING_INITIALIZER
12045                 (struct cmd_config_e_tag_result,
12046                  e_tag_id, "e-tag-id");
12047 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12048         TOKEN_NUM_INITIALIZER
12049                 (struct cmd_config_e_tag_result,
12050                  e_tag_id_val, UINT16);
12051 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12052         TOKEN_STRING_INITIALIZER
12053                 (struct cmd_config_e_tag_result,
12054                  dst_pool, "dst-pool");
12055 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12056         TOKEN_NUM_INITIALIZER
12057                 (struct cmd_config_e_tag_result,
12058                  dst_pool_val, UINT8);
12059 cmdline_parse_token_string_t cmd_config_e_tag_port =
12060         TOKEN_STRING_INITIALIZER
12061                 (struct cmd_config_e_tag_result,
12062                  port, "port");
12063 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12064         TOKEN_NUM_INITIALIZER
12065                 (struct cmd_config_e_tag_result,
12066                  port_id, UINT16);
12067 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_config_e_tag_result,
12070                  vf, "vf");
12071 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12072         TOKEN_NUM_INITIALIZER
12073                 (struct cmd_config_e_tag_result,
12074                  vf_id, UINT8);
12075
12076 /* E-tag insertion configuration */
12077 static void
12078 cmd_config_e_tag_insertion_en_parsed(
12079         void *parsed_result,
12080         __attribute__((unused)) struct cmdline *cl,
12081         __attribute__((unused)) void *data)
12082 {
12083         struct cmd_config_e_tag_result *res =
12084                 parsed_result;
12085         struct rte_eth_l2_tunnel_conf entry;
12086
12087         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12088                 return;
12089
12090         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12091         entry.tunnel_id = res->port_tag_id_val;
12092         entry.vf_id = res->vf_id;
12093         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12094                                           &entry,
12095                                           ETH_L2_TUNNEL_INSERTION_MASK,
12096                                           1);
12097 }
12098
12099 static void
12100 cmd_config_e_tag_insertion_dis_parsed(
12101         void *parsed_result,
12102         __attribute__((unused)) struct cmdline *cl,
12103         __attribute__((unused)) void *data)
12104 {
12105         struct cmd_config_e_tag_result *res =
12106                 parsed_result;
12107         struct rte_eth_l2_tunnel_conf entry;
12108
12109         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12110                 return;
12111
12112         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12113         entry.vf_id = res->vf_id;
12114
12115         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12116                                           &entry,
12117                                           ETH_L2_TUNNEL_INSERTION_MASK,
12118                                           0);
12119 }
12120
12121 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12122         .f = cmd_config_e_tag_insertion_en_parsed,
12123         .data = NULL,
12124         .help_str = "E-tag ... : E-tag insertion enable",
12125         .tokens = {
12126                 (void *)&cmd_config_e_tag_e_tag,
12127                 (void *)&cmd_config_e_tag_set,
12128                 (void *)&cmd_config_e_tag_insertion,
12129                 (void *)&cmd_config_e_tag_on,
12130                 (void *)&cmd_config_e_tag_port_tag_id,
12131                 (void *)&cmd_config_e_tag_port_tag_id_val,
12132                 (void *)&cmd_config_e_tag_port,
12133                 (void *)&cmd_config_e_tag_port_id,
12134                 (void *)&cmd_config_e_tag_vf,
12135                 (void *)&cmd_config_e_tag_vf_id,
12136                 NULL,
12137         },
12138 };
12139
12140 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12141         .f = cmd_config_e_tag_insertion_dis_parsed,
12142         .data = NULL,
12143         .help_str = "E-tag ... : E-tag insertion disable",
12144         .tokens = {
12145                 (void *)&cmd_config_e_tag_e_tag,
12146                 (void *)&cmd_config_e_tag_set,
12147                 (void *)&cmd_config_e_tag_insertion,
12148                 (void *)&cmd_config_e_tag_off,
12149                 (void *)&cmd_config_e_tag_port,
12150                 (void *)&cmd_config_e_tag_port_id,
12151                 (void *)&cmd_config_e_tag_vf,
12152                 (void *)&cmd_config_e_tag_vf_id,
12153                 NULL,
12154         },
12155 };
12156
12157 /* E-tag stripping configuration */
12158 static void
12159 cmd_config_e_tag_stripping_parsed(
12160         void *parsed_result,
12161         __attribute__((unused)) struct cmdline *cl,
12162         __attribute__((unused)) void *data)
12163 {
12164         struct cmd_config_e_tag_result *res =
12165                 parsed_result;
12166         struct rte_eth_l2_tunnel_conf entry;
12167
12168         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12169                 return;
12170
12171         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12172
12173         if (!strcmp(res->on_off, "on"))
12174                 rte_eth_dev_l2_tunnel_offload_set
12175                         (res->port_id,
12176                          &entry,
12177                          ETH_L2_TUNNEL_STRIPPING_MASK,
12178                          1);
12179         else
12180                 rte_eth_dev_l2_tunnel_offload_set
12181                         (res->port_id,
12182                          &entry,
12183                          ETH_L2_TUNNEL_STRIPPING_MASK,
12184                          0);
12185 }
12186
12187 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12188         .f = cmd_config_e_tag_stripping_parsed,
12189         .data = NULL,
12190         .help_str = "E-tag ... : E-tag stripping enable/disable",
12191         .tokens = {
12192                 (void *)&cmd_config_e_tag_e_tag,
12193                 (void *)&cmd_config_e_tag_set,
12194                 (void *)&cmd_config_e_tag_stripping,
12195                 (void *)&cmd_config_e_tag_on_off,
12196                 (void *)&cmd_config_e_tag_port,
12197                 (void *)&cmd_config_e_tag_port_id,
12198                 NULL,
12199         },
12200 };
12201
12202 /* E-tag forwarding configuration */
12203 static void
12204 cmd_config_e_tag_forwarding_parsed(
12205         void *parsed_result,
12206         __attribute__((unused)) struct cmdline *cl,
12207         __attribute__((unused)) void *data)
12208 {
12209         struct cmd_config_e_tag_result *res = parsed_result;
12210         struct rte_eth_l2_tunnel_conf entry;
12211
12212         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12213                 return;
12214
12215         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12216
12217         if (!strcmp(res->on_off, "on"))
12218                 rte_eth_dev_l2_tunnel_offload_set
12219                         (res->port_id,
12220                          &entry,
12221                          ETH_L2_TUNNEL_FORWARDING_MASK,
12222                          1);
12223         else
12224                 rte_eth_dev_l2_tunnel_offload_set
12225                         (res->port_id,
12226                          &entry,
12227                          ETH_L2_TUNNEL_FORWARDING_MASK,
12228                          0);
12229 }
12230
12231 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12232         .f = cmd_config_e_tag_forwarding_parsed,
12233         .data = NULL,
12234         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12235         .tokens = {
12236                 (void *)&cmd_config_e_tag_e_tag,
12237                 (void *)&cmd_config_e_tag_set,
12238                 (void *)&cmd_config_e_tag_forwarding,
12239                 (void *)&cmd_config_e_tag_on_off,
12240                 (void *)&cmd_config_e_tag_port,
12241                 (void *)&cmd_config_e_tag_port_id,
12242                 NULL,
12243         },
12244 };
12245
12246 /* E-tag filter configuration */
12247 static void
12248 cmd_config_e_tag_filter_add_parsed(
12249         void *parsed_result,
12250         __attribute__((unused)) struct cmdline *cl,
12251         __attribute__((unused)) void *data)
12252 {
12253         struct cmd_config_e_tag_result *res = parsed_result;
12254         struct rte_eth_l2_tunnel_conf entry;
12255         int ret = 0;
12256
12257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12258                 return;
12259
12260         if (res->e_tag_id_val > 0x3fff) {
12261                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12262                 return;
12263         }
12264
12265         ret = rte_eth_dev_filter_supported(res->port_id,
12266                                            RTE_ETH_FILTER_L2_TUNNEL);
12267         if (ret < 0) {
12268                 printf("E-tag filter is not supported on port %u.\n",
12269                        res->port_id);
12270                 return;
12271         }
12272
12273         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12274         entry.tunnel_id = res->e_tag_id_val;
12275         entry.pool = res->dst_pool_val;
12276
12277         ret = rte_eth_dev_filter_ctrl(res->port_id,
12278                                       RTE_ETH_FILTER_L2_TUNNEL,
12279                                       RTE_ETH_FILTER_ADD,
12280                                       &entry);
12281         if (ret < 0)
12282                 printf("E-tag filter programming error: (%s)\n",
12283                        strerror(-ret));
12284 }
12285
12286 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12287         .f = cmd_config_e_tag_filter_add_parsed,
12288         .data = NULL,
12289         .help_str = "E-tag ... : E-tag filter add",
12290         .tokens = {
12291                 (void *)&cmd_config_e_tag_e_tag,
12292                 (void *)&cmd_config_e_tag_set,
12293                 (void *)&cmd_config_e_tag_filter,
12294                 (void *)&cmd_config_e_tag_add,
12295                 (void *)&cmd_config_e_tag_e_tag_id,
12296                 (void *)&cmd_config_e_tag_e_tag_id_val,
12297                 (void *)&cmd_config_e_tag_dst_pool,
12298                 (void *)&cmd_config_e_tag_dst_pool_val,
12299                 (void *)&cmd_config_e_tag_port,
12300                 (void *)&cmd_config_e_tag_port_id,
12301                 NULL,
12302         },
12303 };
12304
12305 static void
12306 cmd_config_e_tag_filter_del_parsed(
12307         void *parsed_result,
12308         __attribute__((unused)) struct cmdline *cl,
12309         __attribute__((unused)) void *data)
12310 {
12311         struct cmd_config_e_tag_result *res = parsed_result;
12312         struct rte_eth_l2_tunnel_conf entry;
12313         int ret = 0;
12314
12315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12316                 return;
12317
12318         if (res->e_tag_id_val > 0x3fff) {
12319                 printf("e-tag-id must be less than 0x3fff.\n");
12320                 return;
12321         }
12322
12323         ret = rte_eth_dev_filter_supported(res->port_id,
12324                                            RTE_ETH_FILTER_L2_TUNNEL);
12325         if (ret < 0) {
12326                 printf("E-tag filter is not supported on port %u.\n",
12327                        res->port_id);
12328                 return;
12329         }
12330
12331         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12332         entry.tunnel_id = res->e_tag_id_val;
12333
12334         ret = rte_eth_dev_filter_ctrl(res->port_id,
12335                                       RTE_ETH_FILTER_L2_TUNNEL,
12336                                       RTE_ETH_FILTER_DELETE,
12337                                       &entry);
12338         if (ret < 0)
12339                 printf("E-tag filter programming error: (%s)\n",
12340                        strerror(-ret));
12341 }
12342
12343 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12344         .f = cmd_config_e_tag_filter_del_parsed,
12345         .data = NULL,
12346         .help_str = "E-tag ... : E-tag filter delete",
12347         .tokens = {
12348                 (void *)&cmd_config_e_tag_e_tag,
12349                 (void *)&cmd_config_e_tag_set,
12350                 (void *)&cmd_config_e_tag_filter,
12351                 (void *)&cmd_config_e_tag_del,
12352                 (void *)&cmd_config_e_tag_e_tag_id,
12353                 (void *)&cmd_config_e_tag_e_tag_id_val,
12354                 (void *)&cmd_config_e_tag_port,
12355                 (void *)&cmd_config_e_tag_port_id,
12356                 NULL,
12357         },
12358 };
12359
12360 /* vf vlan anti spoof configuration */
12361
12362 /* Common result structure for vf vlan anti spoof */
12363 struct cmd_vf_vlan_anti_spoof_result {
12364         cmdline_fixed_string_t set;
12365         cmdline_fixed_string_t vf;
12366         cmdline_fixed_string_t vlan;
12367         cmdline_fixed_string_t antispoof;
12368         portid_t port_id;
12369         uint32_t vf_id;
12370         cmdline_fixed_string_t on_off;
12371 };
12372
12373 /* Common CLI fields for vf vlan anti spoof enable disable */
12374 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_vf_vlan_anti_spoof_result,
12377                  set, "set");
12378 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_vf_vlan_anti_spoof_result,
12381                  vf, "vf");
12382 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12383         TOKEN_STRING_INITIALIZER
12384                 (struct cmd_vf_vlan_anti_spoof_result,
12385                  vlan, "vlan");
12386 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12387         TOKEN_STRING_INITIALIZER
12388                 (struct cmd_vf_vlan_anti_spoof_result,
12389                  antispoof, "antispoof");
12390 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12391         TOKEN_NUM_INITIALIZER
12392                 (struct cmd_vf_vlan_anti_spoof_result,
12393                  port_id, UINT16);
12394 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12395         TOKEN_NUM_INITIALIZER
12396                 (struct cmd_vf_vlan_anti_spoof_result,
12397                  vf_id, UINT32);
12398 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12399         TOKEN_STRING_INITIALIZER
12400                 (struct cmd_vf_vlan_anti_spoof_result,
12401                  on_off, "on#off");
12402
12403 static void
12404 cmd_set_vf_vlan_anti_spoof_parsed(
12405         void *parsed_result,
12406         __attribute__((unused)) struct cmdline *cl,
12407         __attribute__((unused)) void *data)
12408 {
12409         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12410         int ret = -ENOTSUP;
12411
12412         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12413
12414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12415                 return;
12416
12417 #ifdef RTE_LIBRTE_IXGBE_PMD
12418         if (ret == -ENOTSUP)
12419                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12420                                 res->vf_id, is_on);
12421 #endif
12422 #ifdef RTE_LIBRTE_I40E_PMD
12423         if (ret == -ENOTSUP)
12424                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12425                                 res->vf_id, is_on);
12426 #endif
12427 #ifdef RTE_LIBRTE_BNXT_PMD
12428         if (ret == -ENOTSUP)
12429                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12430                                 res->vf_id, is_on);
12431 #endif
12432
12433         switch (ret) {
12434         case 0:
12435                 break;
12436         case -EINVAL:
12437                 printf("invalid vf_id %d\n", res->vf_id);
12438                 break;
12439         case -ENODEV:
12440                 printf("invalid port_id %d\n", res->port_id);
12441                 break;
12442         case -ENOTSUP:
12443                 printf("function not implemented\n");
12444                 break;
12445         default:
12446                 printf("programming error: (%s)\n", strerror(-ret));
12447         }
12448 }
12449
12450 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12451         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12452         .data = NULL,
12453         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12454         .tokens = {
12455                 (void *)&cmd_vf_vlan_anti_spoof_set,
12456                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12457                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12458                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12459                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12460                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12461                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12462                 NULL,
12463         },
12464 };
12465
12466 /* vf mac anti spoof configuration */
12467
12468 /* Common result structure for vf mac anti spoof */
12469 struct cmd_vf_mac_anti_spoof_result {
12470         cmdline_fixed_string_t set;
12471         cmdline_fixed_string_t vf;
12472         cmdline_fixed_string_t mac;
12473         cmdline_fixed_string_t antispoof;
12474         portid_t port_id;
12475         uint32_t vf_id;
12476         cmdline_fixed_string_t on_off;
12477 };
12478
12479 /* Common CLI fields for vf mac anti spoof enable disable */
12480 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12481         TOKEN_STRING_INITIALIZER
12482                 (struct cmd_vf_mac_anti_spoof_result,
12483                  set, "set");
12484 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_vf_mac_anti_spoof_result,
12487                  vf, "vf");
12488 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_vf_mac_anti_spoof_result,
12491                  mac, "mac");
12492 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12493         TOKEN_STRING_INITIALIZER
12494                 (struct cmd_vf_mac_anti_spoof_result,
12495                  antispoof, "antispoof");
12496 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12497         TOKEN_NUM_INITIALIZER
12498                 (struct cmd_vf_mac_anti_spoof_result,
12499                  port_id, UINT16);
12500 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12501         TOKEN_NUM_INITIALIZER
12502                 (struct cmd_vf_mac_anti_spoof_result,
12503                  vf_id, UINT32);
12504 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_vf_mac_anti_spoof_result,
12507                  on_off, "on#off");
12508
12509 static void
12510 cmd_set_vf_mac_anti_spoof_parsed(
12511         void *parsed_result,
12512         __attribute__((unused)) struct cmdline *cl,
12513         __attribute__((unused)) void *data)
12514 {
12515         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12516         int ret = -ENOTSUP;
12517
12518         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12519
12520         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12521                 return;
12522
12523 #ifdef RTE_LIBRTE_IXGBE_PMD
12524         if (ret == -ENOTSUP)
12525                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12526                         res->vf_id, is_on);
12527 #endif
12528 #ifdef RTE_LIBRTE_I40E_PMD
12529         if (ret == -ENOTSUP)
12530                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12531                         res->vf_id, is_on);
12532 #endif
12533 #ifdef RTE_LIBRTE_BNXT_PMD
12534         if (ret == -ENOTSUP)
12535                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12536                         res->vf_id, is_on);
12537 #endif
12538
12539         switch (ret) {
12540         case 0:
12541                 break;
12542         case -EINVAL:
12543                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12544                 break;
12545         case -ENODEV:
12546                 printf("invalid port_id %d\n", res->port_id);
12547                 break;
12548         case -ENOTSUP:
12549                 printf("function not implemented\n");
12550                 break;
12551         default:
12552                 printf("programming error: (%s)\n", strerror(-ret));
12553         }
12554 }
12555
12556 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12557         .f = cmd_set_vf_mac_anti_spoof_parsed,
12558         .data = NULL,
12559         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12560         .tokens = {
12561                 (void *)&cmd_vf_mac_anti_spoof_set,
12562                 (void *)&cmd_vf_mac_anti_spoof_vf,
12563                 (void *)&cmd_vf_mac_anti_spoof_mac,
12564                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12565                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12566                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12567                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12568                 NULL,
12569         },
12570 };
12571
12572 /* vf vlan strip queue configuration */
12573
12574 /* Common result structure for vf mac anti spoof */
12575 struct cmd_vf_vlan_stripq_result {
12576         cmdline_fixed_string_t set;
12577         cmdline_fixed_string_t vf;
12578         cmdline_fixed_string_t vlan;
12579         cmdline_fixed_string_t stripq;
12580         portid_t port_id;
12581         uint16_t vf_id;
12582         cmdline_fixed_string_t on_off;
12583 };
12584
12585 /* Common CLI fields for vf vlan strip enable disable */
12586 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12587         TOKEN_STRING_INITIALIZER
12588                 (struct cmd_vf_vlan_stripq_result,
12589                  set, "set");
12590 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12591         TOKEN_STRING_INITIALIZER
12592                 (struct cmd_vf_vlan_stripq_result,
12593                  vf, "vf");
12594 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12595         TOKEN_STRING_INITIALIZER
12596                 (struct cmd_vf_vlan_stripq_result,
12597                  vlan, "vlan");
12598 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12599         TOKEN_STRING_INITIALIZER
12600                 (struct cmd_vf_vlan_stripq_result,
12601                  stripq, "stripq");
12602 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12603         TOKEN_NUM_INITIALIZER
12604                 (struct cmd_vf_vlan_stripq_result,
12605                  port_id, UINT16);
12606 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12607         TOKEN_NUM_INITIALIZER
12608                 (struct cmd_vf_vlan_stripq_result,
12609                  vf_id, UINT16);
12610 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12611         TOKEN_STRING_INITIALIZER
12612                 (struct cmd_vf_vlan_stripq_result,
12613                  on_off, "on#off");
12614
12615 static void
12616 cmd_set_vf_vlan_stripq_parsed(
12617         void *parsed_result,
12618         __attribute__((unused)) struct cmdline *cl,
12619         __attribute__((unused)) void *data)
12620 {
12621         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12622         int ret = -ENOTSUP;
12623
12624         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12625
12626         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12627                 return;
12628
12629 #ifdef RTE_LIBRTE_IXGBE_PMD
12630         if (ret == -ENOTSUP)
12631                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12632                         res->vf_id, is_on);
12633 #endif
12634 #ifdef RTE_LIBRTE_I40E_PMD
12635         if (ret == -ENOTSUP)
12636                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12637                         res->vf_id, is_on);
12638 #endif
12639 #ifdef RTE_LIBRTE_BNXT_PMD
12640         if (ret == -ENOTSUP)
12641                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12642                         res->vf_id, is_on);
12643 #endif
12644
12645         switch (ret) {
12646         case 0:
12647                 break;
12648         case -EINVAL:
12649                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12650                 break;
12651         case -ENODEV:
12652                 printf("invalid port_id %d\n", res->port_id);
12653                 break;
12654         case -ENOTSUP:
12655                 printf("function not implemented\n");
12656                 break;
12657         default:
12658                 printf("programming error: (%s)\n", strerror(-ret));
12659         }
12660 }
12661
12662 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12663         .f = cmd_set_vf_vlan_stripq_parsed,
12664         .data = NULL,
12665         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12666         .tokens = {
12667                 (void *)&cmd_vf_vlan_stripq_set,
12668                 (void *)&cmd_vf_vlan_stripq_vf,
12669                 (void *)&cmd_vf_vlan_stripq_vlan,
12670                 (void *)&cmd_vf_vlan_stripq_stripq,
12671                 (void *)&cmd_vf_vlan_stripq_port_id,
12672                 (void *)&cmd_vf_vlan_stripq_vf_id,
12673                 (void *)&cmd_vf_vlan_stripq_on_off,
12674                 NULL,
12675         },
12676 };
12677
12678 /* vf vlan insert configuration */
12679
12680 /* Common result structure for vf vlan insert */
12681 struct cmd_vf_vlan_insert_result {
12682         cmdline_fixed_string_t set;
12683         cmdline_fixed_string_t vf;
12684         cmdline_fixed_string_t vlan;
12685         cmdline_fixed_string_t insert;
12686         portid_t port_id;
12687         uint16_t vf_id;
12688         uint16_t vlan_id;
12689 };
12690
12691 /* Common CLI fields for vf vlan insert enable disable */
12692 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12693         TOKEN_STRING_INITIALIZER
12694                 (struct cmd_vf_vlan_insert_result,
12695                  set, "set");
12696 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12697         TOKEN_STRING_INITIALIZER
12698                 (struct cmd_vf_vlan_insert_result,
12699                  vf, "vf");
12700 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12701         TOKEN_STRING_INITIALIZER
12702                 (struct cmd_vf_vlan_insert_result,
12703                  vlan, "vlan");
12704 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12705         TOKEN_STRING_INITIALIZER
12706                 (struct cmd_vf_vlan_insert_result,
12707                  insert, "insert");
12708 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12709         TOKEN_NUM_INITIALIZER
12710                 (struct cmd_vf_vlan_insert_result,
12711                  port_id, UINT16);
12712 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12713         TOKEN_NUM_INITIALIZER
12714                 (struct cmd_vf_vlan_insert_result,
12715                  vf_id, UINT16);
12716 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12717         TOKEN_NUM_INITIALIZER
12718                 (struct cmd_vf_vlan_insert_result,
12719                  vlan_id, UINT16);
12720
12721 static void
12722 cmd_set_vf_vlan_insert_parsed(
12723         void *parsed_result,
12724         __attribute__((unused)) struct cmdline *cl,
12725         __attribute__((unused)) void *data)
12726 {
12727         struct cmd_vf_vlan_insert_result *res = parsed_result;
12728         int ret = -ENOTSUP;
12729
12730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12731                 return;
12732
12733 #ifdef RTE_LIBRTE_IXGBE_PMD
12734         if (ret == -ENOTSUP)
12735                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12736                         res->vlan_id);
12737 #endif
12738 #ifdef RTE_LIBRTE_I40E_PMD
12739         if (ret == -ENOTSUP)
12740                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12741                         res->vlan_id);
12742 #endif
12743 #ifdef RTE_LIBRTE_BNXT_PMD
12744         if (ret == -ENOTSUP)
12745                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12746                         res->vlan_id);
12747 #endif
12748
12749         switch (ret) {
12750         case 0:
12751                 break;
12752         case -EINVAL:
12753                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12754                 break;
12755         case -ENODEV:
12756                 printf("invalid port_id %d\n", res->port_id);
12757                 break;
12758         case -ENOTSUP:
12759                 printf("function not implemented\n");
12760                 break;
12761         default:
12762                 printf("programming error: (%s)\n", strerror(-ret));
12763         }
12764 }
12765
12766 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12767         .f = cmd_set_vf_vlan_insert_parsed,
12768         .data = NULL,
12769         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12770         .tokens = {
12771                 (void *)&cmd_vf_vlan_insert_set,
12772                 (void *)&cmd_vf_vlan_insert_vf,
12773                 (void *)&cmd_vf_vlan_insert_vlan,
12774                 (void *)&cmd_vf_vlan_insert_insert,
12775                 (void *)&cmd_vf_vlan_insert_port_id,
12776                 (void *)&cmd_vf_vlan_insert_vf_id,
12777                 (void *)&cmd_vf_vlan_insert_vlan_id,
12778                 NULL,
12779         },
12780 };
12781
12782 /* tx loopback configuration */
12783
12784 /* Common result structure for tx loopback */
12785 struct cmd_tx_loopback_result {
12786         cmdline_fixed_string_t set;
12787         cmdline_fixed_string_t tx;
12788         cmdline_fixed_string_t loopback;
12789         portid_t port_id;
12790         cmdline_fixed_string_t on_off;
12791 };
12792
12793 /* Common CLI fields for tx loopback enable disable */
12794 cmdline_parse_token_string_t cmd_tx_loopback_set =
12795         TOKEN_STRING_INITIALIZER
12796                 (struct cmd_tx_loopback_result,
12797                  set, "set");
12798 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12799         TOKEN_STRING_INITIALIZER
12800                 (struct cmd_tx_loopback_result,
12801                  tx, "tx");
12802 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12803         TOKEN_STRING_INITIALIZER
12804                 (struct cmd_tx_loopback_result,
12805                  loopback, "loopback");
12806 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12807         TOKEN_NUM_INITIALIZER
12808                 (struct cmd_tx_loopback_result,
12809                  port_id, UINT16);
12810 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12811         TOKEN_STRING_INITIALIZER
12812                 (struct cmd_tx_loopback_result,
12813                  on_off, "on#off");
12814
12815 static void
12816 cmd_set_tx_loopback_parsed(
12817         void *parsed_result,
12818         __attribute__((unused)) struct cmdline *cl,
12819         __attribute__((unused)) void *data)
12820 {
12821         struct cmd_tx_loopback_result *res = parsed_result;
12822         int ret = -ENOTSUP;
12823
12824         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12825
12826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12827                 return;
12828
12829 #ifdef RTE_LIBRTE_IXGBE_PMD
12830         if (ret == -ENOTSUP)
12831                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12832 #endif
12833 #ifdef RTE_LIBRTE_I40E_PMD
12834         if (ret == -ENOTSUP)
12835                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12836 #endif
12837 #ifdef RTE_LIBRTE_BNXT_PMD
12838         if (ret == -ENOTSUP)
12839                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12840 #endif
12841 #ifdef RTE_LIBRTE_DPAA_PMD
12842         if (ret == -ENOTSUP)
12843                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12844 #endif
12845
12846         switch (ret) {
12847         case 0:
12848                 break;
12849         case -EINVAL:
12850                 printf("invalid is_on %d\n", is_on);
12851                 break;
12852         case -ENODEV:
12853                 printf("invalid port_id %d\n", res->port_id);
12854                 break;
12855         case -ENOTSUP:
12856                 printf("function not implemented\n");
12857                 break;
12858         default:
12859                 printf("programming error: (%s)\n", strerror(-ret));
12860         }
12861 }
12862
12863 cmdline_parse_inst_t cmd_set_tx_loopback = {
12864         .f = cmd_set_tx_loopback_parsed,
12865         .data = NULL,
12866         .help_str = "set tx loopback <port_id> on|off",
12867         .tokens = {
12868                 (void *)&cmd_tx_loopback_set,
12869                 (void *)&cmd_tx_loopback_tx,
12870                 (void *)&cmd_tx_loopback_loopback,
12871                 (void *)&cmd_tx_loopback_port_id,
12872                 (void *)&cmd_tx_loopback_on_off,
12873                 NULL,
12874         },
12875 };
12876
12877 /* all queues drop enable configuration */
12878
12879 /* Common result structure for all queues drop enable */
12880 struct cmd_all_queues_drop_en_result {
12881         cmdline_fixed_string_t set;
12882         cmdline_fixed_string_t all;
12883         cmdline_fixed_string_t queues;
12884         cmdline_fixed_string_t drop;
12885         portid_t port_id;
12886         cmdline_fixed_string_t on_off;
12887 };
12888
12889 /* Common CLI fields for tx loopback enable disable */
12890 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_all_queues_drop_en_result,
12893                  set, "set");
12894 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12895         TOKEN_STRING_INITIALIZER
12896                 (struct cmd_all_queues_drop_en_result,
12897                  all, "all");
12898 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12899         TOKEN_STRING_INITIALIZER
12900                 (struct cmd_all_queues_drop_en_result,
12901                  queues, "queues");
12902 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12903         TOKEN_STRING_INITIALIZER
12904                 (struct cmd_all_queues_drop_en_result,
12905                  drop, "drop");
12906 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12907         TOKEN_NUM_INITIALIZER
12908                 (struct cmd_all_queues_drop_en_result,
12909                  port_id, UINT16);
12910 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12911         TOKEN_STRING_INITIALIZER
12912                 (struct cmd_all_queues_drop_en_result,
12913                  on_off, "on#off");
12914
12915 static void
12916 cmd_set_all_queues_drop_en_parsed(
12917         void *parsed_result,
12918         __attribute__((unused)) struct cmdline *cl,
12919         __attribute__((unused)) void *data)
12920 {
12921         struct cmd_all_queues_drop_en_result *res = parsed_result;
12922         int ret = -ENOTSUP;
12923         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12924
12925         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12926                 return;
12927
12928 #ifdef RTE_LIBRTE_IXGBE_PMD
12929         if (ret == -ENOTSUP)
12930                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12931 #endif
12932 #ifdef RTE_LIBRTE_BNXT_PMD
12933         if (ret == -ENOTSUP)
12934                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12935 #endif
12936         switch (ret) {
12937         case 0:
12938                 break;
12939         case -EINVAL:
12940                 printf("invalid is_on %d\n", is_on);
12941                 break;
12942         case -ENODEV:
12943                 printf("invalid port_id %d\n", res->port_id);
12944                 break;
12945         case -ENOTSUP:
12946                 printf("function not implemented\n");
12947                 break;
12948         default:
12949                 printf("programming error: (%s)\n", strerror(-ret));
12950         }
12951 }
12952
12953 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12954         .f = cmd_set_all_queues_drop_en_parsed,
12955         .data = NULL,
12956         .help_str = "set all queues drop <port_id> on|off",
12957         .tokens = {
12958                 (void *)&cmd_all_queues_drop_en_set,
12959                 (void *)&cmd_all_queues_drop_en_all,
12960                 (void *)&cmd_all_queues_drop_en_queues,
12961                 (void *)&cmd_all_queues_drop_en_drop,
12962                 (void *)&cmd_all_queues_drop_en_port_id,
12963                 (void *)&cmd_all_queues_drop_en_on_off,
12964                 NULL,
12965         },
12966 };
12967
12968 /* vf split drop enable configuration */
12969
12970 /* Common result structure for vf split drop enable */
12971 struct cmd_vf_split_drop_en_result {
12972         cmdline_fixed_string_t set;
12973         cmdline_fixed_string_t vf;
12974         cmdline_fixed_string_t split;
12975         cmdline_fixed_string_t drop;
12976         portid_t port_id;
12977         uint16_t vf_id;
12978         cmdline_fixed_string_t on_off;
12979 };
12980
12981 /* Common CLI fields for vf split drop enable disable */
12982 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12983         TOKEN_STRING_INITIALIZER
12984                 (struct cmd_vf_split_drop_en_result,
12985                  set, "set");
12986 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12987         TOKEN_STRING_INITIALIZER
12988                 (struct cmd_vf_split_drop_en_result,
12989                  vf, "vf");
12990 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12991         TOKEN_STRING_INITIALIZER
12992                 (struct cmd_vf_split_drop_en_result,
12993                  split, "split");
12994 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12995         TOKEN_STRING_INITIALIZER
12996                 (struct cmd_vf_split_drop_en_result,
12997                  drop, "drop");
12998 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12999         TOKEN_NUM_INITIALIZER
13000                 (struct cmd_vf_split_drop_en_result,
13001                  port_id, UINT16);
13002 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13003         TOKEN_NUM_INITIALIZER
13004                 (struct cmd_vf_split_drop_en_result,
13005                  vf_id, UINT16);
13006 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13007         TOKEN_STRING_INITIALIZER
13008                 (struct cmd_vf_split_drop_en_result,
13009                  on_off, "on#off");
13010
13011 static void
13012 cmd_set_vf_split_drop_en_parsed(
13013         void *parsed_result,
13014         __attribute__((unused)) struct cmdline *cl,
13015         __attribute__((unused)) void *data)
13016 {
13017         struct cmd_vf_split_drop_en_result *res = parsed_result;
13018         int ret = -ENOTSUP;
13019         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13020
13021         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13022                 return;
13023
13024 #ifdef RTE_LIBRTE_IXGBE_PMD
13025         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13026                         is_on);
13027 #endif
13028         switch (ret) {
13029         case 0:
13030                 break;
13031         case -EINVAL:
13032                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13033                 break;
13034         case -ENODEV:
13035                 printf("invalid port_id %d\n", res->port_id);
13036                 break;
13037         case -ENOTSUP:
13038                 printf("not supported on port %d\n", res->port_id);
13039                 break;
13040         default:
13041                 printf("programming error: (%s)\n", strerror(-ret));
13042         }
13043 }
13044
13045 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13046         .f = cmd_set_vf_split_drop_en_parsed,
13047         .data = NULL,
13048         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13049         .tokens = {
13050                 (void *)&cmd_vf_split_drop_en_set,
13051                 (void *)&cmd_vf_split_drop_en_vf,
13052                 (void *)&cmd_vf_split_drop_en_split,
13053                 (void *)&cmd_vf_split_drop_en_drop,
13054                 (void *)&cmd_vf_split_drop_en_port_id,
13055                 (void *)&cmd_vf_split_drop_en_vf_id,
13056                 (void *)&cmd_vf_split_drop_en_on_off,
13057                 NULL,
13058         },
13059 };
13060
13061 /* vf mac address configuration */
13062
13063 /* Common result structure for vf mac address */
13064 struct cmd_set_vf_mac_addr_result {
13065         cmdline_fixed_string_t set;
13066         cmdline_fixed_string_t vf;
13067         cmdline_fixed_string_t mac;
13068         cmdline_fixed_string_t addr;
13069         portid_t port_id;
13070         uint16_t vf_id;
13071         struct ether_addr mac_addr;
13072
13073 };
13074
13075 /* Common CLI fields for vf split drop enable disable */
13076 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_set_vf_mac_addr_result,
13079                  set, "set");
13080 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13081         TOKEN_STRING_INITIALIZER
13082                 (struct cmd_set_vf_mac_addr_result,
13083                  vf, "vf");
13084 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_set_vf_mac_addr_result,
13087                  mac, "mac");
13088 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_set_vf_mac_addr_result,
13091                  addr, "addr");
13092 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13093         TOKEN_NUM_INITIALIZER
13094                 (struct cmd_set_vf_mac_addr_result,
13095                  port_id, UINT16);
13096 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13097         TOKEN_NUM_INITIALIZER
13098                 (struct cmd_set_vf_mac_addr_result,
13099                  vf_id, UINT16);
13100 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13101         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13102                  mac_addr);
13103
13104 static void
13105 cmd_set_vf_mac_addr_parsed(
13106         void *parsed_result,
13107         __attribute__((unused)) struct cmdline *cl,
13108         __attribute__((unused)) void *data)
13109 {
13110         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13111         int ret = -ENOTSUP;
13112
13113         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13114                 return;
13115
13116 #ifdef RTE_LIBRTE_IXGBE_PMD
13117         if (ret == -ENOTSUP)
13118                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13119                                 &res->mac_addr);
13120 #endif
13121 #ifdef RTE_LIBRTE_I40E_PMD
13122         if (ret == -ENOTSUP)
13123                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13124                                 &res->mac_addr);
13125 #endif
13126 #ifdef RTE_LIBRTE_BNXT_PMD
13127         if (ret == -ENOTSUP)
13128                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13129                                 &res->mac_addr);
13130 #endif
13131
13132         switch (ret) {
13133         case 0:
13134                 break;
13135         case -EINVAL:
13136                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13137                 break;
13138         case -ENODEV:
13139                 printf("invalid port_id %d\n", res->port_id);
13140                 break;
13141         case -ENOTSUP:
13142                 printf("function not implemented\n");
13143                 break;
13144         default:
13145                 printf("programming error: (%s)\n", strerror(-ret));
13146         }
13147 }
13148
13149 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13150         .f = cmd_set_vf_mac_addr_parsed,
13151         .data = NULL,
13152         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13153         .tokens = {
13154                 (void *)&cmd_set_vf_mac_addr_set,
13155                 (void *)&cmd_set_vf_mac_addr_vf,
13156                 (void *)&cmd_set_vf_mac_addr_mac,
13157                 (void *)&cmd_set_vf_mac_addr_addr,
13158                 (void *)&cmd_set_vf_mac_addr_port_id,
13159                 (void *)&cmd_set_vf_mac_addr_vf_id,
13160                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13161                 NULL,
13162         },
13163 };
13164
13165 /* MACsec configuration */
13166
13167 /* Common result structure for MACsec offload enable */
13168 struct cmd_macsec_offload_on_result {
13169         cmdline_fixed_string_t set;
13170         cmdline_fixed_string_t macsec;
13171         cmdline_fixed_string_t offload;
13172         portid_t port_id;
13173         cmdline_fixed_string_t on;
13174         cmdline_fixed_string_t encrypt;
13175         cmdline_fixed_string_t en_on_off;
13176         cmdline_fixed_string_t replay_protect;
13177         cmdline_fixed_string_t rp_on_off;
13178 };
13179
13180 /* Common CLI fields for MACsec offload disable */
13181 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13182         TOKEN_STRING_INITIALIZER
13183                 (struct cmd_macsec_offload_on_result,
13184                  set, "set");
13185 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13186         TOKEN_STRING_INITIALIZER
13187                 (struct cmd_macsec_offload_on_result,
13188                  macsec, "macsec");
13189 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13190         TOKEN_STRING_INITIALIZER
13191                 (struct cmd_macsec_offload_on_result,
13192                  offload, "offload");
13193 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13194         TOKEN_NUM_INITIALIZER
13195                 (struct cmd_macsec_offload_on_result,
13196                  port_id, UINT16);
13197 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13198         TOKEN_STRING_INITIALIZER
13199                 (struct cmd_macsec_offload_on_result,
13200                  on, "on");
13201 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13202         TOKEN_STRING_INITIALIZER
13203                 (struct cmd_macsec_offload_on_result,
13204                  encrypt, "encrypt");
13205 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13206         TOKEN_STRING_INITIALIZER
13207                 (struct cmd_macsec_offload_on_result,
13208                  en_on_off, "on#off");
13209 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13210         TOKEN_STRING_INITIALIZER
13211                 (struct cmd_macsec_offload_on_result,
13212                  replay_protect, "replay-protect");
13213 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13214         TOKEN_STRING_INITIALIZER
13215                 (struct cmd_macsec_offload_on_result,
13216                  rp_on_off, "on#off");
13217
13218 static void
13219 cmd_set_macsec_offload_on_parsed(
13220         void *parsed_result,
13221         __attribute__((unused)) struct cmdline *cl,
13222         __attribute__((unused)) void *data)
13223 {
13224         struct cmd_macsec_offload_on_result *res = parsed_result;
13225         int ret = -ENOTSUP;
13226         portid_t port_id = res->port_id;
13227         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13228         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13229         struct rte_eth_dev_info dev_info;
13230
13231         if (port_id_is_invalid(port_id, ENABLED_WARN))
13232                 return;
13233         if (!port_is_stopped(port_id)) {
13234                 printf("Please stop port %d first\n", port_id);
13235                 return;
13236         }
13237
13238         rte_eth_dev_info_get(port_id, &dev_info);
13239         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13240 #ifdef RTE_LIBRTE_IXGBE_PMD
13241                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13242 #endif
13243         }
13244         RTE_SET_USED(en);
13245         RTE_SET_USED(rp);
13246
13247         switch (ret) {
13248         case 0:
13249                 ports[port_id].dev_conf.txmode.offloads |=
13250                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13251                 cmd_reconfig_device_queue(port_id, 1, 1);
13252                 break;
13253         case -ENODEV:
13254                 printf("invalid port_id %d\n", port_id);
13255                 break;
13256         case -ENOTSUP:
13257                 printf("not supported on port %d\n", port_id);
13258                 break;
13259         default:
13260                 printf("programming error: (%s)\n", strerror(-ret));
13261         }
13262 }
13263
13264 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13265         .f = cmd_set_macsec_offload_on_parsed,
13266         .data = NULL,
13267         .help_str = "set macsec offload <port_id> on "
13268                 "encrypt on|off replay-protect on|off",
13269         .tokens = {
13270                 (void *)&cmd_macsec_offload_on_set,
13271                 (void *)&cmd_macsec_offload_on_macsec,
13272                 (void *)&cmd_macsec_offload_on_offload,
13273                 (void *)&cmd_macsec_offload_on_port_id,
13274                 (void *)&cmd_macsec_offload_on_on,
13275                 (void *)&cmd_macsec_offload_on_encrypt,
13276                 (void *)&cmd_macsec_offload_on_en_on_off,
13277                 (void *)&cmd_macsec_offload_on_replay_protect,
13278                 (void *)&cmd_macsec_offload_on_rp_on_off,
13279                 NULL,
13280         },
13281 };
13282
13283 /* Common result structure for MACsec offload disable */
13284 struct cmd_macsec_offload_off_result {
13285         cmdline_fixed_string_t set;
13286         cmdline_fixed_string_t macsec;
13287         cmdline_fixed_string_t offload;
13288         portid_t port_id;
13289         cmdline_fixed_string_t off;
13290 };
13291
13292 /* Common CLI fields for MACsec offload disable */
13293 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13294         TOKEN_STRING_INITIALIZER
13295                 (struct cmd_macsec_offload_off_result,
13296                  set, "set");
13297 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13298         TOKEN_STRING_INITIALIZER
13299                 (struct cmd_macsec_offload_off_result,
13300                  macsec, "macsec");
13301 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13302         TOKEN_STRING_INITIALIZER
13303                 (struct cmd_macsec_offload_off_result,
13304                  offload, "offload");
13305 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13306         TOKEN_NUM_INITIALIZER
13307                 (struct cmd_macsec_offload_off_result,
13308                  port_id, UINT16);
13309 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13310         TOKEN_STRING_INITIALIZER
13311                 (struct cmd_macsec_offload_off_result,
13312                  off, "off");
13313
13314 static void
13315 cmd_set_macsec_offload_off_parsed(
13316         void *parsed_result,
13317         __attribute__((unused)) struct cmdline *cl,
13318         __attribute__((unused)) void *data)
13319 {
13320         struct cmd_macsec_offload_off_result *res = parsed_result;
13321         int ret = -ENOTSUP;
13322         struct rte_eth_dev_info dev_info;
13323         portid_t port_id = res->port_id;
13324
13325         if (port_id_is_invalid(port_id, ENABLED_WARN))
13326                 return;
13327         if (!port_is_stopped(port_id)) {
13328                 printf("Please stop port %d first\n", port_id);
13329                 return;
13330         }
13331
13332         rte_eth_dev_info_get(port_id, &dev_info);
13333         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13334 #ifdef RTE_LIBRTE_IXGBE_PMD
13335                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13336 #endif
13337         }
13338         switch (ret) {
13339         case 0:
13340                 ports[port_id].dev_conf.txmode.offloads &=
13341                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13342                 cmd_reconfig_device_queue(port_id, 1, 1);
13343                 break;
13344         case -ENODEV:
13345                 printf("invalid port_id %d\n", port_id);
13346                 break;
13347         case -ENOTSUP:
13348                 printf("not supported on port %d\n", port_id);
13349                 break;
13350         default:
13351                 printf("programming error: (%s)\n", strerror(-ret));
13352         }
13353 }
13354
13355 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13356         .f = cmd_set_macsec_offload_off_parsed,
13357         .data = NULL,
13358         .help_str = "set macsec offload <port_id> off",
13359         .tokens = {
13360                 (void *)&cmd_macsec_offload_off_set,
13361                 (void *)&cmd_macsec_offload_off_macsec,
13362                 (void *)&cmd_macsec_offload_off_offload,
13363                 (void *)&cmd_macsec_offload_off_port_id,
13364                 (void *)&cmd_macsec_offload_off_off,
13365                 NULL,
13366         },
13367 };
13368
13369 /* Common result structure for MACsec secure connection configure */
13370 struct cmd_macsec_sc_result {
13371         cmdline_fixed_string_t set;
13372         cmdline_fixed_string_t macsec;
13373         cmdline_fixed_string_t sc;
13374         cmdline_fixed_string_t tx_rx;
13375         portid_t port_id;
13376         struct ether_addr mac;
13377         uint16_t pi;
13378 };
13379
13380 /* Common CLI fields for MACsec secure connection configure */
13381 cmdline_parse_token_string_t cmd_macsec_sc_set =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_macsec_sc_result,
13384                  set, "set");
13385 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_macsec_sc_result,
13388                  macsec, "macsec");
13389 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13390         TOKEN_STRING_INITIALIZER
13391                 (struct cmd_macsec_sc_result,
13392                  sc, "sc");
13393 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_macsec_sc_result,
13396                  tx_rx, "tx#rx");
13397 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13398         TOKEN_NUM_INITIALIZER
13399                 (struct cmd_macsec_sc_result,
13400                  port_id, UINT16);
13401 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13402         TOKEN_ETHERADDR_INITIALIZER
13403                 (struct cmd_macsec_sc_result,
13404                  mac);
13405 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13406         TOKEN_NUM_INITIALIZER
13407                 (struct cmd_macsec_sc_result,
13408                  pi, UINT16);
13409
13410 static void
13411 cmd_set_macsec_sc_parsed(
13412         void *parsed_result,
13413         __attribute__((unused)) struct cmdline *cl,
13414         __attribute__((unused)) void *data)
13415 {
13416         struct cmd_macsec_sc_result *res = parsed_result;
13417         int ret = -ENOTSUP;
13418         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13419
13420 #ifdef RTE_LIBRTE_IXGBE_PMD
13421         ret = is_tx ?
13422                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13423                                 res->mac.addr_bytes) :
13424                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13425                                 res->mac.addr_bytes, res->pi);
13426 #endif
13427         RTE_SET_USED(is_tx);
13428
13429         switch (ret) {
13430         case 0:
13431                 break;
13432         case -ENODEV:
13433                 printf("invalid port_id %d\n", res->port_id);
13434                 break;
13435         case -ENOTSUP:
13436                 printf("not supported on port %d\n", res->port_id);
13437                 break;
13438         default:
13439                 printf("programming error: (%s)\n", strerror(-ret));
13440         }
13441 }
13442
13443 cmdline_parse_inst_t cmd_set_macsec_sc = {
13444         .f = cmd_set_macsec_sc_parsed,
13445         .data = NULL,
13446         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13447         .tokens = {
13448                 (void *)&cmd_macsec_sc_set,
13449                 (void *)&cmd_macsec_sc_macsec,
13450                 (void *)&cmd_macsec_sc_sc,
13451                 (void *)&cmd_macsec_sc_tx_rx,
13452                 (void *)&cmd_macsec_sc_port_id,
13453                 (void *)&cmd_macsec_sc_mac,
13454                 (void *)&cmd_macsec_sc_pi,
13455                 NULL,
13456         },
13457 };
13458
13459 /* Common result structure for MACsec secure connection configure */
13460 struct cmd_macsec_sa_result {
13461         cmdline_fixed_string_t set;
13462         cmdline_fixed_string_t macsec;
13463         cmdline_fixed_string_t sa;
13464         cmdline_fixed_string_t tx_rx;
13465         portid_t port_id;
13466         uint8_t idx;
13467         uint8_t an;
13468         uint32_t pn;
13469         cmdline_fixed_string_t key;
13470 };
13471
13472 /* Common CLI fields for MACsec secure connection configure */
13473 cmdline_parse_token_string_t cmd_macsec_sa_set =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_macsec_sa_result,
13476                  set, "set");
13477 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_macsec_sa_result,
13480                  macsec, "macsec");
13481 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13482         TOKEN_STRING_INITIALIZER
13483                 (struct cmd_macsec_sa_result,
13484                  sa, "sa");
13485 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13486         TOKEN_STRING_INITIALIZER
13487                 (struct cmd_macsec_sa_result,
13488                  tx_rx, "tx#rx");
13489 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13490         TOKEN_NUM_INITIALIZER
13491                 (struct cmd_macsec_sa_result,
13492                  port_id, UINT16);
13493 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13494         TOKEN_NUM_INITIALIZER
13495                 (struct cmd_macsec_sa_result,
13496                  idx, UINT8);
13497 cmdline_parse_token_num_t cmd_macsec_sa_an =
13498         TOKEN_NUM_INITIALIZER
13499                 (struct cmd_macsec_sa_result,
13500                  an, UINT8);
13501 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13502         TOKEN_NUM_INITIALIZER
13503                 (struct cmd_macsec_sa_result,
13504                  pn, UINT32);
13505 cmdline_parse_token_string_t cmd_macsec_sa_key =
13506         TOKEN_STRING_INITIALIZER
13507                 (struct cmd_macsec_sa_result,
13508                  key, NULL);
13509
13510 static void
13511 cmd_set_macsec_sa_parsed(
13512         void *parsed_result,
13513         __attribute__((unused)) struct cmdline *cl,
13514         __attribute__((unused)) void *data)
13515 {
13516         struct cmd_macsec_sa_result *res = parsed_result;
13517         int ret = -ENOTSUP;
13518         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13519         uint8_t key[16] = { 0 };
13520         uint8_t xdgt0;
13521         uint8_t xdgt1;
13522         int key_len;
13523         int i;
13524
13525         key_len = strlen(res->key) / 2;
13526         if (key_len > 16)
13527                 key_len = 16;
13528
13529         for (i = 0; i < key_len; i++) {
13530                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13531                 if (xdgt0 == 0xFF)
13532                         return;
13533                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13534                 if (xdgt1 == 0xFF)
13535                         return;
13536                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13537         }
13538
13539 #ifdef RTE_LIBRTE_IXGBE_PMD
13540         ret = is_tx ?
13541                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13542                         res->idx, res->an, res->pn, key) :
13543                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13544                         res->idx, res->an, res->pn, key);
13545 #endif
13546         RTE_SET_USED(is_tx);
13547         RTE_SET_USED(key);
13548
13549         switch (ret) {
13550         case 0:
13551                 break;
13552         case -EINVAL:
13553                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13554                 break;
13555         case -ENODEV:
13556                 printf("invalid port_id %d\n", res->port_id);
13557                 break;
13558         case -ENOTSUP:
13559                 printf("not supported on port %d\n", res->port_id);
13560                 break;
13561         default:
13562                 printf("programming error: (%s)\n", strerror(-ret));
13563         }
13564 }
13565
13566 cmdline_parse_inst_t cmd_set_macsec_sa = {
13567         .f = cmd_set_macsec_sa_parsed,
13568         .data = NULL,
13569         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13570         .tokens = {
13571                 (void *)&cmd_macsec_sa_set,
13572                 (void *)&cmd_macsec_sa_macsec,
13573                 (void *)&cmd_macsec_sa_sa,
13574                 (void *)&cmd_macsec_sa_tx_rx,
13575                 (void *)&cmd_macsec_sa_port_id,
13576                 (void *)&cmd_macsec_sa_idx,
13577                 (void *)&cmd_macsec_sa_an,
13578                 (void *)&cmd_macsec_sa_pn,
13579                 (void *)&cmd_macsec_sa_key,
13580                 NULL,
13581         },
13582 };
13583
13584 /* VF unicast promiscuous mode configuration */
13585
13586 /* Common result structure for VF unicast promiscuous mode */
13587 struct cmd_vf_promisc_result {
13588         cmdline_fixed_string_t set;
13589         cmdline_fixed_string_t vf;
13590         cmdline_fixed_string_t promisc;
13591         portid_t port_id;
13592         uint32_t vf_id;
13593         cmdline_fixed_string_t on_off;
13594 };
13595
13596 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13597 cmdline_parse_token_string_t cmd_vf_promisc_set =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_promisc_result,
13600                  set, "set");
13601 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13602         TOKEN_STRING_INITIALIZER
13603                 (struct cmd_vf_promisc_result,
13604                  vf, "vf");
13605 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13606         TOKEN_STRING_INITIALIZER
13607                 (struct cmd_vf_promisc_result,
13608                  promisc, "promisc");
13609 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_promisc_result,
13612                  port_id, UINT16);
13613 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13614         TOKEN_NUM_INITIALIZER
13615                 (struct cmd_vf_promisc_result,
13616                  vf_id, UINT32);
13617 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13618         TOKEN_STRING_INITIALIZER
13619                 (struct cmd_vf_promisc_result,
13620                  on_off, "on#off");
13621
13622 static void
13623 cmd_set_vf_promisc_parsed(
13624         void *parsed_result,
13625         __attribute__((unused)) struct cmdline *cl,
13626         __attribute__((unused)) void *data)
13627 {
13628         struct cmd_vf_promisc_result *res = parsed_result;
13629         int ret = -ENOTSUP;
13630
13631         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13632
13633         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13634                 return;
13635
13636 #ifdef RTE_LIBRTE_I40E_PMD
13637         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13638                                                   res->vf_id, is_on);
13639 #endif
13640
13641         switch (ret) {
13642         case 0:
13643                 break;
13644         case -EINVAL:
13645                 printf("invalid vf_id %d\n", res->vf_id);
13646                 break;
13647         case -ENODEV:
13648                 printf("invalid port_id %d\n", res->port_id);
13649                 break;
13650         case -ENOTSUP:
13651                 printf("function not implemented\n");
13652                 break;
13653         default:
13654                 printf("programming error: (%s)\n", strerror(-ret));
13655         }
13656 }
13657
13658 cmdline_parse_inst_t cmd_set_vf_promisc = {
13659         .f = cmd_set_vf_promisc_parsed,
13660         .data = NULL,
13661         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13662                 "Set unicast promiscuous mode for a VF from the PF",
13663         .tokens = {
13664                 (void *)&cmd_vf_promisc_set,
13665                 (void *)&cmd_vf_promisc_vf,
13666                 (void *)&cmd_vf_promisc_promisc,
13667                 (void *)&cmd_vf_promisc_port_id,
13668                 (void *)&cmd_vf_promisc_vf_id,
13669                 (void *)&cmd_vf_promisc_on_off,
13670                 NULL,
13671         },
13672 };
13673
13674 /* VF multicast promiscuous mode configuration */
13675
13676 /* Common result structure for VF multicast promiscuous mode */
13677 struct cmd_vf_allmulti_result {
13678         cmdline_fixed_string_t set;
13679         cmdline_fixed_string_t vf;
13680         cmdline_fixed_string_t allmulti;
13681         portid_t port_id;
13682         uint32_t vf_id;
13683         cmdline_fixed_string_t on_off;
13684 };
13685
13686 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13687 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13688         TOKEN_STRING_INITIALIZER
13689                 (struct cmd_vf_allmulti_result,
13690                  set, "set");
13691 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13692         TOKEN_STRING_INITIALIZER
13693                 (struct cmd_vf_allmulti_result,
13694                  vf, "vf");
13695 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13696         TOKEN_STRING_INITIALIZER
13697                 (struct cmd_vf_allmulti_result,
13698                  allmulti, "allmulti");
13699 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13700         TOKEN_NUM_INITIALIZER
13701                 (struct cmd_vf_allmulti_result,
13702                  port_id, UINT16);
13703 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13704         TOKEN_NUM_INITIALIZER
13705                 (struct cmd_vf_allmulti_result,
13706                  vf_id, UINT32);
13707 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_vf_allmulti_result,
13710                  on_off, "on#off");
13711
13712 static void
13713 cmd_set_vf_allmulti_parsed(
13714         void *parsed_result,
13715         __attribute__((unused)) struct cmdline *cl,
13716         __attribute__((unused)) void *data)
13717 {
13718         struct cmd_vf_allmulti_result *res = parsed_result;
13719         int ret = -ENOTSUP;
13720
13721         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13722
13723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13724                 return;
13725
13726 #ifdef RTE_LIBRTE_I40E_PMD
13727         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13728                                                     res->vf_id, is_on);
13729 #endif
13730
13731         switch (ret) {
13732         case 0:
13733                 break;
13734         case -EINVAL:
13735                 printf("invalid vf_id %d\n", res->vf_id);
13736                 break;
13737         case -ENODEV:
13738                 printf("invalid port_id %d\n", res->port_id);
13739                 break;
13740         case -ENOTSUP:
13741                 printf("function not implemented\n");
13742                 break;
13743         default:
13744                 printf("programming error: (%s)\n", strerror(-ret));
13745         }
13746 }
13747
13748 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13749         .f = cmd_set_vf_allmulti_parsed,
13750         .data = NULL,
13751         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13752                 "Set multicast promiscuous mode for a VF from the PF",
13753         .tokens = {
13754                 (void *)&cmd_vf_allmulti_set,
13755                 (void *)&cmd_vf_allmulti_vf,
13756                 (void *)&cmd_vf_allmulti_allmulti,
13757                 (void *)&cmd_vf_allmulti_port_id,
13758                 (void *)&cmd_vf_allmulti_vf_id,
13759                 (void *)&cmd_vf_allmulti_on_off,
13760                 NULL,
13761         },
13762 };
13763
13764 /* vf broadcast mode configuration */
13765
13766 /* Common result structure for vf broadcast */
13767 struct cmd_set_vf_broadcast_result {
13768         cmdline_fixed_string_t set;
13769         cmdline_fixed_string_t vf;
13770         cmdline_fixed_string_t broadcast;
13771         portid_t port_id;
13772         uint16_t vf_id;
13773         cmdline_fixed_string_t on_off;
13774 };
13775
13776 /* Common CLI fields for vf broadcast enable disable */
13777 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_set_vf_broadcast_result,
13780                  set, "set");
13781 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13782         TOKEN_STRING_INITIALIZER
13783                 (struct cmd_set_vf_broadcast_result,
13784                  vf, "vf");
13785 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13786         TOKEN_STRING_INITIALIZER
13787                 (struct cmd_set_vf_broadcast_result,
13788                  broadcast, "broadcast");
13789 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_set_vf_broadcast_result,
13792                  port_id, UINT16);
13793 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13794         TOKEN_NUM_INITIALIZER
13795                 (struct cmd_set_vf_broadcast_result,
13796                  vf_id, UINT16);
13797 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13798         TOKEN_STRING_INITIALIZER
13799                 (struct cmd_set_vf_broadcast_result,
13800                  on_off, "on#off");
13801
13802 static void
13803 cmd_set_vf_broadcast_parsed(
13804         void *parsed_result,
13805         __attribute__((unused)) struct cmdline *cl,
13806         __attribute__((unused)) void *data)
13807 {
13808         struct cmd_set_vf_broadcast_result *res = parsed_result;
13809         int ret = -ENOTSUP;
13810
13811         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13812
13813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13814                 return;
13815
13816 #ifdef RTE_LIBRTE_I40E_PMD
13817         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13818                                             res->vf_id, is_on);
13819 #endif
13820
13821         switch (ret) {
13822         case 0:
13823                 break;
13824         case -EINVAL:
13825                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13826                 break;
13827         case -ENODEV:
13828                 printf("invalid port_id %d\n", res->port_id);
13829                 break;
13830         case -ENOTSUP:
13831                 printf("function not implemented\n");
13832                 break;
13833         default:
13834                 printf("programming error: (%s)\n", strerror(-ret));
13835         }
13836 }
13837
13838 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13839         .f = cmd_set_vf_broadcast_parsed,
13840         .data = NULL,
13841         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13842         .tokens = {
13843                 (void *)&cmd_set_vf_broadcast_set,
13844                 (void *)&cmd_set_vf_broadcast_vf,
13845                 (void *)&cmd_set_vf_broadcast_broadcast,
13846                 (void *)&cmd_set_vf_broadcast_port_id,
13847                 (void *)&cmd_set_vf_broadcast_vf_id,
13848                 (void *)&cmd_set_vf_broadcast_on_off,
13849                 NULL,
13850         },
13851 };
13852
13853 /* vf vlan tag configuration */
13854
13855 /* Common result structure for vf vlan tag */
13856 struct cmd_set_vf_vlan_tag_result {
13857         cmdline_fixed_string_t set;
13858         cmdline_fixed_string_t vf;
13859         cmdline_fixed_string_t vlan;
13860         cmdline_fixed_string_t tag;
13861         portid_t port_id;
13862         uint16_t vf_id;
13863         cmdline_fixed_string_t on_off;
13864 };
13865
13866 /* Common CLI fields for vf vlan tag enable disable */
13867 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13868         TOKEN_STRING_INITIALIZER
13869                 (struct cmd_set_vf_vlan_tag_result,
13870                  set, "set");
13871 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13872         TOKEN_STRING_INITIALIZER
13873                 (struct cmd_set_vf_vlan_tag_result,
13874                  vf, "vf");
13875 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_set_vf_vlan_tag_result,
13878                  vlan, "vlan");
13879 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13880         TOKEN_STRING_INITIALIZER
13881                 (struct cmd_set_vf_vlan_tag_result,
13882                  tag, "tag");
13883 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13884         TOKEN_NUM_INITIALIZER
13885                 (struct cmd_set_vf_vlan_tag_result,
13886                  port_id, UINT16);
13887 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13888         TOKEN_NUM_INITIALIZER
13889                 (struct cmd_set_vf_vlan_tag_result,
13890                  vf_id, UINT16);
13891 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13892         TOKEN_STRING_INITIALIZER
13893                 (struct cmd_set_vf_vlan_tag_result,
13894                  on_off, "on#off");
13895
13896 static void
13897 cmd_set_vf_vlan_tag_parsed(
13898         void *parsed_result,
13899         __attribute__((unused)) struct cmdline *cl,
13900         __attribute__((unused)) void *data)
13901 {
13902         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13903         int ret = -ENOTSUP;
13904
13905         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13906
13907         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13908                 return;
13909
13910 #ifdef RTE_LIBRTE_I40E_PMD
13911         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13912                                            res->vf_id, is_on);
13913 #endif
13914
13915         switch (ret) {
13916         case 0:
13917                 break;
13918         case -EINVAL:
13919                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13920                 break;
13921         case -ENODEV:
13922                 printf("invalid port_id %d\n", res->port_id);
13923                 break;
13924         case -ENOTSUP:
13925                 printf("function not implemented\n");
13926                 break;
13927         default:
13928                 printf("programming error: (%s)\n", strerror(-ret));
13929         }
13930 }
13931
13932 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13933         .f = cmd_set_vf_vlan_tag_parsed,
13934         .data = NULL,
13935         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13936         .tokens = {
13937                 (void *)&cmd_set_vf_vlan_tag_set,
13938                 (void *)&cmd_set_vf_vlan_tag_vf,
13939                 (void *)&cmd_set_vf_vlan_tag_vlan,
13940                 (void *)&cmd_set_vf_vlan_tag_tag,
13941                 (void *)&cmd_set_vf_vlan_tag_port_id,
13942                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13943                 (void *)&cmd_set_vf_vlan_tag_on_off,
13944                 NULL,
13945         },
13946 };
13947
13948 /* Common definition of VF and TC TX bandwidth configuration */
13949 struct cmd_vf_tc_bw_result {
13950         cmdline_fixed_string_t set;
13951         cmdline_fixed_string_t vf;
13952         cmdline_fixed_string_t tc;
13953         cmdline_fixed_string_t tx;
13954         cmdline_fixed_string_t min_bw;
13955         cmdline_fixed_string_t max_bw;
13956         cmdline_fixed_string_t strict_link_prio;
13957         portid_t port_id;
13958         uint16_t vf_id;
13959         uint8_t tc_no;
13960         uint32_t bw;
13961         cmdline_fixed_string_t bw_list;
13962         uint8_t tc_map;
13963 };
13964
13965 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13966         TOKEN_STRING_INITIALIZER
13967                 (struct cmd_vf_tc_bw_result,
13968                  set, "set");
13969 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13970         TOKEN_STRING_INITIALIZER
13971                 (struct cmd_vf_tc_bw_result,
13972                  vf, "vf");
13973 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13974         TOKEN_STRING_INITIALIZER
13975                 (struct cmd_vf_tc_bw_result,
13976                  tc, "tc");
13977 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13978         TOKEN_STRING_INITIALIZER
13979                 (struct cmd_vf_tc_bw_result,
13980                  tx, "tx");
13981 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13982         TOKEN_STRING_INITIALIZER
13983                 (struct cmd_vf_tc_bw_result,
13984                  strict_link_prio, "strict-link-priority");
13985 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13986         TOKEN_STRING_INITIALIZER
13987                 (struct cmd_vf_tc_bw_result,
13988                  min_bw, "min-bandwidth");
13989 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_vf_tc_bw_result,
13992                  max_bw, "max-bandwidth");
13993 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13994         TOKEN_NUM_INITIALIZER
13995                 (struct cmd_vf_tc_bw_result,
13996                  port_id, UINT16);
13997 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13998         TOKEN_NUM_INITIALIZER
13999                 (struct cmd_vf_tc_bw_result,
14000                  vf_id, UINT16);
14001 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14002         TOKEN_NUM_INITIALIZER
14003                 (struct cmd_vf_tc_bw_result,
14004                  tc_no, UINT8);
14005 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14006         TOKEN_NUM_INITIALIZER
14007                 (struct cmd_vf_tc_bw_result,
14008                  bw, UINT32);
14009 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14010         TOKEN_STRING_INITIALIZER
14011                 (struct cmd_vf_tc_bw_result,
14012                  bw_list, NULL);
14013 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14014         TOKEN_NUM_INITIALIZER
14015                 (struct cmd_vf_tc_bw_result,
14016                  tc_map, UINT8);
14017
14018 /* VF max bandwidth setting */
14019 static void
14020 cmd_vf_max_bw_parsed(
14021         void *parsed_result,
14022         __attribute__((unused)) struct cmdline *cl,
14023         __attribute__((unused)) void *data)
14024 {
14025         struct cmd_vf_tc_bw_result *res = parsed_result;
14026         int ret = -ENOTSUP;
14027
14028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14029                 return;
14030
14031 #ifdef RTE_LIBRTE_I40E_PMD
14032         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14033                                          res->vf_id, res->bw);
14034 #endif
14035
14036         switch (ret) {
14037         case 0:
14038                 break;
14039         case -EINVAL:
14040                 printf("invalid vf_id %d or bandwidth %d\n",
14041                        res->vf_id, res->bw);
14042                 break;
14043         case -ENODEV:
14044                 printf("invalid port_id %d\n", res->port_id);
14045                 break;
14046         case -ENOTSUP:
14047                 printf("function not implemented\n");
14048                 break;
14049         default:
14050                 printf("programming error: (%s)\n", strerror(-ret));
14051         }
14052 }
14053
14054 cmdline_parse_inst_t cmd_vf_max_bw = {
14055         .f = cmd_vf_max_bw_parsed,
14056         .data = NULL,
14057         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14058         .tokens = {
14059                 (void *)&cmd_vf_tc_bw_set,
14060                 (void *)&cmd_vf_tc_bw_vf,
14061                 (void *)&cmd_vf_tc_bw_tx,
14062                 (void *)&cmd_vf_tc_bw_max_bw,
14063                 (void *)&cmd_vf_tc_bw_port_id,
14064                 (void *)&cmd_vf_tc_bw_vf_id,
14065                 (void *)&cmd_vf_tc_bw_bw,
14066                 NULL,
14067         },
14068 };
14069
14070 static int
14071 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14072                            uint8_t *tc_num,
14073                            char *str)
14074 {
14075         uint32_t size;
14076         const char *p, *p0 = str;
14077         char s[256];
14078         char *end;
14079         char *str_fld[16];
14080         uint16_t i;
14081         int ret;
14082
14083         p = strchr(p0, '(');
14084         if (p == NULL) {
14085                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14086                 return -1;
14087         }
14088         p++;
14089         p0 = strchr(p, ')');
14090         if (p0 == NULL) {
14091                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14092                 return -1;
14093         }
14094         size = p0 - p;
14095         if (size >= sizeof(s)) {
14096                 printf("The string size exceeds the internal buffer size\n");
14097                 return -1;
14098         }
14099         snprintf(s, sizeof(s), "%.*s", size, p);
14100         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14101         if (ret <= 0) {
14102                 printf("Failed to get the bandwidth list. ");
14103                 return -1;
14104         }
14105         *tc_num = ret;
14106         for (i = 0; i < ret; i++)
14107                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14108
14109         return 0;
14110 }
14111
14112 /* TC min bandwidth setting */
14113 static void
14114 cmd_vf_tc_min_bw_parsed(
14115         void *parsed_result,
14116         __attribute__((unused)) struct cmdline *cl,
14117         __attribute__((unused)) void *data)
14118 {
14119         struct cmd_vf_tc_bw_result *res = parsed_result;
14120         uint8_t tc_num;
14121         uint8_t bw[16];
14122         int ret = -ENOTSUP;
14123
14124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14125                 return;
14126
14127         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14128         if (ret)
14129                 return;
14130
14131 #ifdef RTE_LIBRTE_I40E_PMD
14132         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14133                                               tc_num, bw);
14134 #endif
14135
14136         switch (ret) {
14137         case 0:
14138                 break;
14139         case -EINVAL:
14140                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14141                 break;
14142         case -ENODEV:
14143                 printf("invalid port_id %d\n", res->port_id);
14144                 break;
14145         case -ENOTSUP:
14146                 printf("function not implemented\n");
14147                 break;
14148         default:
14149                 printf("programming error: (%s)\n", strerror(-ret));
14150         }
14151 }
14152
14153 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14154         .f = cmd_vf_tc_min_bw_parsed,
14155         .data = NULL,
14156         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14157                     " <bw1, bw2, ...>",
14158         .tokens = {
14159                 (void *)&cmd_vf_tc_bw_set,
14160                 (void *)&cmd_vf_tc_bw_vf,
14161                 (void *)&cmd_vf_tc_bw_tc,
14162                 (void *)&cmd_vf_tc_bw_tx,
14163                 (void *)&cmd_vf_tc_bw_min_bw,
14164                 (void *)&cmd_vf_tc_bw_port_id,
14165                 (void *)&cmd_vf_tc_bw_vf_id,
14166                 (void *)&cmd_vf_tc_bw_bw_list,
14167                 NULL,
14168         },
14169 };
14170
14171 static void
14172 cmd_tc_min_bw_parsed(
14173         void *parsed_result,
14174         __attribute__((unused)) struct cmdline *cl,
14175         __attribute__((unused)) void *data)
14176 {
14177         struct cmd_vf_tc_bw_result *res = parsed_result;
14178         struct rte_port *port;
14179         uint8_t tc_num;
14180         uint8_t bw[16];
14181         int ret = -ENOTSUP;
14182
14183         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14184                 return;
14185
14186         port = &ports[res->port_id];
14187         /** Check if the port is not started **/
14188         if (port->port_status != RTE_PORT_STOPPED) {
14189                 printf("Please stop port %d first\n", res->port_id);
14190                 return;
14191         }
14192
14193         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14194         if (ret)
14195                 return;
14196
14197 #ifdef RTE_LIBRTE_IXGBE_PMD
14198         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14199 #endif
14200
14201         switch (ret) {
14202         case 0:
14203                 break;
14204         case -EINVAL:
14205                 printf("invalid bandwidth\n");
14206                 break;
14207         case -ENODEV:
14208                 printf("invalid port_id %d\n", res->port_id);
14209                 break;
14210         case -ENOTSUP:
14211                 printf("function not implemented\n");
14212                 break;
14213         default:
14214                 printf("programming error: (%s)\n", strerror(-ret));
14215         }
14216 }
14217
14218 cmdline_parse_inst_t cmd_tc_min_bw = {
14219         .f = cmd_tc_min_bw_parsed,
14220         .data = NULL,
14221         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14222         .tokens = {
14223                 (void *)&cmd_vf_tc_bw_set,
14224                 (void *)&cmd_vf_tc_bw_tc,
14225                 (void *)&cmd_vf_tc_bw_tx,
14226                 (void *)&cmd_vf_tc_bw_min_bw,
14227                 (void *)&cmd_vf_tc_bw_port_id,
14228                 (void *)&cmd_vf_tc_bw_bw_list,
14229                 NULL,
14230         },
14231 };
14232
14233 /* TC max bandwidth setting */
14234 static void
14235 cmd_vf_tc_max_bw_parsed(
14236         void *parsed_result,
14237         __attribute__((unused)) struct cmdline *cl,
14238         __attribute__((unused)) void *data)
14239 {
14240         struct cmd_vf_tc_bw_result *res = parsed_result;
14241         int ret = -ENOTSUP;
14242
14243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14244                 return;
14245
14246 #ifdef RTE_LIBRTE_I40E_PMD
14247         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14248                                             res->tc_no, res->bw);
14249 #endif
14250
14251         switch (ret) {
14252         case 0:
14253                 break;
14254         case -EINVAL:
14255                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14256                        res->vf_id, res->tc_no, res->bw);
14257                 break;
14258         case -ENODEV:
14259                 printf("invalid port_id %d\n", res->port_id);
14260                 break;
14261         case -ENOTSUP:
14262                 printf("function not implemented\n");
14263                 break;
14264         default:
14265                 printf("programming error: (%s)\n", strerror(-ret));
14266         }
14267 }
14268
14269 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14270         .f = cmd_vf_tc_max_bw_parsed,
14271         .data = NULL,
14272         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14273                     " <bandwidth>",
14274         .tokens = {
14275                 (void *)&cmd_vf_tc_bw_set,
14276                 (void *)&cmd_vf_tc_bw_vf,
14277                 (void *)&cmd_vf_tc_bw_tc,
14278                 (void *)&cmd_vf_tc_bw_tx,
14279                 (void *)&cmd_vf_tc_bw_max_bw,
14280                 (void *)&cmd_vf_tc_bw_port_id,
14281                 (void *)&cmd_vf_tc_bw_vf_id,
14282                 (void *)&cmd_vf_tc_bw_tc_no,
14283                 (void *)&cmd_vf_tc_bw_bw,
14284                 NULL,
14285         },
14286 };
14287
14288
14289 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14290
14291 /* *** Set Port default Traffic Management Hierarchy *** */
14292 struct cmd_set_port_tm_hierarchy_default_result {
14293         cmdline_fixed_string_t set;
14294         cmdline_fixed_string_t port;
14295         cmdline_fixed_string_t tm;
14296         cmdline_fixed_string_t hierarchy;
14297         cmdline_fixed_string_t def;
14298         portid_t port_id;
14299 };
14300
14301 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14302         TOKEN_STRING_INITIALIZER(
14303                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14304 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14305         TOKEN_STRING_INITIALIZER(
14306                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14307 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14308         TOKEN_STRING_INITIALIZER(
14309                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14310 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14311         TOKEN_STRING_INITIALIZER(
14312                 struct cmd_set_port_tm_hierarchy_default_result,
14313                         hierarchy, "hierarchy");
14314 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14315         TOKEN_STRING_INITIALIZER(
14316                 struct cmd_set_port_tm_hierarchy_default_result,
14317                         def, "default");
14318 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14319         TOKEN_NUM_INITIALIZER(
14320                 struct cmd_set_port_tm_hierarchy_default_result,
14321                         port_id, UINT16);
14322
14323 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14324         __attribute__((unused)) struct cmdline *cl,
14325         __attribute__((unused)) void *data)
14326 {
14327         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14328         struct rte_port *p;
14329         portid_t port_id = res->port_id;
14330
14331         if (port_id_is_invalid(port_id, ENABLED_WARN))
14332                 return;
14333
14334         p = &ports[port_id];
14335
14336         /* Port tm flag */
14337         if (p->softport.tm_flag == 0) {
14338                 printf("  tm not enabled on port %u (error)\n", port_id);
14339                 return;
14340         }
14341
14342         /* Forward mode: tm */
14343         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14344                 printf("  tm mode not enabled(error)\n");
14345                 return;
14346         }
14347
14348         /* Set the default tm hierarchy */
14349         p->softport.tm.default_hierarchy_enable = 1;
14350 }
14351
14352 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14353         .f = cmd_set_port_tm_hierarchy_default_parsed,
14354         .data = NULL,
14355         .help_str = "set port tm hierarchy default <port_id>",
14356         .tokens = {
14357                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14358                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14359                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14360                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14361                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14362                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14363                 NULL,
14364         },
14365 };
14366 #endif
14367
14368 /* Strict link priority scheduling mode setting */
14369 static void
14370 cmd_strict_link_prio_parsed(
14371         void *parsed_result,
14372         __attribute__((unused)) struct cmdline *cl,
14373         __attribute__((unused)) void *data)
14374 {
14375         struct cmd_vf_tc_bw_result *res = parsed_result;
14376         int ret = -ENOTSUP;
14377
14378         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14379                 return;
14380
14381 #ifdef RTE_LIBRTE_I40E_PMD
14382         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14383 #endif
14384
14385         switch (ret) {
14386         case 0:
14387                 break;
14388         case -EINVAL:
14389                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14390                 break;
14391         case -ENODEV:
14392                 printf("invalid port_id %d\n", res->port_id);
14393                 break;
14394         case -ENOTSUP:
14395                 printf("function not implemented\n");
14396                 break;
14397         default:
14398                 printf("programming error: (%s)\n", strerror(-ret));
14399         }
14400 }
14401
14402 cmdline_parse_inst_t cmd_strict_link_prio = {
14403         .f = cmd_strict_link_prio_parsed,
14404         .data = NULL,
14405         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14406         .tokens = {
14407                 (void *)&cmd_vf_tc_bw_set,
14408                 (void *)&cmd_vf_tc_bw_tx,
14409                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14410                 (void *)&cmd_vf_tc_bw_port_id,
14411                 (void *)&cmd_vf_tc_bw_tc_map,
14412                 NULL,
14413         },
14414 };
14415
14416 /* Load dynamic device personalization*/
14417 struct cmd_ddp_add_result {
14418         cmdline_fixed_string_t ddp;
14419         cmdline_fixed_string_t add;
14420         portid_t port_id;
14421         char filepath[];
14422 };
14423
14424 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14425         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14426 cmdline_parse_token_string_t cmd_ddp_add_add =
14427         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14428 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14429         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14430 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14431         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14432
14433 static void
14434 cmd_ddp_add_parsed(
14435         void *parsed_result,
14436         __attribute__((unused)) struct cmdline *cl,
14437         __attribute__((unused)) void *data)
14438 {
14439         struct cmd_ddp_add_result *res = parsed_result;
14440         uint8_t *buff;
14441         uint32_t size;
14442         char *filepath;
14443         char *file_fld[2];
14444         int file_num;
14445         int ret = -ENOTSUP;
14446
14447         if (res->port_id > nb_ports) {
14448                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14449                 return;
14450         }
14451
14452         if (!all_ports_stopped()) {
14453                 printf("Please stop all ports first\n");
14454                 return;
14455         }
14456
14457         filepath = strdup(res->filepath);
14458         if (filepath == NULL) {
14459                 printf("Failed to allocate memory\n");
14460                 return;
14461         }
14462         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14463
14464         buff = open_file(file_fld[0], &size);
14465         if (!buff) {
14466                 free((void *)filepath);
14467                 return;
14468         }
14469
14470 #ifdef RTE_LIBRTE_I40E_PMD
14471         if (ret == -ENOTSUP)
14472                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14473                                                buff, size,
14474                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14475 #endif
14476
14477         if (ret == -EEXIST)
14478                 printf("Profile has already existed.\n");
14479         else if (ret < 0)
14480                 printf("Failed to load profile.\n");
14481         else if (file_num == 2)
14482                 save_file(file_fld[1], buff, size);
14483
14484         close_file(buff);
14485         free((void *)filepath);
14486 }
14487
14488 cmdline_parse_inst_t cmd_ddp_add = {
14489         .f = cmd_ddp_add_parsed,
14490         .data = NULL,
14491         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14492         .tokens = {
14493                 (void *)&cmd_ddp_add_ddp,
14494                 (void *)&cmd_ddp_add_add,
14495                 (void *)&cmd_ddp_add_port_id,
14496                 (void *)&cmd_ddp_add_filepath,
14497                 NULL,
14498         },
14499 };
14500
14501 /* Delete dynamic device personalization*/
14502 struct cmd_ddp_del_result {
14503         cmdline_fixed_string_t ddp;
14504         cmdline_fixed_string_t del;
14505         portid_t port_id;
14506         char filepath[];
14507 };
14508
14509 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14510         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14511 cmdline_parse_token_string_t cmd_ddp_del_del =
14512         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14513 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14514         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14515 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14516         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14517
14518 static void
14519 cmd_ddp_del_parsed(
14520         void *parsed_result,
14521         __attribute__((unused)) struct cmdline *cl,
14522         __attribute__((unused)) void *data)
14523 {
14524         struct cmd_ddp_del_result *res = parsed_result;
14525         uint8_t *buff;
14526         uint32_t size;
14527         int ret = -ENOTSUP;
14528
14529         if (res->port_id > nb_ports) {
14530                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14531                 return;
14532         }
14533
14534         if (!all_ports_stopped()) {
14535                 printf("Please stop all ports first\n");
14536                 return;
14537         }
14538
14539         buff = open_file(res->filepath, &size);
14540         if (!buff)
14541                 return;
14542
14543 #ifdef RTE_LIBRTE_I40E_PMD
14544         if (ret == -ENOTSUP)
14545                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14546                                                buff, size,
14547                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14548 #endif
14549
14550         if (ret == -EACCES)
14551                 printf("Profile does not exist.\n");
14552         else if (ret < 0)
14553                 printf("Failed to delete profile.\n");
14554
14555         close_file(buff);
14556 }
14557
14558 cmdline_parse_inst_t cmd_ddp_del = {
14559         .f = cmd_ddp_del_parsed,
14560         .data = NULL,
14561         .help_str = "ddp del <port_id> <profile_path>",
14562         .tokens = {
14563                 (void *)&cmd_ddp_del_ddp,
14564                 (void *)&cmd_ddp_del_del,
14565                 (void *)&cmd_ddp_del_port_id,
14566                 (void *)&cmd_ddp_del_filepath,
14567                 NULL,
14568         },
14569 };
14570
14571 /* Get dynamic device personalization profile info */
14572 struct cmd_ddp_info_result {
14573         cmdline_fixed_string_t ddp;
14574         cmdline_fixed_string_t get;
14575         cmdline_fixed_string_t info;
14576         char filepath[];
14577 };
14578
14579 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14580         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14581 cmdline_parse_token_string_t cmd_ddp_info_get =
14582         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14583 cmdline_parse_token_string_t cmd_ddp_info_info =
14584         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14585 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14586         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14587
14588 static void
14589 cmd_ddp_info_parsed(
14590         void *parsed_result,
14591         __attribute__((unused)) struct cmdline *cl,
14592         __attribute__((unused)) void *data)
14593 {
14594         struct cmd_ddp_info_result *res = parsed_result;
14595         uint8_t *pkg;
14596         uint32_t pkg_size;
14597         int ret = -ENOTSUP;
14598 #ifdef RTE_LIBRTE_I40E_PMD
14599         uint32_t i, j, n;
14600         uint8_t *buff;
14601         uint32_t buff_size = 0;
14602         struct rte_pmd_i40e_profile_info info;
14603         uint32_t dev_num = 0;
14604         struct rte_pmd_i40e_ddp_device_id *devs;
14605         uint32_t proto_num = 0;
14606         struct rte_pmd_i40e_proto_info *proto = NULL;
14607         uint32_t pctype_num = 0;
14608         struct rte_pmd_i40e_ptype_info *pctype;
14609         uint32_t ptype_num = 0;
14610         struct rte_pmd_i40e_ptype_info *ptype;
14611         uint8_t proto_id;
14612
14613 #endif
14614
14615         pkg = open_file(res->filepath, &pkg_size);
14616         if (!pkg)
14617                 return;
14618
14619 #ifdef RTE_LIBRTE_I40E_PMD
14620         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14621                                 (uint8_t *)&info, sizeof(info),
14622                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14623         if (!ret) {
14624                 printf("Global Track id:       0x%x\n", info.track_id);
14625                 printf("Global Version:        %d.%d.%d.%d\n",
14626                         info.version.major,
14627                         info.version.minor,
14628                         info.version.update,
14629                         info.version.draft);
14630                 printf("Global Package name:   %s\n\n", info.name);
14631         }
14632
14633         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14634                                 (uint8_t *)&info, sizeof(info),
14635                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14636         if (!ret) {
14637                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14638                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14639                         info.version.major,
14640                         info.version.minor,
14641                         info.version.update,
14642                         info.version.draft);
14643                 printf("i40e Profile name:     %s\n\n", info.name);
14644         }
14645
14646         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14647                                 (uint8_t *)&buff_size, sizeof(buff_size),
14648                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14649         if (!ret && buff_size) {
14650                 buff = (uint8_t *)malloc(buff_size);
14651                 if (buff) {
14652                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14653                                                 buff, buff_size,
14654                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14655                         if (!ret)
14656                                 printf("Package Notes:\n%s\n\n", buff);
14657                         free(buff);
14658                 }
14659         }
14660
14661         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14662                                 (uint8_t *)&dev_num, sizeof(dev_num),
14663                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14664         if (!ret && dev_num) {
14665                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14666                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14667                 if (devs) {
14668                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14669                                                 (uint8_t *)devs, buff_size,
14670                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14671                         if (!ret) {
14672                                 printf("List of supported devices:\n");
14673                                 for (i = 0; i < dev_num; i++) {
14674                                         printf("  %04X:%04X %04X:%04X\n",
14675                                                 devs[i].vendor_dev_id >> 16,
14676                                                 devs[i].vendor_dev_id & 0xFFFF,
14677                                                 devs[i].sub_vendor_dev_id >> 16,
14678                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14679                                 }
14680                                 printf("\n");
14681                         }
14682                         free(devs);
14683                 }
14684         }
14685
14686         /* get information about protocols and packet types */
14687         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14688                 (uint8_t *)&proto_num, sizeof(proto_num),
14689                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14690         if (ret || !proto_num)
14691                 goto no_print_return;
14692
14693         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14694         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14695         if (!proto)
14696                 goto no_print_return;
14697
14698         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14699                                         buff_size,
14700                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14701         if (!ret) {
14702                 printf("List of used protocols:\n");
14703                 for (i = 0; i < proto_num; i++)
14704                         printf("  %2u: %s\n", proto[i].proto_id,
14705                                proto[i].name);
14706                 printf("\n");
14707         }
14708         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14709                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14710                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14711         if (ret || !pctype_num)
14712                 goto no_print_pctypes;
14713
14714         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14715         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14716         if (!pctype)
14717                 goto no_print_pctypes;
14718
14719         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14720                                         buff_size,
14721                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14722         if (ret) {
14723                 free(pctype);
14724                 goto no_print_pctypes;
14725         }
14726
14727         printf("List of defined packet classification types:\n");
14728         for (i = 0; i < pctype_num; i++) {
14729                 printf("  %2u:", pctype[i].ptype_id);
14730                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14731                         proto_id = pctype[i].protocols[j];
14732                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14733                                 for (n = 0; n < proto_num; n++) {
14734                                         if (proto[n].proto_id == proto_id) {
14735                                                 printf(" %s", proto[n].name);
14736                                                 break;
14737                                         }
14738                                 }
14739                         }
14740                 }
14741                 printf("\n");
14742         }
14743         printf("\n");
14744         free(pctype);
14745
14746 no_print_pctypes:
14747
14748         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14749                                         sizeof(ptype_num),
14750                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14751         if (ret || !ptype_num)
14752                 goto no_print_return;
14753
14754         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14755         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14756         if (!ptype)
14757                 goto no_print_return;
14758
14759         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14760                                         buff_size,
14761                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14762         if (ret) {
14763                 free(ptype);
14764                 goto no_print_return;
14765         }
14766         printf("List of defined packet types:\n");
14767         for (i = 0; i < ptype_num; i++) {
14768                 printf("  %2u:", ptype[i].ptype_id);
14769                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14770                         proto_id = ptype[i].protocols[j];
14771                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14772                                 for (n = 0; n < proto_num; n++) {
14773                                         if (proto[n].proto_id == proto_id) {
14774                                                 printf(" %s", proto[n].name);
14775                                                 break;
14776                                         }
14777                                 }
14778                         }
14779                 }
14780                 printf("\n");
14781         }
14782         free(ptype);
14783         printf("\n");
14784
14785         ret = 0;
14786 no_print_return:
14787         if (proto)
14788                 free(proto);
14789 #endif
14790         if (ret == -ENOTSUP)
14791                 printf("Function not supported in PMD driver\n");
14792         close_file(pkg);
14793 }
14794
14795 cmdline_parse_inst_t cmd_ddp_get_info = {
14796         .f = cmd_ddp_info_parsed,
14797         .data = NULL,
14798         .help_str = "ddp get info <profile_path>",
14799         .tokens = {
14800                 (void *)&cmd_ddp_info_ddp,
14801                 (void *)&cmd_ddp_info_get,
14802                 (void *)&cmd_ddp_info_info,
14803                 (void *)&cmd_ddp_info_filepath,
14804                 NULL,
14805         },
14806 };
14807
14808 /* Get dynamic device personalization profile info list*/
14809 #define PROFILE_INFO_SIZE 48
14810 #define MAX_PROFILE_NUM 16
14811
14812 struct cmd_ddp_get_list_result {
14813         cmdline_fixed_string_t ddp;
14814         cmdline_fixed_string_t get;
14815         cmdline_fixed_string_t list;
14816         portid_t port_id;
14817 };
14818
14819 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14820         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14821 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14822         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14823 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14824         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14825 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14826         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14827
14828 static void
14829 cmd_ddp_get_list_parsed(
14830         void *parsed_result,
14831         __attribute__((unused)) struct cmdline *cl,
14832         __attribute__((unused)) void *data)
14833 {
14834         struct cmd_ddp_get_list_result *res = parsed_result;
14835 #ifdef RTE_LIBRTE_I40E_PMD
14836         struct rte_pmd_i40e_profile_list *p_list;
14837         struct rte_pmd_i40e_profile_info *p_info;
14838         uint32_t p_num;
14839         uint32_t size;
14840         uint32_t i;
14841 #endif
14842         int ret = -ENOTSUP;
14843
14844         if (res->port_id > nb_ports) {
14845                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14846                 return;
14847         }
14848
14849 #ifdef RTE_LIBRTE_I40E_PMD
14850         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14851         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14852         if (!p_list)
14853                 printf("%s: Failed to malloc buffer\n", __func__);
14854
14855         if (ret == -ENOTSUP)
14856                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14857                                                 (uint8_t *)p_list, size);
14858
14859         if (!ret) {
14860                 p_num = p_list->p_count;
14861                 printf("Profile number is: %d\n\n", p_num);
14862
14863                 for (i = 0; i < p_num; i++) {
14864                         p_info = &p_list->p_info[i];
14865                         printf("Profile %d:\n", i);
14866                         printf("Track id:     0x%x\n", p_info->track_id);
14867                         printf("Version:      %d.%d.%d.%d\n",
14868                                p_info->version.major,
14869                                p_info->version.minor,
14870                                p_info->version.update,
14871                                p_info->version.draft);
14872                         printf("Profile name: %s\n\n", p_info->name);
14873                 }
14874         }
14875
14876         free(p_list);
14877 #endif
14878
14879         if (ret < 0)
14880                 printf("Failed to get ddp list\n");
14881 }
14882
14883 cmdline_parse_inst_t cmd_ddp_get_list = {
14884         .f = cmd_ddp_get_list_parsed,
14885         .data = NULL,
14886         .help_str = "ddp get list <port_id>",
14887         .tokens = {
14888                 (void *)&cmd_ddp_get_list_ddp,
14889                 (void *)&cmd_ddp_get_list_get,
14890                 (void *)&cmd_ddp_get_list_list,
14891                 (void *)&cmd_ddp_get_list_port_id,
14892                 NULL,
14893         },
14894 };
14895
14896 /* Configure input set */
14897 struct cmd_cfg_input_set_result {
14898         cmdline_fixed_string_t port;
14899         cmdline_fixed_string_t cfg;
14900         portid_t port_id;
14901         cmdline_fixed_string_t pctype;
14902         uint8_t pctype_id;
14903         cmdline_fixed_string_t inset_type;
14904         cmdline_fixed_string_t opt;
14905         cmdline_fixed_string_t field;
14906         uint8_t field_idx;
14907 };
14908
14909 static void
14910 cmd_cfg_input_set_parsed(
14911         void *parsed_result,
14912         __attribute__((unused)) struct cmdline *cl,
14913         __attribute__((unused)) void *data)
14914 {
14915         struct cmd_cfg_input_set_result *res = parsed_result;
14916 #ifdef RTE_LIBRTE_I40E_PMD
14917         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14918         struct rte_pmd_i40e_inset inset;
14919 #endif
14920         int ret = -ENOTSUP;
14921
14922         if (res->port_id > nb_ports) {
14923                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14924                 return;
14925         }
14926
14927         if (!all_ports_stopped()) {
14928                 printf("Please stop all ports first\n");
14929                 return;
14930         }
14931
14932 #ifdef RTE_LIBRTE_I40E_PMD
14933         if (!strcmp(res->inset_type, "hash_inset"))
14934                 inset_type = INSET_HASH;
14935         else if (!strcmp(res->inset_type, "fdir_inset"))
14936                 inset_type = INSET_FDIR;
14937         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14938                 inset_type = INSET_FDIR_FLX;
14939         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14940                                      &inset, inset_type);
14941         if (ret) {
14942                 printf("Failed to get input set.\n");
14943                 return;
14944         }
14945
14946         if (!strcmp(res->opt, "get")) {
14947                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14948                                                    res->field_idx);
14949                 if (ret)
14950                         printf("Field index %d is enabled.\n", res->field_idx);
14951                 else
14952                         printf("Field index %d is disabled.\n", res->field_idx);
14953                 return;
14954         } else if (!strcmp(res->opt, "set"))
14955                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14956                                                    res->field_idx);
14957         else if (!strcmp(res->opt, "clear"))
14958                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14959                                                      res->field_idx);
14960         if (ret) {
14961                 printf("Failed to configure input set field.\n");
14962                 return;
14963         }
14964
14965         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14966                                      &inset, inset_type);
14967         if (ret) {
14968                 printf("Failed to set input set.\n");
14969                 return;
14970         }
14971 #endif
14972
14973         if (ret == -ENOTSUP)
14974                 printf("Function not supported\n");
14975 }
14976
14977 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14978         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14979                                  port, "port");
14980 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14981         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14982                                  cfg, "config");
14983 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14984         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14985                               port_id, UINT16);
14986 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14987         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14988                                  pctype, "pctype");
14989 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14990         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14991                               pctype_id, UINT8);
14992 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14993         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14994                                  inset_type,
14995                                  "hash_inset#fdir_inset#fdir_flx_inset");
14996 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14997         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14998                                  opt, "get#set#clear");
14999 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15000         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15001                                  field, "field");
15002 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15003         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15004                               field_idx, UINT8);
15005
15006 cmdline_parse_inst_t cmd_cfg_input_set = {
15007         .f = cmd_cfg_input_set_parsed,
15008         .data = NULL,
15009         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15010                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15011         .tokens = {
15012                 (void *)&cmd_cfg_input_set_port,
15013                 (void *)&cmd_cfg_input_set_cfg,
15014                 (void *)&cmd_cfg_input_set_port_id,
15015                 (void *)&cmd_cfg_input_set_pctype,
15016                 (void *)&cmd_cfg_input_set_pctype_id,
15017                 (void *)&cmd_cfg_input_set_inset_type,
15018                 (void *)&cmd_cfg_input_set_opt,
15019                 (void *)&cmd_cfg_input_set_field,
15020                 (void *)&cmd_cfg_input_set_field_idx,
15021                 NULL,
15022         },
15023 };
15024
15025 /* Clear input set */
15026 struct cmd_clear_input_set_result {
15027         cmdline_fixed_string_t port;
15028         cmdline_fixed_string_t cfg;
15029         portid_t port_id;
15030         cmdline_fixed_string_t pctype;
15031         uint8_t pctype_id;
15032         cmdline_fixed_string_t inset_type;
15033         cmdline_fixed_string_t clear;
15034         cmdline_fixed_string_t all;
15035 };
15036
15037 static void
15038 cmd_clear_input_set_parsed(
15039         void *parsed_result,
15040         __attribute__((unused)) struct cmdline *cl,
15041         __attribute__((unused)) void *data)
15042 {
15043         struct cmd_clear_input_set_result *res = parsed_result;
15044 #ifdef RTE_LIBRTE_I40E_PMD
15045         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15046         struct rte_pmd_i40e_inset inset;
15047 #endif
15048         int ret = -ENOTSUP;
15049
15050         if (res->port_id > nb_ports) {
15051                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15052                 return;
15053         }
15054
15055         if (!all_ports_stopped()) {
15056                 printf("Please stop all ports first\n");
15057                 return;
15058         }
15059
15060 #ifdef RTE_LIBRTE_I40E_PMD
15061         if (!strcmp(res->inset_type, "hash_inset"))
15062                 inset_type = INSET_HASH;
15063         else if (!strcmp(res->inset_type, "fdir_inset"))
15064                 inset_type = INSET_FDIR;
15065         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15066                 inset_type = INSET_FDIR_FLX;
15067
15068         memset(&inset, 0, sizeof(inset));
15069
15070         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15071                                      &inset, inset_type);
15072         if (ret) {
15073                 printf("Failed to clear input set.\n");
15074                 return;
15075         }
15076
15077 #endif
15078
15079         if (ret == -ENOTSUP)
15080                 printf("Function not supported\n");
15081 }
15082
15083 cmdline_parse_token_string_t cmd_clear_input_set_port =
15084         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15085                                  port, "port");
15086 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15087         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15088                                  cfg, "config");
15089 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15090         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15091                               port_id, UINT16);
15092 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15093         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15094                                  pctype, "pctype");
15095 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15096         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15097                               pctype_id, UINT8);
15098 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15099         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15100                                  inset_type,
15101                                  "hash_inset#fdir_inset#fdir_flx_inset");
15102 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15103         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15104                                  clear, "clear");
15105 cmdline_parse_token_string_t cmd_clear_input_set_all =
15106         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15107                                  all, "all");
15108
15109 cmdline_parse_inst_t cmd_clear_input_set = {
15110         .f = cmd_clear_input_set_parsed,
15111         .data = NULL,
15112         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15113                     "fdir_inset|fdir_flx_inset clear all",
15114         .tokens = {
15115                 (void *)&cmd_clear_input_set_port,
15116                 (void *)&cmd_clear_input_set_cfg,
15117                 (void *)&cmd_clear_input_set_port_id,
15118                 (void *)&cmd_clear_input_set_pctype,
15119                 (void *)&cmd_clear_input_set_pctype_id,
15120                 (void *)&cmd_clear_input_set_inset_type,
15121                 (void *)&cmd_clear_input_set_clear,
15122                 (void *)&cmd_clear_input_set_all,
15123                 NULL,
15124         },
15125 };
15126
15127 /* show vf stats */
15128
15129 /* Common result structure for show vf stats */
15130 struct cmd_show_vf_stats_result {
15131         cmdline_fixed_string_t show;
15132         cmdline_fixed_string_t vf;
15133         cmdline_fixed_string_t stats;
15134         portid_t port_id;
15135         uint16_t vf_id;
15136 };
15137
15138 /* Common CLI fields show vf stats*/
15139 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_show_vf_stats_result,
15142                  show, "show");
15143 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_show_vf_stats_result,
15146                  vf, "vf");
15147 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15148         TOKEN_STRING_INITIALIZER
15149                 (struct cmd_show_vf_stats_result,
15150                  stats, "stats");
15151 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15152         TOKEN_NUM_INITIALIZER
15153                 (struct cmd_show_vf_stats_result,
15154                  port_id, UINT16);
15155 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15156         TOKEN_NUM_INITIALIZER
15157                 (struct cmd_show_vf_stats_result,
15158                  vf_id, UINT16);
15159
15160 static void
15161 cmd_show_vf_stats_parsed(
15162         void *parsed_result,
15163         __attribute__((unused)) struct cmdline *cl,
15164         __attribute__((unused)) void *data)
15165 {
15166         struct cmd_show_vf_stats_result *res = parsed_result;
15167         struct rte_eth_stats stats;
15168         int ret = -ENOTSUP;
15169         static const char *nic_stats_border = "########################";
15170
15171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15172                 return;
15173
15174         memset(&stats, 0, sizeof(stats));
15175
15176 #ifdef RTE_LIBRTE_I40E_PMD
15177         if (ret == -ENOTSUP)
15178                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15179                                                 res->vf_id,
15180                                                 &stats);
15181 #endif
15182 #ifdef RTE_LIBRTE_BNXT_PMD
15183         if (ret == -ENOTSUP)
15184                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15185                                                 res->vf_id,
15186                                                 &stats);
15187 #endif
15188
15189         switch (ret) {
15190         case 0:
15191                 break;
15192         case -EINVAL:
15193                 printf("invalid vf_id %d\n", res->vf_id);
15194                 break;
15195         case -ENODEV:
15196                 printf("invalid port_id %d\n", res->port_id);
15197                 break;
15198         case -ENOTSUP:
15199                 printf("function not implemented\n");
15200                 break;
15201         default:
15202                 printf("programming error: (%s)\n", strerror(-ret));
15203         }
15204
15205         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15206                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15207
15208         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15209                "%-"PRIu64"\n",
15210                stats.ipackets, stats.imissed, stats.ibytes);
15211         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15212         printf("  RX-nombuf:  %-10"PRIu64"\n",
15213                stats.rx_nombuf);
15214         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15215                "%-"PRIu64"\n",
15216                stats.opackets, stats.oerrors, stats.obytes);
15217
15218         printf("  %s############################%s\n",
15219                                nic_stats_border, nic_stats_border);
15220 }
15221
15222 cmdline_parse_inst_t cmd_show_vf_stats = {
15223         .f = cmd_show_vf_stats_parsed,
15224         .data = NULL,
15225         .help_str = "show vf stats <port_id> <vf_id>",
15226         .tokens = {
15227                 (void *)&cmd_show_vf_stats_show,
15228                 (void *)&cmd_show_vf_stats_vf,
15229                 (void *)&cmd_show_vf_stats_stats,
15230                 (void *)&cmd_show_vf_stats_port_id,
15231                 (void *)&cmd_show_vf_stats_vf_id,
15232                 NULL,
15233         },
15234 };
15235
15236 /* clear vf stats */
15237
15238 /* Common result structure for clear vf stats */
15239 struct cmd_clear_vf_stats_result {
15240         cmdline_fixed_string_t clear;
15241         cmdline_fixed_string_t vf;
15242         cmdline_fixed_string_t stats;
15243         portid_t port_id;
15244         uint16_t vf_id;
15245 };
15246
15247 /* Common CLI fields clear vf stats*/
15248 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15249         TOKEN_STRING_INITIALIZER
15250                 (struct cmd_clear_vf_stats_result,
15251                  clear, "clear");
15252 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15253         TOKEN_STRING_INITIALIZER
15254                 (struct cmd_clear_vf_stats_result,
15255                  vf, "vf");
15256 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15257         TOKEN_STRING_INITIALIZER
15258                 (struct cmd_clear_vf_stats_result,
15259                  stats, "stats");
15260 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15261         TOKEN_NUM_INITIALIZER
15262                 (struct cmd_clear_vf_stats_result,
15263                  port_id, UINT16);
15264 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15265         TOKEN_NUM_INITIALIZER
15266                 (struct cmd_clear_vf_stats_result,
15267                  vf_id, UINT16);
15268
15269 static void
15270 cmd_clear_vf_stats_parsed(
15271         void *parsed_result,
15272         __attribute__((unused)) struct cmdline *cl,
15273         __attribute__((unused)) void *data)
15274 {
15275         struct cmd_clear_vf_stats_result *res = parsed_result;
15276         int ret = -ENOTSUP;
15277
15278         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15279                 return;
15280
15281 #ifdef RTE_LIBRTE_I40E_PMD
15282         if (ret == -ENOTSUP)
15283                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15284                                                   res->vf_id);
15285 #endif
15286 #ifdef RTE_LIBRTE_BNXT_PMD
15287         if (ret == -ENOTSUP)
15288                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15289                                                   res->vf_id);
15290 #endif
15291
15292         switch (ret) {
15293         case 0:
15294                 break;
15295         case -EINVAL:
15296                 printf("invalid vf_id %d\n", res->vf_id);
15297                 break;
15298         case -ENODEV:
15299                 printf("invalid port_id %d\n", res->port_id);
15300                 break;
15301         case -ENOTSUP:
15302                 printf("function not implemented\n");
15303                 break;
15304         default:
15305                 printf("programming error: (%s)\n", strerror(-ret));
15306         }
15307 }
15308
15309 cmdline_parse_inst_t cmd_clear_vf_stats = {
15310         .f = cmd_clear_vf_stats_parsed,
15311         .data = NULL,
15312         .help_str = "clear vf stats <port_id> <vf_id>",
15313         .tokens = {
15314                 (void *)&cmd_clear_vf_stats_clear,
15315                 (void *)&cmd_clear_vf_stats_vf,
15316                 (void *)&cmd_clear_vf_stats_stats,
15317                 (void *)&cmd_clear_vf_stats_port_id,
15318                 (void *)&cmd_clear_vf_stats_vf_id,
15319                 NULL,
15320         },
15321 };
15322
15323 /* port config pctype mapping reset */
15324
15325 /* Common result structure for port config pctype mapping reset */
15326 struct cmd_pctype_mapping_reset_result {
15327         cmdline_fixed_string_t port;
15328         cmdline_fixed_string_t config;
15329         portid_t port_id;
15330         cmdline_fixed_string_t pctype;
15331         cmdline_fixed_string_t mapping;
15332         cmdline_fixed_string_t reset;
15333 };
15334
15335 /* Common CLI fields for port config pctype mapping reset*/
15336 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15337         TOKEN_STRING_INITIALIZER
15338                 (struct cmd_pctype_mapping_reset_result,
15339                  port, "port");
15340 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15341         TOKEN_STRING_INITIALIZER
15342                 (struct cmd_pctype_mapping_reset_result,
15343                  config, "config");
15344 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15345         TOKEN_NUM_INITIALIZER
15346                 (struct cmd_pctype_mapping_reset_result,
15347                  port_id, UINT16);
15348 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15349         TOKEN_STRING_INITIALIZER
15350                 (struct cmd_pctype_mapping_reset_result,
15351                  pctype, "pctype");
15352 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15353         TOKEN_STRING_INITIALIZER
15354                 (struct cmd_pctype_mapping_reset_result,
15355                  mapping, "mapping");
15356 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15357         TOKEN_STRING_INITIALIZER
15358                 (struct cmd_pctype_mapping_reset_result,
15359                  reset, "reset");
15360
15361 static void
15362 cmd_pctype_mapping_reset_parsed(
15363         void *parsed_result,
15364         __attribute__((unused)) struct cmdline *cl,
15365         __attribute__((unused)) void *data)
15366 {
15367         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15368         int ret = -ENOTSUP;
15369
15370         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15371                 return;
15372
15373 #ifdef RTE_LIBRTE_I40E_PMD
15374         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15375 #endif
15376
15377         switch (ret) {
15378         case 0:
15379                 break;
15380         case -ENODEV:
15381                 printf("invalid port_id %d\n", res->port_id);
15382                 break;
15383         case -ENOTSUP:
15384                 printf("function not implemented\n");
15385                 break;
15386         default:
15387                 printf("programming error: (%s)\n", strerror(-ret));
15388         }
15389 }
15390
15391 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15392         .f = cmd_pctype_mapping_reset_parsed,
15393         .data = NULL,
15394         .help_str = "port config <port_id> pctype mapping reset",
15395         .tokens = {
15396                 (void *)&cmd_pctype_mapping_reset_port,
15397                 (void *)&cmd_pctype_mapping_reset_config,
15398                 (void *)&cmd_pctype_mapping_reset_port_id,
15399                 (void *)&cmd_pctype_mapping_reset_pctype,
15400                 (void *)&cmd_pctype_mapping_reset_mapping,
15401                 (void *)&cmd_pctype_mapping_reset_reset,
15402                 NULL,
15403         },
15404 };
15405
15406 /* show port pctype mapping */
15407
15408 /* Common result structure for show port pctype mapping */
15409 struct cmd_pctype_mapping_get_result {
15410         cmdline_fixed_string_t show;
15411         cmdline_fixed_string_t port;
15412         portid_t port_id;
15413         cmdline_fixed_string_t pctype;
15414         cmdline_fixed_string_t mapping;
15415 };
15416
15417 /* Common CLI fields for pctype mapping get */
15418 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15419         TOKEN_STRING_INITIALIZER
15420                 (struct cmd_pctype_mapping_get_result,
15421                  show, "show");
15422 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15423         TOKEN_STRING_INITIALIZER
15424                 (struct cmd_pctype_mapping_get_result,
15425                  port, "port");
15426 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15427         TOKEN_NUM_INITIALIZER
15428                 (struct cmd_pctype_mapping_get_result,
15429                  port_id, UINT16);
15430 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15431         TOKEN_STRING_INITIALIZER
15432                 (struct cmd_pctype_mapping_get_result,
15433                  pctype, "pctype");
15434 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15435         TOKEN_STRING_INITIALIZER
15436                 (struct cmd_pctype_mapping_get_result,
15437                  mapping, "mapping");
15438
15439 static void
15440 cmd_pctype_mapping_get_parsed(
15441         void *parsed_result,
15442         __attribute__((unused)) struct cmdline *cl,
15443         __attribute__((unused)) void *data)
15444 {
15445         struct cmd_pctype_mapping_get_result *res = parsed_result;
15446         int ret = -ENOTSUP;
15447 #ifdef RTE_LIBRTE_I40E_PMD
15448         struct rte_pmd_i40e_flow_type_mapping
15449                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15450         int i, j, first_pctype;
15451 #endif
15452
15453         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15454                 return;
15455
15456 #ifdef RTE_LIBRTE_I40E_PMD
15457         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15458 #endif
15459
15460         switch (ret) {
15461         case 0:
15462                 break;
15463         case -ENODEV:
15464                 printf("invalid port_id %d\n", res->port_id);
15465                 return;
15466         case -ENOTSUP:
15467                 printf("function not implemented\n");
15468                 return;
15469         default:
15470                 printf("programming error: (%s)\n", strerror(-ret));
15471                 return;
15472         }
15473
15474 #ifdef RTE_LIBRTE_I40E_PMD
15475         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15476                 if (mapping[i].pctype != 0ULL) {
15477                         first_pctype = 1;
15478
15479                         printf("pctype: ");
15480                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15481                                 if (mapping[i].pctype & (1ULL << j)) {
15482                                         printf(first_pctype ?
15483                                                "%02d" : ",%02d", j);
15484                                         first_pctype = 0;
15485                                 }
15486                         }
15487                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15488                 }
15489         }
15490 #endif
15491 }
15492
15493 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15494         .f = cmd_pctype_mapping_get_parsed,
15495         .data = NULL,
15496         .help_str = "show port <port_id> pctype mapping",
15497         .tokens = {
15498                 (void *)&cmd_pctype_mapping_get_show,
15499                 (void *)&cmd_pctype_mapping_get_port,
15500                 (void *)&cmd_pctype_mapping_get_port_id,
15501                 (void *)&cmd_pctype_mapping_get_pctype,
15502                 (void *)&cmd_pctype_mapping_get_mapping,
15503                 NULL,
15504         },
15505 };
15506
15507 /* port config pctype mapping update */
15508
15509 /* Common result structure for port config pctype mapping update */
15510 struct cmd_pctype_mapping_update_result {
15511         cmdline_fixed_string_t port;
15512         cmdline_fixed_string_t config;
15513         portid_t port_id;
15514         cmdline_fixed_string_t pctype;
15515         cmdline_fixed_string_t mapping;
15516         cmdline_fixed_string_t update;
15517         cmdline_fixed_string_t pctype_list;
15518         uint16_t flow_type;
15519 };
15520
15521 /* Common CLI fields for pctype mapping update*/
15522 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15523         TOKEN_STRING_INITIALIZER
15524                 (struct cmd_pctype_mapping_update_result,
15525                  port, "port");
15526 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15527         TOKEN_STRING_INITIALIZER
15528                 (struct cmd_pctype_mapping_update_result,
15529                  config, "config");
15530 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15531         TOKEN_NUM_INITIALIZER
15532                 (struct cmd_pctype_mapping_update_result,
15533                  port_id, UINT16);
15534 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15535         TOKEN_STRING_INITIALIZER
15536                 (struct cmd_pctype_mapping_update_result,
15537                  pctype, "pctype");
15538 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15539         TOKEN_STRING_INITIALIZER
15540                 (struct cmd_pctype_mapping_update_result,
15541                  mapping, "mapping");
15542 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15543         TOKEN_STRING_INITIALIZER
15544                 (struct cmd_pctype_mapping_update_result,
15545                  update, "update");
15546 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15547         TOKEN_STRING_INITIALIZER
15548                 (struct cmd_pctype_mapping_update_result,
15549                  pctype_list, NULL);
15550 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15551         TOKEN_NUM_INITIALIZER
15552                 (struct cmd_pctype_mapping_update_result,
15553                  flow_type, UINT16);
15554
15555 static void
15556 cmd_pctype_mapping_update_parsed(
15557         void *parsed_result,
15558         __attribute__((unused)) struct cmdline *cl,
15559         __attribute__((unused)) void *data)
15560 {
15561         struct cmd_pctype_mapping_update_result *res = parsed_result;
15562         int ret = -ENOTSUP;
15563 #ifdef RTE_LIBRTE_I40E_PMD
15564         struct rte_pmd_i40e_flow_type_mapping mapping;
15565         unsigned int i;
15566         unsigned int nb_item;
15567         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15568 #endif
15569
15570         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15571                 return;
15572
15573 #ifdef RTE_LIBRTE_I40E_PMD
15574         nb_item = parse_item_list(res->pctype_list, "pctypes",
15575                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15576         mapping.flow_type = res->flow_type;
15577         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15578                 mapping.pctype |= (1ULL << pctype_list[i]);
15579         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15580                                                 &mapping,
15581                                                 1,
15582                                                 0);
15583 #endif
15584
15585         switch (ret) {
15586         case 0:
15587                 break;
15588         case -EINVAL:
15589                 printf("invalid pctype or flow type\n");
15590                 break;
15591         case -ENODEV:
15592                 printf("invalid port_id %d\n", res->port_id);
15593                 break;
15594         case -ENOTSUP:
15595                 printf("function not implemented\n");
15596                 break;
15597         default:
15598                 printf("programming error: (%s)\n", strerror(-ret));
15599         }
15600 }
15601
15602 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15603         .f = cmd_pctype_mapping_update_parsed,
15604         .data = NULL,
15605         .help_str = "port config <port_id> pctype mapping update"
15606         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15607         .tokens = {
15608                 (void *)&cmd_pctype_mapping_update_port,
15609                 (void *)&cmd_pctype_mapping_update_config,
15610                 (void *)&cmd_pctype_mapping_update_port_id,
15611                 (void *)&cmd_pctype_mapping_update_pctype,
15612                 (void *)&cmd_pctype_mapping_update_mapping,
15613                 (void *)&cmd_pctype_mapping_update_update,
15614                 (void *)&cmd_pctype_mapping_update_pc_type,
15615                 (void *)&cmd_pctype_mapping_update_flow_type,
15616                 NULL,
15617         },
15618 };
15619
15620 /* ptype mapping get */
15621
15622 /* Common result structure for ptype mapping get */
15623 struct cmd_ptype_mapping_get_result {
15624         cmdline_fixed_string_t ptype;
15625         cmdline_fixed_string_t mapping;
15626         cmdline_fixed_string_t get;
15627         portid_t port_id;
15628         uint8_t valid_only;
15629 };
15630
15631 /* Common CLI fields for ptype mapping get */
15632 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15633         TOKEN_STRING_INITIALIZER
15634                 (struct cmd_ptype_mapping_get_result,
15635                  ptype, "ptype");
15636 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15637         TOKEN_STRING_INITIALIZER
15638                 (struct cmd_ptype_mapping_get_result,
15639                  mapping, "mapping");
15640 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15641         TOKEN_STRING_INITIALIZER
15642                 (struct cmd_ptype_mapping_get_result,
15643                  get, "get");
15644 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15645         TOKEN_NUM_INITIALIZER
15646                 (struct cmd_ptype_mapping_get_result,
15647                  port_id, UINT16);
15648 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15649         TOKEN_NUM_INITIALIZER
15650                 (struct cmd_ptype_mapping_get_result,
15651                  valid_only, UINT8);
15652
15653 static void
15654 cmd_ptype_mapping_get_parsed(
15655         void *parsed_result,
15656         __attribute__((unused)) struct cmdline *cl,
15657         __attribute__((unused)) void *data)
15658 {
15659         struct cmd_ptype_mapping_get_result *res = parsed_result;
15660         int ret = -ENOTSUP;
15661 #ifdef RTE_LIBRTE_I40E_PMD
15662         int max_ptype_num = 256;
15663         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15664         uint16_t count;
15665         int i;
15666 #endif
15667
15668         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15669                 return;
15670
15671 #ifdef RTE_LIBRTE_I40E_PMD
15672         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15673                                         mapping,
15674                                         max_ptype_num,
15675                                         &count,
15676                                         res->valid_only);
15677 #endif
15678
15679         switch (ret) {
15680         case 0:
15681                 break;
15682         case -ENODEV:
15683                 printf("invalid port_id %d\n", res->port_id);
15684                 break;
15685         case -ENOTSUP:
15686                 printf("function not implemented\n");
15687                 break;
15688         default:
15689                 printf("programming error: (%s)\n", strerror(-ret));
15690         }
15691
15692 #ifdef RTE_LIBRTE_I40E_PMD
15693         if (!ret) {
15694                 for (i = 0; i < count; i++)
15695                         printf("%3d\t0x%08x\n",
15696                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15697         }
15698 #endif
15699 }
15700
15701 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15702         .f = cmd_ptype_mapping_get_parsed,
15703         .data = NULL,
15704         .help_str = "ptype mapping get <port_id> <valid_only>",
15705         .tokens = {
15706                 (void *)&cmd_ptype_mapping_get_ptype,
15707                 (void *)&cmd_ptype_mapping_get_mapping,
15708                 (void *)&cmd_ptype_mapping_get_get,
15709                 (void *)&cmd_ptype_mapping_get_port_id,
15710                 (void *)&cmd_ptype_mapping_get_valid_only,
15711                 NULL,
15712         },
15713 };
15714
15715 /* ptype mapping replace */
15716
15717 /* Common result structure for ptype mapping replace */
15718 struct cmd_ptype_mapping_replace_result {
15719         cmdline_fixed_string_t ptype;
15720         cmdline_fixed_string_t mapping;
15721         cmdline_fixed_string_t replace;
15722         portid_t port_id;
15723         uint32_t target;
15724         uint8_t mask;
15725         uint32_t pkt_type;
15726 };
15727
15728 /* Common CLI fields for ptype mapping replace */
15729 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15730         TOKEN_STRING_INITIALIZER
15731                 (struct cmd_ptype_mapping_replace_result,
15732                  ptype, "ptype");
15733 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15734         TOKEN_STRING_INITIALIZER
15735                 (struct cmd_ptype_mapping_replace_result,
15736                  mapping, "mapping");
15737 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15738         TOKEN_STRING_INITIALIZER
15739                 (struct cmd_ptype_mapping_replace_result,
15740                  replace, "replace");
15741 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15742         TOKEN_NUM_INITIALIZER
15743                 (struct cmd_ptype_mapping_replace_result,
15744                  port_id, UINT16);
15745 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15746         TOKEN_NUM_INITIALIZER
15747                 (struct cmd_ptype_mapping_replace_result,
15748                  target, UINT32);
15749 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15750         TOKEN_NUM_INITIALIZER
15751                 (struct cmd_ptype_mapping_replace_result,
15752                  mask, UINT8);
15753 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15754         TOKEN_NUM_INITIALIZER
15755                 (struct cmd_ptype_mapping_replace_result,
15756                  pkt_type, UINT32);
15757
15758 static void
15759 cmd_ptype_mapping_replace_parsed(
15760         void *parsed_result,
15761         __attribute__((unused)) struct cmdline *cl,
15762         __attribute__((unused)) void *data)
15763 {
15764         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15765         int ret = -ENOTSUP;
15766
15767         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15768                 return;
15769
15770 #ifdef RTE_LIBRTE_I40E_PMD
15771         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15772                                         res->target,
15773                                         res->mask,
15774                                         res->pkt_type);
15775 #endif
15776
15777         switch (ret) {
15778         case 0:
15779                 break;
15780         case -EINVAL:
15781                 printf("invalid ptype 0x%8x or 0x%8x\n",
15782                                 res->target, res->pkt_type);
15783                 break;
15784         case -ENODEV:
15785                 printf("invalid port_id %d\n", res->port_id);
15786                 break;
15787         case -ENOTSUP:
15788                 printf("function not implemented\n");
15789                 break;
15790         default:
15791                 printf("programming error: (%s)\n", strerror(-ret));
15792         }
15793 }
15794
15795 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15796         .f = cmd_ptype_mapping_replace_parsed,
15797         .data = NULL,
15798         .help_str =
15799                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15800         .tokens = {
15801                 (void *)&cmd_ptype_mapping_replace_ptype,
15802                 (void *)&cmd_ptype_mapping_replace_mapping,
15803                 (void *)&cmd_ptype_mapping_replace_replace,
15804                 (void *)&cmd_ptype_mapping_replace_port_id,
15805                 (void *)&cmd_ptype_mapping_replace_target,
15806                 (void *)&cmd_ptype_mapping_replace_mask,
15807                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15808                 NULL,
15809         },
15810 };
15811
15812 /* ptype mapping reset */
15813
15814 /* Common result structure for ptype mapping reset */
15815 struct cmd_ptype_mapping_reset_result {
15816         cmdline_fixed_string_t ptype;
15817         cmdline_fixed_string_t mapping;
15818         cmdline_fixed_string_t reset;
15819         portid_t port_id;
15820 };
15821
15822 /* Common CLI fields for ptype mapping reset*/
15823 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15824         TOKEN_STRING_INITIALIZER
15825                 (struct cmd_ptype_mapping_reset_result,
15826                  ptype, "ptype");
15827 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15828         TOKEN_STRING_INITIALIZER
15829                 (struct cmd_ptype_mapping_reset_result,
15830                  mapping, "mapping");
15831 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15832         TOKEN_STRING_INITIALIZER
15833                 (struct cmd_ptype_mapping_reset_result,
15834                  reset, "reset");
15835 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15836         TOKEN_NUM_INITIALIZER
15837                 (struct cmd_ptype_mapping_reset_result,
15838                  port_id, UINT16);
15839
15840 static void
15841 cmd_ptype_mapping_reset_parsed(
15842         void *parsed_result,
15843         __attribute__((unused)) struct cmdline *cl,
15844         __attribute__((unused)) void *data)
15845 {
15846         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15847         int ret = -ENOTSUP;
15848
15849         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15850                 return;
15851
15852 #ifdef RTE_LIBRTE_I40E_PMD
15853         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15854 #endif
15855
15856         switch (ret) {
15857         case 0:
15858                 break;
15859         case -ENODEV:
15860                 printf("invalid port_id %d\n", res->port_id);
15861                 break;
15862         case -ENOTSUP:
15863                 printf("function not implemented\n");
15864                 break;
15865         default:
15866                 printf("programming error: (%s)\n", strerror(-ret));
15867         }
15868 }
15869
15870 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15871         .f = cmd_ptype_mapping_reset_parsed,
15872         .data = NULL,
15873         .help_str = "ptype mapping reset <port_id>",
15874         .tokens = {
15875                 (void *)&cmd_ptype_mapping_reset_ptype,
15876                 (void *)&cmd_ptype_mapping_reset_mapping,
15877                 (void *)&cmd_ptype_mapping_reset_reset,
15878                 (void *)&cmd_ptype_mapping_reset_port_id,
15879                 NULL,
15880         },
15881 };
15882
15883 /* ptype mapping update */
15884
15885 /* Common result structure for ptype mapping update */
15886 struct cmd_ptype_mapping_update_result {
15887         cmdline_fixed_string_t ptype;
15888         cmdline_fixed_string_t mapping;
15889         cmdline_fixed_string_t reset;
15890         portid_t port_id;
15891         uint8_t hw_ptype;
15892         uint32_t sw_ptype;
15893 };
15894
15895 /* Common CLI fields for ptype mapping update*/
15896 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15897         TOKEN_STRING_INITIALIZER
15898                 (struct cmd_ptype_mapping_update_result,
15899                  ptype, "ptype");
15900 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15901         TOKEN_STRING_INITIALIZER
15902                 (struct cmd_ptype_mapping_update_result,
15903                  mapping, "mapping");
15904 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15905         TOKEN_STRING_INITIALIZER
15906                 (struct cmd_ptype_mapping_update_result,
15907                  reset, "update");
15908 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15909         TOKEN_NUM_INITIALIZER
15910                 (struct cmd_ptype_mapping_update_result,
15911                  port_id, UINT16);
15912 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15913         TOKEN_NUM_INITIALIZER
15914                 (struct cmd_ptype_mapping_update_result,
15915                  hw_ptype, UINT8);
15916 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15917         TOKEN_NUM_INITIALIZER
15918                 (struct cmd_ptype_mapping_update_result,
15919                  sw_ptype, UINT32);
15920
15921 static void
15922 cmd_ptype_mapping_update_parsed(
15923         void *parsed_result,
15924         __attribute__((unused)) struct cmdline *cl,
15925         __attribute__((unused)) void *data)
15926 {
15927         struct cmd_ptype_mapping_update_result *res = parsed_result;
15928         int ret = -ENOTSUP;
15929 #ifdef RTE_LIBRTE_I40E_PMD
15930         struct rte_pmd_i40e_ptype_mapping mapping;
15931 #endif
15932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15933                 return;
15934
15935 #ifdef RTE_LIBRTE_I40E_PMD
15936         mapping.hw_ptype = res->hw_ptype;
15937         mapping.sw_ptype = res->sw_ptype;
15938         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15939                                                 &mapping,
15940                                                 1,
15941                                                 0);
15942 #endif
15943
15944         switch (ret) {
15945         case 0:
15946                 break;
15947         case -EINVAL:
15948                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15949                 break;
15950         case -ENODEV:
15951                 printf("invalid port_id %d\n", res->port_id);
15952                 break;
15953         case -ENOTSUP:
15954                 printf("function not implemented\n");
15955                 break;
15956         default:
15957                 printf("programming error: (%s)\n", strerror(-ret));
15958         }
15959 }
15960
15961 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15962         .f = cmd_ptype_mapping_update_parsed,
15963         .data = NULL,
15964         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15965         .tokens = {
15966                 (void *)&cmd_ptype_mapping_update_ptype,
15967                 (void *)&cmd_ptype_mapping_update_mapping,
15968                 (void *)&cmd_ptype_mapping_update_update,
15969                 (void *)&cmd_ptype_mapping_update_port_id,
15970                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15971                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15972                 NULL,
15973         },
15974 };
15975
15976 /* Common result structure for file commands */
15977 struct cmd_cmdfile_result {
15978         cmdline_fixed_string_t load;
15979         cmdline_fixed_string_t filename;
15980 };
15981
15982 /* Common CLI fields for file commands */
15983 cmdline_parse_token_string_t cmd_load_cmdfile =
15984         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15985 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15986         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15987
15988 static void
15989 cmd_load_from_file_parsed(
15990         void *parsed_result,
15991         __attribute__((unused)) struct cmdline *cl,
15992         __attribute__((unused)) void *data)
15993 {
15994         struct cmd_cmdfile_result *res = parsed_result;
15995
15996         cmdline_read_from_file(res->filename);
15997 }
15998
15999 cmdline_parse_inst_t cmd_load_from_file = {
16000         .f = cmd_load_from_file_parsed,
16001         .data = NULL,
16002         .help_str = "load <filename>",
16003         .tokens = {
16004                 (void *)&cmd_load_cmdfile,
16005                 (void *)&cmd_load_cmdfile_filename,
16006                 NULL,
16007         },
16008 };
16009
16010 /* ******************************************************************************** */
16011
16012 /* list of instructions */
16013 cmdline_parse_ctx_t main_ctx[] = {
16014         (cmdline_parse_inst_t *)&cmd_help_brief,
16015         (cmdline_parse_inst_t *)&cmd_help_long,
16016         (cmdline_parse_inst_t *)&cmd_quit,
16017         (cmdline_parse_inst_t *)&cmd_load_from_file,
16018         (cmdline_parse_inst_t *)&cmd_showport,
16019         (cmdline_parse_inst_t *)&cmd_showqueue,
16020         (cmdline_parse_inst_t *)&cmd_showportall,
16021         (cmdline_parse_inst_t *)&cmd_showcfg,
16022         (cmdline_parse_inst_t *)&cmd_start,
16023         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16024         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16025         (cmdline_parse_inst_t *)&cmd_set_link_up,
16026         (cmdline_parse_inst_t *)&cmd_set_link_down,
16027         (cmdline_parse_inst_t *)&cmd_reset,
16028         (cmdline_parse_inst_t *)&cmd_set_numbers,
16029         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16030         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16031         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16032         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16033         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16034         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16035         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16036         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16037         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16038         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16039         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16040         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16041         (cmdline_parse_inst_t *)&cmd_set_link_check,
16042         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16043         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16044         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16045         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16046 #ifdef RTE_LIBRTE_PMD_BOND
16047         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16048         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16049         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16050         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16051         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16052         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16053         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16054         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16055         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16056         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16057         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16058 #endif
16059         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16060         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16061         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16062         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16063         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16064         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16065         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16066         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16067         (cmdline_parse_inst_t *)&cmd_csum_set,
16068         (cmdline_parse_inst_t *)&cmd_csum_show,
16069         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16070         (cmdline_parse_inst_t *)&cmd_tso_set,
16071         (cmdline_parse_inst_t *)&cmd_tso_show,
16072         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16073         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16074         (cmdline_parse_inst_t *)&cmd_gro_enable,
16075         (cmdline_parse_inst_t *)&cmd_gro_flush,
16076         (cmdline_parse_inst_t *)&cmd_gro_show,
16077         (cmdline_parse_inst_t *)&cmd_gso_enable,
16078         (cmdline_parse_inst_t *)&cmd_gso_size,
16079         (cmdline_parse_inst_t *)&cmd_gso_show,
16080         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16081         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16082         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16083         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16084         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16085         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16086         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16087         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16088         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16089         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16090         (cmdline_parse_inst_t *)&cmd_config_dcb,
16091         (cmdline_parse_inst_t *)&cmd_read_reg,
16092         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16093         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16094         (cmdline_parse_inst_t *)&cmd_write_reg,
16095         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16096         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16097         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16098         (cmdline_parse_inst_t *)&cmd_stop,
16099         (cmdline_parse_inst_t *)&cmd_mac_addr,
16100         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16101         (cmdline_parse_inst_t *)&cmd_set_qmap,
16102         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16103         (cmdline_parse_inst_t *)&cmd_operate_port,
16104         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16105         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16106         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16107         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16108         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16109         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16110         (cmdline_parse_inst_t *)&cmd_config_mtu,
16111         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16112         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16113         (cmdline_parse_inst_t *)&cmd_config_rss,
16114         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16115         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16116         (cmdline_parse_inst_t *)&cmd_showport_reta,
16117         (cmdline_parse_inst_t *)&cmd_config_burst,
16118         (cmdline_parse_inst_t *)&cmd_config_thresh,
16119         (cmdline_parse_inst_t *)&cmd_config_threshold,
16120         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16121         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16122         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16123         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16124         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16125         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16126         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16127         (cmdline_parse_inst_t *)&cmd_global_config,
16128         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16129         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16130         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16131         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16132         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16133         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16134         (cmdline_parse_inst_t *)&cmd_dump,
16135         (cmdline_parse_inst_t *)&cmd_dump_one,
16136         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16137         (cmdline_parse_inst_t *)&cmd_syn_filter,
16138         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16139         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16140         (cmdline_parse_inst_t *)&cmd_flex_filter,
16141         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16142         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16143         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16144         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16145         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16146         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16147         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16148         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16149         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16150         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16151         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16152         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16153         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16154         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16155         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16156         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16157         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16158         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16159         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16160         (cmdline_parse_inst_t *)&cmd_flow,
16161         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16162         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16163         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16164         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16165         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16166         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16167         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16168         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16169         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16170         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16171         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16172         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16173         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16174         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16175         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16176         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16177         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16178         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16179         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16180         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16181         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16182         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16183         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16184         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16185         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16186         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16187         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16188         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16189         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16190         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16191         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16192         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16193         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16194         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16195         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16196         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16197         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16198         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16199         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16200         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16201         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16202         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16203         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16204         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16205         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16206         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16207         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16208         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16209         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16210 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16211         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16212 #endif
16213         (cmdline_parse_inst_t *)&cmd_ddp_add,
16214         (cmdline_parse_inst_t *)&cmd_ddp_del,
16215         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16216         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16217         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16218         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16219         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16220         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16221         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16222         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16223         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16224         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16225
16226         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16227         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16228         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16229         (cmdline_parse_inst_t *)&cmd_queue_region,
16230         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16231         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16232         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16233         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16234         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16235         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16236         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16237         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16238         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16239         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16240         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16241         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16242         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16243         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16244         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16245         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16246         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16247         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16248         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16249         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16250         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16251         NULL,
16252 };
16253
16254 /* read cmdline commands from file */
16255 void
16256 cmdline_read_from_file(const char *filename)
16257 {
16258         struct cmdline *cl;
16259
16260         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16261         if (cl == NULL) {
16262                 printf("Failed to create file based cmdline context: %s\n",
16263                        filename);
16264                 return;
16265         }
16266
16267         cmdline_interact(cl);
16268         cmdline_quit(cl);
16269
16270         cmdline_free(cl);
16271
16272         printf("Read CLI commands from %s\n", filename);
16273 }
16274
16275 /* prompt function, called from main on MASTER lcore */
16276 void
16277 prompt(void)
16278 {
16279         /* initialize non-constant commands */
16280         cmd_set_fwd_mode_init();
16281         cmd_set_fwd_retry_mode_init();
16282
16283         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16284         if (testpmd_cl == NULL)
16285                 return;
16286         cmdline_interact(testpmd_cl);
16287         cmdline_stdin_exit(testpmd_cl);
16288 }
16289
16290 void
16291 prompt_exit(void)
16292 {
16293         if (testpmd_cl != NULL)
16294                 cmdline_quit(testpmd_cl);
16295 }
16296
16297 static void
16298 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16299 {
16300         if (id == (portid_t)RTE_PORT_ALL) {
16301                 portid_t pid;
16302
16303                 RTE_ETH_FOREACH_DEV(pid) {
16304                         /* check if need_reconfig has been set to 1 */
16305                         if (ports[pid].need_reconfig == 0)
16306                                 ports[pid].need_reconfig = dev;
16307                         /* check if need_reconfig_queues has been set to 1 */
16308                         if (ports[pid].need_reconfig_queues == 0)
16309                                 ports[pid].need_reconfig_queues = queue;
16310                 }
16311         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16312                 /* check if need_reconfig has been set to 1 */
16313                 if (ports[id].need_reconfig == 0)
16314                         ports[id].need_reconfig = dev;
16315                 /* check if need_reconfig_queues has been set to 1 */
16316                 if (ports[id].need_reconfig_queues == 0)
16317                         ports[id].need_reconfig_queues = queue;
16318         }
16319 }